use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class RemoteFileFolderLoaderTest method testLoad_15_16bytes.
/**
* Load 15 files; 1K size; 1 document sample; force binary storage
*/
@SuppressWarnings("unchecked")
public void testLoad_15_16bytes() throws Exception {
JSONObject body = new JSONObject();
body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath);
body.put(FileFolderLoaderPost.KEY_MIN_FILE_SIZE, 16L);
body.put(FileFolderLoaderPost.KEY_MAX_FILE_SIZE, 16L);
body.put(FileFolderLoaderPost.KEY_MAX_UNIQUE_DOCUMENTS, 1L);
body.put(FileFolderLoaderPost.KEY_FORCE_BINARY_STORAGE, Boolean.TRUE);
Response response = null;
try {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser("maggi");
response = sendRequest(new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_OK, "maggi");
} finally {
AuthenticationUtil.popAuthentication();
}
assertEquals("{\"count\":100}", response.getContentAsString());
// Check file(s)
assertEquals(100, nodeService.countChildAssocs(loadHomeNodeRef, true));
// Consistent binary text
String contentUrlCheck = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 16L);
ContentReader readerCheck = new SpoofedTextContentReader(contentUrlCheck);
String textCheck = readerCheck.getContentString();
// Size should be default
List<FileInfo> fileInfos = fileFolderService.list(loadHomeNodeRef);
for (FileInfo fileInfo : fileInfos) {
NodeRef fileNodeRef = fileInfo.getNodeRef();
ContentReader reader = fileFolderService.getReader(fileNodeRef);
// Expect storage in store
assertTrue(reader.getContentUrl().startsWith(FileContentStore.STORE_PROTOCOL));
// Check text
String text = reader.getContentString();
assertEquals("Text not the same.", textCheck, text);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class RemoteFileFolderLoaderTest method testLoad_noFolderPath.
/**
* Load with no folder path
*/
public void testLoad_noFolderPath() throws Exception {
JSONObject body = new JSONObject();
sendRequest(new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_BAD_REQUEST, "bmarley");
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class RunningActionRestApiTest method testRunningReplicationsActionsPost.
public void testRunningReplicationsActionsPost() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new PostRequest(URL_RUNNING_REPLICATION_ACTIONS, "{}", JSON), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new PostRequest(URL_RUNNING_REPLICATION_ACTIONS, "{}", JSON), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
// If no noderef supplied, will get an error
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
response = sendRequest(new PostRequest(URL_RUNNING_REPLICATION_ACTIONS, "{}", JSON), Status.STATUS_BAD_REQUEST);
assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
// Add a running action
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
replicationService.saveReplicationDefinition(rd);
String id = rd.getId();
txn.commit();
// Ask for it to be started
// (It should start but fail due to missing definition parts)
JSONObject json = new JSONObject();
json.put("name", "Test1");
response = sendRequest(new PostRequest(URL_RUNNING_REPLICATION_ACTIONS, json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
// Check we got back some details on it
String jsonStr = response.getContentAsString();
JSONObject jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
// specify enough options for a valid transfer)
for (int i = 0; i < 50; i++) {
txn = transactionService.getUserTransaction();
txn.begin();
rd = replicationService.loadReplicationDefinition("Test1");
txn.commit();
if (rd.getExecutionStatus() == ActionStatus.New) {
// Still pending, or maybe running
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
} else if (rd.getExecutionStatus() == ActionStatus.Failed) {
// We're done
break;
} else {
fail("Unexpected status in repo of " + rd.getExecutionStatus());
}
}
assertEquals(ActionStatus.Failed, rd.getExecutionStatus());
// Ensure you can't start with an invalid name
json = new JSONObject();
json.put("name", "MadeUpName");
response = sendRequest(new PostRequest(URL_RUNNING_REPLICATION_ACTIONS, json.toString(), JSON), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class RunningActionRestApiTest method testRunningActionsPost.
public void testRunningActionsPost() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new PostRequest(URL_RUNNING_ACTIONS, "{}", JSON), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new PostRequest(URL_RUNNING_ACTIONS, "{}", JSON), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
// If no noderef supplied, will get an error
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
response = sendRequest(new PostRequest(URL_RUNNING_ACTIONS, "{}", JSON), Status.STATUS_BAD_REQUEST);
assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
// Add a running action
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
replicationService.saveReplicationDefinition(rd);
String id = rd.getId();
txn.commit();
// Ask for it to be started
// (It should start but fail due to missing definition parts)
JSONObject json = new JSONObject();
json.put("nodeRef", rd.getNodeRef().toString());
response = sendRequest(new PostRequest(URL_RUNNING_ACTIONS, json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
// Check we got back some details on it
String jsonStr = response.getContentAsString();
JSONObject jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
// specify enough options for a valid transfer)
for (int i = 0; i < 50; i++) {
txn = transactionService.getUserTransaction();
txn.begin();
rd = replicationService.loadReplicationDefinition("Test1");
txn.commit();
if (rd.getExecutionStatus() == ActionStatus.New) {
// Still pending, or maybe running
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
} else if (rd.getExecutionStatus() == ActionStatus.Failed) {
// We're done
break;
} else {
fail("Unexpected status in repo of " + rd.getExecutionStatus());
}
}
assertEquals(ActionStatus.Failed, rd.getExecutionStatus());
// Ensure you can't start with an invalid nodeRef
json = new JSONObject();
json.put("nodeRef", "XX" + rd.getNodeRef().toString() + "ZZ");
response = sendRequest(new PostRequest(URL_RUNNING_ACTIONS, json.toString(), JSON), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
}
Aggregations