Search in sources :

Example 6 with ClasspathScriptLocation

use of org.alfresco.repo.jscript.ClasspathScriptLocation 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 7 with ClasspathScriptLocation

use of org.alfresco.repo.jscript.ClasspathScriptLocation 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 8 with ClasspathScriptLocation

use of org.alfresco.repo.jscript.ClasspathScriptLocation 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)

Example 9 with ClasspathScriptLocation

use of org.alfresco.repo.jscript.ClasspathScriptLocation in project alfresco-repository by Alfresco.

the class TaggingServiceImplTest method test93JSTagScope.

@Test
@Category({ RedundantTests.class, LuceneTests.class })
public void test93JSTagScope() throws Exception {
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            // Add a load of tags to test the global tag methods with
            taggingService.createTag(storeRef, "alpha");
            taggingService.createTag(storeRef, "alpha double");
            taggingService.createTag(storeRef, "beta");
            taggingService.createTag(storeRef, "gamma");
            taggingService.createTag(storeRef, "delta");
            // Add a load of tags and tag scopes to the object and commit before executing the script
            taggingService.addTagScope(folder);
            taggingService.addTagScope(subFolder);
            taggingService.addTag(subDocument, TAG_1);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            taggingService.addTag(subDocument, TAG_2);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            taggingService.addTag(subDocument, TAG_3);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            taggingService.addTag(subFolder, TAG_1);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            taggingService.addTag(subFolder, TAG_2);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            taggingService.addTag(document, TAG_1);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            taggingService.addTag(document, TAG_2);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            taggingService.addTag(folder, TAG_1);
            return null;
        }
    });
    asyncOccurs.awaitExecution(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            Map<String, Object> model = new HashMap<String, Object>(0);
            model.put("folder", folder);
            model.put("subFolder", subFolder);
            model.put("document", document);
            model.put("subDocument", subDocument);
            model.put("tagScopeTest", true);
            model.put("store", storeRef.toString());
            ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/tagging/script/test_taggingService.js");
            scriptService.executeScript(location, model);
            // Let the script run
            return null;
        }
    });
}
Also used : ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) PropertyMap(org.alfresco.util.PropertyMap) Category(org.junit.experimental.categories.Category) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 10 with ClasspathScriptLocation

use of org.alfresco.repo.jscript.ClasspathScriptLocation in project alfresco-repository by Alfresco.

the class ThumbnailServiceImplTest method testJSAPI.

// == Test the JavaScript API ==
@Test
public void testJSAPI() throws Exception {
    NodeRef jpgOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);
    NodeRef gifOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_GIF);
    NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
    NodeRef docOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_WORD);
    Map<String, Object> model = new HashMap<String, Object>(2);
    model.put("jpgOrig", jpgOrig);
    model.put("gifOrig", gifOrig);
    model.put("pdfOrig", pdfOrig);
    model.put("docOrig", docOrig);
    ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/thumbnail/script/test_thumbnailAPI.js");
    this.scriptService.executeScript(location, model);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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)

Aggregations

ClasspathScriptLocation (org.alfresco.repo.jscript.ClasspathScriptLocation)10 HashMap (java.util.HashMap)8 ScriptLocation (org.alfresco.service.cmr.repository.ScriptLocation)8 Test (org.junit.Test)7 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)2 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)2 BaseSpringTest (org.alfresco.util.BaseSpringTest)2 Serializable (java.io.Serializable)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 UserTransaction (javax.transaction.UserTransaction)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 TransferTargetImpl (org.alfresco.repo.transfer.TransferTargetImpl)1 ServiceRegistry (org.alfresco.service.ServiceRegistry)1 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)1 TransferDefinition (org.alfresco.service.cmr.transfer.TransferDefinition)1