@Test public void insertObjectCommandListTest() throws Exception { List<String> objectList = new ArrayList<String>(); objectList.add("obj"); InsertObjectCommand cmd = new InsertObjectCommand(objectList, "out-id"); InsertObjectCommand copyCmd = roundTrip(cmd); assertNotNull(copyCmd); assertThat(copyCmd.getObject(), is(instanceOf(List.class))); assertEquals( "object", cmd.getObject(), copyCmd.getObject()); }
@Test public void insertObjectCommandEmptyListTest() throws Exception { List<String> objectList = new ArrayList<String>(); objectList.add("one-element"); InsertObjectCommand cmd = new InsertObjectCommand(objectList, "out-id"); // test list with 1 element InsertObjectCommand copyCmd = roundTrip(cmd); assertNotNull(copyCmd); assertThat(copyCmd.getObject(), is(instanceOf(List.class))); assertEquals( "object", cmd.getObject(), copyCmd.getObject()); // test empty list objectList.clear(); copyCmd = roundTrip(cmd); assertNotNull(copyCmd); assertThat(copyCmd.getObject(), is(instanceOf(List.class))); assertEquals( "object", cmd.getObject(), copyCmd.getObject()); }
cmds.add(new InsertObjectCommand(new String("Hi!"), "handle")); cmds.add(new InsertObjectCommand(new String("Hi!"), "handle")); batchCmd = CommandFactory.newBatchExecution(cmds, "kresults"); execCmd = new ExecuteCommand(batchCmd);
InsertObjectCommand cmd = new InsertObjectCommand(); cmd.setEntryPoint("entry-point"); cmd.setOutIdentifier("out-id");
@Test public void insertObjectCommandTest() throws Exception { InsertObjectCommand cmd = new InsertObjectCommand("obj", "out-id"); cmd.setReturnObject(false); cmd.setEntryPoint("entry-point"); InsertObjectCommand copyCmd = roundTrip(cmd); assertEquals( "object", cmd.getObject(), copyCmd.getObject()); assertEquals( "out id", cmd.getOutIdentifier(), copyCmd.getOutIdentifier() ); assertEquals( "return obj", cmd.isReturnObject(), copyCmd.isReturnObject() ); assertEquals( "entry point", cmd.getEntryPoint(), copyCmd.getEntryPoint() ); assertEquals( "disconnected", cmd.isDisconnected(), copyCmd.isDisconnected() ); }
@Test public void test1() throws Exception { JAXBContext jaxbContext = getJaxbContext(); List<Command<?>> cmds = new ArrayList<>(); cmds.add(new InsertObjectCommand(new Person("darth", 21), "p")); cmds.add(new GetGlobalCommand("xxx")); cmds.add(new SetGlobalCommand("yyy", new Person("yoda", 21))); BatchExecutionCommandImpl batch = new BatchExecutionCommandImpl(cmds); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); marshaller.marshal(batch, baos); logger.debug("{}", baos); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); BatchExecutionCommandImpl batch2 = (BatchExecutionCommandImpl)unmarshaller.unmarshal(new ByteArrayInputStream(baos.toByteArray())); baos = new ByteArrayOutputStream(); marshaller.marshal(batch2, baos); logger.debug("{}", baos); }
@Test public void test1() throws Exception { JAXBContext jaxbContext = getJaxbContext(); List<GenericCommand< ? >> cmds = new ArrayList<GenericCommand< ? >>(); cmds.add( new InsertObjectCommand( new Person( "darth", 21 ), "p" ) ); cmds.add( new GetGlobalCommand( "xxx" ) ); cmds.add( new SetGlobalCommand( "yyy", new Person( "yoda", 21 ) ) ); BatchExecutionCommandImpl batch = new BatchExecutionCommandImpl( cmds ); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); marshaller.marshal( batch, baos ); System.out.println( baos ); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); BatchExecutionCommandImpl batch2 = (BatchExecutionCommandImpl) unmarshaller.unmarshal( new ByteArrayInputStream( baos.toByteArray() ) ); baos = new ByteArrayOutputStream(); marshaller.marshal( batch2, baos ); System.out.println( baos ); }
@Test public void testSessionInsert() throws Exception { BatchExecutionCommandImpl cmd = new BatchExecutionCommandImpl(); cmd.setLookup("ksession1"); cmd.addCommand(new InsertObjectCommand(new Person("lucaz", 25), "person1")); cmd.addCommand(new InsertObjectCommand(new Person("hadrian", 25), "person2")); cmd.addCommand(new InsertObjectCommand(new Person("baunax", 21), "person3")); cmd.addCommand(new FireAllRulesCommand()); StringWriter xmlReq = new StringWriter(); Marshaller marshaller = getJaxbContext().createMarshaller(); marshaller.setProperty("jaxb.formatted.output", true); marshaller.marshal(cmd, xmlReq); logger.debug(xmlReq.toString()); byte[] xmlResp = (byte[])template.requestBody("direct:test-with-session", xmlReq.toString()); assertNotNull(xmlResp); logger.debug(new String(xmlResp)); ExecutionResults resp = (ExecutionResults)getJaxbContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xmlResp)); assertNotNull(resp); assertEquals(3, resp.getIdentifiers().size()); assertNotNull(resp.getValue("person1")); assertNotNull(resp.getValue("person2")); assertNotNull(resp.getValue("person3")); assertNotNull(resp.getFactHandle("person1")); assertNotNull(resp.getFactHandle("person2")); assertNotNull(resp.getFactHandle("person3")); }
@Override protected void configureDroolsContext(javax.naming.Context jndiContext) { Person me = new Person(); me.setName("Hadrian"); KieSession ksession = registerKnowledgeRuntime("ksession1", null); InsertObjectCommand cmd = new InsertObjectCommand(me); cmd.setOutIdentifier("camel-rider"); cmd.setReturnObject(false); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl(Arrays.asList(new Command<?>[] {cmd})); ExecutionResults results = ksession.execute(script); handle = ((FactHandle)results.getFactHandle("camel-rider")).toExternalForm(); }
@Override protected void configureDroolsContext(Context jndiContext) { Person me = new Person(); me.setName("Hadrian"); KieSession ksession = registerKnowledgeRuntime("ksession1", null); InsertObjectCommand cmd = new InsertObjectCommand(me); cmd.setOutIdentifier("camel-rider"); cmd.setReturnObject(false); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl(Arrays.asList(new Command<?>[] {cmd})); ExecutionResults results = ksession.execute(script); handle = ((FactHandle)results.getFactHandle("camel-rider")).toExternalForm(); } }
@Override protected void configureDroolsContext(Context jndiContext) { Person me = new Person(); me.setName("Hadrian"); KieSession ksession = registerKnowledgeRuntime("ksession1", null); InsertObjectCommand cmd = new InsertObjectCommand(me); cmd.setOutIdentifier("camel-rider"); cmd.setReturnObject(false); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl(Arrays.asList(new Command<?>[] {cmd})); ExecutionResults results = ksession.execute(script); handle = ((FactHandle)results.getFactHandle("camel-rider")).toExternalForm(); } }
@Override protected void configureDroolsContext(javax.naming.Context jndiContext) { Person me = new Person(); me.setName( "Hadrian" ); StatefulKnowledgeSession ksession = registerKnowledgeRuntime( "ksession1", null ); InsertObjectCommand cmd = new InsertObjectCommand( me ); cmd.setOutIdentifier( "camel-rider" ); cmd.setReturnObject( false ); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl( Arrays.asList( new GenericCommand< ? >[]{cmd} ) ); ExecutionResults results = ksession.execute( script ); handle = ((FactHandle) results.getFactHandle( "camel-rider" )).toExternalForm(); }
@Override protected void configureDroolsContext(Context jndiContext) { Person me = new Person(); me.setName( "Hadrian" ); StatefulKnowledgeSession ksession = registerKnowledgeRuntime( "ksession1", null ); InsertObjectCommand cmd = new InsertObjectCommand( me ); cmd.setOutIdentifier( "camel-rider" ); cmd.setReturnObject( false ); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl( Arrays.asList( new GenericCommand< ? >[]{cmd} ) ); ExecutionResults results = ksession.execute( script ); handle = ((FactHandle) results.getFactHandle( "camel-rider" )).toExternalForm(); } }
@Override protected void configureDroolsContext(Context jndiContext) { Person me = new Person(); me.setName( "Hadrian" ); StatefulKnowledgeSession ksession = registerKnowledgeRuntime( "ksession1", null ); InsertObjectCommand cmd = new InsertObjectCommand( me ); cmd.setOutIdentifier( "camel-rider" ); cmd.setReturnObject( false ); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl( Arrays.asList( new GenericCommand< ? >[]{cmd} ) ); ExecutionResults results = ksession.execute( script ); handle = ((FactHandle) results.getFactHandle( "camel-rider" )).toExternalForm(); } }
@Test public void testWorkingSetGlobalTestSessionSetAndGetGlobal() throws Exception { BatchExecutionCommandImpl cmd = new BatchExecutionCommandImpl(); cmd.setLookup("ksession1"); SetGlobalCommand setGlobal = new SetGlobalCommand("list", new WrappedList()); setGlobal.setOutIdentifier("list"); cmd.addCommand(setGlobal); cmd.addCommand(new InsertObjectCommand(new Person("baunax"))); cmd.addCommand(new FireAllRulesCommand()); cmd.addCommand(new GetGlobalCommand("list")); Marshaller marshaller = getJaxbContext().createMarshaller(); marshaller.setProperty("jaxb.formatted.output", true); StringWriter xml = new StringWriter(); marshaller.marshal(cmd, xml); logger.debug(xml.toString()); byte[] response = (byte[])template.requestBody("direct:test-with-session", xml.toString()); assertNotNull(response); logger.debug("response:\n" + new String(response)); Unmarshaller unmarshaller = getJaxbContext().createUnmarshaller(); ExecutionResults res = (ExecutionResults)unmarshaller.unmarshal(new ByteArrayInputStream(response)); WrappedList resp = (WrappedList)res.getValue("list"); assertNotNull(resp); assertEquals(resp.size(), 2); assertEquals("baunax", resp.get(0).getName()); assertEquals("Hadrian", resp.get(1).getName()); }
@Test public void factHandleTest() throws Exception { // Don't run with YAML? Assume.assumeFalse(getType().equals(TestType.YAML)); KieSession ksession = createKnowledgeSession(null); InsertObjectCommand cmd = new InsertObjectCommand("The Sky is Green"); FactHandle factHandle = ksession.execute(cmd); JaxbOtherResponse jor = new JaxbOtherResponse(factHandle, 0, cmd); testRoundTrip(jor); }
@Test public void factHandleTest() throws Exception { RuntimeEngine runtimeEngine = createRuntimeManager("BPMN2-StringStructureRef.bpmn2").getRuntimeEngine(null); KieSession ksession = runtimeEngine.getKieSession(); InsertObjectCommand cmd = new InsertObjectCommand("The Sky is Green"); FactHandle factHandle = ksession.execute(cmd); addClassesToSerializationProvider(DisconnectedFactHandle.class); JaxbOtherResponse jor = new JaxbOtherResponse(DisconnectedFactHandle.newFrom(factHandle), 0, cmd); testRoundTrip(jor); }
@Override protected void configureDroolsContext(javax.naming.Context jndiContext) { Person me = new Person(); me.setName( "Hadrian" ); String rule = ""; rule += "package org.drools.pipeline.camel \n"; rule += "import org.drools.pipeline.camel.Person \n"; rule += "global java.util.List list \n"; rule += "query persons \n"; rule += " $p : Person(name != null) \n"; rule += "end \n"; rule += "query personWithName(String param)\n"; rule += " $p : Person(name == param) \n"; rule += "end \n"; rule += "rule rule1 \n"; rule += " when \n"; rule += " $p : Person() \n"; rule += " \n"; rule += " then \n"; rule += " System.out.println(\"executed\"); \n"; rule += "end\n"; StatefulKnowledgeSession ksession = registerKnowledgeRuntime( "ksession1", rule ); InsertObjectCommand cmd = new InsertObjectCommand( me ); cmd.setOutIdentifier( "camel-rider" ); cmd.setReturnObject( false ); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl( Arrays.asList( new GenericCommand< ? >[]{cmd} ) ); ExecutionResults results = ksession.execute( script ); handle = ((FactHandle) results.getFactHandle( "camel-rider" )).toExternalForm(); }
@Override protected void configureDroolsContext(Context jndiContext) { Person me = new Person(); me.setName("Hadrian"); String rule = ""; rule += "package org.kie.pipeline.camel \n"; rule += "import org.kie.pipeline.camel.Person\n"; rule += "import org.kie.pipeline.camel.WrappedList\n"; rule += "global WrappedList list\n"; rule += "rule rule1 \n"; rule += " when \n"; rule += " $p : Person() \n"; rule += " \n"; rule += " then \n"; rule += " System.out.println(\"executed\"); \n"; rule += " list.add($p); \n"; rule += "end\n"; KieSession ksession = registerKnowledgeRuntime("ksession1", rule); InsertObjectCommand cmd = new InsertObjectCommand(me); cmd.setOutIdentifier("camel-rider"); cmd.setReturnObject(false); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl(Arrays.asList(new Command<?>[] {cmd})); ExecutionResults results = ksession.execute(script); handle = ((FactHandle)results.getFactHandle("camel-rider")).toExternalForm(); }
@Override protected void configureDroolsContext(Context jndiContext) { Person me = new Person(); me.setName( "Hadrian" ); String rule = ""; rule += "package org.drools.pipeline.camel \n"; rule += "import org.drools.pipeline.camel.Person\n"; rule += "import org.drools.pipeline.camel.WrappedList\n"; rule += "global WrappedList list\n"; rule += "rule rule1 \n"; rule += " when \n"; rule += " $p : Person() \n"; rule += " \n"; rule += " then \n"; rule += " System.out.println(\"executed\"); \n"; rule += " list.add($p); \n"; rule += "end\n"; StatefulKnowledgeSession ksession = registerKnowledgeRuntime( "ksession1", rule ); InsertObjectCommand cmd = new InsertObjectCommand( me ); cmd.setOutIdentifier( "camel-rider" ); cmd.setReturnObject( false ); BatchExecutionCommandImpl script = new BatchExecutionCommandImpl( Arrays.asList( new GenericCommand< ? >[]{cmd} ) ); ExecutionResults results = ksession.execute( script ); handle = ((FactHandle) results.getFactHandle( "camel-rider" )).toExternalForm(); }