Search in sources :

Example 51 with KModuleDeploymentUnit

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

the class UserTaskAdminServiceImplTest method prepare.

@Before
public void prepare() {
    configureServices();
    logger.debug("Preparing kjar");
    KieServices ks = KieServices.Factory.get();
    // version 1 of kjar
    ReleaseId releaseId = ks.newReleaseId(ADMIN_GROUP_ID, ADMIN_ARTIFACT_ID, ADMIN_VERSION_V1);
    List<String> processes = new ArrayList<String>();
    processes.add("repo/processes/general/humanTask.bpmn");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    File pom = new File("target/admin", "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.installArtifact(releaseId, kJar1, pom);
    userTaskAdminService = new UserTaskAdminServiceImpl();
    ((UserTaskAdminServiceImpl) userTaskAdminService).setUserTaskService(userTaskService);
    ((UserTaskAdminServiceImpl) userTaskAdminService).setRuntimeDataService(runtimeDataService);
    ((UserTaskAdminServiceImpl) userTaskAdminService).setIdentityProvider(identityProvider);
    ((UserTaskAdminServiceImpl) userTaskAdminService).setCommandService(new TransactionalCommandService(emf));
    // now let's deploy to runtime both kjars
    deploymentUnit = new KModuleDeploymentUnit(ADMIN_GROUP_ID, ADMIN_ARTIFACT_ID, ADMIN_VERSION_V1);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    // set user to administrator so it will be allowed to do operations
    identityProvider.setName("Administrator");
    identityProvider.setRoles(Collections.singletonList(""));
}
Also used : ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Before(org.junit.Before)

Example 52 with KModuleDeploymentUnit

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

the class BPMN2DataServicesTest method testHumanTaskProcessBeforeAndAfterUndeploy.

@Test
public void testHumanTaskProcessBeforeAndAfterUndeploy() throws IOException {
    assertNotNull(deploymentService);
    DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    String processId = "org.jbpm.writedocument";
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentUnit.getIdentifier(), processId);
    assertNotNull(procDef);
    assertEquals(procDef.getId(), "org.jbpm.writedocument");
    assertEquals(procDef.getName(), "humanTaskSample");
    assertEquals(procDef.getKnowledgeType(), "PROCESS");
    assertEquals(procDef.getPackageName(), "defaultPackage");
    assertEquals(procDef.getType(), "RuleFlow");
    assertEquals(procDef.getVersion(), "3");
    // now let's undeploy the unit
    deploymentService.undeploy(deploymentUnit);
    try {
        bpmn2Service.getProcessDefinition(deploymentUnit.getIdentifier(), processId);
        fail("DeploymentNotFoundException was not thrown");
    } catch (DeploymentNotFoundException e) {
    // expected
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 53 with KModuleDeploymentUnit

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

the class BPMN2DataServicesTest method testGetProcessDefinitionUndeployedDeploymentUnit.

@Test(expected = DeploymentNotFoundException.class)
public void testGetProcessDefinitionUndeployedDeploymentUnit() throws IOException {
    assertNotNull(deploymentService);
    DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    deploymentService.undeploy(deploymentUnit);
    bpmn2Service.getProcessDefinition(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
}
Also used : KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 54 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit 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);
}
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) 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) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 55 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit 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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) CoundDownDeploymentListener(org.jbpm.kie.services.test.objects.CoundDownDeploymentListener) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ListenerSupport(org.jbpm.services.api.ListenerSupport) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) 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