[jboss-svn-commits] JBL Code SVN: r28030 - in labs/jbossrules/trunk/drools-simulator/src: test/java and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jul 15 01:05:05 EDT 2009
Author: michael.neale at jboss.com
Date: 2009-07-15 01:05:03 -0400 (Wed, 15 Jul 2009)
New Revision: 28030
Added:
labs/jbossrules/trunk/drools-simulator/src/test/java/org/
labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/
labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/Person.java
labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/PersonInterface.java
labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/simulation/
labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/simulation/impl/
labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java
Removed:
labs/jbossrules/trunk/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationTest.java
Log:
moved test code to test directory, dragged in appropriate "Person" that has the necessary equals method
Deleted: labs/jbossrules/trunk/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationTest.java 2009-07-15 04:10:56 UTC (rev 28029)
+++ labs/jbossrules/trunk/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationTest.java 2009-07-15 05:05:03 UTC (rev 28030)
@@ -1,397 +0,0 @@
-package org.drools.simulation.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseFactory;
-import org.drools.Person;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
-import org.drools.command.Command;
-import org.drools.io.ResourceFactory;
-import org.drools.process.command.AssertEquals;
-import org.drools.process.command.FireAllRulesCommand;
-import org.drools.process.command.GetGlobalCommand;
-import org.drools.process.command.InsertObjectCommand;
-import org.drools.process.command.SetGlobalCommand;
-import org.drools.runtime.KnowledgeSessionConfiguration;
-import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.conf.ClockTypeOption;
-import org.drools.simulation.KnowledgeBaseAddKnowledgePackagesCommand;
-import org.drools.simulation.KnowledgeContextResolveFromContextCommand;
-import org.drools.simulation.NewStatefulKnowledgeSessionCommand;
-import org.drools.simulation.SetVariableCommand;
-import org.drools.simulation.KnowledgeBuilderAddCommand;
-import org.drools.simulation.NewKnowledgeBaseCommand;
-import org.drools.simulation.NewKnowledgeBuilderCommand;
-import org.drools.simulation.Simulation;
-import org.drools.simulation.Statement;
-import org.drools.simulation.Step;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TestGenerator;
-
-import junit.framework.TestCase;
-
-import static junit.framework.Assert.*;
-
- at RunWith(JUnitSimulationRunner.class)
-public class SimulationTest {
-
- @Test
- public Simulation testOnePathNoDSL() {
-
- Simulation simulation = new SimulationImpl();
-
- String str = "";
- str += "package org.drools \n";
- str += "global java.util.List list \n";
- str += "rule rule1 \n";
- str += " dialect \"java\" \n";
- str += "when \n";
- str += " $p : Person() \n";
- str += "then \n";
- str += " list.add( $p ); \n";
- str += "end \n";
-
- PathImpl path = new PathImpl( simulation,
- "path1" );
-
- List<Step> steps = new ArrayList<Step>();
-
- List<Command> cmds = new ArrayList<Command>();
-
- cmds.add( new SetVariableCommand( "path1",
- "kbuilder",
- new NewKnowledgeBuilderCommand( null ) ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
- ResourceType.DRL,
- null ),
- "kbuilder",
- null,
- null ) );
-
- cmds.add( new SetVariableCommand( "path1",
- "kbase",
- new NewKnowledgeBaseCommand( null ) ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
- "kbuilder",
- "kbase",
- null ) );
-
- KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
- ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );
-
- cmds.add( new SetVariableCommand( "path1",
- "ksession",
- new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
- "kbuilder",
- "kbase",
- null ) ) );
-
- List list = new ArrayList();
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
- list ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- steps.add( new StepImpl( path,
- cmds,
- 0 ) );
-
- cmds = new ArrayList<Command>();
- cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
- 97 ) ),
- "kbuilder",
- "kbase",
- "ksession" ) );
- cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
- "kbuilder",
- "kbase",
- "ksession" ) );
- steps.add( new StepImpl( path,
- cmds,
- 2000 ) );
-
- cmds = new ArrayList<Command>();
- cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
- 98 ) ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
- "kbuilder",
- "kbase",
- "ksession" ) );
- steps.add( new StepImpl( path,
- cmds,
- 4000 ) );
-
- cmds = new ArrayList<Command>();
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
- 2,
- new GetGlobalCommand( "list" ),
- "size()" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
- new Person( "darth",
- 97 ),
- new GetGlobalCommand( "list" ),
- "get( 0 )" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
- new Person( "yoda",
- 98 ),
- new GetGlobalCommand( "list" ),
- "get( 1 )" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- steps.add( new StepImpl( path,
- new TestGroupCommand( "test1",
- cmds ),
- 5000 ) );
-
- path.setSteps( steps );
-
- simulation.getPaths().put( "path1",
- path );
-
- return simulation;
-
- // Simulator simulator = new Simulator( simulation,
- // System.currentTimeMillis() );
- //
- // simulator.run();
- }
-
- @Test
- public Simulation testTwoPathsNoDSL() {
-
- Simulation simulation = new SimulationImpl();
-
- String str = "";
- str += "package org.drools \n";
- str += "global java.util.List list \n";
- str += "rule rule1 \n";
- str += " dialect \"java\" \n";
- str += "when \n";
- str += " $p : Person() \n";
- str += "then \n";
- str += " list.add( $p ); \n";
- str += "end \n";
-
- PathImpl path = new PathImpl( simulation,
- "path1" );
-
- List<Step> steps = new ArrayList<Step>();
-
- List<Command> cmds = new ArrayList<Command>();
-
- cmds.add( new SetVariableCommand( "ROOT",
- "kbuilder",
- new NewKnowledgeBuilderCommand( null ) ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
- ResourceType.DRL,
- null ),
- "kbuilder",
- null,
- null ) );
-
- cmds.add( new SetVariableCommand( "ROOT",
- "kbase",
- new NewKnowledgeBaseCommand( null ) ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
- "kbuilder",
- "kbase",
- null ) );
-
- KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
- ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );
-
- cmds.add( new SetVariableCommand( "ROOT",
- "ksession",
- new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
- "kbuilder",
- "kbase",
- null ) ) );
-
- List list = new ArrayList();
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
- list ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- steps.add( new StepImpl( path,
- cmds,
- 0 ) );
-
- cmds = new ArrayList<Command>();
- cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
- 97 ) ),
- "kbuilder",
- "kbase",
- "ksession" ) );
- cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
- "kbuilder",
- "kbase",
- "ksession" ) );
- steps.add( new StepImpl( path,
- cmds,
- 2000 ) );
-
- cmds = new ArrayList<Command>();
- cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
- 98 ) ),
- "kbuilder",
- "kbase",
- "ksession" ) );
- cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
- "kbuilder",
- "kbase",
- "ksession" ) );
- steps.add( new StepImpl( path,
- cmds,
- 4000 ) );
-
- path.setSteps( steps );
-
- simulation.getPaths().put( "path1",
- path );
-
- path = new PathImpl( simulation,
- "path2" );
-
- steps = new ArrayList<Step>();
-
- cmds = new ArrayList<Command>();
- cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "bobba",
- 77 ) ),
- "kbuilder",
- "kbase",
- "ksession" ) );
- cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
- "kbuilder",
- "kbase",
- "ksession" ) );
- steps.add( new StepImpl( path,
- cmds,
- 1500 ) );
-
- cmds = new ArrayList<Command>();
- cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "luke",
- 30 ) ),
- "kbuilder",
- "kbase",
- "ksession" ) );
- cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
- "kbuilder",
- "kbase",
- "ksession" ) );
- steps.add( new StepImpl( path,
- cmds,
- 2200 ) );
-
- cmds = new ArrayList<Command>();
- cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "ben",
- 150 ) ),
- "kbuilder",
- "kbase",
- "ksession" ) );
- cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
- "kbuilder",
- "kbase",
- "ksession" ) );
- steps.add( new StepImpl( path,
- cmds,
- 4500 ) );
-
- cmds = new ArrayList<Command>();
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
- 5,
- new GetGlobalCommand( "list" ),
- "size()" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
- new Person( "bobba",
- 77 ),
- new GetGlobalCommand( "list" ),
- "get( 0 )" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
- new Person( "darth",
- 97 ),
- new GetGlobalCommand( "list" ),
- "get( 1 )" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
- new Person( "luke",
- 30 ),
- new GetGlobalCommand( "list" ),
- "get( 2 )" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
- new Person( "yoda",
- 98 ),
- new GetGlobalCommand( "list" ),
- "get( 3 )" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
- new Person( "ben",
- 150 ),
- new GetGlobalCommand( "list" ),
- "get( 4 )" ),
- "kbuilder",
- "kbase",
- "ksession" ) );
-
- steps.add( new StepImpl( path,
- new TestGroupCommand( "test2",
- cmds ),
- 5000 ) );
-
- path.setSteps( steps );
-
- simulation.getPaths().put( "path2",
- path );
-
- return simulation;
-
- }
-}
Added: labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/Person.java
===================================================================
--- labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/Person.java (rev 0)
+++ labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/Person.java 2009-07-15 05:05:03 UTC (rev 28030)
@@ -0,0 +1,274 @@
+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<Address> addresses = new ArrayList<Address>();
+
+// 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 Person() {
+
+ }
+
+ public Person(String name,
+ int age) {
+ super();
+ this.name = name;
+ this.age = age;
+ }
+
+ public Person(final String name) {
+ this( name,
+ "",
+ 0 );
+ }
+
+ public List<Address> getAddresses() {
+ return addresses;
+ }
+
+ public void setAddresses(List<Address> addresses) {
+ this.addresses = addresses;
+ }
+
+ public void addAddress( Address address ) {
+ this.addresses.add( address );
+ }
+
+ 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-simulator/src/test/java/org/drools/PersonInterface.java
===================================================================
--- labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/PersonInterface.java (rev 0)
+++ labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/PersonInterface.java 2009-07-15 05:05:03 UTC (rev 28030)
@@ -0,0 +1,34 @@
+package org.drools;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+public interface PersonInterface {
+
+ public abstract String getStatus();
+
+ public abstract void setStatus(String status);
+
+ public abstract String getLikes();
+
+ public abstract String getName();
+
+ public abstract int getAge();
+
+ public abstract boolean isAlive();
+
+ public abstract void setAlive(boolean alive);
+
+ public abstract char getSex();
+
+ public abstract void setSex(char sex);
+
+ public abstract BigDecimal getBigDecimal();
+
+ public abstract void setBigDecimal(BigDecimal bigDecimal);
+
+ public abstract BigInteger getBigInteger();
+
+ public abstract void setBigInteger(BigInteger bigInteger);
+
+}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java (from rev 28027, labs/jbossrules/trunk/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java 2009-07-15 05:05:03 UTC (rev 28030)
@@ -0,0 +1,396 @@
+package org.drools.simulation.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.Person;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderFactory;
+import org.drools.builder.ResourceType;
+import org.drools.command.Command;
+import org.drools.io.ResourceFactory;
+import org.drools.process.command.AssertEquals;
+import org.drools.process.command.FireAllRulesCommand;
+import org.drools.process.command.GetGlobalCommand;
+import org.drools.process.command.InsertObjectCommand;
+import org.drools.process.command.SetGlobalCommand;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.conf.ClockTypeOption;
+import org.drools.simulation.KnowledgeBaseAddKnowledgePackagesCommand;
+import org.drools.simulation.KnowledgeContextResolveFromContextCommand;
+import org.drools.simulation.NewStatefulKnowledgeSessionCommand;
+import org.drools.simulation.SetVariableCommand;
+import org.drools.simulation.KnowledgeBuilderAddCommand;
+import org.drools.simulation.NewKnowledgeBaseCommand;
+import org.drools.simulation.NewKnowledgeBuilderCommand;
+import org.drools.simulation.Simulation;
+import org.drools.simulation.Step;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TestGenerator;
+
+import junit.framework.TestCase;
+
+import static junit.framework.Assert.*;
+
+ at RunWith(JUnitSimulationRunner.class)
+public class SimulationTest {
+
+ @Test
+ public Simulation testOnePathNoDSL() {
+
+ Simulation simulation = new SimulationImpl();
+
+ String str = "";
+ str += "package org.drools \n";
+ str += "global java.util.List list \n";
+ str += "rule rule1 \n";
+ str += " dialect \"java\" \n";
+ str += "when \n";
+ str += " $p : Person() \n";
+ str += "then \n";
+ str += " list.add( $p ); \n";
+ str += "end \n";
+
+ PathImpl path = new PathImpl( simulation,
+ "path1" );
+
+ List<Step> steps = new ArrayList<Step>();
+
+ List<Command> cmds = new ArrayList<Command>();
+
+ cmds.add( new SetVariableCommand( "path1",
+ "kbuilder",
+ new NewKnowledgeBuilderCommand( null ) ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL,
+ null ),
+ "kbuilder",
+ null,
+ null ) );
+
+ cmds.add( new SetVariableCommand( "path1",
+ "kbase",
+ new NewKnowledgeBaseCommand( null ) ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
+ "kbuilder",
+ "kbase",
+ null ) );
+
+ KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+ ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );
+
+ cmds.add( new SetVariableCommand( "path1",
+ "ksession",
+ new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
+ "kbuilder",
+ "kbase",
+ null ) ) );
+
+ List list = new ArrayList();
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
+ list ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ steps.add( new StepImpl( path,
+ cmds,
+ 0 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
+ 97 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 2000 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
+ 98 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 4000 ) );
+
+ cmds = new ArrayList<Command>();
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
+ 2,
+ new GetGlobalCommand( "list" ),
+ "size()" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "darth",
+ 97 ),
+ new GetGlobalCommand( "list" ),
+ "get( 0 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "yoda",
+ 98 ),
+ new GetGlobalCommand( "list" ),
+ "get( 1 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ steps.add( new StepImpl( path,
+ new TestGroupCommand( "test1",
+ cmds ),
+ 5000 ) );
+
+ path.setSteps( steps );
+
+ simulation.getPaths().put( "path1",
+ path );
+
+ return simulation;
+
+ // Simulator simulator = new Simulator( simulation,
+ // System.currentTimeMillis() );
+ //
+ // simulator.run();
+ }
+
+ @Test
+ public Simulation testTwoPathsNoDSL() {
+
+ Simulation simulation = new SimulationImpl();
+
+ String str = "";
+ str += "package org.drools \n";
+ str += "global java.util.List list \n";
+ str += "rule rule1 \n";
+ str += " dialect \"java\" \n";
+ str += "when \n";
+ str += " $p : Person() \n";
+ str += "then \n";
+ str += " list.add( $p ); \n";
+ str += "end \n";
+
+ PathImpl path = new PathImpl( simulation,
+ "path1" );
+
+ List<Step> steps = new ArrayList<Step>();
+
+ List<Command> cmds = new ArrayList<Command>();
+
+ cmds.add( new SetVariableCommand( "ROOT",
+ "kbuilder",
+ new NewKnowledgeBuilderCommand( null ) ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL,
+ null ),
+ "kbuilder",
+ null,
+ null ) );
+
+ cmds.add( new SetVariableCommand( "ROOT",
+ "kbase",
+ new NewKnowledgeBaseCommand( null ) ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
+ "kbuilder",
+ "kbase",
+ null ) );
+
+ KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+ ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );
+
+ cmds.add( new SetVariableCommand( "ROOT",
+ "ksession",
+ new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
+ "kbuilder",
+ "kbase",
+ null ) ) );
+
+ List list = new ArrayList();
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
+ list ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ steps.add( new StepImpl( path,
+ cmds,
+ 0 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
+ 97 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 2000 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
+ 98 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 4000 ) );
+
+ path.setSteps( steps );
+
+ simulation.getPaths().put( "path1",
+ path );
+
+ path = new PathImpl( simulation,
+ "path2" );
+
+ steps = new ArrayList<Step>();
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "bobba",
+ 77 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 1500 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "luke",
+ 30 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 2200 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "ben",
+ 150 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 4500 ) );
+
+ cmds = new ArrayList<Command>();
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
+ 5,
+ new GetGlobalCommand( "list" ),
+ "size()" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "bobba",
+ 77 ),
+ new GetGlobalCommand( "list" ),
+ "get( 0 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "darth",
+ 97 ),
+ new GetGlobalCommand( "list" ),
+ "get( 1 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "luke",
+ 30 ),
+ new GetGlobalCommand( "list" ),
+ "get( 2 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "yoda",
+ 98 ),
+ new GetGlobalCommand( "list" ),
+ "get( 3 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "ben",
+ 150 ),
+ new GetGlobalCommand( "list" ),
+ "get( 4 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession" ) );
+
+ steps.add( new StepImpl( path,
+ new TestGroupCommand( "test2",
+ cmds ),
+ 5000 ) );
+
+ path.setSteps( steps );
+
+ simulation.getPaths().put( "path2",
+ path );
+
+ return simulation;
+
+ }
+}
More information about the jboss-svn-commits
mailing list