mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Unit tests for the action tracking service javascript interface (ALF-4505)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22183 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -113,7 +113,7 @@ public class ScriptActionTrackingService extends BaseScopableProcessorExtension
|
||||
ExecutionDetails detail = actionTrackingService.getExecutionDetails(summary);
|
||||
if(detail != null)
|
||||
{
|
||||
details.add( new ScriptExecutionDetails(detail) );
|
||||
details.add( new ScriptExecutionDetails(detail, serviceRegistry) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,9 +22,10 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.repo.jscript.Scopeable;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.ExecutionDetails;
|
||||
import org.alfresco.service.cmr.action.ExecutionSummary;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
@@ -43,10 +44,14 @@ public final class ScriptExecutionDetails implements Serializable, Scopeable
|
||||
|
||||
/** The details we wrap */
|
||||
private ExecutionDetails details;
|
||||
|
||||
public ScriptExecutionDetails(ExecutionDetails details)
|
||||
|
||||
/** Services, used when building Script objects */
|
||||
private ServiceRegistry services;
|
||||
|
||||
public ScriptExecutionDetails(ExecutionDetails details, ServiceRegistry services)
|
||||
{
|
||||
this.details = details;
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
protected ExecutionDetails getExecutionDetails()
|
||||
@@ -67,8 +72,8 @@ public final class ScriptExecutionDetails implements Serializable, Scopeable
|
||||
return details.getExecutionInstance();
|
||||
}
|
||||
|
||||
public NodeRef getPersistedActionRef() {
|
||||
return details.getPersistedActionRef();
|
||||
public ScriptNode getPersistedActionRef() {
|
||||
return new ScriptNode(details.getPersistedActionRef(), services);
|
||||
}
|
||||
|
||||
public String getRunningOn() {
|
||||
|
@@ -0,0 +1,94 @@
|
||||
var sleepActionType = "sleep-action";
|
||||
var moveActionType = "move";
|
||||
|
||||
// Checks the details of one action
|
||||
function testExecutionDetails()
|
||||
{
|
||||
var definitions = actionTrackingService.getExecutingActions(sleepActionType);
|
||||
test.assertEquals(1, definitions.length);
|
||||
|
||||
var definition = definitions[0];
|
||||
test.assertEquals(sleepActionType, definition.actionType);
|
||||
test.assertEquals(1, definition.executionInstance);
|
||||
test.assertEquals(NodeRef, definition.persistedActionRef.nodeRef.toString());
|
||||
test.assertEquals(false, definition.cancelRequested);
|
||||
}
|
||||
|
||||
// Checks that we can list different actions
|
||||
function testGetAllExecuting()
|
||||
{
|
||||
var definitions;
|
||||
definitions = actionTrackingService.getAllExecutingActions();
|
||||
test.assertEquals(2, definitions.length);
|
||||
|
||||
// Check for the two, but be aware that
|
||||
// we don't know what order they'll be in
|
||||
var foundSleep = false;
|
||||
var foundMove = false;
|
||||
|
||||
for(var i in definitions)
|
||||
{
|
||||
var definition = definitions[i];
|
||||
if(definition.actionType == sleepActionType)
|
||||
{
|
||||
foundSleep = true;
|
||||
}
|
||||
if(definition.actionType == moveActionType)
|
||||
{
|
||||
foundMove = true;
|
||||
}
|
||||
}
|
||||
|
||||
test.assertEquals(true, foundSleep);
|
||||
test.assertEquals(true, foundMove);
|
||||
}
|
||||
|
||||
// Test we can fetch by type
|
||||
function testGetOfType()
|
||||
{
|
||||
var definitions;
|
||||
|
||||
// By name
|
||||
definitions = actionTrackingService.getExecutingActions(sleepActionType);
|
||||
test.assertEquals(1, definitions.length);
|
||||
test.assertEquals(sleepActionType, definitions[0].actionType);
|
||||
|
||||
definitions = actionTrackingService.getExecutingActions(moveActionType);
|
||||
test.assertEquals(1, definitions.length);
|
||||
test.assertEquals(moveActionType, definitions[0].actionType);
|
||||
|
||||
definitions = actionTrackingService.getExecutingActions("MADE UP");
|
||||
test.assertEquals(0, definitions.length);
|
||||
|
||||
// By action
|
||||
definitions = actionTrackingService.getExecutingActions(SleepAction);
|
||||
test.assertEquals(1, definitions.length);
|
||||
test.assertEquals(sleepActionType, definitions[0].actionType);
|
||||
}
|
||||
|
||||
// Test the we can request the cancellation
|
||||
function testCancel()
|
||||
{
|
||||
// Check
|
||||
var definitions = actionTrackingService.getExecutingActions(sleepActionType);
|
||||
test.assertEquals(1, definitions.length);
|
||||
|
||||
var definition = definitions[0];
|
||||
test.assertEquals(false, definition.cancelRequested);
|
||||
|
||||
// Cancel
|
||||
actionTrackingService.requestActionCancellation(definition);
|
||||
|
||||
// Ensure it worked
|
||||
definitions = actionTrackingService.getExecutingActions(sleepActionType);
|
||||
test.assertEquals(1, definitions.length);
|
||||
|
||||
definition = definitions[0];
|
||||
test.assertEquals(true, definition.cancelRequested);
|
||||
}
|
||||
|
||||
// Execute Tests
|
||||
testExecutionDetails();
|
||||
testGetAllExecuting();
|
||||
testGetOfType();
|
||||
testCancel();
|
Reference in New Issue
Block a user