提交 1247a9bc 编写于 作者: T tijsrademakers

Merge branch 'master' of https://github.com/Activiti/Activiti

......@@ -14,6 +14,7 @@ package org.activiti.cdi.impl.util;
import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
......@@ -40,11 +41,11 @@ public class ProgrammaticBeanLookup {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Object lookup(String name, BeanManager bm) {
Iterator<Bean< ? >> iter = bm.getBeans(name).iterator();
if (!iter.hasNext()) {
Set<Bean< ? >> beans = bm.getBeans(name);
if (beans.isEmpty()) {
throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type '" + name + "'");
}
Bean bean = iter.next();
Bean bean = bm.resolve(beans);
CreationalContext ctx = bm.createCreationalContext(bean);
// select one beantype randomly. A bean has a non-empty set of beantypes.
Type type = (Type) bean.getTypes().iterator().next();
......
package org.activiti.cdi.test.impl.beans;
import javax.enterprise.inject.Specializes;
import org.activiti.cdi.test.impl.util.ProgrammaticBeanLookupTest.TestBean;
@Specializes
public class SpecializedTestBean extends TestBean {
}
package org.activiti.cdi.test.impl.util;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import javax.enterprise.inject.Alternative;
import javax.inject.Named;
import org.activiti.cdi.impl.util.ActivitiServices;
import org.activiti.cdi.impl.util.ProgrammaticBeanLookup;
import org.activiti.cdi.test.impl.beans.SpecializedTestBean;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* @author Ronny Bräunlich
*
*/
@RunWith(Arquillian.class)
public class ProgrammaticBeanLookupTest {
/**
* Because of all alternatives and specializations I have to handle
* deployment myself
*/
@ArquillianResource
private Deployer deployer;
@Deployment(name = "normal", managed = false)
public static JavaArchive createDeployment() {
return ShrinkWrap
.create(JavaArchive.class)
.addClass(ProgrammaticBeanLookup.class)
.addClass(ActivitiServices.class)
.addAsManifestResource(
"org/activiti/cdi/test/impl/util/beans.xml",
"beans.xml");
}
@Deployment(name = "withAlternative", managed = false)
public static JavaArchive createDeploymentWithAlternative() {
return ShrinkWrap
.create(JavaArchive.class)
.addClass(ProgrammaticBeanLookup.class)
.addClass(ActivitiServices.class)
.addClass(AlternativeTestBean.class)
.addAsManifestResource(
"org/activiti/cdi/test/impl/util/beansWithAlternative.xml",
"beans.xml");
}
@Deployment(name = "withSpecialization", managed = false)
public static JavaArchive createDeploymentWithSpecialization() {
return ShrinkWrap
.create(JavaArchive.class)
.addClass(ProgrammaticBeanLookup.class)
.addClass(ActivitiServices.class)
.addClass(SpecializedTestBean.class)
.addAsManifestResource(
"org/activiti/cdi/test/impl/util/beans.xml",
"beans.xml");
}
@Test
public void testLookupBean() {
deployer.deploy("normal");
Object lookup = ProgrammaticBeanLookup.lookup("testOnly");
assertThat(lookup.getClass(), is(TestBean.class.getClass()));
deployer.undeploy("normal");
}
@Test
public void testLookupShouldFindAlternative() {
deployer.deploy("withAlternative");
Object lookup = ProgrammaticBeanLookup.lookup("testOnly");
assertThat(lookup.getClass().getName(),
is(equalTo(AlternativeTestBean.class.getName())));
deployer.undeploy("withAlternative");
}
@Test
public void testLookupShouldFindSpecialization() {
deployer.deploy("withSpecialization");
Object lookup = ProgrammaticBeanLookup.lookup("testOnly");
assertThat(lookup.getClass().getName(),
is(equalTo(SpecializedTestBean.class.getName())));
deployer.undeploy("withSpecialization");
}
@Named("testOnly")
public static class TestBean {
}
@Alternative
@Named("testOnly")
public static class AlternativeTestBean extends TestBean {
}
}
<?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>
\ No newline at end of file
<?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">
<alternatives>
<class>org.activiti.cdi.test.impl.util.ProgrammaticBeanLookupTest$AlternativeTestBean</class>
</alternatives>
</beans>
......@@ -77,12 +77,15 @@ public class AtomicOperationActivityEnd extends AbstractEventAtomicOperation {
execution.remove();
// if we are a scope under the process instance
// and have no outgoing transitions: end the process instance here
if(activity.getParent() == activity.getProcessDefinition()
&& activity.getOutgoingTransitions().isEmpty()) {
if(activity.getParent() == activity.getProcessDefinition()) {
parentScopeExecution.setActivity(activity);
// we call end() because it sets isEnded on the execution
parentScopeExecution.end();
} else {
if(activity.getOutgoingTransitions().isEmpty()) {
// we call end() because it sets isEnded on the execution
parentScopeExecution.end();
} else {
parentScopeExecution.performOperation(PROCESS_END);
}
} else {
parentScopeExecution.setActivity(parentActivity);
parentScopeExecution.performOperation(ACTIVITY_END);
}
......
......@@ -22,6 +22,7 @@ import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.impl.history.HistoryLevel;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.impl.util.CollectionUtil;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
......@@ -378,7 +379,35 @@ public class BoundaryErrorEventTest extends PluggableActivitiTestCase {
assertTextPresent("No catching boundary event found for error with errorCode '23', neither in same process nor in parent process", e.getMessage());
}
}
@Deployment(resources = {
"org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorOnScriptTask.bpmn20.xml"
})
public void testCatchErrorOnScriptTask() {
String procId = runtimeService.startProcessInstanceByKey("catchErrorOnScriptTask").getId();
assertProcessEnded(procId);
}
@Deployment(resources = {
"org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorOnScriptTaskWithEmptyErrorEventDefinition.bpmn20.xml"
})
public void testUncaughtErrorOnScriptTaskWithEmptyErrorEventDefinition() {
String procId = runtimeService.startProcessInstanceByKey("uncaughtErrorOnScriptTaskWithEmptyErrorEventDefinition").getId();
assertProcessEnded(procId);
}
@Deployment(resources = {
"org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorOnScriptTask.bpmn20.xml"
})
public void testUncaughtErrorOnScriptTask() {
try {
String procId = runtimeService.startProcessInstanceByKey("uncaughtErrorOnScriptTask").getId();
assertProcessEnded(procId);
} catch (NullPointerException e) {
fail("The script throws error event with errorCode 'errorUncaught', but no catching boundary event was defined. Execution should simply be ended (none end event semantics).");
}
}
@Deployment
public void testCatchErrorThrownByJavaDelegateOnMultiInstanceServiceTaskSequential() {
Map<String, Object> variables = new HashMap<String, Object>();
......
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples">
<error id="errorOne" name="Error One" errorCode="errorOne" />
<process id="catchErrorOnScriptTask">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="theScript" />
<scriptTask id="theScript" scriptFormat="groovy">
<script><![CDATA[
import org.activiti.engine.delegate.BpmnError;
throw new BpmnError("errorOne");
]]></script>
</scriptTask>
<sequenceFlow id="flow4" sourceRef="theScript" targetRef="theEnd" />
<boundaryEvent id="catchError" attachedToRef="theScript" cancelActivity="true">
<errorEventDefinition id="one" errorRef="errorOne" />
</boundaryEvent>
<sequenceFlow id="errorFlow" sourceRef="catchError" targetRef="theEnd"/>
<endEvent id="theEnd" />
</process>
</definitions>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples">
<error id="errorOne" name="Error One" errorCode="errorOne" />
<process id="uncaughtErrorOnScriptTask">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="theScript" />
<scriptTask id="theScript" scriptFormat="groovy">
<script><![CDATA[
import org.activiti.engine.delegate.BpmnError;
throw new BpmnError("errorUncaught"); // non-defined error code!
]]></script>
</scriptTask>
<sequenceFlow id="flow4" sourceRef="theScript" targetRef="theEnd" />
<boundaryEvent id="catchErrorOne" attachedToRef="theScript" cancelActivity="true">
<errorEventDefinition id="one" errorRef="errorOne" />
</boundaryEvent>
<sequenceFlow id="errorFlow" sourceRef="catchErrorOne" targetRef="theEnd"/>
<endEvent id="theEnd" />
</process>
</definitions>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples">
<process id="uncaughtErrorOnScriptTaskWithEmptyErrorEventDefinition">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="theScript" />
<scriptTask id="theScript" scriptFormat="groovy">
<script><![CDATA[
import org.activiti.engine.delegate.BpmnError;
throw new BpmnError("errorUncaught"); // non-defined error code!
]]></script>
</scriptTask>
<sequenceFlow id="flow4" sourceRef="theScript" targetRef="theEnd" />
<boundaryEvent id="catchAnyError" attachedToRef="theScript" cancelActivity="true">
<errorEventDefinition /> <!-- no errorCode: catch any error -->
</boundaryEvent>
<sequenceFlow id="errorFlow" sourceRef="catchAnyError" targetRef="theEnd"/>
<endEvent id="theEnd" />
</process>
</definitions>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册