Search in sources :

Example 1 with ClasspathScriptLocation

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

the class ActionTrackingServiceImplTest method testJavascriptAPI.

public void testJavascriptAPI() throws Exception {
    // We need a background action to sleep for long enough for
    // it still to be running when the JS fires off
    final SleepActionExecuter sleepActionExec = (SleepActionExecuter) ctx.getBean(SleepActionExecuter.NAME);
    sleepActionExec.setSleepMs(2000);
    ActionImpl sleepAction;
    ActionImpl action;
    // Create three test actions:
    ((ActionTrackingServiceImpl) actionTrackingService).resetNextExecutionId();
    // Sleep one that will still be running
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    sleepAction = (ActionImpl) createWorkingSleepAction(null);
    // This isn't true!
    sleepAction.setNodeRef(nodeRef);
    this.actionService.executeAction(sleepAction, null, false, true);
    txn.commit();
    // Move one that will appear to be "running"
    action = (ActionImpl) createFailingMoveAction();
    actionTrackingService.recordActionExecuting(action);
    // Finally one that has "failed"
    // (Shouldn't show up in any lists)
    txn = transactionService.getUserTransaction();
    txn.begin();
    action = (ActionImpl) createWorkingSleepAction(null);
    action.setExecutionStartDate(new Date(1234));
    action.setExecutionEndDate(new Date(54321));
    action.setExecutionStatus(ActionStatus.Failed);
    this.actionService.saveAction(this.nodeRef, action);
    txn.commit();
    // Call the test
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("NodeRef", nodeRef.toString());
    model.put("SleepAction", sleepAction);
    ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/action/script/test_actionTrackingService.js");
    this.scriptService.executeScript(location, model);
}
Also used : UserTransaction(javax.transaction.UserTransaction) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) HashMap(java.util.HashMap) SleepActionExecuter(org.alfresco.repo.action.ActionServiceImplTest.SleepActionExecuter) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) Date(java.util.Date)

Example 2 with ClasspathScriptLocation

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

the class ActivityServiceImplTest method testJSAPI.

public void testJSAPI() throws Exception {
    ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/activities/script/test_activityService.js");
    String result = (String) this.scriptService.executeScript(location, new HashMap<String, Object>(0));
    // Check the result and fail if message returned
    if (result != null && result.length() != 0) {
        fail("The activity service test JS script failed: " + result);
    }
}
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)

Example 3 with ClasspathScriptLocation

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

the class FormServiceImplTest method testJavascriptAPI.

@Test
public void testJavascriptAPI() throws Exception {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("testDoc", this.document.toString());
    model.put("testDocName", this.documentName);
    model.put("testAssociatedDoc", this.associatedDoc.toString());
    model.put("folder", this.folder.toString());
    model.put("folderName", this.folderName);
    ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/forms/script/test_formService.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)

Example 4 with ClasspathScriptLocation

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

the class SiteServiceImplTest method testJSAPI.

// == Test the JavaScript API ==
@Test
public void testJSAPI() throws Exception {
    // Create a site with a custom property
    SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteWithCustomProperty", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
    NodeRef siteNodeRef = siteInfo.getNodeRef();
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
    properties.put(QName.createQName(SiteModel.SITE_CUSTOM_PROPERTY_URL, "additionalInformation"), "information");
    this.nodeService.addAspect(siteNodeRef, QName.createQName(SiteModel.SITE_MODEL_URL, "customSiteProperties"), properties);
    // Create a model to pass to the unit test scripts
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("customSiteName", "mySiteWithCustomProperty");
    model.put("preexistingSiteCount", siteService.listSites(null, null).size());
    // Execute the unit test script
    ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/site/script/test_siteService.js");
    this.scriptService.executeScript(location, model);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 5 with ClasspathScriptLocation

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

the class TaggingServiceImplTest method testTagScopeIfUrlNull.

/**
 * ALF-21875
 */
@Test
public void testTagScopeIfUrlNull() {
    TagScopePropertyMethodInterceptor.setEnabled(Boolean.TRUE);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    String siteName = GUID.generate();
    this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @SuppressWarnings("unchecked")
        @Override
        public Void execute() throws Throwable {
            // STEP1 CreateSite
            SiteInfo siteInfo = createSite(siteName, "doclib", SiteVisibility.PUBLIC);
            // STEP2 upload a document in documentLibrary
            NodeRef documentLibraryOfSite = siteService.getContainer(siteInfo.getShortName(), "doclib");
            NodeRef containerTagScope = fileFolderService.create(documentLibraryOfSite, "containerTagScope" + GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
            // STEP4 create tag
            String tagName = GUID.generate();
            taggingService.createTag(storeRef, tagName);
            // Add some tag scopes
            taggingService.addTagScope(containerTagScope);
            NodeRef file = fileFolderService.create(containerTagScope, "_test_" + GUID.generate() + ".text", ContentModel.TYPE_CONTENT).getNodeRef();
            taggingService.addTag(file, tagName);
            fileFolderService.delete(file);
            return null;
        }
    });
    this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @SuppressWarnings("unchecked")
        @Override
        public Void execute() throws Throwable {
            // STEP5 start job taggingStartupJobDetail
            // Fire off the quartz bean, this time it can really work
            final UpdateTagScopesActionExecuter updateTagsAction = (UpdateTagScopesActionExecuter) applicationContext.getBean("update-tagscope");
            UpdateTagScopesQuartzJob job = new UpdateTagScopesQuartzJob();
            job.execute(actionService, updateTagsAction);
            return null;
        }
    });
    // STEP6 execute script
    // Create a model to pass to the unit test scripts
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("customSiteName", siteName);
    // Execute the unit test script
    ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/site/script/test_tagScopeALF_21875.js");
    this.scriptService.executeScript(location, model);
    TagScopePropertyMethodInterceptor.setEnabled(Boolean.FALSE);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

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