use of org.kie.internal.runtime.conf.NamedObjectModel in project jbpm by kiegroup.
the class DeploymentDescriptorMergerTest method testDeploymentDesciptorMergeHierarchy.
@Test
public void testDeploymentDesciptorMergeHierarchy() {
DeploymentDescriptor master = new DeploymentDescriptorImpl("org.jbpm.domain");
master.getBuilder().addMarshalingStrategy(new ObjectModel("org.jbpm.test.CustomStrategy", new Object[] { "param2" }));
assertNotNull(master);
assertEquals("org.jbpm.domain", master.getPersistenceUnit());
assertEquals("org.jbpm.domain", master.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, master.getAuditMode());
assertEquals(PersistenceMode.JPA, master.getPersistenceMode());
assertEquals(RuntimeStrategy.SINGLETON, master.getRuntimeStrategy());
assertEquals(1, master.getMarshallingStrategies().size());
assertEquals(0, master.getConfiguration().size());
assertEquals(0, master.getEnvironmentEntries().size());
assertEquals(0, master.getEventListeners().size());
assertEquals(0, master.getGlobals().size());
assertEquals(0, master.getTaskEventListeners().size());
assertEquals(0, master.getWorkItemHandlers().size());
DeploymentDescriptor slave = new DeploymentDescriptorImpl("org.jbpm.domain");
slave.getBuilder().auditMode(AuditMode.NONE).persistenceMode(PersistenceMode.JPA).persistenceUnit("my.custom.unit").auditPersistenceUnit("my.custom.unit2");
assertNotNull(slave);
assertEquals("my.custom.unit", slave.getPersistenceUnit());
assertEquals("my.custom.unit2", slave.getAuditPersistenceUnit());
assertEquals(AuditMode.NONE, slave.getAuditMode());
assertEquals(PersistenceMode.JPA, slave.getPersistenceMode());
assertEquals(RuntimeStrategy.SINGLETON, slave.getRuntimeStrategy());
assertEquals(0, slave.getMarshallingStrategies().size());
assertEquals(0, slave.getConfiguration().size());
assertEquals(0, slave.getEnvironmentEntries().size());
assertEquals(0, slave.getEventListeners().size());
assertEquals(0, slave.getGlobals().size());
assertEquals(0, slave.getTaskEventListeners().size());
assertEquals(0, slave.getWorkItemHandlers().size());
DeploymentDescriptor slave2 = new DeploymentDescriptorImpl("org.jbpm.domain");
slave2.getBuilder().auditMode(AuditMode.JMS).persistenceMode(PersistenceMode.JPA).persistenceUnit("my.custom.unit2").auditPersistenceUnit("my.custom.altered").runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addEnvironmentEntry(new NamedObjectModel("IS_JTA", "java.lang.Boolean", new Object[] { "false" }));
assertNotNull(slave2);
assertEquals("my.custom.unit2", slave2.getPersistenceUnit());
assertEquals("my.custom.altered", slave2.getAuditPersistenceUnit());
assertEquals(AuditMode.JMS, slave2.getAuditMode());
assertEquals(PersistenceMode.JPA, slave2.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, slave2.getRuntimeStrategy());
assertEquals(0, slave2.getMarshallingStrategies().size());
assertEquals(0, slave2.getConfiguration().size());
assertEquals(1, slave2.getEnvironmentEntries().size());
assertEquals(0, slave2.getEventListeners().size());
assertEquals(0, slave2.getGlobals().size());
assertEquals(0, slave2.getTaskEventListeners().size());
assertEquals(0, slave2.getWorkItemHandlers().size());
// assemble hierarchy
List<DeploymentDescriptor> hierarchy = new ArrayList<DeploymentDescriptor>();
hierarchy.add(slave2);
hierarchy.add(slave);
hierarchy.add(master);
// and now let's merge them
DeploymentDescriptorMerger merger = new DeploymentDescriptorMerger();
DeploymentDescriptor outcome = merger.merge(hierarchy, MergeMode.MERGE_COLLECTIONS);
assertNotNull(outcome);
assertEquals("my.custom.unit2", outcome.getPersistenceUnit());
assertEquals("my.custom.altered", outcome.getAuditPersistenceUnit());
assertEquals(AuditMode.JMS, outcome.getAuditMode());
assertEquals(PersistenceMode.JPA, outcome.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, outcome.getRuntimeStrategy());
assertEquals(1, outcome.getMarshallingStrategies().size());
assertEquals(0, outcome.getConfiguration().size());
assertEquals(1, outcome.getEnvironmentEntries().size());
assertEquals(0, outcome.getEventListeners().size());
assertEquals(0, outcome.getGlobals().size());
assertEquals(0, outcome.getTaskEventListeners().size());
assertEquals(0, outcome.getWorkItemHandlers().size());
}
use of org.kie.internal.runtime.conf.NamedObjectModel in project jbpm by kiegroup.
the class ReflectionObjectModelResolverTest method testSimpleNoArgNamedObjectModel.
@Test
public void testSimpleNoArgNamedObjectModel() {
NamedObjectModel model = new NamedObjectModel("CustomObject", "org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject");
assertEquals("CustomObject", model.getName());
ObjectModelResolver resolver = new ReflectionObjectModelResolver();
Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
assertNotNull(result);
assertTrue(result instanceof SimpleCustomObject);
assertEquals("default", ((SimpleCustomObject) result).getName());
}
use of org.kie.internal.runtime.conf.NamedObjectModel in project jbpm by kiegroup.
the class RuntimeManagerWithDescriptorTest method testDeployWithFullCustomDeploymentDescriptor.
@Test
public void testDeployWithFullCustomDeploymentDescriptor() throws Exception {
Map<String, String> resources = new HashMap<String, String>();
String scriptString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ScriptTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ScriptTask.bpmn2", scriptString);
String manualString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ManualTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ManualTask.bpmn2", manualString);
String userString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-UserTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-UserTask.bpmn2", userString);
String callString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivity.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivity.bpmn2", callString);
String subProcessString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivitySubProcess.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivitySubProcess.bpmn2", subProcessString);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")).addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[] { DefaultSignalManagerFactory.class.getName() })).addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")).addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")).addGlobal(new NamedObjectModel("service", "java.util.ArrayList")).addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")).addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler"));
resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
String drl = "package org.jbpm; global java.util.List service; " + " rule \"Start Hello1\"" + " when" + " then" + " System.out.println(\"Hello\");" + " end";
resources.put("src/main/resources/simple.drl", drl);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.dd", "-kjar-with-dd", "1.0.0");
InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
installKjar(releaseId, kJar1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
InternalRuntimeManager internalManager = (InternalRuntimeManager) manager;
RegisterableItemsFactory factory = internalManager.getEnvironment().getRegisterableItemsFactory();
assertNotNull(factory);
assertTrue(factory instanceof InternalRegisterableItemsFactory);
assertNotNull(((InternalRegisterableItemsFactory) factory).getRuntimeManager());
DeploymentDescriptor descriptor = internalManager.getDeploymentDescriptor();
assertNotNull(descriptor);
assertEquals("org.jbpm.persistence.jpa", descriptor.getPersistenceUnit());
assertEquals("org.jbpm.persistence.jpa", descriptor.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, descriptor.getAuditMode());
assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
assertEquals(1, descriptor.getMarshallingStrategies().size());
// assertEquals(1, descriptor.getConfiguration().size());
assertEquals(1, descriptor.getEnvironmentEntries().size());
assertEquals(1, descriptor.getEventListeners().size());
assertEquals(1, descriptor.getGlobals().size());
assertEquals(1, descriptor.getTaskEventListeners().size());
assertEquals(1, descriptor.getWorkItemHandlers().size());
assertEquals(0, descriptor.getRequiredRoles().size());
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
KieSession kieSession = engine.getKieSession();
// configuration
assertEquals(((SessionConfiguration) kieSession.getSessionConfiguration()).getSignalManagerFactory(), DefaultSignalManagerFactory.class.getName());
BusinessCalendar bc = (BusinessCalendar) kieSession.getEnvironment().get("jbpm.business.calendar");
assertNotNull(bc);
assertTrue(bc instanceof TestBusinessCalendar);
// globals
Object service = kieSession.getGlobal("service");
assertNotNull(service);
assertTrue(service instanceof ArrayList);
// work item handler
ProcessInstance processInstance = kieSession.startProcess("ManualTask");
long processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
kieSession.getWorkItemManager().completeWorkItem(TestWorkItemHandler.getWorkItem().getId(), null);
assertNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// process event listener
assertArrayEquals(new String[] { "beforeProcessStarted", "afterProcessStarted", "beforeProcessCompleted", "afterProcessCompleted" }, processEvents.toArray());
processEvents.clear();
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// task event listener
processInstance = kieSession.startProcess("UserTask");
processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
TaskService taskService = engine.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
assertArrayEquals(new String[] { "beforeTaskAddedEvent", "afterTaskAddedEvent", "beforeTaskStartedEvent", "afterTaskStartedEvent", "beforeTaskCompletedEvent", "afterTaskCompletedEvent" }, taskEvents.toArray());
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// marshalling strategy
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "marshal");
processInstance = kieSession.startProcess("ParentProcess", params);
processInstanceId = processInstance.getId();
ProcessInstance pi = kieSession.getProcessInstance(processInstanceId);
assertNotNull(pi);
String varX = (String) ((WorkflowProcessInstance) pi).getVariable("x");
assertEquals(TestMarshallingStrategy.ALWAYS_RESPOND_WITH, varX);
manager.disposeRuntimeEngine(engine);
}
use of org.kie.internal.runtime.conf.NamedObjectModel in project jbpm by kiegroup.
the class IdentityProviderAwareProcessListenerTest method init.
@Before
public void init() {
configureServices();
final KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
final List<String> processes = Collections.singletonList("repo/processes/general/humanTask.bpmn");
final InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
final File pom = new File("target/kmodule", "pom.xml");
pom.getParentFile().mkdir();
try (FileOutputStream fs = new FileOutputStream(pom)) {
fs.write(getPom(releaseId).getBytes());
} catch (Exception e) {
e.printStackTrace();
}
getKieMavenRepository().deployArtifact(releaseId, kJar1, pom);
deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
final DeploymentDescriptor descriptor = new DeploymentDescriptorImpl();
descriptor.getBuilder().addEventListener(new NamedObjectModel("mvel", "processIdentity", "new org.jbpm.kie.services.impl.IdentityProviderAwareProcessListener(ksession)"));
deploymentUnit.setDeploymentDescriptor(descriptor);
deploymentService.deploy(deploymentUnit);
final DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processDefinitions = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processDefinitions);
assertEquals(1, processDefinitions.size());
}
use of org.kie.internal.runtime.conf.NamedObjectModel in project jbpm by kiegroup.
the class KModuleDeploymentServiceTest method testDeploymentOfProcessWithDescriptorKieConteinerInjection.
@Test
public void testDeploymentOfProcessWithDescriptorKieConteinerInjection() {
assertNotNull(deploymentService);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "kjar-with-dd", VERSION);
List<String> processes = new ArrayList<String>();
processes.add("repo/processes/general/customtask.bpmn");
processes.add("repo/processes/general/humanTask.bpmn");
processes.add("repo/processes/general/import.bpmn");
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_REQUEST).addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.kie.services.test.objects.KieConteinerSystemOutWorkItemHandler(kieContainer)"));
Map<String, String> resources = new HashMap<String, String>();
resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, resources);
File pom = new File("target/kmodule", "pom.xml");
pom.getParentFile().mkdir();
try {
FileOutputStream fs = new FileOutputStream(pom);
fs.write(getPom(releaseId).getBytes());
fs.close();
} catch (Exception e) {
}
KieMavenRepository repository = getKieMavenRepository();
repository.deployArtifact(releaseId, kJar1, pom);
DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, "kjar-with-dd", VERSION, "KBase-test", "ksession-test2");
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployedGeneral);
assertNotNull(deployedGeneral.getDeploymentUnit());
assertNotNull(deployedGeneral.getRuntimeManager());
DeploymentDescriptor descriptor = ((InternalRuntimeManager) deployedGeneral.getRuntimeManager()).getDeploymentDescriptor();
assertNotNull(descriptor);
assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, descriptor.getAuditMode());
assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_REQUEST, descriptor.getRuntimeStrategy());
assertEquals(0, descriptor.getMarshallingStrategies().size());
assertEquals(0, descriptor.getConfiguration().size());
assertEquals(0, descriptor.getEnvironmentEntries().size());
assertEquals(0, descriptor.getEventListeners().size());
assertEquals(0, descriptor.getGlobals().size());
assertEquals(0, descriptor.getTaskEventListeners().size());
assertEquals(1, descriptor.getWorkItemHandlers().size());
assertEquals(0, descriptor.getRequiredRoles().size());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
manager.disposeRuntimeEngine(engine);
checkFormsDeployment(deploymentUnit.getIdentifier());
}
Aggregations