mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -25,10 +25,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.api.tests;
|
package org.alfresco.rest.api.tests;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
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.SiteInformation;
|
||||||
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
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.PublicApiClient;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
|
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
|
||||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
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.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;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +54,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||||
{
|
{
|
||||||
|
private static final String RESOURCE_PREFIX = "publicapi/upload/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The api scope. either public or private
|
* 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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,33 +19,13 @@
|
|||||||
package org.alfresco.rest.api.tests;
|
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.parsePaging;
|
||||||
|
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
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.ContentModel;
|
||||||
import org.alfresco.model.ForumModel;
|
import org.alfresco.model.ForumModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
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.security.PersonService;
|
||||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||||
import org.alfresco.util.TempFileProvider;
|
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.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
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:
|
* API tests for:
|
||||||
@@ -106,8 +99,6 @@ import org.springframework.util.ResourceUtils;
|
|||||||
*/
|
*/
|
||||||
public class NodeApiTest extends AbstractBaseApiTest
|
public class NodeApiTest extends AbstractBaseApiTest
|
||||||
{
|
{
|
||||||
private static final String RESOURCE_PREFIX = "publicapi/upload/";
|
|
||||||
|
|
||||||
private static final String URL_NODES = "nodes/";
|
private static final String URL_NODES = "nodes/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,50 +169,6 @@ public class NodeApiTest extends AbstractBaseApiTest
|
|||||||
AuthenticationUtil.clearCurrentSecurityContext();
|
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.
|
* Tests get document library children.
|
||||||
* <p>GET:</p>
|
* <p>GET:</p>
|
||||||
@@ -1847,7 +1794,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
|||||||
dUpdate = new Document();
|
dUpdate = new Document();
|
||||||
dUpdate.setProperties(props);
|
dUpdate.setProperties(props);
|
||||||
put("nodes", user1, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
put("nodes", user1, dId, toJsonAsStringNonNull(dUpdate), null, 400);
|
||||||
|
|
||||||
// -ve test - fail on unknown aspect
|
// -ve test - fail on unknown aspect
|
||||||
List<String> aspects = new ArrayList<>(d1.getAspectNames());
|
List<String> aspects = new ArrayList<>(d1.getAspectNames());
|
||||||
aspects.add("cm:unknownAspect");
|
aspects.add("cm:unknownAspect");
|
||||||
@@ -2133,17 +2080,17 @@ public class NodeApiTest extends AbstractBaseApiTest
|
|||||||
|
|
||||||
String fileName = "quick-1.txt";
|
String fileName = "quick-1.txt";
|
||||||
File file = getResourceFile(fileName);
|
File file = getResourceFile(fileName);
|
||||||
|
|
||||||
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create()
|
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create()
|
||||||
.setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_TEXT_PLAIN));
|
.setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_TEXT_PLAIN));
|
||||||
MultiPartRequest reqBody = multiPartBuilder.build();
|
MultiPartRequest reqBody = multiPartBuilder.build();
|
||||||
|
|
||||||
// Upload text content
|
// Upload text content
|
||||||
HttpResponse response = post(getChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201);
|
HttpResponse response = post(getChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||||
Document document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
Document document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||||
|
|
||||||
String contentNodeId = document.getId();
|
String contentNodeId = document.getId();
|
||||||
|
|
||||||
// Check the upload response
|
// Check the upload response
|
||||||
assertEquals(fileName, document.getName());
|
assertEquals(fileName, document.getName());
|
||||||
ContentInfo contentInfo = document.getContent();
|
ContentInfo contentInfo = document.getContent();
|
||||||
@@ -2204,27 +2151,9 @@ public class NodeApiTest extends AbstractBaseApiTest
|
|||||||
return URL_NODES + parentId + "/children";
|
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
|
@Override
|
||||||
public String getScope()
|
public String getScope()
|
||||||
{
|
{
|
||||||
return "public";
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -27,15 +27,16 @@
|
|||||||
package org.alfresco.rest.api.tests.util;
|
package org.alfresco.rest.api.tests.util;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
import org.codehaus.jackson.map.annotate.JsonSerialize;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility class for Rest API tests
|
* A utility class for Rest API tests
|
||||||
*
|
*
|
||||||
@@ -141,4 +142,16 @@ public class RestApiUtil
|
|||||||
assertNotNull(object);
|
assertNotNull(object);
|
||||||
return OBJECT_MAPPER.writeValueAsString(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user