use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferServiceCallbackTest method testCompleteSuccess.
public void testCompleteSuccess() {
TransferProgress status0 = new TransferProgress();
status0.setStatus(Status.COMMIT_REQUESTED);
status0.setCurrentPosition(0);
status0.setEndPosition(0);
TransferProgress status1 = new TransferProgress();
status1.setStatus(Status.COMMITTING);
status1.setCurrentPosition(0);
status1.setEndPosition(4);
TransferProgress status2 = new TransferProgress();
status2.setStatus(Status.COMMITTING);
status2.setCurrentPosition(3);
status2.setEndPosition(4);
TransferProgress status3 = new TransferProgress();
status3.setStatus(Status.COMMITTING);
status3.setCurrentPosition(5);
status3.setEndPosition(8);
TransferProgress status4 = new TransferProgress();
status4.setStatus(Status.COMPLETE);
status4.setCurrentPosition(8);
status4.setEndPosition(8);
TransferProgress[] statuses = new TransferProgress[] { status0, status1, status2, status3, status4 };
configureBasicMockTransmitter(statuses);
when(mockedTransferTransmitter.begin(target, localRepositoryId, version)).thenReturn(transfer);
TransferDefinition transferDef = new TransferDefinition();
transferDef.setNodes(folder1, file1, file2, file3);
transferService.transfer(TRANSFER_TARGET_NAME, transferDef, mockedCallback);
List<TransferEvent> expectedEvents = new ArrayList<TransferEvent>();
TransferEventImpl event;
event = new TransferEventEnterState();
event.setTransferState(TransferState.START);
expectedEvents.add(event);
event = new TransferEventBegin();
event.setTransferState(TransferState.START);
expectedEvents.add(event);
event = new TransferEventEndState();
event.setTransferState(TransferState.START);
expectedEvents.add(event);
event = new TransferEventEnterState();
event.setTransferState(TransferState.SENDING_SNAPSHOT);
expectedEvents.add(event);
event = new TransferEventSendingSnapshot();
event.setTransferState(TransferState.SENDING_SNAPSHOT);
expectedEvents.add(event);
event = new TransferEventEndState();
event.setTransferState(TransferState.SENDING_SNAPSHOT);
expectedEvents.add(event);
event = new TransferEventEnterState();
event.setTransferState(TransferState.SENDING_CONTENT);
expectedEvents.add(event);
event = new TransferEventSendingContent();
event.setTransferState(TransferState.SENDING_CONTENT);
expectedEvents.add(event);
event = new TransferEventSendingContent();
event.setTransferState(TransferState.SENDING_CONTENT);
expectedEvents.add(event);
event = new TransferEventSendingContent();
event.setTransferState(TransferState.SENDING_CONTENT);
expectedEvents.add(event);
event = new TransferEventEndState();
event.setTransferState(TransferState.SENDING_CONTENT);
expectedEvents.add(event);
event = new TransferEventEnterState();
event.setTransferState(TransferState.PREPARING);
expectedEvents.add(event);
event = new TransferEventEndState();
event.setTransferState(TransferState.PREPARING);
expectedEvents.add(event);
event = new TransferEventEnterState();
event.setTransferState(TransferState.COMMITTING);
expectedEvents.add(event);
event = new TransferEventCommittingStatus();
event.setTransferState(TransferState.COMMITTING);
expectedEvents.add(event);
event = new TransferEventCommittingStatus();
event.setTransferState(TransferState.COMMITTING);
expectedEvents.add(event);
event = new TransferEventCommittingStatus();
event.setTransferState(TransferState.COMMITTING);
expectedEvents.add(event);
event = new TransferEventCommittingStatus();
event.setTransferState(TransferState.COMMITTING);
expectedEvents.add(event);
event = new TransferEventEndState();
event.setTransferState(TransferState.COMMITTING);
expectedEvents.add(event);
event = new TransferEventEnterState();
event.setTransferState(TransferState.SUCCESS);
expectedEvents.add(event);
event = new TransferEventReport();
event.setTransferState(TransferState.SUCCESS);
expectedEvents.add(event);
event = new TransferEventReport();
event.setTransferState(TransferState.SUCCESS);
expectedEvents.add(event);
event = new TransferEventSuccess();
event.setTransferState(TransferState.SUCCESS);
expectedEvents.add(event);
verifyCallback(expectedEvents);
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferServiceImplTest method testExistingNodes.
// testPeerAssocs
/**
* Test Existing nodes. ALF-12262
*
* Guest Home
* |
* GUID
* |
* A1 B1
* | |
* A2 B2
*
* @throws Exception
*/
@Test
public void testExistingNodes() throws Exception {
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
final String CONTENT_TITLE = "ContentTitle";
final Locale CONTENT_LOCALE = Locale.GERMAN;
final String CONTENT_ENCODING = "UTF-8";
/**
* For unit test
* - replace the HTTP transport with the in-process transport
* - replace the node factory with one that will map node refs, paths etc.
*
* Fake Repository Id
*/
final TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService);
transferServiceImpl.setTransmitter(transmitter);
final UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory);
transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory);
final List<Pair<Path, Path>> pathMap = testNodeFactory.getPathMap();
// Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level.
pathMap.add(new Pair<Path, Path>(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
final String targetName = "testExistingNodes";
class TestContext {
TransferTarget transferMe;
NodeRef folderNodeRef;
NodeRef contentNodeRef;
NodeRef rootNodeRef;
NodeRef destFolderNodeRef;
NodeRef destFileNodeRef;
}
;
RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>() {
@Override
public TestContext execute() throws Throwable {
TestContext testContext = new TestContext();
NodeRef guestHome = repositoryHelper.getGuestHome();
NodeRef companyHome = repositoryHelper.getCompanyHome();
/**
* Create a test node that we will read and write
*/
String name = GUID.generate();
TransferDefinition def = new TransferDefinition();
ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_FOLDER);
testContext.rootNodeRef = child.getChildRef();
nodeService.setProperty(testContext.rootNodeRef, ContentModel.PROP_TITLE, name);
nodeService.setProperty(testContext.rootNodeRef, ContentModel.PROP_NAME, name);
// Side effect - initialisee nodeid mapping
testNodeFactory.createTransferManifestNode(testContext.rootNodeRef, def, new TransferContext());
child = nodeService.createNode(testContext.rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("A1"), ContentModel.TYPE_FOLDER);
testContext.folderNodeRef = child.getChildRef();
nodeService.setProperty(testContext.folderNodeRef, ContentModel.PROP_TITLE, "A1");
nodeService.setProperty(testContext.folderNodeRef, ContentModel.PROP_NAME, "A1");
// Side effect - initialise nodeid mapping
testNodeFactory.createTransferManifestNode(testContext.folderNodeRef, def, new TransferContext());
child = nodeService.createNode(testContext.folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("A2"), ContentModel.TYPE_CONTENT);
testContext.contentNodeRef = child.getChildRef();
nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_TITLE, "A2");
nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_NAME, "A2");
// Side effect - initialise nodeid mapping
testNodeFactory.createTransferManifestNode(testContext.contentNodeRef, def, new TransferContext());
// Put nodes into destination
child = nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_FOLDER);
// testContext.rootNodeRef = child.getChildRef();
nodeService.setProperty(testContext.rootNodeRef, ContentModel.PROP_TITLE, name);
nodeService.setProperty(testContext.rootNodeRef, ContentModel.PROP_NAME, name);
child = nodeService.createNode(child.getChildRef(), ContentModel.ASSOC_CONTAINS, QName.createQName("A1"), ContentModel.TYPE_FOLDER);
testContext.destFolderNodeRef = child.getChildRef();
nodeService.setProperty(testContext.destFolderNodeRef, ContentModel.PROP_TITLE, "A1");
nodeService.setProperty(testContext.destFolderNodeRef, ContentModel.PROP_NAME, "A1");
child = nodeService.createNode(testContext.destFolderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("A2"), ContentModel.TYPE_CONTENT);
testContext.destFileNodeRef = child.getChildRef();
nodeService.setProperty(testContext.destFileNodeRef, ContentModel.PROP_TITLE, "A2");
nodeService.setProperty(testContext.destFileNodeRef, ContentModel.PROP_NAME, "A2");
/**
* Make sure the transfer target exists and is enabled.
*/
if (!transferService.targetExists(targetName)) {
testContext.transferMe = createTransferTarget(targetName);
} else {
testContext.transferMe = transferService.getTransferTarget(targetName);
}
transferService.enableTransferTarget(targetName, true);
return testContext;
}
};
final TestContext testContext = tran.doInTransaction(setupCB);
RetryingTransactionCallback<Void> transferCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodes = new HashSet<NodeRef>();
nodes.add(testContext.rootNodeRef);
nodes.add(testContext.folderNodeRef);
nodes.add(testContext.contentNodeRef);
definition.setNodes(nodes);
transferService.transfer(targetName, definition);
return null;
}
};
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
assertTrue("folder has transferred aspect", !nodeService.hasAspect(testContext.destFolderNodeRef, TransferModel.ASPECT_TRANSFERRED));
assertTrue("file has transferred aspctet", !nodeService.hasAspect(testContext.destFileNodeRef, TransferModel.ASPECT_TRANSFERRED));
return null;
}
};
/**
* This is the test
*/
tran.doInTransaction(transferCB);
tran.doInTransaction(validateCB);
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferServiceImplTest method testMoveNode.
/**
* Test the transfer method w.r.t. moving a node.
*
* Step 1.
* Move by changing the parent's node ref.
*
* This is a unit test so it does some shenanigans to send to the same instance of alfresco.
*/
@Test
public void testMoveNode() throws Exception {
final String CONTENT_TITLE = "ContentTitle";
final String CONTENT_TITLE_UPDATED = "ContentTitleUpdated";
final Locale CONTENT_LOCALE = Locale.GERMAN;
final String CONTENT_STRING = "Hello";
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Now go ahead and create our first transfer target
*/
final String targetName = "testTransferMoveNode";
class TestContext {
TransferTarget transferMe;
NodeRef contentNodeRef;
NodeRef parentNodeRef;
NodeRef destNodeRef;
NodeRef moveToNodeRef;
}
;
/**
* Unit test kludge to transfer from guest home to company home
*/
final UnitTestTransferManifestNodeFactory testNodeFactory = unitTestKludgeToTransferGuestHomeToCompanyHome();
RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>() {
@Override
public TestContext execute() throws Throwable {
TestContext ctx = new TestContext();
NodeRef guestHome = repositoryHelper.getGuestHome();
/**
* Create a test node that we will read and write
*/
String name = GUID.generate();
ChildAssociationRef newParent = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_FOLDER);
ctx.parentNodeRef = newParent.getChildRef();
nodeService.setProperty(ctx.parentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
nodeService.setProperty(ctx.parentNodeRef, ContentModel.PROP_NAME, name);
ChildAssociationRef child = nodeService.createNode(ctx.parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("TransferOneNode"), ContentModel.TYPE_CONTENT);
ctx.contentNodeRef = child.getChildRef();
nodeService.setProperty(ctx.contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
nodeService.setProperty(ctx.contentNodeRef, ContentModel.PROP_NAME, "TransferOneNode");
ChildAssociationRef moveTo = nodeService.createNode(ctx.parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("moveTo"), ContentModel.TYPE_FOLDER);
ctx.moveToNodeRef = moveTo.getChildRef();
nodeService.setProperty(ctx.moveToNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
nodeService.setProperty(ctx.moveToNodeRef, ContentModel.PROP_NAME, "moveTo");
if (!transferService.targetExists(targetName)) {
ctx.transferMe = createTransferTarget(targetName);
} else {
ctx.transferMe = transferService.getTransferTarget(targetName);
}
transferService.enableTransferTarget(targetName, true);
return ctx;
}
};
final TestContext testContext = tran.doInTransaction(setupCB);
DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A);
transferServiceImpl.setDescriptorService(mockedDescriptorService);
RetryingTransactionCallback<Void> firstTransferCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
logger.debug("First transfer - create new node (no content yet)");
/**
* Step 0: Transfer our node which has no content
*/
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodes = new HashSet<NodeRef>();
nodes.add(testContext.parentNodeRef);
nodes.add(testContext.contentNodeRef);
nodes.add(testContext.moveToNodeRef);
definition.setNodes(nodes);
transferService.transfer(targetName, definition);
return null;
}
};
tran.doInTransaction(firstTransferCB);
RetryingTransactionCallback<Void> validateTransferCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Now validate that the target node exists and has similar properties to the source
NodeRef destNodeRef = testNodeFactory.getMappedNodeRef(testContext.contentNodeRef);
NodeRef destParentNodeRef = testNodeFactory.getMappedNodeRef(testContext.parentNodeRef);
ChildAssociationRef destParent = nodeService.getPrimaryParent(destNodeRef);
assertEquals("parent node ref not correct prior to test", destParentNodeRef, destParent.getParentRef());
return null;
}
};
tran.doInTransaction(validateTransferCB);
/**
* Step 1: Move a node through transfer
* Move the destination node
* transfer (Should transfer the destination node back)
*/
RetryingTransactionCallback<Void> moveNodeCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
logger.debug("Transfer again with moved node");
// Move the node up one level on the destination.
nodeService.moveNode(testContext.contentNodeRef, testContext.moveToNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("testOneNode"));
return null;
}
};
tran.doInTransaction(moveNodeCB);
RetryingTransactionCallback<Void> secondTransferCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
logger.debug("Second transfer");
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodes = new HashSet<NodeRef>();
nodes.add(testContext.contentNodeRef);
definition.setNodes(nodes);
transferService.transfer(targetName, definition);
return null;
}
};
tran.doInTransaction(secondTransferCB);
RetryingTransactionCallback<Void> secondValidateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Now validate that the target node exists and has similar properties to the source
NodeRef destNodeRef = testNodeFactory.getMappedNodeRef(testContext.contentNodeRef);
NodeRef destParentNodeRef = testNodeFactory.getMappedNodeRef(testContext.moveToNodeRef);
ChildAssociationRef destParent = nodeService.getPrimaryParent(destNodeRef);
assertEquals("node not moved", destParentNodeRef, destParent.getParentRef());
return null;
}
};
tran.doInTransaction(secondValidateCB);
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferServiceImplTest method testRepeatUpdateOfContent.
// end of testEmptyContent
/**
* Test the transfer method with regard to a repeated update of content.by sending one node (CRUD).
*
* This is a unit test so it does some shenanigans to send to the same instance of alfresco.
*/
@Test
public void testRepeatUpdateOfContent() throws Exception {
final String CONTENT_TITLE = "ContentTitle";
final Locale CONTENT_LOCALE = Locale.GERMAN;
final String CONTENT_ENCODING = "UTF-8";
/**
* For unit test
* - replace the HTTP transport with the in-process transport
* - replace the node factory with one that will map node refs, paths etc.
*
* Fake Repository Id
*/
final TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService);
transferServiceImpl.setTransmitter(transmitter);
final UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory);
transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory);
final List<Pair<Path, Path>> pathMap = testNodeFactory.getPathMap();
// Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level.
pathMap.add(new Pair<Path, Path>(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A);
transferServiceImpl.setDescriptorService(mockedDescriptorService);
final String targetName = "testRepeatUpdateOfContent";
class TestContext {
TransferTarget transferMe;
NodeRef contentNodeRef;
NodeRef destNodeRef;
String contentString;
}
;
RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>() {
@Override
public TestContext execute() throws Throwable {
TestContext testContext = new TestContext();
NodeRef guestHome = repositoryHelper.getGuestHome();
/**
* Create a test node that we will read and write
*/
String name = GUID.generate();
ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT);
testContext.contentNodeRef = child.getChildRef();
nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_NAME, name);
/**
* Make sure the transfer target exists and is enabled.
*/
if (!transferService.targetExists(targetName)) {
testContext.transferMe = createTransferTarget(targetName);
} else {
testContext.transferMe = transferService.getTransferTarget(targetName);
}
transferService.enableTransferTarget(targetName, true);
return testContext;
}
};
final TestContext testContext = transactionService.getRetryingTransactionHelper().doInTransaction(setupCB, false, true);
RetryingTransactionCallback<Void> updateContentCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true);
writer.setLocale(CONTENT_LOCALE);
writer.setEncoding(CONTENT_ENCODING);
writer.putContent(testContext.contentString);
return null;
}
};
RetryingTransactionCallback<Void> transferCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodes = new HashSet<NodeRef>();
nodes.add(testContext.contentNodeRef);
definition.setNodes(nodes);
transferService.transfer(targetName, definition);
return null;
}
};
RetryingTransactionCallback<Void> checkTransferCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Now validate that the target node exists and has similar properties to the source
NodeRef destNodeRef = testNodeFactory.getMappedNodeRef(testContext.contentNodeRef);
ContentReader reader = contentService.getReader(destNodeRef, ContentModel.PROP_CONTENT);
assertNotNull("content reader is null", reader);
assertTrue("content encoding is wrong", reader.getEncoding().equalsIgnoreCase(CONTENT_ENCODING));
assertEquals("content locale is wrong", reader.getLocale(), CONTENT_LOCALE);
assertTrue("content does not exist", reader.exists());
String contentStr = reader.getContentString();
assertEquals("Content is wrong", contentStr, testContext.contentString);
return null;
}
};
/**
* This is the test
*/
for (int i = 0; i < 6; i++) {
logger.debug("testRepeatUpdateContent - iteration:" + i);
testContext.contentString = String.valueOf(i);
transactionService.getRetryingTransactionHelper().doInTransaction(updateContentCB);
transactionService.getRetryingTransactionHelper().doInTransaction(transferCB);
transactionService.getRetryingTransactionHelper().doInTransaction(checkTransferCB);
}
}
use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.
the class TransferServiceImplTest method testTransferOneNode.
/**
* Test the transfer method by sending one node (CRUD).
*
* Step 1: Create a new node (No content)
* transfer
*
* Step 2: Update Node title property
* transfer
*
* Step 3: Update Content property (add content)
* transfer
*
* Step 4: Transfer again
* transfer (Should transfer but not request the content item)
*
* Step 5: Update Content property (update content)
*
* Step 6: Delete the node
*
* Step 7: Negative test : transfer no nodes
* transfer (should throw exception)
*
* Step 8: Negative test : transfer to a disabled transfer target
* transfer (should throw exception)
*
* This is a unit test so it does some shenanigans to send to the same instance of alfresco.
*/
@Test
public void testTransferOneNode() throws Exception {
final String CONTENT_TITLE = "ContentTitle";
final String CONTENT_TITLE_UPDATED = "ContentTitleUpdated";
final Locale CONTENT_LOCALE = Locale.GERMAN;
final String CONTENT_STRING = "Hello World";
final String CONTENT_UPDATE_STRING = "Foo Bar";
final String targetName = "testXferOneNode";
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
class TestContext {
TransferTarget transferMe;
NodeRef contentNodeRef;
NodeRef destNodeRef;
}
;
/**
* Unit test kludge to transfer from guest home to company home
*/
final UnitTestTransferManifestNodeFactory testNodeFactory = unitTestKludgeToTransferGuestHomeToCompanyHome();
DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A);
transferServiceImpl.setDescriptorService(mockedDescriptorService);
RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>() {
@Override
public TestContext execute() throws Throwable {
TestContext ctx = new TestContext();
NodeRef guestHome = repositoryHelper.getGuestHome();
/**
* Create a test node that we will read and write
*/
String name = GUID.generate();
ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT);
ctx.contentNodeRef = child.getChildRef();
nodeService.setProperty(ctx.contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
nodeService.setProperty(ctx.contentNodeRef, ContentModel.PROP_NAME, name);
if (!transferService.targetExists(targetName)) {
ctx.transferMe = createTransferTarget(targetName);
} else {
ctx.transferMe = transferService.getTransferTarget(targetName);
}
transferService.enableTransferTarget(targetName, true);
return ctx;
}
};
final TestContext testContext = tran.doInTransaction(setupCB);
/**
* Step 1: Transfer our node which has no content
*/
logger.debug("First transfer - create new node (no content yet)");
RetryingTransactionCallback<Void> transferCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodes = new HashSet<NodeRef>();
nodes.add(testContext.contentNodeRef);
definition.setNodes(nodes);
transferService.transfer(targetName, definition);
return null;
}
};
tran.doInTransaction(transferCB);
RetryingTransactionCallback<Void> validateStep1CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Now validate that the target node exists and has similar properties to the source
testContext.destNodeRef = testNodeFactory.getMappedNodeRef(testContext.contentNodeRef);
assertFalse("unit test stuffed up - comparing with self", testContext.destNodeRef.equals(testContext.transferMe.getNodeRef()));
assertTrue("dest node ref does not exist", nodeService.exists(testContext.destNodeRef));
assertEquals("title is wrong", (String) nodeService.getProperty(testContext.destNodeRef, ContentModel.PROP_TITLE), CONTENT_TITLE);
assertEquals("type is wrong", nodeService.getType(testContext.contentNodeRef), nodeService.getType(testContext.destNodeRef));
// Check the modified time of the destination node is the same as the source node.
Date destModifiedDate = (Date) nodeService.getProperty(testContext.destNodeRef, ContentModel.PROP_MODIFIED);
Date srcModifiedDate = (Date) nodeService.getProperty(testContext.contentNodeRef, ContentModel.PROP_MODIFIED);
logger.debug("srcModifiedDate : " + srcModifiedDate + " destModifiedDate : " + destModifiedDate);
assertTrue("dest modified date is not correct", destModifiedDate.compareTo(srcModifiedDate) == 0);
Date destCreatedDate = (Date) nodeService.getProperty(testContext.destNodeRef, ContentModel.PROP_CREATED);
Date srcCreatedDate = (Date) nodeService.getProperty(testContext.contentNodeRef, ContentModel.PROP_CREATED);
logger.debug("srcCreatedDate : " + srcCreatedDate + " destCreatedDate : " + destCreatedDate);
assertTrue("dest created date is not correct", destCreatedDate.compareTo(srcCreatedDate) == 0);
// Check injected transferred aspect.
assertNotNull("transferredAspect", (String) nodeService.getProperty(testContext.destNodeRef, TransferModel.PROP_REPOSITORY_ID));
// Now set up the next test which is to change the title
nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE_UPDATED);
return null;
}
};
tran.doInTransaction(validateStep1CB);
/**
* Step 2:
* Transfer our node again - so this is an update of the title property
*/
logger.debug("Second transfer - update title property (no content yet)");
tran.doInTransaction(transferCB);
RetryingTransactionCallback<Void> validateStep2CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Now validate that the target node exists and has similar properties to the source
assertFalse("unit test stuffed up - comparing with self", testContext.destNodeRef.equals(testContext.transferMe.getNodeRef()));
assertTrue("dest node ref does not exist", nodeService.exists(testContext.destNodeRef));
assertEquals("title is wrong", (String) nodeService.getProperty(testContext.destNodeRef, ContentModel.PROP_TITLE), CONTENT_TITLE_UPDATED);
assertEquals("type is wrong", nodeService.getType(testContext.contentNodeRef), nodeService.getType(testContext.destNodeRef));
// Check the modified time of the destination node is the same as the source node.
Date destModifiedDate = (Date) nodeService.getProperty(testContext.destNodeRef, ContentModel.PROP_MODIFIED);
Date srcModifiedDate = (Date) nodeService.getProperty(testContext.contentNodeRef, ContentModel.PROP_MODIFIED);
logger.debug("srcModifiedDate : " + srcModifiedDate + " destModifiedDate : " + destModifiedDate);
assertTrue("after update, modified date is not correct", destModifiedDate.compareTo(srcModifiedDate) == 0);
Date destCreatedDate = (Date) nodeService.getProperty(testContext.destNodeRef, ContentModel.PROP_CREATED);
Date srcCreatedDate = (Date) nodeService.getProperty(testContext.contentNodeRef, ContentModel.PROP_CREATED);
logger.debug("srcCreatedDate : " + srcCreatedDate + " destCreatedDate : " + destCreatedDate);
assertTrue("after update, created date is not correct", destCreatedDate.compareTo(srcCreatedDate) == 0);
// Check injected transferred aspect.
assertNotNull("transferredAspect", (String) nodeService.getProperty(testContext.destNodeRef, TransferModel.PROP_REPOSITORY_ID));
return null;
}
};
tran.doInTransaction(validateStep2CB);
/**
* Step 3 - update to add content
*/
RetryingTransactionCallback<Void> step3WriteContentCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true);
writer.setLocale(CONTENT_LOCALE);
writer.putContent(CONTENT_STRING);
return null;
}
};
tran.doInTransaction(step3WriteContentCB);
logger.debug("Transfer again - this is an update to add new content");
tran.doInTransaction(transferCB);
RetryingTransactionCallback<Void> validateStep3CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
ContentReader reader = contentService.getReader(testContext.destNodeRef, ContentModel.PROP_CONTENT);
assertNotNull("reader is null", reader);
String contentStr = reader.getContentString();
assertEquals("Content is wrong", contentStr, CONTENT_STRING);
return null;
}
};
tran.doInTransaction(validateStep3CB);
/**
* Step 4:
* Now transfer nothing - content items do not need to be transferred since its already on
* the destination.
*/
logger.debug("Transfer again - with no new content");
tran.doInTransaction(transferCB);
RetryingTransactionCallback<Void> validateStep4CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Now validate that the target node still exists and in particular that the old content is still there
assertFalse("unit test stuffed up - comparing with self", testContext.destNodeRef.equals(testContext.transferMe.getNodeRef()));
assertTrue("dest node ref does not exist", nodeService.exists(testContext.destNodeRef));
assertEquals("title is wrong", (String) nodeService.getProperty(testContext.destNodeRef, ContentModel.PROP_TITLE), CONTENT_TITLE_UPDATED);
assertEquals("type is wrong", nodeService.getType(testContext.contentNodeRef), nodeService.getType(testContext.destNodeRef));
ContentReader reader = contentService.getReader(testContext.destNodeRef, ContentModel.PROP_CONTENT);
assertNotNull("reader is null", reader);
String contentStr = reader.getContentString();
assertEquals("Content is wrong", contentStr, CONTENT_STRING);
// Check injected transferred aspect.
assertNotNull("transferredAspect", (String) nodeService.getProperty(testContext.destNodeRef, TransferModel.PROP_REPOSITORY_ID));
return null;
}
};
tran.doInTransaction(validateStep4CB);
/**
* Step 5 - update content through transfer
*/
RetryingTransactionCallback<Void> step5UpdateContentCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true);
writer.setLocale(CONTENT_LOCALE);
writer.putContent(CONTENT_UPDATE_STRING);
return null;
}
};
tran.doInTransaction(step5UpdateContentCB);
logger.debug("Transfer again - this is an update to add new content");
tran.doInTransaction(transferCB);
RetryingTransactionCallback<Void> validateStep5CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
ContentReader reader = contentService.getReader(testContext.destNodeRef, ContentModel.PROP_CONTENT);
assertNotNull("reader is null", reader);
String contentStr = reader.getContentString();
assertEquals("Content is wrong", CONTENT_UPDATE_STRING, contentStr);
return null;
}
};
tran.doInTransaction(validateStep5CB);
/**
* Step 6
* Delete the node through transfer of the archive node
*/
logger.debug("Transfer again - to delete a node through transferring an archive node");
RetryingTransactionCallback<Void> step6CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
nodeService.deleteNode(testContext.contentNodeRef);
return null;
}
};
tran.doInTransaction(step6CB);
RetryingTransactionCallback<Void> transferDeletedCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef deletedContentNodeRef = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, testContext.contentNodeRef.getId());
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodesToRemove = new HashSet<NodeRef>();
nodesToRemove.add(deletedContentNodeRef);
definition.setNodesToRemove(nodesToRemove);
transferService.transfer(targetName, definition);
return null;
}
};
tran.doInTransaction(transferDeletedCB);
RetryingTransactionCallback<Void> validateStep6CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
assertFalse("dest node still exists", nodeService.exists(testContext.destNodeRef));
return null;
}
};
tran.doInTransaction(validateStep6CB);
/**
* Step 7
* Negative test transfer nothing
*/
logger.debug("Transfer again - with no content - should throw exception");
try {
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodes = new HashSet<NodeRef>();
definition.setNodes(nodes);
transferService.transfer(targetName, definition);
fail("exception not thrown");
} catch (TransferException te) {
// expect to go here
}
/**
* Step 7: Negative test : transfer to a disabled transfer target
* transfer (should throw exception)
*/
logger.debug("Transfer again - with no content - should throw exception");
try {
transferService.enableTransferTarget(targetName, false);
TransferDefinition definition = new TransferDefinition();
Set<NodeRef> nodes = new HashSet<NodeRef>();
nodes.add(testContext.contentNodeRef);
definition.setNodes(nodes);
transferService.transfer(targetName, definition);
fail("target not enabled exception not thrown");
} catch (TransferException te) {
// expect to go here
assertTrue("check contents of exception message :" + te.toString(), te.getCause().getMessage().contains("enabled"));
}
}
Aggregations