Search in sources :

Example 16 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository 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());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) File(java.io.File) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 17 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository 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());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 18 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class KieScannerTest method testKScanner.

@Test
public void testKScanner() throws Exception {
    List<String> results = new ArrayList<String>();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("results", results);
    InternalKieModule kJar1 = createJbpmKieJar("Hello");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployArtifact(releaseId, kJar1, kPom);
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    ProcessInstance processInstance = ksession.startProcess("Minimal", params);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);
    assertEquals(1, results.size());
    assertEquals("Hello", results.get(0));
    results.clear();
    InternalKieModule kJar2 = createJbpmKieJar("Morning");
    repository.deployArtifact(releaseId, kJar2, kPom);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    scanner.scanNow();
    // create a ksesion and check it works as expected
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    ProcessInstance processInstance2 = ksession2.startProcess("Minimal", params);
    assertTrue(processInstance2.getState() == ProcessInstance.STATE_COMPLETED);
    assertEquals(1, results.size());
    assertEquals("Morning", results.get(0));
    results.clear();
    ks.getRepository().removeKieModule(releaseId);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 19 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class ProcessServiceImplTest method prepare.

@Before
public void prepare() {
    configureServices();
    logger.debug("Preparing kjar");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, 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");
    processes.add("repo/processes/general/signal.bpmn");
    processes.add("repo/processes/general/signalWithExpression.bpmn2");
    processes.add("repo/processes/general/callactivity.bpmn");
    processes.add("repo/processes/general/boundarysignal.bpmn2");
    processes.add("repo/processes/general/boundarysignalwithexpression.bpmn2");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    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);
    ReleaseId releaseId3 = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, "1.1.0-SNAPSHOT");
    InternalKieModule kJar3 = createKieJar(ks, releaseId3, processes);
    File pom3 = new File("target/kmodule3", "pom.xml");
    pom3.getParentFile().mkdirs();
    try {
        FileOutputStream fs = new FileOutputStream(pom3);
        fs.write(getPom(releaseId3).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    repository = getKieMavenRepository();
    repository.deployArtifact(releaseId3, kJar3, pom3);
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Before(org.junit.Before)

Example 20 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest 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");
    processes.add("repo/processes/general/BPMN2-IntermediateCatchEventTimerDuration.bpmn2");
    processes.add("repo/processes/errors/BPMN2-BrokenScriptTask.bpmn2");
    processes.add("repo/processes/errors/BPMN2-UserTaskWithRollback.bpmn2");
    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);
    processAdminService = new ProcessInstanceAdminServiceImpl();
    ((ProcessInstanceAdminServiceImpl) processAdminService).setProcessService(processService);
    ((ProcessInstanceAdminServiceImpl) processAdminService).setRuntimeDataService(runtimeDataService);
    ((ProcessInstanceAdminServiceImpl) processAdminService).setCommandService(new TransactionalCommandService(emf));
    ((ProcessInstanceAdminServiceImpl) processAdminService).setIdentityProvider(identityProvider);
    // 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);
}
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) 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)

Aggregations

KieMavenRepository (org.kie.scanner.KieMavenRepository)58 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)55 KieServices (org.kie.api.KieServices)54 ReleaseId (org.kie.api.builder.ReleaseId)53 File (java.io.File)51 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)51 FileOutputStream (java.io.FileOutputStream)45 ArrayList (java.util.ArrayList)42 Before (org.junit.Before)32 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)17 HashMap (java.util.HashMap)15 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)15 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)12 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)12 Test (org.junit.Test)10 KieContainer (org.kie.api.runtime.KieContainer)7 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)5 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)5 IOException (java.io.IOException)4 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)4