mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
129178 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1) 128608 jvonka: V1 REST API: cleanup and rationalise new api tests (re: remotable helpers & runAs user / admin) - round 4 REPO-113 (also relates to REPO-28, REPO-114, REPO-825) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129352 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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<Node> 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<String, String> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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<String, String> params, Map<String, String> headers, String apiName, int expectedStatus) throws Exception
|
||||
protected HttpResponse post(String url, String body, Map<String, String> params, Map<String, String> 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<String, String> otherParams, int expectedStatus) throws Exception
|
||||
protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map<String, String> otherParams, int expectedStatus) throws Exception
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(runAsUser));
|
||||
Map<String, String> 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<String, String> otherParams, int expectedStatus) throws Exception
|
||||
protected HttpResponse getAll(Class<?> entityResource, PublicApiClient.Paging paging, Map<String, String> 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<String, String> otherParams, Map<String, String> headers, int expectedStatus) throws Exception
|
||||
protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map<String, String> otherParams, Map<String, String> 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<String, String> otherParams, Map<String, String> headers, String apiName, int expectedStatus) throws Exception
|
||||
protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map<String, String> otherParams, Map<String, String> headers, String apiName, int expectedStatus) throws Exception
|
||||
{
|
||||
Map<String, String> 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<String, String> params, int expectedStatus) throws Exception
|
||||
protected HttpResponse getSingle(String url, String entityId, Map<String, String> 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<String, String> params, int expectedStatus) throws Exception
|
||||
protected HttpResponse getSingle(Class<?> entityResource, String entityId, Map<String, String> 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<String, String> params, Map<String, String> headers, int expectedStatus) throws Exception
|
||||
protected HttpResponse getSingle(String url, String entityId, Map<String, String> params, Map<String, String> 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<String, String> params, Map<String, String> headers, String apiName, int expectedStatus) throws Exception
|
||||
protected HttpResponse getSingle(String url, String entityId, Map<String, String> params, Map<String, String> 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<String, String> params,
|
||||
protected HttpResponse getSingleWithDelayRetry(String url, String entityId, Map<String, String> params,
|
||||
Map<String, String> 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<String, String> params,
|
||||
protected HttpResponse putBinary(String url, int version, BinaryPayload payload, String queryString, Map<String, String> 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<String, String> params,
|
||||
protected HttpResponse putBinary(String url, BinaryPayload payload, String queryString, Map<String, String> 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<String, String> params, int expectedStatus) throws Exception
|
||||
protected HttpResponse delete(String url, String entityId, Map<String, String> 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<String, String> params, Map<String, String> headers, String apiName, int expectedStatus) throws Exception
|
||||
protected HttpResponse delete(String url, String entityId, Map<String, String> params, Map<String, String> 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;
|
||||
}
|
||||
|
@@ -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<Activity> activitiesAgain = getMyActivities();
|
||||
assertEquals("No activites should be created for non-site nodes", activities, activitiesAgain);
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -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<String, String> 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<String, String> 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<Document> 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)
|
||||
|
@@ -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");
|
||||
|
@@ -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<String, String> params = createParams(null, null);
|
||||
|
||||
//Call an endpoint that doesn't exist
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -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 <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/{nodeId}/versions</li>
|
||||
*
|
||||
@@ -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<Node> 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<Node> 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<Node> 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<String, Object> 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<String> 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<String, Object> 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<String, String> params = new HashMap<>();
|
||||
params.put("include", "properties");
|
||||
response = getAll(getNodeVersionsUrl(d1Id), user1, paging, params, 200);
|
||||
response = getAll(getNodeVersionsUrl(d1Id), paging, params, 200);
|
||||
List<Node> 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<Node> 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<Node> 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<String, String> 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<Node> 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());
|
||||
|
@@ -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
|
||||
*
|
||||
* <ul>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/queries} </li>
|
||||
* </ul>
|
||||
@@ -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<Node> 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<Node> 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<String, String> 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<Node> 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);
|
||||
}
|
||||
|
@@ -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<Rendition> 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<String, String> 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<Rendition> 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<Rendition> 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<String, String> 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<String, String> 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<String, String> 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
|
||||
|
@@ -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")
|
||||
*
|
||||
* <ul>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links} </li>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>} </li>
|
||||
@@ -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<String, String> 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<String, String> 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<String, String> responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
@@ -240,12 +241,12 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertNotNull(lastModifiedHeader);
|
||||
// Test 304 response
|
||||
Map<String, String> 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<Rendition> 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<QuickShareLink> 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<String, String> 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<String, String> 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<String, String> 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<String> 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<String, String> 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<String, String> 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<String, String> responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
@@ -732,12 +735,12 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertNotNull(lastModifiedHeader);
|
||||
// Test 304 response
|
||||
Map<String, String> 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<Rendition> 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);
|
||||
}
|
||||
}
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* #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 <http://www.gnu.org/licenses/>.
|
||||
* #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<CustomModelConstraint> 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<CustomModelConstraint> 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<CustomModelConstraint> 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<CustomModelConstraint> 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<CustomModelConstraint> 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<CustomModelConstraint> 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<CustomModelConstraint> 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<String, String> 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<CustomModelConstraint> 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<String, String> 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<CustomModelConstraint> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* #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 <http://www.gnu.org/licenses/>.
|
||||
* #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 + "<script>alert('oops')</script>");
|
||||
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<String, String> 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<CustomModel> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* #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 <http://www.gnu.org/licenses/>.
|
||||
* #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());
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* #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 <http://www.gnu.org/licenses/>.
|
||||
* #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<String, String> namespacePair = getTestNamespaceUriPrefixPair();
|
||||
// Create the model as a Model Administrator
|
||||
@@ -86,18 +88,23 @@ public class TestCustomProperty extends BaseCustomModelApiTest
|
||||
List<CustomModelProperty> 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<String, String> 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<String, String> 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.<CustomModelConstraint>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<String, String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* #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 <http://www.gnu.org/licenses/>.
|
||||
* #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<String, String> 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<String, String> 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<name");
|
||||
post(typeURL, customModelAdmin, RestApiUtil.toJsonAsString(type), 400);
|
||||
post(typeURL, RestApiUtil.toJsonAsString(type), 400);
|
||||
}
|
||||
|
||||
// Add aspect
|
||||
@@ -191,25 +203,27 @@ public class TestCustomTypeAspect extends BaseCustomModelApiTest
|
||||
aspect.setTitle("test aspect title");
|
||||
|
||||
// Try to create a model with an invalid aspect name (null)
|
||||
post(aspectURL, customModelAdmin, RestApiUtil.toJsonAsString(aspect), 400);
|
||||
post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400);
|
||||
|
||||
// Try to create a model with an invalid aspect name (name contains ':')
|
||||
aspect.setName("prefix:someAspectname");
|
||||
post(aspectURL, customModelAdmin, RestApiUtil.toJsonAsString(aspect), 400);
|
||||
post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400);
|
||||
|
||||
// Try to create a model with an invalid aspect name (name is empty)
|
||||
aspect.setName("");
|
||||
post(aspectURL, customModelAdmin, RestApiUtil.toJsonAsString(aspect), 400);
|
||||
post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400);
|
||||
|
||||
// Try to create a model with an invalid aspect name (name contains '>')
|
||||
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<String, String> 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<String, String> 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<CustomType> 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<String, String> 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<CustomModelProperty> 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<String, String> 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());
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -54,6 +54,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* V1 REST API tests for managing Sites
|
||||
*
|
||||
* @author sglover
|
||||
* @author janv
|
||||
*/
|
||||
|
Reference in New Issue
Block a user