Search in sources :

Example 36 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit 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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ArrayList(java.util.ArrayList) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) InternalTaskService(org.kie.internal.task.api.InternalTaskService) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeployedUnitImpl(org.jbpm.kie.services.impl.DeployedUnitImpl) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 37 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ProcessServiceImplPerProcessInstanceTest method prepareDeploymentUnit.

@BeforeClass
public static void prepareDeploymentUnit() {
    deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentUnit.setStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);
}
Also used : KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) BeforeClass(org.junit.BeforeClass)

Example 38 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ProcessServiceImplTest method testStartProcessAndAbortAlreadyAborted.

@Test
public void testStartProcessAndAbortAlreadyAborted() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "test");
    params.put("approval_reviewComment", "need review");
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    processService.abortProcessInstance(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
    try {
        processService.abortProcessInstance(processInstanceId);
        fail("Process instance was aborted so process instance does not exist any more");
    } catch (ProcessInstanceNotFoundException e) {
    // expected
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 39 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ProcessServiceImplTest method testStartAndSignalBoundary.

@Test
public void testStartAndSignalBoundary() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.boundarysignal");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<String> signals = processService.getAvailableSignals(processInstanceId);
    assertNotNull(signals);
    assertEquals(1, signals.size());
    assertTrue(signals.contains("MySignal"));
    processService.signalProcessInstance(processInstanceId, "MySignal", null);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 40 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ProcessServiceImplTest method testStartAndSignalProcessWithExpression.

@Test
public void testStartAndSignalProcessWithExpression() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.signalWithExpression");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<String> signals = processService.getAvailableSignals(processInstanceId);
    assertNotNull(signals);
    assertEquals(1, signals.size());
    assertTrue(signals.contains("MySignal"));
    processService.signalProcessInstance(processInstanceId, "MySignal", null);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)170 Test (org.junit.Test)131 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)97 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)83 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)55 HashMap (java.util.HashMap)46 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)42 ArrayList (java.util.ArrayList)34 QueryContext (org.kie.api.runtime.query.QueryContext)34 ReleaseId (org.kie.api.builder.ReleaseId)29 KieServices (org.kie.api.KieServices)26 File (java.io.File)22 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)22 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)21 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)19 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)19 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)19 Before (org.junit.Before)18 FileOutputStream (java.io.FileOutputStream)17 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)17