use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class ScriptBehaviourTest method test2ClasspathLocationBehaviour.
@Test
public void test2ClasspathLocationBehaviour() {
// Register the onCreateNode behaviour script
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/jscript/test_onCreateNode_cmContent.js");
ScriptBehaviour behaviour = new ScriptBehaviour(this.serviceRegistry, location);
this.policyComponent.bindClassBehaviour(QName.createQName(NodeServicePolicies.OnCreateNodePolicy.NAMESPACE, "onCreateNode"), ContentModel.TYPE_CONTENT, behaviour);
// Create a content node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "myDoc.txt");
ChildAssociationRef childAssoc = this.nodeService.createNode(this.folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc.txt"), ContentModel.TYPE_CONTENT, props);
// Since the behavoiour will have been run check that the titled aspect has been applied
assertTrue(this.nodeService.hasAspect(childAssoc.getChildRef(), ContentModel.ASPECT_TITLED));
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class ScriptBehaviourTest method test1EnableDisableBehaviour.
@Test
public void test1EnableDisableBehaviour() {
// Register the onCreateNode behaviour script
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/jscript/test_onCreateNode_cmContent.js");
ScriptBehaviour behaviour = new ScriptBehaviour(this.serviceRegistry, location);
this.policyComponent.bindClassBehaviour(QName.createQName(NodeServicePolicies.OnCreateNodePolicy.NAMESPACE, "onCreateNode"), ContentModel.TYPE_CONTENT, behaviour);
behaviour.disable();
// Create a content node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "myDoc.txt");
ChildAssociationRef childAssoc = this.nodeService.createNode(this.folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc.txt"), ContentModel.TYPE_CONTENT, props);
assertFalse(this.nodeService.hasAspect(childAssoc.getChildRef(), ContentModel.ASPECT_TITLED));
behaviour.enable();
Map<QName, Serializable> props2 = new HashMap<QName, Serializable>(1);
props2.put(ContentModel.PROP_NAME, "myDoc1.txt");
ChildAssociationRef childAssoc2 = this.nodeService.createNode(this.folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc1.txt"), ContentModel.TYPE_CONTENT, props2);
assertTrue(this.nodeService.hasAspect(childAssoc2.getChildRef(), ContentModel.ASPECT_TITLED));
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class ReplicationServiceIntegrationTest method testJavascriptAPI.
public void testJavascriptAPI() 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);
ReplicationDefinition persisted2 = replicationService.createReplicationDefinition(ACTION_NAME3, "Persisted2");
persisted2.setTargetName("AnotherTarget");
replicationService.saveReplicationDefinition(persisted2);
// 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().toString());
model.put("PersistedTarget", persisted.getTargetName());
model.put("Persisted2", new ScriptReplicationDefinition(serviceRegistry, replicationService, null, persisted2));
model.put("Persisted2Name", ACTION_NAME3);
model.put("Persisted2NodeRef", persisted2.getNodeRef().toString());
model.put("Persisted2Target", persisted2.getTargetName());
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/replication/script/test_replicationService.js");
this.scriptService.executeScript(location, model);
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testJavascriptAPI.
@Test
public void testJavascriptAPI() throws Exception {
Map<String, Object> model = new HashMap<String, Object>();
model.put("testSourceNode", this.nodeWithImageContent);
model.put("testDocNode", this.nodeWithDocContent);
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/rendition/script/test_renditionService.js");
this.scriptService.executeScript(location, model);
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class ScriptTransferServiceTest method testJSAPI.
// == Test the JavaScript API ==
@Test
public void testJSAPI() throws Exception {
/**
* Prepare some dummy data for tests
*/
TransferTargetImpl dummyTarget = new TransferTargetImpl();
dummyTarget.setName("dummyTarget");
dummyTarget.setNodeRef(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "4"));
Set<TransferTarget> dummyTargets = new HashSet<TransferTarget>();
dummyTargets.add(dummyTarget);
TransferService mockedTransferService = Mockito.mock(TransferService.class);
scriptTransferService.setTransferService(mockedTransferService);
// When the transfer method is called return a node ref - mocks a good call.
// When the transfer method is called with a transfer name of exception - throw a transferException
Mockito.when(mockedTransferService.transfer(Matchers.anyString(), Matchers.isA(TransferDefinition.class))).thenReturn(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "123"));
Mockito.when(mockedTransferService.transfer(Matchers.eq("exception"), Matchers.isA(TransferDefinition.class))).thenThrow(new TransferException("mocked transfer exception"));
// When getTransferTarget called return a TransferTarget
Mockito.when(mockedTransferService.getTransferTarget(Matchers.anyString())).thenReturn(dummyTarget);
Mockito.when(mockedTransferService.getTransferTargets(Matchers.anyString())).thenReturn(dummyTargets);
Mockito.when(mockedTransferService.getTransferTargets()).thenReturn(dummyTargets);
// Execute the unit test script
Map<String, Object> model = new HashMap<String, Object>(1);
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/transfer/script/test_transferService.js");
this.scriptService.executeScript(location, model);
}
Aggregations