mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-15 15:02:20 +00:00
Merged DEV to 5.2.N (5.2.1)
131050 skopf: REPO-483 - The repository does not contain any code or data related to JBPM / ACE-1659 - Remove JBPM and Hibernate 131057 skopf: REPO-483 - The repository does not contain any code or data related to JBPM / ACE-1659 - Remove JBPM and Hibernate / fix test CMISTest.testModelAvailability 131064 skopf: REPO-483 - The repository does not contain any code or data related to JBPM / ACE-1659 - Remove JBPM and Hibernate - added patch to remove JBPM database tables 131169 skopf: REPO-483 - The repository does not contain any code or data related to JBPM / ACE-1659 - Remove JBPM and Hibernate - replaced generic DB script with database specific scripts 131171 skopf: REPO-483 - The repository does not contain any code or data related to JBPM / ACE-1659 - Remove JBPM and Hibernate - Fix DB2 patch 131213 skopf: REPO-483 - The repository does not contain any code or data related to JBPM / ACE-1659 - Remove JBPM and Hibernate - Fix JBPM table removal patch git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131286 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,11 +26,8 @@
|
||||
|
||||
package org.alfresco.repo.workflow;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.repo.workflow.jbpm.WorkflowTaskInstance;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
|
||||
public class WorkflowSuiteContextShutdownTest extends TestCase
|
||||
@@ -49,11 +46,6 @@ public class WorkflowSuiteContextShutdownTest extends TestCase
|
||||
public static void closeContext() throws NoSuchFieldException, IllegalAccessException, InterruptedException
|
||||
{
|
||||
ApplicationContextHelper.closeApplicationContext();
|
||||
|
||||
// Null out the static Workflow engine field
|
||||
Field engineField = WorkflowTaskInstance.class.getDeclaredField("jbpmEngine");
|
||||
engineField.setAccessible(true);
|
||||
engineField.set(null, null);
|
||||
|
||||
Thread.yield();
|
||||
Thread.sleep(25);
|
||||
|
@@ -70,7 +70,6 @@ public class WorkflowTestSuite extends TestSuite
|
||||
// ActivitiTaskComponentTest
|
||||
// ActivitiWorkflowComponentTest
|
||||
// ActivitiWorkflowRestApiTest
|
||||
// JbpmWorkflowRestApiTest
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
@@ -1,341 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.scripts.ScriptException;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.BaseAlfrescoSpringTest;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.jbpm.context.exe.ContextInstance;
|
||||
import org.jbpm.graph.exe.ExecutionContext;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
|
||||
{
|
||||
private static final QName fooName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Foo");
|
||||
private static final QName barName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Bar");
|
||||
private static final QName docName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Doc");
|
||||
private static final String BASIC_USER = "basic"+GUID.generate();
|
||||
private static String systemUser = AuthenticationUtil.getSystemUserName();
|
||||
|
||||
private ServiceRegistry services;
|
||||
private ExecutionContext context;
|
||||
private HashMap<String, Object> variables;
|
||||
private PersonService personService;
|
||||
private Repository repository;
|
||||
|
||||
/**
|
||||
* Test that JavaScript can still be run even if no Authentication is provided.
|
||||
* This can occur if, e.g. the action is executed as part of an asynchronous task.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunsWithoutAuthentication() throws Exception
|
||||
{
|
||||
NodeRef systemNode = personService.getPerson(systemUser);
|
||||
NodeRef baseUserNode = personService.getPerson(BASIC_USER);
|
||||
TestUserStore userStore = new TestUserStore();
|
||||
variables.put("userStore", userStore);
|
||||
Element script = buildScript("userStore.storeUsers(person)");
|
||||
|
||||
// Check authentication cleared.
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
|
||||
// Check uses system user when no authentication set and no task assignee.
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(systemUser, userStore.runAsUser);
|
||||
assertEquals(systemUser, userStore.fullUser);
|
||||
assertEquals(systemNode, userStore.person.getNodeRef());
|
||||
|
||||
// Check authentication is correctly reset.
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
|
||||
// Check that when a task assignee exists, then he/she is used for authentication.
|
||||
TaskInstance taskInstance = mock(TaskInstance.class);
|
||||
when(taskInstance.getActorId()).thenReturn(BASIC_USER);
|
||||
when(context.getTaskInstance()).thenReturn(taskInstance);
|
||||
scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(BASIC_USER, userStore.runAsUser);
|
||||
assertEquals(BASIC_USER, userStore.fullUser);
|
||||
assertEquals(baseUserNode, userStore.person.getNodeRef());
|
||||
|
||||
// Check authentication is correctly reset.
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* See Jira issue ALF-657.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunAsAdminMoveContent() throws Exception
|
||||
{
|
||||
NodeRef fooFolder = nodeService.createNode(rootNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
fooName,
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
|
||||
NodeRef barFolder = nodeService.createNode(rootNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
barName,
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
|
||||
NodeRef doc = nodeService.createNode(fooFolder,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
docName,
|
||||
ContentModel.TYPE_CONTENT).getChildRef();
|
||||
PermissionService permissions = services.getPermissionService();
|
||||
permissions.setPermission(doc, BASIC_USER, PermissionService.ALL_PERMISSIONS, true);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(BASIC_USER);
|
||||
|
||||
Element script = buildScript("doc.move(bar)");
|
||||
|
||||
variables.put("doc", new JBPMNode(doc, services));
|
||||
variables.put("bar", new JBPMNode(barFolder, services));
|
||||
assertEquals(fooFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
try
|
||||
{
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
fail("The user should not have permission to write to bar!");
|
||||
}
|
||||
catch (ScriptException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
assertEquals(fooFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.setRunas(AuthenticationUtil.getAdminUserName());
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(barFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* See Jira issue ALF-5346.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunAsAdminMoveContentBetweenSites() throws Exception
|
||||
{
|
||||
SiteService siteService = services.getSiteService();
|
||||
FileFolderService fileFolderService = services.getFileFolderService();
|
||||
|
||||
String siteAName = "siteA"+GUID.generate();
|
||||
String siteBName = "siteB"+GUID.generate();
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
siteService.createSite(
|
||||
"testSitePreset", siteAName, "title", "description", SiteVisibility.PRIVATE);
|
||||
|
||||
siteService.createSite(
|
||||
"testSitePreset", siteBName, "title", "description", SiteVisibility.PRIVATE);
|
||||
|
||||
NodeRef docLibA = siteService.createContainer(siteAName, "documentLibrary", ContentModel.TYPE_FOLDER, null);
|
||||
NodeRef docLibB = siteService.createContainer(siteBName, "documentLibrary", ContentModel.TYPE_FOLDER, null);
|
||||
|
||||
FileInfo docInfo = fileFolderService.create(docLibA, "test.txt", ContentModel.TYPE_CONTENT);
|
||||
NodeRef doc = docInfo.getNodeRef();
|
||||
ContentWriter writer = fileFolderService.getWriter(doc);
|
||||
writer.putContent("Just some old content that doesn't mean anything");
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(BASIC_USER);
|
||||
|
||||
Element script = buildScript("doc.move(companyhome.childByNamePath(\"Sites/"+ siteBName +"/documentLibrary\"))");
|
||||
|
||||
NodeRef companyHome = repository.getCompanyHome();
|
||||
variables.put("companyhome", new JBPMNode(companyHome, services));
|
||||
variables.put("doc", new JBPMNode(doc, services));
|
||||
assertEquals(docLibA, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
try
|
||||
{
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
fail("The user should not have permission to write to Site B!");
|
||||
} catch(ScriptException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
assertEquals(docLibA, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.setRunas(AuthenticationUtil.getAdminUserName());
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(docLibB, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
}
|
||||
|
||||
public void testScopeVariables() throws Exception
|
||||
{
|
||||
String admin = AuthenticationUtil.getAdminUserName();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(admin);
|
||||
NodeRef person = personService.getPerson(admin);
|
||||
Serializable userHome = nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
|
||||
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
String key = "result";
|
||||
|
||||
// Check person node set.
|
||||
Element script = buildScript("executionContext.setVariable('" + key + "', person)");
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
ScriptNode value = (ScriptNode) variables.get(key);
|
||||
assertEquals(person, value.getNodeRef());
|
||||
|
||||
// Check user home set.
|
||||
script = buildScript("executionContext.setVariable('" + key + "', userhome)");
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
value = (ScriptNode) variables.get(key);
|
||||
assertEquals(userHome, value.getNodeRef());
|
||||
|
||||
// Check company home set.
|
||||
NodeRef companyHome = repository.getCompanyHome();
|
||||
script = buildScript("executionContext.setVariable('" + key + "', companyhome)");
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
value = (ScriptNode) variables.get(key);
|
||||
assertEquals(companyHome, value.getNodeRef());
|
||||
}
|
||||
|
||||
private Element buildScript(String expression)
|
||||
{
|
||||
Element script = DocumentHelper.createElement("script");
|
||||
script.setText(expression);
|
||||
return script;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void onSetUp() throws Exception
|
||||
{
|
||||
super.onSetUp();
|
||||
|
||||
this.services = (ServiceRegistry) applicationContext.getBean("ServiceRegistry");
|
||||
repository = (Repository) applicationContext.getBean("repositoryHelper");
|
||||
personService = services.getPersonService();
|
||||
createUser(BASIC_USER);
|
||||
|
||||
// Sets up the Execution Context
|
||||
context = mock(ExecutionContext.class);
|
||||
ContextInstance contextInstance = mock(ContextInstance.class);
|
||||
when(context.getContextInstance()).thenReturn(contextInstance);
|
||||
variables = new HashMap<String, Object>();
|
||||
when(contextInstance.getVariables()).thenReturn(variables);
|
||||
when(contextInstance.getVariables( any(Token.class))).thenReturn(variables);
|
||||
when(context.getVariable(anyString())).thenAnswer(new Answer<Object>()
|
||||
{
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
String key = (String)invocation.getArguments()[0];
|
||||
return variables.get(key);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
String key = (String)invocation.getArguments()[0];
|
||||
Object value= invocation.getArguments()[1];
|
||||
variables.put(key, value);
|
||||
return null;
|
||||
}
|
||||
}).when(context).setVariable(anyString(), any());
|
||||
}
|
||||
|
||||
private void createUser(String userName)
|
||||
{
|
||||
if (this.authenticationService.authenticationExists(userName) == false)
|
||||
{
|
||||
this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
|
||||
|
||||
PropertyMap ppOne = new PropertyMap(4);
|
||||
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
||||
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
|
||||
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
|
||||
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
|
||||
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
|
||||
personService.createPerson(ppOne);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestUserStore
|
||||
{
|
||||
private String runAsUser;
|
||||
private String fullUser;
|
||||
private ScriptNode person = null;
|
||||
|
||||
public void storeUsers(ScriptNode user)
|
||||
{
|
||||
fullUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
runAsUser = AuthenticationUtil.getRunAsUser();
|
||||
this.person = user;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* This test shows a performance benefit from a usage of direct queries
|
||||
* instead of creating required classes like WorkflowTask in a loop with collecting
|
||||
* required properties from different services.
|
||||
*
|
||||
* @author arsenyko
|
||||
*
|
||||
*/
|
||||
public class JBPMJunit4LoadTests extends BaseSpringTest
|
||||
{
|
||||
|
||||
private static String WORKFLOW_NAME = "jbpm$wf:adhoc";
|
||||
private static String WORKFLOW_NODE_NAME = "workflow-test-19243cbb-c58a-485e-bcd9-2e2be030dfb9.txt";
|
||||
private static int WORKFLOW_COUNT = 2000;
|
||||
|
||||
private static List<String> workflowIds = null;
|
||||
private static NodeRef rootNode = null;
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private RetryingTransactionHelper retryingTransactionHelper;
|
||||
private static NodeService nodeService;
|
||||
private static WorkflowService workflowService;
|
||||
private FileFolderService fileFolderService;
|
||||
|
||||
private Repository repositoryHelper;
|
||||
|
||||
private JBPMEngine jbpmEngine;
|
||||
|
||||
private NodeRef companyHomeNodeRef;
|
||||
|
||||
public void onSetUp() throws Exception
|
||||
{
|
||||
serviceRegistry = (ServiceRegistry) getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
repositoryHelper = (Repository) getApplicationContext().getBean("repositoryHelper");
|
||||
jbpmEngine = (JBPMEngine) getApplicationContext().getBean("jbpm_engine");
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
|
||||
fileFolderService = serviceRegistry.getFileFolderService();
|
||||
workflowService = serviceRegistry.getWorkflowService();
|
||||
nodeService = serviceRegistry.getNodeService();
|
||||
|
||||
companyHomeNodeRef = repositoryHelper.getCompanyHome();
|
||||
System.out.println(" -------------- ");
|
||||
createWorkflowStuff();
|
||||
}
|
||||
|
||||
public void createWorkflowStuff() throws Exception
|
||||
{
|
||||
System.out.println(" [createWorkflowStuff] Started at " + new Date().toString());
|
||||
|
||||
if (rootNode == null)
|
||||
{
|
||||
workflowIds =new ArrayList<String>();
|
||||
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>(){
|
||||
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
FileInfo rootInfo = fileFolderService.create(companyHomeNodeRef,
|
||||
WORKFLOW_NODE_NAME,
|
||||
ContentModel.TYPE_FOLDER);
|
||||
rootNode = rootInfo.getNodeRef();
|
||||
FileInfo contentInfo = fileFolderService.create(rootNode,
|
||||
WORKFLOW_NODE_NAME,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
NodeRef content = contentInfo.getNodeRef();
|
||||
ContentService contentService = serviceRegistry.getContentService();
|
||||
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype("text/plain");
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.putContent("many workflows many workflows many workflows many workflows many workflows many workflows many workflows many workflows");
|
||||
System.out.println(" [createWorkflowStuff] Workflow root node '" + WORKFLOW_NODE_NAME + "' has been created");
|
||||
|
||||
WorkflowDefinition wfDef = jbpmEngine.getDefinitionByName(WORKFLOW_NAME);
|
||||
long startTime = new Date().getTime();
|
||||
for (Integer i = 0; i < WORKFLOW_COUNT; i++)
|
||||
{
|
||||
// We are creating workflows in usual way, but with new persistent objects.
|
||||
// There is a some performance issue with sesssion.flash() in each iteration,
|
||||
// but this was made to avoid a lot of changes in a logic related to org.alfresco.service.cmr.workflow.*
|
||||
// classes.
|
||||
Map<QName, Serializable> properties = prepareWorkflowProperties(rootNode, content, i.toString());
|
||||
WorkflowPath path = workflowService.startWorkflow(wfDef.getId(), properties);
|
||||
workflowIds.add(path.getInstance().getId());
|
||||
// jbpmEngine.startWorkflow_ALF1787(wfDef.id, prepareWorkflowProperties(fileInfo.getNodeRef(), i.toString()));
|
||||
}
|
||||
long endTime = new Date().getTime();
|
||||
System.out.println(" [createWorkflowStuff] Execution time (ms): " + (endTime - startTime));
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
retryingTransactionHelper.setMaxRetries(1);
|
||||
retryingTransactionHelper.doInTransaction(callback);
|
||||
System.out.println(" [createWorkflowStuff] Finished at " + new Date().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(" [createWorkflowStuff] Workflow node '" + WORKFLOW_NODE_NAME + "' already exists");
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
// public void testQuery1() throws Exception
|
||||
// {
|
||||
// RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>(){
|
||||
//
|
||||
// @Override
|
||||
// public Void execute() throws Throwable
|
||||
// {
|
||||
// JbpmTemplate jbpmTemplate = (JbpmTemplate) applicationContext.getBean("jbpm_template");
|
||||
// List<Object[]> result = (List<Object[]>) jbpmTemplate.execute(new JbpmCallback()
|
||||
// {
|
||||
// public List<Object[]> doInJbpm(JbpmContext context)
|
||||
// {
|
||||
// Session session = context.getSession();
|
||||
// Query query = session.getNamedQuery("org.alfresco.repo.workflow.findTaskInstancesByActorId");
|
||||
// return query.setString("actorId", "admin").list();
|
||||
// }
|
||||
// });
|
||||
// for(Object[] ti : result)
|
||||
// {
|
||||
// System.out.println(Arrays.toString(ti));
|
||||
// }
|
||||
// System.out.println(result.size());
|
||||
// return null;
|
||||
// }
|
||||
// };
|
||||
// retryingTransactionHelper.setMaxRetries(1);
|
||||
// retryingTransactionHelper.doInTransaction(callback);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testGetAssignedTasks_NEW() throws Exception
|
||||
{
|
||||
final int RUN_COUNT = 7;
|
||||
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>(){
|
||||
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
Date beginTime = new Date();
|
||||
System.out.println(" [testGetAssignedTasks_NEW] Started at " + beginTime.toString());
|
||||
List<WorkflowTask> tasks = workflowService.getAssignedTasks("admin", WorkflowTaskState.IN_PROGRESS);
|
||||
Date endTime = new Date();
|
||||
System.out.println(" [testGetAssignedTasks_NEW] Retrieved tasks: " + tasks.size() + " in " + (endTime.getTime() - beginTime.getTime()) + " ms");
|
||||
System.out.println(" [testGetAssignedTasks_NEW] Finished at " + endTime.toString());
|
||||
return null;
|
||||
}
|
||||
};
|
||||
retryingTransactionHelper.setMaxRetries(1);
|
||||
for(int i=0; i<RUN_COUNT; i++)
|
||||
{
|
||||
retryingTransactionHelper.doInTransaction(callback);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
public void testGetAssignedTasks_OLD() throws Exception
|
||||
{
|
||||
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>(){
|
||||
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
Date beginTime = new Date();
|
||||
System.out.println(" [testGetAssignedTasks_OLD] Started at " + beginTime.toString());
|
||||
List<WorkflowTask> tasks = jbpmEngine.getAssignedTasks_OLD("admin", WorkflowTaskState.IN_PROGRESS);
|
||||
Date endTime = new Date();
|
||||
System.out.println(" [testGetAssignedTasks_OLD] Retrieved tasks: " + tasks.size() + " in " + (endTime.getTime() - beginTime.getTime()) + " ms");
|
||||
System.out.println(" [testGetAssignedTasks_OLD] Finished at " + new Date().toString());
|
||||
return null;
|
||||
}
|
||||
};
|
||||
retryingTransactionHelper.setMaxRetries(1);
|
||||
retryingTransactionHelper.doInTransaction(callback);
|
||||
}
|
||||
*/
|
||||
|
||||
public void onTearDown() throws Exception
|
||||
{
|
||||
System.out.println(" -------------- ");
|
||||
}
|
||||
|
||||
private Map<QName, Serializable> prepareWorkflowProperties(NodeRef root, NodeRef content, String id)
|
||||
{
|
||||
NodeRef packageRef = makePackage(root, content, id);
|
||||
Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
|
||||
parameters.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
|
||||
parameters.put(WorkflowModel.ASSOC_ASSIGNEE, "admin");
|
||||
parameters.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Test workflow '" + id + "'");
|
||||
parameters.put(WorkflowModel.PROP_WORKFLOW_DEFINITION_NAME, "test_workflow_" + id);
|
||||
return parameters;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root
|
||||
* @param content
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private NodeRef makePackage(NodeRef root, NodeRef content, String id)
|
||||
{
|
||||
NodeRef container = fileFolderService.create(root, "package"+id, ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
NodeRef packageRef = workflowService.createPackage(container);
|
||||
nodeService.addChild(packageRef, content, ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.DEFAULT_URI, id));
|
||||
return packageRef;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup()
|
||||
{
|
||||
// Clean up workflows
|
||||
if(workflowIds !=null)
|
||||
{
|
||||
for (String wfId : workflowIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
workflowService.cancelWorkflow(wfId);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeService.deleteNode(rootNode);
|
||||
}
|
||||
|
||||
}
|
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.springmodules.workflow.jbpm31.JbpmCallback;
|
||||
import org.springmodules.workflow.jbpm31.JbpmTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* Test Usage of jBPM within Alfresco Spring Context
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class JBPMSpringTest extends BaseSpringTest
|
||||
{
|
||||
JbpmTemplate jbpmTemplate;
|
||||
DescriptorService descriptorService;
|
||||
|
||||
|
||||
//@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
jbpmTemplate = (JbpmTemplate)applicationContext.getBean("jbpm_template");
|
||||
descriptorService = (DescriptorService)applicationContext.getBean("DescriptorService");
|
||||
}
|
||||
|
||||
public void testHelloWorld()
|
||||
throws Exception
|
||||
{
|
||||
deployProcessDefinition();
|
||||
processInstanceIsCreatedWhenUserSubmitsWebappForm();
|
||||
theProcessInstanceContinuesWhenAnAsyncMessageIsReceived();
|
||||
undeployProcessDefinition();
|
||||
}
|
||||
|
||||
private void deployProcessDefinition()
|
||||
{
|
||||
// This test shows a process definition and one execution
|
||||
// of the process definition. The process definition has
|
||||
// 3 nodes: an unnamed start-state, a state 's' and an
|
||||
// end-state named 'end'.
|
||||
final ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
|
||||
"<process-definition name='hello world'>" +
|
||||
" <start-state name='start'>" +
|
||||
" <transition to='s' />" +
|
||||
" </start-state>" +
|
||||
" <node name='s'>" +
|
||||
" <action class='org.alfresco.repo.workflow.jbpm.JBPMTestSpringActionHandler' config-type='bean'>" +
|
||||
" <value>a test value</value>" +
|
||||
" </action>" +
|
||||
" <transition to='end' />" +
|
||||
" </node>" +
|
||||
" <end-state name='end' />" +
|
||||
"</process-definition>"
|
||||
);
|
||||
|
||||
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
context.deployProcessDefinition(processDefinition);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void undeployProcessDefinition()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
graphSession.deleteProcessDefinition(processDefinition.getId());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processInstanceIsCreatedWhenUserSubmitsWebappForm()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// With the processDefinition that we retrieved from the database, we
|
||||
// can create an execution of the process definition just like in the
|
||||
// hello world example (which was without persistence).
|
||||
ProcessInstance processInstance = new ProcessInstance(processDefinition);
|
||||
|
||||
Token token = processInstance.getRootToken();
|
||||
assertEquals("start", token.getNode().getName());
|
||||
// Let's start the process execution
|
||||
token.signal();
|
||||
// Now the process is in the state 's'.
|
||||
assertEquals("s", token.getNode().getName());
|
||||
// Spring based action has been called, check the result by looking at the
|
||||
// process variable set by the action
|
||||
String result = "Repo: " + descriptorService.getServerDescriptor().getVersion() + ", Value: a test value, Node: s, Token: /";
|
||||
assertEquals(result, processInstance.getContextInstance().getVariable("jbpm.test.action.result"));
|
||||
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void theProcessInstanceContinuesWhenAnAsyncMessageIsReceived()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
|
||||
// First, we need to get the process instance back out of the database.
|
||||
// There are several options to know what process instance we are dealing
|
||||
// with here. The easiest in this simple test case is just to look for
|
||||
// the full list of process instances. That should give us only one
|
||||
// result. So let's look up the process definition.
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// Now, we search for all process instances of this process definition.
|
||||
List<?> processInstances = graphSession.findProcessInstances(processDefinition.getId());
|
||||
|
||||
// Because we know that in the context of this unit test, there is
|
||||
// only one execution. In real life, the processInstanceId can be
|
||||
// extracted from the content of the message that arrived or from
|
||||
// the user making a choice.
|
||||
ProcessInstance processInstance = (ProcessInstance) processInstances.get(0);
|
||||
|
||||
// Now we can continue the execution. Note that the processInstance
|
||||
// delegates signals to the main path of execution (=the root token).
|
||||
processInstance.signal();
|
||||
|
||||
// After this signal, we know the process execution should have
|
||||
// arrived in the end-state.
|
||||
assertTrue(processInstance.hasEnded());
|
||||
|
||||
// Now we can update the state of the execution in the database
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import org.alfresco.repo.workflow.AbstractMultitenantWorkflowTest;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class JbpmMultitenantWorkflowTest extends AbstractMultitenantWorkflowTest
|
||||
{
|
||||
@Override
|
||||
protected String getEngine()
|
||||
{
|
||||
return JBPMEngine.ENGINE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_simple_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDefinitionKey()
|
||||
{
|
||||
return "jbpm$test";
|
||||
}
|
||||
|
||||
protected String getAdhocDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/adhoc_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAdhocDefinitionKey()
|
||||
{
|
||||
return "jbpm$wf:adhoc";
|
||||
}
|
||||
|
||||
public void testSetup() throws Exception
|
||||
{
|
||||
// dummy test
|
||||
}
|
||||
}
|
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.workflow.WorkflowAdminServiceImpl;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.repo.workflow.WorkflowTestHelper;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
public class JbpmTimerTest extends TestCase
|
||||
{
|
||||
private static final String simpleDefLocation = "jbpmresources/test_simpleTimer.xml";
|
||||
private static final String exceptionDefLocation = "jbpmresources/test_timerException.xml";
|
||||
|
||||
private WorkflowService workflowService;
|
||||
private WorkflowTestHelper testHelper;
|
||||
private String defId;
|
||||
|
||||
public void testTimerException() throws Exception
|
||||
{
|
||||
defId = deployDefinition(exceptionDefLocation);
|
||||
|
||||
NodeRef pckg = workflowService.createPackage(null);
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, pckg);
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
WorkflowPath path = workflowService.startWorkflow(defId, params);
|
||||
String instanceId = path.getInstance().getId();
|
||||
WorkflowTask start = workflowService.getStartTask(instanceId);
|
||||
workflowService.endTask(start.getId(), null);
|
||||
Thread.sleep(30000);
|
||||
System.out.println("Done!");
|
||||
}
|
||||
|
||||
public void testTimerIsReassignable() throws Exception
|
||||
{
|
||||
defId = deployDefinition(simpleDefLocation);
|
||||
|
||||
NodeRef pckg = workflowService.createPackage(null);
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, pckg);
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
WorkflowPath path = workflowService.startWorkflow(defId, params);
|
||||
String instanceId = path.getInstance().getId();
|
||||
WorkflowTask start = workflowService.getStartTask(instanceId);
|
||||
workflowService.endTask(start.getId(), null);
|
||||
|
||||
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
|
||||
WorkflowTask task = tasks.get(0);
|
||||
assertTrue(workflowService.isTaskReassignable(task, AuthenticationUtil.getAdminUserName()));
|
||||
|
||||
// Wait for timer to end task
|
||||
Thread.sleep(30000);
|
||||
assertFalse(workflowService.isTaskReassignable(task, AuthenticationUtil.getAdminUserName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||
ServiceRegistry services = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
workflowService = services.getWorkflowService();
|
||||
WorkflowAdminServiceImpl adminService = (WorkflowAdminServiceImpl) ctx.getBean(WorkflowAdminServiceImpl.NAME);
|
||||
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
testHelper = new WorkflowTestHelper(adminService, JBPMEngine.ENGINE_ID, false);
|
||||
testHelper.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private String deployDefinition(String location)
|
||||
{
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream input = classLoader.getResourceAsStream(exceptionDefLocation);
|
||||
input = classLoader.getResourceAsStream(location);
|
||||
WorkflowDeployment deployment
|
||||
= workflowService.deployDefinition(JBPMEngine.ENGINE_ID, input, MimetypeMap.MIMETYPE_XML);
|
||||
return deployment.getDefinition().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
workflowService.undeployDefinition(defId);
|
||||
testHelper.tearDown();
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
public static void throwException() throws HibernateException
|
||||
{
|
||||
throw new HibernateException("My Timer Exception");
|
||||
}
|
||||
}
|
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.workflow.AbstractWorkflowServiceIntegrationTest;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
/**
|
||||
* JBPM Workflow Service Implementation Tests
|
||||
*
|
||||
* @author Nick Smith
|
||||
* @since 3.4.e
|
||||
*/
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class JbpmWorkflowServiceIntegrationTest extends AbstractWorkflowServiceIntegrationTest
|
||||
{
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void disabledTestAsynchronousTaskExecutes() throws Exception
|
||||
{
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
String defId = null;
|
||||
String instanceId = null;
|
||||
try
|
||||
{
|
||||
WorkflowDefinition def = deployDefinition(getAsyncAdhocPath());
|
||||
defId = def.getId();
|
||||
|
||||
// Create workflow parameters
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
Serializable wfPackage = workflowService.createPackage(null);
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage);
|
||||
Date dueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1);
|
||||
NodeRef assignee = personManager.get(USER2);
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);
|
||||
|
||||
WorkflowPath path = workflowService.startWorkflow(defId, params);
|
||||
instanceId = path.getInstance().getId();
|
||||
|
||||
// End the Start Task.
|
||||
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask startTask = tasks.get(0);
|
||||
workflowService.endTask(startTask.getId(), null);
|
||||
|
||||
// Wait for async execution to occur.
|
||||
Thread.sleep(1000);
|
||||
|
||||
// Should move past the asynchronous adhoc task.
|
||||
tasks = workflowService.getTasksForWorkflowPath(path.getId());
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask endTask = tasks.get(0);
|
||||
assertEquals("wf:completedAdhocTask", endTask.getName());
|
||||
|
||||
// Check async task assigned to USER2
|
||||
tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask adhocTask = tasks.get(0);
|
||||
assertEquals("wf:adhocTask", adhocTask.getName());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(instanceId != null)
|
||||
{
|
||||
workflowService.cancelWorkflow(instanceId);
|
||||
}
|
||||
if(defId != null)
|
||||
{
|
||||
workflowService.undeployDefinition(defId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String getAsyncAdhocPath()
|
||||
{
|
||||
return "jbpmresources/async_adhoc_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getEngine()
|
||||
{
|
||||
return JBPMEngine.ENGINE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_simple_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAdhocDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/adhoc_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPooledReviewDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/review_pooled_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getParallelReviewDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/parallelreview_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestTimerDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_timer.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QName getAdhocProcessName()
|
||||
{
|
||||
return QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "adhoc");
|
||||
}
|
||||
}
|
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.workflow.BPMEngineRegistry;
|
||||
import org.alfresco.repo.workflow.TaskComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.BaseSpringTestsCategory;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
|
||||
/**
|
||||
* Review and Approve workflow specific Tests
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
@Category(BaseSpringTestsCategory.class)
|
||||
public class ReviewAndApproveTest extends BaseSpringTest
|
||||
{
|
||||
AuthenticationComponent authenticationComponent;
|
||||
PersonService personService;
|
||||
WorkflowComponent workflowComponent;
|
||||
TaskComponent taskComponent;
|
||||
WorkflowDefinition testWorkflowDef;
|
||||
NodeRef testNodeRef;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
personService = (PersonService)applicationContext.getBean("personService");
|
||||
BPMEngineRegistry registry = (BPMEngineRegistry)applicationContext.getBean("bpm_engineRegistry");
|
||||
workflowComponent = registry.getWorkflowComponent(JBPMEngine.ENGINE_ID);
|
||||
taskComponent = registry.getTaskComponent(JBPMEngine.ENGINE_ID);
|
||||
|
||||
// deploy latest review and approve process definition
|
||||
ClassPathResource processDef = new ClassPathResource("alfresco/workflow/review_processdefinition.xml");
|
||||
WorkflowDeployment deployment = workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
|
||||
testWorkflowDef = deployment.getDefinition();
|
||||
assertNotNull(testWorkflowDef);
|
||||
|
||||
// run as system
|
||||
authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
|
||||
authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
// get valid node ref
|
||||
NodeService nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
testNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTearDownInTransaction()
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
|
||||
public void testSubmitForReview()
|
||||
{
|
||||
WorkflowDefinition workflowDef = testWorkflowDef;
|
||||
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, testNodeRef);
|
||||
Date reviewDueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, reviewDueDate);
|
||||
NodeRef reviewer = personService.getPerson(AuthenticationUtil.getAdminUserName());
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, reviewer);
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Test review");
|
||||
|
||||
WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
|
||||
assertNotNull(path);
|
||||
List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
|
||||
assertNotNull(tasks1);
|
||||
assertEquals(1, tasks1.size());
|
||||
|
||||
WorkflowTask task = tasks1.get(0);
|
||||
assertTrue(task.getProperties().containsKey(WorkflowModel.ASSOC_PACKAGE));
|
||||
WorkflowTask endedTask = taskComponent.endTask(task.getId(), null);
|
||||
assertNotNull(endedTask);
|
||||
assertTrue(endedTask.getProperties().containsKey(WorkflowModel.PROP_OUTCOME));
|
||||
assertEquals("", endedTask.getProperties().get(WorkflowModel.PROP_OUTCOME));
|
||||
assertEquals("Test review", endedTask.getProperties().get(WorkflowModel.PROP_DESCRIPTION));
|
||||
assertEquals("Test review", endedTask.getPath().getInstance().getDescription());
|
||||
|
||||
List<WorkflowTask> assignedTasks = taskComponent.getAssignedTasks(AuthenticationUtil.getAdminUserName(), WorkflowTaskState.IN_PROGRESS, false);
|
||||
assertNotNull(assignedTasks);
|
||||
assignedTasks = filterTasksByWorkflowInstance(assignedTasks, path.getInstance().getId());
|
||||
|
||||
assertEquals(testNodeRef, assignedTasks.get(0).getProperties().get(WorkflowModel.ASSOC_PACKAGE));
|
||||
assertEquals(reviewDueDate, assignedTasks.get(0).getProperties().get(WorkflowModel.PROP_DUE_DATE));
|
||||
}
|
||||
|
||||
public void testCompletedItems()
|
||||
{
|
||||
WorkflowDefinition workflowDef = testWorkflowDef;
|
||||
|
||||
List<NodeRef> nodeRefs = new ArrayList<NodeRef>();
|
||||
nodeRefs.add(testNodeRef);
|
||||
nodeRefs.add(testNodeRef);
|
||||
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, testNodeRef);
|
||||
params.put(WorkflowModel.PROP_COMPLETED_ITEMS, (Serializable)nodeRefs);
|
||||
Date reviewDueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, reviewDueDate);
|
||||
NodeRef reviewer = personService.getPerson(AuthenticationUtil.getAdminUserName());
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, reviewer);
|
||||
|
||||
WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
|
||||
assertNotNull(path);
|
||||
List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
|
||||
assertNotNull(tasks1);
|
||||
assertEquals(1, tasks1.size());
|
||||
|
||||
WorkflowTask task = tasks1.get(0);
|
||||
assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_COMPLETED_ITEMS));
|
||||
assertEquals(2, ((List<?>)task.getProperties().get(WorkflowModel.PROP_COMPLETED_ITEMS)).size());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter task list by workflow instance
|
||||
*
|
||||
* @param tasks
|
||||
* @param workflowInstanceId
|
||||
* @return
|
||||
*/
|
||||
private List<WorkflowTask> filterTasksByWorkflowInstance(List<WorkflowTask> tasks, String workflowInstanceId)
|
||||
{
|
||||
List<WorkflowTask> filteredTasks = new ArrayList<WorkflowTask>();
|
||||
for (WorkflowTask task : tasks)
|
||||
{
|
||||
if (task.getPath().getInstance().getId().equals(workflowInstanceId))
|
||||
{
|
||||
filteredTasks.add(task);
|
||||
}
|
||||
}
|
||||
return filteredTasks;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user