Merged HEAD (5.2) to 5.2.N (5.2.1)

126401 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      121206 jvonka: FileFolder API - NodeApiTest - minor updates around 'expected' checks
      - pre-work (eg. before implementing "move" and also hiding "sys" namespace aspects/props, etc) 
      RA-638, RA-683


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126746 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 11:02:45 +00:00
parent 92dbce46aa
commit d559c54151
4 changed files with 138 additions and 80 deletions

View File

@@ -28,14 +28,14 @@ public class ContentInfo
{ {
private String mimeType; private String mimeType;
private String mimeTypeName; private String mimeTypeName;
private long sizeInBytes; private Long sizeInBytes;
private String encoding; private String encoding;
public ContentInfo() public ContentInfo()
{ {
} }
public ContentInfo( String mimeType, String mimeTypeName, long sizeInBytes, String encoding) public ContentInfo(String mimeType, String mimeTypeName, Long sizeInBytes, String encoding)
{ {
this.mimeType = mimeType; this.mimeType = mimeType;
this.mimeTypeName = mimeTypeName; this.mimeTypeName = mimeTypeName;
@@ -55,7 +55,7 @@ public class ContentInfo
return mimeTypeName; return mimeTypeName;
} }
public long getSizeInBytes() { public Long getSizeInBytes() {
return sizeInBytes; return sizeInBytes;
} }

View File

@@ -511,99 +511,90 @@ public class NodeApiTest extends AbstractBaseApiTest
public void testGetNodeInfo() throws Exception public void testGetNodeInfo() throws Exception
{ {
AuthenticationUtil.setFullyAuthenticatedUser(user1); AuthenticationUtil.setFullyAuthenticatedUser(user1);
HttpResponse response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, null, 200);
HttpResponse response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_ROOT, null, 200);
Node node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class); Node node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
NodeRef companyHomeNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, node.getId());
response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, null, 200);
node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
String myFilesNodeId = node.getId(); String myFilesNodeId = node.getId();
assertNotNull(myFilesNodeId); assertNotNull(myFilesNodeId);
assertEquals(user1, node.getName()); assertEquals(user1, node.getName());
assertTrue(node.getIsFolder()); assertTrue(node.getIsFolder());
NodeRef myHomeNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myFilesNodeId);
NodeRef userHomesNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, node.getParentId());
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A // /Company Home/User Homes/user<timestamp>/folder<timestamp>_A
String folderA = "folder" + System.currentTimeMillis() + "_A"; String folderA = "folder" + System.currentTimeMillis() + "_A";
NodeRef folderA_Ref = repoService.createFolder(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myFilesNodeId), folderA); NodeRef folderA_Ref = repoService.createFolder(myHomeNodeRef, folderA);
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B // /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B
String folderB = "folder" + System.currentTimeMillis() + "_B"; String folderB = "folder" + System.currentTimeMillis() + "_B";
NodeRef folderB_Ref = repoService.createFolder(folderA_Ref, folderB); NodeRef folderB_Ref = repoService.createFolder(folderA_Ref, folderB);
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B/content<timestamp> // /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B/content<timestamp>
String content = "content" + System.currentTimeMillis(); String contentName = "content" + System.currentTimeMillis();
NodeRef contentNodeRef = repoService.createDocument(folderB_Ref, content, "The quick brown fox jumps over the lazy dog."); NodeRef contentNodeRef = repoService.createDocument(folderB_Ref, contentName, "The quick brown fox jumps over the lazy dog.");
// Add property // Add property
repoService.nodeService.setProperty(contentNodeRef, ContentModel.PROP_TITLE, "test title"); String title = "test title";
repoService.nodeService.setProperty(contentNodeRef, ContentModel.PROP_TITLE, title);
// get node info // get node info
response = getSingle(NodesEntityResource.class, user1, contentNodeRef.getId(), null, 200); response = getSingle(NodesEntityResource.class, user1, contentNodeRef.getId(), null, 200);
Document document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); Document documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
// Check all the default info the node API should return
assertEquals(content, document.getName()); // Expected result ...
assertNotNull(document.getId()); UserInfo expectedUser = new UserInfo(user1, user1+" "+user1);
assertNotNull(document.getCreatedAt());
assertNotNull(document.getCreatedByUser()); Document d1 = new Document();
UserInfo createdByUser = document.getCreatedByUser(); d1.setId(documentResp.getId());
assertEquals(user1, createdByUser.getId()); d1.setParentId(folderB_Ref.getId());
assertEquals(user1 + " " + user1, createdByUser.getDisplayName()); d1.setName(contentName);
assertNotNull(document.getModifiedAt()); d1.setNodeType("cm:content");
assertNotNull(document.getModifiedByUser()); ContentInfo ci = new ContentInfo();
UserInfo modifiedByUser = document.getModifiedByUser();
assertEquals(user1, modifiedByUser.getId()); // TODO fix me !!
assertEquals(user1 + " " + user1, modifiedByUser.getDisplayName()); //ci.setMimeType("text/plain");
assertFalse(document.getIsFolder()); //ci.setMimeTypeName("Plain Text");
assertNull(document.getIsLink()); ci.setMimeType("application/octet-stream");
assertEquals("cm:content", document.getNodeType()); ci.setMimeTypeName("Binary File (Octet Stream)");
assertNotNull(document.getParentId());
assertNotNull(document.getProperties()); ci.setSizeInBytes(44L);
assertTrue(document.getProperties().containsKey("cm:title")); ci.setEncoding("UTF-8");
assertNotNull(document.getAspectNames()); d1.setContent(ci);
assertTrue(document.getAspectNames().contains("cm:titled")); d1.setCreatedByUser(expectedUser);
ContentInfo contentInfo = document.getContent(); d1.setModifiedByUser(expectedUser);
assertNotNull(contentInfo);
assertNotNull(contentInfo.getEncoding()); Map<String,Object> props = new HashMap<>();
assertTrue(contentInfo.getSizeInBytes() > 0); props.put("cm:title",title);
assertNotNull(contentInfo.getMimeType());
assertNotNull(contentInfo.getMimeTypeName()); d1.setProperties(props);
// Path is not part of the default info d1.setAspectNames(Arrays.asList("cm:auditable","cm:titled"));
assertNull(document.getPath());
// Note: Path is not part of the default info
d1.expected(documentResp);
// get node info + path // get node info + path
//...nodes/nodeId?select=path //...nodes/nodeId?select=path
Map<String, String> params = Collections.singletonMap("select", "path"); Map<String, String> params = Collections.singletonMap("select", "path");
response = getSingle(NodesEntityResource.class, user1, contentNodeRef.getId(), params, 200); response = getSingle(NodesEntityResource.class, user1, contentNodeRef.getId(), params, 200);
document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
// default info
assertEquals(content, document.getName()); // Expected path ...
assertNotNull(document.getId()); // note: the pathInfo should only include the parents (not the requested node)
assertNotNull(document.getCreatedAt()); List<ElementInfo> elements = new ArrayList<>(5);
assertNotNull(document.getCreatedByUser()); elements.add(new ElementInfo(companyHomeNodeRef, "Company Home"));
assertNotNull(document.getModifiedAt()); elements.add(new ElementInfo(userHomesNodeRef, "User Homes"));
assertNotNull(document.getModifiedByUser()); elements.add(new ElementInfo(myHomeNodeRef, user1));
assertFalse(document.getIsFolder()); elements.add(new ElementInfo(folderA_Ref, folderA));
assertNull(document.getIsLink()); elements.add(new ElementInfo(folderB_Ref, folderB));
assertEquals("cm:content", document.getNodeType()); PathInfo expectedPath = new PathInfo("/Company Home/User Homes/"+user1+"/"+folderA+"/"+folderB, true, elements);
assertNotNull(document.getParentId()); d1.setPath(expectedPath);
assertNotNull(document.getProperties());
assertNotNull(document.getAspectNames()); d1.expected(documentResp);
assertNotNull(document.getContent());
// Path info
PathInfo pathInfo = document.getPath();
assertNotNull(pathInfo);
assertTrue(pathInfo.getIsComplete());
assertNotNull(pathInfo.getName());
// the pathInfo should only include the parents (not the requested node)
assertFalse(pathInfo.getName().endsWith(content));
assertTrue(pathInfo.getName().startsWith("/Company Home"));
List<ElementInfo> pathElements = pathInfo.getElements();
assertEquals(5, pathElements.size());
assertEquals("Company Home", pathElements.get(0).getName());
assertNotNull(pathElements.get(0).getId());
assertEquals("User Homes", pathElements.get(1).getName());
assertNotNull(pathElements.get(1).getId());
assertEquals(user1, pathElements.get(2).getName());
assertNotNull(pathElements.get(2).getId());
assertEquals(folderA, pathElements.get(3).getName());
assertNotNull(pathElements.get(3).getId());
assertEquals(folderB, pathElements.get(4).getName());
assertNotNull(pathElements.get(4).getId());
} }
/** /**

View File

@@ -212,7 +212,14 @@ public class Node
assertNotNull(other.createdAt); assertNotNull(other.createdAt);
} }
createdByUser.expected(other.getCreatedByUser()); if (createdByUser != null)
{
createdByUser.expected(other.getCreatedByUser());
}
else
{
assertNotNull(other.createdByUser);
}
if (modifiedAt != null) if (modifiedAt != null)
{ {
@@ -223,12 +230,19 @@ public class Node
assertNotNull(other.modifiedAt); assertNotNull(other.modifiedAt);
} }
modifiedByUser.expected(other.getModifiedByUser()); if (modifiedByUser != null)
{
modifiedByUser.expected(other.getModifiedByUser());
}
else
{
assertNotNull(other.modifiedByUser);
}
if (aspectNames != null) if (aspectNames != null)
{ {
assertNotNull(other.getAspectNames()); assertNotNull(other.getAspectNames());
assertEquals(aspectNames.size(), other.getAspectNames().size()); assertEquals("Expected: "+aspectNames+", actual: "+other.getAspectNames(), aspectNames.size(), other.getAspectNames().size());
for (String aspectName : aspectNames) for (String aspectName : aspectNames)
{ {
assertTrue(other.getAspectNames().contains(aspectName)); assertTrue(other.getAspectNames().contains(aspectName));
@@ -254,6 +268,7 @@ public class Node
assertNull(other.getProperties()); assertNull(other.getProperties());
} }
AssertUtil.assertEquals("isFolder", isFolder, other.getIsFolder());
AssertUtil.assertEquals("isLink", isLink, other.getIsLink()); AssertUtil.assertEquals("isLink", isLink, other.getIsLink());
if (path != null) { if (path != null) {

View File

@@ -1,12 +1,32 @@
/*
* Copyright (C) 2005-2016 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.rest.api.tests.client.data; package org.alfresco.rest.api.tests.client.data;
import junit.framework.Assert; import junit.framework.Assert;
import junit.framework.TestCase;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/** /**
* Representation of a path info (initially for client tests for File Folder API) * Representation of a path info (initially for client tests for File Folder API)
@@ -23,6 +43,13 @@ public class PathInfo
{ {
} }
public PathInfo(String name, Boolean isComplete, List<ElementInfo> elements)
{
this.name = name;
this.isComplete = isComplete;
this.elements = elements;
}
public String getName() public String getName()
{ {
return name; return name;
@@ -47,6 +74,12 @@ public class PathInfo
{ {
} }
public ElementInfo(NodeRef id, String name)
{
this.id = id;
this.name = name;
}
public String getName() public String getName()
{ {
return name; return name;
@@ -56,6 +89,15 @@ public class PathInfo
{ {
return id; return id;
} }
public void expected(Object o)
{
assertTrue(o instanceof ElementInfo);
ElementInfo other = (ElementInfo) o;
assertEquals(id, other.getName());
assertEquals(name, other.getName());
}
} }
public void expected(Object o) public void expected(Object o)
@@ -64,7 +106,17 @@ public class PathInfo
PathInfo other = (PathInfo) o; PathInfo other = (PathInfo) o;
// TODO assertEquals(getIsComplete(), other.getIsComplete());
Assert.fail("TODO test optional path elements !"); assertEquals(getName(), other.getName());
int idx = 0;
for (ElementInfo element : elements)
{
ElementInfo otherElement = other.getElements().get(idx);
assertEquals("Expected: "+element.getId()+", actual: "+otherElement.getId(), element.getId(), otherElement.getId());
assertEquals("Expected: "+element.getName()+", actual: "+otherElement.getName(), element.getName(), otherElement.getName());
idx++;
}
} }
} }