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);
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations