Refine search
@Test @RequirePersistence public void testEventTypesLifeCycle() throws Exception { ksession.startProcess("BPMN2-IntermediateCatchSignalBetweenUserTasks"); int signalListSize = ksession.execute(new ExecutableCommand<Integer>() { public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); signalListSize = ksession.execute(new ExecutableCommand<Integer>() { public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); signalListSize = ksession.execute(new ExecutableCommand<Integer>() { public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
@Test public void testMultiInstanceLoopCharacteristicsProcess2() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultiInstanceProcessWithOutputOnTask.bpmn2"); assertEquals(2, workItems.size()); myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput")); assertNull(myOutList); ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), results); myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput")); assertNull(myOutList); ksession.getWorkItemManager().completeWorkItem(workItems.get(1).getId(), results); myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput")); assertNotNull(myOutList); assertEquals(2, myOutList.size());
@Test public void testDynamicCatchEventSignalWithVariableUpdated() throws Exception { KieBase kbase = createKnowledgeBase("subprocess/dynamic-signal-parent.bpmn2", "subprocess/dynamic-signal-child.bpmn2"); Map<String, Object> updatedVariables = new HashMap<>(); updatedVariables.put("fatherId", 999L); ksession.execute(new SetProcessInstanceVariablesCommand(changeProcessInstanceId, updatedVariables));
@RequirePersistence @Test public void testDynamicCatchEventSignalWithVariableUpdatedBroadcastSignal() throws Exception { KieBase kbase = createKnowledgeBase("subprocess/dynamic-signal-parent.bpmn2", "subprocess/dynamic-signal-child.bpmn2"); Map<String, Object> updatedVariables = new HashMap<>(); updatedVariables.put("fatherId", 999L); ksession.execute(new SetProcessInstanceVariablesCommand(changeProcessInstanceId, updatedVariables));
@Test public void testVarAndNodeInstanceCommands() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-SubProcessUserTask.bpmn2"); Object result = ksession.execute(cmd); assertNotNull( "Command result is empty!", result ); assertTrue( result instanceof List ); result = ksession.execute(cmd); assertNotNull( "Command result is empty!", result ); assertTrue( result instanceof List ); result = ksession.execute(cmd); assertNotNull( "Command result is empty!", result ); assertTrue( result instanceof List );
@Test public void testFindProcessInstanceCommands() throws Exception { String processId = "IntermediateCatchEvent"; Object result = ksession.execute(cmd); assertNotNull( "Command result is empty!", result ); assertTrue( result instanceof List ); result = ksession.execute(cmd); assertNotNull( "Command result is empty!", result ); assertTrue( result instanceof List ); result = ksession.execute(cmd); assertNotNull( "Command result is empty!", result ); assertTrue( result instanceof ProcessInstanceLog ); result = ksession.execute(cmd); assertEquals( "There should be no more logs", 0, logService.findProcessInstances().size() );
@Test(timeout=10000) @RequirePersistence public void testIntermediateCatchEventTimerDurationWithError() throws Exception { NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1); KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2"); ksession = createKnowledgeSession(kbase); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler()); ksession.addEventListener(countDownListener); Map<String, Object> params = new HashMap<String, Object>(); params.put("x", 0); ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params); long waitTime = 2; assertProcessInstanceActive(processInstance); // now wait for 1 second for timer to trigger countDownListener.waitTillCompleted(waitTime * 1000); assertProcessInstanceActive(processInstance); processInstance = ksession.getProcessInstance(processInstance.getId()); // reschedule it to allow to move on ksession.setGlobal("TestOK", Boolean.TRUE); ksession.execute(new UpdateTimerCommand(processInstance.getId(), "timer", waitTime + 1)); countDownListener.reset(1); countDownListener.waitTillCompleted(); assertProcessInstanceFinished(processInstance, ksession); }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testInsertElementsCommand() throws Exception { String expected_1 = "expected_1"; String expected_2 = "expected_2"; Object [] expectedArr = {expected_1, expected_2}; Collection<Object> factCollection = Arrays.asList(expectedArr); List<Command<?>> commands = new ArrayList<Command<?>>(); commands.add(CommandFactory.newInsertElements(factCollection, "out_list", true, null)); Command cmds = CommandFactory.newBatchExecution( commands ); ExecutionResults result = (ExecutionResults) ksession.execute( cmds ); Collection<? extends Object> outList = (Collection<? extends Object>) result.getValue("out_list"); assertNotNull(outList); ksession.fireAllRules(); List<Object> expectedList = new ArrayList<Object>(Arrays.asList(expectedArr)); Collection<? extends Object> factList = ksession.getObjects(); assertTrue("Expected " + expectedList.size() + " objects but retrieved " + factList.size(), factList.size() == expectedList.size() ); for( Object fact : factList ) { if( expectedList.contains(fact) ) { expectedList.remove(fact); } } assertTrue("Retrieved object list did not contain expected objects.", expectedList.isEmpty() ); }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testSetGlobalCommand() throws Exception { ksession.insert(new Integer(5)); ksession.insert(new Integer(7)); ksession.fireAllRules(); List<Command<?>> commands = new ArrayList<Command<?>>(); commands.add(CommandFactory.newSetGlobal( "globalCheeseCountry", "France", true )); Command cmds = CommandFactory.newBatchExecution( commands ); ExecutionResults result = (ExecutionResults) ksession.execute( cmds ); assertNotNull(result); Object global = result.getValue("globalCheeseCountry"); assertNotNull(global); assertEquals("France", global); }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testGetGlobalCommand() throws Exception { ksession.insert(new Integer(5)); ksession.insert(new Integer(7)); ksession.fireAllRules(); ksession.setGlobal("globalCheeseCountry", "France"); List<Command<?>> commands = new ArrayList<Command<?>>(); commands.add(CommandFactory.newGetGlobal( "globalCheeseCountry", "cheeseCountry" )); Command cmds = CommandFactory.newBatchExecution( commands ); ExecutionResults result = (ExecutionResults) ksession.execute( cmds ); assertNotNull("GetGlobalCommand result is null!", result); Object global = result.getValue("cheeseCountry"); assertNotNull("Retrieved global fact is null!", global); assertEquals("Retrieved global is not equal to 'France'.", "France", global ); }
@Test public void testModifyCommand() { final String str = "rule \"sample rule\"\n" + " when\n" + " then\n" + " System.out.println(\"\\\"Hello world!\\\"\");\n" + "end"; final KieBase kbase = loadKnowledgeBaseFromString(str); final KieSession ksession = kbase.newKieSession(); final Person p1 = new Person("John", "nobody", 25); ksession.execute(CommandFactory.newInsert(p1)); final FactHandle fh = ksession.getFactHandle(p1); final Person p = new Person("Frank", "nobody", 30); final List<Setter> setterList = new ArrayList<Setter>(); setterList.add(CommandFactory.newSetter("age", String.valueOf(p.getAge()))); setterList.add(CommandFactory.newSetter("name", p.getName())); setterList.add(CommandFactory.newSetter("likes", p.getLikes())); ksession.execute(CommandFactory.newModify(fh, setterList)); }
@Test public void testEnableAuditLogCommand() throws Exception { String str = ""; str += "package org.drools.compiler.integrationtests \n"; str += "import " + Cheese.class.getCanonicalName() + " \n"; str += "rule StringRule \n"; str += " when \n"; str += " $c : Cheese() \n"; str += " then \n"; str += " System.out.println($c); \n"; str += "end \n"; KieSession kSession = new KieHelper().addContent( str, ResourceType.DRL ) .build().newKieSession(); List<Command> commands = new ArrayList<Command>(); commands.add( CommandFactory.newEnableAuditLog( auditFileDir, auditFileName ) ); commands.add( CommandFactory.newInsert( new Cheese() ) ); commands.add( CommandFactory.newFireAllRules() ); kSession.execute( CommandFactory.newBatchExecution( commands ) ); kSession.dispose(); File file = new File( auditFileDir + File.separator + auditFileName + ".log" ); assertTrue( file.exists() ); } }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testGetObjectCommand() throws Exception { String expected_1 = "expected_1"; String expected_2 = "expected_2"; FactHandle handle_1 = ksession.insert( expected_1 ); FactHandle handle_2 = ksession.insert( expected_2 ); ksession.fireAllRules(); Object fact = ksession.getObject(handle_1); assertNotNull(fact); assertEquals(expected_1, fact); List<Command<?>> commands = new ArrayList<Command<?>>(); commands.add(CommandFactory.newGetObject(handle_1, "out_1")); commands.add(CommandFactory.newGetObject(handle_2, "out_2")); Command cmds = CommandFactory.newBatchExecution( commands ); ExecutionResults result = (ExecutionResults) ksession.execute( cmds ); assertNotNull("GetObjectCommand result is null!", result); assertEquals( expected_1, result.getValue("out_1") ); assertEquals( expected_2, result.getValue("out_2") ); }
@Test public void testFireAllRules() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/drl/test_ImportFunctions.drl"), ResourceType.DRL); if (kbuilder.hasErrors()) { fail(kbuilder.getErrors().toString()); } InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages(kbuilder.getKnowledgePackages()); ksession = createKnowledgeSession(kbase); final Cheese cheese = new Cheese("stilton", 15); ksession.insert(cheese); List<?> list = new ArrayList(); ksession.setGlobal("list", list); List<Command<?>> commands = new ArrayList<Command<?>>(); commands.add(CommandFactory.newFireAllRules("fired")); Command<?> cmds = CommandFactory.newBatchExecution(commands); ExecutionResults result = (ExecutionResults) ksession.execute(cmds); assertNotNull("Batch execution result is null!", result); Object firedObject = result.getValue("fired"); assertTrue("Retrieved object is null or incorrect!", firedObject != null && firedObject instanceof Integer); assertEquals(4, firedObject); list = (List<?>) ksession.getGlobal("list"); assertEquals(4, list.size()); assertEquals("rule1", list.get(0)); assertEquals("rule2", list.get(1)); assertEquals("rule3", list.get(2)); assertEquals("rule4", list.get(3)); }