use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class RemoteFileFolderLoaderTest method testLoad_15_default.
/**
* Load 15 files with default sizes
*/
@SuppressWarnings("unchecked")
public void testLoad_15_default() throws Exception {
JSONObject body = new JSONObject();
body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath);
body.put(FileFolderLoaderPost.KEY_FILE_COUNT, 15);
body.put(FileFolderLoaderPost.KEY_FILES_PER_TXN, 10);
Response response = null;
try {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser("hhoudini");
response = sendRequest(new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_OK, "hhoudini");
} finally {
AuthenticationUtil.popAuthentication();
}
assertEquals("{\"count\":15}", response.getContentAsString());
// Check file(s)
assertEquals(15, nodeService.countChildAssocs(loadHomeNodeRef, true));
// Size should be default
List<FileInfo> fileInfos = fileFolderService.list(loadHomeNodeRef);
for (FileInfo fileInfo : fileInfos) {
NodeRef fileNodeRef = fileInfo.getNodeRef();
ContentReader reader = fileFolderService.getReader(fileNodeRef);
// Expect spoofing by default
assertTrue(reader.getContentUrl().startsWith(FileContentStore.SPOOF_PROTOCOL));
assertTrue("Default file size not correct: " + reader, FileFolderLoaderPost.DEFAULT_MIN_FILE_SIZE < reader.getSize() && reader.getSize() < FileFolderLoaderPost.DEFAULT_MAX_FILE_SIZE);
// Check creator
assertEquals("hhoudini", nodeService.getProperty(fileNodeRef, ContentModel.PROP_CREATOR));
// We also expect the default language description to be present
String description = (String) nodeService.getProperty(fileNodeRef, ContentModel.PROP_DESCRIPTION);
assertNotNull("No description", description);
assertEquals("Description length incorrect: \"" + description + "\"", 128L, description.getBytes("UTF-8").length);
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class NodeArchiveServiceRestApiTest method testPurgeDeletedItems.
/**
* This test method purges some deleted nodes from the archive store.
*/
public void testPurgeDeletedItems() throws Exception {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
JSONObject archivedNodesJson = getArchivedNodes();
JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data");
JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES);
int archivedNodesLength = archivedNodesArray.length();
assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1);
// Take a specific archived node and purge it.
JSONObject requiredNodeInArchive = null;
for (int i = 0; i < archivedNodesLength; i++) {
JSONObject archivedNode = archivedNodesArray.getJSONObject(i);
// We ensure in #setUp() that this NodeRef will be in the archive store.
if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(adminDeletedTestNode.toString())) {
requiredNodeInArchive = archivedNode;
break;
} else if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(user1_DeletedTestNode.toString())) {
requiredNodeInArchive = archivedNode;
break;
} else if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(user2_DeletedTestNode.toString())) {
requiredNodeInArchive = archivedNode;
break;
}
}
assertNotNull("Expected node not found in archive", requiredNodeInArchive);
// So we have identified a specific Node in the archive that we want to delete permanently (purge).
String nodeRefString = requiredNodeInArchive.getString(AbstractArchivedNodeWebScript.NODEREF);
assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
NodeRef nodeRef = new NodeRef(nodeRefString);
// This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore
// This is its current StoreRef i.e. archive://SpacesStore
final StoreRef currentStoreRef = nodeRef.getStoreRef();
String deleteUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId();
// Send the DELETE REST call.
Response rsp = sendRequest(new DeleteRequest(deleteUrl), 200);
JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
JSONObject dataObj = jsonRsp.getJSONObject("data");
JSONArray purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
assertEquals("Only expected one NodeRef to have been purged.", 1, purgedNodesArray.length());
// Now we'll purge all the other nodes in the archive that came from the same StoreRef.
String deleteAllUrl = getArchiveUrl(this.nodesOriginalStoreRef);
rsp = sendRequest(new DeleteRequest(deleteAllUrl), 200);
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
dataObj = jsonRsp.getJSONObject("data");
purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
// Now retrieve all items from the archive store. There should be none.
assertEquals("Archive store was unexpectedly not empty", 0, getArchivedNodesCount());
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class NodeArchiveServiceRestApiTest method testRestoreDeletedItems.
/**
* This test method restores some deleted nodes from the archive store.
*/
public void testRestoreDeletedItems() throws Exception {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
JSONObject archivedNodesJson = getArchivedNodes();
JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data");
JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES);
int archivedNodesLength = archivedNodesArray.length();
assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1);
// Take a specific archived node and restore it.
JSONObject firstArchivedNode = archivedNodesArray.getJSONObject(0);
// So we have identified a specific Node in the archive that we want to restore.
String nodeRefString = firstArchivedNode.getString(AbstractArchivedNodeWebScript.NODEREF);
assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
NodeRef nodeRef = new NodeRef(nodeRefString);
// This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore
// This is its current StoreRef i.e. archive://SpacesStore
final StoreRef currentStoreRef = nodeRef.getStoreRef();
String restoreUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId();
int archivedNodesCountBeforeRestore = getArchivedNodesCount();
// Send the PUT REST call.
String jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString();
Response rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 200);
assertEquals("Expected archive to shrink by one", archivedNodesCountBeforeRestore - 1, getArchivedNodesCount());
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class AuditWebScriptTest method testGetAuditSearchService.
public void testGetAuditSearchService() throws Exception {
// Delete search audit entries (if any)
String url = "/api/audit/clear/" + APP_SEARCHTEST_NAME;
TestWebScriptServer.PostRequest postReq = new TestWebScriptServer.PostRequest(url, "", MimetypeMap.MIMETYPE_JSON);
Response response = sendRequest(postReq, Status.STATUS_OK, admin);
JSONObject json = new JSONObject(response.getContentAsString());
assertTrue(json.getInt(AbstractAuditWebScript.JSON_KEY_CLEARED) >= 0);
// create a file
this.testRoot = this.repositoryHelper.getCompanyHome();
String filename = "test_doc" + GUID.generate() + ".txt";
NodeRef testFile = this.fileFolderService.create(this.testRoot, filename, ContentModel.TYPE_CONTENT).getNodeRef();
// search the newly created file
SearchParameters sp = new SearchParameters();
sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
sp.setQuery("=cm:name:" + filename);
sp.addStore(testFile.getStoreRef());
searchService.query(sp);
// construct the get audit request
url = "/api/audit/query/" + APP_SEARCHTEST_NAME + "/searchaudit/queryX/searchParametersX?verbose=true";
TestWebScriptServer.GetRequest getReq = new TestWebScriptServer.GetRequest(url);
response = sendRequest(getReq, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
JSONArray jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
assertEquals("Incorrect number of entries reported", 1, jsonEntries.length());
JSONObject values = (JSONObject) ((JSONObject) jsonEntries.get(0)).get(AbstractAuditWebScript.JSON_KEY_ENTRY_VALUES);
assertTrue("Audit entry was not found", values.toString(0).contains("query==cm:name:" + filename));
// clear audit entries for the application
auditService.clearAudit(APP_SEARCHTEST_NAME, null, null);
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TaggingServiceTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
this.taggingService = (TaggingService) getServer().getApplicationContext().getBean("TaggingService");
this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");
this.repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
this.authenticationComponent.setSystemUserAsCurrentUser();
// Add a load of tags ready to use
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);
// Create test node's
NodeRef testRoot = this.repositoryHelper.getCompanyHome();
String guid = GUID.generate();
this.nodeOne = this.fileFolderService.create(testRoot, "test_doc1" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
this.nodeTwo = this.fileFolderService.create(testRoot, "test_dco2" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
// Add tags to test nodes
this.taggingService.addTag(nodeOne, TAG_1);
this.taggingService.addTag(nodeOne, TAG_2);
this.taggingService.addTag(nodeTwo, TAG_2);
// Create users
createUser(TEST_USER);
// Do tests as user one
this.authenticationComponent.setCurrentUser(TEST_USER);
}
Aggregations