Permalink
Browse files

- fixing failing tests in jbpm-test

  • Loading branch information...
1 parent 3962502 commit d3169cf139486bba6f573302b6401cbd1a661d8e @Salaboy Salaboy committed Apr 27, 2012
View
6 jbpm-human-task/pom.xml
@@ -161,6 +161,12 @@
<scope>test</scope>
<type>jar</type>
</dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-core</artifactId>
+ <version>5.4.0-SNAPSHOT</version>
+ <type>jar</type>
+ </dependency>
</dependencies>
<build>
View
2 jbpm-human-task/src/main/java/org/jbpm/process/workitem/wsht/SyncWSHumanTaskHandler.java
@@ -75,7 +75,7 @@
private boolean initialized = false;
- private ContentMarshallerContext marshallerContext;
+ private ContentMarshallerContext marshallerContext = new ContentMarshallerContext();
public SyncWSHumanTaskHandler() {
View
3 jbpm-human-task/src/main/java/org/jbpm/process/workitem/wsht/WSHumanTaskHandler.java
@@ -60,6 +60,7 @@
import org.jbpm.task.service.mina.MinaTaskClientConnector;
import org.jbpm.task.service.mina.MinaTaskClientHandler;
import org.jbpm.task.service.responsehandlers.AbstractBaseResponseHandler;
+import org.jbpm.task.utils.ContentMarshallerContext;
import org.jbpm.task.utils.OnErrorAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -76,7 +77,7 @@
private boolean initialized = false;
private KnowledgeRuntime session;
private OnErrorAction action;
-
+ private ContentMarshallerContext marshallerContext = new ContentMarshallerContext();
public WSHumanTaskHandler() {
this.action = OnErrorAction.LOG;
}
View
4 jbpm-human-task/src/main/java/org/jbpm/task/utils/ContentMarshallerContext.java
@@ -21,10 +21,10 @@
public class ContentMarshallerContext {
- public final Map<ObjectMarshallingStrategy, ObjectMarshallingStrategy.Context> strategyContext;
+ public final Map<Class, ObjectMarshallingStrategy.Context> strategyContext;
public ContentMarshallerContext() {
- strategyContext = new HashMap<ObjectMarshallingStrategy, ObjectMarshallingStrategy.Context>();
+ strategyContext = new HashMap<Class, ObjectMarshallingStrategy.Context>();
}
View
38 jbpm-human-task/src/main/java/org/jbpm/task/utils/ContentMarshallerHelper.java
@@ -17,9 +17,11 @@
import java.io.*;
import java.util.Map;
-import java.util.logging.Level;
import org.drools.marshalling.ObjectMarshallingStrategy;
import org.drools.marshalling.ObjectMarshallingStrategy.Context;
+import org.drools.marshalling.impl.ClassObjectMarshallingStrategyAcceptor;
+
+import org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy;
import org.drools.runtime.Environment;
import org.drools.runtime.EnvironmentName;
import org.jbpm.process.workitem.wsht.SyncWSHumanTaskHandler;
@@ -33,7 +35,13 @@
private static final Logger logger = LoggerFactory.getLogger(SyncWSHumanTaskHandler.class);
public static ContentData marshal(Object o, ContentMarshallerContext marshallerContext, Environment env) {
- ObjectMarshallingStrategy[] strats = (ObjectMarshallingStrategy[]) env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
+ ObjectMarshallingStrategy[] strats = null;
+ if (env != null && env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null) {
+ strats = (ObjectMarshallingStrategy[]) env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
+ } else {
+ strats = new ObjectMarshallingStrategy[1];
+ strats[0] = new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
+ }
ContentData content = null;
if (o instanceof Map) {
@@ -73,11 +81,15 @@ private static MarshalledContentWrapper marshalSingle(ObjectMarshallingStrategy
MarshalledContentWrapper contentWrap = null;
try {
Context context = null;
- if(marshallerContext.strategyContext.get(strat) == null){
- context = strat.createContext();
- marshallerContext.strategyContext.put(strat, context);
- } else{
- context = marshallerContext.strategyContext.get(strat);
+ if(marshallerContext != null){
+ if (marshallerContext.strategyContext.get(strat.getClass()) == null) {
+ context = strat.createContext();
+ marshallerContext.strategyContext.put(strat.getClass(), context);
+ } else {
+ context = marshallerContext.strategyContext.get(strat.getClass());
+ }
+ }else{
+ throw new IllegalStateException(" The Marshaller Context Needs to be Provided");
}
byte[] marshalled = strat.marshal(context, null, o);
contentWrap = new MarshalledContentWrapper(marshalled, strat.getClass().getCanonicalName(), o.getClass());
@@ -93,15 +105,21 @@ private static MarshalledContentWrapper marshalSingle(ObjectMarshallingStrategy
public static Object unmarshall(String type, byte[] content, ContentMarshallerContext marshallerContext, Environment env) {
- ObjectMarshallingStrategy[] strats = (ObjectMarshallingStrategy[]) env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
+ ObjectMarshallingStrategy[] strats = null;
+ if (env != null && env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null) {
+ strats = (ObjectMarshallingStrategy[]) env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
+ } else {
+ strats = new ObjectMarshallingStrategy[1];
+ strats[0] = new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
+ }
Object data = null;
ObjectMarshallingStrategy selectedStrat = null;
for (ObjectMarshallingStrategy strat : strats) {
if (strat.getClass().getCanonicalName().equals(type)) {
selectedStrat = strat;
}
}
- Context context = marshallerContext.strategyContext.get(selectedStrat);
+ Context context = marshallerContext.strategyContext.get(selectedStrat.getClass());
try {
data = selectedStrat.unmarshal(context, null, content, ContentMarshallerHelper.class.getClassLoader());
if (data instanceof Map) {
@@ -114,7 +132,7 @@ public static Object unmarshall(String type, byte[] content, ContentMarshallerCo
selectedStrat = strat;
}
}
- context = marshallerContext.strategyContext.get(selectedStrat);
+ context = marshallerContext.strategyContext.get(selectedStrat.getClass());
unmarshalledObj = selectedStrat.unmarshal(context, null, value.getContent(), ContentMarshallerHelper.class.getClassLoader());
((Map) data).put(key, unmarshalledObj);
}
View
60 ...ask/src/test/java/org/jbpm/process/workitem/wsht/sync/WSHumanTaskHandlerBaseSyncTest.java
@@ -38,6 +38,7 @@
import org.jbpm.task.query.TaskSummary;
import org.jbpm.task.service.ContentData;
import org.jbpm.task.service.PermissionDeniedException;
+import org.jbpm.task.utils.ContentMarshallerHelper;
import org.jbpm.task.utils.OnErrorAction;
public abstract class WSHumanTaskHandlerBaseSyncTest extends BaseTest {
@@ -362,22 +363,27 @@ public void testTaskData() throws Exception {
long contentId = task.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
- ByteArrayInputStream bis = new ByteArrayInputStream(getClient().getContent(contentId).getContent());
- ObjectInputStream in = new ObjectInputStream(bis);
- Object data = in.readObject();
- in.close();
+// ByteArrayInputStream bis = new ByteArrayInputStream(getClient().getContent(contentId).getContent());
+// ObjectInputStream in = new ObjectInputStream(bis);
+// Object data = in.readObject();
+// in.close();
+ Object data = ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(),
+ getClient().getContent(contentId).getContent(),
+ ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(),
+ ksession.getEnvironment());
assertEquals("This is the content", data);
getClient().start(task.getId(), "Darth Vader");
- ContentData result = new ContentData();
- result.setAccessType(AccessType.Inline);
- result.setType("java.lang.String");
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(bos);
- out.writeObject("This is the result");
- out.close();
- result.setContent(bos.toByteArray());
+// ContentData result = new ContentData();
+// result.setAccessType(AccessType.Inline);
+// result.setType("java.lang.String");
+// ByteArrayOutputStream bos = new ByteArrayOutputStream();
+// ObjectOutputStream out = new ObjectOutputStream(bos);
+// out.writeObject("This is the result");
+// out.close();
+// result.setContent(bos.toByteArray());
+ ContentData result = ContentMarshallerHelper.marshal("This is the result", ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
getClient().complete(task.getId(), "Darth Vader", result);
assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
@@ -428,25 +434,31 @@ public void testTaskDataAutomaticMapping() throws Exception {
assertTrue(contentId != -1);
- ByteArrayInputStream bis = new ByteArrayInputStream(getClient().getContent(contentId).getContent());
- ObjectInputStream in = new ObjectInputStream(bis);
- Map<String, Object> data = (Map<String, Object>) in.readObject();
- in.close();
+// ByteArrayInputStream bis = new ByteArrayInputStream(getClient().getContent(contentId).getContent());
+// ObjectInputStream in = new ObjectInputStream(bis);
+ Map<String, Object> data = (Map<String, Object>) ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(),
+ getClient().getContent(contentId).getContent(),
+ ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(),
+ ksession.getEnvironment());
+ //in.readObject();
+ //in.close();
//Checking that the input parameters are being copied automatically if the Content Element doesn't exist
assertEquals("MyObjectValue", ((MyObject) data.get("MyObject")).getValue());
assertEquals("10", data.get("Priority"));
assertEquals("MyObjectValue", ((MyObject) ((Map<String, Object>) data.get("MyMap")).get("MyObjectInsideTheMap")).getValue());
getClient().start(task.getId(), "Darth Vader");
- ContentData result = new ContentData();
- result.setAccessType(AccessType.Inline);
- result.setType("java.lang.String");
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(bos);
- out.writeObject("This is the result");
- out.close();
- result.setContent(bos.toByteArray());
+ ContentData result = ContentMarshallerHelper.marshal("This is the result", ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
+// new ContentData();
+// result.setAccessType(AccessType.Inline);
+// result.setType("java.lang.String");
+// ByteArrayOutputStream bos = new ByteArrayOutputStream();
+// ObjectOutputStream out = new ObjectOutputStream(bos);
+// out.writeObject("This is the result");
+// out.close();
+// result.setContent(bos.toByteArray());
+
getClient().complete(task.getId(), "Darth Vader", result);
assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
View
15 .../java/org/jbpm/task/service/persistence/variable/VariablePersistenceStrategiesHTTest.java
@@ -58,7 +58,7 @@
private WorkItemHandler handler;
private EntityManagerFactory domainEmf;
protected TestStatefulKnowledgeSession ksession = new TestStatefulKnowledgeSession();
- protected ContentMarshallerContext marshallerContext = new ContentMarshallerContext();
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -75,7 +75,6 @@ protected void setUp() throws Exception {
setClient(new LocalTaskService(taskService));
SyncWSHumanTaskHandler syncWSHumanTaskHandler = new SyncWSHumanTaskHandler(getClient(), ksession);
- syncWSHumanTaskHandler.setMarshallerContext(marshallerContext);
setHandler(syncWSHumanTaskHandler);
}
@@ -134,7 +133,7 @@ public void testTaskDataWithVPSJPAEntity() throws Exception {
long contentId = task.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
- Object data = ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(), getClient().getContent(contentId).getContent(), marshallerContext, ksession.getEnvironment());
+ Object data = ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(), getClient().getContent(contentId).getContent(), ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
assertEquals(myEntity.getTest(), ((MyEntity)data).getTest());
getClient().start(task.getId(), "Darth Vader");
@@ -144,7 +143,7 @@ public void testTaskDataWithVPSJPAEntity() throws Exception {
em.persist(myEntity2);
em.getTransaction().commit();
- ContentData result = ContentMarshallerHelper.marshal(myEntity2, marshallerContext, ksession.getEnvironment());
+ ContentData result = ContentMarshallerHelper.marshal(myEntity2, ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
getClient().complete(task.getId(), "Darth Vader", result);
assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
@@ -186,7 +185,7 @@ public void testTaskDataWithVPSSerializableObject() throws Exception {
long contentId = task.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
- Object data = ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(),getClient().getContent(contentId).getContent(), marshallerContext, ksession.getEnvironment());
+ Object data = ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(),getClient().getContent(contentId).getContent(), ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
assertEquals(myObject.getValue(), ((MyObject)data).getValue());
getClient().start(task.getId(), "Darth Vader");
@@ -195,7 +194,7 @@ public void testTaskDataWithVPSSerializableObject() throws Exception {
MyObject myObject2 = new MyObject("This is a Serializable Object 2");
- ContentData result = ContentMarshallerHelper.marshal(myObject2, marshallerContext, ksession.getEnvironment());
+ ContentData result = ContentMarshallerHelper.marshal(myObject2, ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
getClient().complete(task.getId(), "Darth Vader", result);
assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
@@ -250,7 +249,7 @@ public void testTaskDataWithVPSandMAP() throws Exception {
long contentId = task.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
- Object data = ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(), getClient().getContent(contentId).getContent(), marshallerContext, ksession.getEnvironment());
+ Object data = ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(), getClient().getContent(contentId).getContent(), ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
Map<String, Object> dataMap = (Map<String, Object>)data;
assertEquals(myEntity.getTest(), ((MyEntity)dataMap.get("myJPAEntity")).getTest());
@@ -267,7 +266,7 @@ public void testTaskDataWithVPSandMAP() throws Exception {
MyObject myObject2 = new MyObject("This is a Serializable Object 2");
results.put("myObject2", myObject2);
- ContentData result = ContentMarshallerHelper.marshal(results, marshallerContext, ksession.getEnvironment());
+ ContentData result = ContentMarshallerHelper.marshal(results, ((SyncWSHumanTaskHandler)getHandler()).getMarshallerContext(), ksession.getEnvironment());
getClient().complete(task.getId(), "Darth Vader", result);
assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
View
63 jbpm-test/src/test/java/org/jbpm/persistence/PatientVariablePersistenceStrategyTest.java
@@ -30,6 +30,7 @@
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
+import org.drools.impl.EnvironmentFactory;
import org.drools.io.impl.ClassPathResource;
import org.drools.marshalling.ObjectMarshallingStrategy;
import org.drools.marshalling.impl.ClassObjectMarshallingStrategyAcceptor;
@@ -47,16 +48,14 @@
import org.jbpm.persistence.objects.Patient;
import org.jbpm.persistence.objects.RecordRow;
import org.jbpm.process.workitem.wsht.SyncWSHumanTaskHandler;
-import org.jbpm.task.AccessType;
-import org.jbpm.task.Content;
-import org.jbpm.task.Group;
-import org.jbpm.task.User;
+import org.jbpm.task.*;
import org.jbpm.task.query.TaskSummary;
import org.jbpm.task.service.ContentData;
import org.jbpm.task.service.SendIcal;
import org.jbpm.task.service.TaskService;
import org.jbpm.task.service.TaskServiceSession;
import org.jbpm.task.service.local.LocalTaskService;
+import org.jbpm.task.utils.ContentMarshallerHelper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -86,7 +85,9 @@
protected MockUserInfo userInfo;
protected Properties conf;
-
+
+ protected StatefulKnowledgeSession ksession;
+ protected SyncWSHumanTaskHandler htHandler;
@Before
public void setUp() throws Exception {
context = setupWithPoolingDataSource("org.jbpm.runtime", false);
@@ -176,8 +177,8 @@ public void simplePatientMedicalRecordTest() throws Exception {
em.getTransaction().commit();
Environment env = createEnvironment();
KnowledgeBase kbase = createKnowledgeBase("patient-appointment.bpmn");
- StatefulKnowledgeSession ksession = createSession(kbase, env);
- SyncWSHumanTaskHandler htHandler = new SyncWSHumanTaskHandler(localTaskService, ksession);
+ ksession = createSession(kbase, env);
+ htHandler = new SyncWSHumanTaskHandler(localTaskService, ksession);
htHandler.setLocal(true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", htHandler);
logger.info("### Starting process ###");
@@ -295,9 +296,11 @@ private KnowledgeBase createKnowledgeBase(String flowFile) {
}
private Environment createEnvironment() {
+ Environment domainEnv = EnvironmentFactory.newEnvironment();
+ domainEnv.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emfDomain);
Environment env = PersistenceUtil.createEnvironment(context);
env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[]{
- new JPAPlaceholderResolverStrategy(env),
+ new JPAPlaceholderResolverStrategy(domainEnv),
new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT)
});
return env;
@@ -340,9 +343,15 @@ public Object eval(String str, Map vars) {
private MedicalRecord getTaskContent(TaskSummary summary) throws IOException, ClassNotFoundException{
logger.info(" >>> Getting Task Content = "+summary.getId());
Content content = this.localTaskService.getContent(summary.getId());
+ Task task = this.localTaskService.getTask(summary.getId());
+// ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(content.getContent()));
+ Object readObject =
+ ContentMarshallerHelper.unmarshall(task.getTaskData().getDocumentType(),
+ content.getContent(),
+ ((SyncWSHumanTaskHandler)htHandler).getMarshallerContext(),
+ ksession.getEnvironment());
+ //ois.readObject();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(content.getContent()));
- Object readObject = ois.readObject();
logger.info(" >>> Object = "+readObject);
return (MedicalRecord)readObject;
}
@@ -353,22 +362,24 @@ private MedicalRecord getTaskContent(TaskSummary summary) throws IOException, Cl
* @return
*/
private ContentData prepareContentData(Map data){
- ContentData contentData = null;
- if (data != null) {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream out;
- try {
- out = new ObjectOutputStream(bos);
- out.writeObject(data);
- out.close();
- contentData = new ContentData();
- contentData.setContent(bos.toByteArray());
- contentData.setAccessType(AccessType.Inline);
- }
- catch (IOException e) {
- System.err.print(e);
- }
- }
+ ContentData contentData = ContentMarshallerHelper.marshal(data, ((SyncWSHumanTaskHandler)htHandler).getMarshallerContext(), ksession.getEnvironment());
+
+// null;
+// if (data != null) {
+// ByteArrayOutputStream bos = new ByteArrayOutputStream();
+// ObjectOutputStream out;
+// try {
+// out = new ObjectOutputStream(bos);
+// out.writeObject(data);
+// out.close();
+// contentData = new ContentData();
+// contentData.setContent(bos.toByteArray());
+// contentData.setAccessType(AccessType.Inline);
+// }
+// catch (IOException e) {
+// System.err.print(e);
+// }
+// }
return contentData;
}
View
6 jbpm-test/src/test/java/org/jbpm/persistence/objects/MedicalRecord.java
@@ -33,6 +33,10 @@
private List<RecordRow> rows;
private int priority;
+ public MedicalRecord() {
+ }
+
+
public MedicalRecord(String desc, Patient patient) {
this.description = desc;
this.patient = patient;
@@ -80,7 +84,7 @@ public void setRows(List<RecordRow> rows) {
@Override
public String toString() {
- return "MedicalRecord{" + "id=" + id + ", desc=" + description + ", patient=" + patient + ", rows=" + rows + ", priority=" + priority + '}';
+ return "MedicalRecord{" + "id=" + id + ", desc=" + description + ", patient=" + patient.getId() + ", rows=" + rows + ", priority=" + priority + '}';
}
@Override
View
4 jbpm-test/src/test/java/org/jbpm/persistence/objects/Patient.java
@@ -28,6 +28,10 @@
@Temporal(TemporalType.TIMESTAMP)
private Date nextAppointment;
+ public Patient() {
+ }
+
+
public Patient(String name) {
this.name = name;
}
View
6 jbpm-test/src/test/java/org/jbpm/persistence/objects/RecordRow.java
@@ -28,6 +28,10 @@
@JoinColumn(name="MEDREC_ID", nullable=false, updatable=false)
private MedicalRecord medicalRecord;
+ public RecordRow() {
+ }
+
+
public RecordRow(String code, String desc) {
this.code = code;
this.description = desc;
@@ -68,7 +72,7 @@ public void setId(Long id) {
@Override
public String toString() {
- return "RecordRow{" + "id=" + id + ", code=" + code + ", desc=" + description + ", medicalRecord=" + medicalRecord + '}';
+ return "RecordRow{" + "id=" + id + ", code=" + code + ", desc=" + description + ", medicalRecord=" + medicalRecord.getId() + '}';
}
@Override

0 comments on commit d3169cf

Please sign in to comment.