提交 c7d5fc29 编写于 作者: M meyerd

ACT-1060 started porting activiti-cdi testsuite to jboss arquillian to be able...

ACT-1060 started porting activiti-cdi testsuite to jboss arquillian to be able to run against both Jboss Weld and Apache OWB
上级 a33b6bd5
......@@ -15,19 +15,152 @@
<version>5.10-SNAPSHOT</version>
</parent>
<profiles>
<profile>
<id>weld-embedded-11</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>2.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>xalan</artifactId>
<groupId>org.apache.xalan</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-bom</artifactId>
<version>1.1.5.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
<profile>
<id>openwebbeans-embedded-1</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-openwebbeans-embedded-1</artifactId>
<version>1.0.0.CR2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-el_2.2_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-validation_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.1_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans</artifactId>
<version>1.1.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
<profile>
<id>distro</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.0.CR7</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -40,16 +173,6 @@
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
......@@ -71,28 +194,4 @@
</plugins>
</build>
<profiles>
<profile>
<id>distro</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
......@@ -46,7 +46,7 @@ public class ProcessVariables {
}
@Produces
@ProcessVariable("")
@ProcessVariable
protected Object getProcessVariable(InjectionPoint ip) {
String processVariableName = getVariableName(ip);
......
......@@ -12,10 +12,9 @@
*/
package org.activiti.cdi.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.enterprise.util.Nonbinding;
import javax.inject.Qualifier;
......@@ -48,8 +47,8 @@ import javax.inject.Qualifier;
* @author Daniel Meyer
*/
@Qualifier
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ProcessVariable {
/**
......
......@@ -38,7 +38,7 @@ public class CompleteTaskInterceptor implements Serializable {
@Inject BusinessProcess businessProcess;
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Throwable {
public Object invoke(InvocationContext ctx) throws Exception {
try {
Object result = ctx.proceed();
......
......@@ -42,7 +42,7 @@ public class StartProcessInterceptor implements Serializable {
@Inject BusinessProcess businessProcess;
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Throwable {
public Object invoke(InvocationContext ctx) throws Exception {
try {
Object result = ctx.proceed();
......@@ -61,7 +61,12 @@ public class StartProcessInterceptor implements Serializable {
return result;
} catch (InvocationTargetException e) {
throw e.getCause();
Throwable cause = e.getCause();
if(cause != null && cause instanceof Exception) {
throw (Exception) cause;
} else {
throw e;
}
} catch (Exception e) {
throw new ActivitiException("Error while starting process using @StartProcess on method '"+ctx.getMethod()+"': " + e.getMessage(), e);
}
......
......@@ -12,6 +12,7 @@
*/
package org.activiti.cdi.impl.util;
import java.lang.reflect.Type;
import java.util.Iterator;
import javax.enterprise.context.spi.CreationalContext;
......@@ -45,7 +46,9 @@ public class ProgrammaticBeanLookup {
}
Bean bean = iter.next();
CreationalContext ctx = bm.createCreationalContext(bean);
return bm.getReference(bean, bean.getBeanClass(), ctx);
// select one beantype randomly. A bean has a non-empty set of beantypes.
Type type = (Type) bean.getTypes().iterator().next();
return bm.getReference(bean, type, ctx);
}
public static <T> T lookup(Class<T> clazz) {
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.impl.context;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.engine.test.Deployment;
/**
*
* @author Daniel Meyer
*/
public class ContextScopingTest extends CdiActivitiTestCase {
@Override
public void beginConversation() {
// do not activate conversation
}
@Override
public void endConversation() {
// do not deactivate conversation
}
@Deployment
public void testFallbackToRequestContext() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
String pid = businessProcess.startProcessByKey("processkey").getId();
assertEquals(pid, businessProcess.getProcessInstanceId());
endRequest();
beginRequest();
// assert that now the process is not associated with the new request.
assertNull(businessProcess.getProcessInstanceId());
runtimeService.deleteProcessInstance(pid, null);
}
}
......@@ -12,24 +12,36 @@
*/
package org.activiti.cdi.test;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.logging.Logger;
import javax.enterprise.inject.spi.BeanManager;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.impl.util.BeanManagerLookup;
import org.activiti.cdi.impl.util.ProgrammaticBeanLookup;
import org.activiti.cdi.test.util.ProcessEngineLookupForTestsuite;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.jboss.weld.context.bound.BoundConversationContext;
import org.jboss.weld.context.bound.BoundRequestContext;
import org.jboss.weld.context.bound.BoundSessionContext;
import org.jboss.weld.context.bound.MutableBoundRequest;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.ProcessEngineImpl;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.jobexecutor.JobExecutor;
import org.activiti.engine.test.ActivitiRule;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Before;
import org.junit.Rule;
import org.junit.runner.RunWith;
/**
* Abstract base class for executing activiti-cdi tests in a Java SE
......@@ -37,185 +49,139 @@ import org.jboss.weld.environment.se.WeldContainer;
*
* @author Daniel Meyer
*/
public abstract class CdiActivitiTestCase extends PluggableActivitiTestCase {
@RunWith(Arquillian.class)
public abstract class CdiActivitiTestCase {
protected Logger logger = Logger.getLogger(getClass().getName());
protected WeldContainer weldContainer;
protected BeanManager beanManager;
protected Weld weld;
// hide from subclasses
private HashMap<String, Object> currentRequestMap;
private HashMap<String, Object> currentSessionMap;
@Override
protected void setUp() throws Exception {
// set the process engine in the TestProcessEngineLookup-bean.
ProcessEngineLookupForTestsuite.processEngine = processEngine;
// bootstrap the CDI container
weld = new Weld();
weldContainer = weld.initialize();
beanManager = weldContainer.getBeanManager();
BeanManagerLookup.localInstance = beanManager;
beginRequest();
beginSession();
beginConversation();
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
.addPackages(true, "org.activiti.cdi")
.addAsManifestResource("META-INF/beans.xml", "beans.xml");
}
public void beginSession() {
currentSessionMap = new HashMap<String, Object>();
beginSession(currentSessionMap);
}
@Rule
public ActivitiRule activitiRule = new ActivitiRule(getBeanInstance(ProcessEngine.class));
public void beginSession(Map<String, Object> sessionDataMap) {
BoundSessionContext sessionContext = getSessionContext();
sessionContext.associate(currentSessionMap);
sessionContext.activate();
if (logger.isLoggable(Level.FINE)) {
logger.fine(" ----------------------------- Started a new Session -----------------------");
}
}
protected BeanManager beanManager;
public void endSession() {
endSession(currentSessionMap);
currentSessionMap = null;
protected ProcessEngine processEngine;
protected FormService formService;
protected HistoryService historyService;
protected IdentityService identityService;
protected ManagementService managementService;
protected RepositoryService repositoryService;
protected RuntimeService runtimeService;
protected TaskService taskService;
protected ProcessEngineConfigurationImpl processEngineConfiguration;
@Before
public void setUp() throws Exception {
beanManager = ProgrammaticBeanLookup.lookup(BeanManager.class);
processEngine = ProgrammaticBeanLookup.lookup(ProcessEngine.class);
processEngineConfiguration = ((ProcessEngineImpl)ProcessEngineLookupForTestsuite.processEngine).getProcessEngineConfiguration();
formService = processEngine.getFormService();
historyService = processEngine.getHistoryService();
identityService = processEngine.getIdentityService();
managementService = processEngine.getManagementService();
repositoryService = processEngine.getRepositoryService();
runtimeService = processEngine.getRuntimeService();
taskService = processEngine.getTaskService();
}
public void endSession(Map<String, Object> sessionDataMap) {
BoundSessionContext sessionContext = getSessionContext();
try {
sessionContext.invalidate();
sessionContext.deactivate();
if (logger.isLoggable(Level.FINE)) {
logger.fine(" ----------------------------- Ended the current Session -----------------------");
}
} finally {
sessionContext.dissociate(sessionDataMap);
}
protected void endConversationAndBeginNew(String processInstanceId) {
getBeanInstance(BusinessProcess.class).associateExecutionById(processInstanceId);
}
public void beginRequest() {
currentRequestMap = new HashMap<String, Object>();
beginRequest(currentRequestMap);
protected <T> T getBeanInstance(Class<T> clazz) {
return ProgrammaticBeanLookup.lookup(clazz);
}
public void beginRequest(Map<String, Object> requestDataStore) {
// Associate the store with the context and acticate the context
BoundRequestContext requestContext = getRequestContext();
requestContext.associate(requestDataStore);
requestContext.activate();
if (logger.isLoggable(Level.FINE)) {
logger.fine(" ----------------------------- Started a new Request -----------------------");
}
protected Object getBeanInstance(String name) {
return ProgrammaticBeanLookup.lookup(name);
}
public void endRequest() {
endRequest(currentRequestMap);
currentRequestMap = null;
}
//////////////////////// copied from AbstractActivitiTestcase
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
public void endRequest(Map<String, Object> requestDataStore) {
BoundRequestContext requestContext = getRequestContext();
try {
requestContext.invalidate();
requestContext.deactivate();
if (logger.isLoggable(Level.FINE)) {
logger.fine(" ----------------------------- Ended the current Request -----------------------");
Timer timer = new Timer();
InteruptTask task = new InteruptTask(Thread.currentThread());
timer.schedule(task, maxMillisToWait);
boolean areJobsAvailable = true;
try {
while (areJobsAvailable && !task.isTimeLimitExceeded()) {
Thread.sleep(intervalMillis);
areJobsAvailable = areJobsAvailable();
}
} catch (InterruptedException e) {
} finally {
requestContext.dissociate(requestDataStore);
timer.cancel();
}
if (areJobsAvailable) {
throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
public void beginConversation() {
if (currentRequestMap == null) {
throw new ActivitiException("Cannot start conversation: no request active.");
}
if(currentSessionMap == null) {
throw new ActivitiException("Cannot start conversation: no session active.");
}
currentSessionMap = new HashMap<String, Object>();
startTransientConversation(currentRequestMap, currentSessionMap);
}
public void endConversation() {
if (currentRequestMap == null) {
throw new ActivitiException("Cannot end conversation: no request active.");
}
if(currentSessionMap == null) {
throw new ActivitiException("Cannot end conversation: no session active.");
}
endOrPassivateConversation(currentRequestMap, currentSessionMap);
} finally {
jobExecutor.shutdown();
}
public void startTransientConversation(Map<String, Object> requestDataStore, Map<String, Object> sessionDataStore) {
resumeOrStartConversation(requestDataStore, sessionDataStore, null);
}
public void resumeOrStartConversation(Map<String, Object> requestDataStore, Map<String, Object> sessionDataStore, String cid) {
BoundConversationContext conversationContext = getConversationContext();
conversationContext.associate(new MutableBoundRequest(requestDataStore, sessionDataStore));
conversationContext.activate(cid);
if (logger.isLoggable(Level.FINE)) {
logger.fine("---------------------------------------- Started a new Conversation -----------------------");
}
}
public void waitForJobExecutorOnCondition(long maxMillisToWait, long intervalMillis, Callable<Boolean> condition) {
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
public void endOrPassivateConversation(Map<String, Object> requestDataStore, Map<String, Object> sessionDataStore) {
BoundConversationContext conversationContext = getConversationContext();
try {
conversationContext.invalidate();
conversationContext.deactivate();
if (logger.isLoggable(Level.FINE)) {
logger.fine("---------------------------------------- Ended the current Conversation -----------------------");
Timer timer = new Timer();
InteruptTask task = new InteruptTask(Thread.currentThread());
timer.schedule(task, maxMillisToWait);
boolean conditionIsViolated = true;
try {
while (conditionIsViolated) {
Thread.sleep(intervalMillis);
conditionIsViolated = !condition.call();
}
} catch (InterruptedException e) {
} catch (Exception e) {
throw new ActivitiException("Exception while waiting on condition: "+e.getMessage(), e);
} finally {
conversationContext.dissociate(new MutableBoundRequest(requestDataStore, sessionDataStore));
}
timer.cancel();
}
@Override
protected void tearDown() throws Exception {
endConversation();
endRequest();
endSession();
// https://issues.jboss.org/browse/WELD-891
weld.shutdown();
if (conditionIsViolated) {
throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
protected void endConversationAndBeginNew() {
endConversation();
beginConversation();
} finally {
jobExecutor.shutdown();
}
protected void endConversationAndBeginNew(String processInstanceId) {
endConversation();
beginConversation();
getBeanInstance(BusinessProcess.class).associateExecutionById(processInstanceId);
}
protected BoundConversationContext getConversationContext() {
return getBeanInstance(BoundConversationContext.class);
public boolean areJobsAvailable() {
return !managementService
.createJobQuery()
.executable()
.list()
.isEmpty();
}
protected BoundSessionContext getSessionContext() {
return getBeanInstance(BoundSessionContext.class);
private static class InteruptTask extends TimerTask {
protected boolean timeLimitExceeded = false;
protected Thread thread;
public InteruptTask(Thread thread) {
this.thread = thread;
}
protected BoundRequestContext getRequestContext() {
return getBeanInstance(BoundRequestContext.class);
public boolean isTimeLimitExceeded() {
return timeLimitExceeded;
}
protected <T> T getBeanInstance(Class<T> clazz) {
return ProgrammaticBeanLookup.lookup(clazz);
public void run() {
timeLimitExceeded = true;
thread.interrupt();
}
protected Object getBeanInstance(String name) {
return ProgrammaticBeanLookup.lookup(name);
}
}
......@@ -10,13 +10,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi;
package org.activiti.cdi.test.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
/**
* @author Daniel Meyer
......@@ -24,6 +30,7 @@ import org.activiti.engine.test.Deployment;
public class BusinessProcessBeanTest extends CdiActivitiTestCase {
/* General test asserting that the business process bean is functional */
@Test
@Deployment
public void test() throws Exception {
......@@ -55,7 +62,8 @@ public class BusinessProcessBeanTest extends CdiActivitiTestCase {
}
@Deployment(resources = "org/activiti/cdi/BusinessProcessBeanTest.test.bpmn20.xml")
@Test
@Deployment(resources = "org/activiti/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testResolveProcessInstanceBean() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
......@@ -75,7 +83,8 @@ public class BusinessProcessBeanTest extends CdiActivitiTestCase {
taskService.complete(taskService.createTaskQuery().singleResult().getId());
}
@Deployment(resources = "org/activiti/cdi/BusinessProcessBeanTest.test.bpmn20.xml")
@Test
@Deployment(resources = "org/activiti/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testResolveTaskBean() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
......
......@@ -10,11 +10,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.annotation;
package org.activiti.cdi.test.api.annotation;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.impl.util.ProgrammaticBeanLookup;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.engine.test.Deployment;
import org.junit.Assert;
import org.junit.Test;
/**
*
......@@ -22,6 +25,7 @@ import org.activiti.engine.test.Deployment;
*/
public class BusinessKeyTest extends CdiActivitiTestCase {
@Test
@Deployment
public void testBusinessKeyInjectable() {
String businessKey = "Activiti";
......@@ -29,8 +33,7 @@ public class BusinessKeyTest extends CdiActivitiTestCase {
getBeanInstance(BusinessProcess.class).associateExecutionById(pid);
// assert that now the businessKey-Bean can be looked up:
assertEquals(businessKey, getBeanInstance("businessKey"));
Assert.assertEquals(businessKey, ProgrammaticBeanLookup.lookup("businessKey"));
}
}
......@@ -10,14 +10,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.annotation;
package org.activiti.cdi.test.api.annotation;
import static org.junit.Assert.assertNull;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.impl.annotation.CompleteTaskInterceptor;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.cdi.test.beans.DeclarativeProcessController;
import org.activiti.cdi.test.impl.beans.DeclarativeProcessController;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
/**
* Testcase for assuring that the {@link CompleteTaskInterceptor} works as
......@@ -27,7 +30,8 @@ import org.activiti.engine.test.Deployment;
*/
public class CompleteTaskTest extends CdiActivitiTestCase {
@Deployment(resources = "org/activiti/cdi/annotation/CompleteTaskTest.bpmn20.xml")
@Test
@Deployment(resources = "org/activiti/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testCompleteTask() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
......
......@@ -10,22 +10,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.annotation;
package org.activiti.cdi.test.api.annotation;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.engine.test.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* @author Daniel Meyer
*/
@RunWith(Arquillian.class)
public class ProcessIdTest extends CdiActivitiTestCase {
@Test
@Deployment
public void testProcessIdInjectable() {
getBeanInstance(BusinessProcess.class).startProcessByKey("keyOfTheProcess");
assertNotNull(getBeanInstance("processInstanceId"));
Assert.assertNotNull(getBeanInstance("processInstanceId"));
}
}
......@@ -10,13 +10,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.annotation;
package org.activiti.cdi.test.api.annotation;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.impl.annotation.StartProcessInterceptor;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.cdi.test.beans.DeclarativeProcessController;
import org.activiti.cdi.test.impl.beans.DeclarativeProcessController;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Testcase for assuring that the {@link StartProcessInterceptor} behaves as
......@@ -26,7 +29,8 @@ import org.activiti.engine.test.Deployment;
*/
public class StartProcessTest extends CdiActivitiTestCase {
@Deployment(resources = "org/activiti/cdi/annotation/StartProcessTest.bpmn20.xml")
@Test
@Deployment(resources = "org/activiti/cdi/test/api/annotation/StartProcessTest.bpmn20.xml")
public void testStartProcessByKey() {
assertNull(runtimeService.createProcessInstanceQuery().singleResult());
......@@ -42,7 +46,8 @@ public class StartProcessTest extends CdiActivitiTestCase {
businessProcess.completeTask();
}
@Deployment(resources = "org/activiti/cdi/annotation/StartProcessTest.bpmn20.xml")
@Test
@Deployment(resources = "org/activiti/cdi/test/api/annotation/StartProcessTest.bpmn20.xml")
public void testStartProcessByName() {
assertNull(runtimeService.createProcessInstanceQuery().singleResult());
......
......@@ -10,11 +10,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.annotation;
package org.activiti.cdi.test.api.annotation;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
......@@ -22,6 +25,7 @@ import org.activiti.engine.test.Deployment;
*/
public class TaskIdTest extends CdiActivitiTestCase {
@Test
@Deployment
public void testTaskIdInjectable() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
......
......@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.test.beans;
package org.activiti.cdi.test.impl.beans;
import java.io.Serializable;
......
......@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.test.beans;
package org.activiti.cdi.test.impl.beans;
import org.activiti.cdi.annotation.CompleteTask;
import org.activiti.cdi.annotation.ProcessVariable;
......
......@@ -10,18 +10,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.test.beans;
package org.activiti.cdi.test.impl.beans;
import java.io.Serializable;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
/**
* @author Daniel Meyer
*/
@Named
@ConversationScoped
@ApplicationScoped
public class MessageBean implements Serializable {
private static final long serialVersionUID = 1L;
......
......@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.test.beans;
package org.activiti.cdi.test.impl.beans;
import java.io.Serializable;
......
......@@ -10,13 +10,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.impl.context;
package org.activiti.cdi.test.impl.context;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.cdi.test.beans.CreditCard;
import org.activiti.cdi.test.beans.ProcessScopedMessageBean;
import org.activiti.cdi.test.impl.beans.CreditCard;
import org.activiti.cdi.test.impl.beans.ProcessScopedMessageBean;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
......@@ -24,6 +27,7 @@ import org.activiti.engine.test.Deployment;
*/
public class BusinessProcessContextTest extends CdiActivitiTestCase {
@Test
@Deployment
public void testResolution() throws Exception {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
......@@ -33,19 +37,21 @@ public class BusinessProcessContextTest extends CdiActivitiTestCase {
assertNotNull(getBeanInstance(CreditCard.class));
}
@Test
// no @Deployment for this test
public void testResolutionBeforeProcessStart() throws Exception {
// assert that @BusinessProcessScoped beans can be resolved in the absence of an underlying process instance:
assertNotNull(getBeanInstance(CreditCard.class));
}
@Test
@Deployment
public void testConversationalBeanStoreFlush() throws Exception {
getBeanInstance(BusinessProcess.class).setVariable("testVariable", "testValue");
String pid = getBeanInstance(BusinessProcess.class).startProcessByKey("testConversationalBeanStoreFlush").getId();
endConversationAndBeginNew(pid); ///////////////////////////////////////////// 2nd Conversation
getBeanInstance(BusinessProcess.class).associateExecutionById(pid);
// assert that the variable assigned on the businessProcess bean is flushed
assertEquals("testValue", runtimeService.getVariable(pid, "testVariable"));
......@@ -57,6 +63,7 @@ public class BusinessProcessContextTest extends CdiActivitiTestCase {
taskService.complete(taskService.createTaskQuery().singleResult().getId());
}
@Test
@Deployment
public void testChangeProcessScopedBeanProperty() throws Exception {
......@@ -64,8 +71,6 @@ public class BusinessProcessContextTest extends CdiActivitiTestCase {
getBeanInstance(CreditCard.class).setCreditcardNumber("123");
String pid = getBeanInstance(BusinessProcess.class).startProcessByKey("testConversationalBeanStoreFlush").getId();
endConversationAndBeginNew(); ///////////////////////////////////////////// 2nd Conversation
getBeanInstance(BusinessProcess.class).startTask(taskService.createTaskQuery().singleResult().getId());
// assert that the value of creditCardNumber is '123'
......@@ -75,7 +80,7 @@ public class BusinessProcessContextTest extends CdiActivitiTestCase {
// complete the task
getBeanInstance(BusinessProcess.class).completeTask();
endConversationAndBeginNew(pid); ///////////////////////////////////////////// 3rd Conversation
getBeanInstance(BusinessProcess.class).associateExecutionById(pid);
// now assert that the value of creditcard is "321":
assertEquals("321", getBeanInstance(CreditCard.class).getCreditcardNumber());
......
......@@ -10,11 +10,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.impl.context;
package org.activiti.cdi.test.impl.context;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.cdi.test.beans.ProcessScopedMessageBean;
import org.activiti.cdi.test.impl.beans.ProcessScopedMessageBean;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
......@@ -22,37 +25,7 @@ import org.activiti.engine.test.Deployment;
*/
public class ThreadContextAssociationTest extends CdiActivitiTestCase {
@Override
public void beginConversation() {
// do not activate conversation
}
@Override
public void endConversation() {
// do not deactivate conversation
}
@Override
public void beginRequest() {
// do not activate
}
@Override
public void endRequest() {
// do not deactivate
}
@Override
public void beginSession() {
// do not activate
}
@Override
public void endSession() {
// do not deactivate
}
@Test
@Deployment
public void testBusinessProcessScopedWithJobExecutor() throws InterruptedException {
String pid = runtimeService.startProcessInstanceByKey("processkey").getId();
......
......@@ -10,17 +10,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.impl.el;
package org.activiti.cdi.test.impl.el;
import static org.junit.Assert.assertEquals;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.cdi.test.beans.MessageBean;
import org.activiti.cdi.test.impl.beans.MessageBean;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
/**
* @author Daniel Meyer
*/
public class ElTest extends CdiActivitiTestCase {
@Test
@Deployment
public void testSetBeanProperty() throws Exception {
MessageBean messageBean = getBeanInstance(MessageBean.class);
......
......@@ -10,16 +10,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.impl.event;
package org.activiti.cdi.test.impl.event;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
import static org.junit.Assert.*;
public class EventNotificationTest extends CdiActivitiTestCase {
@Deployment(resources = {"org/activiti/cdi/impl/event/EventNotificationTest.process1.bpmn20.xml"})
@Test
@Deployment(resources = {"org/activiti/cdi/test/impl/event/EventNotificationTest.process1.bpmn20.xml"})
public void testReceiveAll() {
TestEventListener listenerBean = getBeanInstance(TestEventListener.class);
listenerBean.reset();
// assert that the bean has received 0 events
assertEquals(0, listenerBean.getEventsReceived().size());
......@@ -29,12 +34,13 @@ public class EventNotificationTest extends CdiActivitiTestCase {
assertEquals(11, listenerBean.getEventsReceived().size());
}
@Test
@Deployment(resources = {
"org/activiti/cdi/impl/event/EventNotificationTest.process1.bpmn20.xml",
"org/activiti/cdi/impl/event/EventNotificationTest.process2.bpmn20.xml" })
"org/activiti/cdi/test/impl/event/EventNotificationTest.process1.bpmn20.xml",
"org/activiti/cdi/test/impl/event/EventNotificationTest.process2.bpmn20.xml" })
public void testSelectEventsPerProcessDefinition() {
TestEventListener listenerBean = getBeanInstance(TestEventListener.class);
listenerBean.reset();
assertEquals(0, listenerBean.getEventsReceivedByKey().size());
//start the 2 processes
......@@ -45,9 +51,11 @@ public class EventNotificationTest extends CdiActivitiTestCase {
assertEquals(11, listenerBean.getEventsReceivedByKey().size());
}
@Deployment(resources = {"org/activiti/cdi/impl/event/EventNotificationTest.process1.bpmn20.xml"})
@Test
@Deployment(resources = {"org/activiti/cdi/test/impl/event/EventNotificationTest.process1.bpmn20.xml"})
public void testSelectEventsPerActivity() {
TestEventListener listenerBean = getBeanInstance(TestEventListener.class);
listenerBean.reset();
assertEquals(0, listenerBean.getEndActivityService1());
assertEquals(0, listenerBean.getStartActivityService1());
......
......@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.impl.event;
package org.activiti.cdi.test.impl.event;
import java.util.HashSet;
import java.util.Set;
......@@ -27,6 +27,15 @@ import org.activiti.cdi.annotation.event.TakeTransition;
@ApplicationScoped
public class TestEventListener {
public void reset() {
startActivityService1 = 0;
endActivityService1 = 0;
takeTransitiont1 = 0;
eventsReceivedByKey.clear();
eventsReceived.clear();
}
private final Set<BusinessProcessEvent> eventsReceivedByKey = new HashSet<BusinessProcessEvent>();
// receives all events related to "process1"
......
package org.activiti.cdi.impl.task;
package org.activiti.cdi.test.impl.task;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.engine.task.Task;
import org.junit.Test;
public class CdiTaskServiceTest extends CdiActivitiTestCase {
@Test
public void testClaimTask() {
Task newTask = taskService.newTask();
taskService.saveTask(newTask);
......
......@@ -10,19 +10,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.test;
import javax.enterprise.inject.Alternative;
package org.activiti.cdi.test.util;
import org.activiti.cdi.spi.ProcessEngineLookup;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
/**
* {@link Alternative} implementation of the {@link ProcessEngineLookup}
* -interface, providing access to the ProcessEngine built for unit-tests.
*
* @see CdiActivitiTestCase
*
* @author Daniel Meyer
*/
public class ProcessEngineLookupForTestsuite implements ProcessEngineLookup {
......@@ -36,6 +30,9 @@ public class ProcessEngineLookupForTestsuite implements ProcessEngineLookup {
@Override
public ProcessEngine getProcessEngine() {
if(processEngine == null) {
processEngine = ProcessEngines.getDefaultProcessEngine();
}
return processEngine;
}
......
......@@ -10,12 +10,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.test.beans;
import org.activiti.cdi.annotation.ProcessVariable;
package org.activiti.experimental;
import javax.inject.Inject;
import org.activiti.cdi.annotation.ProcessVariable;
public class InjectProcessVariable {
@Inject @ProcessVariable public Object testKeyString;
......
......@@ -10,18 +10,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.cdi.impl.context;
package org.activiti.experimental;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.activiti.cdi.BusinessProcess;
import org.activiti.cdi.test.CdiActivitiTestCase;
import org.activiti.cdi.test.beans.InjectProcessVariable;
import org.activiti.engine.test.Deployment;
import org.junit.Ignore;
import org.junit.Test;
public class ProcessVariablesTest extends CdiActivitiTestCase {
@Ignore
@Test
@Deployment(resources = "org/activiti/cdi/BusinessProcessBeanTest.test.bpmn20.xml")
public void testResolveString() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
......
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
org.activiti.cdi.test.ProcessEngineLookupForTestsuite
\ No newline at end of file
org.activiti.cdi.test.util.ProcessEngineLookupForTestsuite
\ No newline at end of file
......@@ -403,21 +403,6 @@
<version>2.0.0</version>
</dependency>
<!-- cdi integration -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP2</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>1.1.4.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册