diff --git a/source/test-java/org/alfresco/rest/DeletedNodesTest.java b/source/test-java/org/alfresco/rest/DeletedNodesTest.java index 433aec6fdf..4a50d1f88c 100644 --- a/source/test-java/org/alfresco/rest/DeletedNodesTest.java +++ b/source/test-java/org/alfresco/rest/DeletedNodesTest.java @@ -48,6 +48,8 @@ import java.util.List; import java.util.Map; /** + * V1 REST API tests for managing the user's Trashcan (ie. "deleted nodes") + * * Tests Deleting nodes and recovering * * @author gethin @@ -93,7 +95,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest PublicApiClient.Paging paging = getPaging(0, 5); //First get any deleted nodes - HttpResponse response = getAll(URL_DELETED_NODES, user1, paging, 200); + HttpResponse response = getAll(URL_DELETED_NODES, paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertNotNull(nodes); int numOfNodes = nodes.size(); @@ -102,13 +104,13 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest deleteNode(createdFolder.getId()); deleteNode(createdFolderNonSite.getId()); - response = getAll(URL_DELETED_NODES, user1, paging, 200); + response = getAll(URL_DELETED_NODES, paging, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertNotNull(nodes); assertEquals(numOfNodes+3,nodes.size()); Map params = Collections.singletonMap("include", "path"); - response = getSingle(URL_DELETED_NODES, user1, document.getId(), params, 200); + response = getSingle(URL_DELETED_NODES, document.getId(), params, 200); Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); assertNotNull(node); assertEquals(user1, node.getArchivedByUser().getId()); @@ -117,7 +119,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest assertNull("Path should be null because its parent has been deleted",path); assertNull("We don't show the parent id for a deleted node",node.getParentId()); - response = getSingle(URL_DELETED_NODES, user1, createdFolder.getId(), params, 200); + response = getSingle(URL_DELETED_NODES, createdFolder.getId(), params, 200); Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class); assertNotNull(fNode); assertEquals(user1, fNode.getArchivedByUser().getId()); @@ -128,7 +130,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest assertTrue(path.getIsComplete()); assertNull("We don't show the parent id for a deleted node",fNode.getParentId()); - response = getSingle(URL_DELETED_NODES, user1, createdFolderNonSite.getId(), params, 200); + response = getSingle(URL_DELETED_NODES, createdFolderNonSite.getId(), params, 200); fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class); assertNotNull(fNode); assertEquals(user1, fNode.getArchivedByUser().getId()); @@ -142,10 +144,13 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest checkDeletedNodes(now, createdFolder, createdFolderNonSite, document, nodes); //User 2 can't get it but user 1 can. - getSingle(URL_DELETED_NODES, user2, createdFolderNonSite.getId(), Status.STATUS_FORBIDDEN); + setRequestContext(user2); + getSingle(URL_DELETED_NODES, createdFolderNonSite.getId(), Status.STATUS_FORBIDDEN); + setRequestContext(user1); + //Invalid node ref - getSingle(URL_DELETED_NODES, user1, "iddontexist", 404); + getSingle(URL_DELETED_NODES, "iddontexist", 404); //Now as admin setRequestContext("admin"); @@ -182,24 +187,26 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest Document documentSameName = createEmptyTextFile(createdFolder, "restoreme.txt"); //Can't restore a node of the same name - post(URL_DELETED_NODES+"/"+document.getId()+"/restore", user1, null, null, Status.STATUS_CONFLICT); + post(URL_DELETED_NODES+"/"+document.getId()+"/restore", null, null, Status.STATUS_CONFLICT); deleteNode(documentSameName.getId()); //Now we can restore it. - post(URL_DELETED_NODES+"/"+document.getId()+"/restore", user1, null, null, 200); + post(URL_DELETED_NODES+"/"+document.getId()+"/restore", null, null, 200); deleteNode(createdFolder.getId()); //We deleted the parent folder so lets see if we can restore a child doc, hopefully not. - post(URL_DELETED_NODES+"/"+documentSameName.getId()+"/restore", user1, null, null, Status.STATUS_NOT_FOUND); + post(URL_DELETED_NODES+"/"+documentSameName.getId()+"/restore", null, null, Status.STATUS_NOT_FOUND); //Can't delete "nonsense" noderef - post("deleted-nodes/nonsense/restore", user1, null, null, Status.STATUS_NOT_FOUND); + post("deleted-nodes/nonsense/restore", null, null, Status.STATUS_NOT_FOUND); //User 2 can't restore it but user 1 can. - post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", user2, null, null, Status.STATUS_FORBIDDEN); - post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", user1, null, null, 200); + setRequestContext(user2); + post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", null, null, Status.STATUS_FORBIDDEN); + setRequestContext(user1); + post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", null, null, 200); } /** @@ -219,21 +226,24 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest deleteNode(createdFolder.getId()); - HttpResponse response = getSingle(URL_DELETED_NODES, user1, createdFolder.getId(), 200); + HttpResponse response = getSingle(URL_DELETED_NODES, createdFolder.getId(), 200); Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class); assertNotNull(fNode); //try purging "nonsense" - delete(URL_DELETED_NODES, user1, "nonsense", 404); + delete(URL_DELETED_NODES, "nonsense", 404); //User 2 can't do it - delete(URL_DELETED_NODES, user2, createdFolder.getId(), Status.STATUS_FORBIDDEN); + setRequestContext(user2); + delete(URL_DELETED_NODES, createdFolder.getId(), Status.STATUS_FORBIDDEN); + + setRequestContext(user1); //Now purge the folder - delete(URL_DELETED_NODES, user1, createdFolder.getId(), 204); + delete(URL_DELETED_NODES, createdFolder.getId(), 204); //This time we can't find it. - getSingle(URL_DELETED_NODES, user1, createdFolder.getId(), 404); + getSingle(URL_DELETED_NODES, createdFolder.getId(), 404); } /** diff --git a/source/test-java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/source/test-java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index cd948de183..f4c3b53701 100644 --- a/source/test-java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -74,7 +74,11 @@ import java.util.List; import java.util.Map; /** - * Generic methods for calling the Api, taken from BaseCustomModelApiTest + * Generic methods for calling the Api (originally taken and adapted from BaseCustomModelApiTest) + * + * @author Jamal Kaabi-Mofrad + * @author janv + * @author gethin */ public abstract class AbstractBaseApiTest extends EnterpriseTestApi { @@ -191,21 +195,19 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi */ public abstract String getScope(); - protected HttpResponse post(String url, String runAsUser, String body, int expectedStatus) throws Exception + protected HttpResponse post(String url, String body, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); - HttpResponse response = publicApiClient.post(getScope(), url, null, null, null, body); checkStatus(expectedStatus, response.getStatusCode()); return response; } - protected HttpResponse post(String url, String runAsUser, String body, Map params, Map headers, String apiName, int expectedStatus) throws Exception + protected HttpResponse post(String url, String body, Map params, Map headers, String apiName, int expectedStatus) throws Exception { RequestBuilder requestBuilder = httpClient.new PostRequestBuilder() .setBodyAsString(body) - .setRequestContext(new RequestContext(runAsUser)) + .setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) .setEntityCollectionName(url) @@ -217,9 +219,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse post(String url, String runAsUser, String body, String queryString, int expectedStatus) throws Exception + protected HttpResponse post(String url, String body, String queryString, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); if (queryString != null) { url += queryString; @@ -230,9 +231,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse post(String url, String runAsUser, String body, String queryString, String contentType, int expectedStatus) throws Exception + protected HttpResponse post(String url, String body, String queryString, String contentType, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); if (queryString != null) { url += queryString; @@ -243,9 +243,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse post(String url, String runAsUser, byte[] body, String queryString, String contentType, int expectedStatus) throws Exception + protected HttpResponse post(String url, byte[] body, String queryString, String contentType, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); if (queryString != null) { url += queryString; @@ -256,23 +255,21 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse post(String runAsUser, String entityCollectionName, String entityId, String relationCollectionName, byte[] body, String queryString, String contentType, int expectedStatus) throws Exception + protected HttpResponse post(String entityCollectionName, String entityId, String relationCollectionName, byte[] body, String queryString, String contentType, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); HttpResponse response = publicApiClient.post(getScope(), entityCollectionName, entityId, relationCollectionName, null, body, contentType); checkStatus(expectedStatus, response.getStatusCode()); return response; } - protected HttpResponse getAll(String url, String runAsUser, PublicApiClient.Paging paging, int expectedStatus) throws Exception + protected HttpResponse getAll(String url, PublicApiClient.Paging paging, int expectedStatus) throws Exception { - return getAll(url, runAsUser, paging, null, expectedStatus); + return getAll(url, paging, null, expectedStatus); } - protected HttpResponse getAll(String url, String runAsUser, PublicApiClient.Paging paging, Map otherParams, int expectedStatus) throws Exception + protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); Map params = createParams(paging, otherParams); HttpResponse response = publicApiClient.get(getScope(), url, null, null, null, params); @@ -281,26 +278,24 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse getAll(Class entityResource, String runAsUser, PublicApiClient.Paging paging, Map otherParams, int expectedStatus) throws Exception + protected HttpResponse getAll(Class entityResource, PublicApiClient.Paging paging, Map otherParams, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); - HttpResponse response = publicApiClient.get(entityResource, null, null, otherParams); checkStatus(expectedStatus, response.getStatusCode()); return response; } - protected HttpResponse getAll(String url, String runAsUser, PublicApiClient.Paging paging, Map otherParams, Map headers, int expectedStatus) throws Exception + protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, Map headers, int expectedStatus) throws Exception { - return getAll(url, runAsUser, paging, otherParams, headers, null, expectedStatus); + return getAll(url, paging, otherParams, headers, null, expectedStatus); } - protected HttpResponse getAll(String url, String runAsUser, PublicApiClient.Paging paging, Map otherParams, Map headers, String apiName, int expectedStatus) throws Exception + protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, Map headers, String apiName, int expectedStatus) throws Exception { Map params = createParams(paging, otherParams); RequestBuilder requestBuilder = httpClient.new GetRequestBuilder() - .setRequestContext(new RequestContext(runAsUser)) + .setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) .setEntityCollectionName(url) @@ -312,41 +307,37 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - - protected HttpResponse getSingle(String url, String runAsUser, String entityId, int expectedStatus) throws Exception + + protected HttpResponse getSingle(String url, String entityId, int expectedStatus) throws Exception { - return getSingle(url, runAsUser, entityId, null, expectedStatus); + return getSingle(url, entityId, null, expectedStatus); } - protected HttpResponse getSingle(String url, String runAsUser, String entityId, Map params, int expectedStatus) throws Exception + protected HttpResponse getSingle(String url, String entityId, Map params, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); - HttpResponse response = publicApiClient.get(getScope(), url, entityId, null, null, params); checkStatus(expectedStatus, response.getStatusCode()); return response; } - protected HttpResponse getSingle(Class entityResource, String runAsUser, String entityId, Map params, int expectedStatus) throws Exception + protected HttpResponse getSingle(Class entityResource, String entityId, Map params, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); - HttpResponse response = publicApiClient.get(entityResource, entityId, null, params); checkStatus(expectedStatus, response.getStatusCode()); return response; } - protected HttpResponse getSingle(String url, String runAsUser, String entityId, Map params, Map headers, int expectedStatus) throws Exception + protected HttpResponse getSingle(String url, String entityId, Map params, Map headers, int expectedStatus) throws Exception { - return getSingle(url, runAsUser, entityId, params, headers, null, expectedStatus); + return getSingle(url, entityId, params, headers, null, expectedStatus); } - protected HttpResponse getSingle(String url, String runAsUser, String entityId, Map params, Map headers, String apiName, int expectedStatus) throws Exception + protected HttpResponse getSingle(String url, String entityId, Map params, Map headers, String apiName, int expectedStatus) throws Exception { RequestBuilder requestBuilder = httpClient.new GetRequestBuilder() - .setRequestContext(new RequestContext(runAsUser)) + .setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) .setEntityCollectionName(url) @@ -360,7 +351,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse getSingleWithDelayRetry(String url, String runAsUser, String entityId, Map params, + protected HttpResponse getSingleWithDelayRetry(String url, String entityId, Map params, Map headers, int repeat, long pauseInMillisecond, int expectedStatus) throws Exception { int retryCount = 0; @@ -368,7 +359,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi { try { - return getSingle(url, runAsUser, entityId, params, headers, expectedStatus); + return getSingle(url, entityId, params, headers, expectedStatus); } catch (AssertionError ex) { @@ -379,9 +370,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return null; } - protected HttpResponse put(String url, String runAsUser, String entityId, String body, String queryString, int expectedStatus) throws Exception + protected HttpResponse put(String url, String entityId, String body, String queryString, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); if (queryString != null) { entityId += queryString; @@ -392,10 +382,9 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse putBinary(String url, int version, String runAsUser, BinaryPayload payload, String queryString, Map params, + protected HttpResponse putBinary(String url, int version, BinaryPayload payload, String queryString, Map params, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); if (queryString != null) { url += queryString; @@ -407,31 +396,29 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi return response; } - protected HttpResponse putBinary(String url, String runAsUser, BinaryPayload payload, String queryString, Map params, + protected HttpResponse putBinary(String url, BinaryPayload payload, String queryString, Map params, int expectedStatus) throws Exception { - return putBinary(url, 1, runAsUser, payload, queryString, params, expectedStatus); + return putBinary(url, 1, payload, queryString, params, expectedStatus); } - protected HttpResponse delete(String url, String runAsUser, String entityId, int expectedStatus) throws Exception + protected HttpResponse delete(String url, String entityId, int expectedStatus) throws Exception { - return delete(url, runAsUser, entityId, null, expectedStatus); + return delete(url, entityId, null, expectedStatus); } - protected HttpResponse delete(String url, String runAsUser, String entityId, Map params, int expectedStatus) throws Exception + protected HttpResponse delete(String url, String entityId, Map params, int expectedStatus) throws Exception { - publicApiClient.setRequestContext(new RequestContext(runAsUser)); - HttpResponse response = publicApiClient.delete(getScope(), 1, url, entityId, null, null, params); checkStatus(expectedStatus, response.getStatusCode()); return response; } - protected HttpResponse delete(String url, String runAsUser, String entityId, Map params, Map headers, String apiName, int expectedStatus) throws Exception + protected HttpResponse delete(String url, String entityId, Map params, Map headers, String apiName, int expectedStatus) throws Exception { RequestBuilder requestBuilder = httpClient.new DeleteRequestBuilder() - .setRequestContext(new RequestContext(runAsUser)) + .setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) .setEntityCollectionName(url) @@ -558,7 +545,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi // -root- (eg. Company Home for on-prem) protected String getRootNodeId() throws Exception { - HttpResponse response = getSingle(NodesEntityResource.class, publicApiClient.getRequestContext().getRunAsUser(), Nodes.PATH_ROOT, null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, null, 200); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); return node.getId(); } @@ -566,7 +553,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi // -my- (eg. User's Home for on-prem) protected String getMyNodeId() throws Exception { - HttpResponse response = getSingle(NodesEntityResource.class, publicApiClient.getRequestContext().getRunAsUser(), Nodes.PATH_MY, null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); return node.getId(); } @@ -574,7 +561,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi // -shared- (eg. "Shared" folder for on-prem) protected String getSharedNodeId() throws Exception { - HttpResponse response = getSingle(NodesEntityResource.class, publicApiClient.getRequestContext().getRunAsUser(), Nodes.PATH_SHARED, null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_SHARED, null, 200); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); return node.getId(); } @@ -603,7 +590,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi n.setProperties(props); // create node - HttpResponse response = post(getNodeChildrenUrl(parentId), publicApiClient.getRequestContext().getRunAsUser(), RestApiUtil.toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getNodeChildrenUrl(parentId), RestApiUtil.toJsonAsStringNonNull(n), 201); return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), returnType); } @@ -626,7 +613,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi params = Collections.singletonMap("permanent", "true"); } - delete(URL_NODES, publicApiClient.getRequestContext().getRunAsUser(), nodeId, params, expectedStatus); + delete(URL_NODES, nodeId, params, expectedStatus); } protected Document createTextFile(String parentId, String fileName, String textContent) throws IOException, Exception @@ -655,7 +642,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi .setProperties(props) .build(); - HttpResponse response = post(getNodeChildrenUrl(parentId), publicApiClient.getRequestContext().getRunAsUser(), reqBody.getBody(), null, reqBody.getContentType(), expectedStatus); + HttpResponse response = post(getNodeChildrenUrl(parentId), reqBody.getBody(), null, reqBody.getContentType(), expectedStatus); if (response.getJsonResponse().get("error") != null) { @@ -675,7 +662,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi d1.setContent(ci); // create empty file - HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), publicApiClient.getRequestContext().getRunAsUser(), toJsonAsStringNonNull(d1), 201); + HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), toJsonAsStringNonNull(d1), 201); return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); } @@ -685,7 +672,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); BinaryPayload payload = new BinaryPayload(txtFile); - HttpResponse response = putBinary(getNodeContentUrl(contentId), publicApiClient.getRequestContext().getRunAsUser(), payload, null, parameters, 200); + HttpResponse response = putBinary(getNodeContentUrl(contentId), payload, null, parameters, 200); return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); } @@ -709,7 +696,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi { try { - HttpResponse response = getSingle(getNodeRenditionsUrl(sourceNodeId), publicApiClient.getRequestContext().getRunAsUser(), renditionId, 200); + HttpResponse response = getSingle(getNodeRenditionsUrl(sourceNodeId), renditionId, 200); Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class); assertNotNull(rendition); assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus()); @@ -739,7 +726,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi { try { - HttpResponse res = post(getNodeRenditionsUrl(sourceNodeId), publicApiClient.getRequestContext().getRunAsUser(), toJsonAsString(renditionRequest), 202); + HttpResponse res = post(getNodeRenditionsUrl(sourceNodeId), toJsonAsString(renditionRequest), 202); assertNull(res.getJsonResponse()); break; } diff --git a/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java b/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java index 6e7d3e0494..ecb84d20bf 100644 --- a/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java @@ -46,6 +46,8 @@ import java.util.List; import java.util.Map; /** + * V1 REST API test for posting Activities + * * Tests posting activities from the public api. * * @author gethin @@ -71,10 +73,10 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest //Update the file Document dUpdate = new Document(); dUpdate.setName("d1b.txt"); - put(URL_NODES, user1, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200); + put(URL_NODES, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200); //Now download it - HttpResponse response = getSingle(NodesEntityResource.class, user1, documentResp.getId()+"/content", null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, documentResp.getId()+"/content", null, 200); String textContent = response.getResponse(); assertNotNull(textContent); @@ -146,7 +148,7 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest //Update the file Document dUpdate = new Document(); dUpdate.setName("nonsite_d2.txt"); - put(URL_NODES, user1, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200); + put(URL_NODES, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200); List activitiesAgain = getMyActivities(); assertEquals("No activites should be created for non-site nodes", activities, activitiesAgain); diff --git a/source/test-java/org/alfresco/rest/api/tests/ApiTest.java b/source/test-java/org/alfresco/rest/api/tests/ApiTest.java index 4365514aa8..d8c5f21813 100644 --- a/source/test-java/org/alfresco/rest/api/tests/ApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/ApiTest.java @@ -41,6 +41,7 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ + NodeApiTest.class, NodeAssociationsApiTest.class, NodeVersionsApiTest.class, @@ -50,6 +51,7 @@ import org.junit.runners.Suite; ActivitiesPostingTest.class, DeletedNodesTest.class, AuthenticationsTest.class, + ModulePackagesApiTest.class, TestSites.class, TestNodeComments.class, TestCMIS.class, @@ -67,8 +69,7 @@ import org.junit.runners.Suite; TestFavourites.class, TestRemovePermissions.class, TestPublicApi128.class, - TestPublicApiCaching.class, - ModulePackagesApiTest.class + TestPublicApiCaching.class }) public class ApiTest { diff --git a/source/test-java/org/alfresco/rest/api/tests/AuthenticationsTest.java b/source/test-java/org/alfresco/rest/api/tests/AuthenticationsTest.java index ba537678d0..8836b037da 100644 --- a/source/test-java/org/alfresco/rest/api/tests/AuthenticationsTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/AuthenticationsTest.java @@ -45,7 +45,7 @@ import java.util.List; import java.util.Map; /** - * Authentication tickets API tests. + * V1 REST API tests for authentication Tickets * * @author Jamal Kaabi-Mofrad */ @@ -71,9 +71,11 @@ public class AuthenticationsTest extends AbstractBaseApiTest public void testCreateValidateDeleteTicket() throws Exception { Paging paging = getPaging(0, 100); + + setRequestContext(null); // Unauthorized call - getAll(SiteEntityResource.class, null, paging, null, 401); + getAll(SiteEntityResource.class, paging, null, 401); /* * user1 login - via alf_ticket parameter @@ -82,22 +84,22 @@ public class AuthenticationsTest extends AbstractBaseApiTest // User1 login request LoginTicket loginRequest = new LoginTicket(); // Invalid login details - post(TICKETS_URL, null, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400); + post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400); loginRequest.setUserId(null); loginRequest.setPassword("user1Password"); // Invalid login details - post(TICKETS_URL, null, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400); + post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400); loginRequest.setUserId(user1); loginRequest.setPassword(null); // Invalid login details - post(TICKETS_URL, null, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400); + post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400); loginRequest.setUserId(user1); loginRequest.setPassword("user1Password"); // Authenticate and create a ticket - HttpResponse response = post(TICKETS_URL, null, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 201); + HttpResponse response = post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 201); LoginTicketResponse loginResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class); assertNotNull(loginResponse.getId()); assertNotNull(loginResponse.getUserId()); @@ -105,35 +107,40 @@ public class AuthenticationsTest extends AbstractBaseApiTest // Get list of sites by appending the alf_ticket to the URL // e.g. .../alfresco/versions/1/sites/?alf_ticket=TICKET_57866258ea56c28491bb3e75d8355ebf6fbaaa23 Map ticket = Collections.singletonMap("alf_ticket", loginResponse.getId()); - getAll(SiteEntityResource.class, null, paging, ticket, 200); + getAll(SiteEntityResource.class, paging, ticket, 200); // Unauthorized - Invalid ticket - getAll(SiteEntityResource.class, null, paging, Collections.singletonMap("alf_ticket", "TICKET_" + System.currentTimeMillis()), 401); + getAll(SiteEntityResource.class, paging, Collections.singletonMap("alf_ticket", "TICKET_" + System.currentTimeMillis()), 401); // Validate ticket - Invalid parameter. Only '-me-' is supported - getSingle(TICKETS_URL, null, loginResponse.getId(), ticket, null, TICKETS_API_NAME, 400); + getSingle(TICKETS_URL, loginResponse.getId(), ticket, null, TICKETS_API_NAME, 400); // Validate ticket - response = getSingle(TICKETS_URL, null, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 200); + response = getSingle(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 200); LoginTicketResponse validatedTicket = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class); assertEquals(loginResponse.getId(), validatedTicket.getId()); // Validate ticket - Invalid parameter. Only '-me-' is supported - getSingle(TICKETS_URL, null, loginResponse.getId(), ticket, null, TICKETS_API_NAME, 400); + getSingle(TICKETS_URL, loginResponse.getId(), ticket, null, TICKETS_API_NAME, 400); // Delete the ticket - Logout - delete(TICKETS_URL, null, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 204); + delete(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 204); // Validate ticket - 401 as ticket has been invalidated so the API call is unauthorized - getSingle(TICKETS_URL, null, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 401); + getSingle(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 401); + + setRequestContext(user1); + // Check the ticket has been invalidated - the difference with the above is that the API call is authorized - getSingle(TICKETS_URL, user1, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 404); + getSingle(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 404); // Ticket has already been invalidated - delete(TICKETS_URL, user1, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 404); + delete(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 404); + + setRequestContext(null); // Get list of site by appending the invalidated ticket - getAll(SiteEntityResource.class, null, paging, ticket, 401); + getAll(SiteEntityResource.class, paging, ticket, 401); /* @@ -146,25 +153,27 @@ public class AuthenticationsTest extends AbstractBaseApiTest Folder folderResp = createFolder(Nodes.PATH_MY, "F2", null); assertNotNull(folderResp.getId()); - getAll(getNodeChildrenUrl(Nodes.PATH_MY), null, paging, 401); + setRequestContext(null); + + getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 401); // User2 login request loginRequest = new LoginTicket(); loginRequest.setUserId(user2); loginRequest.setPassword("wrongPassword"); // Authentication failed - wrong password - post(TICKETS_URL, null, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403); + post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403); loginRequest.setUserId(user1); loginRequest.setPassword("user2Password"); // Authentication failed - userId/password mismatch - post(TICKETS_URL, null, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403); + post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403); // Set the correct details loginRequest.setUserId(user2); loginRequest.setPassword("user2Password"); // Authenticate and create a ticket - response = post(TICKETS_URL, null, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 201); + response = post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 201); loginResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class); assertNotNull(loginResponse.getId()); assertNotNull(loginResponse.getUserId()); @@ -173,15 +182,15 @@ public class AuthenticationsTest extends AbstractBaseApiTest // Set the authorization (encoded ticket only) header rather than appending the ticket to the URL Map header = Collections.singletonMap("Authorization", "Basic " + encodedTicket); // Get children of user2 home folder - response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), null, paging, null, header, 200); + response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(1, nodes.size()); // Validate ticket - Invalid parameter. Only '-me-' is supported - getSingle(TICKETS_URL, null, loginResponse.getId(), null, header, TICKETS_API_NAME, 400); + getSingle(TICKETS_URL, loginResponse.getId(), null, header, TICKETS_API_NAME, 400); // Validate ticket - user2 - response = getSingle(TICKETS_URL, null, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 200); + response = getSingle(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 200); validatedTicket = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class); assertEquals(loginResponse.getId(), validatedTicket.getId()); @@ -191,28 +200,32 @@ public class AuthenticationsTest extends AbstractBaseApiTest // Set the authorization (encoded userId:ticket) header rather than appending the ticket to the URL header = Collections.singletonMap("Authorization", "Basic " + encodedUserIdAndTicket); // Get children of user2 home folder - response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), null, paging, null, header, 200); + response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(1, nodes.size()); // Try list children for user2 again - appending ticket ticket = Collections.singletonMap("alf_ticket", loginResponse.getId()); - response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), null, paging, ticket, 200); + response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, ticket, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(1, nodes.size()); + setRequestContext(user2); + // Try to validate the ticket without supplying the Authorization header or the alf_ticket param - getSingle(TICKETS_URL, user2, People.DEFAULT_USER, null, null, TICKETS_API_NAME, 400); + getSingle(TICKETS_URL, People.DEFAULT_USER, null, null, TICKETS_API_NAME, 400); + + setRequestContext(null); // Delete the ticket - Invalid parameter. Only '-me-' is supported header = Collections.singletonMap("Authorization", "Basic " + encodedUserIdAndTicket); - delete(TICKETS_URL, null, loginResponse.getId(), null, header, TICKETS_API_NAME, 400); + delete(TICKETS_URL, loginResponse.getId(), null, header, TICKETS_API_NAME, 400); // Delete the ticket - Logout - delete(TICKETS_URL, null, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 204); + delete(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 204); // Get children of user2 home folder - invalidated ticket - getAll(getNodeChildrenUrl(Nodes.PATH_MY), null, paging, null, header, 401); + getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 401); } private String encodeB64(String str) diff --git a/source/test-java/org/alfresco/rest/api/tests/BaseCustomModelApiTest.java b/source/test-java/org/alfresco/rest/api/tests/BaseCustomModelApiTest.java index 50cf4f76de..0f1865afe1 100644 --- a/source/test-java/org/alfresco/rest/api/tests/BaseCustomModelApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/BaseCustomModelApiTest.java @@ -142,9 +142,9 @@ public class BaseCustomModelApiTest extends AbstractBaseApiTest customModel.setDescription(desc); customModel.setStatus(status); customModel.setAuthor(author); - + // Create the model as a Model Administrator - HttpResponse response = post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 201); + HttpResponse response = post("cmm", RestApiUtil.toJsonAsString(customModel), 201); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); if (author == null) { @@ -181,7 +181,7 @@ public class BaseCustomModelApiTest extends AbstractBaseApiTest classModel.setParentName(parent); // Create type as a Model Administrator - HttpResponse response = post(uri, customModelAdmin, RestApiUtil.toJsonAsString(classModel), 201); + HttpResponse response = post(uri, RestApiUtil.toJsonAsString(classModel), 201); T returnedClassModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), glazz); compareCustomTypesAspects(classModel, returnedClassModel, "prefixedName"); diff --git a/source/test-java/org/alfresco/rest/api/tests/ModulePackagesApiTest.java b/source/test-java/org/alfresco/rest/api/tests/ModulePackagesApiTest.java index 0a5b7abdbd..1c7bc960da 100644 --- a/source/test-java/org/alfresco/rest/api/tests/ModulePackagesApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/ModulePackagesApiTest.java @@ -36,7 +36,6 @@ import static org.junit.Assert.assertTrue; import org.alfresco.rest.api.model.ModulePackage; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; -import org.alfresco.rest.api.tests.client.RequestContext; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PersonService; @@ -50,6 +49,7 @@ import java.util.Map; /** * Basic modulepackages api calls + * * @author Gethin James. */ public class ModulePackagesApiTest extends AbstractBaseApiTest @@ -78,7 +78,9 @@ public class ModulePackagesApiTest extends AbstractBaseApiTest @Test public void testAllModulePackages() throws Exception { - HttpResponse response = getAll(MODULEPACKAGES, nonAdminUserName, null, HttpStatus.SC_OK); + setRequestContext(nonAdminUserName); + + HttpResponse response = getAll(MODULEPACKAGES, null, HttpStatus.SC_OK); assertNotNull(response); PublicApiClient.ExpectedPaging paging = parsePaging(response.getJsonResponse()); @@ -96,10 +98,12 @@ public class ModulePackagesApiTest extends AbstractBaseApiTest @Test public void testSingleModulePackage() throws Exception { - HttpResponse response = getSingle(MODULEPACKAGES, nonAdminUserName, "NonSENSE_NOTFOUND", HttpStatus.SC_NOT_FOUND); + setRequestContext(nonAdminUserName); + + HttpResponse response = getSingle(MODULEPACKAGES, "NonSENSE_NOTFOUND", HttpStatus.SC_NOT_FOUND); assertNotNull(response); - response = getSingle(MODULEPACKAGES, nonAdminUserName, "alfresco-simple-module", HttpStatus.SC_OK); + response = getSingle(MODULEPACKAGES, "alfresco-simple-module", HttpStatus.SC_OK); assertNotNull(response); ModulePackage simpleModule = parseRestApiEntry(response.getJsonResponse(),ModulePackage.class); @@ -111,7 +115,8 @@ public class ModulePackagesApiTest extends AbstractBaseApiTest @Test public void testErrorUrls() throws Exception { - publicApiClient.setRequestContext(new RequestContext(null)); + setRequestContext(null); + Map params = createParams(null, null); //Call an endpoint that doesn't exist 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 6c6da63abf..fb5d3899c6 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -89,7 +89,8 @@ import java.util.Set; import java.util.UUID; /** - * API tests for: + * V1 REST API tests for Nodes (files, folders and custom node types) + * *
    *
  • {@literal :/alfresco/api//public/alfresco/versions/1/nodes/}
  • *
  • {@literal :/alfresco/api//public/alfresco/versions/1/nodes//children}
  • @@ -98,7 +99,7 @@ import java.util.UUID; * TODO * - improve test 'fwk' to enable api tests to be run against remote repo (rather than embedded jetty) * - requires replacement of remaining non-remote calls with remote (preferably public) apis - * - eg. createUser (or any other usage of repoService), permissionService, ... + * - eg. createUser (or any other usage of repoService), permissionService, AuthentictionUtil, ... * * @author Jamal Kaabi-Mofrad * @author janv @@ -152,7 +153,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest createNode(tDocLibNodeId, forum1, "fm:topic", null); Paging paging = getPaging(0, 100); - HttpResponse response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, 200); + HttpResponse response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(4, nodes.size()); // forum is part of the default ignored types // Paging @@ -164,7 +165,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // Order by folders and modified date first Map orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC"); - response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200); + response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(4, nodes.size()); assertEquals(folder2, nodes.get(0).getName()); @@ -182,7 +183,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // Order by folders last and modified date first orderBy = Collections.singletonMap("orderBy", "isFolder ASC,modifiedAt DESC"); - response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200); + response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(4, nodes.size()); assertEquals(content2, nodes.get(0).getName()); @@ -192,7 +193,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // Order by folders and modified date last orderBy = Collections.singletonMap("orderBy", "isFolder,modifiedAt"); - response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200); + response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(4, nodes.size()); assertEquals(content1, nodes.get(0).getName()); @@ -205,7 +206,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // SkipCount=0,MaxItems=2 paging = getPaging(0, 2); - response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200); + response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); assertEquals(folder2, nodes.get(0).getName()); @@ -218,7 +219,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // SkipCount=null,MaxItems=2 paging = getPaging(null, 2); - response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200); + response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); assertEquals(folder2, nodes.get(0).getName()); @@ -231,7 +232,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // SkipCount=2,MaxItems=4 paging = getPaging(2, 4); - response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200); + response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); assertEquals(content2, nodes.get(0).getName()); @@ -245,7 +246,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // SkipCount=2,MaxItems=null paging = getPaging(2, null); - response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200); + response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); assertEquals(content2, nodes.get(0).getName()); @@ -260,18 +261,18 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // user2 tries to access user1's docLib paging = getPaging(0, Integer.MAX_VALUE); - getAll(getNodeChildrenUrl(tDocLibNodeId), user2, paging, 403); + getAll(getNodeChildrenUrl(tDocLibNodeId), paging, 403); setRequestContext(user1); // -ve test - paging (via list children) cannot have skipCount < 0 paging = getPaging(-1, 4); - getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 400); + getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 400); // -ve test - paging (via list children) cannot have maxItems < 1 paging = getPaging(0, 0); - getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 400); + getAll(getNodeChildrenUrl(tDocLibNodeId), paging, orderBy, 400); } /** @@ -314,20 +315,20 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Node nodeUpdate = new Node(); nodeUpdate.setProperties(props); - put(URL_NODES, user1, content1_Id, toJsonAsStringNonNull(nodeUpdate), null, 200); + put(URL_NODES, content1_Id, toJsonAsStringNonNull(nodeUpdate), null, 200); List folderIds = Arrays.asList(folder1_Id, folder2_Id); List contentIds = Arrays.asList(content1_Id); Paging paging = getPaging(0, Integer.MAX_VALUE); - HttpResponse response = getAll(myChildrenUrl, user1, paging, 200); + HttpResponse response = getAll(myChildrenUrl, paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(3, nodes.size()); // Order by folders and modified date first Map orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC"); - response = getAll(myChildrenUrl, user1, paging, orderBy, 200); + response = getAll(myChildrenUrl, paging, orderBy, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(3, nodes.size()); assertEquals(folder2, nodes.get(0).getName()); @@ -349,7 +350,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // request without "include" Map params = new HashMap<>(); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); for (Node n : nodes) { @@ -362,7 +363,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // request with include - example 1 params = new HashMap<>(); params.put("include", "isLink"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); for (Node n : nodes) { @@ -372,7 +373,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // request with include - example 2 params = new HashMap<>(); params.put("include", "aspectNames,properties,path,isLink"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); for (Node n : nodes) { @@ -386,7 +387,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("include", "cm:lastThumbnailModification"); params.put("orderBy", "isFolder DESC,modifiedAt DESC"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(3, nodes.size()); assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(0).getProperties()); @@ -402,7 +403,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // filtering, via where clause - folders only params = new HashMap<>(); params.put("where", "("+Nodes.PARAM_ISFOLDER+"=true)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(2, nodes.size()); @@ -417,7 +418,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // filtering, via where clause - content only params = new HashMap<>(); params.put("where", "("+Nodes.PARAM_ISFILE+"=true)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); assertEquals(1, nodes.size()); assertFalse(nodes.get(0).getIsFolder()); @@ -427,7 +428,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // list children via relativePath params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folder1); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); JSONObject jsonResponse = response.getJsonResponse(); nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class); assertEquals(1, nodes.size()); @@ -439,7 +440,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertNull(jsonSrcObj); params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder2); - response = getAll(rootChildrenUrl, user1, paging, params, 200); + response = getAll(rootChildrenUrl, paging, params, 200); jsonResponse = response.getJsonResponse(); nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class); assertEquals(1, nodes.size()); @@ -457,7 +458,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params.put("includeSource", "true"); params.put("include", "path,isLink"); params.put("fields", "id"); - response = getAll(rootChildrenUrl, user1, paging, params, 200); + response = getAll(rootChildrenUrl, paging, params, 200); jsonResponse = response.getJsonResponse(); nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class); assertEquals(1, nodes.size()); @@ -481,28 +482,30 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // -ve test - Invalid QName (Namespace prefix cm... is not mapped to a namespace URI) for the orderBy parameter. params = Collections.singletonMap("orderBy", Nodes.PARAM_ISFOLDER+" DESC,cm" + System.currentTimeMillis() + ":modified DESC"); - getAll(myChildrenUrl, user1, paging, params, 400); + getAll(myChildrenUrl, paging, params, 400); paging = getPaging(0, 10); // -ve test - list folder children for unknown node should return 404 - getAll(getNodeChildrenUrl(UUID.randomUUID().toString()), user1, paging, 404); + getAll(getNodeChildrenUrl(UUID.randomUUID().toString()), paging, 404); // -ve test - user2 tries to access user1's home folder - AuthenticationUtil.setFullyAuthenticatedUser(user2); - getAll(getNodeChildrenUrl(myNodeId), user2, paging, 403); + setRequestContext(user2); + getAll(getNodeChildrenUrl(myNodeId), paging, 403); + + setRequestContext(user1); // -ve test - try to list children using relative path to unknown node params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/unknown"); - getAll(rootChildrenUrl, user1, paging, params, 404); + getAll(rootChildrenUrl, paging, params, 404); // -ve test - try to list children using relative path to node for which user does not have read permission (expect 404 instead of 403) params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user2); - getAll(rootChildrenUrl, user1, paging, params, 404); + getAll(rootChildrenUrl, paging, params, 404); // -ve test - list folder children with relative path to unknown node should return 400 params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown"); - getAll(getNodeChildrenUrl(content1_Id), user1, paging, params, 400); + getAll(getNodeChildrenUrl(content1_Id), paging, params, 400); } /** @@ -546,7 +549,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest //...nodes/nodeId?include=path Map params = Collections.singletonMap("include", "path"); - HttpResponse response = getSingle(NodesEntityResource.class, user1, content1_Id, params, 200); + HttpResponse response = getSingle(NodesEntityResource.class, content1_Id, params, 200); Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); PathInfo path = node.getPath(); assertNotNull(path); @@ -568,8 +571,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // Try the above tests with user2 (site consumer) setRequestContext(user2); - AuthenticationUtil.setFullyAuthenticatedUser(user2); - response = getSingle(NodesEntityResource.class, user2, content1_Id, params, 200); + response = getSingle(NodesEntityResource.class, content1_Id, params, 200); node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); path = node.getPath(); assertNotNull(path); @@ -595,11 +597,11 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest { setRequestContext(user1); - HttpResponse response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_ROOT, null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, null, 200); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String rootNodeId = node.getId(); - response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, null, 200); + response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200); node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String myFilesNodeId = node.getId(); assertNotNull(myFilesNodeId); @@ -626,7 +628,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // get node info - response = getSingle(NodesEntityResource.class, user1, content1Id, null, 200); + response = getSingle(NodesEntityResource.class, content1Id, null, 200); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String content_Id = documentResp.getId(); @@ -663,7 +665,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // get node info + path //...nodes/nodeId?include=path Map params = Collections.singletonMap("include", "path"); - response = getSingle(NodesEntityResource.class, user1, content1Id, params, 200); + response = getSingle(NodesEntityResource.class, content1Id, params, 200); documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); // Expected path ... @@ -682,12 +684,12 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // get node info via relativePath params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/"+folderA+"/"+folderB); - response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, params, 200); + response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200); Folder folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderB_Id, folderResp.getId()); params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folderA+"/"+folderB+"/"+contentName); - response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, params, 200); + response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(content_Id, documentResp.getId()); @@ -696,28 +698,30 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String folderC_Id = createFolder(folderB_Id, folderC).getId(); params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/"+folderA+"/"+folderB+"/"+folderC); - response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, params, 200); + response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderC_Id, folderResp.getId()); // -ve test - get info for unknown node should return 404 - getSingle(NodesEntityResource.class, user1, UUID.randomUUID().toString(), null, 404); + getSingle(NodesEntityResource.class, UUID.randomUUID().toString(), null, 404); // -ve test - user2 tries to get node info about user1's home folder - AuthenticationUtil.setFullyAuthenticatedUser(user2); - getSingle(NodesEntityResource.class, user2, myFilesNodeId, null, 403); + setRequestContext(user2); + getSingle(NodesEntityResource.class, myFilesNodeId, null, 403); + + setRequestContext(user1); // -ve test - try to get node info using relative path to unknown node params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folderA+"/unknown"); - getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, params, 404); + getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 404); // -ve test - try to get node info using relative path to node for which user does not have read permission (expect 404 instead of 403) params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/"+user2); - getSingle(NodesEntityResource.class, user1, Nodes.PATH_ROOT, params, 404); + getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, params, 404); // -ve test - attempt to get node info for non-folder node with relative path should return 400 params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown"); - getSingle(NodesEntityResource.class, user1, content_Id, params, 400); + getSingle(NodesEntityResource.class, content_Id, params, 400); } /** @@ -734,16 +738,16 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest { setRequestContext(user1); - HttpResponse response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_ROOT, null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, null, 200); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals("Company Home", node.getName()); assertNotNull(node.getId()); assertNull(node.getPath()); // unknown alias - getSingle(NodesEntityResource.class, user1, "testSomeUndefinedAlias", null, 404); + getSingle(NodesEntityResource.class, "testSomeUndefinedAlias", null, 404); - response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, null, 200); + response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200); node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String myFilesNodeId = node.getId(); assertNotNull(myFilesNodeId); @@ -752,7 +756,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertFalse(node.getIsFile()); assertNull(node.getPath()); // note: path can be optionally "include"'ed - see separate test - response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_SHARED, null, 200); + response = getSingle(NodesEntityResource.class, Nodes.PATH_SHARED, null, 200); node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String sharedFilesNodeId = node.getId(); assertNotNull(sharedFilesNodeId); @@ -766,7 +770,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest deleteNode(myFilesNodeId); setRequestContext(user1); - getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, null, 404); // Not found + getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 404); // Not found } /** @@ -789,7 +793,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d.setName("my doc"); d.setNodeType(TYPE_CM_CONTENT); - HttpResponse response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(d), 201); + HttpResponse response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(d), 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(MimetypeMap.MIMETYPE_BINARY, documentResp.getContent().getMimeType()); assertEquals("Binary File (Octet Stream)", documentResp.getContent().getMimeTypeName()); @@ -800,7 +804,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d.setName("my doc.txt"); d.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(d), 201); + response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(d), 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, documentResp.getContent().getMimeType()); assertEquals("Plain Text", documentResp.getContent().getMimeTypeName()); @@ -811,7 +815,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d.setName("my doc.pdf"); d.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(d), 201); + response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(d), 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(MimetypeMap.MIMETYPE_PDF, documentResp.getContent().getMimeType()); assertEquals("Adobe PDF Document", documentResp.getContent().getMimeTypeName()); @@ -827,7 +831,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); MultiPartRequest reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); ContentInfo contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType()); @@ -840,7 +844,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData("quick-2", file)); // note: we've deliberately dropped the file ext here reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType()); @@ -853,7 +857,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); @@ -866,7 +870,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); @@ -879,7 +883,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); @@ -892,7 +896,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_XML, contentInfo.getMimeType()); @@ -905,7 +909,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_XML, contentInfo.getMimeType()); @@ -920,7 +924,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String docId = document.getId(); contentInfo = document.getContent(); @@ -931,7 +935,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Document dUpdate = new Document(); dUpdate.setName("quick.docx"); - response = put(URL_NODES, user1, docId, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, docId, toJsonAsStringNonNull(dUpdate), null, 200); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType()); @@ -941,7 +945,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest file = getResourceFile(fileName); BinaryPayload payload = new BinaryPayload(file); - response = putBinary(getNodeContentUrl(docId), user1, payload, null, null, 200); + response = putBinary(getNodeContentUrl(docId), payload, null, null, 200); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING, contentInfo.getMimeType()); @@ -955,7 +959,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData("special-"+GUID.generate(), file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(fId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(fId), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentInfo = document.getContent(); assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); @@ -979,7 +983,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest final File file = getResourceFile(fileName); Paging paging = getPaging(0, Integer.MAX_VALUE); - HttpResponse response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), user1, paging, 200); + HttpResponse response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 200); PublicApiClient.ExpectedPaging pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); final int numOfNodes = pagingResult.getCount(); @@ -989,10 +993,10 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest MultiPartRequest reqBody = multiPartBuilder.build(); // Try to upload into a non-existent folder - post(getNodeChildrenUrl(UUID.randomUUID().toString()), user1, reqBody.getBody(), null, reqBody.getContentType(), 404); + post(getNodeChildrenUrl(UUID.randomUUID().toString()), reqBody.getBody(), null, reqBody.getContentType(), 404); // Upload - response = post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName, document.getName()); @@ -1006,7 +1010,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertNull(document.getPath()); // Retrieve the uploaded file - response = getSingle(NodesEntityResource.class, user1, document.getId(), null, 200); + response = getSingle(NodesEntityResource.class, document.getId(), null, 200); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(fileName, document.getName()); contentInfo = document.getContent(); @@ -1014,15 +1018,15 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType()); // Check 'get children' is confirming the upload - response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), user1, paging, 200); + response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 200); pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); assertEquals(numOfNodes + 1, pagingResult.getCount().intValue()); // Upload the same file again to check the name conflicts handling - post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 409); + post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 409); - response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), user1, paging, 200); + response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 200); pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); assertEquals("Duplicate file name. The file shouldn't have been uploaded.", numOfNodes + 1, pagingResult.getCount().intValue()); @@ -1032,19 +1036,19 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setAutoRename(true) .build(); - response = post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals("quick-1.pdf", document.getName()); // upload the same file again, and request the path info to be present in the response - response = post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), "?include=path", reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), "?include=path", reqBody.getContentType(), 201); document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals("quick-2.pdf", document.getName()); assertNotNull(document.getPath()); - response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), user1, paging, 200); + response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 200); pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); assertEquals(numOfNodes + 3, pagingResult.getCount().intValue()); @@ -1055,7 +1059,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest reqBody = MultiPartBuilder.create() .setFileData(new FileData(null, file1)) .build(); - response = post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 201); document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName1, document.getName()); @@ -1068,33 +1072,39 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest reqBody = MultiPartBuilder.create() .setFileData(new FileData(fileName2b, file2)) .build(); - response = post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 201); document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName2b, document.getName()); assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, document.getContent().getMimeType()); + + response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200); + Folder user1Home = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); // User2 tries to upload a new file into the user1's home folder. - response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_MY, null, 200); - Folder user1Home = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); + + setRequestContext(user2); + final File file3 = getResourceFile(fileName2); reqBody = MultiPartBuilder.create() .setFileData(new FileData(fileName2, file3)) .build(); - post(getNodeChildrenUrl(user1Home.getId()), user2, reqBody.getBody(), null, reqBody.getContentType(), 403); + post(getNodeChildrenUrl(user1Home.getId()), reqBody.getBody(), null, reqBody.getContentType(), 403); - response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), user1, paging, 200); + setRequestContext(user1); + + response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 200); pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); assertEquals("Access Denied. The file shouldn't have been uploaded.", numOfNodes + 5, pagingResult.getCount().intValue()); // User1 tries to upload a file into a document rather than a folder! - post(getNodeChildrenUrl(document.getId()), user1, reqBody.getBody(), null, reqBody.getContentType(), 400); + post(getNodeChildrenUrl(document.getId()), reqBody.getBody(), null, reqBody.getContentType(), 400); // Try to upload a file without defining the required formData reqBody = MultiPartBuilder.create().setAutoRename(true).build(); - post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 400); + post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 400); // Test unsupported node type reqBody = MultiPartBuilder.create() @@ -1102,13 +1112,13 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setAutoRename(true) .setNodeType("cm:link") .build(); - post(getNodeChildrenUrl(user1Home.getId()), user1, reqBody.getBody(), null, reqBody.getContentType(), 400); + post(getNodeChildrenUrl(user1Home.getId()), reqBody.getBody(), null, reqBody.getContentType(), 400); // User1 uploads a new file reqBody = MultiPartBuilder.create() .setFileData(new FileData(fileName2, file2)) .build(); - response = post(getNodeChildrenUrl(user1Home.getId()), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(user1Home.getId()), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName2, document.getName()); @@ -1131,7 +1141,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .build(); // Try to upload a file larger than the configured size limit - post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 413); + post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 413); } finally { @@ -1156,7 +1166,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String folderA_id = createFolder(tDocLibNodeId, folderA).getId(); Paging paging = getPaging(0, Integer.MAX_VALUE); - HttpResponse response = getAll(getNodeChildrenUrl(folderA_id), user1, paging, 200); + HttpResponse response = getAll(getNodeChildrenUrl(folderA_id), paging, 200); PublicApiClient.ExpectedPaging pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); final int numOfNodes = pagingResult.getCount(); @@ -1165,7 +1175,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setFileData(new FileData(fileName, file)); MultiPartRequest reqBody = multiPartBuilder.build(); // Try to upload - response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName, document.getName()); @@ -1175,7 +1185,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); // Retrieve the uploaded file - response = getSingle(NodesEntityResource.class, user1, document.getId(), null, 200); + response = getSingle(NodesEntityResource.class, document.getId(), null, 200); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(fileName, document.getName()); contentInfo = document.getContent(); @@ -1183,29 +1193,33 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); // Check 'get children' is confirming the upload - response = getAll(getNodeChildrenUrl(folderA_id), user1, paging, 200); + response = getAll(getNodeChildrenUrl(folderA_id), paging, 200); pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); assertEquals(numOfNodes + 1, pagingResult.getCount().intValue()); // Upload the same file again to check the name conflicts handling - post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 409); + post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 409); - response = getAll(getNodeChildrenUrl(folderA_id), user1, paging, 200); + response = getAll(getNodeChildrenUrl(folderA_id), paging, 200); pagingResult = parsePaging(response.getJsonResponse()); assertNotNull(paging); assertEquals(numOfNodes + 1, pagingResult.getCount().intValue()); + setRequestContext(user2); + final String fileName2 = "quick-2.txt"; final File file2 = getResourceFile(fileName2); reqBody = MultiPartBuilder.create() .setFileData(new FileData(fileName2, file2)) .build(); // user2 tries to upload a new file into the folderA of user1 - post(getNodeChildrenUrl(folderA_id), user2, reqBody.getBody(), null, reqBody.getContentType(), 403); + post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 403); + setRequestContext(user1); + // Test upload with properties - response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName2, document.getName()); @@ -1226,7 +1240,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setProperties(props) .build(); - response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Check the upload response // "quick-2-1.txt" => fileName2 + autoRename @@ -1247,7 +1261,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setProperties(props) .build(); // Prop prefix is unknown - post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 400); + post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 400); // Test relativePath multi-part field. // Any folders in the relativePath that do not exist, are created before the content is created. @@ -1256,7 +1270,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setRelativePath("X/Y/Z"); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), "?include=path", reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), "?include=path", reqBody.getContentType(), 201); document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName, document.getName()); @@ -1280,7 +1294,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest reqBody = MultiPartBuilder.copy(multiPartBuilder) .setRelativePath("X/Y/Z/" + document.getName()) .build(); - post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 409); + post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 409); // Test the same functionality as "mkdir -p x/y/z" which the folders should be created // as needed but no errors thrown if the path or any part of the path already exists. @@ -1288,7 +1302,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest reqBody = MultiPartBuilder.copy(multiPartBuilder) .setRelativePath("/X/ Y/Z /CoolFolder/") .build(); - response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals(fileName, document.getName()); @@ -1297,7 +1311,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); // Retrieve the uploaded file parent folder - response = getSingle(NodesEntityResource.class, user1, document.getParentId(), null, 200); + response = getSingle(NodesEntityResource.class, document.getParentId(), null, 200); Folder coolFolder = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(document.getParentId(), coolFolder.getId()); assertEquals("CoolFolder", coolFolder.getName()); @@ -1307,13 +1321,15 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest .setRelativePath(" ")// blank .build(); // 409 -> as the blank string is ignored and quick-1.txt already exists in the coolFolder - post(getNodeChildrenUrl(coolFolder.getId()), user1, reqBody.getBody(), null, reqBody.getContentType(), 409); + post(getNodeChildrenUrl(coolFolder.getId()), reqBody.getBody(), null, reqBody.getContentType(), 409); + + setRequestContext(user2); // user2 tries to upload the same file by creating sub-folders in the folderA of user1 reqBody = MultiPartBuilder.copy(multiPartBuilder) .setRelativePath("userTwoFolder1/userTwoFolder2") .build(); - post(getNodeChildrenUrl(folderA_id), user2, reqBody.getBody(), null, reqBody.getContentType(), 403); + post(getNodeChildrenUrl(folderA_id), reqBody.getBody(), null, reqBody.getContentType(), 403); } /** @@ -1387,7 +1403,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Node nUpdate = new Node(); nUpdate.setProperties(props); - HttpResponse response = put(URL_NODES, user1, folder5Id, toJsonAsStringNonNull(nUpdate), null, 200); + HttpResponse response = put(URL_NODES, folder5Id, toJsonAsStringNonNull(nUpdate), null, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(user2, ((Map)nodeResp.getProperties().get(PROP_OWNER)).get("id")); @@ -1415,7 +1431,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Map params = new HashMap<>(); params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites"); - response = getSingle(NodesEntityResource.class, user1, rootNodeId, params, 200); + response = getSingle(NodesEntityResource.class, rootNodeId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String sitesNodeId = nodeResp.getId(); @@ -1424,7 +1440,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary"); - response = getSingle(NodesEntityResource.class, user1, rootNodeId, params, 200); + response = getSingle(NodesEntityResource.class, rootNodeId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String ddNodeId = nodeResp.getId(); @@ -1477,7 +1493,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(f2Id); - HttpResponse response = post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 200); + HttpResponse response = post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(tgt), null, 200); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(d1Name, documentResp.getName()); @@ -1491,7 +1507,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest tgt.setName(d1NewName); tgt.setTargetParentId(f1Id); - response = post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 200); + response = post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(tgt), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(d1NewName, documentResp.getName()); @@ -1502,28 +1518,28 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // missing target tgt = new NodeTarget(); tgt.setName("new name"); - post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 400); + post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(tgt), null, 400); // name already exists tgt = new NodeTarget(); tgt.setName(d2Name); tgt.setTargetParentId(f2Id); - post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 409); + post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(tgt), null, 409); // unknown source nodeId tgt = new NodeTarget(); tgt.setTargetParentId(f2Id); - post("nodes/"+UUID.randomUUID().toString()+"/move", user1, toJsonAsStringNonNull(tgt), null, 404); + post("nodes/"+UUID.randomUUID().toString()+"/move", toJsonAsStringNonNull(tgt), null, 404); // unknown target nodeId tgt = new NodeTarget(); tgt.setTargetParentId(UUID.randomUUID().toString()); - post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 404); + post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(tgt), null, 404); // target is not a folder tgt = new NodeTarget(); tgt.setTargetParentId(d2Id); - post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 400); + post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(tgt), null, 400); String rootNodeId = getRootNodeId(); @@ -1534,49 +1550,49 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // can't create cycle (move into own subtree) tgt = new NodeTarget(); tgt.setTargetParentId(f3Id); - post("nodes/"+f2Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 400); + post("nodes/"+f2Id+"/move", toJsonAsStringNonNull(tgt), null, 400); // no (write/create) permissions to move to target tgt = new NodeTarget(); tgt.setTargetParentId(rootNodeId); - post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(tgt), null, 403); + post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(tgt), null, 403); - AuthenticationUtil.setFullyAuthenticatedUser(user2); + setRequestContext(user2); String my2NodeId = getMyNodeId(); // no (write/delete) permissions to move source tgt = new NodeTarget(); tgt.setTargetParentId(my2NodeId); - post("nodes/"+f1Id+"/move", user2, toJsonAsStringNonNull(tgt), null, 403); + post("nodes/"+f1Id+"/move", toJsonAsStringNonNull(tgt), null, 403); // -ve - cannot move (delete) Company Home root node setRequestContext(DEFAULT_ADMIN); - post("nodes/"+rootNodeId+"/move", DEFAULT_ADMIN, toJsonAsStringNonNull(tgt), null, 403); + post("nodes/"+rootNodeId+"/move", toJsonAsStringNonNull(tgt), null, 403); - setRequestContext("user1"); + setRequestContext(user1); Map params = new HashMap<>(); params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites"); - response = getSingle(NodesEntityResource.class, user1, rootNodeId, params, 200); + response = getSingle(NodesEntityResource.class, rootNodeId, params, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String sitesNodeId = nodeResp.getId(); // -ve - cannot move (delete) Sites node setRequestContext(DEFAULT_ADMIN); - post("nodes/"+sitesNodeId+"/move", DEFAULT_ADMIN, toJsonAsStringNonNull(tgt), null, 403); + post("nodes/"+sitesNodeId+"/move", toJsonAsStringNonNull(tgt), null, 403); - setRequestContext("user1"); + setRequestContext(user1); params = new HashMap<>(); params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary"); - response = getSingle(NodesEntityResource.class, user1, rootNodeId, params, 200); + response = getSingle(NodesEntityResource.class, rootNodeId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String ddNodeId = nodeResp.getId(); // -ve - cannot move (delete) Data Dictionary node setRequestContext(DEFAULT_ADMIN); - post("nodes/"+ddNodeId+"/move", DEFAULT_ADMIN, toJsonAsStringNonNull(tgt), null, 403); + post("nodes/"+ddNodeId+"/move", toJsonAsStringNonNull(tgt), null, 403); // -ve test - cannot move to multiple destinations in single POST call (unsupported) List nodeDestinations = new ArrayList<>(2); @@ -1587,7 +1603,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest nodeTarget.setTargetParentId(f2Id); nodeDestinations.add(nodeTarget); - post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(nodeDestinations), null, 405); + post("nodes/"+d1Id+"/move", toJsonAsStringNonNull(nodeDestinations), null, 405); } /** @@ -1619,7 +1635,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Map body = new HashMap<>(); body.put("targetParentId", targetId); - HttpResponse response = post(user1, URL_NODES, d1Id, "copy", toJsonAsStringNonNull(body).getBytes(), null, null, 201); + HttpResponse response = post(URL_NODES, d1Id, "copy", toJsonAsStringNonNull(body).getBytes(), null, null, 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(d1Name, documentResp.getName()); @@ -1632,7 +1648,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest body.put("targetParentId", targetId); body.put("name", newD2Name); - response = post(user1, URL_NODES, d2Id, "copy", toJsonAsStringNonNull(body).getBytes(), null, null, 201); + response = post(URL_NODES, d2Id, "copy", toJsonAsStringNonNull(body).getBytes(), null, null, 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(newD2Name, documentResp.getName()); @@ -1643,40 +1659,40 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // missing target NodeTarget tgt = new NodeTarget(); tgt.setName("new name"); - post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 400); + post("nodes/"+d1Id+"/copy", toJsonAsStringNonNull(tgt), null, 400); // name already exists - different parent tgt = new NodeTarget(); tgt.setName(newD2Name); tgt.setTargetParentId(targetId); - post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 409); + post("nodes/"+d1Id+"/copy", toJsonAsStringNonNull(tgt), null, 409); // name already exists - same parent tgt = new NodeTarget(); tgt.setTargetParentId(sourceId); - post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 409); + post("nodes/"+d1Id+"/copy", toJsonAsStringNonNull(tgt), null, 409); // unknown source nodeId tgt = new NodeTarget(); tgt.setTargetParentId(targetId); - post("nodes/"+UUID.randomUUID().toString()+"/copy", user1, toJsonAsStringNonNull(tgt), null, 404); + post("nodes/"+UUID.randomUUID().toString()+"/copy", toJsonAsStringNonNull(tgt), null, 404); // unknown target nodeId tgt = new NodeTarget(); tgt.setTargetParentId(UUID.randomUUID().toString()); - post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 404); + post("nodes/"+d1Id+"/copy", toJsonAsStringNonNull(tgt), null, 404); // target is not a folder tgt = new NodeTarget(); tgt.setTargetParentId(d2Id); - post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 400); + post("nodes/"+d1Id+"/copy", toJsonAsStringNonNull(tgt), null, 400); String rootNodeId = getRootNodeId(); // no (write/create) permissions to copy to target tgt = new NodeTarget(); tgt.setTargetParentId(rootNodeId); - post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 403); + post("nodes/"+d1Id+"/copy", toJsonAsStringNonNull(tgt), null, 403); // -ve test - cannot copy to multiple destinations in single POST call (unsupported) List nodeDestinations = new ArrayList<>(2); @@ -1687,7 +1703,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest nodeTarget.setTargetParentId(targetId); nodeDestinations.add(nodeTarget); - post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(nodeDestinations), null, 405); + post("nodes/"+d1Id+"/copy", toJsonAsStringNonNull(nodeDestinations), null, 405); } @Test @@ -1703,13 +1719,13 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest body.put("targetParentId", targetId); //test that you can't copy a site - HttpResponse response = getSingle("sites", user1, tSiteId, null, null, 200); + HttpResponse response = getSingle("sites", tSiteId, null, null, 200); Site siteResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class); String siteNodeId = siteResp.getGuid(); - post("nodes/"+siteNodeId+"/copy", user1, toJsonAsStringNonNull(body), null, 422); + post("nodes/"+siteNodeId+"/copy", toJsonAsStringNonNull(body), null, 422); //test that you can't copy a site doclib - post("nodes/"+tDocLibNodeId+"/copy", user1, toJsonAsStringNonNull(body), null, 422); + post("nodes/"+tDocLibNodeId+"/copy", toJsonAsStringNonNull(body), null, 422); } @@ -1769,7 +1785,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest NodeTarget target = new NodeTarget(); target.setTargetParentId(user2SitetDocLibNodeId); - HttpResponse response = post("nodes/" + user2FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 200); + HttpResponse response = post("nodes/" + user2FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 200); Folder moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(user2SitetDocLibNodeId, moveFolderResp.getParentId()); @@ -1777,12 +1793,12 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // as user1 is just a SiteCollaborator in the user2Site, he can't move the folder which he doesn't own - ACL access permission. target = new NodeTarget(); target.setTargetParentId(user1SitetDocLibNodeId); - post("nodes/" + user2FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 403); + post("nodes/" + user2FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 403); // user1 moves the folder created by himself to the docLib of the user2Site target = new NodeTarget(); target.setTargetParentId(user2SitetDocLibNodeId); - response = post("nodes/" + user1FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 200); + response = post("nodes/" + user1FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 200); moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(user2SitetDocLibNodeId, moveFolderResp.getParentId()); @@ -1790,7 +1806,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // The undo should be successful as user1 owns the folder target = new NodeTarget(); target.setTargetParentId(user1SitetDocLibNodeId); - response = post("nodes/" + user1FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 200); + response = post("nodes/" + user1FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 200); moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(user1SitetDocLibNodeId, moveFolderResp.getParentId()); @@ -1801,7 +1817,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // user1 copies the folder created by user2 to the user2Site's docLib target = new NodeTarget(); target.setTargetParentId(user2SitetDocLibNodeId); - response = post("nodes/" + user2Folder2NodeId + "/copy", user1, toJsonAsStringNonNull(target), null, 201); + response = post("nodes/" + user2Folder2NodeId + "/copy", toJsonAsStringNonNull(target), null, 201); Folder copyFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(user2SitetDocLibNodeId, copyFolderResp.getParentId()); @@ -1809,7 +1825,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest deleteNode( copyFolderResp.getId(), true, 204); // Check it's deleted - getSingle("nodes", user1, copyFolderResp.getId(), 404); + getSingle("nodes", copyFolderResp.getId(), 404); } /** @@ -1874,23 +1890,23 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest n.setRelativePath("/f1/f2/f3/f4"); // create node - HttpResponse response = post(getNodeChildrenUrl(myNodeId), user1, RestApiUtil.toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getNodeChildrenUrl(myNodeId), RestApiUtil.toJsonAsStringNonNull(n), 201); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); // check parent hierarchy ... - response = getSingle(NodesEntityResource.class, user1, folderResp.getId(), null, 200); + response = getSingle(NodesEntityResource.class, folderResp.getId(), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderResp.getName(),"fZ"); - response = getSingle(NodesEntityResource.class, user1, folderResp.getParentId(), null, 200); + response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderResp.getName(),"f4"); - response = getSingle(NodesEntityResource.class, user1, folderResp.getParentId(), null, 200); + response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderResp.getName(),"f3"); - response = getSingle(NodesEntityResource.class, user1, folderResp.getParentId(), null, 200); + response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderResp.getName(),"f2"); assertEquals(folderResp.getId(), f2Id); @@ -1898,25 +1914,25 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // -ve test - name is mandatory Folder invalid = new Folder(); invalid.setNodeType(TYPE_CM_FOLDER); - post(postUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(postUrl, toJsonAsStringNonNull(invalid), 400); // -ve test - invalid name invalid = new Folder(); invalid.setName("inv:alid"); invalid.setNodeType(TYPE_CM_FOLDER); - post(postUrl, user1, toJsonAsStringNonNull(invalid), 422); + post(postUrl, toJsonAsStringNonNull(invalid), 422); // -ve test - node type is mandatory invalid = new Folder(); invalid.setName("my folder"); - post(postUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(postUrl, toJsonAsStringNonNull(invalid), 400); // create empty file - used in -ve test below Document d1 = new Document(); d1.setName("d1.txt"); d1.setNodeType(TYPE_CM_CONTENT); - response = post(postUrl, user1, toJsonAsStringNonNull(d1), 201); + response = post(postUrl, toJsonAsStringNonNull(d1), 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String d1Id = documentResp.getId(); @@ -1924,32 +1940,32 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Folder f3 = new Folder(); f3.setName("f3"); f3.setNodeType(TYPE_CM_FOLDER); - post(getNodeChildrenUrl(d1Id), user1, toJsonAsStringNonNull(f3), 422); + post(getNodeChildrenUrl(d1Id), toJsonAsStringNonNull(f3), 422); // -ve test - it should not be possible to create a "system folder" invalid = new Folder(); invalid.setName("my sys folder"); invalid.setNodeType("cm:systemfolder"); - post(postUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(postUrl, toJsonAsStringNonNull(invalid), 400); // -ve test - unknown parent folder node id - post(getNodeChildrenUrl(UUID.randomUUID().toString()), user1, toJsonAsStringNonNull(f3), 404); + post(getNodeChildrenUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(f3), 404); // -ve test - duplicate name - post(postUrl, user1, toJsonAsStringNonNull(f1), 409); + post(postUrl, toJsonAsStringNonNull(f1), 409); // Create a folder with a duplicate name (f1), but set the autoRename to true - response = post(postUrl, user1, toJsonAsStringNonNull(f1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); + response = post(postUrl, toJsonAsStringNonNull(f1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("f1-1", documentResp.getName()); // Create a folder with a duplicate name (f1) again, but set the autoRename to true - response = post(postUrl, user1, toJsonAsStringNonNull(f1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); + response = post(postUrl, toJsonAsStringNonNull(f1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("f1-2", documentResp.getName()); // -ve test - create a folder with a duplicate name (f1), but set the autoRename to false - post(postUrl, user1, toJsonAsStringNonNull(f1), "?"+Nodes.PARAM_AUTO_RENAME+"=false", 409); + post(postUrl, toJsonAsStringNonNull(f1), "?"+Nodes.PARAM_AUTO_RENAME+"=false", 409); // Create folder using relative path n = new Node(); @@ -1957,31 +1973,31 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest n.setNodeType(TYPE_CM_FOLDER); n.setRelativePath("/f1/f2"); - response = post(postUrl, user1, toJsonAsStringNonNull(n), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); + response = post(postUrl, toJsonAsStringNonNull(n), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("fX", documentResp.getName()); // Create a folder using relative path, with a duplicate name (fX) but set the autoRename to true - response = post(postUrl, user1, toJsonAsStringNonNull(n), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); + response = post(postUrl, toJsonAsStringNonNull(n), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("fX-1", documentResp.getName()); // -ve test - create a folder with a duplicate name (fX), but set the autoRename to false - post(postUrl, user1, toJsonAsStringNonNull(n), "?"+Nodes.PARAM_AUTO_RENAME+"=false", 409); + post(postUrl, toJsonAsStringNonNull(n), "?"+Nodes.PARAM_AUTO_RENAME+"=false", 409); // -ve test - invalid relative path n = new Node(); n.setName("fX"); n.setNodeType(TYPE_CM_FOLDER); n.setRelativePath("/f1/inv:alid"); - post(getNodeChildrenUrl(f2Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 422); + post(getNodeChildrenUrl(f2Id), RestApiUtil.toJsonAsStringNonNull(n), 422); // -ve test - invalid relative path - points to existing node that is not a folder n = new Node(); n.setName("fY"); n.setNodeType(TYPE_CM_FOLDER); n.setRelativePath("d1.txt"); - post(getNodeChildrenUrl(myNodeId), user1, RestApiUtil.toJsonAsStringNonNull(n), 409); + post(getNodeChildrenUrl(myNodeId), RestApiUtil.toJsonAsStringNonNull(n), 409); // -ve test - minor: error code if trying to create with property with invalid format (REPO-473) props = new HashMap<>(); @@ -1990,7 +2006,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest n.setName("fZ"); n.setNodeType(TYPE_CM_FOLDER); n.setProperties(props); - post(getNodeChildrenUrl(myNodeId), user1, RestApiUtil.toJsonAsStringNonNull(n), 400); + post(getNodeChildrenUrl(myNodeId), RestApiUtil.toJsonAsStringNonNull(n), 400); } /** @@ -2018,9 +2034,9 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Node nodeUpdate = new Node(); nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES)); - put(URL_NODES, user1, fId, toJsonAsStringNonNull(nodeUpdate), null, 200); + put(URL_NODES, fId, toJsonAsStringNonNull(nodeUpdate), null, 200); - HttpResponse response = getAll(getNodeChildrenUrl(fId), user1, null, null, 200); + HttpResponse response = getAll(getNodeChildrenUrl(fId), null, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -2029,7 +2045,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest obj.setNodeType(TYPE_CM_CONTENT); // assoc type => cm:contains - response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201); + response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String c1Id = nodeResp.getId(); assertEquals(fId, nodeResp.getParentId()); @@ -2042,19 +2058,19 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest obj.setAssociation(assoc); // assoc type => cm:preferenceImage - response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201); + response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String c2Id = nodeResp.getId(); assertEquals(fId, nodeResp.getParentId()); - response = getAll(getNodeChildrenUrl(fId), user1, null, null, 200); + response = getAll(getNodeChildrenUrl(fId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); Map params = new HashMap<>(); params.put("where", "(assocType='"+ASSOC_TYPE_CM_CONTAINS+"')"); params.put("include", "association"); - response = getAll(getNodeChildrenUrl(fId), user1, null, params, 200); + response = getAll(getNodeChildrenUrl(fId), null, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(c1Id, nodes.get(0).getId()); @@ -2063,7 +2079,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("where", "(assocType='"+ASSOC_TYPE_CM_PREFERENCE_IMAGE+"')"); params.put("include", "association"); - response = getAll(getNodeChildrenUrl(fId), user1, null, params, 200); + response = getAll(getNodeChildrenUrl(fId), null, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(c2Id, nodes.get(0).getId()); @@ -2079,7 +2095,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES)); // assoc type => cm:contains - response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201); + response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String c3Id = nodeResp.getId(); @@ -2091,7 +2107,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest obj.setAssociation(assoc); // assoc type => cm:preferenceImage - response = post(getNodeChildrenUrl(c3Id), user1, toJsonAsStringNonNull(obj), 201); + response = post(getNodeChildrenUrl(c3Id), toJsonAsStringNonNull(obj), 201); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(c3Id, nodeResp.getParentId()); @@ -2104,7 +2120,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest obj.setAssociation(assoc); // assoc type => cm:contains (requires parent to be a folder !) - post(getNodeChildrenUrl(c3Id), user1, toJsonAsStringNonNull(obj), 422); + post(getNodeChildrenUrl(c3Id), toJsonAsStringNonNull(obj), 422); } finally { @@ -2156,7 +2172,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest obj.setNodeType(TYPE_CM_OBJECT); // create node/object - HttpResponse response = post(myChildrenUrl, user1, toJsonAsStringNonNull(obj), 201); + HttpResponse response = post(myChildrenUrl, toJsonAsStringNonNull(obj), 201); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); objIds.add(nodeResp.getId()); } @@ -2182,7 +2198,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // no filtering - HttpResponse response = getAll(myChildrenUrl, user1, paging, null, 200); + HttpResponse response = getAll(myChildrenUrl, paging, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds); @@ -2191,21 +2207,21 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Map params = new HashMap<>(); params.put("where", "(nodeType='"+TYPE_CM_FOLDER+"')"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, folderIds); params = new HashMap<>(); params.put("where", "(isFolder=true)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, folderIds); params = new HashMap<>(); params.put("where", "(isFolder=true AND isFile=false)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, folderIds); @@ -2214,21 +2230,21 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("where", "(nodeType='"+TYPE_CM_CONTENT+"')"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, fileIds); params = new HashMap<>(); params.put("where", "(isFile=true)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, fileIds); params = new HashMap<>(); params.put("where", "(isFile=true AND isFolder=false)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, fileIds); @@ -2237,21 +2253,21 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("where", "(nodeType='"+TYPE_CM_OBJECT+"')"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, objIds); params = new HashMap<>(); params.put("where", "(nodeType='cm:cmobject INCLUDESUBTYPES')"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds); params = new HashMap<>(); params.put("where", "(isFile=false AND isFolder=false)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, objIds); @@ -2259,7 +2275,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("where", "(isFile=false)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, notFileIds); @@ -2267,23 +2283,23 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("where", "(isFolder=false)"); - response = getAll(myChildrenUrl, user1, paging, params, 200); + response = getAll(myChildrenUrl, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, notFolderIds); // -ve - node cannot be both a file and a folder params = new HashMap<>(); params.put("where", "(isFile=true AND isFolder=true)"); - getAll(myChildrenUrl, user1, paging, params, 400); + getAll(myChildrenUrl, paging, params, 400); // -ve - nodeType and isFile/isFolder are mutually exclusive params = new HashMap<>(); params.put("where", "(nodeType='cm:object' AND isFolder=true)"); - getAll(myChildrenUrl, user1, paging, params, 400); + getAll(myChildrenUrl, paging, params, 400); params = new HashMap<>(); params.put("where", "(nodeType='cm:object' AND isFile=true)"); - getAll(myChildrenUrl, user1, paging, params, 400); + getAll(myChildrenUrl, paging, params, 400); } private void checkNodeIds(List nodes, List nodeIds) @@ -2317,7 +2333,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d1.setName("d1.txt"); d1.setNodeType(TYPE_CM_CONTENT); - HttpResponse response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(d1), 201); + HttpResponse response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(d1), 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String d1Id = documentResp.getId(); @@ -2348,7 +2364,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest n1.expected(nodeResp); // get node info - response = getSingle(NodesEntityResource.class, user1, n1Id, null, 200); + response = getSingle(NodesEntityResource.class, n1Id, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); n1.expected(nodeResp); @@ -2376,7 +2392,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest n2.expected(nodeResp); // get node info - response = getSingle(NodesEntityResource.class, user1, n2Id, null, 200); + response = getSingle(NodesEntityResource.class, n2Id, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); n2.expected(nodeResp); @@ -2389,7 +2405,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Node nUpdate = new Node(); nUpdate.setName(updatedName); - response = put(URL_NODES, user1, n1Id, toJsonAsStringNonNull(nUpdate), null, 200); + response = put(URL_NODES, n1Id, toJsonAsStringNonNull(nUpdate), null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); n1.setName(updatedName); @@ -2405,7 +2421,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Paging paging = getPaging(0, Integer.MAX_VALUE); - response = getAll(getNodeChildrenUrl(f2Id), user1, paging, params, 200); + response = getAll(getNodeChildrenUrl(f2Id), paging, params, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -2416,7 +2432,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest paging = getPaging(0, Integer.MAX_VALUE); - response = getAll(getNodeChildrenUrl(f2Id), user1, paging, params, 200); + response = getAll(getNodeChildrenUrl(f2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(linkIds.size(), nodes.size()); assertTrue(linkIds.contains(nodes.get(0).getId())); @@ -2427,7 +2443,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest paging = getPaging(0, Integer.MAX_VALUE); - response = getAll(getNodeChildrenUrl(f2Id), user1, paging, params, 200); + response = getAll(getNodeChildrenUrl(f2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(linkIds.size(), nodes.size()); assertTrue(linkIds.contains(nodes.get(0).getId())); @@ -2443,35 +2459,35 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // -ve test - create - name is mandatory Node invalid = new Node(); invalid.setNodeType("cm:link"); - post(myChildrenUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(myChildrenUrl, toJsonAsStringNonNull(invalid), 400); // -ve test - create - node type is mandatory invalid = new Node(); invalid.setName("my node"); - post(myChildrenUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(myChildrenUrl, toJsonAsStringNonNull(invalid), 400); // -ve test - create - unsupported node type invalid = new Node(); invalid.setName("my node"); invalid.setNodeType("sys:base"); - post(myChildrenUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(myChildrenUrl, toJsonAsStringNonNull(invalid), 400); // -ve test - create - duplicate name - post(getNodeChildrenUrl(f2Id), user1, toJsonAsStringNonNull(n2), 409); + post(getNodeChildrenUrl(f2Id), toJsonAsStringNonNull(n2), 409); // -ve test - unknown nodeType when filtering params = new HashMap<>(); params.put("where", "(nodeType='my:unknown'"); - getAll(getNodeChildrenUrl(f2Id), user1, paging, params, 400); + getAll(getNodeChildrenUrl(f2Id), paging, params, 400); // -ver test - invalid node type localname format and suffix is not ' includesubtypes' params = new HashMap<>(); params.put("where", "(nodeType='cm:link ')"); - getAll(getNodeChildrenUrl(f2Id), user1, paging, params, 400); + getAll(getNodeChildrenUrl(f2Id), paging, params, 400); params = new HashMap<>(); params.put("where", "(nodeType='cm:link blah')"); - getAll(getNodeChildrenUrl(f2Id), user1, paging, params, 400); + getAll(getNodeChildrenUrl(f2Id), paging, params, 400); } @@ -2496,7 +2512,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d1.setNodeType(TYPE_CM_CONTENT); // create empty file - HttpResponse response = post(postUrl, user1, toJsonAsStringNonNull(d1), 201); + HttpResponse response = post(postUrl, toJsonAsStringNonNull(d1), 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String d1Id = documentResp.getId(); @@ -2526,7 +2542,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d2.setNodeType(TYPE_CM_CONTENT); d2.setProperties(props); - response = post(postUrl, user1, toJsonAsStringNonNull(d2), 201); + response = post(postUrl, toJsonAsStringNonNull(d2), 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); @@ -2553,66 +2569,66 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest n.setRelativePath("/f1/f2"); // create node - response = post(getNodeChildrenUrl(myNodeId), user1, RestApiUtil.toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(myNodeId), RestApiUtil.toJsonAsStringNonNull(n), 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // check parent hierarchy ... - response = getSingle(NodesEntityResource.class, user1, documentResp.getId(), null, 200); + response = getSingle(NodesEntityResource.class, documentResp.getId(), null, 200); Folder folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderResp.getName(),"d3.txt"); - response = getSingle(NodesEntityResource.class, user1, folderResp.getParentId(), null, 200); + response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderResp.getName(),"f2"); - response = getSingle(NodesEntityResource.class, user1, folderResp.getParentId(), null, 200); + response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(folderResp.getName(),"f1"); - response = getSingle(NodesEntityResource.class, user1, folderResp.getParentId(), null, 200); + response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(myNodeId, folderResp.getId()); // -ve test - name is mandatory Document invalid = new Document(); invalid.setNodeType(TYPE_CM_CONTENT); - post(postUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(postUrl, toJsonAsStringNonNull(invalid), 400); // -ve test - node type is mandatory invalid = new Document(); invalid.setName("my file.txt"); - post(postUrl, user1, toJsonAsStringNonNull(invalid), 400); + post(postUrl, toJsonAsStringNonNull(invalid), 400); // -ve test - invalid (model integrity exception) Document d3 = new Document(); d3.setName("d3.txt"); d3.setNodeType(TYPE_CM_CONTENT); - post(getNodeChildrenUrl(d1Id), user1, toJsonAsStringNonNull(d3), 422); + post(getNodeChildrenUrl(d1Id), toJsonAsStringNonNull(d3), 422); // -ve test - unknown parent folder node id - post(getNodeChildrenUrl(UUID.randomUUID().toString()), user1, toJsonAsStringNonNull(d3), 404); + post(getNodeChildrenUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(d3), 404); // -ve test - duplicate name - post(postUrl, user1, toJsonAsStringNonNull(d1), 409); + post(postUrl, toJsonAsStringNonNull(d1), 409); // Create a file with a duplicate name (d1.txt), but set the autoRename to true - response = post(postUrl, user1, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); + response = post(postUrl, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("d1-1.txt", documentResp.getName()); // Create a file with a duplicate name (d1.txt) again, but set the autoRename to true - response = post(postUrl, user1, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); + response = post(postUrl, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("d1-2.txt", documentResp.getName()); // Create a file with a duplicate name (d1-2.txt) again, but set the autoRename to true d1.setName("d1-2.txt"); - response = post(postUrl, user1, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); + response = post(postUrl, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=true", 201); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("d1-2-1.txt", documentResp.getName()); // -ve test - create a file with a duplicate name (d1-2.txt), but set the autoRename to false - post(postUrl, user1, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=false", 409); + post(postUrl, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=false", 409); } /** @@ -2657,7 +2673,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d1.setName("d1.txt"); d1.setNodeType(TYPE_CM_CONTENT); - HttpResponse response = post(postUrl, user1, toJsonAsStringNonNull(d1), 201); + HttpResponse response = post(postUrl, toJsonAsStringNonNull(d1), 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String dId = documentResp.getId(); @@ -2683,7 +2699,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Document dUpdate = new Document(); dUpdate.setName("d1b.txt"); - response = put(URL_NODES, user1, dId, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); d1.setName("d1b.txt"); @@ -2698,7 +2714,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest dUpdate = new Document(); dUpdate.setProperties(props); - response = put(URL_NODES, user1, dId, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); d1.setProperties(props); @@ -2710,7 +2726,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest dUpdate = new Document(); dUpdate.setAspectNames(Arrays.asList("cm:auditable","cm:titled","cm:versionable")); - response = put(URL_NODES, user1, dId, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); d1.getProperties().put("cm:versionLabel","1.0"); @@ -2718,7 +2734,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest d1.setAspectNames(Arrays.asList("cm:auditable","cm:titled","cm:versionable")); d1.expected(documentResp); - response = getSingle(URL_NODES, user1, dId, 200); + response = getSingle(URL_NODES, dId, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); d1.getProperties().put("cm:versionLabel", "1.0"); @@ -2730,7 +2746,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest dUpdate = new Document(); dUpdate.setAspectNames(Arrays.asList("cm:auditable","cm:versionable")); - response = put(URL_NODES, user1, dId, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); d1.getProperties().remove("cm:title"); @@ -2749,7 +2765,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest fUpdate.setProperties(props); fUpdate.setName(folderName); - response = put(URL_NODES, user1, fId, toJsonAsStringNonNull(fUpdate), null, 200); + response = put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); f1.setName(folderName); @@ -2765,7 +2781,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest fUpdate = new Folder(); fUpdate.setProperties(props); - response = put(URL_NODES, user1, fId, toJsonAsStringNonNull(fUpdate), null, 200); + response = put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); f1.getProperties().remove("cm:title"); @@ -2776,7 +2792,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest fUpdate = new Folder(); fUpdate.setNodeType("app:glossary"); - response = put(URL_NODES, user1, fId, toJsonAsStringNonNull(fUpdate), null, 200); + response = put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); f1.setNodeType("app:glossary"); @@ -2787,29 +2803,29 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest props.put("cm:xyz","my unknown property"); dUpdate = new Document(); dUpdate.setProperties(props); - put(URL_NODES, user1, dId, toJsonAsStringNonNull(dUpdate), null, 400); + put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400); // -ve test - fail on unknown aspect List aspects = new ArrayList<>(d1.getAspectNames()); aspects.add("cm:unknownAspect"); dUpdate = new Document(); dUpdate.setAspectNames(aspects); - put(URL_NODES, user1, dId, toJsonAsStringNonNull(dUpdate), null, 400); + put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400); // -ve test - duplicate name dUpdate = new Document(); dUpdate.setName(folderName); - put(URL_NODES, user1, dId, toJsonAsStringNonNull(dUpdate), null, 409); + put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 409); // -ve test - unknown node id dUpdate = new Document(); dUpdate.setName("some.txt"); - put(URL_NODES, user1, UUID.randomUUID().toString(), toJsonAsStringNonNull(dUpdate), null, 404); + put(URL_NODES, UUID.randomUUID().toString(), toJsonAsStringNonNull(dUpdate), null, 404); // -ve test - generalise node type fUpdate = new Folder(); fUpdate.setNodeType(TYPE_CM_FOLDER); - put(URL_NODES, user1, fId, toJsonAsStringNonNull(fUpdate), null, 400); + put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 400); // -ve test - try to move to a different parent using PUT (note: should use new POST /nodes/{nodeId}/move operation instead) @@ -2818,19 +2834,19 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest fUpdate = new Folder(); fUpdate.setParentId(f2Id); - put(URL_NODES, user1, fId, toJsonAsStringNonNull(fUpdate), null, 400); + put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 400); // ok - if parent does not change fUpdate = new Folder(); fUpdate.setParentId(myNodeId); - put(URL_NODES, user1, fId, toJsonAsStringNonNull(fUpdate), null, 200); + put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200); // -ve test - minor: error code if trying to update property with invalid format (REPO-473) props = new HashMap<>(); props.put("exif:pixelYDimension", "my unknown property"); fUpdate = new Folder(); fUpdate.setProperties(props); - put(URL_NODES, user1, f2Id, toJsonAsStringNonNull(fUpdate), null, 400); + put(URL_NODES, f2Id, toJsonAsStringNonNull(fUpdate), null, 400); } /** @@ -2856,7 +2872,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Folder fUpdate = new Folder(); fUpdate.setProperties(props); - HttpResponse response = put(URL_NODES, user1, f1Id, toJsonAsStringNonNull(fUpdate), null, 200); + HttpResponse response = put(URL_NODES, f1Id, toJsonAsStringNonNull(fUpdate), null, 200); folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class); assertEquals(user1, ((Map)folderResp.getProperties().get(PROP_OWNER)).get("id")); @@ -2866,7 +2882,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String d1Id = createTextFile(f1Id, d1Name, "The quick brown fox jumps over the lazy dog.").getId(); // get node info - response = getSingle(NodesEntityResource.class, user1, d1Id, null, 200); + response = getSingle(NodesEntityResource.class, d1Id, null, 200); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // note: owner is implied @@ -2879,7 +2895,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Document dUpdate = new Document(); dUpdate.setProperties(props); - response = put(URL_NODES, user1, d1Id, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(user1, ((Map)documentResp.getProperties().get(PROP_OWNER)).get("id")); @@ -2891,11 +2907,11 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest dUpdate = new Document(); dUpdate.setProperties(props); - put(URL_NODES, user1, d1Id, toJsonAsStringNonNull(dUpdate), null, 400); + put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 400); - AuthenticationUtil.setFullyAuthenticatedUser(user2); + setRequestContext(user2); - response = getSingle(URL_NODES, user1, d1Id, 200); + response = getSingle(URL_NODES, d1Id, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(user1, ((Map)documentResp.getProperties().get(PROP_OWNER)).get("id")); @@ -2907,30 +2923,30 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest dUpdate = new Document(); dUpdate.setProperties(props); - put(URL_NODES, user2, d1Id, toJsonAsStringNonNull(dUpdate), null, 403); + put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 403); props = new HashMap<>(); props.put(PROP_OWNER, user1); dUpdate = new Document(); dUpdate.setProperties(props); - put(URL_NODES, user2, d1Id, toJsonAsStringNonNull(dUpdate), null, 403); + put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 403); - AuthenticationUtil.setFullyAuthenticatedUser(user1); + setRequestContext(user1); props = new HashMap<>(); props.put(PROP_OWNER, user2); dUpdate = new Document(); dUpdate.setProperties(props); - response = put(URL_NODES, user1, d1Id, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, d1Id, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(user2, ((Map)documentResp.getProperties().get(PROP_OWNER)).get("id")); - AuthenticationUtil.setFullyAuthenticatedUser(user2); + setRequestContext(user2); - response = getSingle(URL_NODES, user2, d1Id, 200); + response = getSingle(URL_NODES, d1Id, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(user2, ((Map)documentResp.getProperties().get(PROP_OWNER)).get("id")); @@ -2972,7 +2988,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest doc.setContent(contentInfo); // create an empty file within F1 folder - HttpResponse response = post(getNodeChildrenUrl(f1_nodeId), user1, toJsonAsStringNonNull(doc), 201); + HttpResponse response = post(getNodeChildrenUrl(f1_nodeId), toJsonAsStringNonNull(doc), 201); Document docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(docName, docResp.getName()); @@ -2989,15 +3005,15 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest BinaryPayload payload = new BinaryPayload(txtFile); // Try to update a folder! - putBinary(getNodeContentUrl(f1_nodeId), user1, payload, null, null, 400); + putBinary(getNodeContentUrl(f1_nodeId), payload, null, null, 400); // Try to update a non-existent file - putBinary(getNodeContentUrl(UUID.randomUUID().toString()), user1, payload, null, null, 404); + putBinary(getNodeContentUrl(UUID.randomUUID().toString()), payload, null, null, 404); final String url = getNodeContentUrl(docResp.getId()); // Update the empty file - response = putBinary(url, user1, payload, null, null, 200); + response = putBinary(url, payload, null, null, 200); docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(docName, docResp.getName()); assertNotNull(docResp.getId()); @@ -3033,7 +3049,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); payload = new BinaryPayload(txtFile); - response = putBinary(url + "?include=path", user1, payload, null, null, 200); + response = putBinary(url + "?include=path", payload, null, null, 200); docResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); assertEquals(docName, docResp.getName()); assertNotNull(docResp.getContent()); @@ -3062,7 +3078,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String docName2 = "hello-world.txt"; Map params = new HashMap<>(); params.put(Nodes.PARAM_NAME, docName2); - response = putBinary(url, user1, payload, null, params, 200); + response = putBinary(url, payload, null, params, 200); docResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); assertEquals(docName2, docResp.getName()); @@ -3074,21 +3090,21 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put(Nodes.PARAM_NAME, "hello/world.txt"); payload = new BinaryPayload(txtFile); - putBinary(url, user1, payload, null, params, 422); + putBinary(url, payload, null, params, 422); // -ve - optional "name" already exists ... params = new HashMap<>(); params.put(Nodes.PARAM_NAME, anoNodeName); payload = new BinaryPayload(txtFile); - putBinary(url, user1, payload, null, params, 409); + putBinary(url, payload, null, params, 409); // -ve - try to update content using multi-part form data payload = new BinaryPayload(txtFile, "multipart/form-data", null); - putBinary(url, user1, payload, null, null, 415); + putBinary(url, payload, null, null, 415); // -ve - try to invalid media type argument (when parsing request) payload = new BinaryPayload(txtFile, "/jpeg", null); - putBinary(url, user1, payload, null, null, 415); + putBinary(url, payload, null, null, 415); } /** @@ -3113,7 +3129,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest MultiPartRequest reqBody = multiPartBuilder.build(); // Upload text content - HttpResponse response = post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String contentNodeId = document.getId(); @@ -3125,7 +3141,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType()); // Download text content - by default with Content-Disposition header - response = getSingle(NodesEntityResource.class, user1, contentNodeId+"/content", null, 200); + response = getSingle(NodesEntityResource.class, contentNodeId+"/content", null, 200); String textContent = response.getResponse(); assertEquals("The quick brown fox jumps over the lazy dog", textContent); @@ -3141,7 +3157,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertNotNull(lastModifiedHeader); Map headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); // Test 304 response - getSingle(getNodeContentUrl(contentNodeId), user1, null, null, headers, 304); + getSingle(getNodeContentUrl(contentNodeId), null, null, headers, 304); // Update the content to change the node's modified date Document docUpdate = new Document(); @@ -3149,12 +3165,12 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // Wait a second then update, as the dates will be rounded to // ignore millisecond when checking for If-Modified-Since Thread.sleep(1000L); - response = put(URL_NODES, user1, contentNodeId, toJsonAsStringNonNull(docUpdate), null, 200); + response = put(URL_NODES, contentNodeId, toJsonAsStringNonNull(docUpdate), null, 200); Document updatedDocument = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals(contentNodeId, updatedDocument.getId()); // The requested "If-Modified-Since" date is older than node's modified date - response = getSingle(getNodeContentUrl(contentNodeId), user1, null, null, headers, 200); + response = getSingle(getNodeContentUrl(contentNodeId), null, null, headers, 200); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); assertNotNull(responseHeaders.get("Cache-Control")); @@ -3176,7 +3192,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest reqBody = multiPartBuilder.build(); // Upload binary content - response = post(getNodeChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentNodeId = document.getId(); @@ -3191,7 +3207,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Map params = new LinkedHashMap<>(); params.put("attachment", "false"); - response = getSingle(NodesEntityResource.class, user1, contentNodeId + "/content", params, 200); + response = getSingle(NodesEntityResource.class, contentNodeId + "/content", params, 200); byte[] bytes = response.getResponseAsBytes(); assertArrayEquals(originalBytes, bytes); @@ -3204,7 +3220,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertNotNull(lastModifiedHeader); headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); // Test 304 response - getSingle(getNodeContentUrl(contentNodeId), user1, null, null, headers, 304); + getSingle(getNodeContentUrl(contentNodeId), null, null, headers, 304); } /** @@ -3225,13 +3241,13 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Map params = new HashMap<>(); params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites"); - HttpResponse response = getSingle(NodesEntityResource.class, user1, rootNodeId, params, 200); + HttpResponse response = getSingle(NodesEntityResource.class, rootNodeId, params, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String sitesNodeId = nodeResp.getId(); params = new HashMap<>(); params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary"); - response = getSingle(NodesEntityResource.class, user1, rootNodeId, params, 200); + response = getSingle(NodesEntityResource.class, rootNodeId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String ddNodeId = nodeResp.getId(); @@ -3239,11 +3255,11 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("include", "allowableOperations"); - response = getSingle(NodesEntityResource.class, user1, rootNodeId, params, 200); + response = getSingle(NodesEntityResource.class, rootNodeId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNull(nodeResp.getAllowableOperations()); - response = getSingle(NodesEntityResource.class, user1, sharedNodeId, params, 200); + response = getSingle(NodesEntityResource.class, sharedNodeId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNotNull(nodeResp.getAllowableOperations()); assertEquals(1, nodeResp.getAllowableOperations().size()); @@ -3252,7 +3268,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // -ve deleteNode(sharedNodeId, 403); - response = getSingle(NodesEntityResource.class, user1, getMyNodeId(), params, 200); + response = getSingle(NodesEntityResource.class, getMyNodeId(), params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNotNull(nodeResp.getAllowableOperations()); assertEquals(3, nodeResp.getAllowableOperations().size()); @@ -3265,11 +3281,11 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String folderId = nodeResp.getId(); assertNull(nodeResp.getAllowableOperations()); - response = getSingle(NodesEntityResource.class, user1, folderId, null, 200); + response = getSingle(NodesEntityResource.class, folderId, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNull(nodeResp.getAllowableOperations()); - response = getSingle(NodesEntityResource.class, user1, folderId, params, 200); + response = getSingle(NodesEntityResource.class, folderId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNotNull(nodeResp.getAllowableOperations()); assertEquals(3, nodeResp.getAllowableOperations().size()); @@ -3282,12 +3298,12 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String fileId = nodeResp.getId(); assertNull(nodeResp.getAllowableOperations()); - response = getSingle(NodesEntityResource.class, user1, fileId, null, 200); + response = getSingle(NodesEntityResource.class, fileId, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNull(nodeResp.getAllowableOperations()); // a file - no create - response = getSingle(NodesEntityResource.class, user1, fileId, params, 200); + response = getSingle(NodesEntityResource.class, fileId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNotNull(nodeResp.getAllowableOperations()); assertEquals(2, nodeResp.getAllowableOperations().size()); @@ -3298,7 +3314,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // as user2 ... setRequestContext(user2); - response = getSingle(NodesEntityResource.class, user2, folderId, params, 200); + response = getSingle(NodesEntityResource.class, folderId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNotNull(nodeResp.getAllowableOperations()); assertEquals(1, nodeResp.getAllowableOperations().size()); @@ -3307,7 +3323,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest // -ve deleteNode(folderId, 403); - response = getSingle(NodesEntityResource.class, user2, fileId, params, 200); + response = getSingle(NodesEntityResource.class, fileId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNull(nodeResp.getAllowableOperations()); @@ -3380,11 +3396,11 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String userId = user1; setRequestContext(userId); - response = getSingle("sites", userId, tSiteId, null, null, 200); + response = getSingle("sites", tSiteId, null, null, 200); Site siteResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class); String siteNodeId = siteResp.getGuid(); - response = getSingle(NodesEntityResource.class, userId, siteNodeId, params, 200); + response = getSingle(NodesEntityResource.class, siteNodeId, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(userId, nodeResp.getCreatedByUser().getId()); assertNotNull(nodeResp.getAllowableOperations()); @@ -3401,13 +3417,13 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest Node n = new Node(); n.setName("o1"); n.setNodeType(TYPE_CM_OBJECT); - response = post(getNodeChildrenUrl(folderId), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(folderId), toJsonAsStringNonNull(n), 201); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String o1Id = nodeResp.getId(); params = new HashMap<>(); params.put("include", "allowableOperations"); - response = getSingle(NodesEntityResource.class, user1, o1Id, params, 200); + response = getSingle(NodesEntityResource.class, o1Id, params, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertNotNull(nodeResp.getAllowableOperations()); diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java index adf850dcf2..5653138e9d 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java @@ -54,7 +54,7 @@ import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull import static org.junit.Assert.*; /** - * API tests for Node Associations + * V1 REST API tests for Node Associations * * Peer Associations (source -> target) *
      @@ -154,7 +154,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setName("o1"); n.setNodeType(TYPE_CM_CONTENT); n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE)); - HttpResponse response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(n), 201); String o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); // create ano' folder @@ -165,7 +165,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setName("o2"); n.setNodeType(TYPE_CM_CONTENT); n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE)); - response = post(getNodeChildrenUrl(f2Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(f2Id), toJsonAsStringNonNull(n), 201); String o2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); @@ -177,67 +177,67 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // empty lists - before - response = getAll(getNodeTargetsUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o1Id), paging, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeSourcesUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeSourcesUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // create two assocs in one direction (from src to tgt) AssocTarget tgt = new AssocTarget(o2Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(o1Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(o1Id), toJsonAsStringNonNull(tgt), 201); tgt = new AssocTarget(o2Id, ASSOC_TYPE_CM_PARTS); - post(getNodeTargetsUrl(o1Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(o1Id), toJsonAsStringNonNull(tgt), 201); - response = getAll(getNodeTargetsUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeSourcesUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeSourcesUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); // create two assocs in the other direction (from tgt to src) tgt = new AssocTarget(o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(o2Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(o2Id), toJsonAsStringNonNull(tgt), 201); tgt = new AssocTarget(o1Id, ASSOC_TYPE_CM_PARTS); - post(getNodeTargetsUrl(o2Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(o2Id), toJsonAsStringNonNull(tgt), 201); - response = getAll(getNodeTargetsUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeSourcesUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeTargetsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeSourcesUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); @@ -246,13 +246,13 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest Map params = new HashMap<>(1); params.put("where", "(assocType='"+ASSOC_TYPE_CM_REFERENCES+"')"); - response = getAll(getNodeTargetsUrl(o1Id), user1, paging, params, 200); + response = getAll(getNodeTargetsUrl(o1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o2Id, nodes.get(0).getId()); assertEquals(ASSOC_TYPE_CM_REFERENCES, nodes.get(0).getAssociation().getAssocType()); - response = getAll(getNodeSourcesUrl(o1Id), user1, paging, params, 200); + response = getAll(getNodeSourcesUrl(o1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o2Id, nodes.get(0).getId()); @@ -261,13 +261,13 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put("where", "(assocType='"+ASSOC_TYPE_CM_PARTS+"')"); - response = getAll(getNodeTargetsUrl(o2Id), user1, paging, params, 200); + response = getAll(getNodeTargetsUrl(o2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o1Id, nodes.get(0).getId()); assertEquals(ASSOC_TYPE_CM_PARTS, nodes.get(0).getAssociation().getAssocType()); - response = getAll(getNodeSourcesUrl(o2Id), user1, paging, params, 200); + response = getAll(getNodeSourcesUrl(o2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o1Id, nodes.get(0).getId()); @@ -276,62 +276,62 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // remove assocs - specific type - in one direction params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_REFERENCES); - delete(getNodeTargetsUrl(o1Id), user1, o2Id, params, 204); + delete(getNodeTargetsUrl(o1Id), o2Id, params, 204); - response = getAll(getNodeTargetsUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); - response = getAll(getNodeSourcesUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeTargetsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeSourcesUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_PARTS); - delete(getNodeTargetsUrl(o1Id), user1, o2Id, params, 204); + delete(getNodeTargetsUrl(o1Id), o2Id, params, 204); - response = getAll(getNodeTargetsUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeSourcesUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeTargetsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); - response = getAll(getNodeSourcesUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // remove assocs - both types at once (ie. no assocType param) - in the other direction - delete(getNodeTargetsUrl(o2Id), user1, o1Id, 204); + delete(getNodeTargetsUrl(o2Id), o1Id, 204); // empty lists - after - response = getAll(getNodeTargetsUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeSourcesUrl(o1Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeSourcesUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -341,21 +341,25 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) tgt = new AssocTarget(o2Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(o1Id), null, toJsonAsStringNonNull(tgt), 401); + post(getNodeTargetsUrl(o1Id), toJsonAsStringNonNull(tgt), 401); + + setRequestContext(user1); // -ve test - model integrity tgt = new AssocTarget(f2Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(o1Id), user1, toJsonAsStringNonNull(tgt), 422); + post(getNodeTargetsUrl(o1Id), toJsonAsStringNonNull(tgt), 422); // -ve test - duplicate assoc tgt = new AssocTarget(o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(o2Id), user1, toJsonAsStringNonNull(tgt), 201); - post(getNodeTargetsUrl(o2Id), user1, toJsonAsStringNonNull(tgt), 409); + post(getNodeTargetsUrl(o2Id), toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(o2Id), toJsonAsStringNonNull(tgt), 409); tgt = new AssocTarget(o1Id, "cm:unknowntype"); - post(getNodeTargetsUrl(o2Id), user1, toJsonAsStringNonNull(tgt), 400); + post(getNodeTargetsUrl(o2Id), toJsonAsStringNonNull(tgt), 400); } // @@ -363,18 +367,22 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) - getAll(getNodeTargetsUrl(f1Id), null, paging, null, 401); - getAll(getNodeSourcesUrl(f1Id), null, paging, null, 401); + getAll(getNodeTargetsUrl(f1Id), paging, null, 401); + getAll(getNodeSourcesUrl(f1Id), paging, null, 401); - getAll(getNodeTargetsUrl(UUID.randomUUID().toString()), user1, paging, null, 404); - getAll(getNodeSourcesUrl(UUID.randomUUID().toString()), user1, paging, null, 404); + setRequestContext(user1); + + getAll(getNodeTargetsUrl(UUID.randomUUID().toString()), paging, null, 404); + getAll(getNodeSourcesUrl(UUID.randomUUID().toString()), paging, null, 404); params = new HashMap<>(1); params.put("where", "(assocType='cm:unknownassoctype')"); - getAll(getNodeTargetsUrl(o1Id), user1, paging, params, 400); - getAll(getNodeSourcesUrl(o1Id), user1, paging, params, 400); + getAll(getNodeTargetsUrl(o1Id), paging, params, 400); + getAll(getNodeSourcesUrl(o1Id), paging, params, 400); // TODO paging - in-built sort order ? (RA-926, RA-927) } @@ -385,24 +393,28 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) - delete(getNodeTargetsUrl(o1Id), null, o2Id, 401); + delete(getNodeTargetsUrl(o1Id), o2Id, 401); - delete(getNodeTargetsUrl(UUID.randomUUID().toString()), user1, o2Id, null, 404); - delete(getNodeTargetsUrl(o1Id), user1, UUID.randomUUID().toString(), null, 404); + setRequestContext(user1); + + delete(getNodeTargetsUrl(UUID.randomUUID().toString()), o2Id, null, 404); + delete(getNodeTargetsUrl(o1Id), UUID.randomUUID().toString(), null, 404); // -ve test -nothing to delete - for any assoc type - delete(getNodeTargetsUrl(o1Id), user1, o2Id, null, 404); + delete(getNodeTargetsUrl(o1Id), o2Id, null, 404); // -ve test - nothing to delete - for given assoc type params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_REFERENCES); - delete(getNodeTargetsUrl(o1Id), user1, o2Id, params, 404); + delete(getNodeTargetsUrl(o1Id), o2Id, params, 404); // -ve test - unknown assoc type params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, "cm:unknowntype"); - delete(getNodeTargetsUrl(o1Id), user1, o2Id, params, 400); + delete(getNodeTargetsUrl(o1Id), o2Id, params, 400); } } finally @@ -441,7 +453,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setName("shared content "+RUNID); n.setNodeType(TYPE_CM_CONTENT); n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE)); - HttpResponse response = post(getNodeChildrenUrl(sf1Id), user1, toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getNodeChildrenUrl(sf1Id), toJsonAsStringNonNull(n), 201); String so1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); @@ -455,7 +467,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setName("o1"); n.setNodeType(TYPE_CM_CONTENT); n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE)); - response = post(getNodeChildrenUrl(u1f1Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(u1f1Id), toJsonAsStringNonNull(n), 201); String u1o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); // as user 2 - create folder in user's home (My Files) area and content within the folder @@ -470,38 +482,48 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setName("o1"); n.setNodeType(TYPE_CM_CONTENT); n.setAspectNames(Arrays.asList(ASPECT_CM_REFERENCING, ASPECT_CM_PARTABLE)); - response = post(getNodeChildrenUrl(u2f1Id), user2, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(u2f1Id), toJsonAsStringNonNull(n), 201); String u2o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); try { - setRequestContext(user1); - Paging paging = getPaging(0, 100); // empty lists - before - response = getAll(getNodeTargetsUrl(u1f1Id), user1, paging, null, 200); + setRequestContext(user1); + + response = getAll(getNodeTargetsUrl(u1f1Id), paging, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(u2f1Id), user2, paging, null, 200); + setRequestContext(user2); + + response = getAll(getNodeTargetsUrl(u2f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // Create some assocs + setRequestContext(user1); + AssocTarget tgt = new AssocTarget(u1o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(u1f1Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(u1f1Id), toJsonAsStringNonNull(tgt), 201); + + setRequestContext(user2); tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(u2f1Id), user2, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 201); - response = getAll(getNodeTargetsUrl(u1f1Id), user1, paging, null, 200); + setRequestContext(user1); + + response = getAll(getNodeTargetsUrl(u1f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); - response = getAll(getNodeTargetsUrl(u2f1Id), user2, paging, null, 200); + setRequestContext(user2); + + response = getAll(getNodeTargetsUrl(u2f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); @@ -509,22 +531,29 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest { // source/target not readable + setRequestContext(user2); + // list - getAll(getNodeTargetsUrl(u1f1Id), user2, paging, null, 403); - getAll(getNodeSourcesUrl(u1o1Id), user2, paging, null, 403); + getAll(getNodeTargetsUrl(u1f1Id), paging, null, 403); + getAll(getNodeSourcesUrl(u1o1Id), paging, null, 403); + + setRequestContext(user1); // create tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(u1f1Id), user1, toJsonAsStringNonNull(tgt), 403); + post(getNodeTargetsUrl(u1f1Id), toJsonAsStringNonNull(tgt), 403); tgt = new AssocTarget(u1o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(u2f1Id), user1, toJsonAsStringNonNull(tgt), 403); + post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 403); + + setRequestContext(user2); // remove - delete(getNodeTargetsUrl(u1f1Id), user2, u2o1Id, null, 403); - delete(getNodeTargetsUrl(u2f1Id), user2, u1o1Id, null, 404); + delete(getNodeTargetsUrl(u1f1Id), u2o1Id, null, 403); + delete(getNodeTargetsUrl(u2f1Id), u1o1Id, null, 404); } + setRequestContext(user1); // Test listing targets (with permissions applied) @@ -543,12 +572,12 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // user 1 setRequestContext(user1); tgt = new AssocTarget(u1o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(sf1Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(sf1Id), toJsonAsStringNonNull(tgt), 201); // user 2 setRequestContext(user2); tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(sf1Id), user2, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(sf1Id), toJsonAsStringNonNull(tgt), 201); setRequestContext(DEFAULT_ADMIN); @@ -558,13 +587,13 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest assertEquals(2, nodes.size()); setRequestContext(user1); - response = getAll(getNodeTargetsUrl(sf1Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(sf1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(u1o1Id, nodes.get(0).getId()); setRequestContext(user2); - response = getAll(getNodeTargetsUrl(sf1Id), user2, paging, null, 200); + response = getAll(getNodeTargetsUrl(sf1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(u2o1Id, nodes.get(0).getId()); @@ -587,12 +616,12 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // user 1 setRequestContext(user1); tgt = new AssocTarget(so1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(u1f1Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(u1f1Id), toJsonAsStringNonNull(tgt), 201); // user 2 setRequestContext(user2); tgt = new AssocTarget(so1Id, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(u2f1Id), user2, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 201); setRequestContext(DEFAULT_ADMIN); @@ -602,13 +631,13 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest assertEquals(2, nodes.size()); setRequestContext(user1); - response = getAll(getNodeSourcesUrl(so1Id), user1, paging, null, 200); + response = getAll(getNodeSourcesUrl(so1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(u1f1Id, nodes.get(0).getId()); setRequestContext(user2); - response = getAll(getNodeSourcesUrl(so1Id), user2, paging, null, 200); + response = getAll(getNodeSourcesUrl(so1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(u2f1Id, nodes.get(0).getId()); @@ -653,7 +682,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setName("f1"); n.setNodeType(TYPE_CM_FOLDER); n.setAspectNames(Arrays.asList(ASPECT_CM_PREFERENCES)); - HttpResponse response = post(getNodeChildrenUrl(myFolderNodeId), user1, toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getNodeChildrenUrl(myFolderNodeId), toJsonAsStringNonNull(n), 201); String f1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); // create content node @@ -661,7 +690,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n = new Node(); n.setName(o1Name); n.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(n), 201); String o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); // create ano' folder @@ -672,7 +701,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n = new Node(); n.setName(o2Name); n.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(f2Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(f2Id), toJsonAsStringNonNull(n), 201); String o2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); @@ -689,12 +718,12 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // lists - before - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // primary parent only - response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f2Id, nodes.get(0).getId()); @@ -703,14 +732,14 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // create secondary child assoc AssocChild secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f1Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201); // create ano' secondary child assoc (different type) between the same two nodes secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_PREFERENCE_IMAGE); - post(getNodeSecondaryChildrenUrl(f1Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201); - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); int i = 0; for (Node node : nodes) @@ -729,7 +758,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest } assertEquals(2, i); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); i = 0; for (Node node : nodes) @@ -762,13 +791,13 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest Map params = new HashMap<>(1); params.put("where", "(assocType='"+ASSOC_TYPE_CM_CONTAINS+"')"); - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, params, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o2Id, nodes.get(0).getId()); assertEquals(ASSOC_TYPE_CM_CONTAINS, nodes.get(0).getAssociation().getAssocType()); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); i = 0; for (Node node : nodes) @@ -793,14 +822,14 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put("where", "(assocType='"+ASSOC_TYPE_CM_PREFERENCE_IMAGE+"')"); - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, params, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o2Id, nodes.get(0).getId()); assertEquals(ASSOC_TYPE_CM_PREFERENCE_IMAGE, nodes.get(0).getAssociation().getAssocType()); assertFalse(nodes.get(0).getAssociation().getIsPrimary()); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1Id, nodes.get(0).getId()); @@ -813,7 +842,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // note: see NodeApiTest for other filters related to /nodes/{parentId}/children filters // note: currently collapses same nodeIds (o2Id x 2) into one - makes sense in terms of File/Folder to avoid duplicate names - response = getAll(getNodeChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeChildrenUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); List nodeIds = Arrays.asList(new String[] { nodes.get(0).getId(), nodes.get(1).getId()} ); @@ -823,7 +852,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put("where", "(isPrimary=true)"); - response = getAll(getNodeChildrenUrl(f1Id), user1, paging, params, 200); + response = getAll(getNodeChildrenUrl(f1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o1Id, nodes.get(0).getId()); @@ -832,7 +861,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params.put("where", "(isPrimary=false)"); // note: currently collapses same nodeIds (o2Id x 2) into one - makes sense in terms of File/Folder to avoid duplicate names - response = getAll(getNodeChildrenUrl(f1Id), user1, paging, params, 200); + response = getAll(getNodeChildrenUrl(f1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o2Id, nodes.get(0).getId()); @@ -840,14 +869,14 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // test list filter - isPrimary (/parents) - response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(3, nodes.size()); params = new HashMap<>(1); params.put("where", "(isPrimary=true)"); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f2Id, nodes.get(0).getId()); @@ -855,7 +884,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put("where", "(isPrimary=false)"); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); i = 0; for (Node node : nodes) @@ -881,7 +910,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put("where", "(isPrimary=false and assocType='"+ASSOC_TYPE_CM_PREFERENCE_IMAGE+"')"); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1Id, nodes.get(0).getId()); @@ -894,13 +923,13 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_CONTAINS); - delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, params, 204); + delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, params, 204); - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); @@ -908,41 +937,41 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_PREFERENCE_IMAGE); // remove other secondary child assoc - delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, params, 204); + delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, params, 204); - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200); + response = getAll(getNodeParentsUrl(o2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); { // test removal of multiple secondary child assocs (if assoc type is not specified) - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // re-create secondary child assoc secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f1Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201); // re-create ano' secondary child assoc (different type) between the same two nodes secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_PREFERENCE_IMAGE); - post(getNodeSecondaryChildrenUrl(f1Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201); - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); assertEquals(o2Id, nodes.get(0).getId()); assertEquals(o2Id, nodes.get(1).getId()); // now remove both secondary child assocs - delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, null, 204); + delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 204); - response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); } @@ -951,7 +980,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // sanity check paging of list of secondary children paging = getPaging(0, 100); - response = getAll(getNodeSecondaryChildrenUrl(f3Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f3Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -964,18 +993,18 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n = new Node(); n.setName(childName); n.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(f2Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(f2Id), toJsonAsStringNonNull(n), 201); childIds[j] = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); secChild = new AssocChild(childIds[j], ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f3Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f3Id), toJsonAsStringNonNull(secChild), 201); } int skipCount = 0; int maxItems = 100; paging = getPaging(skipCount, maxItems); - response = getAll(getNodeSecondaryChildrenUrl(f3Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f3Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(childCnt, nodes.size()); @@ -988,7 +1017,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest skipCount = 1; maxItems = 3; paging = getPaging(skipCount, maxItems); - response = getAll(getNodeSecondaryChildrenUrl(f3Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f3Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(maxItems, nodes.size()); assertEquals(childIds[1], nodes.get(0).getId()); @@ -1008,12 +1037,12 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n = new Node(); n.setName(childName); n.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(f4Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(f4Id), toJsonAsStringNonNull(n), 201); String childId = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); paging = getPaging(0, 100); - response = getAll(getNodeParentsUrl(childId), user1, paging, null, 200); + response = getAll(getNodeParentsUrl(childId), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f4Id, nodes.get(0).getId()); @@ -1027,7 +1056,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest parentIds[j] = createFolder(f4Id, parentName).getId(); secChild = new AssocChild(childId, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(parentIds[j]), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(parentIds[j]), toJsonAsStringNonNull(secChild), 201); } int skipCount = 0; @@ -1035,7 +1064,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest int expectedCnt = parentCnt+1; paging = getPaging(skipCount, maxItems); - response = getAll(getNodeParentsUrl(childId), user1, paging, null, 200); + response = getAll(getNodeParentsUrl(childId), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(expectedCnt, nodes.size()); @@ -1056,7 +1085,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest skipCount=0; maxItems=2; paging = getPaging(skipCount, maxItems); - response = getAll(getNodeParentsUrl(childId), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(childId), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(maxItems, nodes.size()); for (Node node : nodes) @@ -1073,7 +1102,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest skipCount=2; maxItems=2; paging = getPaging(skipCount, maxItems); - response = getAll(getNodeParentsUrl(childId), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(childId), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(maxItems, nodes.size()); for (Node node : nodes) @@ -1090,7 +1119,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest skipCount=4; maxItems=2; paging = getPaging(skipCount, maxItems); - response = getAll(getNodeParentsUrl(childId), user1, paging, params, 200); + response = getAll(getNodeParentsUrl(childId), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); for (Node node : nodes) @@ -1110,22 +1139,26 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f1Id), null, toJsonAsStringNonNull(secChild), 401); + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 401); + + setRequestContext(user1); // -ve test - model integrity secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(o1Id), user1, toJsonAsStringNonNull(secChild), 422); + post(getNodeSecondaryChildrenUrl(o1Id), toJsonAsStringNonNull(secChild), 422); // -ve test - duplicate assoc secChild = new AssocChild(o2Id, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f1Id), user1, toJsonAsStringNonNull(secChild), 201); - post(getNodeSecondaryChildrenUrl(f1Id), user1, toJsonAsStringNonNull(secChild), 409); - delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, null, 204); // cleanup + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 409); + delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 204); // cleanup secChild = new AssocChild(o2Id, "cm:unknowntype"); - post(getNodeSecondaryChildrenUrl(f1Id), user1, toJsonAsStringNonNull(secChild), 400); + post(getNodeSecondaryChildrenUrl(f1Id), toJsonAsStringNonNull(secChild), 400); } // @@ -1133,18 +1166,22 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) - getAll(getNodeSecondaryChildrenUrl(f1Id), null, paging, null, 401); - getAll(getNodeParentsUrl(o2Id), null, paging, null, 401); + getAll(getNodeSecondaryChildrenUrl(f1Id), paging, null, 401); + getAll(getNodeParentsUrl(o2Id), paging, null, 401); - getAll(getNodeSecondaryChildrenUrl(UUID.randomUUID().toString()), user1, paging, null, 404); - getAll(getNodeParentsUrl(UUID.randomUUID().toString()), user1, paging, null, 404); + setRequestContext(user1); + + getAll(getNodeSecondaryChildrenUrl(UUID.randomUUID().toString()), paging, null, 404); + getAll(getNodeParentsUrl(UUID.randomUUID().toString()), paging, null, 404); params = new HashMap<>(1); params.put("where", "(assocType='cm:unknownassoctype')"); - getAll(getNodeSecondaryChildrenUrl(o1Id), user1, paging, params, 400); - getAll(getNodeParentsUrl(o1Id), user1, paging, params, 400); + getAll(getNodeSecondaryChildrenUrl(o1Id), paging, params, 400); + getAll(getNodeParentsUrl(o1Id), paging, params, 400); } // @@ -1152,29 +1189,33 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // { + setRequestContext(null); + // unauthenticated - belts-and-braces ;-) - delete(getNodeSecondaryChildrenUrl(f1Id), null, o2Id, null, 401); + delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 401); - delete(getNodeSecondaryChildrenUrl(UUID.randomUUID().toString()), user1, o2Id, null, 404); - delete(getNodeSecondaryChildrenUrl(f1Id), user1, UUID.randomUUID().toString(), null, 404); + setRequestContext(user1); + + delete(getNodeSecondaryChildrenUrl(UUID.randomUUID().toString()), o2Id, null, 404); + delete(getNodeSecondaryChildrenUrl(f1Id), UUID.randomUUID().toString(), null, 404); // nothing to remove - for any assoc type - delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, null, 404); + delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, null, 404); // nothing to remove - for given assoc type params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_PREFERENCE_IMAGE); - delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, params, 404); + delete(getNodeSecondaryChildrenUrl(f1Id), o2Id, params, 404); // unknown assoc type params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, "cm:unknowntype"); - delete(getNodeSecondaryChildrenUrl(o1Id), user1, o2Id, params, 400); + delete(getNodeSecondaryChildrenUrl(o1Id), o2Id, params, 400); // do not allow delete of primary child (via secondary child removal) params = new HashMap<>(1); params.put(PARAM_ASSOC_TYPE, "cm:contains"); - delete(getNodeSecondaryChildrenUrl(f1Id), user1, o1Id, params, 400); + delete(getNodeSecondaryChildrenUrl(f1Id), o1Id, params, 400); } } finally @@ -1218,94 +1259,94 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest f2Id = createFolder(myFolderNodeId, "f2").getId(); f3Id = createFolder(myFolderNodeId, "f3").getId(); - HttpResponse response = getAll(getNodeParentsUrl(f1bId), user1, null, null, 200); + HttpResponse response = getAll(getNodeParentsUrl(f1bId), null, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1Id, nodes.get(0).getId()); - response = getAll(getNodeParentsUrl(f1dId), user1, null, null, 200); + response = getAll(getNodeParentsUrl(f1dId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1cId, nodes.get(0).getId()); - response = getAll(getNodeSourcesUrl(c1eId), user1, null, null, 200); + response = getAll(getNodeSourcesUrl(c1eId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // add some secondary parent/child assocs outside of the hierarchy AssocChild secChild = new AssocChild(f1bId, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f2Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f2Id), toJsonAsStringNonNull(secChild), 201); secChild = new AssocChild(f1bId, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f3Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f3Id), toJsonAsStringNonNull(secChild), 201); secChild = new AssocChild(f1dId, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f2Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f2Id), toJsonAsStringNonNull(secChild), 201); secChild = new AssocChild(f1dId, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f3Id), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f3Id), toJsonAsStringNonNull(secChild), 201); // also add a secondary parent/child assoc within the hierarchy secChild = new AssocChild(f1dId, ASSOC_TYPE_CM_CONTAINS); - post(getNodeSecondaryChildrenUrl(f1bId), user1, toJsonAsStringNonNull(secChild), 201); + post(getNodeSecondaryChildrenUrl(f1bId), toJsonAsStringNonNull(secChild), 201); // add some peer assocs outside of the hierarchy AssocTarget tgt = new AssocTarget(c1eId, ASSOC_TYPE_CM_REFERENCES); - post(getNodeTargetsUrl(f2Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(f2Id), toJsonAsStringNonNull(tgt), 201); tgt = new AssocTarget(c1eId, ASSOC_TYPE_CM_PARTS); - post(getNodeTargetsUrl(f3Id), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(f3Id), toJsonAsStringNonNull(tgt), 201); // also add a peer assoc within the hierarchy tgt = new AssocTarget(c1eId, ASSOC_TYPE_CM_PARTS); - post(getNodeTargetsUrl(f1cId), user1, toJsonAsStringNonNull(tgt), 201); + post(getNodeTargetsUrl(f1cId), toJsonAsStringNonNull(tgt), 201); // double-check the secondary parent/child assocs - response = getAll(getNodeParentsUrl(f1bId), user1, null, null, 200); + response = getAll(getNodeParentsUrl(f1bId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(3, nodes.size()); - response = getAll(getNodeParentsUrl(f1dId), user1, null, null, 200); + response = getAll(getNodeParentsUrl(f1dId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(4, nodes.size()); - response = getAll(getNodeSecondaryChildrenUrl(f2Id), user1, null, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f2Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); List nodeIds = Arrays.asList(new String[]{nodes.get(0).getId(), nodes.get(1).getId()}); assertTrue(nodeIds.contains(f1bId)); assertTrue(nodeIds.contains(f1dId)); - response = getAll(getNodeSecondaryChildrenUrl(f3Id), user1, null, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f3Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); nodeIds = Arrays.asList(new String[]{nodes.get(0).getId(), nodes.get(1).getId()}); assertTrue(nodeIds.contains(f1bId)); assertTrue(nodeIds.contains(f1dId)); - response = getAll(getNodeSecondaryChildrenUrl(f1bId), user1, null, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f1bId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1dId, nodes.get(0).getId()); // double-check the peer assocs - response = getAll(getNodeSourcesUrl(c1eId), user1, null, null, 200); + response = getAll(getNodeSourcesUrl(c1eId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(3, nodes.size()); - response = getAll(getNodeTargetsUrl(f2Id), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f2Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(c1eId, nodes.get(0).getId()); - response = getAll(getNodeTargetsUrl(f3Id), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f3Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(c1eId, nodes.get(0).getId()); - response = getAll(getNodeTargetsUrl(f1cId), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f1cId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(c1eId, nodes.get(0).getId()); @@ -1314,75 +1355,75 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest // ... delete to trashcan/archive ... deleteNode(f1bId); - getSingle(NodesEntityResource.class, user1, f1bId, null, 404); + getSingle(NodesEntityResource.class, f1bId, null, 404); - response = getAll(getNodeTargetsUrl(f2Id), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f2Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(f3Id), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f3Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // ... and then restore again ... - post(URL_DELETED_NODES+"/"+f1bId+"/restore", user1, null, null, 200); + post(URL_DELETED_NODES+"/"+f1bId+"/restore", null, null, 200); // check primary parent-child hierarchy is restored // but not the secondary parents or peer assocs of the deleted nodes (outside or within the hierarchy) - response = getSingle(NodesEntityResource.class, user1, f1bId, null, 200); + response = getSingle(NodesEntityResource.class, f1bId, null, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(f1Id, nodeResp.getParentId()); - response = getSingle(NodesEntityResource.class, user1, f1cId, null, 200); + response = getSingle(NodesEntityResource.class, f1cId, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(f1bId, nodeResp.getParentId()); - response = getSingle(NodesEntityResource.class, user1, f1dId, null, 200); + response = getSingle(NodesEntityResource.class, f1dId, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(f1cId, nodeResp.getParentId()); // secondary child assocs have not been restored - response = getAll(getNodeParentsUrl(f1bId), user1, null, null, 200); + response = getAll(getNodeParentsUrl(f1bId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1Id, nodes.get(0).getId()); - response = getAll(getNodeParentsUrl(f1cId), user1, null, null, 200); + response = getAll(getNodeParentsUrl(f1cId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1bId, nodes.get(0).getId()); - response = getAll(getNodeParentsUrl(f1dId), user1, null, null, 200); + response = getAll(getNodeParentsUrl(f1dId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(f1cId, nodes.get(0).getId()); - response = getAll(getNodeSecondaryChildrenUrl(f2Id), user1, null, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f2Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeSecondaryChildrenUrl(f3Id), user1, null, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f3Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // peer assocs have not been restored - response = getAll(getNodeSourcesUrl(c1eId), user1, null, null, 200); + response = getAll(getNodeSourcesUrl(c1eId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(f1cId), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f1cId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(f2Id), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f2Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); - response = getAll(getNodeTargetsUrl(f3Id), user1, null, null, 200); + response = getAll(getNodeTargetsUrl(f3Id), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); } @@ -1428,7 +1469,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setName("f1"); n.setNodeType(TYPE_CM_FOLDER); n.setAspectNames(Arrays.asList(ASPECT_CM_PREFERENCES)); - HttpResponse response = post(getNodeChildrenUrl(myFolderNodeId), user1, toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getNodeChildrenUrl(myFolderNodeId), toJsonAsStringNonNull(n), 201); String f1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); // create content node @@ -1436,14 +1477,14 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n = new Node(); n.setName(o1Name); n.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(n), 201); String o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); String o2Name = "o2"; n = new Node(); n.setName(o2Name); n.setNodeType(TYPE_CM_CONTENT); - response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(n), 201); String o2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); // create folder node with some assocs @@ -1458,7 +1499,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest AssocTarget tgt = new AssocTarget(o2Id, ASSOC_TYPE_CM_REFERENCES); n.setTargets(Collections.singletonList(tgt)); - response = post(getNodeChildrenUrl(myFolderNodeId), user1, toJsonAsStringNonNull(n), 201); + response = post(getNodeChildrenUrl(myFolderNodeId), toJsonAsStringNonNull(n), 201); String f2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); String f3Id = createFolder(myFolderNodeId, "f3").getId(); @@ -1467,12 +1508,12 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest { Paging paging = getPaging(0, 100); - response = getAll(getNodeSecondaryChildrenUrl(f2Id), user1, paging, null, 200); + response = getAll(getNodeSecondaryChildrenUrl(f2Id), paging, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o1Id, nodes.get(0).getId()); - response = getAll(getNodeTargetsUrl(f2Id), user1, paging, null, 200); + response = getAll(getNodeTargetsUrl(f2Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(o2Id, nodes.get(0).getId()); @@ -1486,7 +1527,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setNodeType(TYPE_CM_FOLDER); AssocChild assocChild = new AssocChild(myFolderNodeId, "cm:contains"); n.setSecondaryChildren(Collections.singletonList(assocChild)); - post(getNodeChildrenUrl(myFolderNodeId), user1, RestApiUtil.toJsonAsStringNonNull(n), 400); + post(getNodeChildrenUrl(myFolderNodeId), RestApiUtil.toJsonAsStringNonNull(n), 400); // -ve tests - missing targetId / childId or assocType @@ -1495,28 +1536,28 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest n.setNodeType(TYPE_CM_FOLDER); assocChild = new AssocChild(null, ASSOC_TYPE_CM_CONTAINS); n.setSecondaryChildren(Collections.singletonList(assocChild)); - post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400); + post(getNodeChildrenUrl(f3Id), RestApiUtil.toJsonAsStringNonNull(n), 400); n = new Node(); n.setName("my-folder"); n.setNodeType(TYPE_CM_FOLDER); assocChild = new AssocChild(f2Id, null); n.setSecondaryChildren(Collections.singletonList(assocChild)); - post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400); + post(getNodeChildrenUrl(f3Id), RestApiUtil.toJsonAsStringNonNull(n), 400); n = new Node(); n.setName("my-folder"); n.setNodeType(TYPE_CM_FOLDER); tgt = new AssocTarget(null, ASSOC_TYPE_CM_REFERENCES); n.setTargets(Collections.singletonList(tgt)); - post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400); + post(getNodeChildrenUrl(f3Id), RestApiUtil.toJsonAsStringNonNull(n), 400); n = new Node(); n.setName("my-folder"); n.setNodeType(TYPE_CM_FOLDER); tgt = new AssocTarget(f2Id, null); n.setTargets(Collections.singletonList(tgt)); - post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400); + post(getNodeChildrenUrl(f3Id), RestApiUtil.toJsonAsStringNonNull(n), 400); } finally { diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeVersionsApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeVersionsApiTest.java index e0203ed570..30ecd14e54 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeVersionsApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeVersionsApiTest.java @@ -52,7 +52,7 @@ import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull import static org.junit.Assert.*; /** - * API tests for Node Versions (File Version History) + * V1 REST API tests for Node Versions (File Version History) * * {@literal :/alfresco/api//public/alfresco/versions/1/nodes/{nodeId}/versions * @@ -148,13 +148,13 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest Document dUpdate = new Document(); dUpdate.setAspectNames(aspectNames); - HttpResponse response = put(URL_NODES, user1, docId, toJsonAsStringNonNull(dUpdate), null, 200); + HttpResponse response = put(URL_NODES, docId, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertFalse(documentResp.getAspectNames().contains("cm:versionable")); assertNull(documentResp.getProperties()); // no properties (ie. no "cm:versionLabel") // check no version history - response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + response = getAll(getNodeVersionsUrl(docId), null, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -179,11 +179,11 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile); - putBinary(getNodeContentUrl(docId), user1, payload, null, null, 200); + putBinary(getNodeContentUrl(docId), payload, null, null, 200); } // check no version history - response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + response = getAll(getNodeVersionsUrl(docId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); } @@ -244,7 +244,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals(6, verCnt); // check version history count - HttpResponse response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + HttpResponse response = getAll(getNodeVersionsUrl(docId), null, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(verCnt, nodes.size()); } @@ -286,66 +286,74 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals("1.3", versionLabel); // check version history count - HttpResponse response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + HttpResponse response = getAll(getNodeVersionsUrl(docId), null, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(cnt, nodes.size()); { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) - delete(getNodeVersionsUrl(docId), null, "1.0", null, 401); + delete(getNodeVersionsUrl(docId), "1.0", null, 401); + + setRequestContext(user1); // -ve test - unknown nodeId - delete(getNodeVersionsUrl("dummy"), user1, "1.0", null, 404); + delete(getNodeVersionsUrl("dummy"), "1.0", null, 404); // -ve test - unknown versionId - delete(getNodeVersionsUrl(docId), user1, "15.0", null, 404); + delete(getNodeVersionsUrl(docId), "15.0", null, 404); + + setRequestContext(user2); // -ve test - permission denied (on version other than most recent) - delete(getNodeVersionsUrl(docId), user2, "1.0", null, 403); + delete(getNodeVersionsUrl(docId), "1.0", null, 403); // -ve test - permission denied (on most recent version) - delete(getNodeVersionsUrl(docId), user2, "1.3", null, 403); + delete(getNodeVersionsUrl(docId), "1.3", null, 403); } - delete(getNodeVersionsUrl(docId), user1, "1.0", null, 204); + setRequestContext(user1); - response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + delete(getNodeVersionsUrl(docId), "1.0", null, 204); + + response = getAll(getNodeVersionsUrl(docId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(cnt - 1, nodes.size()); // check live node (version label does not change) - response = getSingle(URL_NODES, user1, docId, 200); + response = getSingle(URL_NODES, docId, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals("1.3", nodeResp.getProperties().get("cm:versionLabel")); - delete(getNodeVersionsUrl(docId), user1, "1.3", null, 204); + delete(getNodeVersionsUrl(docId), "1.3", null, 204); - response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + response = getAll(getNodeVersionsUrl(docId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(cnt - 2, nodes.size()); // check live node (version label changes) - response = getSingle(URL_NODES, user1, docId, 200); + response = getSingle(URL_NODES, docId, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals("1.2", nodeResp.getProperties().get("cm:versionLabel")); - delete(getNodeVersionsUrl(docId), user1, "1.1", null, 204); + delete(getNodeVersionsUrl(docId), "1.1", null, 204); - response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + response = getAll(getNodeVersionsUrl(docId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(cnt - 3, nodes.size()); // check live node (version label does not change) - response = getSingle(URL_NODES, user1, docId, 200); + response = getSingle(URL_NODES, docId, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals("1.2", nodeResp.getProperties().get("cm:versionLabel")); // -ve test - cannot delete last version (via delete version api call) (see REPO-835 & REPO-834) - delete(getNodeVersionsUrl(docId), user1, "1.2", null, 422); + delete(getNodeVersionsUrl(docId), "1.2", null, 422); /* note: currently we cannot delete last version so this is not applicable // check live node - removing last version does not (currently) remove versionable aspect - response = getSingle(URL_NODES, user1, docId, 200); + response = getSingle(URL_NODES, docId, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); Map props = nodeResp.getProperties(); @@ -356,7 +364,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest } */ - response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + response = getAll(getNodeVersionsUrl(docId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals("1.2", nodes.get(0).getId()); @@ -367,14 +375,14 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile); - response = putBinary(getNodeContentUrl(docId), user1, payload, null, null, 200); + response = putBinary(getNodeContentUrl(docId), payload, null, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); assertEquals("1.3", nodeResp.getProperties().get("cm:versionLabel")); assertEquals("MINOR", nodeResp.getProperties().get("cm:versionType")); // remove versionable aspect (this will clear the history and disable versioning) - response = getSingle(URL_NODES, user1, docId, 200); + response = getSingle(URL_NODES, docId, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); List aspectNamesToKeep = new ArrayList<>(); @@ -384,7 +392,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest Node nUpdate = new Node(); nUpdate.setAspectNames(aspectNamesToKeep); - response = put(URL_NODES, user1, docId, toJsonAsStringNonNull(nUpdate), null, 200); + response = put(URL_NODES, docId, toJsonAsStringNonNull(nUpdate), null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertFalse(nodeResp.getAspectNames().contains("cm:versionable")); Map props = nodeResp.getProperties(); @@ -394,7 +402,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertNull(props.get("cm:versionType")); } - response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + response = getAll(getNodeVersionsUrl(docId), null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -403,12 +411,12 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest inputStream = new ByteArrayInputStream(textContent.getBytes()); txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); payload = new PublicApiHttpClient.BinaryPayload(txtFile); - response = putBinary(getNodeContentUrl(docId), user1, payload, null, null, 200); + response = putBinary(getNodeContentUrl(docId), payload, null, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertFalse(nodeResp.getAspectNames().contains("cm:versionable")); // re-enable versioning (default model properties should cause initial version to be created as 1.0) - response = getSingle(URL_NODES, user1, docId, 200); + response = getSingle(URL_NODES, docId, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); aspectNamesToKeep = new ArrayList<>(); aspectNamesToKeep.addAll(nodeResp.getAspectNames()); @@ -417,7 +425,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest nUpdate = new Node(); nUpdate.setAspectNames(aspectNamesToKeep); - response = put(URL_NODES, user1, docId, toJsonAsStringNonNull(nUpdate), null, 200); + response = put(URL_NODES, docId, toJsonAsStringNonNull(nUpdate), null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); props = nodeResp.getProperties(); @@ -425,7 +433,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals("MAJOR", props.get("cm:versionType")); // double-check content - response = getSingle(getNodeVersionsUrl(docId), user1, "1.0/content", null, 200); + response = getSingle(getNodeVersionsUrl(docId), "1.0/content", null, 200); assertEquals(textContent, response.getResponse()); // Update again .. @@ -434,7 +442,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); payload = new PublicApiHttpClient.BinaryPayload(txtFile); - response = putBinary(getNodeContentUrl(docId), user1, payload, null, null, 200); + response = putBinary(getNodeContentUrl(docId), payload, null, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); props = nodeResp.getProperties(); @@ -442,7 +450,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals("MINOR", props.get("cm:versionType")); // double-check content - response = getSingle(getNodeVersionsUrl(docId), user1, "1.1/content", null, 200); + response = getSingle(getNodeVersionsUrl(docId), "1.1/content", null, 200); assertEquals(textContent, response.getResponse()); } finally @@ -530,7 +538,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals(currentVersionLabel, documentResp.getProperties().get("cm:versionLabel")); // double-check - get version node info - HttpResponse response = getSingle(getNodeVersionsUrl(docId), userId, currentVersionLabel, null, 200); + HttpResponse response = getSingle(getNodeVersionsUrl(docId), currentVersionLabel, null, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(currentVersionLabel, nodeResp.getProperties().get("cm:versionLabel")); assertEquals((expectedMajorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties().get("cm:versionType")); @@ -603,7 +611,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile); - HttpResponse response = putBinary(getNodeContentUrl(contentNodeId), userId, payload, null, params, 200); + HttpResponse response = putBinary(getNodeContentUrl(contentNodeId), payload, null, params, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); @@ -612,7 +620,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals((majorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties().get("cm:versionType")); // double-check - get version node info - response = getSingle(getNodeVersionsUrl(contentNodeId), userId, currentVersionLabel, null, 200); + response = getSingle(getNodeVersionsUrl(contentNodeId), currentVersionLabel, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(currentVersionLabel, nodeResp.getProperties().get("cm:versionLabel")); assertEquals((majorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties().get("cm:versionType")); @@ -665,7 +673,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest String versionId = majorVersion+"."+minorVersion; - HttpResponse response = getSingle(URL_NODES, user1, d1Id, 200); + HttpResponse response = getSingle(URL_NODES, d1Id, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); assertEquals(versionId, nodeResp.getProperties().get("cm:versionLabel")); @@ -675,14 +683,14 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest Map params = new HashMap<>(); params.put("include", "properties"); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, params, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, params, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(verCnt, nodes.size()); assertEquals(versionId, nodes.get(0).getProperties().get("cm:versionLabel")); assertEquals("MAJOR", nodes.get(0).getProperties().get("cm:versionType")); // get version info - response = getSingle(getNodeVersionsUrl(d1Id), user1, versionId, null, 200); + response = getSingle(getNodeVersionsUrl(d1Id), versionId, null, 200); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(versionId, node.getProperties().get("cm:versionLabel")); assertEquals("MAJOR", node.getProperties().get("cm:versionType")); @@ -700,25 +708,25 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile); - putBinary(getNodeContentUrl(d1Id), user1, payload, null, null, 200); + putBinary(getNodeContentUrl(d1Id), payload, null, null, 200); versionId = majorVersion+"."+minorVersion; // get live node - response = getSingle(URL_NODES, user1, d1Id, 200); + response = getSingle(URL_NODES, d1Id, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); assertEquals(versionId, nodeResp.getProperties().get("cm:versionLabel")); assertEquals("MINOR", nodeResp.getProperties().get("cm:versionType")); // get version node info - response = getSingle(getNodeVersionsUrl(d1Id), user1, versionId, null, 200); + response = getSingle(getNodeVersionsUrl(d1Id), versionId, null, 200); node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(versionId, node.getProperties().get("cm:versionLabel")); assertEquals("MINOR", node.getProperties().get("cm:versionType")); // check version history count - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, null, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(verCnt, nodes.size()); } @@ -728,7 +736,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // check total version count - also get properties so that we can check version label etc params = new HashMap<>(); params.put("include", "properties"); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, params, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(totalVerCnt, nodes.size()); @@ -739,23 +747,27 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest { // -ve tests - getSingle(NodesEntityResource.class, user1, d1Id, null, 404); - getAll(getNodeVersionsUrl(d1Id), user1, null, null, 404); + getSingle(NodesEntityResource.class, d1Id, null, 404); + getAll(getNodeVersionsUrl(d1Id), null, null, 404); } // ... and then restore again - post(URL_DELETED_NODES+"/"+d1Id+"/restore", user1, null, null, 200); + post(URL_DELETED_NODES+"/"+d1Id+"/restore", null, null, 200); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, null, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(totalVerCnt, nodes.size()); { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) - getAll(getNodeVersionsUrl(d1Id), null, paging, null, 401); + getAll(getNodeVersionsUrl(d1Id), paging, null, 401); + + setRequestContext(user1); // -ve test - unknown nodeId - getAll(getNodeVersionsUrl("dummy"), user1, paging, null, 404); + getAll(getNodeVersionsUrl("dummy"), paging, null, 404); } } finally @@ -819,13 +831,13 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put(Nodes.PARAM_VERSION_COMMENT, updateVerCommentSuffix+verCnt); - putBinary(getNodeContentUrl(d1Id), user1, payload, null, params, 200); + putBinary(getNodeContentUrl(d1Id), payload, null, params, 200); } // check version history count - also get properties so that we can check version label etc params = new HashMap<>(); params.put("include", "properties"); - HttpResponse response = getAll(getNodeVersionsUrl(d1Id), user1, null, params, 200); + HttpResponse response = getAll(getNodeVersionsUrl(d1Id), null, params, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(verCnt, nodes.size()); @@ -846,7 +858,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest versionOptions.setMajorVersion(true); versionOptions.setComment(revertVerCommentSuffix+i); - post(getNodeVersionRevertUrl(d1Id, revertVersionId), user1, toJsonAsStringNonNull(versionOptions), null, 200); + post(getNodeVersionRevertUrl(d1Id, revertVersionId), toJsonAsStringNonNull(versionOptions), null, 200); verCnt++; revertMinorVersion++; @@ -857,7 +869,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // check version history count - also get properties so that we can check version label etc params = new HashMap<>(); params.put("include", "properties"); - response = getAll(getNodeVersionsUrl(d1Id), user1, null, params, 200); + response = getAll(getNodeVersionsUrl(d1Id), null, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(verCnt, nodes.size()); @@ -871,20 +883,25 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest checkVersionHistoryAndContent(d1Id, originalUpdatedNodes, updateCnt+1, textContentSuffix, updateVerCommentSuffix, 1, minorVersion, false); // Currently, we also allow the most recent version to be reverted (ie. not disallowed by underlying VersionService) - post(getNodeVersionRevertUrl(d1Id, majorVersion+".0"), user1, "{}", null, 200); + post(getNodeVersionRevertUrl(d1Id, majorVersion+".0"), "{}", null, 200); { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) - post(getNodeVersionRevertUrl(d1Id, "1.0"), null, "{}", null, 401); + post(getNodeVersionRevertUrl(d1Id, "1.0"), "{}", null, 401); + + setRequestContext(user1); // -ve test - unknown nodeId - post(getNodeVersionRevertUrl("dummy", "1.0"), user1, "{}", null, 404); + post(getNodeVersionRevertUrl("dummy", "1.0"), "{}", null, 404); // -ve test - unknown versionId - post(getNodeVersionRevertUrl(d1Id, "15.0"), user1, "{}", null, 404); + post(getNodeVersionRevertUrl(d1Id, "15.0"), "{}", null, 404); // -ve test - permission denied - post(getNodeVersionRevertUrl(d1Id, "1.0"), user2, "{}", null, 403); + setRequestContext(user2); + post(getNodeVersionRevertUrl(d1Id, "1.0"), "{}", null, 403); } } finally @@ -926,7 +943,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals((verCommentSuffix != null ? verCommentSuffix+verCnt : null), versionNode.getVersionComment()); // Download version content - by default with Content-Disposition header - HttpResponse response = getSingle(getNodeVersionsUrl(docId), user1, versionId+"/content", null, 200); + HttpResponse response = getSingle(getNodeVersionsUrl(docId), versionId+"/content", null, 200); String textContent = response.getResponse(); assertEquals(textContentSuffix+verCnt, textContent); @@ -975,10 +992,10 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest Node n = new Node(); n.setName("d1"); n.setNodeType(TYPE_CM_CONTENT); - HttpResponse response = post(getNodeChildrenUrl(f1Id), user1, toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(n), 201); String d1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); - response = getSingle(URL_NODES, user1, d1Id, 200); + response = getSingle(URL_NODES, d1Id, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertFalse(nodeResp.getAspectNames().contains("cm:versionable")); @@ -986,12 +1003,12 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // empty list - before - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, null, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); // note: we do not disallow listing version history on non-content node - however currently no API method to version say a folder - response = getAll(getNodeVersionsUrl(f1Id), user1, paging, null, 200); + response = getAll(getNodeVersionsUrl(f1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -1008,15 +1025,15 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile); - putBinary(getNodeContentUrl(d1Id), user1, payload, null, null, 200); + putBinary(getNodeContentUrl(d1Id), payload, null, null, 200); verCnt++; - response = getSingle(URL_NODES, user1, d1Id, 200); + response = getSingle(URL_NODES, d1Id, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertFalse(nodeResp.getAspectNames().contains("cm:versionable")); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, null, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); } @@ -1025,20 +1042,20 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // note: alternatively can use version params ("comment" &/or "majorVersion") on update (see separate test below) Node nodeUpdate = new Node(); nodeUpdate.setAspectNames(Collections.singletonList("cm:versionable")); - put(URL_NODES, user1, d1Id, toJsonAsStringNonNull(nodeUpdate), null, 200); + put(URL_NODES, d1Id, toJsonAsStringNonNull(nodeUpdate), null, 200); String versionId = "1.0"; Map params = new HashMap<>(); params.put("include", "properties"); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, params, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(1, nodes.size()); assertEquals(versionId, nodes.get(0).getProperties().get("cm:versionLabel")); assertEquals("MAJOR", nodes.get(0).getProperties().get("cm:versionType")); // get version info - response = getSingle(getNodeVersionsUrl(d1Id), user1, versionId, null, 200); + response = getSingle(getNodeVersionsUrl(d1Id), versionId, null, 200); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(versionId, node.getProperties().get("cm:versionLabel")); assertEquals("MAJOR", node.getProperties().get("cm:versionType")); @@ -1053,18 +1070,18 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile); - putBinary(getNodeContentUrl(d1Id), user1, payload, null, null, 200); + putBinary(getNodeContentUrl(d1Id), payload, null, null, 200); verCnt++; // get version info versionId = "1."+i; - response = getSingle(getNodeVersionsUrl(d1Id), user1, versionId, null, 200); + response = getSingle(getNodeVersionsUrl(d1Id), versionId, null, 200); node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(versionId, node.getProperties().get("cm:versionLabel")); assertEquals("MINOR", node.getProperties().get("cm:versionType")); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, null, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(i+1, nodes.size()); } @@ -1075,7 +1092,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(); params.put("include", "properties"); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, params, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(totalVerCnt, nodes.size()); @@ -1086,14 +1103,14 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // -ve tests { - getSingle(NodesEntityResource.class, user1, d1Id, null, 404); - getAll(getNodeVersionsUrl(d1Id), user1, null, null, 404); + getSingle(NodesEntityResource.class, d1Id, null, 404); + getAll(getNodeVersionsUrl(d1Id), null, null, 404); } // ... and then restore again - post(URL_DELETED_NODES+"/"+d1Id+"/restore", user1, null, null, 200); + post(URL_DELETED_NODES+"/"+d1Id+"/restore", null, null, 200); - response = getAll(getNodeVersionsUrl(d1Id), user1, paging, null, 200); + response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(cntAfter+1, nodes.size()); @@ -1102,11 +1119,15 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // { + setRequestContext(null); + // -ve test - unauthenticated - belts-and-braces ;-) - getAll(getNodeVersionsUrl(d1Id), null, paging, null, 401); + getAll(getNodeVersionsUrl(d1Id), paging, null, 401); - // -ve test - unauthenticated - belts-and-braces ;-) - getAll(getNodeVersionsUrl("dummy"), user1, paging, null, 404); + setRequestContext(user1); + + // -ve test - unknown node + getAll(getNodeVersionsUrl("dummy"), paging, null, 404); } } finally @@ -1138,7 +1159,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest d1.setNodeType(TYPE_CM_CONTENT); // create *empty* text file - as of now, versioning is not enabled by default - HttpResponse response = post(getNodeChildrenUrl(myNodeId), user1, toJsonAsStringNonNull(d1), 201); + HttpResponse response = post(getNodeChildrenUrl(myNodeId), toJsonAsStringNonNull(d1), 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String docId = documentResp.getId(); @@ -1262,7 +1283,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest Document dUpdate = new Document(); dUpdate.setAspectNames(aspectNames); - response = put(URL_NODES, user1, docId, toJsonAsStringNonNull(dUpdate), null, 200); + response = put(URL_NODES, docId, toJsonAsStringNonNull(dUpdate), null, 200); documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertFalse(documentResp.getAspectNames().contains("cm:versionable")); assertNull(documentResp.getProperties()); // no properties (ie. no "cm:versionLabel") @@ -1311,7 +1332,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest assertEquals("1.5", versionLabel); // 1.0, 1.1, ... 1.5 // check version history count (note: no paging => default max items => 100) - HttpResponse response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200); + HttpResponse response = getAll(getNodeVersionsUrl(docId), null, null, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(cnt, nodes.size()); @@ -1319,7 +1340,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // SkipCount=0,MaxItems=2 Paging paging = getPaging(0, 2); - response = getAll(getNodeVersionsUrl(docId), user1, paging, 200); + response = getAll(getNodeVersionsUrl(docId), paging, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); PublicApiClient.ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse()); @@ -1331,7 +1352,7 @@ public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest // SkipCount=2,MaxItems=3 paging = getPaging(2, 3); - response = getAll(getNodeVersionsUrl(docId), user1, paging, 200); + response = getAll(getNodeVersionsUrl(docId), paging, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(3, nodes.size()); expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse()); diff --git a/source/test-java/org/alfresco/rest/api/tests/QueriesApiTest.java b/source/test-java/org/alfresco/rest/api/tests/QueriesApiTest.java index cc55499d1b..9e5910b839 100644 --- a/source/test-java/org/alfresco/rest/api/tests/QueriesApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/QueriesApiTest.java @@ -51,7 +51,8 @@ import java.util.Map; import static org.junit.Assert.*; /** - * API tests for: +* V1 REST API tests for pre-defined 'live' search Queries + * *
        *
      • {@literal :/alfresco/api//public/alfresco/versions/1/queries}
      • *
      @@ -117,7 +118,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params.put(Queries.PARAM_TERM, testTerm); // Try to get nodes with search term 'abc123' - assume clean repo (ie. none to start with) - HttpResponse response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + HttpResponse response = getAll(URL_QUERIES_LSN, paging, params, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -205,7 +206,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest // Search hits based on FTS (content) and also name (in case of folder nodes) params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testTerm); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, null); for (Node node : nodes) @@ -220,7 +221,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("include", "aspectNames,properties,path,isLink"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, null); for (Node node : nodes) @@ -235,7 +236,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put(Queries.PARAM_NODE_TYPE, "cm:folder"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, f3NodeIds, null); @@ -243,7 +244,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put(Queries.PARAM_ROOT_NODE_ID, Nodes.PATH_ROOT); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, null); @@ -251,7 +252,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put(Queries.PARAM_ROOT_NODE_ID, Nodes.PATH_SHARED); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(0, nodes.size()); @@ -259,7 +260,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put(Queries.PARAM_ROOT_NODE_ID, f1Id); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, f1NodeIds, null); @@ -267,7 +268,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put(Queries.PARAM_ROOT_NODE_ID, f2Id); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, f2NodeIds, null); @@ -275,7 +276,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, name+"*"); params.put(Queries.PARAM_ROOT_NODE_ID, Nodes.PATH_MY); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, null); @@ -283,7 +284,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest String term = name+String.format("%05d", 1)+name; params = new HashMap<>(1); params.put(Queries.PARAM_TERM, "\""+term+"\""); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(3, nodes.size()); for (Node node : nodes) @@ -302,7 +303,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest term = name+String.format("%05d", 1)+name+txtSuffix; params = new HashMap<>(1); params.put(Queries.PARAM_TERM, term); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); @@ -310,7 +311,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest term = name+String.format("%05d", 1)+name+txtSuffix; params = new HashMap<>(1); params.put(Queries.PARAM_TERM, "\""+term+"\""); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(2, nodes.size()); @@ -319,7 +320,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, "\""+term+"\""); params.put("include", "properties"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(3, nodes.size()); assertEquals(term, nodes.get(0).getProperties().get("cm:title")); @@ -331,7 +332,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, "\""+term+"\""); params.put("include", "properties"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(3, nodes.size()); assertEquals(term, nodes.get(0).getProperties().get("cm:description")); @@ -341,37 +342,38 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest // TODO sanity check tag search // -ve test - no params (ie. no term) - getAll(URL_QUERIES_LSN, user1, paging, null, 400); + getAll(URL_QUERIES_LSN, paging, null, 400); // -ve test - no term params = new HashMap<>(1); params.put(Queries.PARAM_ROOT_NODE_ID, f1Id); - getAll(URL_QUERIES_LSN, user1, paging, params, 400); + getAll(URL_QUERIES_LSN, paging, params, 400); // -ve test - unknown root node id params = new HashMap<>(2); params.put(Queries.PARAM_TERM, "abc"); params.put(Queries.PARAM_ROOT_NODE_ID, "dummy"); - getAll(URL_QUERIES_LSN, user1, paging, params, 404); + getAll(URL_QUERIES_LSN, paging, params, 404); // -ve test - unknown node type params = new HashMap<>(2); params.put(Queries.PARAM_TERM, "abc"); params.put(Queries.PARAM_NODE_TYPE, "cm:dummy"); - getAll(URL_QUERIES_LSN, user1, paging, params, 400); + getAll(URL_QUERIES_LSN, paging, params, 400); // -ve test - term too short params = new HashMap<>(1); params.put(Queries.PARAM_TERM, "ab"); - getAll(URL_QUERIES_LSN, user1, paging, params, 400); + getAll(URL_QUERIES_LSN, paging, params, 400); // -ve test - term is still too short params = new HashMap<>(1); params.put(Queries.PARAM_TERM, " \"a b *\" "); - getAll(URL_QUERIES_LSN, user1, paging, params, 400); + getAll(URL_QUERIES_LSN, paging, params, 400); // -ve test - unauthenticated - belts-and-braces ;-) - getAll(URL_QUERIES_LSN, null, paging, params, 401); + setRequestContext(null); + getAll(URL_QUERIES_LSN, paging, params, 401); } finally { @@ -474,7 +476,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest // default sort order (modifiedAt desc) params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testTerm); - HttpResponse response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + HttpResponse response = getAll(URL_QUERIES_LSN, paging, params, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, false); @@ -482,7 +484,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "modifiedAt asc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, false); @@ -490,7 +492,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "modifiedAt desc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, true); @@ -498,7 +500,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "createdAt asc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, true); @@ -506,7 +508,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "createdAt desc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, false); @@ -514,7 +516,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "name asc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, idsSortedByNameAsc, true); @@ -522,7 +524,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "name desc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, idsSortedByNameAsc, false); @@ -530,7 +532,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "name desc, createdAt asc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, idsSortedByNameDescCreatedAtAsc, false); @@ -538,7 +540,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "name asc, createdAt desc"); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, idsSortedByNameDescCreatedAtAsc, true); @@ -548,21 +550,21 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testTerm); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, false); paging = getPaging(0, f1Count); params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testTerm); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, f1NodeIds, false); paging = getPaging(f1Count, f2Count); params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testTerm); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, f2NodeIds, false); @@ -573,11 +575,11 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest params = new HashMap<>(2); params.put(Queries.PARAM_TERM, testTerm); params.put("orderBy", "invalid asc"); - getAll(URL_QUERIES_LSN, user1, paging, params, 400); + getAll(URL_QUERIES_LSN, paging, params, 400); // -ve test - unauthenticated - belts-and-braces ;-) setRequestContext(null); - getAll(URL_QUERIES_LSN, null, paging, params, 401); + getAll(URL_QUERIES_LSN, paging, params, 401); } finally { @@ -659,19 +661,19 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest Map params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testTag); - HttpResponse response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + HttpResponse response = getAll(URL_QUERIES_LSN, paging, params, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, allIds, null); params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testFileTag); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, f1NodeIds, null); params = new HashMap<>(1); params.put(Queries.PARAM_TERM, testFolderTag); - response = getAll(URL_QUERIES_LSN, user1, paging, params, 200); + response = getAll(URL_QUERIES_LSN, paging, params, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); checkNodeIds(nodes, f2NodeIds, null); } diff --git a/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java b/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java index 6c2381c1c9..d6c2ed87a6 100644 --- a/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java @@ -69,7 +69,7 @@ import java.util.Map; import java.util.UUID; /** - * Renditions API tests. + * V1 REST API tests for Renditions * * @author Jamal Kaabi-Mofrad */ @@ -131,13 +131,13 @@ public class RenditionsTest extends AbstractBaseApiTest MultiPartRequest reqBody = multiPartBuilder.build(); // Upload quick.pdf file into 'folder' - HttpResponse response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String contentNodeId = document.getId(); Paging paging = getPaging(0, 50); // List all available renditions (includes those that have been created and those that are yet to be created) - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200); List renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertTrue(renditions.size() >= 5); Rendition docLib = getRendition(renditions, "doclib"); @@ -154,13 +154,13 @@ public class RenditionsTest extends AbstractBaseApiTest Map params = new HashMap<>(1); params.put("where", "(status='NOT_CREATED')"); // List only the NOT_CREATED renditions - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertTrue(renditions.size() >= 5); params.put("where", "(status='CREATED')"); // List only the CREATED renditions - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals("There is no rendition created yet.", 0, renditions.size()); @@ -168,7 +168,7 @@ public class RenditionsTest extends AbstractBaseApiTest // SkipCount=0,MaxItems=2 paging = getPaging(0, 2); // List all available renditions - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals(2, renditions.size()); ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse()); @@ -181,7 +181,7 @@ public class RenditionsTest extends AbstractBaseApiTest // SkipCount=2,MaxItems=3 paging = getPaging(2, 3); // List all available renditions - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals(3, renditions.size()); expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse()); @@ -195,7 +195,7 @@ public class RenditionsTest extends AbstractBaseApiTest // List all available renditions (includes those that have been created and those that are yet to be created) paging = getPaging(0, 50); - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertTrue(renditions.size() >= 5); docLib = getRendition(renditions, "doclib"); @@ -209,13 +209,13 @@ public class RenditionsTest extends AbstractBaseApiTest assertTrue(contentInfo.getSizeInBytes() > 0); // List only the CREATED renditions - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals("Should've only returned the 'doclib' rendition.", 1, renditions.size()); params.put("where", "(status='NOT_CREATED')"); // List only the NOT_CREATED renditions - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertTrue(renditions.size() > 0); docLib = getRendition(renditions, "doclib"); @@ -223,31 +223,31 @@ public class RenditionsTest extends AbstractBaseApiTest // Test returned renditions are ordered (natural sort order) // List all renditions - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertTrue(Ordering.natural().isOrdered(renditions)); // Try again to make sure the ordering wasn't coincidental - response = getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200); + response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertTrue(Ordering.natural().isOrdered(renditions)); // nodeId in the path parameter does not represent a file - getAll(getNodeRenditionsUrl(folder_Id), userOneN1.getId(), paging, params, 400); + getAll(getNodeRenditionsUrl(folder_Id), paging, params, 400); // nodeId in the path parameter does not exist - getAll(getNodeRenditionsUrl(UUID.randomUUID().toString()), userOneN1.getId(), paging, params, 404); + getAll(getNodeRenditionsUrl(UUID.randomUUID().toString()), paging, params, 404); // Create a node without any content String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId()); - getAll(getNodeRenditionsUrl(emptyContentNodeId), userOneN1.getId(), paging, params, 200); + getAll(getNodeRenditionsUrl(emptyContentNodeId), paging, params, 200); // Invalid status value params.put("where", "(status='WRONG')"); - getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 400); + getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 400); // Invalid filter (only 'status' is supported) params.put("where", "(id='doclib')"); - getAll(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 400); + getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 400); } /** @@ -271,12 +271,12 @@ public class RenditionsTest extends AbstractBaseApiTest MultiPartRequest reqBody = multiPartBuilder.build(); // Upload quick.pdf file into 'folder' - HttpResponse response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String contentNodeId = document.getId(); // Get rendition (not created yet) information for node - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib", 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), "doclib", 200); Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class); assertNotNull(rendition); assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus()); @@ -299,17 +299,17 @@ public class RenditionsTest extends AbstractBaseApiTest assertTrue(contentInfo.getSizeInBytes() > 0); // nodeId in the path parameter does not represent a file - getSingle(getNodeRenditionsUrl(folder_Id), userOneN1.getId(), "doclib", 400); + getSingle(getNodeRenditionsUrl(folder_Id), "doclib", 400); // nodeId in the path parameter does not exist - getSingle(getNodeRenditionsUrl(UUID.randomUUID().toString()), userOneN1.getId(), "doclib", 404); + getSingle(getNodeRenditionsUrl(UUID.randomUUID().toString()), "doclib", 404); // renditionId in the path parameter is not registered/available - getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), ("renditionId" + System.currentTimeMillis()), 404); + getSingle(getNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis()), 404); // Create a node without any content String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId()); - getSingle(getNodeRenditionsUrl(emptyContentNodeId), userOneN1.getId(), "doclib", 404); // TODO different results local (200) than build (404) ? + getSingle(getNodeRenditionsUrl(emptyContentNodeId), "doclib", 404); // TODO different results local (200) than build (404) ? // Create multipart request String jpgFileName = "quick.jpg"; @@ -319,19 +319,19 @@ public class RenditionsTest extends AbstractBaseApiTest .build(); // Upload quick.jpg file into 'folder' - response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document jpgImage = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String jpgImageNodeId = jpgImage.getId(); // List all available renditions (includes those that have been created and those that are yet to be created) - response = getAll(getNodeRenditionsUrl(jpgImageNodeId), userOneN1.getId(), getPaging(0, 50), 200); + response = getAll(getNodeRenditionsUrl(jpgImageNodeId), getPaging(0, 50), 200); List renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); // Check there is no pdf rendition is available for the jpg file Rendition pdf = getRendition(renditions, "pdf"); assertNull(pdf); // The renditionId (pdf) is registered but it is not applicable for the node's mimeType - getSingle(getNodeRenditionsUrl(jpgImageNodeId), userOneN1.getId(), "pdf", 404); + getSingle(getNodeRenditionsUrl(jpgImageNodeId), "pdf", 404); } /** @@ -355,12 +355,12 @@ public class RenditionsTest extends AbstractBaseApiTest MultiPartRequest reqBody = multiPartBuilder.build(); // Upload quick.pdf file into 'folder' - HttpResponse response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String contentNodeId = document.getId(); // Get rendition (not created yet) information for node - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "imgpreview", 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), "imgpreview", 200); Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class); assertNotNull(rendition); assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus()); @@ -378,7 +378,7 @@ public class RenditionsTest extends AbstractBaseApiTest // -ve Tests // The rendition requested already exists - response = post(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), toJsonAsString(new Rendition().setId("imgpreview")), 409); + response = post(getNodeRenditionsUrl(contentNodeId), toJsonAsString(new Rendition().setId("imgpreview")), 409); ExpectedErrorResponse errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse()); assertNotNull(errorResponse); assertNotNull(errorResponse.getErrorKey()); @@ -390,10 +390,10 @@ public class RenditionsTest extends AbstractBaseApiTest // Create 'doclib' rendition request Rendition renditionRequest = new Rendition().setId("doclib"); // nodeId in the path parameter does not represent a file - post(getNodeRenditionsUrl(folder_Id), userOneN1.getId(), toJsonAsString(renditionRequest), 400); + post(getNodeRenditionsUrl(folder_Id), toJsonAsString(renditionRequest), 400); // nodeId in the path parameter does not exist - response = post(getNodeRenditionsUrl(UUID.randomUUID().toString()), userOneN1.getId(), toJsonAsString(renditionRequest), 404); + response = post(getNodeRenditionsUrl(UUID.randomUUID().toString()), toJsonAsString(renditionRequest), 404); // EntityNotFoundException errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse()); assertNotNull(errorResponse); @@ -405,19 +405,19 @@ public class RenditionsTest extends AbstractBaseApiTest // renditionId is not registered final String randomRenditionId = "renditionId" + System.currentTimeMillis(); - post(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), toJsonAsString(new Rendition().setId(randomRenditionId)), 404); + post(getNodeRenditionsUrl(contentNodeId), toJsonAsString(new Rendition().setId(randomRenditionId)), 404); // renditionId is null - post(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), toJsonAsString(new Rendition().setId(null)), 400); + post(getNodeRenditionsUrl(contentNodeId), toJsonAsString(new Rendition().setId(null)), 400); // renditionId is empty - post(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), toJsonAsString(new Rendition().setId("")), 400); + post(getNodeRenditionsUrl(contentNodeId), toJsonAsString(new Rendition().setId("")), 400); // -ve test - we do not currently accept multiple create entities List request = new ArrayList<>(2); request.add(new Rendition().setId("doclib")); request.add(new Rendition().setId("imgpreview")); - post(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), toJsonAsString(request), 400); + post(getNodeRenditionsUrl(contentNodeId), toJsonAsString(request), 400); // Create a node without any content String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId()); @@ -425,17 +425,17 @@ public class RenditionsTest extends AbstractBaseApiTest // The source node has no content request = new ArrayList<>(2); request.add(new Rendition().setId("doclib")); - post(getNodeRenditionsUrl(emptyContentNodeId), userOneN1.getId(), toJsonAsString(renditionRequest), 400); // TODO different results local (202) than build (400) ? + post(getNodeRenditionsUrl(emptyContentNodeId), toJsonAsString(renditionRequest), 400); // TODO different results local (202) than build (400) ? String content = "The quick brown fox jumps over the lazy dog."; file = TempFileProvider.createTempFile(new ByteArrayInputStream(content.getBytes()), getClass().getSimpleName(), ".bin"); multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData("binaryFileName", file)); reqBody = multiPartBuilder.build(); - response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document binaryDocument = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // No transformer is currently available for 'application/octet-stream' - post(getNodeRenditionsUrl(binaryDocument.getId()), userOneN1.getId(), toJsonAsString(renditionRequest), 400); + post(getNodeRenditionsUrl(binaryDocument.getId()), toJsonAsString(renditionRequest), 400); ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class); // Disable thumbnail generation @@ -448,10 +448,10 @@ public class RenditionsTest extends AbstractBaseApiTest reqBody = MultiPartBuilder.create().setFileData(new FileData(txtFileName, txtFile)).build(); // Upload quick-1.txt file into 'folder' - response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document txtDocument = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); // Thumbnail generation has been disabled - response = post(getNodeRenditionsUrl(txtDocument.getId()), userOneN1.getId(), toJsonAsString(renditionRequest), 501); + response = post(getNodeRenditionsUrl(txtDocument.getId()), toJsonAsString(renditionRequest), 501); errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse()); assertNotNull(errorResponse); assertNotNull(errorResponse.getErrorKey()); @@ -492,7 +492,7 @@ public class RenditionsTest extends AbstractBaseApiTest .build(); // Upload quick.pdf file into 'folder' - including request to create 'doclib' thumbnail - HttpResponse response = post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String contentNodeId = document.getId(); @@ -557,7 +557,7 @@ public class RenditionsTest extends AbstractBaseApiTest .setRenditions(Arrays.asList(new String[]{"doclib,imgpreview"})) .build(); - post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 400); + post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 400); // Unknown rendition reqBody = MultiPartBuilder.create() @@ -566,7 +566,7 @@ public class RenditionsTest extends AbstractBaseApiTest .setRenditions(Arrays.asList(new String[]{"unknown"})) .build(); - post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 201); + post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); // ThumbnailService is disabled ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class); @@ -581,7 +581,7 @@ public class RenditionsTest extends AbstractBaseApiTest .setRenditions(Arrays.asList(new String[]{"doclib"})) .build(); - post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 201); + post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); } finally { @@ -611,12 +611,12 @@ public class RenditionsTest extends AbstractBaseApiTest MultiPartRequest reqBody = multiPartBuilder.build(); // Upload quick.pdf file into 'folder' - HttpResponse response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String contentNodeId = document.getId(); // Get rendition (not created yet) information for node - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib", 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), "doclib", 200); Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class); assertNotNull(rendition); assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus()); @@ -624,7 +624,7 @@ public class RenditionsTest extends AbstractBaseApiTest // Download placeholder - by default with Content-Disposition header Map params = new HashMap<>(); params.put("placeholder", "true"); - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), ("doclib/content"), params, 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), ("doclib/content"), params, 200); assertNotNull(response.getResponseAsBytes()); Map responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -637,7 +637,7 @@ public class RenditionsTest extends AbstractBaseApiTest // Download placeholder - without Content-Disposition header (attachment=false) params.put("attachment", "false"); - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), ("doclib/content"), params, 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), ("doclib/content"), params, 200); assertNotNull(response.getResponseAsBytes()); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -655,7 +655,7 @@ public class RenditionsTest extends AbstractBaseApiTest Map headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); // Currently the placeholder file is not cached. // As the placeholder is not a NodeRef, so we can't get the ContentModel.PROP_MODIFIED date. - getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", params, headers, 200); + getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, 200); // Create and get 'doclib' rendition rendition = createAndGetRendition(contentNodeId, "doclib"); @@ -663,7 +663,7 @@ public class RenditionsTest extends AbstractBaseApiTest assertEquals(RenditionStatus.CREATED, rendition.getStatus()); // Download rendition - by default with Content-Disposition header - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", 200); assertNotNull(response.getResponseAsBytes()); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -676,7 +676,7 @@ public class RenditionsTest extends AbstractBaseApiTest // Download rendition - without Content-Disposition header (attachment=false) params = Collections.singletonMap("attachment", "false"); - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", params, 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200); assertNotNull(response.getResponseAsBytes()); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -687,7 +687,7 @@ public class RenditionsTest extends AbstractBaseApiTest // Download rendition - with Content-Disposition header (attachment=true) same as default params = Collections.singletonMap("attachment", "true"); - response = getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", params, 200); + response = getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200); assertNotNull(response.getResponseAsBytes()); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -707,7 +707,7 @@ public class RenditionsTest extends AbstractBaseApiTest lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER); assertNotNull(lastModifiedHeader); headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); - getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", params, headers, 304); + getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, 304); // Here we want to overwrite/update the existing content in order to force a new rendition creation, // so the ContentModel.PROP_MODIFIED date would be different. Hence, we use the multipart upload by providing @@ -719,10 +719,10 @@ public class RenditionsTest extends AbstractBaseApiTest reqBody = multiPartBuilder.build(); // Update quick.pdf - post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); // The requested "If-Modified-Since" date is older than rendition modified date - response = getSingleWithDelayRetry(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", params, headers, MAX_RETRY, + response = getSingleWithDelayRetry(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, MAX_RETRY, PAUSE_TIME, 200); assertNotNull(response); responseHeaders = response.getHeaders(); @@ -733,13 +733,13 @@ public class RenditionsTest extends AbstractBaseApiTest //-ve tests // nodeId in the path parameter does not represent a file - getSingle(getNodeRenditionsUrl(folder_Id), userOneN1.getId(), "doclib/content", 400); + getSingle(getNodeRenditionsUrl(folder_Id), "doclib/content", 400); // nodeId in the path parameter does not exist - getSingle(getNodeRenditionsUrl(UUID.randomUUID().toString()), userOneN1.getId(), "doclib/content", 404); + getSingle(getNodeRenditionsUrl(UUID.randomUUID().toString()), "doclib/content", 404); // renditionId in the path parameter is not registered/available - getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), ("renditionId" + System.currentTimeMillis() + "/content"), 404); + getSingle(getNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), 404); InputStream inputStream = new ByteArrayInputStream("The quick brown fox jumps over the lazy dog".getBytes()); file = TempFileProvider.createTempFile(inputStream, "RenditionsTest-", ".abcdef"); @@ -747,24 +747,24 @@ public class RenditionsTest extends AbstractBaseApiTest .setFileData(new FileData(file.getName(), file)) .build(); // Upload temp file into 'folder' - response = post(getNodeChildrenUrl(folder_Id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201); document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); contentNodeId = document.getId(); // The content of the rendition does not exist and the placeholder parameter is not present - getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", 404); + getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", 404); // The content of the rendition does not exist and the placeholder parameter has a value of "false" params = Collections.singletonMap("placeholder", "false"); - getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", params, 404); + getSingle(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, 404); // The rendition does not exist, a placeholder is not available and the placeholder parameter has a value of "true" params = Collections.singletonMap("placeholder", "true"); - getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), ("renditionId" + System.currentTimeMillis() + "/content"), params, 404); + getSingle(getNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), params, 404); // Create a node without any content String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId()); - getSingle(getNodeRenditionsUrl(emptyContentNodeId), userOneN1.getId(), "doclib/content", params, 200); + getSingle(getNodeRenditionsUrl(emptyContentNodeId), "doclib/content", params, 200); } private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception diff --git a/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java b/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java index 923268acc1..bbe97e131b 100644 --- a/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java @@ -57,7 +57,8 @@ import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull import static org.junit.Assert.*; /** - * API tests for: + * V1 REST API tests for Shared Links (aka public "quick shares") + * *
        *
      • {@literal :/alfresco/api//public/alfresco/versions/1/shared-links}
      • *
      • {@literal :/alfresco/api//public/alfresco/versions/1/shared-links/}
      • @@ -106,7 +107,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest .setFileData(new MultiPartBuilder.FileData(fileName1, file1, file1_MimeType)); MultiPartBuilder.MultiPartRequest reqBody = multiPartBuilder.build(); - HttpResponse response = post(getNodeChildrenUrl(sharedFolderNodeId), user1, reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(sharedFolderNodeId), reqBody.getBody(), null, reqBody.getContentType(), 201); Document doc1 = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String d1Id = doc1.getId(); @@ -125,7 +126,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // As user 2 ... setRequestContext(user2); - response = getSingle(NodesEntityResource.class, user2, d1Id, null, 200); + response = getSingle(NodesEntityResource.class, d1Id, null, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); Date docModifiedAt = nodeResp.getModifiedAt(); String docModifiedBy = nodeResp.getModifiedByUser().getId(); @@ -135,7 +136,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest Map body = new HashMap<>(); body.put("nodeId", d1Id); - response = post(URL_SHARED_LINKS, user2, toJsonAsStringNonNull(body), 201); + response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201); QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); String shared1Id = resp.getId(); @@ -158,7 +159,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertEquals(user2+" "+user2, resp.getSharedByUser().getDisplayName()); // -ve test - try to create again (same user) - already exists - post(URL_SHARED_LINKS, user2, toJsonAsStringNonNull(body), 409); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 409); // As user 1 ... @@ -168,7 +169,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest body = new HashMap<>(); body.put("nodeId", d2Id); - response = post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 201); + response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); String shared2Id = resp.getId(); @@ -177,7 +178,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // access to get shared link info - pass user1 (but ignore in non-MT) Map params = Collections.singletonMap("include", "allowableOperations"); - response = getSingle(QuickShareLinkEntityResource.class, user1, shared1Id, params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id, params, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertEquals(shared1Id, resp.getId()); @@ -192,7 +193,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // access to get shared link info - pass user2 (but ignore in non-MT) params = Collections.singletonMap("include", "allowableOperations"); - response = getSingle(QuickShareLinkEntityResource.class, user2, shared1Id, params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id, params, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertEquals(shared1Id, resp.getId()); @@ -207,7 +208,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // allowable operations not included - no params - response = getSingle(QuickShareLinkEntityResource.class, user2, shared1Id, null, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id, null, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertNull(resp.getAllowableOperations()); @@ -215,7 +216,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // unauth access to get shared link info params = Collections.singletonMap("include", "allowableOperations"); // note: this will be ignore for unauth access - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id, params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id, params, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertEquals(shared1Id, resp.getId()); @@ -229,7 +230,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertEquals(user2+" "+user2, resp.getSharedByUser().getDisplayName()); // unauth access to file 1 content (via shared link) - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/content", null, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", null, 200); assertArrayEquals(file1_originalBytes, response.getResponseAsBytes()); Map responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -240,12 +241,12 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertNotNull(lastModifiedHeader); // Test 304 response Map headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); - getSingle(URL_SHARED_LINKS, null, shared1Id + "/content", null, headers, 304); + getSingle(URL_SHARED_LINKS, shared1Id + "/content", null, headers, 304); // unauth access to file 1 content (via shared link) - without Content-Disposition header (attachment=false) params = new HashMap<>(); params.put("attachment", "false"); - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/content", params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", params, 200); assertArrayEquals(file1_originalBytes, response.getResponseAsBytes()); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -256,7 +257,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // unauth access to file 2 content (via shared link) - response = getSingle(QuickShareLinkEntityResource.class, null, shared2Id + "/content", null, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared2Id + "/content", null, 200); assertArrayEquals(content2Text.getBytes(), response.getResponseAsBytes()); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -268,20 +269,20 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // -ve test - unauth access to get shared link file content - without Content-Disposition header (attachment=false) - header ignored (plain text is not in white list) params = new HashMap<>(); params.put("attachment", "false"); - response = getSingle(QuickShareLinkEntityResource.class, null, shared2Id + "/content", params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared2Id + "/content", params, 200); assertEquals("attachment; filename=\"" + fileName2 + "\"; filename*=UTF-8''" + fileName2 + "", response.getHeaders().get("Content-Disposition")); // -ve shared link rendition tests { // -ve test - try to get non-existent rendition content - getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/doclib/content", null, 404); + getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", null, 404); // -ve test - try to get unregistered rendition content - getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/dummy/content", null, 404); + getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/dummy/content", null, 404); } // unauth access to get shared link renditions info (available => CREATED renditions only) - response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, null, 200); + response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, 200); List renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals(0, renditions.size()); @@ -296,14 +297,14 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // unauth access to get shared link renditions info (available => CREATED renditions only) - response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, null, 200); + response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals(1, renditions.size()); assertEquals(Rendition.RenditionStatus.CREATED, renditions.get(0).getStatus()); assertEquals("doclib", renditions.get(0).getId()); // unauth access to get shared link file rendition content - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/doclib/content", null, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", null, 200); assertTrue(response.getResponseAsBytes().length > 0); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -316,7 +317,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // unauth access to get shared link file rendition content - without Content-Disposition header (attachment=false) params = new HashMap<>(); params.put("attachment", "false"); - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/doclib/content", params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", params, 200); assertTrue(response.getResponseAsBytes().length > 0); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -327,7 +328,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertNotNull(lastModifiedHeader); // Test 304 response headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); - getSingle(URL_SHARED_LINKS, null, shared1Id + "/renditions/doclib/content", null, headers, 304); + getSingle(URL_SHARED_LINKS, shared1Id + "/renditions/doclib/content", null, headers, 304); // -ve delete tests @@ -353,32 +354,34 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // -ve test - try to create again (different user, that has read permission) - already exists body = new HashMap<>(); body.put("nodeId", d1Id); - post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 409); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 409); // -ve - create - missing nodeId body = new HashMap<>(); - post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 400); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 400); // -ve - create - unknown nodeId body = new HashMap<>(); body.put("nodeId", "dummy"); - post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 404); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 404); // -ve - create - try to link to folder (ie. not a file) String f1Id = createFolder(myFolderNodeId, "f1 " + RUNID).getId(); body = new HashMap<>(); body.put("nodeId", f1Id); - post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 400); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 400); // -ve test - cannot create if user does not have permission to read + setRequestContext(user2); body = new HashMap<>(); body.put("nodeId", d2Id); - post(URL_SHARED_LINKS, user2, toJsonAsStringNonNull(body), 403); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 403); // -ve test - unauthenticated + setRequestContext(null); body = new HashMap<>(); body.put("nodeId", d1Id); - post(URL_SHARED_LINKS, null, toJsonAsStringNonNull(body), 401); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 401); } @@ -392,7 +395,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest setRequestContext(user2); - response = getSingle(NodesEntityResource.class, user2, d1Id, null, 200); + response = getSingle(NodesEntityResource.class, d1Id, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); assertEquals(docModifiedAt.getTime(), nodeResp.getModifiedAt().getTime()); // not changed @@ -402,12 +405,12 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // -ve get tests { // try to get link that has been deleted (see above) - getSingle(QuickShareLinkEntityResource.class, null, shared1Id, null, 404); - getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/content", null, 404); + getSingle(QuickShareLinkEntityResource.class, shared1Id, null, 404); + getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", null, 404); // try to get non-existent link - getSingle(QuickShareLinkEntityResource.class, null, "dummy", null, 404); - getSingle(QuickShareLinkEntityResource.class, null, "dummy/content", null, 404); + getSingle(QuickShareLinkEntityResource.class, "dummy", null, 404); + getSingle(QuickShareLinkEntityResource.class, "dummy/content", null, 404); } // TODO if and when these tests are optionally runnable via remote env then we could skip this part of the test @@ -422,11 +425,11 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // -ve - disabled service tests body.put("nodeId", "dummy"); - post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 501); + post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 501); setRequestContext(null); - getSingle(QuickShareLinkEntityResource.class, null, "dummy", null, 501); - getSingle(QuickShareLinkEntityResource.class, null, "dummy/content", null, 501); + getSingle(QuickShareLinkEntityResource.class, "dummy", null, 501); + getSingle(QuickShareLinkEntityResource.class, "dummy/content", null, 501); setRequestContext(user1); deleteSharedLink("dummy", 501); @@ -454,7 +457,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest Paging paging = getPaging(0, 100); // Get all shared links visible to user 1 (note: for now assumes clean repo) - HttpResponse response = getAll(URL_SHARED_LINKS, user1, paging, 200); + HttpResponse response = getAll(URL_SHARED_LINKS, paging, 200); List sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class); assertEquals(0, sharedLinks.size()); @@ -475,7 +478,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // create shared link to doc 1 Map body = new HashMap<>(); body.put("nodeId", d1Id); - response = post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 201); + response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201); QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); String shared1Id = resp.getId(); @@ -485,7 +488,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // create shared link to doc 2 body = new HashMap<>(); body.put("nodeId", d2Id); - response = post(URL_SHARED_LINKS, user2, toJsonAsStringNonNull(body), 201); + response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); String shared2Id = resp.getId(); @@ -496,7 +499,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest setRequestContext(user1); - response = getAll(URL_SHARED_LINKS, user1, paging, 200); + response = getAll(URL_SHARED_LINKS, paging, 200); sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class); assertEquals(2, sharedLinks.size()); assertEquals(shared2Id, sharedLinks.get(0).getId()); @@ -506,7 +509,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest setRequestContext(user2); - response = getAll(URL_SHARED_LINKS, user2, paging, 200); + response = getAll(URL_SHARED_LINKS, paging, 200); sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class); assertEquals(1, sharedLinks.size()); assertEquals(shared2Id, sharedLinks.get(0).getId()); @@ -518,7 +521,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest Map params = new HashMap<>(); params.put("where", "("+ QuickShareLinks.PARAM_SHAREDBY+"='"+People.DEFAULT_USER+"')"); - response = getAll(URL_SHARED_LINKS, user1, paging, params, 200); + response = getAll(URL_SHARED_LINKS, paging, params, 200); sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class); assertEquals(1, sharedLinks.size()); assertEquals(shared1Id, sharedLinks.get(0).getId()); @@ -528,7 +531,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest params = new HashMap<>(); params.put("where", "("+ QuickShareLinks.PARAM_SHAREDBY+"='"+user2+"')"); - response = getAll(URL_SHARED_LINKS, user1, paging, params, 200); + response = getAll(URL_SHARED_LINKS, paging, params, 200); sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class); assertEquals(1, sharedLinks.size()); assertEquals(shared2Id, sharedLinks.get(0).getId()); @@ -537,7 +540,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest setRequestContext(null); // -ve test - unauthenticated - getAll(URL_SHARED_LINKS, null, paging, params, 401); + getAll(URL_SHARED_LINKS, paging, params, 401); // delete the shared links @@ -559,7 +562,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest quickShareLinks.setEnabled(false); // -ve - disabled service tests - getAll(URL_SHARED_LINKS, user1, paging, 501); + getAll(URL_SHARED_LINKS, paging, 501); } finally { @@ -586,7 +589,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // Create shared link to document Map body = Collections.singletonMap("nodeId", docId); - HttpResponse response = post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 201); + HttpResponse response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201); QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); String sharedId = resp.getId(); assertNotNull(sharedId); @@ -599,7 +602,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest recipients.add(user2 + "@acme.test"); recipients.add(user2 + "@ping.test"); request.setRecipientEmails(recipients); - post(getEmailSharedLinkUrl(sharedId), user1, RestApiUtil.toJsonAsString(request), 202); + post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 202); // Email request with all the properties request = new QuickShareLinkEmailRequest(); @@ -608,27 +611,27 @@ public class SharedLinkApiTest extends AbstractBaseApiTest request.setLocale(Locale.UK.toString()); recipients = Collections.singletonList(user2 + "@acme.test"); request.setRecipientEmails(recipients); - post(getEmailSharedLinkUrl(sharedId), user1, RestApiUtil.toJsonAsString(request), 202); + post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 202); // -ve tests // sharedId path parameter does not exist - post(getEmailSharedLinkUrl(sharedId + System.currentTimeMillis()), user1, RestApiUtil.toJsonAsString(request), 404); + post(getEmailSharedLinkUrl(sharedId + System.currentTimeMillis()), RestApiUtil.toJsonAsString(request), 404); // Unregistered client request = new QuickShareLinkEmailRequest(); request.setClient("VeryCoolClient" + System.currentTimeMillis()); List user2Email = Collections.singletonList(user2 + "@acme.test"); request.setRecipientEmails(user2Email); - post(getEmailSharedLinkUrl(sharedId), user1, RestApiUtil.toJsonAsString(request), 400); + post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 400); // client is mandatory request.setClient(null); - post(getEmailSharedLinkUrl(sharedId), user1, RestApiUtil.toJsonAsString(request), 400); + post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 400); // recipientEmails is mandatory request.setClient("sfs"); request.setRecipientEmails(null); - post(getEmailSharedLinkUrl(sharedId), user1, RestApiUtil.toJsonAsString(request), 400); + post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 400); // TODO if and when these tests are optionally runnable via remote env then we could skip this part of the test // (else need to verify test mechanism for enterprise admin via jmx ... etc) @@ -639,7 +642,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest request = new QuickShareLinkEmailRequest(); request.setClient("sfs"); request.setRecipientEmails(user2Email); - post(getEmailSharedLinkUrl(sharedId), user1, RestApiUtil.toJsonAsString(request), 501); + post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 501); } finally { @@ -687,7 +690,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest .setFileData(new MultiPartBuilder.FileData(fileName1, file1, file1_MimeType)) .build(); - HttpResponse response = post(getNodeChildrenUrl(folderId), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201); + HttpResponse response = post(getNodeChildrenUrl(folderId), reqBody.getBody(), null, reqBody.getContentType(), 201); Document doc1 = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String d1Id = doc1.getId(); assertNotNull(d1Id); @@ -695,7 +698,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // create shared link to document 1 Map body = new HashMap<>(); body.put("nodeId", d1Id); - response = post(URL_SHARED_LINKS, userOneN1.getId(), toJsonAsStringNonNull(body), 201); + response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201); QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); String shared1Id = resp.getId(); assertNotNull(shared1Id); @@ -705,7 +708,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertEquals(userOneN1.getId(), resp.getSharedByUser().getId()); // allowable operations not included - no params - response = getSingle(QuickShareLinkEntityResource.class, userOneN1.getId(), shared1Id, null, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id, null, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertNull(resp.getAllowableOperations()); @@ -713,7 +716,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // unauth access to get shared link info Map params = Collections.singletonMap("include", "allowableOperations"); // note: this will be ignore for unauth access - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id, params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id, params, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertEquals(shared1Id, resp.getId()); assertEquals(fileName1, resp.getName()); @@ -721,7 +724,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertNull(resp.getAllowableOperations()); // include is ignored // unauth access to file 1 content (via shared link) - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/content", null, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", null, 200); assertArrayEquals(file1_originalBytes, response.getResponseAsBytes()); Map responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -732,12 +735,12 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertNotNull(lastModifiedHeader); // Test 304 response Map headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); - getSingle(URL_SHARED_LINKS, null, shared1Id + "/content", null, headers, 304); + getSingle(URL_SHARED_LINKS, shared1Id + "/content", null, headers, 304); // unauth access to file 1 content (via shared link) - without Content-Disposition header (attachment=false) params = new HashMap<>(); params.put("attachment", "false"); - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/content", params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", params, 200); assertArrayEquals(file1_originalBytes, response.getResponseAsBytes()); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -749,14 +752,14 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // -ve shared link rendition tests { // -ve test - try to get non-existent rendition content - getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/doclib/content", null, 404); + getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", null, 404); // -ve test - try to get unregistered rendition content - getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/dummy/content", null, 404); + getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/dummy/content", null, 404); } // unauth access to get shared link renditions info (available => CREATED renditions only) - response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, null, 200); + response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, 200); List renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals(0, renditions.size()); @@ -770,14 +773,14 @@ public class SharedLinkApiTest extends AbstractBaseApiTest setRequestContext(null); // unauth access to get shared link renditions info (available => CREATED renditions only) - response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, null, 200); + response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, 200); renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); assertEquals(1, renditions.size()); assertEquals(Rendition.RenditionStatus.CREATED, renditions.get(0).getStatus()); assertEquals("doclib", renditions.get(0).getId()); // unauth access to get shared link file rendition content - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/doclib/content", null, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", null, 200); assertTrue(response.getResponseAsBytes().length > 0); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -790,7 +793,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // unauth access to get shared link file rendition content - without Content-Disposition header (attachment=false) params = new HashMap<>(); params.put("attachment", "false"); - response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id + "/renditions/doclib/content", params, 200); + response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", params, 200); assertTrue(response.getResponseAsBytes().length > 0); responseHeaders = response.getHeaders(); assertNotNull(responseHeaders); @@ -801,7 +804,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertNotNull(lastModifiedHeader); // Test 304 response headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); - getSingle(URL_SHARED_LINKS, null, shared1Id + "/renditions/doclib/content", null, headers, 304); + getSingle(URL_SHARED_LINKS, shared1Id + "/renditions/doclib/content", null, headers, 304); // -ve test - userTwoN1 cannot delete shared link setRequestContext(userTwoN1.getId()); @@ -834,6 +837,6 @@ public class SharedLinkApiTest extends AbstractBaseApiTest private void deleteSharedLink(String sharedId, int expectedStatus) throws Exception { - delete(URL_SHARED_LINKS, publicApiClient.getRequestContext().getRunAsUser(), sharedId, expectedStatus); + delete(URL_SHARED_LINKS, sharedId, expectedStatus); } } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestCustomConstraint.java b/source/test-java/org/alfresco/rest/api/tests/TestCustomConstraint.java index 4790488ba0..559f9cee3e 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestCustomConstraint.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestCustomConstraint.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 . + * #L% + */ package org.alfresco.rest.api.tests; @@ -74,6 +74,8 @@ public class TestCustomConstraint extends BaseCustomModelApiTest @Test public void testCreateConstraints() throws Exception { + setRequestContext(customModelAdmin); + final Paging paging = getPaging(0, Integer.MAX_VALUE); String modelName = "testModelConstraint" + System.currentTimeMillis(); @@ -95,27 +97,33 @@ public class TestCustomConstraint extends BaseCustomModelApiTest parameters.add(buildNamedValue("requiresMatch", "false")); // Add the parameters into the constraint regExConstraint.setParameters(parameters); - + + setRequestContext(nonAdminUserName); + // Try to create constraint as a non Admin user - post("cmm/" + modelName + "/constraints", nonAdminUserName, RestApiUtil.toJsonAsString(regExConstraint), 403); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 403); + + setRequestContext(customModelAdmin); // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(regExConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201); // Retrieve the created RegEx constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, regExConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", regExConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); compareCustomModelConstraints(regExConstraint, returnedConstraint, "prefixedName"); // Try to create a duplicate constraint - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(regExConstraint), 409); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 409); // Retrieve all the model's constraints - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(1, constraints.size()); } + setRequestContext(customModelAdmin); + // Try to create invalid RegEx constraint { String regExConstraintName = "testFileNameInvalidRegEx" + System.currentTimeMillis(); @@ -128,9 +136,9 @@ public class TestCustomConstraint extends BaseCustomModelApiTest parameters.add(buildNamedValue("requiresMatch", "false")); // Add the parameters into the constraint regExConstraint.setParameters(parameters); - + // Try to create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(regExConstraint), 400); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 400); } // Create MINMAX constraint @@ -146,9 +154,9 @@ public class TestCustomConstraint extends BaseCustomModelApiTest parameters.add(buildNamedValue("minValue", "0.0")); // Add the parameters into the constraint minMaxConstraint.setParameters(parameters); - + // Try to create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(minMaxConstraint), 400); // constraint's type is mandatory + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 400); // constraint's type is mandatory minMaxConstraint.setType("MINMAX"); parameters.clear(); @@ -157,7 +165,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest // Add the parameters into the constraint minMaxConstraint.setParameters(parameters); // Try to create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(minMaxConstraint), 400); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 400); parameters.clear(); parameters.add(buildNamedValue("maxValue", "100")); @@ -165,7 +173,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest // Add the parameters into the constraint minMaxConstraint.setParameters(parameters); // Try to create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(minMaxConstraint), 400); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 400); parameters.clear(); parameters.add(buildNamedValue("maxValue", "100.0")); @@ -173,15 +181,15 @@ public class TestCustomConstraint extends BaseCustomModelApiTest // Add the parameters into the constraint minMaxConstraint.setParameters(parameters); // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(minMaxConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 201); // Retrieve the created MINMAX constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, minMaxConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", minMaxConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); compareCustomModelConstraints(minMaxConstraint, returnedConstraint, "prefixedName"); // Retrieve all the model's constraints - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(2, constraints.size()); } @@ -200,9 +208,9 @@ public class TestCustomConstraint extends BaseCustomModelApiTest parameters.add(buildNamedValue("minLength", "0")); // Add the parameters into the constraint lengthConstraint.setParameters(parameters); - + // Try to create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(lengthConstraint), 400); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(lengthConstraint), 400); parameters.clear(); parameters.add(buildNamedValue("maxLength", "256")); @@ -210,7 +218,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest // Add the parameters into the constraint lengthConstraint.setParameters(parameters); // Try to create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(lengthConstraint), 400); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(lengthConstraint), 400); parameters.clear(); parameters.add(buildNamedValue("maxLength", "256")); @@ -218,15 +226,15 @@ public class TestCustomConstraint extends BaseCustomModelApiTest // Add the parameters into the constraint lengthConstraint.setParameters(parameters); // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(lengthConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(lengthConstraint), 201); // Retrieve the created LENGTH constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, lengthConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", lengthConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); compareCustomModelConstraints(lengthConstraint, returnedConstraint, "prefixedName"); // Retrieve all the model's constraints - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(3, constraints.size()); } @@ -245,12 +253,12 @@ public class TestCustomConstraint extends BaseCustomModelApiTest parameters.add(buildNamedValue("sorted", "false")); // Add the parameters into the constraint listConstraint.setParameters(parameters); - + // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(listConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(listConstraint), 201); // Retrieve the created List constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, listConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", listConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); compareCustomModelConstraints(listConstraint, returnedConstraint, "prefixedName", "parameters"); String sorted = getParameterSimpleValue(returnedConstraint.getParameters(), "sorted"); @@ -263,7 +271,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest assertEquals("Low", listValues.get(2)); // Retrieve all the model's constraints - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(4, constraints.size()); } @@ -274,16 +282,17 @@ public class TestCustomConstraint extends BaseCustomModelApiTest CustomModelConstraint authorityNameConstraint = new CustomModelConstraint(); authorityNameConstraint.setName(authorityNameConstraintName); authorityNameConstraint.setType("org.alfresco.repo.dictionary.constraint.AuthorityNameConstraint"); + // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(authorityNameConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(authorityNameConstraint), 201); // Retrieve the created authorityName constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, authorityNameConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", authorityNameConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); compareCustomModelConstraints(authorityNameConstraint, returnedConstraint, "prefixedName"); // Retrieve all the model's constraints - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(5, constraints.size()); } @@ -302,33 +311,33 @@ public class TestCustomConstraint extends BaseCustomModelApiTest parameters.add(buildNamedValue("minValue", "0.0")); // Add the parameters into the constraint invalidConstraint.setParameters(parameters); - + // Try to create an invalid constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(invalidConstraint), 400); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(invalidConstraint), 400); // Retrieve all the model's constraints - HttpResponse response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + HttpResponse response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(5, constraints.size()); } - + // Activate the model CustomModel updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); // Retrieve all the model's constraints - HttpResponse response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + HttpResponse response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(5, constraints.size()); // Deactivate the model updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); // Retrieve all the model's constraints - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(5, constraints.size()); } @@ -336,6 +345,8 @@ public class TestCustomConstraint extends BaseCustomModelApiTest @Test public void testCreateConstraintAndAddToProperty() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelConstraint" + System.currentTimeMillis(); final Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -354,17 +365,17 @@ public class TestCustomConstraint extends BaseCustomModelApiTest parameters.add(buildNamedValue("requiresMatch", "false")); // Add the parameters into the constraint regExConstraint.setParameters(parameters); - + // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(regExConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201); // Retrieve the created constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, regExConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", regExConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); // Retrieve all the model's constraints Paging paging = getPaging(0, Integer.MAX_VALUE); - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(1, constraints.size()); @@ -386,16 +397,16 @@ public class TestCustomConstraint extends BaseCustomModelApiTest payload.setProperties(props); // Create the property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); // Activate the model CustomModel updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); // Retrieve all the model's constraints // Test to see if the API took care of duplicate constraints when referencing a constraint within a property. - response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelName + "/constraints", paging, 200); constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals(1, constraints.size()); @@ -441,17 +452,19 @@ public class TestCustomConstraint extends BaseCustomModelApiTest }, person.getId(), testNetwork.getId()); } + setRequestContext(customModelAdmin); + // Deactivate the model updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); // Test update the namespace prefix (test to see if the API updates the constraints refs with this new prefix) CustomModel updateModelPayload = new CustomModel(); String modifiedPrefix = namespacePair.getSecond() + "Modified"; updateModelPayload.setNamespacePrefix(modifiedPrefix); updateModelPayload.setNamespaceUri(namespacePair.getFirst()); - response = put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200); + response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(modifiedPrefix, returnedModel.getNamespacePrefix()); assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri()); @@ -461,7 +474,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest updateModelPayload.setNamespacePrefix(modifiedPrefix); String modifiedURI = namespacePair.getFirst() + "Modified"; updateModelPayload.setNamespaceUri(modifiedURI); - response = put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200); + response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(modifiedURI, returnedModel.getNamespaceUri()); assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix()); @@ -470,11 +483,13 @@ public class TestCustomConstraint extends BaseCustomModelApiTest @Test public void testCreateInlineConstraint() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelInlineConstraint" + System.currentTimeMillis(); final Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator createCustomModel(modelName, namespacePair, ModelStatus.DRAFT); - + String regExConstraintName = "testInlineFileNameRegEx" + System.currentTimeMillis(); { // Create RegEx constraint @@ -506,16 +521,16 @@ public class TestCustomConstraint extends BaseCustomModelApiTest aspectPayload.setProperties(props); // Create the property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); // Retrieve all the model's constraints Paging paging = getPaging(0, Integer.MAX_VALUE); - HttpResponse response = getAll("cmm/" + modelName + "/constraints", customModelAdmin, paging, 200); + HttpResponse response = getAll("cmm/" + modelName + "/constraints", paging, 200); List constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class); assertEquals("Inline constraints should not be included with the model defined constraints.", 0, constraints.size()); // Retrieve the updated aspect - response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 200); + response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); // Check the aspect's added property @@ -544,14 +559,14 @@ public class TestCustomConstraint extends BaseCustomModelApiTest regExConstraint.setParameters(parameters); // Try to create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(regExConstraint), 409); // duplicate name + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 409); // duplicate name String newRegExConstraintName = "testFileNameRegEx" + System.currentTimeMillis(); regExConstraint.setName(newRegExConstraintName); // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(regExConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201); // Retrieve the created RegEx constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, newRegExConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", newRegExConstraintName, 200); CustomModelConstraint returnedRegExConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); // Create inline anonymous LENGTH constraint @@ -584,17 +599,17 @@ public class TestCustomConstraint extends BaseCustomModelApiTest typePayload.setProperties(props); // Try to create the property - LENGTH constraint can only be used with textual data type - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 400); typeProp.setDataType("d:double"); // CTry to create the property - LENGTH constraint can only be used with textual data type - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 400); typeProp.setDataType("d:text"); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); // Retrieve the updated type - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, type.getName(), 200); + response = getSingle("cmm/" + modelName + "/types", type.getName(), 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); // Check the type's added property @@ -614,11 +629,13 @@ public class TestCustomConstraint extends BaseCustomModelApiTest @Test public void testCreateListConstraintInvalid() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelConstraintInvalid" + System.currentTimeMillis(); final Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator createCustomModel(modelName, namespacePair, ModelStatus.DRAFT); - + // Create aspect String aspectName = "testAspect" + System.currentTimeMillis(); createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null); @@ -651,7 +668,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest aspectPayload.setProperties(props); // Try to create the property - Invalid LIST values - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); // Test d:double LIST values with d:int property data type parameters = new ArrayList<>(3); @@ -665,14 +682,17 @@ public class TestCustomConstraint extends BaseCustomModelApiTest aspectPayload.setProperties(props); // Try to create the property - Invalid LIST values - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); } @Test public void testCreateMinMaxConstraintInvalid() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelMinMaxInvalid" + System.currentTimeMillis(); final Pair namespacePair = getTestNamespaceUriPrefixPair(); + // Create the model as a Model Administrator createCustomModel(modelName, namespacePair, ModelStatus.DRAFT); @@ -709,12 +729,12 @@ public class TestCustomConstraint extends BaseCustomModelApiTest // Try to create constraint as a Model Administrator // MINMAX constraint can only be used with numeric data type. - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); // Change type aspectProp.setDataType("d:datetime"); // MINMAX constraint can only be used with numeric data type. - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); // SHA-1126 { @@ -731,15 +751,18 @@ public class TestCustomConstraint extends BaseCustomModelApiTest props.add(aspectProp); aspectPayload.setProperties(props); // Maximum value of the MINMAX constraint must be a positive nonzero value. - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); } } @Test public void testPropDefaultValueWithInlineConstraint() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelInlineConstraint" + System.currentTimeMillis(); final Pair namespacePair = getTestNamespaceUriPrefixPair(); + // Create the model as a Model Administrator createCustomModel(modelName, namespacePair, ModelStatus.DRAFT); @@ -775,7 +798,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest aspectPayload.setProperties(props); // Try to create the property - constraint violation - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); } { @@ -808,7 +831,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest typePayload.setProperties(props); // Try to create the property - constraint violation - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409); } { @@ -841,7 +864,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest typePayload.setProperties(props); // Try to create the property - constraint violation - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409); } { @@ -876,7 +899,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest aspectPayload.setProperties(props); // Try to create the property - constraint violation - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); } { @@ -905,13 +928,15 @@ public class TestCustomConstraint extends BaseCustomModelApiTest aspectPayload.setProperties(props); // Try to create the property - constraint violation - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); } } @Test public void testPropDefaultValueWithConstraintRef() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelConstraintRef" + System.currentTimeMillis(); final Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -931,9 +956,9 @@ public class TestCustomConstraint extends BaseCustomModelApiTest listConstraint.setParameters(parameters); // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(listConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(listConstraint), 201); // Retrieve the created List constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, listConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", listConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); // Create aspect @@ -955,7 +980,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest aspectPayload.setProperties(props); // Try to create the property - constraint violation - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409); } { @@ -972,9 +997,9 @@ public class TestCustomConstraint extends BaseCustomModelApiTest minMaxConstraint.setParameters(parameters); // Create constraint as a Model Administrator - post("cmm/" + modelName + "/constraints", customModelAdmin, RestApiUtil.toJsonAsString(minMaxConstraint), 201); + post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 201); // Retrieve the created MinMax constraint - HttpResponse response = getSingle("cmm/" + modelName + "/constraints", customModelAdmin, minMaxConstraintName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/constraints", minMaxConstraintName, 200); CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class); // Create type @@ -996,7 +1021,7 @@ public class TestCustomConstraint extends BaseCustomModelApiTest typePayload.setProperties(props); // Try to create the property - constraint violation - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409); } } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestCustomModel.java b/source/test-java/org/alfresco/rest/api/tests/TestCustomModel.java index 0774396f83..3ee3acf3e2 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestCustomModel.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestCustomModel.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 . + * #L% + */ package org.alfresco.rest.api.tests; @@ -64,14 +64,18 @@ public class TestCustomModel extends BaseCustomModelApiTest customModel.setDescription("Test model description"); customModel.setStatus(CustomModel.ModelStatus.DRAFT); + setRequestContext(nonAdminUserName); + // Try to create the model as a non Admin user - post("cmm", nonAdminUserName, RestApiUtil.toJsonAsString(customModel), 403); + post("cmm", RestApiUtil.toJsonAsString(customModel), 403); + + setRequestContext(customModelAdmin); // Create the model as a Model Administrator - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 201); + post("cmm", RestApiUtil.toJsonAsString(customModel), 201); // Retrieve the created model - HttpResponse response = getSingle("cmm", customModelAdmin, modelName, 200); + HttpResponse response = getSingle("cmm", modelName, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); // Check the retrieved model is the expected model. // Note: since we didn't specify the Author when created the Model, @@ -92,30 +96,32 @@ public class TestCustomModel extends BaseCustomModelApiTest customModel.setNamespaceUri(namespacePair.getFirst()); customModel.setNamespacePrefix(namespacePair.getSecond()); + setRequestContext(customModelAdmin); + // Test invalid inputs { customModel.setName(modelName + ""); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); customModel.setName("prefix:" + modelName); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // Invalid name. Contains ':' + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // Invalid name. Contains ':' customModel.setName("prefix " + modelName); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // Invalid name. Contains space + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // Invalid name. Contains space customModel.setName(modelName); customModel.setNamespacePrefix(namespacePair.getSecond()+" space"); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // Invalid prefix. Contains space + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // Invalid prefix. Contains space customModel.setNamespacePrefix(namespacePair.getSecond()+"invalid/"); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // Invalid prefix. Contains '/' + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // Invalid prefix. Contains '/' customModel.setNamespacePrefix(namespacePair.getSecond()); customModel.setNamespaceUri(namespacePair.getFirst()+" space"); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // Invalid URI. Contains space + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // Invalid URI. Contains space customModel.setNamespaceUri(namespacePair.getFirst()+"\\"); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // Invalid URI. Contains '\' + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // Invalid URI. Contains '\' } // Test mandatory properties of the model @@ -123,16 +129,16 @@ public class TestCustomModel extends BaseCustomModelApiTest customModel.setName(""); customModel.setNamespacePrefix(namespacePair.getSecond()); customModel.setNamespaceUri(namespacePair.getFirst()); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // name is mandatory + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // name is mandatory customModel.setName(modelName); customModel.setNamespaceUri(null); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // namespaceUri is mandatory + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // namespaceUri is mandatory customModel.setName(modelName); customModel.setNamespaceUri(namespacePair.getFirst()); customModel.setNamespacePrefix(null); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 400); // namespacePrefix is mandatory + post("cmm", RestApiUtil.toJsonAsString(customModel), 400); // namespacePrefix is mandatory } // Test duplicate model name @@ -141,11 +147,11 @@ public class TestCustomModel extends BaseCustomModelApiTest customModel.setName("contentmodel"); customModel.setNamespaceUri(namespacePair.getFirst()); customModel.setNamespacePrefix(namespacePair.getSecond()); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 409); + post("cmm", RestApiUtil.toJsonAsString(customModel), 409); // Create the model customModel.setName(modelName); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 201); + post("cmm", RestApiUtil.toJsonAsString(customModel), 201); // Create a duplicate model // Set a new namespace to make sure the 409 status code is returned @@ -153,7 +159,7 @@ public class TestCustomModel extends BaseCustomModelApiTest namespacePair = getTestNamespaceUriPrefixPair(); customModel.setNamespaceUri(namespacePair.getFirst()); customModel.setNamespacePrefix(namespacePair.getSecond()); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 409); + post("cmm", RestApiUtil.toJsonAsString(customModel), 409); } // Test duplicate namespaceUri @@ -165,7 +171,7 @@ public class TestCustomModel extends BaseCustomModelApiTest customModelTwo.setName(modelNameTwo); customModelTwo.setNamespaceUri(namespacePairTwo.getFirst()); customModelTwo.setNamespacePrefix(namespacePairTwo.getSecond()); - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModelTwo), 201); + post("cmm", RestApiUtil.toJsonAsString(customModelTwo), 201); String modelNameThree = "testModelThree" + System.currentTimeMillis(); Pair namespacePairThree = getTestNamespaceUriPrefixPair(); @@ -175,19 +181,21 @@ public class TestCustomModel extends BaseCustomModelApiTest customModelThree.setNamespacePrefix(namespacePairThree.getSecond()); // Try to create a model with a namespace uri which has already been used. - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModelThree), 409); + post("cmm", RestApiUtil.toJsonAsString(customModelThree), 409); customModelThree.setNamespaceUri(namespacePairThree.getFirst()); customModelThree.setNamespacePrefix(namespacePairTwo.getSecond()); // duplicate prefix // Try to create a model with a namespace prefix which has already been used. - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModelThree), 409); + post("cmm", RestApiUtil.toJsonAsString(customModelThree), 409); } } @Test public void testListBasicModels() throws Exception { + setRequestContext(customModelAdmin); + String modelName_1 = "testModel1" + System.currentTimeMillis(); // Create the model as a Model Administrator CustomModel customModel_1 = createCustomModel(modelName_1, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT); @@ -199,7 +207,7 @@ public class TestCustomModel extends BaseCustomModelApiTest CustomModel customModel_3 = createCustomModel(modelName_3, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT); Paging paging = getPaging(0, Integer.MAX_VALUE); - HttpResponse response = getAll("cmm", customModelAdmin, paging, 200); + HttpResponse response = getAll("cmm", paging, 200); List models = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModel.class); assertTrue(models.size() >= 3); @@ -211,13 +219,15 @@ public class TestCustomModel extends BaseCustomModelApiTest @Test public void testActivateCustomModel() throws Exception { + setRequestContext(customModelAdmin); + String modelNameOne = "testActivateModelOne" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator CustomModel customModelOne = createCustomModel(modelNameOne, namespacePair, ModelStatus.DRAFT, "Test model description", "Jane Doe"); // Retrieve the created model and check its status (the default is DRAFT) - HttpResponse response = getSingle("cmm", customModelAdmin, modelNameOne, 200); + HttpResponse response = getSingle("cmm", modelNameOne, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.DRAFT, returnedModel.getStatus()); @@ -225,20 +235,24 @@ public class TestCustomModel extends BaseCustomModelApiTest CustomModel updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.ACTIVE); + setRequestContext(nonAdminUserName); + // Try to activate the model as a non Admin user - put("cmm", nonAdminUserName, modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 403); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 403); + setRequestContext(customModelAdmin); + // Activate the model as a Model Administrator - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); - response = getSingle("cmm", customModelAdmin, modelNameOne, 200); + response = getSingle("cmm", modelNameOne, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.ACTIVE, returnedModel.getStatus()); // Check other properties have not been modified compareCustomModels(customModelOne, returnedModel, "status"); // Try to activate the already activated model as a Model Administrator - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 500); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 500); // Create another Model String modelNameTwo = "testActivateModelTwo" + System.currentTimeMillis(); @@ -247,9 +261,9 @@ public class TestCustomModel extends BaseCustomModelApiTest // Activate the model as a Model Administrator customModelTwo.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameTwo, RestApiUtil.toJsonAsString(customModelTwo), SELECT_STATUS_QS, 200); + put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(customModelTwo), SELECT_STATUS_QS, 200); - response = getSingle("cmm", customModelAdmin, modelNameTwo, 200); + response = getSingle("cmm", modelNameTwo, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.ACTIVE, returnedModel.getStatus()); // Check other properties have not been modified @@ -259,13 +273,15 @@ public class TestCustomModel extends BaseCustomModelApiTest @Test public void testDeactivateCustomModel() throws Exception { + setRequestContext(customModelAdmin); + String modelNameOne = "testDeactivateModelOne" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator CustomModel customModelOne = createCustomModel(modelNameOne, namespacePair, ModelStatus.ACTIVE, null, "Mark Moe"); // Retrieve the created model and check its status - HttpResponse response = getSingle("cmm", customModelAdmin, modelNameOne, 200); + HttpResponse response = getSingle("cmm", modelNameOne, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.ACTIVE, returnedModel.getStatus()); @@ -273,20 +289,24 @@ public class TestCustomModel extends BaseCustomModelApiTest CustomModel updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.DRAFT); + setRequestContext(nonAdminUserName); + // Try to deactivate the model as a non Admin user - put("cmm", nonAdminUserName, modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 403); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 403); + setRequestContext(customModelAdmin); + // Deactivate the model as a Model Administrator - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); - response = getSingle("cmm", customModelAdmin, modelNameOne, 200); + response = getSingle("cmm", modelNameOne, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.DRAFT, returnedModel.getStatus()); // Check other properties have not been modified compareCustomModels(customModelOne, returnedModel, "status"); // Try to deactivate the already deactivated model as a Model Administrator - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 500); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 500); // Activate/Deactivate a model with an aspect { @@ -298,24 +318,24 @@ public class TestCustomModel extends BaseCustomModelApiTest // Aspect CustomAspect aspect = new CustomAspect(); aspect.setName("testMarkerAspect"); - post("cmm/" + modelNameTwo + "/aspects", customModelAdmin, RestApiUtil.toJsonAsString(aspect), 201); + post("cmm/" + modelNameTwo + "/aspects", RestApiUtil.toJsonAsString(aspect), 201); // Retrieve the created aspect - getSingle("cmm/" + modelNameTwo + "/aspects", customModelAdmin, aspect.getName(), 200); + getSingle("cmm/" + modelNameTwo + "/aspects", aspect.getName(), 200); // Activate the model as a Model Administrator customModelTwo.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameTwo, RestApiUtil.toJsonAsString(customModelTwo), SELECT_STATUS_QS, 200); + put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(customModelTwo), SELECT_STATUS_QS, 200); - response = getSingle("cmm", customModelAdmin, modelNameTwo, 200); + response = getSingle("cmm", modelNameTwo, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.ACTIVE, returnedModel.getStatus()); updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.DRAFT); // Deactivate the model as a Model Administrator - put("cmm", customModelAdmin, modelNameTwo, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); - response = getSingle("cmm", customModelAdmin, modelNameTwo, 200); + response = getSingle("cmm", modelNameTwo, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.DRAFT, returnedModel.getStatus()); } @@ -324,43 +344,51 @@ public class TestCustomModel extends BaseCustomModelApiTest @Test public void testDeleteCustomModel() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testDeleteModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator CustomModel customModel = createCustomModel(modelName, namespacePair, ModelStatus.DRAFT, null, "Joe Bloggs"); // Retrieve the created model - HttpResponse response = getSingle("cmm", customModelAdmin, modelName, 200); + HttpResponse response = getSingle("cmm", modelName, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); compareCustomModels(customModel, returnedModel); + setRequestContext(nonAdminUserName); + // Try to delete the model as a non Admin user - delete("cmm", nonAdminUserName, modelName, 403); + delete("cmm", modelName, 403); + + setRequestContext(customModelAdmin); // Delete the model as a Model Administrator - delete("cmm", customModelAdmin, modelName, 204); + delete("cmm", modelName, 204); // Create the model again - post("cmm", customModelAdmin, RestApiUtil.toJsonAsString(customModel), 201); + post("cmm", RestApiUtil.toJsonAsString(customModel), 201); // Activated the model CustomModel updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); // Try to delete the active model - delete("cmm", customModelAdmin, modelName, 409); + delete("cmm", modelName, 409); // Deactivate and then delete the model updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); - delete("cmm", customModelAdmin, modelName, 204); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + delete("cmm", modelName, 204); } @Test public void testUpdateBasicModel() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -370,31 +398,31 @@ public class TestCustomModel extends BaseCustomModelApiTest CustomModel updatePayload = new CustomModel(); String newName = modelName + "Modified"; updatePayload.setName(newName); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 400); // Cannot update the model name + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 400); // Cannot update the model name // Test update the namespace URI (already in-use) updatePayload = new CustomModel(); updatePayload.setNamespaceUri("http://www.alfresco.org/model/content/1.0"); updatePayload.setNamespacePrefix("newPrefix"); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); // The namespace uri has already been used + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); // The namespace uri has already been used // Test update the namespace Prefix (already in-use) updatePayload = new CustomModel(); updatePayload.setNamespaceUri(getTestNamespaceUriPrefixPair().getFirst()); updatePayload.setNamespacePrefix("cm"); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); // The namespace prefix has already been used + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); // The namespace prefix has already been used // Test update the namespace URI (without sending the namespace prefix) updatePayload = new CustomModel(); updatePayload.setNamespaceUri(getTestNamespaceUriPrefixPair().getFirst()); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 400); // The namespace prefix is mandatory + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 400); // The namespace prefix is mandatory // Test update the namespace URI only updatePayload = new CustomModel(); updatePayload.setNamespacePrefix( namespacePair.getSecond()); Pair newURI = getTestNamespaceUriPrefixPair(); updatePayload.setNamespaceUri(newURI.getFirst()); - HttpResponse response = put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); + HttpResponse response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(newURI.getFirst(), returnedModel.getNamespaceUri()); assertEquals("The namespace prefix shouldn't have changed.", namespacePair.getSecond(), returnedModel.getNamespacePrefix()); @@ -402,14 +430,14 @@ public class TestCustomModel extends BaseCustomModelApiTest // Test update the namespace prefix (without sending the namespace URI) updatePayload = new CustomModel(); updatePayload.setNamespacePrefix("newPrefix"); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 400); // The namespce uri is mandatory + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 400); // The namespce uri is mandatory // Test update the namespace prefix only updatePayload = new CustomModel(); updatePayload.setNamespaceUri(namespacePair.getFirst()); Pair newPrefix = getTestNamespaceUriPrefixPair(); updatePayload.setNamespacePrefix( newPrefix.getSecond()); - response = put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); + response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(newPrefix.getSecond(), returnedModel.getNamespacePrefix()); assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri()); @@ -423,13 +451,18 @@ public class TestCustomModel extends BaseCustomModelApiTest updatePayload.setAuthor("John Moe"); updatePayload.setStatus(ModelStatus.ACTIVE); // This should be ignored + setRequestContext(nonAdminUserName); + // Try to update the model as a non Admin user - put("cmm", nonAdminUserName, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 403); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 403); + + setRequestContext(customModelAdmin); + // Update the model as a Model Administrator - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); // Retrieve the updated model - response = getSingle("cmm", customModelAdmin, modelName, 200); + response = getSingle("cmm", modelName, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); compareCustomModels(updatePayload, returnedModel, "name", "status"); assertEquals("The model status should only be updated via '?select=status' request.", ModelStatus.DRAFT, returnedModel.getStatus()); @@ -437,7 +470,7 @@ public class TestCustomModel extends BaseCustomModelApiTest // Activate the model as a Model Administrator updatePayload = new CustomModel(); updatePayload.setStatus(ModelStatus.ACTIVE); - response = put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); + response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.ACTIVE, returnedModel.getStatus()); @@ -447,14 +480,14 @@ public class TestCustomModel extends BaseCustomModelApiTest updatePayload.setNamespaceUri(newNamespacePair.getFirst()); updatePayload.setNamespacePrefix(returnedModel.getNamespacePrefix()); // Cannot update the namespace uri and/or namespace prefix when the model is Active. - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); // Try to update the ACTIVE model's namespace Prefix updatePayload = new CustomModel(); updatePayload.setNamespaceUri(returnedModel.getNamespaceUri()); updatePayload.setNamespacePrefix("myNewPrefix"); // Cannot update the namespace uri and/or namespace prefix when the model is Active. - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 409); // Test a valid update of an Active model (you can only update desc and author) updatePayload = new CustomModel(); @@ -462,10 +495,10 @@ public class TestCustomModel extends BaseCustomModelApiTest updatePayload.setNamespacePrefix(returnedModel.getNamespacePrefix()); updatePayload.setDescription("Test modifying active model description"); updatePayload.setAuthor("Mark Miller"); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); // Retrieve the updated active model - response = getSingle("cmm", customModelAdmin, modelName, 200); + response = getSingle("cmm", modelName, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); compareCustomModels(updatePayload, returnedModel, "name", "status"); } @@ -474,6 +507,8 @@ public class TestCustomModel extends BaseCustomModelApiTest //SHA-726 public void testUpdateModel_WithAspectsAndTypes() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -492,7 +527,7 @@ public class TestCustomModel extends BaseCustomModelApiTest // Activate the model CustomModel modelOneStatusPayload = new CustomModel(); modelOneStatusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); // Add another type with 'typeBaseName' as its parent String childTypeName = "testTypeChild" + System.currentTimeMillis(); @@ -505,14 +540,14 @@ public class TestCustomModel extends BaseCustomModelApiTest // Deactivate the model modelOneStatusPayload = new CustomModel(); modelOneStatusPayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); // Test update the namespace prefix CustomModel updatePayload = new CustomModel(); String modifiedPrefix = namespacePair.getSecond() + "Modified"; updatePayload.setNamespacePrefix(modifiedPrefix); updatePayload.setNamespaceUri(namespacePair.getFirst()); - HttpResponse response = put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); + HttpResponse response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(modifiedPrefix, returnedModel.getNamespacePrefix()); assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri()); @@ -522,19 +557,19 @@ public class TestCustomModel extends BaseCustomModelApiTest updatePayload.setNamespacePrefix(modifiedPrefix); String modifiedURI = namespacePair.getFirst() + "Modified"; updatePayload.setNamespaceUri(modifiedURI); - response = put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); + response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(modifiedURI, returnedModel.getNamespaceUri()); assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix()); // Retrieve the child type - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, childTypeName, 200); + response = getSingle("cmm/" + modelName + "/types", childTypeName, 200); CustomType returnedChildType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); final String newTypeParentName = modifiedPrefix + QName.NAMESPACE_PREFIX + typeBaseName; assertEquals("The parent name prefix should have been updated.", newTypeParentName, returnedChildType.getParentName()); // Retrieve the child aspect - response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, childAspectName, 200); + response = getSingle("cmm/" + modelName + "/aspects", childAspectName, 200); CustomAspect returnedChildAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); final String newAspectParentName = modifiedPrefix + QName.NAMESPACE_PREFIX + aspectName; assertEquals("The parent name prefix should have been updated.", newAspectParentName, returnedChildAspect.getParentName()); @@ -544,6 +579,8 @@ public class TestCustomModel extends BaseCustomModelApiTest @Test public void testModelsCircularDependency() throws Exception { + setRequestContext(customModelAdmin); + // Model One String modelNameOne = "testModelOne" + System.currentTimeMillis(); Pair namespacePairOne = getTestNamespaceUriPrefixPair(); @@ -558,7 +595,7 @@ public class TestCustomModel extends BaseCustomModelApiTest // Activate modelOne CustomModel modelOneStatusPayload = new CustomModel(); modelOneStatusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); // Add another type into modelOne with 'typeA_M1' as its parent String typeB_M1 = "testTypeB_M1" + System.currentTimeMillis(); @@ -579,7 +616,7 @@ public class TestCustomModel extends BaseCustomModelApiTest // Activate modelTwo CustomModel modelTwoStatusPayload = new CustomModel(); modelTwoStatusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200); // Test that the API can handle "circular dependency" - (modelOne depends on modelTwo) { @@ -591,7 +628,7 @@ public class TestCustomModel extends BaseCustomModelApiTest typeC_M1_Payload.setParentName(type1_M2_WithPrefix); // => 'type1_M2' (from modelTwo) // Try to create typeC_M1 which has 'circular dependency' - post("cmm/" + modelNameOne + "/types", customModelAdmin, RestApiUtil.toJsonAsString(typeC_M1_Payload), 409); //Constraint violation + post("cmm/" + modelNameOne + "/types", RestApiUtil.toJsonAsString(typeC_M1_Payload), 409); //Constraint violation } // Model Three @@ -608,7 +645,7 @@ public class TestCustomModel extends BaseCustomModelApiTest // Activate modelThree CustomModel modelThreeStatusPayload = new CustomModel(); modelThreeStatusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameThree, RestApiUtil.toJsonAsString(modelThreeStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameThree, RestApiUtil.toJsonAsString(modelThreeStatusPayload), SELECT_STATUS_QS, 200); // Test that the API can handle "circular dependency" - (modelOne depends on modelThree) { @@ -620,7 +657,7 @@ public class TestCustomModel extends BaseCustomModelApiTest typeC_M1_Payload.setParentName(type1_M3_WithPrefix); // => 'type1_M3' (from modelThree) // Try to create typeC_M1 which has 'circular dependency' - post("cmm/" + modelNameOne + "/types", customModelAdmin, RestApiUtil.toJsonAsString(typeC_M1_Payload), 409); //Constraint violation + post("cmm/" + modelNameOne + "/types", RestApiUtil.toJsonAsString(typeC_M1_Payload), 409); //Constraint violation } // Model Three @@ -637,7 +674,7 @@ public class TestCustomModel extends BaseCustomModelApiTest // Activate modelFour CustomModel modelFourStatusPayload = new CustomModel(); modelFourStatusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameFour, RestApiUtil.toJsonAsString(modelFourStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameFour, RestApiUtil.toJsonAsString(modelFourStatusPayload), SELECT_STATUS_QS, 200); // Test that the API can handle "circular dependency" - (modelOne depends on modelFour) { @@ -649,7 +686,7 @@ public class TestCustomModel extends BaseCustomModelApiTest typeC_M1_Payload.setParentName(type1_M4_WithPrefix); // => 'type1_M4' (from modelFour) // Try to create typeC_M1 which has 'circular dependency' - post("cmm/" + modelNameOne + "/types", customModelAdmin, RestApiUtil.toJsonAsString(typeC_M1_Payload), 409); //Constraint violation + post("cmm/" + modelNameOne + "/types", RestApiUtil.toJsonAsString(typeC_M1_Payload), 409); //Constraint violation } // Test that the API can handle "circular dependency" - (modelTwo depends on modelFour) @@ -662,7 +699,7 @@ public class TestCustomModel extends BaseCustomModelApiTest type2_M2_Payload.setParentName(type1_M4_WithPrefix); // => 'type1_M4' (from modelFour) // Try to create type2_M2 which has 'circular dependency' - post("cmm/" + modelNameTwo + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type2_M2_Payload), 409); //Constraint violation + post("cmm/" + modelNameTwo + "/types", RestApiUtil.toJsonAsString(type2_M2_Payload), 409); //Constraint violation } } } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestCustomModelExport.java b/source/test-java/org/alfresco/rest/api/tests/TestCustomModelExport.java index 175f132283..b2f316865b 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestCustomModelExport.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestCustomModelExport.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 . + * #L% + */ package org.alfresco.rest.api.tests; import static org.junit.Assert.assertEquals; @@ -71,6 +71,8 @@ public class TestCustomModelExport extends BaseCustomModelApiTest @Test public void testCreateDownload() throws Exception { + setRequestContext(customModelAdmin); + final String modelName = "testModel" + System.currentTimeMillis(); final String modelExportFileName = modelName + ".xml"; final String shareExtExportFileName = "CMM_" + modelName + "_module.xml"; @@ -86,11 +88,15 @@ public class TestCustomModelExport extends BaseCustomModelApiTest // Create Share extension module downloadTestUtil.createShareExtModule(modelName); - // Try to create download the model as a non Admin user - post("cmm/" + modelName + "/download", nonAdminUserName, RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 403); + setRequestContext(nonAdminUserName); + // Try to create download the model as a non Admin user + post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 403); + + setRequestContext(customModelAdmin); + // Create download for custom model only - HttpResponse response = post("cmm/" + modelName + "/download", customModelAdmin, RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 201); + HttpResponse response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 201); CustomModelDownload returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class); assertNotNull(returnedDownload); assertNotNull(returnedDownload.getNodeRef()); @@ -111,7 +117,7 @@ public class TestCustomModelExport extends BaseCustomModelApiTest assertEquals(modelEntry, modelExportFileName); // Create download for custom model and its share extension module - response = post("cmm/" + modelName + "/download", customModelAdmin, RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(true), 201); + response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(true), 201); returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class); assertNotNull(returnedDownload); assertNotNull(returnedDownload.getNodeRef()); diff --git a/source/test-java/org/alfresco/rest/api/tests/TestCustomProperty.java b/source/test-java/org/alfresco/rest/api/tests/TestCustomProperty.java index 8b7139b6a0..a37ba0e654 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestCustomProperty.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestCustomProperty.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 . + * #L% + */ package org.alfresco.rest.api.tests; @@ -63,6 +63,8 @@ public class TestCustomProperty extends BaseCustomModelApiTest @Test public void testCreateProperties() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -86,18 +88,23 @@ public class TestCustomProperty extends BaseCustomModelApiTest List props = new ArrayList<>(1); props.add(aspectProp); payload.setProperties(props); - // Try to update the aspect as a non Admin user - put("cmm/" + modelName + "/aspects", nonAdminUserName, aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403); + setRequestContext(nonAdminUserName); + + // Try to update the aspect as a non Admin user + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403); + + setRequestContext(customModelAdmin); + // Try to update the aspect as a Model Administrator - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400); // Type name is mandatory + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400); // Type name is mandatory // Add the mandatory aspect name to the payload payload.setName(aspectName); - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); // Retrieve the updated aspect - HttpResponse response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspect.getName(), 200); + HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); // Check the aspect's added property assertEquals(1, returnedAspect.getProperties().size()); @@ -123,7 +130,7 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(aspectProp); payload.setProperties(props); // Try to update the aspect as a Model Administrator - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409); // property name already exists + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409); // property name already exists } { @@ -145,18 +152,22 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(typeProp); payload.setProperties(props); + setRequestContext(nonAdminUserName); + // Try to update the type as a non Admin user - put("cmm/" + modelName + "/types", nonAdminUserName, typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403); + setRequestContext(customModelAdmin); + // Try to update the type as a Model Administrator - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400); // Type name is mandatory + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400); // Type name is mandatory // Add the mandatory type name to the payload payload.setName(typeName); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); // Retrieve the updated type - HttpResponse response = getSingle("cmm/" + modelName + "/types", customModelAdmin, type.getName(), 200); + HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); // Check the type's added property assertEquals(1, returnedType.getProperties().size()); @@ -175,7 +186,7 @@ public class TestCustomProperty extends BaseCustomModelApiTest assertEquals(IndexTokenisationMode.FALSE, customModelProperty.getIndexTokenisationMode()); // Retrieve the updated type with all the properties (include inherited) - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, type.getName()+SELECT_ALL_PROPS, 200); + response = getSingle("cmm/" + modelName + "/types", type.getName()+SELECT_ALL_PROPS, 200); returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); assertEquals(3, returnedType.getProperties().size()); // Check for the inherited properties @@ -198,10 +209,10 @@ public class TestCustomProperty extends BaseCustomModelApiTest props = new ArrayList<>(1); props.add(typeProp); payload.setProperties(props); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); // Retrieve the updated type - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, type.getName(), 200); + response = getSingle("cmm/" + modelName + "/types", type.getName(), 200); returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); // Check the type's added property assertEquals(2, returnedType.getProperties().size()); @@ -225,13 +236,15 @@ public class TestCustomProperty extends BaseCustomModelApiTest props = new ArrayList<>(1); props.add(typeProp); payload.setProperties(props); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409); // property name already exists + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409); // property name already exists } } @Test public void testDeleteProperty() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelDeleteProp" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -255,7 +268,7 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(aspectPropOne); aspectPayload.setProperties(props); // create property one - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); // Update the Aspect by adding another property - property two aspectPayload = new CustomAspect(); @@ -272,10 +285,10 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(aspectPropTwo); aspectPayload.setProperties(props); // create property two - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); // Retrieve the updated aspect - HttpResponse response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); // Check the aspect's added properties assertEquals(2, returnedAspect.getProperties().size()); @@ -298,7 +311,7 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(typePropOne); typePayload.setProperties(props); // create property one - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); // Update the Type by adding another property - property two typePayload = new CustomType(); @@ -325,10 +338,10 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(typePropTwo); typePayload.setProperties(props); // create property one - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); // Retrieve the updated type - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, typeName, 200); + response = getSingle("cmm/" + modelName + "/types", typeName, 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); // Check the type's added properties assertEquals(2, returnedType.getProperties().size()); @@ -337,47 +350,57 @@ public class TestCustomProperty extends BaseCustomModelApiTest { final String deletePropOneAspectQS = getPropDeleteUpdateQS(aspectPropNameOne, true); // Try to delete propertyOne from aspect - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, null, deletePropOneAspectQS, 400); // missing payload + put("cmm/" + modelName + "/aspects", aspectName, null, deletePropOneAspectQS, 400); // missing payload CustomAspect deletePropAspectPayload = new CustomAspect(); - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 400); // missing aspect name + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 400); // missing aspect name + setRequestContext(nonAdminUserName); + deletePropAspectPayload.setName(aspectName); - put("cmm/" + modelName + "/aspects", nonAdminUserName, aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 403); // unauthorised + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 403); // unauthorised + + setRequestContext(customModelAdmin); + // Delete as a Model Administrator - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 200); // Check the property has been deleted - response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 200); + response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200); returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); assertEquals(1, returnedAspect.getProperties().size()); assertFalse("Property one should have been deleted.", aspectPropNameOne.equals(returnedAspect.getProperties().get(0).getName())); - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 404); //Not found + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 404); //Not found } // Delete type's property two - model is inactive { final String deletePropTwoTypeQS = getPropDeleteUpdateQS(typePropNameTwo, true); // Try to delete propertyOne from type - put("cmm/" + modelName + "/types", customModelAdmin, typeName, null, deletePropTwoTypeQS, 400); // missing payload + put("cmm/" + modelName + "/types", typeName, null, deletePropTwoTypeQS, 400); // missing payload CustomType deletePropTypePayload = new CustomType(); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 400); // missing type name + setRequestContext(nonAdminUserName); + deletePropTypePayload.setName(typeName); - put("cmm/" + modelName + "/types", nonAdminUserName, typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 403); // unauthorised + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 403); // unauthorised + + setRequestContext(customModelAdmin); + // Delete as a Model Administrator - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 200); // Check the property has been deleted - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, typeName, 200); + response = getSingle("cmm/" + modelName + "/types", typeName, 200); returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); assertEquals(1, returnedType.getProperties().size()); assertFalse("Property two should have been deleted.", typePropNameTwo.equals(returnedType.getProperties().get(0).getName())); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 404); //Not found + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 404); //Not found } // Note: at the time of writing, we can't delete a property of an active model, as ModelValidatorImpl.validateIndexedProperty depends on Solr @@ -387,6 +410,8 @@ public class TestCustomProperty extends BaseCustomModelApiTest @Test public void testUpdateProperty() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelUpdateProp" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -410,10 +435,10 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(aspectProp); aspectPayload.setProperties(props); // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); // Retrieve the updated aspect - HttpResponse response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 200); + HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); // Check the aspect's added property assertEquals(1, returnedAspect.getProperties().size()); @@ -450,10 +475,10 @@ public class TestCustomProperty extends BaseCustomModelApiTest props.add(typeProp); typePayload.setProperties(props); // create property - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200); // Retrieve the updated type - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, typeName, 200); + response = getSingle("cmm/" + modelName + "/types", typeName, 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); // Check the type's added property assertEquals(1, returnedType.getProperties().size()); @@ -462,7 +487,7 @@ public class TestCustomProperty extends BaseCustomModelApiTest { final String updatePropOneAspectQS = getPropDeleteUpdateQS(aspectPropName, false); // Try to update property from aspect - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, null, updatePropOneAspectQS, 400); // missing payload + put("cmm/" + modelName + "/aspects", aspectName, null, updatePropOneAspectQS, 400); // missing payload CustomAspect updatePropAspectPayload = new CustomAspect(); CustomModelProperty propertyAspect = new CustomModelProperty(); @@ -476,25 +501,29 @@ public class TestCustomProperty extends BaseCustomModelApiTest modifiedProp.add(propertyAspect); updatePropAspectPayload.setProperties(modifiedProp); - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 400); // missing aspect name + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 400); // missing aspect name // set a random name updatePropAspectPayload.setName(aspectName + System.currentTimeMillis()); - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 404); // Aspect not found + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 404); // Aspect not found // set the correct name updatePropAspectPayload.setName(aspectName); // the requested property name dose not match the payload - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 400); // set the property name that matches the requested property propertyAspect.setName(aspectPropName); - put("cmm/" + modelName + "/aspects", nonAdminUserName, aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 403); // unauthorised + + setRequestContext(nonAdminUserName); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 403); // unauthorised + + setRequestContext(customModelAdmin); // Update as a Model Administrator - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(updatePropAspectPayload), updatePropOneAspectQS, 200); // Check the property has been updated - response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 200); + response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200); returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); assertEquals(1, returnedAspect.getProperties().size()); CustomModelProperty modifiedAspectProperty = returnedAspect.getProperties().get(0); @@ -504,7 +533,7 @@ public class TestCustomProperty extends BaseCustomModelApiTest // Activate the model CustomModel statusPayload = new CustomModel(); statusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); // Update type's property - model is active { @@ -521,26 +550,31 @@ public class TestCustomProperty extends BaseCustomModelApiTest modifiedProp.add(propertyType); updatePropTypePayload.setProperties(modifiedProp); + setRequestContext(nonAdminUserName); + // Unauthorised - put("cmm/" + modelName + "/types", nonAdminUserName, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 403); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 403); + + setRequestContext(customModelAdmin); + // Try to update an active model as a Model Administrator - Cannot change the data type of the property of an active model - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); // Set the data type with its original value propertyType.setDataType("d:int"); propertyType.setMultiValued(true);// the original value was false // Cannot change the multi-valued option of the property of an active model - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); propertyType.setMultiValued(false); propertyType.setMandatory(true);// the original value was false // Cannot change the mandatory option of the property of an active model - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); propertyType.setMandatory(false); propertyType.setMandatoryEnforced(true);// the original value was false // Cannot change the mandatory-enforced option of the property of an active model - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); // Set the mandatory-enforced with its original value propertyType.setMandatoryEnforced(false); @@ -553,13 +587,13 @@ public class TestCustomProperty extends BaseCustomModelApiTest propertyType.setConstraints(Arrays.asList(inlineMinMaxConstraint)); // add the updated inline constraint // Try to Update - constraint violation. The default value is 5 which is not in the MinMax range [20, 120] - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 409); propertyType.setDefaultValue("25"); // we changed the MinMax constraint to be [20, 120] - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 200); // Check the property has been updated - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, typeName, 200); + response = getSingle("cmm/" + modelName + "/types", typeName, 200); returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); assertEquals(1, returnedType.getProperties().size()); CustomModelProperty modifiedTypeProperty = returnedType.getProperties().get(0); @@ -586,13 +620,13 @@ public class TestCustomProperty extends BaseCustomModelApiTest inlineMinMaxConstraint.setParameters(parameters); propertyType.setConstraints(Arrays.asList(inlineMinMaxConstraint)); // LENGTH can only be used with textual data type - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 400); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 400); //update the property by removing the constraint propertyType.setConstraints(Collections.emptyList()); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(updatePropTypePayload), updatePropTwoTypeQS, 200); - response = getSingle("cmm/" + modelName + "/types", customModelAdmin, typeName, 200); + response = getSingle("cmm/" + modelName + "/types", typeName, 200); returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); assertEquals(1, returnedType.getProperties().size()); modifiedTypeProperty = returnedType.getProperties().get(0); @@ -603,6 +637,8 @@ public class TestCustomProperty extends BaseCustomModelApiTest @Test public void testValidatePropertyDefaultValue() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModelPropDefaultValue" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -632,19 +668,19 @@ public class TestCustomProperty extends BaseCustomModelApiTest aspectProp.setDataType("d:int"); aspectProp.setDefaultValue(" ");// space - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); aspectProp.setDefaultValue("abc"); // text // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); aspectProp.setDefaultValue("1.0"); // double // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); aspectProp.setDefaultValue("1,2,3"); // text // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); } // d:float tests @@ -652,50 +688,50 @@ public class TestCustomProperty extends BaseCustomModelApiTest aspectProp.setDataType("d:float"); aspectProp.setDefaultValue(" ");// space - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); aspectProp.setDefaultValue("abc"); // text // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); aspectProp.setDefaultValue("1,2,3"); // text // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400); aspectProp.setDefaultValue("1.0"); // float // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200); aspectProp.setDefaultValue("1.0f"); // float - update // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); aspectProp.setDefaultValue("1.0d"); // double - update // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); } // d:boolean tests { aspectProp.setDataType("d:boolean"); aspectProp.setDefaultValue(" ");// space - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400); aspectProp.setDefaultValue("abc"); // text // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400); aspectProp.setDefaultValue("1"); // number // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400); aspectProp.setDefaultValue("true"); // valid value // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); aspectProp.setDefaultValue("false"); // valid value // create property - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200); } } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestCustomTypeAspect.java b/source/test-java/org/alfresco/rest/api/tests/TestCustomTypeAspect.java index 5986775b74..6f02f89034 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestCustomTypeAspect.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestCustomTypeAspect.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 . + * #L% + */ package org.alfresco.rest.api.tests; @@ -63,6 +63,8 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest @Test public void testCreateAspectsAndTypes_ExistingModel() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -74,23 +76,27 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest CustomAspect aspect = new CustomAspect(); aspect.setName(aspectName); + setRequestContext(nonAdminUserName); + // Try to create aspect as a non Admin user - post("cmm/" + modelName + "/aspects", nonAdminUserName, RestApiUtil.toJsonAsString(aspect), 403); + post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 403); + + setRequestContext(customModelAdmin); // Set the aspect's parent with a type name! aspect.setParentName("cm:content"); // Try to create an invalid aspect as a Model Administrator - post("cmm/" + modelName + "/aspects", customModelAdmin, RestApiUtil.toJsonAsString(aspect), 409); + post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409); // Create aspect as a Model Administrator aspect.setParentName(null); - post("cmm/" + modelName + "/aspects", customModelAdmin, RestApiUtil.toJsonAsString(aspect), 201); + post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 201); // Create the aspect again - duplicate name - post("cmm/" + modelName + "/aspects", customModelAdmin, RestApiUtil.toJsonAsString(aspect), 409); + post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409); // Retrieve the created aspect - HttpResponse response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspect.getName(), 200); + HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); compareCustomTypesAspects(aspect, returnedAspect, "prefixedName"); assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectName, returnedAspect.getPrefixedName()); @@ -105,23 +111,27 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest type.setTitle("test type title"); type.setParentName("cm:content"); + setRequestContext(nonAdminUserName); + // Try to create type as a non Admin user - post("cmm/" + modelName + "/types", nonAdminUserName, RestApiUtil.toJsonAsString(type), 403); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 403); + + setRequestContext(customModelAdmin); // Set the type's parent with an aspect name! type.setParentName("cm:titled"); // Try to create an invalid type as a Model Administrator - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type), 409); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409); // Create type as a Model Administrator type.setParentName("cm:content"); - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type), 201); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 201); // Create the type again - duplicate name - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type), 409); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409); // Retrieve the created type - HttpResponse response = getSingle("cmm/" + modelName + "/types", customModelAdmin, type.getName(), 200); + HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); compareCustomTypesAspects(type, returnedType, "prefixedName"); assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeName, returnedType.getPrefixedName()); @@ -142,19 +152,21 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest // Set the aspect name with an existing type name. The model // cannot have a type and an aspect with the same name. aspect.setName(typeName); - post("cmm/" + modelName + "/aspects", customModelAdmin, RestApiUtil.toJsonAsString(aspect), 409); + post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409); CustomType type = new CustomType(); // Set the type name with an existing aspect name type.setName(aspectName); type.setParentName("cm:content"); - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type), 409); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409); } } @Test public void testCreateModel_WithAspectsAndTypes_Invalid() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -168,19 +180,19 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest type.setDescription("test type Desc"); // Try to create a model with an invalid type name (null) - post(typeURL, customModelAdmin, RestApiUtil.toJsonAsString(type), 400); + post(typeURL, RestApiUtil.toJsonAsString(type), 400); // Try to create a model with an invalid type name (name contains ':') type.setName("prefix:someTypename"); - post(typeURL, customModelAdmin, RestApiUtil.toJsonAsString(type), 400); + post(typeURL, RestApiUtil.toJsonAsString(type), 400); // Try to create a model with an invalid type name (name is empty) type.setName(""); - post(typeURL, customModelAdmin, RestApiUtil.toJsonAsString(type), 400); + post(typeURL, RestApiUtil.toJsonAsString(type), 400); // Try to create a model with an invalid type name (name contains '<') type.setName("testType') aspect.setName("testType>name"); - post(aspectURL, customModelAdmin, RestApiUtil.toJsonAsString(aspect), 400); + post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400); } } @Test public void testCreateAspectsAndTypesWithProperties() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -230,9 +244,9 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest aspect.setProperties(props); // Create aspect as a Model Administrator - post("cmm/" + modelName + "/aspects", customModelAdmin, RestApiUtil.toJsonAsString(aspect), 201); + post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 201); // Retrieve the created aspect - HttpResponse response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspect.getName(), 200); + HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); compareCustomTypesAspects(aspect, returnedAspect, "prefixedName", "dataType", "indexTokenisationMode"); assertEquals(1, returnedAspect.getProperties().size()); @@ -265,13 +279,13 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest type.setProperties(props); // Create type as a Model Administrator - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type), 400); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 400); typeProp.setDataType("d:int"); - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type), 201); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 201); // Retrieve the created type - HttpResponse response = getSingle("cmm/" + modelName + "/types", customModelAdmin, type.getName(), 200); + HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); compareCustomTypesAspects(type, returnedType, "prefixedName", "indexTokenisationMode"); assertEquals("Shouldn't list the inherited properties from 'cm:content'.", 1, returnedType.getProperties().size()); @@ -296,7 +310,7 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest type2.setDescription("test type2 Desc"); type2.setTitle("test type2 title"); type2.setParentName("cm:content"); - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type2), 201); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type2), 201); String typeName3 = "testType3" + System.currentTimeMillis(); CustomType type3 = new CustomType(); @@ -304,18 +318,18 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest type3.setDescription("test type3 Desc"); type3.setTitle("test type3 title"); type3.setParentName("cm:content"); - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type3), 201); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type3), 201); } { // Retrieve the created model - HttpResponse response = getSingle("cmm", customModelAdmin, modelName, 200); + HttpResponse response = getSingle("cmm", modelName, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertNull(returnedModel.getTypes()); assertNull(returnedModel.getAspects()); // Retrieve the created model with its types and aspects - response = getSingle("cmm", customModelAdmin, modelName + SELECT_ALL, 200); + response = getSingle("cmm", modelName + SELECT_ALL, 200); returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertNotNull(returnedModel.getTypes()); assertEquals(3, returnedModel.getTypes().size()); @@ -328,6 +342,8 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest //SHA-679 public void testCustomModelTypesAspectsDependencies() throws Exception { + setRequestContext(customModelAdmin); + String modelNameOne = "testModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -341,9 +357,9 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest // Activate the model CustomModel modelOneStatusPayload = new CustomModel(); modelOneStatusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); - HttpResponse response = getSingle("cmm", customModelAdmin, modelNameOne, 200); + HttpResponse response = getSingle("cmm", modelNameOne, 200); CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class); assertEquals(ModelStatus.ACTIVE, returnedModel.getStatus()); @@ -352,7 +368,7 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest createTypeAspect(CustomType.class, modelNameOne, typeName2, "test typeChild title", "test typeChild Desc", typeBaseNameWithPrefix); Paging paging = getPaging(0, Integer.MAX_VALUE); - response = getAll("cmm/" + modelNameOne + "/types", customModelAdmin, paging, 200); + response = getAll("cmm/" + modelNameOne + "/types", paging, 200); List returnedTypes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomType.class); assertEquals(2, returnedTypes.size()); @@ -368,32 +384,34 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest // Try to deactivate modelOne modelOneStatusPayload = new CustomModel(); modelOneStatusPayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 409); // ModelTwo depends on ModelOne + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 409); // ModelTwo depends on ModelOne // Activate modelTwo CustomModel modelTwoStatusPayload = new CustomModel(); modelTwoStatusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200); // Try to deactivate modelOne again. The dependent model is Active now, however, the result should be the same. - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 409); // ModelTwo depends on ModelOne + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 409); // ModelTwo depends on ModelOne // Deactivate modelTwo modelTwoStatusPayload = new CustomModel(); modelTwoStatusPayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200); // Delete the modelTwo's type as a Model Administrator - delete("cmm/" + modelNameTwo + "/types", customModelAdmin, modelTwoTypeName, 204); + delete("cmm/" + modelNameTwo + "/types", modelTwoTypeName, 204); // Try to deactivate modelOne again. There is no dependency - put("cmm", customModelAdmin, modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200); } @Test public void testDeleteTypeAspect() throws Exception { + setRequestContext(customModelAdmin); + final String modelName = "testDeleteTypeModel" + System.currentTimeMillis(); Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -411,34 +429,46 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest // Delete type { + setRequestContext(nonAdminUserName); + // Try to delete the model's type as a non Admin user - delete("cmm/" + modelName + "/types", nonAdminUserName, typeName, 403); + delete("cmm/" + modelName + "/types", typeName, 403); + + setRequestContext(customModelAdmin); + // Delete the model's type as a Model Administrator - delete("cmm/" + modelName + "/types", customModelAdmin, typeName, 204); + delete("cmm/" + modelName + "/types", typeName, 204); // Try to retrieve the deleted type - getSingle("cmm/" + modelName + "/types", customModelAdmin, typeName, 404); + getSingle("cmm/" + modelName + "/types", typeName, 404); } // Delete Aspect { + setRequestContext(nonAdminUserName); + // Try to delete the model's aspect as a non Admin user - delete("cmm/" + modelName + "/aspects", nonAdminUserName, aspectName, 403); + delete("cmm/" + modelName + "/aspects", aspectName, 403); + + setRequestContext(customModelAdmin); + // Delete the model's aspect as a Model Administrator - delete("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 204); + delete("cmm/" + modelName + "/aspects", aspectName, 204); // Try to retrieve the deleted aspect - getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 404); + getSingle("cmm/" + modelName + "/aspects", aspectName, 404); } + setRequestContext(customModelAdmin); + // Create the type again - post("cmm/" + modelName + "/types", customModelAdmin, RestApiUtil.toJsonAsString(type), 201); + post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 201); // Retrieve the created type - HttpResponse response = getSingle("cmm/" + modelName + "/types", customModelAdmin, type.getName(), 200); + HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); compareCustomTypesAspects(type, returnedType, "prefixedName"); // Create the aspect again - post("cmm/" + modelName + "/aspects", customModelAdmin, RestApiUtil.toJsonAsString(aspect), 201); + post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 201); // Retrieve the created aspect - response = getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspect.getName(), 200); + response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); compareCustomTypesAspects(aspect, returnedAspect, "prefixedName"); @@ -454,13 +484,13 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest List props = new ArrayList<>(1); props.add(typeProp); payload.setProperties(props); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200); // Activate the model CustomModel statusPayload = new CustomModel(); statusPayload.setStatus(ModelStatus.ACTIVE); // Activate the model as a Model Administrator - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); // Test for SHA-703 // Add another type with 'typeName' as its parent @@ -472,54 +502,56 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest createTypeAspect(CustomAspect.class, modelName, childAspectName, "test child aspect title", null, aspectNameWithPrefix); // Delete the model's type as a Model Administrator - delete("cmm/" + modelName + "/types", customModelAdmin, typeName, 409); // Cannot delete a type of an active model + delete("cmm/" + modelName + "/types", typeName, 409); // Cannot delete a type of an active model // Delete the model's aspect as a Model Administrator - delete("cmm/" + modelName + "/aspects", customModelAdmin, childAspectName, 409); // Cannot delete an aspect of an active model + delete("cmm/" + modelName + "/aspects", childAspectName, 409); // Cannot delete an aspect of an active model // Deactivate the model statusPayload = new CustomModel(); statusPayload.setStatus(ModelStatus.DRAFT); // Deactivate the model as a Model Administrator - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); // Delete type { // Try to delete the model's type (parent) as a Model Administrator - delete("cmm/" + modelName + "/types", customModelAdmin, typeName, 409); // conflict: childTypeName depends on typeName + delete("cmm/" + modelName + "/types", typeName, 409); // conflict: childTypeName depends on typeName // Delete the child type first - delete("cmm/" + modelName + "/types", customModelAdmin, childTypeName, 204); + delete("cmm/" + modelName + "/types", childTypeName, 204); // Try to retrieve the deleted child type - getSingle("cmm/" + modelName + "/types", customModelAdmin, childTypeName, 404); + getSingle("cmm/" + modelName + "/types", childTypeName, 404); // Now delete the parent type - delete("cmm/" + modelName + "/types", customModelAdmin, typeName, 204); + delete("cmm/" + modelName + "/types", typeName, 204); // Try to retrieve the deleted parent type - getSingle("cmm/" + modelName + "/types", customModelAdmin, typeName, 404); + getSingle("cmm/" + modelName + "/types", typeName, 404); } // Delete Aspect { // Try to delete the model's aspect (parent) as a Model Administrator - delete("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 409); // conflict: childAspectName depends on aspectName + delete("cmm/" + modelName + "/aspects", aspectName, 409); // conflict: childAspectName depends on aspectName // Delete the child aspect first - delete("cmm/" + modelName + "/aspects", customModelAdmin, childAspectName, 204); + delete("cmm/" + modelName + "/aspects", childAspectName, 204); // Try to retrieve the deleted child aspect - getSingle("cmm/" + modelName + "/aspects", customModelAdmin, childAspectName, 404); + getSingle("cmm/" + modelName + "/aspects", childAspectName, 404); // Now delete the parent aspect - delete("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 204); + delete("cmm/" + modelName + "/aspects", aspectName, 204); // Try to retrieve the deleted parent aspect - getSingle("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, 404); + getSingle("cmm/" + modelName + "/aspects", aspectName, 404); } } @Test public void testUpdateAspectsTypes() throws Exception { + setRequestContext(customModelAdmin); + String modelName = "testModeEditAspectType" + System.currentTimeMillis(); final Pair namespacePair = getTestNamespaceUriPrefixPair(); // Create the model as a Model Administrator @@ -536,41 +568,45 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest aspectPayload.setTitle("title modified"); aspectPayload.setParentName("cm:titled"); - // Try to update the aspect as a non Admin user - put("cmm/" + modelName + "/aspects", nonAdminUserName, aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 403); + setRequestContext(nonAdminUserName); + // Try to update the aspect as a non Admin user + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 403); + + setRequestContext(customModelAdmin); + // Modify the name aspectPayload.setName(aspectName + "Modified"); // Try to update the aspect as a Model Administrator // Note: aspect/type name cannot be modified - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 404); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 404); aspectPayload.setName(aspectName); // Update the aspect as a Model Administrator - HttpResponse response = put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200); + HttpResponse response = put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200); CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class); compareCustomTypesAspects(aspectPayload, returnedAspect, "prefixedName"); // Update the aspect with an invalid parent aspectPayload.setParentName("cm:titled" + System.currentTimeMillis()); - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409); // Activate the model CustomModel statusPayload = new CustomModel(); statusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); // Remove the aspect's parent // Note: cannot update the parent of an ACTIVE type/aspect. aspectPayload.setParentName(null); - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409); statusPayload = new CustomModel(); statusPayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); // now update the aspect's parent - model is inactive - put("cmm/" + modelName + "/aspects", customModelAdmin, aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200); + put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200); } // Test update type @@ -591,25 +627,29 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest props.add(typeProp); addPropertyPayload.setProperties(props); // Create the property - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(addPropertyPayload), SELECT_PROPS_QS, 200); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(addPropertyPayload), SELECT_PROPS_QS, 200); // Update the type CustomType typePayload = new CustomType(); typePayload.setDescription("desc modified"); typePayload.setTitle("title modified"); - // Try to update the type as a non Admin user - put("cmm/" + modelName + "/types", nonAdminUserName, typeName, RestApiUtil.toJsonAsString(typePayload), null, 403); + setRequestContext(nonAdminUserName); + // Try to update the type as a non Admin user + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 403); + + setRequestContext(customModelAdmin); + // Modify the name typePayload.setName(typeName + "Modified"); // Try to update the type as a Model Administrator // Note: type/type name cannot be modified - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), null, 404); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 404); typePayload.setName(typeName); // Update the type as a Model Administrator - HttpResponse response = put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), null, 200); + HttpResponse response = put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 200); CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); assertEquals(typePayload.getDescription(), returnedType.getDescription()); assertEquals(typePayload.getTitle(), returnedType.getTitle()); @@ -620,24 +660,24 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest // Update the type with an invalid parent typePayload.setParentName("cm:folder" + System.currentTimeMillis()); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), null, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 409); // Activate the model CustomModel statusPayload = new CustomModel(); statusPayload.setStatus(ModelStatus.ACTIVE); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); // Remove the type's parent // Note: cannot update the parent of an ACTIVE type/type. typePayload.setParentName("cm:folder"); - put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), null, 409); + put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 409); statusPayload = new CustomModel(); statusPayload.setStatus(ModelStatus.DRAFT); - put("cmm", customModelAdmin, modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); + put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200); // now update the type's parent - model is inactive - response = put("cmm/" + modelName + "/types", customModelAdmin, typeName, RestApiUtil.toJsonAsString(typePayload), null, 200); + response = put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 200); returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class); assertEquals(typePayload.getParentName(), returnedType.getParentName()); } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java b/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java index 238359a518..de791d4178 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java @@ -64,6 +64,10 @@ import org.apache.commons.httpclient.HttpStatus; import org.junit.Before; import org.junit.Test; +/** + * V1 REST API tests for Node Comments + * + */ public class TestNodeComments extends EnterpriseTestApi { private TestNetwork network1; diff --git a/source/test-java/org/alfresco/rest/api/tests/TestSites.java b/source/test-java/org/alfresco/rest/api/tests/TestSites.java index 6b71db658d..8b0adfabc5 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestSites.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestSites.java @@ -54,6 +54,8 @@ import org.junit.Before; import org.junit.Test; /** + * V1 REST API tests for managing Sites + * * @author sglover * @author janv */