mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Start on Replication Service JS API unit tests (more still to test though) - ALF-4505
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22208 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -33,8 +33,10 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.repo.jscript.ClasspathScriptLocation;
|
||||
import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.replication.script.ScriptReplicationDefinition;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.repo.transfer.TransferServiceImpl;
|
||||
@@ -42,6 +44,7 @@ import org.alfresco.repo.transfer.TransferTransmitter;
|
||||
import org.alfresco.repo.transfer.UnitTestInProcessTransmitterImpl;
|
||||
import org.alfresco.repo.transfer.UnitTestTransferManifestNodeFactory;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.action.ActionStatus;
|
||||
import org.alfresco.service.cmr.action.ActionTrackingService;
|
||||
@@ -58,6 +61,8 @@ import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.cmr.repository.ScriptLocation;
|
||||
import org.alfresco.service.cmr.repository.ScriptService;
|
||||
import org.alfresco.service.cmr.transfer.TransferDefinition;
|
||||
import org.alfresco.service.cmr.transfer.TransferException;
|
||||
import org.alfresco.service.cmr.transfer.TransferReceiver;
|
||||
@@ -88,6 +93,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
private TransferService transferService;
|
||||
private ContentService contentService;
|
||||
private JobLockService jobLockService;
|
||||
private ScriptService scriptService;
|
||||
private ActionService actionService;
|
||||
private NodeService nodeService;
|
||||
private LockService lockService;
|
||||
@@ -127,6 +133,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
contentService = (ContentService) ctx.getBean("contentService");
|
||||
jobLockService = (JobLockService) ctx.getBean("jobLockService");
|
||||
actionService = (ActionService) ctx.getBean("actionService");
|
||||
scriptService = (ScriptService)ctx.getBean("scriptService");
|
||||
nodeService = (NodeService) ctx.getBean("nodeService");
|
||||
lockService = (LockService) ctx.getBean("lockService");
|
||||
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
|
||||
@@ -1135,6 +1142,37 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
assertEquals(ActionStatus.Failed, rd.getExecutionStatus());
|
||||
}
|
||||
|
||||
public void DISABLEDtestJavascriptAPI() throws Exception
|
||||
{
|
||||
ServiceRegistry serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
|
||||
|
||||
// Setup some replication tasks
|
||||
ReplicationDefinition empty = replicationService.createReplicationDefinition(ACTION_NAME, "Empty");
|
||||
|
||||
ReplicationDefinition persisted = replicationService.createReplicationDefinition(ACTION_NAME2, "Persisted");
|
||||
persisted.setTargetName(TRANSFER_TARGET);
|
||||
persisted.getPayload().add(
|
||||
new NodeRef("workspace://SpacesStore/Testing")
|
||||
);
|
||||
persisted.getPayload().add(
|
||||
new NodeRef("workspace://SpacesStore/Testing2")
|
||||
);
|
||||
replicationService.saveReplicationDefinition(persisted);
|
||||
|
||||
// Call the test
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("Empty", new ScriptReplicationDefinition(serviceRegistry, replicationService, null, empty));
|
||||
model.put("EmptyName", ACTION_NAME);
|
||||
model.put("Persisted", new ScriptReplicationDefinition(serviceRegistry, replicationService, null, persisted));
|
||||
model.put("PersistedName", ACTION_NAME2);
|
||||
model.put("PersistedNodeRef", persisted.getNodeRef());
|
||||
|
||||
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/replication/script/test_replicationService.js");
|
||||
this.scriptService.executeScript(location, model);
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
|
||||
private NodeRef makeNode(NodeRef parent, QName nodeType)
|
||||
{
|
||||
|
@@ -24,7 +24,6 @@ import org.alfresco.repo.jscript.ScriptAction;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionDefinition;
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.cmr.replication.ReplicationService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -46,7 +45,7 @@ public final class ScriptReplicationDefinition extends ScriptAction
|
||||
public ScriptReplicationDefinition(ServiceRegistry serviceRegistry, ReplicationService replicationService,
|
||||
Scriptable scope, ReplicationDefinition replicationDefinition)
|
||||
{
|
||||
super(serviceRegistry, (Action)replicationDefinition, (ActionDefinition)replicationDefinition);
|
||||
super(serviceRegistry, (Action)replicationDefinition, null);
|
||||
this.replicationService = replicationService;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,66 @@
|
||||
// Test that we can work with the definition properly
|
||||
function testReplicationDefinition()
|
||||
{
|
||||
// Check the empty one
|
||||
test.assertEquals(EmptyName, Empty.replicationName);
|
||||
test.assertEquals("Empty", Empty.description);
|
||||
test.assertEquals(null, Empty.targetName);
|
||||
test.assertEquals(0, Empty.payload.length);
|
||||
|
||||
// Check the persisted one
|
||||
test.assertEquals(PersistedName, Persisted.replicationName);
|
||||
test.assertEquals("Persisted", Persisted.description);
|
||||
test.assertEquals("TestTransferTarget", Persisted.targetName);
|
||||
test.assertEquals(2, Persisted.payload.length);
|
||||
|
||||
test.assertEquals("workspace://SpacesStore/Testing", Persisted.payload[0].nodeRef.toString())
|
||||
test.assertEquals("workspace://SpacesStore/Testing2", Persisted.payload[1].nodeRef.toString())
|
||||
}
|
||||
|
||||
// Test listing
|
||||
function testListing()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Test creating and saving
|
||||
function testCreateSave()
|
||||
{
|
||||
// Create
|
||||
var definition = replicationService.createReplicationDefinition("JS","From JS");
|
||||
test.assertEquals("JS", definition.replicationName);
|
||||
test.assertEquals("From JS", definition.description);
|
||||
test.assertEquals(null, definition.targetName);
|
||||
test.assertEquals(0, definition.payload.length);
|
||||
|
||||
// Set some bits
|
||||
definition.targetName = "TargetTarget";
|
||||
nodes = [
|
||||
Persisted.payload[0], Persisted.payload[1]
|
||||
]
|
||||
definition.payload = nodes
|
||||
|
||||
// Save
|
||||
|
||||
// Load and re-check
|
||||
definition = replicationService.loadReplicationDefinition("JS");
|
||||
test.assertEquals("JS", definition.replicationName);
|
||||
test.assertEquals("From JS", definition.description);
|
||||
test.assertEquals("TargetTarget", definition.targetName);
|
||||
test.assertEquals(2, definition.payload.length);
|
||||
|
||||
test.assertEquals("workspace://SpacesStore/Testing", definition.payload[0].nodeRef.toString())
|
||||
test.assertEquals("workspace://SpacesStore/Testing2", definition.payload[1].nodeRef.toString())
|
||||
}
|
||||
|
||||
// Tests running (without a full definition)
|
||||
function testRunReplication()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Execute Tests
|
||||
testReplicationDefinition();
|
||||
testListing();
|
||||
testCreateSave();
|
||||
testRunReplication();
|
Reference in New Issue
Block a user