[jboss-svn-commits] JBL Code SVN: r25540 - in labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools: runtime/pipeline/impl and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 9 00:34:39 EDT 2009
Author: mark.proctor at jboss.com
Date: 2009-03-09 00:34:39 -0400 (Mon, 09 Mar 2009)
New Revision: 25540
Added:
labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/Person.java
labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/TestVariable.java
Modified:
labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java
Log:
JBRULES-1993 BatchExeution and message format
-Added start-process test
Added: labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/Person.java
===================================================================
--- labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/Person.java (rev 0)
+++ labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/Person.java 2009-03-09 04:34:39 UTC (rev 25540)
@@ -0,0 +1,270 @@
+package org.drools;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Person
+ implements
+ Serializable,
+ PersonInterface {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private String name;
+ private String likes;
+ private int age;
+ private BigDecimal bigDecimal;
+ private BigInteger bigInteger;
+ private String hair;
+
+ private char sex;
+
+ private boolean alive;
+
+ private String status;
+
+ private Cheese cheese;
+
+ private List addresses = new ArrayList();
+
+// public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+// name = (String)in.readObject();
+// likes = (String)in.readObject();
+// age = in.readInt();
+// bigDecimal = (BigDecimal)in.readObject();
+// bigInteger = (BigInteger)in.readObject();
+// hair = (String)in.readObject();
+// sex = in.readChar();
+// alive = in.readBoolean();
+// status = (String)in.readObject();
+// cheese = (Cheese)in.readObject();
+// addresses = (List)in.readObject();
+// }
+//
+// public void writeExternal(ObjectOutput out) throws IOException {
+// out.writeObject(name);
+// out.writeObject(likes);
+// out.writeObject(bigDecimal);
+// out.writeObject(bigInteger);
+// out.writeObject(hair);
+// out.writeChar(sex);
+// out.writeBoolean(alive);
+// out.writeObject(status);
+// out.writeObject(cheese);
+// out.writeObject(addresses);
+// }
+
+ public List getAddresses() {
+ return addresses;
+ }
+
+ public void setAddresses(List addresses) {
+ this.addresses = addresses;
+ }
+
+ public Person() {
+
+ }
+
+ public Person(String name,
+ int age) {
+ super();
+ this.name = name;
+ this.age = age;
+ }
+
+ public Person(final String name) {
+ this( name,
+ "",
+ 0 );
+ }
+
+ public Person(final String name,
+ final String likes) {
+ this( name,
+ likes,
+ 0 );
+ }
+
+ public Person(final String name,
+ final String likes,
+ final int age) {
+ this.name = name;
+ this.likes = likes;
+ this.age = age;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#getStatus()
+ */
+ public String getStatus() {
+ return this.status;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#setStatus(java.lang.String)
+ */
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#getLikes()
+ */
+ public String getLikes() {
+ return this.likes;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#getName()
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#getAge()
+ */
+ public int getAge() {
+ return this.age;
+ }
+
+ public void setAge(final int age) {
+ this.age = age;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#isAlive()
+ */
+ public boolean isAlive() {
+ return this.alive;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#setAlive(boolean)
+ */
+ public void setAlive(final boolean alive) {
+ this.alive = alive;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#getSex()
+ */
+ public char getSex() {
+ return this.sex;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#setSex(char)
+ */
+ public void setSex(final char sex) {
+ this.sex = sex;
+ }
+
+ public String getHair() {
+ return this.hair;
+ }
+
+ public void setHair(final String hair) {
+ this.hair = hair;
+ }
+
+ public String toString() {
+ return "[Person name='" + this.name + "']";
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + this.age;
+ result = PRIME * result + (this.alive ? 1231 : 1237);
+ result = PRIME * result + ((this.name == null) ? 0 : this.name.hashCode());
+ result = PRIME * result + this.sex;
+ return result;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public boolean equals(final Object obj) {
+ if ( this == obj ) {
+ return true;
+ }
+ if ( obj == null ) {
+ return false;
+ }
+ if ( getClass() != obj.getClass() ) {
+ return false;
+ }
+ final Person other = (Person) obj;
+ if ( this.age != other.age ) {
+ return false;
+ }
+ if ( this.alive != other.alive ) {
+ return false;
+ }
+ if ( this.name == null ) {
+ if ( other.name != null ) {
+ return false;
+ }
+ } else if ( !this.name.equals( other.name ) ) {
+ return false;
+ }
+ if ( this.sex != other.sex ) {
+ return false;
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#getBigDecimal()
+ */
+ public BigDecimal getBigDecimal() {
+ return this.bigDecimal;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#setBigDecimal(java.math.BigDecimal)
+ */
+ public void setBigDecimal(final BigDecimal bigDecimal) {
+ this.bigDecimal = bigDecimal;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#getBigInteger()
+ */
+ public BigInteger getBigInteger() {
+ return this.bigInteger;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.PersonInterface#setBigInteger(java.math.BigInteger)
+ */
+ public void setBigInteger(final BigInteger bigInteger) {
+ this.bigInteger = bigInteger;
+ }
+
+ public void setLikes(final String likes) {
+ this.likes = likes;
+ }
+
+ public Cheese getCheese() {
+ return this.cheese;
+ }
+
+ public void setCheese(final Cheese cheese) {
+ this.cheese = cheese;
+ }
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/TestVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/TestVariable.java (rev 0)
+++ labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/TestVariable.java 2009-03-09 04:34:39 UTC (rev 25540)
@@ -0,0 +1,22 @@
+/**
+ *
+ */
+package org.drools;
+
+public class TestVariable {
+
+ private String name;
+
+ public TestVariable(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java 2009-03-08 04:37:36 UTC (rev 25539)
+++ labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java 2009-03-09 04:34:39 UTC (rev 25540)
@@ -1,22 +1,37 @@
package org.drools.runtime.pipeline.impl;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.custommonkey.xmlunit.XMLTestCase;
import org.drools.Cheese;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.WorkingMemory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
+import org.drools.compiler.DroolsError;
+import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderErrors;
import org.drools.definition.KnowledgePackage;
+import org.drools.integrationtests.ProcessActionTest.TestVariable;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
+import org.drools.process.instance.ProcessInstance;
+import org.drools.rule.Package;
import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.StatelessKnowledgeSession;
import org.drools.runtime.help.BatchExecutionHelper;
import org.drools.runtime.pipeline.Action;
@@ -25,6 +40,7 @@
import org.drools.runtime.pipeline.PipelineFactory;
import org.drools.runtime.pipeline.ResultHandler;
import org.drools.runtime.pipeline.Transformer;
+import org.xml.sax.SAXException;
public class XStreamBatchExecutionTest extends XMLTestCase {
@@ -282,6 +298,10 @@
str += " stilton : Cheese(type == 'stilton') \n";
str += " cheddar : Cheese(type == 'cheddar', price == stilton.price) \n";
str += "end\n";
+ str += "query cheesesWithParams(String a, String b) \n";
+ str += " stilton : Cheese(type == a) \n";
+ str += " cheddar : Cheese(type == b, price == stilton.price) \n";
+ str += "end\n";
String inXml = "";
inXml += "<batch-execution>";
@@ -314,6 +334,10 @@
inXml += " </org.drools.Cheese>";
inXml += " </insert>";
inXml += " <query out-identifier='cheeses' name='cheeses'/>";
+ inXml += " <query out-identifier='cheeses2' name='cheesesWithParams'>";
+ inXml += " <string>stilton</string>";
+ inXml += " <string>cheddar</string>";
+ inXml += " </query>";
inXml += "</batch-execution>";
StatelessKnowledgeSession ksession = getSession2( ResourceFactory.newByteArrayResource( str.getBytes() ) );
@@ -355,8 +379,27 @@
expectedXml +=" </row>\n";
expectedXml +=" </query-results>\n";
expectedXml +=" </result>\n";
+ expectedXml +=" <result identifier='cheeses2'>\n";
+ expectedXml +=" <query-results>\n";
+ expectedXml +=" <identifiers>\n";
+ expectedXml +=" <identifier>stilton</identifier>\n";
+ expectedXml +=" <identifier>cheddar</identifier>\n";
+ expectedXml +=" </identifiers>\n";
+ expectedXml +=" <row>\n";
+ expectedXml +=" <org.drools.Cheese reference=\"../../../../result/query-results/row/org.drools.Cheese\"/>\n";
+ expectedXml +=" <org.drools.Cheese reference=\"../../../../result/query-results/row/org.drools.Cheese[2]\"/>\n";
+ expectedXml +=" </row>\n";
+ expectedXml +=" <row>\n";
+ expectedXml +=" <org.drools.Cheese reference=\"../../../../result/query-results/row[2]/org.drools.Cheese\"/>\n";
+ expectedXml +=" <org.drools.Cheese reference=\"../../../../result/query-results/row[2]/org.drools.Cheese[2]\"/>\n";
+ expectedXml +=" </row>\n";
+ expectedXml +=" </query-results>\n";
+ expectedXml +=" </result>\n";
expectedXml +="</batch-execution-results>\n";
+ System.out.println( expectedXml );
+ System.out.println( outXml );
+
assertXMLEqual(expectedXml, outXml );
BatchExecutionResult batchResult = ( BatchExecutionResult ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
@@ -390,6 +433,89 @@
assertEquals( set, newSet );
}
+ public void testProcess() throws SAXException, IOException {
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ Reader source = new StringReader(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
+ " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
+ " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" +
+ "\n" +
+ " <header>\n" +
+ " <imports>\n" +
+ " <import name=\"org.drools.TestVariable\" />\n" +
+ " </imports>\n" +
+ " <globals>\n" +
+ " <global identifier=\"list\" type=\"java.util.List\" />\n" +
+ " </globals>\n" +
+ " <variables>\n" +
+ " <variable name=\"person\" >\n" +
+ " <type name=\"org.drools.process.core.datatype.impl.type.ObjectDataType\" className=\"TestVariable\" />\n" +
+ " </variable>\n" +
+ " </variables>\n" +
+ " </header>\n" +
+ "\n" +
+ " <nodes>\n" +
+ " <start id=\"1\" name=\"Start\" />\n" +
+ " <actionNode id=\"2\" name=\"MyActionNode\" >\n" +
+ " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n" +
+ "list.add(person.name);\n" +
+ "</action>\n" +
+ " </actionNode>\n" +
+ " <end id=\"3\" name=\"End\" />\n" +
+ " </nodes>\n" +
+ "\n" +
+ " <connections>\n" +
+ " <connection from=\"1\" to=\"2\" />\n" +
+ " <connection from=\"2\" to=\"3\" />\n" +
+ " </connections>\n" +
+ "\n" +
+ "</process>");
+ kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
+ if ( kbuilder.hasErrors()) {
+ fail ( kbuilder.getErrors().toString() );
+ }
+
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
+ List<String> list = new ArrayList<String>();
+ ksession.setGlobal("list", list);
+ TestVariable person = new TestVariable("John Doe");
+
+ String inXml = "";
+ inXml += "<batch-execution>";
+ inXml += " <startProcess processId='org.drools.actions'>";
+ inXml += " <parameter identifier='person'>";
+ inXml += " <org.drools.TestVariable>";
+ inXml += " <name>John Doe</name>";
+ inXml += " </org.drools.TestVariable>";
+ inXml += " </parameter>";
+ inXml += " </startProcess>";
+ inXml += " <get-global identifier='list' out-identifier='out-list'/>";
+ inXml += "</batch-execution>";
+
+ ResultHandlerImpl resultHandler = new ResultHandlerImpl();
+ getPipeline(ksession).insert( inXml, resultHandler );
+ String outXml = ( String ) resultHandler.getObject();
+
+ assertEquals(1, list.size());
+ assertEquals("John Doe", list.get(0));
+
+ String expectedXml = "";
+ expectedXml += "<batch-execution-results>\n";
+ expectedXml += " <result identifier=\"out-list\">\n";
+ expectedXml += " <list>\n";
+ expectedXml += " <string>John Doe</string>\n";
+ expectedXml += " </list>\n";
+ expectedXml += " </result>\n";
+ expectedXml += "</batch-execution-results>\n";
+
+ assertXMLEqual(expectedXml, outXml );
+ }
+
private Pipeline getPipeline(StatelessKnowledgeSession ksession) {
Action executeResultHandler = PipelineFactory.newExecuteResultHandler();
More information about the jboss-svn-commits
mailing list