use of org.jbpm.test.entity.Person in project jbpm by kiegroup.
the class ParentChildMarshallingJpaTest method testProcess.
@Test
public void testProcess() throws Exception {
emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.parent-child");
addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "org/jbpm/test/functional/jpa/parent-child.bpmn");
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
Application application = new Application();
application.setType("A");
params.put("application", application);
ProcessInstance pi = ksession.startProcess("com.sample.bpmn.hello", params);
System.out.println("A process instance started : pid = " + pi.getId());
TaskService taskService = runtime.getTaskService();
assertTrue(taskService instanceof CommandBasedTaskService);
assertTrue(((CommandBasedTaskService) taskService).getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null);
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
for (TaskSummary taskSummary : list) {
System.out.println("john starts a task : taskId = " + taskSummary.getId());
Task task = taskService.getTaskById(taskSummary.getId());
long documentContentId = task.getTaskData().getDocumentContentId();
Content content = taskService.getContentById(documentContentId);
HashMap<String, Object> contents = (HashMap<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), ksession.getEnvironment());
Application outputApplication = (Application) contents.get("input1_application");
Person person = new Person();
person.setFullName("John Doe");
outputApplication.setPerson(person);
Map<String, Object> results = new LinkedHashMap<String, Object>();
results.put("output1_application", outputApplication);
taskService.start(taskSummary.getId(), "john");
taskService.complete(taskSummary.getId(), "john", results);
}
list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
for (TaskSummary taskSummary : list) {
System.out.println("mary starts a task : taskId = " + taskSummary.getId());
taskService.start(taskSummary.getId(), "mary");
taskService.complete(taskSummary.getId(), "mary", null);
}
manager.disposeRuntimeEngine(runtime);
// Check!
EntityManager em = emfDomain.createEntityManager();
int size = em.createQuery("select i from Person i").getResultList().size();
assertEquals(1, size);
}
Aggregations