Replication service JS API unit tests (ALF-4505)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22225 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2010-09-03 11:48:06 +00:00
parent 58c507836e
commit c1068b0b0c
3 changed files with 81 additions and 7 deletions

View File

@@ -103,6 +103,8 @@ public class ScriptReplicationService extends BaseScopableProcessorExtension
public ScriptReplicationDefinition loadReplicationDefinition(String replicationName)
{
ReplicationDefinition replicationDefinition = replicationService.loadReplicationDefinition(replicationName);
if(replicationDefinition == null)
return null;
return new ScriptReplicationDefinition(serviceRegistry, replicationService, this.getScope(), replicationDefinition);
}
@@ -117,6 +119,11 @@ public class ScriptReplicationService extends BaseScopableProcessorExtension
List<ReplicationDefinition> definitions = replicationService.loadReplicationDefinitions(targetName);
return toScriptReplicationDefinitions(definitions);
}
public void replicate(ScriptReplicationDefinition definition)
{
replicationService.replicate(definition.getReplicationDefinition());
}
private ScriptReplicationDefinition[] toScriptReplicationDefinitions(List<ReplicationDefinition> definitions)
{

View File

@@ -10,7 +10,7 @@ function testReplicationDefinition()
// Check the persisted one
test.assertEquals(PersistedName, Persisted.replicationName);
test.assertEquals("Persisted", Persisted.description);
test.assertEquals("TestTransferTarget", Persisted.targetName);
test.assertEquals(PersistedTarget, Persisted.targetName);
test.assertEquals(2, Persisted.payload.length);
test.assertEquals("workspace://SpacesStore/Testing", Persisted.payload[0].nodeRef.toString())
@@ -20,7 +20,49 @@ function testReplicationDefinition()
// Test listing
function testListing()
{
// TODO
// All
var definitions = replicationService.loadReplicationDefinitions();
test.assertEquals(2, definitions.length);
var foundP1 = false;
var foundP2 = false;
for(var i in definitions)
{
var definition = definitions[i];
if(definition.replicationName == PersistedName)
{
foundP1 = true;
test.assertEquals(PersistedName, definition.replicationName);
test.assertEquals("Persisted", definition.description);
test.assertEquals(PersistedTarget, 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())
}
if(definition.replicationName == Persisted2Name)
{
foundP2 = true;
test.assertEquals(Persisted2Name, definition.replicationName);
test.assertEquals("Persisted2", definition.description);
test.assertEquals(Persisted2Target, definition.targetName);
test.assertEquals(0, definition.payload.length);
}
}
// By target - for Persisted
definitions = replicationService.loadReplicationDefinitions(PersistedTarget);
test.assertEquals(1, definitions.length);
test.assertEquals(PersistedName, definitions[0].replicationName);
// By target - for Persisted2
definitions = replicationService.loadReplicationDefinitions(Persisted2Target);
test.assertEquals(1, definitions.length);
test.assertEquals(Persisted2Name, definitions[0].replicationName);
// By target - invalid target
definitions = replicationService.loadReplicationDefinitions("MadeUpDoesntExit");
test.assertEquals(0, definitions.length);
}
// Test creating and saving
@@ -40,10 +82,15 @@ function testCreateSave()
]
definition.payload = nodes
// Save
// Won't be there if loaded
test.assertEquals(null, replicationService.loadReplicationDefinition("JS"));
// Save it
replicationService.saveReplicationDefinition(definition);
// Load and re-check
definition = replicationService.loadReplicationDefinition("JS");
test.assertNotNull(definition);
test.assertEquals("JS", definition.replicationName);
test.assertEquals("From JS", definition.description);
test.assertEquals("TargetTarget", definition.targetName);
@@ -53,10 +100,20 @@ function testCreateSave()
test.assertEquals("workspace://SpacesStore/Testing2", definition.payload[1].nodeRef.toString())
}
// Tests running (without a full definition)
// Tests running (without a full definition, so should quickly fail)
function testRunReplication()
{
// TODO
var definition = replicationService.loadReplicationDefinition(Persisted2Name);
test.assertNotNull(definition);
// Should give an error about no payload
try {
replicationService.replicate(definition);
test.fail("Shouldn't be able to run a definition lacking a payload");
} catch(err) {
var msg = err.message;
test.assertTrue(msg.indexOf("payload") > -1, "Payload error not found in " + msg);
}
}
// Execute Tests