diff --git a/source/java/org/alfresco/rest/api/model/ContentInfo.java b/source/java/org/alfresco/rest/api/model/ContentInfo.java index 482b07b2d1..4d03ab62fb 100644 --- a/source/java/org/alfresco/rest/api/model/ContentInfo.java +++ b/source/java/org/alfresco/rest/api/model/ContentInfo.java @@ -28,14 +28,14 @@ public class ContentInfo { private String mimeType; private String mimeTypeName; - private long sizeInBytes; + private Long sizeInBytes; private String encoding; 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.mimeTypeName = mimeTypeName; @@ -55,7 +55,7 @@ public class ContentInfo return mimeTypeName; } - public long getSizeInBytes() { + public Long getSizeInBytes() { return sizeInBytes; } diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java index 3d8940b1b2..04462f9342 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -511,99 +511,90 @@ public class NodeApiTest extends AbstractBaseApiTest public void testGetNodeInfo() throws Exception { 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); + 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(); assertNotNull(myFilesNodeId); assertEquals(user1, node.getName()); 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/folder_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/folder_A/folder_B String folderB = "folder" + System.currentTimeMillis() + "_B"; NodeRef folderB_Ref = repoService.createFolder(folderA_Ref, folderB); // /Company Home/User Homes/user/folder_A/folder_B/content - String content = "content" + System.currentTimeMillis(); - NodeRef contentNodeRef = repoService.createDocument(folderB_Ref, content, "The quick brown fox jumps over the lazy dog."); + String contentName = "content" + System.currentTimeMillis(); + NodeRef contentNodeRef = repoService.createDocument(folderB_Ref, contentName, "The quick brown fox jumps over the lazy dog."); + // 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 response = getSingle(NodesEntityResource.class, user1, contentNodeRef.getId(), null, 200); - Document document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); - // Check all the default info the node API should return - assertEquals(content, document.getName()); - assertNotNull(document.getId()); - assertNotNull(document.getCreatedAt()); - assertNotNull(document.getCreatedByUser()); - UserInfo createdByUser = document.getCreatedByUser(); - assertEquals(user1, createdByUser.getId()); - assertEquals(user1 + " " + user1, createdByUser.getDisplayName()); - assertNotNull(document.getModifiedAt()); - assertNotNull(document.getModifiedByUser()); - UserInfo modifiedByUser = document.getModifiedByUser(); - assertEquals(user1, modifiedByUser.getId()); - assertEquals(user1 + " " + user1, modifiedByUser.getDisplayName()); - assertFalse(document.getIsFolder()); - assertNull(document.getIsLink()); - assertEquals("cm:content", document.getNodeType()); - assertNotNull(document.getParentId()); - assertNotNull(document.getProperties()); - assertTrue(document.getProperties().containsKey("cm:title")); - assertNotNull(document.getAspectNames()); - assertTrue(document.getAspectNames().contains("cm:titled")); - ContentInfo contentInfo = document.getContent(); - assertNotNull(contentInfo); - assertNotNull(contentInfo.getEncoding()); - assertTrue(contentInfo.getSizeInBytes() > 0); - assertNotNull(contentInfo.getMimeType()); - assertNotNull(contentInfo.getMimeTypeName()); - // Path is not part of the default info - assertNull(document.getPath()); + Document documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); + + // Expected result ... + UserInfo expectedUser = new UserInfo(user1, user1+" "+user1); + + Document d1 = new Document(); + d1.setId(documentResp.getId()); + d1.setParentId(folderB_Ref.getId()); + d1.setName(contentName); + d1.setNodeType("cm:content"); + ContentInfo ci = new ContentInfo(); + + // TODO fix me !! + //ci.setMimeType("text/plain"); + //ci.setMimeTypeName("Plain Text"); + ci.setMimeType("application/octet-stream"); + ci.setMimeTypeName("Binary File (Octet Stream)"); + + ci.setSizeInBytes(44L); + ci.setEncoding("UTF-8"); + d1.setContent(ci); + d1.setCreatedByUser(expectedUser); + d1.setModifiedByUser(expectedUser); + + Map props = new HashMap<>(); + props.put("cm:title",title); + + d1.setProperties(props); + d1.setAspectNames(Arrays.asList("cm:auditable","cm:titled")); + + // Note: Path is not part of the default info + d1.expected(documentResp); // get node info + path //...nodes/nodeId?select=path Map params = Collections.singletonMap("select", "path"); response = getSingle(NodesEntityResource.class, user1, contentNodeRef.getId(), params, 200); - document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); - // default info - assertEquals(content, document.getName()); - assertNotNull(document.getId()); - assertNotNull(document.getCreatedAt()); - assertNotNull(document.getCreatedByUser()); - assertNotNull(document.getModifiedAt()); - assertNotNull(document.getModifiedByUser()); - assertFalse(document.getIsFolder()); - assertNull(document.getIsLink()); - assertEquals("cm:content", document.getNodeType()); - assertNotNull(document.getParentId()); - assertNotNull(document.getProperties()); - assertNotNull(document.getAspectNames()); - 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 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()); + documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); + + // Expected path ... + // note: the pathInfo should only include the parents (not the requested node) + List elements = new ArrayList<>(5); + elements.add(new ElementInfo(companyHomeNodeRef, "Company Home")); + elements.add(new ElementInfo(userHomesNodeRef, "User Homes")); + elements.add(new ElementInfo(myHomeNodeRef, user1)); + elements.add(new ElementInfo(folderA_Ref, folderA)); + elements.add(new ElementInfo(folderB_Ref, folderB)); + PathInfo expectedPath = new PathInfo("/Company Home/User Homes/"+user1+"/"+folderA+"/"+folderB, true, elements); + d1.setPath(expectedPath); + + d1.expected(documentResp); } /** diff --git a/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java b/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java index 0480673677..c7cb56b6ed 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java @@ -212,7 +212,14 @@ public class Node assertNotNull(other.createdAt); } - createdByUser.expected(other.getCreatedByUser()); + if (createdByUser != null) + { + createdByUser.expected(other.getCreatedByUser()); + } + else + { + assertNotNull(other.createdByUser); + } if (modifiedAt != null) { @@ -223,12 +230,19 @@ public class Node assertNotNull(other.modifiedAt); } - modifiedByUser.expected(other.getModifiedByUser()); + if (modifiedByUser != null) + { + modifiedByUser.expected(other.getModifiedByUser()); + } + else + { + assertNotNull(other.modifiedByUser); + } if (aspectNames != null) { assertNotNull(other.getAspectNames()); - assertEquals(aspectNames.size(), other.getAspectNames().size()); + assertEquals("Expected: "+aspectNames+", actual: "+other.getAspectNames(), aspectNames.size(), other.getAspectNames().size()); for (String aspectName : aspectNames) { assertTrue(other.getAspectNames().contains(aspectName)); @@ -254,6 +268,7 @@ public class Node assertNull(other.getProperties()); } + AssertUtil.assertEquals("isFolder", isFolder, other.getIsFolder()); AssertUtil.assertEquals("isLink", isLink, other.getIsLink()); if (path != null) { diff --git a/source/test-java/org/alfresco/rest/api/tests/client/data/PathInfo.java b/source/test-java/org/alfresco/rest/api/tests/client/data/PathInfo.java index ce078ac1a2..104d6b3126 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/data/PathInfo.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/data/PathInfo.java @@ -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 . + */ package org.alfresco.rest.api.tests.client.data; import junit.framework.Assert; +import junit.framework.TestCase; import org.alfresco.service.cmr.repository.NodeRef; 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) @@ -23,6 +43,13 @@ public class PathInfo { } + public PathInfo(String name, Boolean isComplete, List elements) + { + this.name = name; + this.isComplete = isComplete; + this.elements = elements; + } + public String getName() { return name; @@ -47,6 +74,12 @@ public class PathInfo { } + public ElementInfo(NodeRef id, String name) + { + this.id = id; + this.name = name; + } + public String getName() { return name; @@ -56,6 +89,15 @@ public class PathInfo { 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) @@ -64,7 +106,17 @@ public class PathInfo PathInfo other = (PathInfo) o; - // TODO - Assert.fail("TODO test optional path elements !"); + assertEquals(getIsComplete(), other.getIsComplete()); + 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++; + } } }