private static ObjectModel getObjectModelParameter(String resolver, boolean named) { if (named) { return new NamedObjectModel(resolver, UUID.randomUUID().toString(), Integer.toString(random.nextInt(100000))); } else { return new ObjectModel(resolver, UUID.randomUUID().toString(), Integer.toString(random.nextInt(100000))); } } }
@Test public void testSimpleNoArgNamedObjectModel() { NamedObjectModel model = new NamedObjectModel("CustomObject", "org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject"); assertEquals("CustomObject", model.getName()); ObjectModelResolver resolver = new ReflectionObjectModelResolver(); Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>()); assertNotNull(result); assertTrue(result instanceof SimpleCustomObject); assertEquals("default", ((SimpleCustomObject) result).getName()); } }
.addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")) .addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[]{DefaultSignalManagerFactory.class.getName()})) .addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")) .addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")) .addGlobal(new NamedObjectModel("service", "java.util.ArrayList")) .addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")) .addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler")); resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
customDescriptor.getBuilder() .runtimeStrategy(RuntimeStrategy.PER_REQUEST) .addGlobal(new NamedObjectModel("service", "java.util.ArrayList"));
.addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()")); .persistenceUnit(null) .auditPersistenceUnit("") .addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.CustomSystemOutWorkItemHandler()"));
.runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE) .auditPersistenceUnit("org.jbpm.audit") .addGlobal(new NamedObjectModel("service", "org.jbpm.global.Service"));
.auditPersistenceUnit("my.custom.altered") .runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE) .addEnvironmentEntry(new NamedObjectModel("IS_JTA", "java.lang.Boolean", new Object[]{"false"}));
@Test public void testValidateMvelResolver() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.MVEL_RESOLVER, "item-name", "new String()"))); assertThat(validationMessages).isEmpty(); }
protected void addAsyncHandler(final KModuleDeploymentUnit unit, final InternalKieContainer kieContainer) { // add async only when the executor component is not disabled if (isExecutorAvailable && executorService != null) { final DeploymentDescriptor descriptor = getDeploymentDescriptor(unit, kieContainer); descriptor.getBuilder() .addWorkItemHandler(new NamedObjectModel("mvel", "async", "new org.jbpm.executor.impl.wih.AsyncWorkItemHandler(org.jbpm.executor.ExecutorServiceFactory.newExecutorService(null),\"org.jbpm.executor.commands.PrintOutCommand\")")); unit.setDeploymentDescriptor(descriptor); } }
@Test public void testValidateReflectionResolver() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.REFLECTION_RESOLVER, "item-name", "java.lang.String"))); assertThat(validationMessages).isEmpty(); }
@Test public void testValidateMvelResolver() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.MVEL_RESOLVER, "item-name", "new String()"))); assertThat(validationMessages).isEmpty(); }
@Test public void testValidateReflectionResolver() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.REFLECTION_RESOLVER, "item-name", "java.lang.String"))); assertThat(validationMessages).isEmpty(); }
@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()); }
protected DeploymentDescriptor createDeploymentDescriptor() { //add this listener by default listenerMvelDefinitions.add("new org.jbpm.casemgmt.impl.util.TrackingCaseEventListener()"); DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain"); DeploymentDescriptorBuilder ddBuilder = customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_CASE).addMarshalingStrategy(new ObjectModel("mvel", "org.jbpm.casemgmt.impl.marshalling.CaseMarshallerFactory.builder().withDoc().get()")).addWorkItemHandler(new NamedObjectModel("mvel", "StartCaseInstance", "new org.jbpm.casemgmt.impl.wih.StartCaseWorkItemHandler(ksession)")); listenerMvelDefinitions.forEach(listenerDefinition -> ddBuilder.addEventListener(new ObjectModel("mvel", listenerDefinition))); getProcessListeners().forEach(listener -> ddBuilder.addEventListener(listener)); getWorkItemHandlers().forEach(listener -> ddBuilder.addWorkItemHandler(listener)); return customDescriptor; }
@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()); }
@Test public void testValidateMvelResolverWithInvalidParameters() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.MVEL_RESOLVER, "item-name", "java.util.Arrays.asList(invalidParamExpr[);"))); assertThat(validationMessages).hasSize(1); ValidationMessage error = validationMessages.get(0); assertThat(error.getLevel()).isEqualTo(Level.WARNING); assertThat(error.getText()).startsWith("Could not compile mvel expression"); assertThat(error).isInstanceOf(DeploymentDescriptorValidationMessage.class); assertThat(((DeploymentDescriptorValidationMessage) error).getKey()).isEqualTo(I18N_KEY_NOT_VALID_MVEL_IDENTIFIER); }
@Test public void testValidateReflectionResolverInvalid() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.REFLECTION_RESOLVER, "item-name", "handler-classname"))); assertThat(validationMessages).hasSize(1); ValidationMessage error = validationMessages.get(0); assertThat(error.getLevel()).isEqualTo(Level.ERROR); assertThat(error.getText()).startsWith("Identifier is not valid Java class which is required by reflection resolver"); assertThat(error).isInstanceOf(DeploymentDescriptorValidationMessage.class); assertThat(((DeploymentDescriptorValidationMessage) error).getKey()).isEqualTo(I18N_KEY_NOT_VALID_REFLECTION_IDENTIFIER); }
@Test public void testValidateReflectionResolverNameEmpty() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.REFLECTION_RESOLVER, "", "java.lang.String"))); assertThat(validationMessages).hasSize(1); ValidationMessage error = validationMessages.get(0); assertThat(error.getLevel()).isEqualTo(Level.ERROR); assertThat(error.getText()).startsWith("Name cannot be empty"); assertThat(error).isInstanceOf(DeploymentDescriptorValidationMessage.class); assertThat(((DeploymentDescriptorValidationMessage) error).getKey()).isEqualTo(I18N_KEY_MISSING_NAME); }
@Test public void testValidateReflectionResolverInvalid() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.REFLECTION_RESOLVER, "item-name", "handler-classname"))); assertThat(validationMessages).hasSize(1); ValidationMessage error = validationMessages.get(0); assertThat(error.getLevel()).isEqualTo(Level.ERROR); assertThat(error.getText()).startsWith("Identifier is not valid Java class which is required by reflection resolver"); assertThat(error).isInstanceOf(DeploymentDescriptorValidationMessage.class); assertThat(((DeploymentDescriptorValidationMessage) error).getKey()).isEqualTo(I18N_KEY_NOT_VALID_REFLECTION_IDENTIFIER); }
@Test public void testValidateMvelResolverInvalid() { List<ValidationMessage> validationMessages = validateObjectModels(null, Collections.singletonList( new NamedObjectModel(ItemObjectModel.MVEL_RESOLVER, "item-name", "org.jbpm.process.workitem.bpmn2.ServiceTaskHandler(ksession, classLoader"))); assertThat(validationMessages).hasSize(1); ValidationMessage error = validationMessages.get(0); assertThat(error.getLevel()).isEqualTo(Level.WARNING); assertThat(error.getText()).startsWith("Could not compile mvel expression"); assertThat(error).isInstanceOf(DeploymentDescriptorValidationMessage.class); assertThat(((DeploymentDescriptorValidationMessage) error).getKey()).isEqualTo(I18N_KEY_NOT_VALID_MVEL_IDENTIFIER); } }