use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class KModuleDeploymentServiceTest method testDeploymentOfProcessWithDescriptor.
@Test
public void testDeploymentOfProcessWithDescriptor() {
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("Log", "org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler"));
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());
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class KModuleDeploymentServiceTest method testDeploymentAvoidEmptyDescriptorOverride.
@Test
public void testDeploymentAvoidEmptyDescriptorOverride() {
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("Log", "org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler"));
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);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, "kjar-with-dd", VERSION, "KBase-test", "ksession-test2");
// let's simulate change of deployment descriptor on deploy time
// set empty one...
deploymentUnit.setDeploymentDescriptor(new DeploymentDescriptorImpl());
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());
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class KModuleWithDependenciesDeploymentServiceTest method testDeploymentOfProcesses.
@Test
public void testDeploymentOfProcesses() throws Exception {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession");
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(deployed.getRuntimeManager());
assertEquals("org.jbpm.test:jbpm-module:1.0.0:defaultKieBase:defaultKieSession", deployed.getDeploymentUnit().getIdentifier());
assertTrue(deployed instanceof DeployedUnitImpl);
assertEquals(2, ((DeployedUnitImpl) deployed).getDeployedClasses().size());
List<String> classnames = new ArrayList<String>();
for (Class<?> clazz : ((DeployedUnitImpl) deployed).getDeployedClasses()) {
classnames.add(clazz.getName());
}
assertTrue(classnames.contains("org.jbpm.data.rest.CustomDataObject"));
assertTrue(classnames.contains("org.jbpm.test.Person"));
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(1, processes.size());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Class<?> clazz = Class.forName("org.jbpm.test.Person", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object instance = clazz.newInstance();
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", instance);
ProcessInstance processInstance = engine.getKieSession().startProcess("testkjar.src.main.resources.process", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
List<TaskSummary> tasks = engine.getTaskService().getTasksOwned("salaboy", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
Map<String, Object> content = ((InternalTaskService) engine.getTaskService()).getTaskContent(taskId);
assertTrue(content.containsKey("personIn"));
Object person = content.get("personIn");
assertEquals(clazz.getName(), person.getClass().getName());
engine.getTaskService().start(taskId, "salaboy");
Map<String, Object> data = new HashMap<String, Object>();
data.put("personOut", instance);
engine.getTaskService().complete(taskId, "salaboy", data);
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class ClassloaderKModuleDeploymentServiceTest method testDeploymentOfProcesses.
@Test
public void testDeploymentOfProcesses() throws Exception {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession");
deploymentUnit.setStrategy(RuntimeStrategy.PER_REQUEST);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(deployed.getRuntimeManager());
assertEquals("org.jbpm.test:jbpm-module:1.0:defaultKieBase:defaultKieSession", deployed.getDeploymentUnit().getIdentifier());
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(1, processes.size());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Class<?> clazz = Class.forName("org.jbpm.test.Person", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object instance = clazz.newInstance();
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", instance);
ProcessInstance processInstance = engine.getKieSession().startProcess("testkjar.src.main.resources.process", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
List<TaskSummary> tasks = engine.getTaskService().getTasksOwned("salaboy", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
Map<String, Object> content = ((InternalTaskService) engine.getTaskService()).getTaskContent(taskId);
assertTrue(content.containsKey("personIn"));
Object person = content.get("personIn");
assertEquals(clazz.getName(), person.getClass().getName());
engine.getTaskService().start(taskId, "salaboy");
Map<String, Object> data = new HashMap<String, Object>();
data.put("personOut", instance);
engine.getTaskService().complete(taskId, "salaboy", data);
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.
the class DeactivateDeploymentServiceWithSyncTest method testDeactivateDeploymentBySync.
@Test
public void testDeactivateDeploymentBySync() throws Exception {
Collection<DeployedUnit> deployed = deploymentService.getDeployedUnits();
assertNotNull(deployed);
assertEquals(0, deployed.size());
KModuleDeploymentUnit unit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(unit);
deploymentService.deactivate(unit.getIdentifier());
((KModuleDeploymentService) deploymentService).shutdown();
sync.clear();
AtomicBoolean deploymentActive = new AtomicBoolean(true);
CoundDownDeploymentListener countDownListener = new CoundDownDeploymentListener(1) {
@Override
public void onDeploy(DeploymentEvent event) {
// This used to use a specific listener for setting the active state
deploymentActive.set(event.getDeployedUnit().isActive());
super.onDeploy(event);
}
};
countDownListener.setDeploy(true);
((ListenerSupport) deploymentService).addListener(countDownListener);
invoker.start();
countDownListener.waitTillCompleted();
assertFalse("Deployment should be deactivated", deploymentActive.get());
deployed = deploymentService.getDeployedUnits();
assertNotNull(deployed);
assertEquals(1, deployed.size());
}
Aggregations