use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class WebDAVMethodTest method expiryLockTest.
/* MNT-10555 Test */
@Test
public void expiryLockTest() {
// ACE-4347 extra debug logging just for this test so we can see what's going on when it next fails
Level repoWebdavSaveLogLevel = Logger.getLogger("org.alfresco.repo.webdav").getLevel();
Logger.getLogger("org.alfresco.repo.webdav").setLevel(Level.ALL);
Level webdavProtocolSaveLogLevel = Logger.getLogger("org.alfresco.webdav.protocol").getLevel();
Logger.getLogger("org.alfresco.webdav.protocol").setLevel(Level.ALL);
try {
setUpApplicationContext();
req = new MockHttpServletRequest();
resp = new MockHttpServletResponse();
String rootPath = "/app:company_home";
StoreRef storeRef = new StoreRef("workspace://SpacesStore");
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
NodeRef defaultRootNode = nodeRefs.get(0);
NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
// Create test folder.
NodeRef folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_FOLDER, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "WebDavMethodExpiryLockTest" + System.currentTimeMillis())).getChildRef();
// Create test document.
NodeRef nodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "text.txt")).getChildRef();
lockMethod = new LockMethod();
lockMethod.createExclusive = true;
lockMethod.m_timeoutDuration = 1;
lockMethod.setDetails(req, resp, webDAVHelper, nodeRef);
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {
@Override
public Object execute() throws Throwable {
try {
// LOCK document.
lockMethod.executeImpl();
// wait for the lock to expire up to 5 seconds
int timeout = 5;
while (timeout > 0 && !lockMethod.lockInfo.isExpired()) {
Thread.sleep(1000);
timeout--;
}
// LOCK against an expired lock.
lockMethod.executeImpl();
} catch (WebDAVServerException e) {
logger.debug(e);
Assert.fail("Document was not locked again, when lock has expired.");
}
return null;
}
});
// Remove test folder.
nodeService.deleteNode(folderNodeRef);
} finally {
Logger.getLogger("org.alfresco.webdav.protocol").setLevel(webdavProtocolSaveLogLevel);
Logger.getLogger("org.alfresco.repo.webdav").setLevel(repoWebdavSaveLogLevel);
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method mockResultset.
private ResultSet mockResultset(List<Long> archivedNodes, List<Long> versionNodes) throws JSONException {
NodeService nodeService = mock(NodeService.class);
when(nodeService.getNodeRef(any())).thenAnswer(new Answer<NodeRef>() {
@Override
public NodeRef answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
// If the DBID is in the list archivedNodes, instead of returning a noderef return achivestore noderef
if (archivedNodes.contains(args[0]))
return new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, GUID.generate());
if (versionNodes.contains(args[0]))
return new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate() + args[0]);
return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
}
});
SearchParameters sp = new SearchParameters();
sp.setBulkFetchEnabled(false);
JSONObject json = new JSONObject(new JSONTokener(JSON_REPONSE));
ResultSet results = new SolrJSONResultSet(json, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
return results;
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method setupTests.
@BeforeClass
public static void setupTests() throws Exception {
Map<String, UserInfo> mapUserInfo = new HashMap<>();
mapUserInfo.put(AuthenticationUtil.getSystemUserName(), new UserInfo(AuthenticationUtil.getSystemUserName(), "sys", "sys"));
Map<QName, Serializable> nodeProps = new HashMap<>();
NodesImpl nodes = mock(NodesImpl.class);
ServiceRegistry sr = mock(ServiceRegistry.class);
DeletedNodes deletedNodes = mock(DeletedNodes.class);
nodes.setServiceRegistry(sr);
VersionService versionService = mock(VersionService.class);
VersionHistory versionHistory = mock(VersionHistory.class);
Map<String, Serializable> versionProperties = new HashMap<>();
versionProperties.put(Version.PROP_DESCRIPTION, "ver desc");
versionProperties.put(Version2Model.PROP_VERSION_TYPE, "v type");
when(versionHistory.getVersion(anyString())).thenAnswer(invocation -> {
return new VersionImpl(versionProperties, new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate()));
});
NodeService nodeService = mock(NodeService.class);
when(versionService.getVersionHistory(notNull(NodeRef.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
NodeRef aNode = (NodeRef) args[0];
return versionHistory;
});
when(nodeService.getProperties(notNull(NodeRef.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
NodeRef aNode = (NodeRef) args[0];
if (StoreMapper.STORE_REF_VERSION2_SPACESSTORE.equals(aNode.getStoreRef())) {
nodeProps.put(Version2Model.PROP_QNAME_FROZEN_NODE_REF, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FROZEN_ID + aNode.getId()));
nodeProps.put(Version2Model.PROP_QNAME_VERSION_LABEL, FROZEN_VER);
}
return nodeProps;
});
when(sr.getVersionService()).thenReturn(versionService);
when(sr.getNodeService()).thenReturn(nodeService);
when(nodes.validateOrLookupNode(notNull(String.class), anyString())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
String aNode = (String) args[0];
if (aNode.endsWith("" + VERSIONED_ID)) {
throw new EntityNotFoundException("" + VERSIONED_ID);
} else {
return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, aNode);
}
});
// // NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
when(nodes.getFolderOrDocument(notNull(NodeRef.class), any(), any(), any(), any())).thenAnswer(new Answer<Node>() {
@Override
public Node answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
NodeRef aNode = (NodeRef) args[0];
if (StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.equals(aNode.getStoreRef())) {
// Return NULL if its from the archive store.
return null;
}
return new Node(aNode, (NodeRef) args[1], nodeProps, mapUserInfo, sr);
}
});
when(deletedNodes.getDeletedNode(notNull(String.class), any(), anyBoolean(), any())).thenAnswer(new Answer<Node>() {
@Override
public Node answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
String nodeId = (String) args[0];
if (FROZEN_ID.equals(nodeId))
throw new EntityNotFoundException(nodeId);
NodeRef aNode = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, nodeId);
return new Node(aNode, new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, "unknown"), nodeProps, mapUserInfo, sr);
}
});
PersonPropertyLookup propertyLookups = mock(PersonPropertyLookup.class);
when(propertyLookups.supports()).thenReturn(Stream.of("creator", "modifier").collect(Collectors.toSet()));
when(propertyLookups.lookup(notNull(String.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
String value = (String) args[0];
if ("mjackson".equals(value))
return "Michael Jackson";
return null;
});
PropertyLookupRegistry propertyLookupRegistry = new PropertyLookupRegistry();
propertyLookupRegistry.setLookups(Arrays.asList(propertyLookups));
mapper = new ResultMapper();
mapper.setNodes(nodes);
mapper.setStoreMapper(new StoreMapper());
mapper.setPropertyLookup(propertyLookupRegistry);
mapper.setDeletedNodes(deletedNodes);
mapper.setServiceRegistry(sr);
NodeVersionsRelation nodeVersionsRelation = new NodeVersionsRelation();
nodeVersionsRelation.setNodes(nodes);
nodeVersionsRelation.setServiceRegistry(sr);
nodeVersionsRelation.afterPropertiesSet();
mapper.setNodeVersions(nodeVersionsRelation);
helper = new SerializerTestHelper();
searchMapper.setStoreMapper(new StoreMapper());
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ReplicationRestApiTest method testReplicationDefinitionGet.
public void testReplicationDefinitionGet() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
// If an invalid name is given, you get a 404
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), 404);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
// Add a definition, it should show up
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
replicationService.saveReplicationDefinition(rd);
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
// Check
assertEquals("Test1", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("New", json.get("status"));
assertEquals(JSONObject.NULL, json.get("startedAt"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals(JSONObject.NULL, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
// Payload is empty
assertEquals(0, json.getJSONArray("payload").length());
// Ensure we didn't get any unexpected data back
JSONArray keys = json.names();
for (int i = 0; i < keys.length(); i++) {
String key = keys.getString(0);
if (key.equals("name") || key.equals("description") || key.equals("status") || key.equals("startedAt") || key.equals("endedAt") || key.equals("failureMessage") || key.equals("executionDetails") || key.equals("payload") || key.equals("transferLocalReport") || key.equals("transferRemoteReport") || key.equals("enabled") || key.equals("targetName") || key.equals("schedule")) {
// All good
} else {
fail("Unexpected key '" + key + "' found in json, raw json is\n" + jsonStr);
}
}
// Mark it as pending, and check
actionTrackingService.recordActionPending(rd);
String actionId = rd.getId();
int instanceId = ((ActionImpl) rd).getExecutionInstance();
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test1", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("Pending", json.get("status"));
assertEquals(JSONObject.NULL, json.get("startedAt"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
// Payload is empty
assertEquals(0, json.getJSONArray("payload").length());
// Change the status to running, and re-check
actionTrackingService.recordActionExecuting(rd);
assertEquals(actionId, rd.getId());
assertEquals(instanceId, ((ActionImpl) rd).getExecutionInstance());
String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test1", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("Running", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
// Payload is empty
assertEquals(0, json.getJSONArray("payload").length());
// Cancel it
actionTrackingService.requestActionCancellation(rd);
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test1", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("CancelRequested", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
// Payload is empty
assertEquals(0, json.getJSONArray("payload").length());
// Add some payload details, ensure that they get expanded
// as they should be
rd.getPayload().add(repositoryHelper.getCompanyHome());
rd.getPayload().add(dataDictionary);
replicationService.saveReplicationDefinition(rd);
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test1", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("CancelRequested", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
// Check Payload
assertEquals(2, json.getJSONArray("payload").length());
JSONObject payload = json.getJSONArray("payload").getJSONObject(0);
assertEquals(repositoryHelper.getCompanyHome().toString(), payload.get("nodeRef"));
assertEquals(true, payload.get("isFolder"));
assertEquals("Company Home", payload.get("name"));
assertEquals("/Company Home", payload.get("path"));
payload = json.getJSONArray("payload").getJSONObject(1);
assertEquals(dataDictionary.toString(), payload.get("nodeRef"));
assertEquals(true, payload.get("isFolder"));
assertEquals("Data Dictionary", payload.get("name"));
assertEquals("/Company Home/Data Dictionary", payload.get("path"));
// Add a deleted NodeRef too, will be silently ignored
// by the webscript layer
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
NodeRef deleted = nodeService.createNode(dataDictionary, ContentModel.ASSOC_CONTAINS, QName.createQName("IwillBEdeleted"), ContentModel.TYPE_CONTENT).getChildRef();
nodeService.deleteNode(deleted);
txn.commit();
rd.getPayload().add(deleted);
replicationService.saveReplicationDefinition(rd);
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test1", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("CancelRequested", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
// Check Payload
assertEquals(2, json.getJSONArray("payload").length());
payload = json.getJSONArray("payload").getJSONObject(0);
assertEquals("Company Home", payload.get("name"));
payload = json.getJSONArray("payload").getJSONObject(1);
assertEquals("Data Dictionary", payload.get("name"));
// Add a 2nd and 3rd definition
rd = replicationService.createReplicationDefinition("Test2", "2nd Testing");
replicationService.saveReplicationDefinition(rd);
rd = replicationService.createReplicationDefinition("Test3", "3rd Testing");
rd.setLocalTransferReport(repositoryHelper.getRootHome());
rd.setRemoteTransferReport(repositoryHelper.getCompanyHome());
rd.setEnabled(false);
// Have the 3rd one flagged as having failed
txn = transactionService.getUserTransaction();
txn.begin();
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionExecuting(rd);
actionTrackingService.recordActionFailure(rd, new Exception("Test Failure"));
txn.commit();
Thread.sleep(50);
replicationService.saveReplicationDefinition(rd);
// Original one comes back unchanged
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test1", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("CancelRequested", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
// Check Payload
assertEquals(2, json.getJSONArray("payload").length());
payload = json.getJSONArray("payload").getJSONObject(0);
assertEquals(repositoryHelper.getCompanyHome().toString(), payload.get("nodeRef"));
assertEquals(true, payload.get("isFolder"));
assertEquals("Company Home", payload.get("name"));
assertEquals("/Company Home", payload.get("path"));
payload = json.getJSONArray("payload").getJSONObject(1);
assertEquals(dataDictionary.toString(), payload.get("nodeRef"));
assertEquals(true, payload.get("isFolder"));
assertEquals("Data Dictionary", payload.get("name"));
assertEquals("/Company Home/Data Dictionary", payload.get("path"));
// They show up things as expected
response = sendRequest(new GetRequest(URL_DEFINITION + "Test2"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test2", json.get("name"));
assertEquals("2nd Testing", json.get("description"));
assertEquals("New", json.get("status"));
assertEquals(JSONObject.NULL, json.get("startedAt"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals(JSONObject.NULL, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// And the 3rd one, which is failed
response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
String endedAt = ISO8601DateFormat.format(rd.getExecutionEndDate());
assertEquals("Test3", json.get("name"));
assertEquals("3rd Testing", json.get("description"));
assertEquals("Failed", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(endedAt, json.getJSONObject("endedAt").get("iso8601"));
assertEquals("Test Failure", json.get("failureMessage"));
assertEquals(JSONObject.NULL, json.get("executionDetails"));
assertEquals(repositoryHelper.getRootHome().toString(), json.get("transferLocalReport"));
assertEquals(repositoryHelper.getCompanyHome().toString(), json.get("transferRemoteReport"));
assertEquals(false, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// When pending/running, the previous end time, transfer reports and
// failure details are hidden
rd = replicationService.loadReplicationDefinition("Test3");
assertEquals(0, actionTrackingService.getExecutingActions(rd).size());
actionTrackingService.recordActionPending(rd);
assertEquals(1, actionTrackingService.getExecutingActions(rd).size());
instanceId = ((ActionImpl) rd).getExecutionInstance();
actionId = rd.getId();
response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertEquals("Test3", json.get("name"));
assertEquals("3rd Testing", json.get("description"));
assertEquals("Pending", json.get("status"));
assertEquals(JSONObject.NULL, json.get("startedAt"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(false, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
actionTrackingService.recordActionExecuting(rd);
response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
assertEquals("Test3", json.get("name"));
assertEquals("3rd Testing", json.get("description"));
assertEquals("Running", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(false, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
actionTrackingService.requestActionCancellation(rd);
response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
assertEquals("Test3", json.get("name"));
assertEquals("3rd Testing", json.get("description"));
assertEquals("CancelRequested", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(false, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// These show up again when no longer running
txn = transactionService.getUserTransaction();
txn.begin();
actionTrackingService.recordActionComplete(rd);
txn.commit();
response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
endedAt = ISO8601DateFormat.format(rd.getExecutionEndDate());
assertEquals("Test3", json.get("name"));
assertEquals("3rd Testing", json.get("description"));
assertEquals("Completed", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(endedAt, json.getJSONObject("endedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals(JSONObject.NULL, json.get("executionDetails"));
assertEquals(repositoryHelper.getRootHome().toString(), json.get("transferLocalReport"));
assertEquals(repositoryHelper.getCompanyHome().toString(), json.get("transferRemoteReport"));
assertEquals(false, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class RuleServiceTest method createTestFolders.
private void createTestFolders() {
StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
if (!nodeService.exists(testStore)) {
testStore = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
}
NodeRef rootNodeRef = nodeService.getRootNode(testStore);
testWorkNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_FOLDER).getChildRef();
testNodeRef = fileFolderService.create(testWorkNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER).getNodeRef();
testNodeRef2 = fileFolderService.create(testWorkNodeRef, TEST_FOLDER_2, ContentModel.TYPE_FOLDER).getNodeRef();
}
Aggregations