Search in sources :

Example 41 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project drools by kiegroup.

the class DeploymentDescriptorTest method testWriteDeploymentDescriptorXmlWithDuplicateNamedObjects.

@Test
public void testWriteDeploymentDescriptorXmlWithDuplicateNamedObjects() {
    DeploymentDescriptor descriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    descriptor.getBuilder().addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()")).addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.CustomSystemOutWorkItemHandler()")).addRequiredRole("experts");
    String deploymentDescriptorXml = descriptor.toXml();
    assertNotNull(deploymentDescriptorXml);
    logger.info(deploymentDescriptorXml);
    ByteArrayInputStream stream = new ByteArrayInputStream(deploymentDescriptorXml.getBytes());
    DeploymentDescriptor fromXml = DeploymentDescriptorIO.fromXml(stream);
    assertNotNull(fromXml);
    assertEquals("org.jbpm.domain", fromXml.getPersistenceUnit());
    assertEquals("org.jbpm.domain", fromXml.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, fromXml.getAuditMode());
    assertEquals(PersistenceMode.JPA, fromXml.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, fromXml.getRuntimeStrategy());
    assertEquals(0, fromXml.getMarshallingStrategies().size());
    assertEquals(0, fromXml.getConfiguration().size());
    assertEquals(0, fromXml.getEnvironmentEntries().size());
    assertEquals(0, fromXml.getEventListeners().size());
    assertEquals(0, fromXml.getGlobals().size());
    assertEquals(0, fromXml.getTaskEventListeners().size());
    assertEquals(1, fromXml.getWorkItemHandlers().size());
    assertEquals(1, fromXml.getRequiredRoles().size());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ByteArrayInputStream(java.io.ByteArrayInputStream) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Example 42 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project drools by kiegroup.

the class DeploymentDescriptorTest method testPrintDescriptor.

@Test
public void testPrintDescriptor() {
    DeploymentDescriptor descriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    descriptor.getBuilder().addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()")).addWorkItemHandler(new NamedObjectModel("mvel", "WebService", "new org.jbpm.process.workitem.webservice.WebServiceWorkItemHandler(ksession)")).addWorkItemHandler(new NamedObjectModel("mvel", "Rest", "new org.jbpm.process.workitem.rest.RESTWorkItemHandler()")).addWorkItemHandler(new NamedObjectModel("mvel", "Service Task", "new org.jbpm.process.workitem.bpmn2.ServiceTaskHandler(ksession)"));
    logger.debug(descriptor.toXml());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Example 43 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project drools by kiegroup.

the class DeploymentDescriptorTest method testEmptyDeploymentDescriptor.

@Test
public void testEmptyDeploymentDescriptor() {
    DeploymentDescriptorImpl descriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    descriptor.getBuilder().addMarshalingStrategy(new ObjectModel("org.jbpm.testCustomStrategy", new Object[] { new ObjectModel("java.lang.String", new Object[] { "param1" }), "param2" })).addRequiredRole("experts");
    assertFalse(descriptor.isEmpty());
    InputStream input = this.getClass().getResourceAsStream("/deployment/empty-descriptor.xml");
    DeploymentDescriptor fromXml = DeploymentDescriptorIO.fromXml(input);
    assertNotNull(fromXml);
    assertTrue(((DeploymentDescriptorImpl) fromXml).isEmpty());
    assertNull(fromXml.getPersistenceUnit());
    assertNull(fromXml.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, fromXml.getAuditMode());
    assertEquals(PersistenceMode.JPA, fromXml.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, fromXml.getRuntimeStrategy());
    assertEquals(0, fromXml.getMarshallingStrategies().size());
    assertEquals(0, fromXml.getConfiguration().size());
    assertEquals(0, fromXml.getEnvironmentEntries().size());
    assertEquals(0, fromXml.getEventListeners().size());
    assertEquals(0, fromXml.getGlobals().size());
    assertEquals(0, fromXml.getTaskEventListeners().size());
    assertEquals(0, fromXml.getWorkItemHandlers().size());
    assertEquals(0, fromXml.getRequiredRoles().size());
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Example 44 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project drools by kiegroup.

the class DeploymentDescriptorMergerTest method testDeploymentDesciptorMergeOverrideEmpty.

@Test
public void testDeploymentDesciptorMergeOverrideEmpty() {
    DeploymentDescriptor primary = new DeploymentDescriptorImpl("org.jbpm.domain");
    primary.getBuilder().addMarshalingStrategy(new ObjectModel("org.jbpm.test.CustomStrategy", new Object[] { "param2" })).setLimitSerializationClasses(true);
    assertNotNull(primary);
    assertEquals("org.jbpm.domain", primary.getPersistenceUnit());
    assertEquals("org.jbpm.domain", primary.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, primary.getAuditMode());
    assertEquals(PersistenceMode.JPA, primary.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, primary.getRuntimeStrategy());
    assertEquals(1, primary.getMarshallingStrategies().size());
    assertEquals(0, primary.getConfiguration().size());
    assertEquals(0, primary.getEnvironmentEntries().size());
    assertEquals(0, primary.getEventListeners().size());
    assertEquals(0, primary.getGlobals().size());
    assertEquals(0, primary.getTaskEventListeners().size());
    assertEquals(0, primary.getWorkItemHandlers().size());
    assertTrue(primary.getLimitSerializationClasses());
    DeploymentDescriptor secondary = new DeploymentDescriptorImpl("org.jbpm.domain");
    secondary.getBuilder().auditMode(AuditMode.JMS).persistenceMode(PersistenceMode.JPA).persistenceUnit(null).auditPersistenceUnit("");
    assertNotNull(secondary);
    assertEquals(null, secondary.getPersistenceUnit());
    assertEquals("", secondary.getAuditPersistenceUnit());
    assertEquals(AuditMode.JMS, secondary.getAuditMode());
    assertEquals(PersistenceMode.JPA, secondary.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, secondary.getRuntimeStrategy());
    assertEquals(0, secondary.getMarshallingStrategies().size());
    assertEquals(0, secondary.getConfiguration().size());
    assertEquals(0, secondary.getEnvironmentEntries().size());
    assertEquals(0, secondary.getEventListeners().size());
    assertEquals(0, secondary.getGlobals().size());
    assertEquals(0, secondary.getTaskEventListeners().size());
    assertEquals(0, secondary.getWorkItemHandlers().size());
    ((DeploymentDescriptorImpl) secondary).setLimitSerializationClasses(null);
    assertNull(secondary.getLimitSerializationClasses());
    // and now let's merge them
    DeploymentDescriptor outcome = DeploymentDescriptorMerger.merge(primary, secondary, MergeMode.OVERRIDE_EMPTY);
    assertNotNull(outcome);
    assertEquals("org.jbpm.domain", outcome.getPersistenceUnit());
    assertEquals("org.jbpm.domain", outcome.getAuditPersistenceUnit());
    assertEquals(AuditMode.JMS, outcome.getAuditMode());
    assertEquals(PersistenceMode.JPA, outcome.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, outcome.getRuntimeStrategy());
    assertEquals(1, outcome.getMarshallingStrategies().size());
    assertEquals(0, outcome.getConfiguration().size());
    assertEquals(0, outcome.getEnvironmentEntries().size());
    assertEquals(0, outcome.getEventListeners().size());
    assertEquals(0, outcome.getGlobals().size());
    assertEquals(0, outcome.getTaskEventListeners().size());
    assertEquals(0, outcome.getWorkItemHandlers().size());
    assertTrue(outcome.getLimitSerializationClasses());
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Example 45 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project drools by kiegroup.

the class DeploymentDescriptorMergerTest method testDeploymentDesciptorMergeHierarchy.

@Test
public void testDeploymentDesciptorMergeHierarchy() {
    DeploymentDescriptor primary = new DeploymentDescriptorImpl("org.jbpm.domain");
    primary.getBuilder().addMarshalingStrategy(new ObjectModel("org.jbpm.test.CustomStrategy", new Object[] { "param2" }));
    assertNotNull(primary);
    assertEquals("org.jbpm.domain", primary.getPersistenceUnit());
    assertEquals("org.jbpm.domain", primary.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, primary.getAuditMode());
    assertEquals(PersistenceMode.JPA, primary.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, primary.getRuntimeStrategy());
    assertEquals(1, primary.getMarshallingStrategies().size());
    assertEquals(0, primary.getConfiguration().size());
    assertEquals(0, primary.getEnvironmentEntries().size());
    assertEquals(0, primary.getEventListeners().size());
    assertEquals(0, primary.getGlobals().size());
    assertEquals(0, primary.getTaskEventListeners().size());
    assertEquals(0, primary.getWorkItemHandlers().size());
    DeploymentDescriptor secondary = new DeploymentDescriptorImpl("org.jbpm.domain");
    secondary.getBuilder().auditMode(AuditMode.NONE).persistenceMode(PersistenceMode.JPA).persistenceUnit("my.custom.unit").auditPersistenceUnit("my.custom.unit2");
    assertNotNull(secondary);
    assertEquals("my.custom.unit", secondary.getPersistenceUnit());
    assertEquals("my.custom.unit2", secondary.getAuditPersistenceUnit());
    assertEquals(AuditMode.NONE, secondary.getAuditMode());
    assertEquals(PersistenceMode.JPA, secondary.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, secondary.getRuntimeStrategy());
    assertEquals(0, secondary.getMarshallingStrategies().size());
    assertEquals(0, secondary.getConfiguration().size());
    assertEquals(0, secondary.getEnvironmentEntries().size());
    assertEquals(0, secondary.getEventListeners().size());
    assertEquals(0, secondary.getGlobals().size());
    assertEquals(0, secondary.getTaskEventListeners().size());
    assertEquals(0, secondary.getWorkItemHandlers().size());
    DeploymentDescriptor third = new DeploymentDescriptorImpl("org.jbpm.domain");
    third.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(third);
    assertEquals("my.custom.unit2", third.getPersistenceUnit());
    assertEquals("my.custom.altered", third.getAuditPersistenceUnit());
    assertEquals(AuditMode.JMS, third.getAuditMode());
    assertEquals(PersistenceMode.JPA, third.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, third.getRuntimeStrategy());
    assertEquals(0, third.getMarshallingStrategies().size());
    assertEquals(0, third.getConfiguration().size());
    assertEquals(1, third.getEnvironmentEntries().size());
    assertEquals(0, third.getEventListeners().size());
    assertEquals(0, third.getGlobals().size());
    assertEquals(0, third.getTaskEventListeners().size());
    assertEquals(0, third.getWorkItemHandlers().size());
    // assemble hierarchy
    List<DeploymentDescriptor> hierarchy = new ArrayList<DeploymentDescriptor>();
    hierarchy.add(third);
    hierarchy.add(secondary);
    hierarchy.add(primary);
    // and now let's merge them
    DeploymentDescriptor outcome = DeploymentDescriptorMerger.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());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)98 Test (org.junit.Test)55 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)43 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)34 HashMap (java.util.HashMap)27 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)26 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)23 KieServices (org.kie.api.KieServices)22 ArrayList (java.util.ArrayList)21 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)21 ReleaseId (org.kie.api.builder.ReleaseId)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 File (java.io.File)13 KieMavenRepository (org.kie.scanner.KieMavenRepository)12 FileOutputStream (java.io.FileOutputStream)11 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)11 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)10 InputStream (java.io.InputStream)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)8