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

126467 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      122325 jkaabimofrad: Moved some of the FileFolder API tests logic to AbstractBaseApiTest.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126811 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 11:25:57 +00:00
parent 4d8abff435
commit 18408af78f
3 changed files with 105 additions and 99 deletions

View File

@@ -25,10 +25,11 @@
*/
package org.alfresco.rest.api.tests;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.nodes.NodesEntityResource;
import org.alfresco.rest.api.tests.RepoService.SiteInformation;
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
import org.alfresco.rest.api.tests.RepoService.TestPerson;
@@ -37,8 +38,15 @@ import org.alfresco.rest.api.tests.client.HttpResponse;
import org.alfresco.rest.api.tests.client.PublicApiClient;
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
import org.alfresco.rest.api.tests.client.RequestContext;
import org.alfresco.rest.api.tests.client.data.Folder;
import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.springframework.util.ResourceUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.Map;
/**
@@ -46,6 +54,7 @@ import java.util.Map;
*/
public abstract class AbstractBaseApiTest extends EnterpriseTestApi
{
private static final String RESOURCE_PREFIX = "publicapi/upload/";
/**
* The api scope. either public or private
@@ -232,4 +241,59 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
fail("Status code " + actualStatus + " returned, but expected " + expectedStatus);
}
}
// root (eg. Company Home for on-prem)
protected String getRootNodeId(String runAsUserId) throws Exception
{
HttpResponse response = getSingle(NodesEntityResource.class, runAsUserId, Nodes.PATH_ROOT, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
return node.getId();
}
// my (eg. User's Home for on-prem)
protected String getMyNodeId(String runAsUserId) throws Exception
{
HttpResponse response = getSingle(NodesEntityResource.class, runAsUserId, Nodes.PATH_MY, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
return node.getId();
}
protected Folder createFolder(String runAsUserId, String parentId, String folderName) throws Exception
{
return createFolder(runAsUserId, parentId, folderName, null);
}
protected Folder createFolder(String runAsUserId, String parentId, String folderName, Map<String, Object> props) throws Exception
{
return createNode(runAsUserId, parentId, folderName, "cm:folder", props, Folder.class);
}
protected Node createNode(String runAsUserId, String parentId, String nodeName, String nodeType, Map<String, Object> props) throws Exception
{
return createNode(runAsUserId, parentId, nodeName, nodeType, props, Node.class);
}
protected <T> T createNode(String runAsUserId, String parentId, String nodeName, String nodeType, Map<String, Object> props, Class<T> returnType)
throws Exception
{
Node n = new Node();
n.setName(nodeName);
n.setNodeType(nodeType);
n.setProperties(props);
// create node
HttpResponse response = post("nodes/" + parentId + "/children", runAsUserId, RestApiUtil.toJsonAsStringNonNull(n), 201);
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), returnType);
}
protected File getResourceFile(String fileName) throws FileNotFoundException
{
URL url = NodeApiTest.class.getClassLoader().getResource(RESOURCE_PREFIX + fileName);
if (url == null)
{
fail("Cannot get the resource: " + fileName);
}
return ResourceUtils.getFile(url);
}
}

View File

@@ -19,33 +19,13 @@
package org.alfresco.rest.api.tests;
import static org.alfresco.rest.api.tests.util.RestApiUtil.parsePaging;
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.repo.content.MimetypeMap;
@@ -83,12 +63,25 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.TempFileProvider;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.util.ResourceUtils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
/**
* API tests for:
@@ -106,8 +99,6 @@ import org.springframework.util.ResourceUtils;
*/
public class NodeApiTest extends AbstractBaseApiTest
{
private static final String RESOURCE_PREFIX = "publicapi/upload/";
private static final String URL_NODES = "nodes/";
/**
@@ -178,50 +169,6 @@ public class NodeApiTest extends AbstractBaseApiTest
AuthenticationUtil.clearCurrentSecurityContext();
}
// root (eg. Company Home for on-prem)
private String getRootNodeId(String runAsUserId) throws Exception
{
HttpResponse response = getSingle(NodesEntityResource.class, runAsUserId, Nodes.PATH_ROOT, null, 200);
Node node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
return node.getId();
}
// my (eg. User's Home for on-prem)
private String getMyNodeId(String runAsUserId) throws Exception
{
HttpResponse response = getSingle(NodesEntityResource.class, runAsUserId, Nodes.PATH_MY, null, 200);
Node node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
return node.getId();
}
private Folder createFolder(String runAsUserId, String parentId, String folderName) throws Exception
{
return createFolder(runAsUserId, parentId, folderName, null);
}
private Folder createFolder(String runAsUserId, String parentId, String folderName, Map<String, Object> props) throws Exception
{
return createNode( runAsUserId, parentId, folderName, "cm:folder", props, Folder.class);
}
private Node createNode(String runAsUserId, String parentId, String nodeName, String nodeType, Map<String, Object> props) throws Exception
{
return createNode( runAsUserId, parentId, nodeName, nodeType, props, Node.class);
}
private <T> T createNode(String runAsUserId, String parentId, String nodeName, String nodeType, Map<String, Object> props, Class<T> returnType) throws Exception
{
Node n = new Node();
n.setName(nodeName);
n.setNodeType(nodeType);
n.setProperties(props);
// create node
HttpResponse response = post(getChildrenUrl(parentId), runAsUserId, toJsonAsStringNonNull(n), 201);
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), returnType);
}
/**
* Tests get document library children.
* <p>GET:</p>
@@ -2204,27 +2151,9 @@ public class NodeApiTest extends AbstractBaseApiTest
return URL_NODES + parentId + "/children";
}
private File getResourceFile(String fileName) throws FileNotFoundException
{
URL url = NodeApiTest.class.getClassLoader().getResource(RESOURCE_PREFIX + fileName);
if (url == null)
{
fail("Cannot get the resource: " + fileName);
}
return ResourceUtils.getFile(url);
}
@Override
public String getScope()
{
return "public";
}
// TODO move into RestApiUtil (and statically init the OM)
private String toJsonAsStringNonNull(Object obj) throws IOException
{
ObjectMapper om = new ObjectMapper();
om.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
return om.writeValueAsString(obj);
}
}

View File

@@ -27,15 +27,16 @@
package org.alfresco.rest.api.tests.util;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.rest.api.tests.client.PublicApiClient;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* A utility class for Rest API tests
*
@@ -141,4 +142,16 @@ public class RestApiUtil
assertNotNull(object);
return OBJECT_MAPPER.writeValueAsString(object);
}
/**
* Converts the POJO which represents the JSON payload into a JSON string.
* null values will be ignored.
*/
public static String toJsonAsStringNonNull(Object object) throws IOException
{
assertNotNull(object);
ObjectMapper om = new ObjectMapper();
om.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
return om.writeValueAsString(object);
}
}