use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testRetrieveNodePermissionsSpecialNodes.
/**
* Test retrieve node permissions for special nodes like:
* 'Company Home', 'Data Dictionary', 'Shared', 'Sites', 'User Home'
*
* @throws Exception
*/
private void testRetrieveNodePermissionsSpecialNodes() throws Exception {
setRequestContext(user1);
String rootNodeId = getRootNodeId();
String userHome = getMyNodeId();
String sharedFolder = getSharedNodeId();
String sitesNodeId = getSitesNodeId();
String ddNodeId = getDataDictionaryNodeId();
Map params = new HashMap<>();
params.put("include", "permissions");
// Test permissions for node 'Company Home'
HttpResponse response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(nodeResp.getPermissions());
// Test permissions for node 'Sites'
response = getSingle(NodesEntityResource.class, sitesNodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(nodeResp.getPermissions());
// Test permissions for node 'Data Dictionary'
response = getSingle(NodesEntityResource.class, ddNodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(nodeResp.getPermissions());
// Test permissions for node 'Shared Folder'
response = getSingle(NodesEntityResource.class, sharedFolder, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNotNull(nodeResp.getPermissions());
Set<String> expectedSettable = new HashSet<>(Arrays.asList("Coordinator", "Collaborator", "Contributor", "Consumer", "Editor"));
// Test permissions for node 'User Home'
response = getSingle(NodesEntityResource.class, userHome, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNotNull(nodeResp.getPermissions());
assertNotNull(nodeResp.getPermissions().getSettable());
assertTrue("Incorrect list of settable permissions returned!", nodeResp.getPermissions().getSettable().containsAll(expectedSettable));
assertFalse(nodeResp.getPermissions().getIsInheritanceEnabled());
// Try as admin
setRequestContext(networkAdmin);
// Test permissions for node 'Company Home'
response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertFalse(nodeResp.getPermissions().getIsInheritanceEnabled());
assertNull(nodeResp.getPermissions().getInherited());
assertNotNull(nodeResp.getPermissions().getLocallySet());
assertTrue(nodeResp.getPermissions().getLocallySet().contains(new NodePermissions.NodePermission("GROUP_EVERYONE", PermissionService.CONSUMER, AccessStatus.ALLOWED.toString())));
assertNotNull(nodeResp.getPermissions().getSettable());
assertTrue("Incorrect list of settable permissions returned!", nodeResp.getPermissions().getSettable().containsAll(expectedSettable));
// Test permissions for node 'Sites'
response = getSingle(NodesEntityResource.class, sitesNodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertTrue(nodeResp.getPermissions().getIsInheritanceEnabled());
assertNotNull(nodeResp.getPermissions().getInherited());
assertTrue(nodeResp.getPermissions().getInherited().contains(new NodePermissions.NodePermission("GROUP_EVERYONE", PermissionService.CONSUMER, AccessStatus.ALLOWED.toString())));
assertNull(nodeResp.getPermissions().getLocallySet());
assertNotNull(nodeResp.getPermissions().getSettable());
assertTrue("Incorrect list of settable permissions returned!", nodeResp.getPermissions().getSettable().containsAll(expectedSettable));
// Test permissions for node 'Data Dictionary'
response = getSingle(NodesEntityResource.class, ddNodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertFalse(nodeResp.getPermissions().getIsInheritanceEnabled());
assertNull(nodeResp.getPermissions().getInherited());
assertNotNull(nodeResp.getPermissions().getLocallySet());
assertTrue(nodeResp.getPermissions().getLocallySet().contains(new NodePermissions.NodePermission("GROUP_EVERYONE", PermissionService.CONSUMER, AccessStatus.ALLOWED.toString())));
assertNotNull(nodeResp.getPermissions().getSettable());
assertTrue("Incorrect list of settable permissions returned!", nodeResp.getPermissions().getSettable().containsAll(expectedSettable));
// Test permissions for node 'Shared Folder'
response = getSingle(NodesEntityResource.class, sharedFolder, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertFalse(nodeResp.getPermissions().getIsInheritanceEnabled());
assertNull(nodeResp.getPermissions().getInherited());
assertNotNull(nodeResp.getPermissions().getLocallySet());
assertTrue(nodeResp.getPermissions().getLocallySet().contains(new NodePermissions.NodePermission("GROUP_EVERYONE", PermissionService.CONTRIBUTOR, AccessStatus.ALLOWED.toString())));
assertNotNull(nodeResp.getPermissions().getSettable());
assertTrue("Incorrect list of settable permissions returned!", nodeResp.getPermissions().getSettable().containsAll(expectedSettable));
// Test permissions for node 'User Home'
response = getSingle(NodesEntityResource.class, userHome, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertFalse(nodeResp.getPermissions().getIsInheritanceEnabled());
assertNull(nodeResp.getPermissions().getInherited());
assertNotNull(nodeResp.getPermissions().getLocallySet());
assertTrue(nodeResp.getPermissions().getLocallySet().contains(new NodePermissions.NodePermission("ROLE_OWNER", "All", AccessStatus.ALLOWED.toString())));
assertTrue(nodeResp.getPermissions().getLocallySet().contains(new NodePermissions.NodePermission(user1, "All", AccessStatus.ALLOWED.toString())));
assertNotNull(nodeResp.getPermissions().getSettable());
assertTrue("Incorrect list of settable permissions returned!", nodeResp.getPermissions().getSettable().containsAll(expectedSettable));
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdateNodeInfo.
/**
* Tests update node info (file or folder)
* <p>PUT:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>}
*/
@Test
public void testUpdateNodeInfo() throws Exception {
setRequestContext(user1);
// create folder f0
String folder0Name = "f0-testUpdateNodeInfo-" + RUNID;
String f0Id = createFolder(Nodes.PATH_MY, folder0Name).getId();
UserInfo expectedUser = new UserInfo(user1);
String postUrl = getNodeChildrenUrl(f0Id);
String folderName = "My Folder";
// create folder
Folder folderResp = createFolder(f0Id, folderName);
String fId = folderResp.getId();
Folder f1 = new Folder();
f1.setName(folderName);
f1.setNodeType(TYPE_CM_FOLDER);
f1.setIsFolder(true);
f1.setParentId(f0Id);
f1.setAspectNames(Collections.singletonList("cm:auditable"));
f1.setCreatedByUser(expectedUser);
f1.setModifiedByUser(expectedUser);
f1.expected(folderResp);
// create empty file
Document d1 = new Document();
d1.setName("d1.txt");
d1.setNodeType(TYPE_CM_CONTENT);
HttpResponse response = post(postUrl, toJsonAsStringNonNull(d1), 201);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String dId = documentResp.getId();
d1.setIsFolder(false);
d1.setParentId(f0Id);
d1.setAspectNames(Collections.singletonList("cm:auditable"));
d1.setCreatedByUser(expectedUser);
d1.setModifiedByUser(expectedUser);
ContentInfo ciExpected = new ContentInfo();
ciExpected.setMimeType("text/plain");
ciExpected.setMimeTypeName("Plain Text");
ciExpected.setSizeInBytes(0L);
ciExpected.setEncoding("UTF-8");
d1.setContent(ciExpected);
d1.expected(documentResp);
// update file - name (=> rename within current folder)
Document dUpdate = new Document();
dUpdate.setName("d1b.txt");
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
d1.setName("d1b.txt");
d1.expected(documentResp);
// update file - add some properties
Map<String, Object> props = new HashMap<>();
props.put("cm:title", "my file title");
props.put("cm:description", "my file description");
dUpdate = new Document();
dUpdate.setProperties(props);
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
d1.setProperties(props);
d1.setAspectNames(Arrays.asList("cm:auditable", "cm:titled"));
d1.expected(documentResp);
// update file - add versionable aspect
dUpdate = new Document();
dUpdate.setAspectNames(Arrays.asList("cm:auditable", "cm:titled", "cm:versionable"));
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
d1.getProperties().put("cm:versionLabel", "1.0");
d1.getProperties().put("cm:versionType", "MAJOR");
d1.setAspectNames(Arrays.asList("cm:auditable", "cm:titled", "cm:versionable"));
d1.expected(documentResp);
response = getSingle(URL_NODES, dId, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
d1.getProperties().put("cm:versionLabel", "1.0");
d1.getProperties().put("cm:versionType", "MAJOR");
d1.expected(documentResp);
// update file - remove titled aspect (and it's related aspect properties)
dUpdate = new Document();
dUpdate.setAspectNames(Arrays.asList("cm:auditable", "cm:versionable"));
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
d1.getProperties().remove("cm:title");
d1.getProperties().remove("cm:description");
d1.setAspectNames(Arrays.asList("cm:auditable", "cm:versionable"));
d1.expected(documentResp);
// update folder - rename and add some properties
props = new HashMap<>();
props.put("cm:title", "my folder title");
props.put("cm:description", "my folder description");
folderName = "My Updated Folder";
Folder fUpdate = new Folder();
fUpdate.setProperties(props);
fUpdate.setName(folderName);
response = put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
f1.setName(folderName);
f1.setAspectNames(Arrays.asList("cm:auditable", "cm:titled"));
f1.setProperties(props);
f1.expected(folderResp);
// update folder - unset a property
props = new HashMap<>();
props.put("cm:title", null);
fUpdate = new Folder();
fUpdate.setProperties(props);
response = put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
f1.getProperties().remove("cm:title");
f1.expected(folderResp);
// update folder - specialise node type
fUpdate = new Folder();
fUpdate.setNodeType("app:glossary");
response = put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
f1.setNodeType("app:glossary");
f1.expected(folderResp);
{
// test versioning for metadata-only updates
Map params = new HashMap<>();
params.put("majorVersion", "true");
params.put("comment", "Initial empty file :-)");
String fileName = "My File";
Node nodeResp = createEmptyTextFile(f0Id, fileName, params, 201);
assertEquals("1.0", nodeResp.getProperties().get("cm:versionLabel"));
props = new HashMap<>();
props.put("cm:title", "my file title");
dUpdate = new Document();
dUpdate.setProperties(props);
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("1.0", nodeResp.getProperties().get("cm:versionLabel"));
// turn-off auto-version on metadata-only updates (OOTB this is now false by default, as per MNT-12226)
props = new HashMap<>();
props.put("cm:autoVersionOnUpdateProps", true);
dUpdate = new Document();
dUpdate.setProperties(props);
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("1.1", nodeResp.getProperties().get("cm:versionLabel"));
props = new HashMap<>();
props.put("cm:title", "my file title 2");
dUpdate = new Document();
dUpdate.setProperties(props);
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("1.2", nodeResp.getProperties().get("cm:versionLabel"));
props = new HashMap<>();
props.put("cm:title", "my file title 3");
dUpdate = new Document();
dUpdate.setProperties(props);
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("1.3", nodeResp.getProperties().get("cm:versionLabel"));
// turn-off auto-version on metadata-only updates
props = new HashMap<>();
props.put("cm:autoVersionOnUpdateProps", false);
dUpdate = new Document();
dUpdate.setProperties(props);
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("1.3", nodeResp.getProperties().get("cm:versionLabel"));
props = new HashMap<>();
props.put("cm:title", "my file title 4");
dUpdate = new Document();
dUpdate.setProperties(props);
response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("1.3", nodeResp.getProperties().get("cm:versionLabel"));
}
// update folder(s) via well-known aliases rather than node id
// note: as of now, the platform does allow a user to modify their home folder [this may change in the future, if so adjust the test accordingly]
response = getSingle(URL_NODES, Nodes.PATH_MY, 200);
Folder user1MyFolder = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
String user1MyFolderId = user1MyFolder.getId();
String description = "my folder description " + RUNID;
props = new HashMap<>();
props.put("cm:description", description);
fUpdate = new Folder();
fUpdate.setProperties(props);
response = put(URL_NODES, Nodes.PATH_MY, toJsonAsStringNonNull(fUpdate), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(description, folderResp.getProperties().get("cm:description"));
setRequestContext(networkAdmin);
props = new HashMap<>();
props.put("cm:description", description);
fUpdate = new Folder();
fUpdate.setProperties(props);
response = put(URL_NODES, Nodes.PATH_ROOT, toJsonAsStringNonNull(fUpdate), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(description, folderResp.getProperties().get("cm:description"));
props = new HashMap<>();
props.put("cm:description", description);
fUpdate = new Folder();
fUpdate.setProperties(props);
response = put(URL_NODES, Nodes.PATH_SHARED, toJsonAsStringNonNull(fUpdate), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(description, folderResp.getProperties().get("cm:description"));
setRequestContext(user1);
// -ve test - fail on unknown property
props = new HashMap<>();
props.put("cm:xyz", "my unknown property");
dUpdate = new Document();
dUpdate.setProperties(props);
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
// -ve test - fail on unknown aspect
List<String> aspects = new ArrayList<>(d1.getAspectNames());
aspects.add("cm:unknownAspect");
dUpdate = new Document();
dUpdate.setAspectNames(aspects);
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
// -ve test - duplicate name
dUpdate = new Document();
dUpdate.setName(folderName);
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 409);
// -ve test - unknown node id
dUpdate = new Document();
dUpdate.setName("some.txt");
put(URL_NODES, UUID.randomUUID().toString(), toJsonAsStringNonNull(dUpdate), null, 404);
// -ve test - generalise node type
fUpdate = new Folder();
fUpdate.setNodeType(TYPE_CM_FOLDER);
put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 400);
// -ve test - try to move to a different parent using PUT (note: should use new POST /nodes/{nodeId}/move operation instead)
folderResp = createFolder(f0Id, "folder 2");
String f2Id = folderResp.getId();
fUpdate = new Folder();
fUpdate.setParentId(f2Id);
put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 400);
// ok - if parent does not change
fUpdate = new Folder();
fUpdate.setParentId(f0Id);
put(URL_NODES, fId, toJsonAsStringNonNull(fUpdate), null, 200);
// -ve test - minor: error code if trying to update property with invalid format (REPO-473)
props = new HashMap<>();
props.put("exif:pixelYDimension", "my unknown property");
fUpdate = new Folder();
fUpdate.setProperties(props);
put(URL_NODES, f2Id, toJsonAsStringNonNull(fUpdate), null, 400);
// -ve test - minor: error code if trying to update property with invalid format (REPO-1635)
props = new HashMap<>();
props.put("exif:dateTimeOriginal", "25-11-2016");
fUpdate = new Folder();
fUpdate.setProperties(props);
put(URL_NODES, f2Id, toJsonAsStringNonNull(fUpdate), null, 400);
// +ve test - try again with valid formats (REPO-473, REPO-1635)
props = new HashMap<>();
props.put("exif:pixelYDimension", "123");
props.put("exif:dateTimeOriginal", "2016-11-21T16:26:19.037+0000");
fUpdate = new Folder();
fUpdate.setProperties(props);
put(URL_NODES, f2Id, toJsonAsStringNonNull(fUpdate), null, 200);
// -ve test - non-admin cannot modify root (Company Home) folder
props = new HashMap<>();
props.put("cm:description", "my folder description");
fUpdate = new Folder();
fUpdate.setProperties(props);
put(URL_NODES, Nodes.PATH_ROOT, toJsonAsStringNonNull(fUpdate), null, 403);
// -ve test - non-admin cannot modify "Shared" folder
props = new HashMap<>();
props.put("cm:description", "my folder description");
fUpdate = new Folder();
fUpdate.setProperties(props);
put(URL_NODES, Nodes.PATH_SHARED, toJsonAsStringNonNull(fUpdate), null, 403);
setRequestContext(user2);
// -ve test - user cannot modify another user's home folder
props = new HashMap<>();
props.put("cm:description", "my folder description");
fUpdate = new Folder();
fUpdate.setProperties(props);
put(URL_NODES, user1MyFolderId, toJsonAsStringNonNull(fUpdate), null, 403);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testCreateFolder.
/**
* Tests create folder.
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testCreateFolder() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
UserInfo expectedUser = new UserInfo(user1);
String postUrl = getNodeChildrenUrl(myNodeId);
// create folder
Folder folderResp = createFolder(myNodeId, "f1");
String f1Id = folderResp.getId();
Folder f1 = new Folder();
f1.setName("f1");
f1.setNodeType(TYPE_CM_FOLDER);
f1.setIsFolder(true);
f1.setParentId(myNodeId);
f1.setAspectNames(Collections.singletonList("cm:auditable"));
f1.setCreatedByUser(expectedUser);
f1.setModifiedByUser(expectedUser);
f1.expected(folderResp);
// create sub-folder with properties
Map<String, Object> props = new HashMap<>();
props.put("cm:title", "my folder title");
props.put("cm:description", "my folder description");
folderResp = createFolder(f1Id, "f2", props);
String f2Id = folderResp.getId();
Folder f2 = new Folder();
f2.setName("f2");
f2.setNodeType(TYPE_CM_FOLDER);
f2.setProperties(props);
f2.setIsFolder(true);
f2.setParentId(f1Id);
f2.setAspectNames(Arrays.asList("cm:auditable", "cm:titled"));
f2.setCreatedByUser(expectedUser);
f2.setModifiedByUser(expectedUser);
f2.expected(folderResp);
// create another folder in a (partially existing) folder path
Node n = new Node();
n.setName("fZ");
n.setNodeType(TYPE_CM_FOLDER);
n.setRelativePath("/f1/f2/f3/f4");
// create node
HttpResponse response = post(getNodeChildrenUrl(myNodeId), RestApiUtil.toJsonAsStringNonNull(n), 201);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
// check parent hierarchy ...
response = getSingle(NodesEntityResource.class, folderResp.getId(), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderResp.getName(), "fZ");
response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderResp.getName(), "f4");
response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderResp.getName(), "f3");
response = getSingle(NodesEntityResource.class, folderResp.getParentId(), null, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderResp.getName(), "f2");
assertEquals(folderResp.getId(), f2Id);
// -ve test - name is mandatory
Folder invalid = new Folder();
invalid.setNodeType(TYPE_CM_FOLDER);
post(postUrl, toJsonAsStringNonNull(invalid), 400);
// -ve test - invalid name
invalid = new Folder();
invalid.setName("inv:alid");
invalid.setNodeType(TYPE_CM_FOLDER);
post(postUrl, toJsonAsStringNonNull(invalid), 422);
// -ve test - node type is mandatory
invalid = new Folder();
invalid.setName("my folder");
post(postUrl, toJsonAsStringNonNull(invalid), 400);
// create empty file - used in -ve test below
Document d1 = new Document();
d1.setName("d1.txt");
d1.setNodeType(TYPE_CM_CONTENT);
response = post(postUrl, toJsonAsStringNonNull(d1), 201);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String d1Id = documentResp.getId();
// -ve test - invalid (model integrity exception)
Folder f3 = new Folder();
f3.setName("f3");
f3.setNodeType(TYPE_CM_FOLDER);
post(getNodeChildrenUrl(d1Id), toJsonAsStringNonNull(f3), 422);
// -ve test - it should not be possible to create a "system folder"
invalid = new Folder();
invalid.setName("my sys folder");
invalid.setNodeType("cm:systemfolder");
post(postUrl, toJsonAsStringNonNull(invalid), 400);
// -ve test - unknown parent folder node id
post(getNodeChildrenUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(f3), 404);
// -ve test - duplicate name
post(postUrl, toJsonAsStringNonNull(f1), 409);
// Create a folder with a duplicate name (f1), but set the autoRename to true
response = post(postUrl, toJsonAsStringNonNull(f1), "?" + Nodes.PARAM_AUTO_RENAME + "=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("f1-1", documentResp.getName());
// Create a folder with a duplicate name (f1) again, but set the autoRename to true
response = post(postUrl, toJsonAsStringNonNull(f1), "?" + Nodes.PARAM_AUTO_RENAME + "=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("f1-2", documentResp.getName());
// -ve test - create a folder with a duplicate name (f1), but set the autoRename to false
post(postUrl, toJsonAsStringNonNull(f1), "?" + Nodes.PARAM_AUTO_RENAME + "=false", 409);
// Create folder using relative path
n = new Node();
n.setName("fX");
n.setNodeType(TYPE_CM_FOLDER);
n.setRelativePath("/f1/f2");
response = post(postUrl, toJsonAsStringNonNull(n), "?" + Nodes.PARAM_AUTO_RENAME + "=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("fX", documentResp.getName());
// Create a folder using relative path, with a duplicate name (fX) but set the autoRename to true
response = post(postUrl, toJsonAsStringNonNull(n), "?" + Nodes.PARAM_AUTO_RENAME + "=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("fX-1", documentResp.getName());
// -ve test - create a folder with a duplicate name (fX), but set the autoRename to false
post(postUrl, toJsonAsStringNonNull(n), "?" + Nodes.PARAM_AUTO_RENAME + "=false", 409);
// -ve test - invalid relative path
n = new Node();
n.setName("fX");
n.setNodeType(TYPE_CM_FOLDER);
n.setRelativePath("/f1/inv:alid");
post(getNodeChildrenUrl(f2Id), RestApiUtil.toJsonAsStringNonNull(n), 422);
// -ve test - invalid relative path - points to existing node that is not a folder
n = new Node();
n.setName("fY");
n.setNodeType(TYPE_CM_FOLDER);
n.setRelativePath("d1.txt");
post(getNodeChildrenUrl(myNodeId), RestApiUtil.toJsonAsStringNonNull(n), 409);
// -ve test - minor: error code if trying to create with property with invalid format (REPO-473)
props = new HashMap<>();
props.put("exif:pixelYDimension", "my unknown property");
n = new Folder();
n.setName("fZ");
n.setNodeType(TYPE_CM_FOLDER);
n.setProperties(props);
post(getNodeChildrenUrl(myNodeId), RestApiUtil.toJsonAsStringNonNull(n), 400);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testChildrenAssocType.
/**
* Tests creation and listing of children using assoc type other than "cm:contains".
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testChildrenAssocType() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
String fId = null;
try {
fId = createFolder(myNodeId, "testChildrenAssocType folder").getId();
Node nodeUpdate = new Node();
nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES));
put(URL_NODES, fId, toJsonAsStringNonNull(nodeUpdate), null, 200);
HttpResponse response = getAll(getNodeChildrenUrl(fId), null, null, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
Node obj = new Node();
obj.setName("c1");
obj.setNodeType(TYPE_CM_CONTENT);
// assoc type => cm:contains
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c1Id = nodeResp.getId();
assertEquals(fId, nodeResp.getParentId());
response = getAll(getNodeChildrenUrl(fId), null, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
obj = new Node();
obj.setName("c2");
obj.setNodeType(TYPE_CM_CONTENT);
Association assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE);
obj.setAssociation(assoc);
// assoc type => cm:preferenceImage
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c2Id = nodeResp.getId();
assertEquals(fId, nodeResp.getParentId());
response = getAll(getNodeChildrenUrl(fId), null, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
Map<String, String> params = new HashMap<>();
params.put("where", "(assocType='" + ASSOC_TYPE_CM_CONTAINS + "')");
params.put("include", "association");
response = getAll(getNodeChildrenUrl(fId), null, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(c1Id, nodes.get(0).getId());
assertTrue(nodes.get(0).getAssociation().getIsPrimary());
params = new HashMap<>();
params.put("where", "(assocType='" + ASSOC_TYPE_CM_PREFERENCE_IMAGE + "')");
params.put("include", "association");
response = getAll(getNodeChildrenUrl(fId), null, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals(c2Id, nodes.get(0).getId());
assertTrue(nodes.get(0).getAssociation().getIsPrimary());
//
// test that we can also create children below content
//
obj = new Node();
obj.setName("c3");
obj.setNodeType(TYPE_CM_CONTENT);
nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES));
// assoc type => cm:contains
response = post(getNodeChildrenUrl(fId), toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c3Id = nodeResp.getId();
obj = new Node();
obj.setName("c4");
obj.setNodeType(TYPE_CM_CONTENT);
assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE);
obj.setAssociation(assoc);
// assoc type => cm:preferenceImage
response = post(getNodeChildrenUrl(c3Id), toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals(c3Id, nodeResp.getParentId());
// -ve test
obj = new Node();
obj.setName("c5");
obj.setNodeType(TYPE_CM_CONTENT);
assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_CONTAINS);
obj.setAssociation(assoc);
// assoc type => cm:contains (requires parent to be a folder !)
post(getNodeChildrenUrl(c3Id), toJsonAsStringNonNull(obj), 422);
} finally {
// some cleanup
if (fId != null) {
deleteNode(fId);
}
}
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testGetNodeWithEmptyProperties.
@Test
public void testGetNodeWithEmptyProperties() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
// create folder f1
Folder folderResp = createFolder(myNodeId, "fld1_" + RUNID);
String f1Id = folderResp.getId();
String nodeName = "f1 link";
String nodeType = "app:folderlink";
String propertyName = "cm:destination";
Map<String, Object> props = new HashMap<>();
props.put(propertyName, "");
Node nodeResp = createNode(f1Id, nodeName, nodeType, props);
String nodeId = nodeResp.getId();
Node n1 = new Node();
n1.setName(nodeName);
n1.setNodeType(nodeType);
n1.setIsFolder(true);
// note: parent of the link (not where it is pointing)
n1.setParentId(f1Id);
n1.setAspectNames(Collections.singletonList("cm:auditable"));
// Empty (zero length) string values are considered to be
// null values, and will be represented the same as null
// values (i.e. by non-existence of the property).
n1.setProperties(null);
// Check create response.
n1.expected(nodeResp);
HttpResponse httpResponse = getSingle(NodesEntityResource.class, nodeId, null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(httpResponse.getJsonResponse(), Node.class);
// Check get response.
n1.expected(nodeResp);
}
Aggregations