Search in sources :

Example 6 with ScriptLocation

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));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 7 with ScriptLocation

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));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 8 with ScriptLocation

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) ScriptReplicationDefinition(org.alfresco.repo.replication.script.ScriptReplicationDefinition) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) HashMap(java.util.HashMap) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) ServiceRegistry(org.alfresco.service.ServiceRegistry) ScriptReplicationDefinition(org.alfresco.repo.replication.script.ScriptReplicationDefinition)

Example 9 with ScriptLocation

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);
}
Also used : ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) HashMap(java.util.HashMap) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 10 with ScriptLocation

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);
}
Also used : HashMap(java.util.HashMap) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TransferException(org.alfresco.service.cmr.transfer.TransferException) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) TransferService(org.alfresco.service.cmr.transfer.TransferService) TransferTargetImpl(org.alfresco.repo.transfer.TransferTargetImpl) HashSet(java.util.HashSet) Test(org.junit.Test) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest)

Aggregations

ScriptLocation (org.alfresco.service.cmr.repository.ScriptLocation)11 HashMap (java.util.HashMap)10 ClasspathScriptLocation (org.alfresco.repo.jscript.ClasspathScriptLocation)8 Test (org.junit.Test)7 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Serializable (java.io.Serializable)3 QName (org.alfresco.service.namespace.QName)3 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 BaseSpringTest (org.alfresco.util.BaseSpringTest)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 UserTransaction (javax.transaction.UserTransaction)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 SleepActionExecuter (org.alfresco.repo.action.ActionServiceImplTest.SleepActionExecuter)1 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)1 ScriptReplicationDefinition (org.alfresco.repo.replication.script.ScriptReplicationDefinition)1 AuthenticationComponent (org.alfresco.repo.security.authentication.AuthenticationComponent)1 TransferTargetImpl (org.alfresco.repo.transfer.TransferTargetImpl)1