use of org.alfresco.service.cmr.transfer.TransferTarget 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.TransferTarget 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.TransferTarget 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.TransferTarget in project alfresco-repository by Alfresco.
the class TransferServiceImplTest method testCreateTarget.
/**
* Test create target.
*
* @throws Exception
*/
@Test
public void testCreateTarget() throws Exception {
String name = "Test Transfer Target " + GUID.generate();
String title = "title";
String description = "description";
String endpointProtocol = "http";
String endpointHost = "localhost";
int endpointPort = 8080;
String endpointPath = "rhubarb";
String username = "admin";
char[] password = "password".toCharArray();
/**
* Now go ahead and create our first transfer target
*/
TransferTarget ret = transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
assertNotNull("return value is null", ret);
assertNotNull("node ref is null", ret.getNodeRef());
// titled aspect
assertEquals("name not equal", ret.getName(), name);
assertEquals("title not equal", ret.getTitle(), title);
assertEquals("description not equal", ret.getDescription(), description);
// endpoint
assertEquals("endpointProtocol not equal", ret.getEndpointProtocol(), endpointProtocol);
assertEquals("endpointHost not equal", ret.getEndpointHost(), endpointHost);
assertEquals("endpointPort not equal", ret.getEndpointPort(), endpointPort);
assertEquals("endpointPath not equal", ret.getEndpointPath(), endpointPath);
// authentication
assertEquals("username not equal", ret.getUsername(), username);
char[] password2 = ret.getPassword();
assertEquals(password.length, password2.length);
for (int i = 0; i < password.length; i++) {
if (password[i] != password2[i]) {
fail("password not equal:" + new String(password) + new String(password2));
}
}
/**
* Negative test - try to create a transfer target with a name that's already used.
*/
try {
transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
fail("duplicate name not detected");
} catch (TransferException e) {
// expect to go here
}
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class TransferServiceImplTest method createTransferTarget.
// testCategoriesAndTags
// Utility methods below.
private TransferTarget createTransferTarget(String name) {
String title = "title";
String description = "description";
String endpointProtocol = "http";
String endpointHost = "MARKR02";
int endpointPort = 7080;
String endpointPath = "/alfresco/service/api/transfer";
String username = "admin";
char[] password = "admin".toCharArray();
/**
* Now go ahead and create our first transfer target
*/
TransferTarget target = transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
return target;
}
Aggregations