[jboss-svn-commits] JBL Code SVN: r36713 - in labs/jbossrules/tags/5.2.0.M1: drools-simulator and 13 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Feb 24 12:53:29 EST 2011
Author: ge0ffrey
Date: 2011-02-24 12:53:29 -0500 (Thu, 24 Feb 2011)
New Revision: 36713
Added:
labs/jbossrules/tags/5.2.0.M1/drools-simulator/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/.gitignore
labs/jbossrules/tags/5.2.0.M1/drools-simulator/pom.xml
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Path.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Simulation.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Step.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/JUnitSimulationRunner.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/PathImpl.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationImpl.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/Simulator.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/StepImpl.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/TestGroupCommand.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Address.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Cheese.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Person.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/PersonInterface.java
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/simulation/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/simulation/impl/
labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java
Log:
All monolothic build versions (<= 5.2.0.M1) stay in subversion
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/.gitignore
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/.gitignore (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/.gitignore 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,10 @@
+/target
+/local
+
+# Eclipse, Netbeans and IntelliJ files
+/.*
+!.gitignore
+/nbproject
+/*.ipr
+/*.iws
+/*.iml
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/pom.xml
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/pom.xml (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/pom.xml 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.drools</groupId>
+ <artifactId>drools</artifactId>
+ <version>5.2.0.M1</version>
+ </parent>
+
+ <artifactId>drools-simulator</artifactId>
+ <packaging>jar</packaging>
+ <name>Drools :: Simulator</name>
+
+
+ <dependencies>
+ <!-- Internal dependencies -->
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-compiler</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jbpm</groupId>
+ <artifactId>jbpm-flow-builder</artifactId>
+ </dependency>
+ <dependency><!-- Overwrites (or duplicates) the parent junit dependency because it is needed at compile time -->
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Path.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Path.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Path.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,25 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation;
+
+import java.util.Collection;
+
+public interface Path {
+ String getName();
+
+ Collection<Step> getSteps();
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Simulation.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Simulation.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Simulation.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,23 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation;
+
+import java.util.Map;
+
+public interface Simulation {
+ Map<String, Path> getPaths();
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Step.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Step.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/Step.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,26 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation;
+
+import java.util.Collection;
+
+import org.drools.command.Command;
+
+public interface Step {
+ long getTemporalDistance();
+ Collection<Command> getCommands();
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/JUnitSimulationRunner.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/JUnitSimulationRunner.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/JUnitSimulationRunner.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,155 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.command.Command;
+import org.drools.command.Context;
+import org.drools.command.impl.GenericCommand;
+import org.drools.simulation.Path;
+import org.drools.simulation.Simulation;
+import org.drools.simulation.Step;
+import org.drools.simulation.impl.Simulator.CommandExecutionHandler;
+import org.junit.Test;
+import org.junit.runner.Description;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Request;
+import org.junit.runner.Runner;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunNotifier;
+
+public class JUnitSimulationRunner extends Runner {
+
+ private Description descr;
+ private Map<String, Description> testGroups = new HashMap<String, Description>();
+
+ private List<Simulation> simulations = new ArrayList<Simulation>();
+
+ public JUnitSimulationRunner(Class cls) {
+ this.descr = Description.createSuiteDescription( cls );
+
+ Object object = null;
+ try {
+ object = cls.newInstance();
+ } catch ( Exception e ) {
+
+ }
+
+ List<Method> methods = new ArrayList<Method>();
+ for ( Method method : cls.getDeclaredMethods() ) {
+ if ( method.getReturnType().equals( Simulation.class ) && method.getAnnotation( Test.class ) != null ) {
+ methods.add( method );
+ }
+ }
+
+ try {
+ for ( Method method : methods ) {
+
+ Simulation simulation = (Simulation) method.invoke( object,
+ null );
+
+ for ( Path path : simulation.getPaths().values() ) {
+ for ( Step step : path.getSteps() ) {
+ for ( Command command : step.getCommands() ) {
+ if ( command instanceof TestGroupCommand ) {
+ String testName = ((TestGroupCommand) command).getName();
+ Description testGroupDescr = Description.createTestDescription( cls,
+ testName );
+ this.descr.addChild( testGroupDescr );
+ this.testGroups.put( testName,
+ testGroupDescr );
+ }
+ }
+ }
+ }
+
+ simulations.add( simulation );
+ }
+ } catch ( Exception e ) {
+ }
+
+ //
+ // System.out.println( "class:" + cls );
+ // this.descr = Description.createSuiteDescription( cls );
+ // this.descr1 = Description.createTestDescription( cls, "test1" );
+ // this.descr2 = Description.createTestDescription( cls, "test2" );
+ //
+ // this.descr.addChild( descr1 );
+ // this.descr.addChild( descr2 );
+
+ }
+
+ @Override
+ public Description getDescription() {
+ return this.descr;
+ }
+
+ @Override
+ public void run(RunNotifier notifier) {
+ JunitCommandExecutionHandler executionHandler = new JunitCommandExecutionHandler( notifier,
+ this.testGroups );
+ for ( Simulation simulation : simulations ) {
+ Simulator simulator = new Simulator( simulation,
+ System.currentTimeMillis() );
+ simulator.setCommandExecutionHandler( executionHandler );
+ simulator.run();
+ }
+
+ }
+
+ public static class JunitCommandExecutionHandler
+ implements
+ CommandExecutionHandler {
+ private RunNotifier notifier;
+ private Map<String, Description> testGroups;
+
+ public JunitCommandExecutionHandler(RunNotifier notifier,
+ Map<String, Description> testGroups) {
+ super();
+ this.notifier = notifier;
+ this.testGroups = testGroups;
+ }
+
+ public Object execute(GenericCommand command,
+ Context context) {
+ if ( command instanceof TestGroupCommand ) {
+ TestGroupCommand testGroupCmd = (TestGroupCommand) command;
+ Description descr = this.testGroups.get( testGroupCmd.getName() );
+ this.notifier.fireTestStarted( descr );
+ try {
+ command.execute( context );
+ this.notifier.fireTestFinished( descr );
+ return null;
+ } catch ( Exception e ) {
+ this.notifier.fireTestFailure( new Failure( descr,
+ e ) );
+ return null;
+ }
+ } else {
+ return command.execute( context );
+ }
+ }
+
+ }
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/PathImpl.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/PathImpl.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/PathImpl.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.command.Context;
+import org.drools.simulation.Path;
+import org.drools.simulation.Simulation;
+import org.drools.simulation.Step;
+
+public class PathImpl
+ implements
+ Path {
+ private SimulationImpl simulation;
+
+ private String name;
+
+ private Collection<Step> steps;
+
+ public PathImpl(Simulation simulation,
+ String name) {
+ this.name = name;
+ this.simulation = (SimulationImpl) simulation;
+ }
+
+ public void setSteps(Collection<Step> steps) {
+ this.steps = steps;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Collection<Step> getSteps() {
+ return this.steps;
+ }
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationImpl.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationImpl.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/SimulationImpl.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.command.Context;
+import org.drools.simulation.Path;
+import org.drools.simulation.Simulation;
+
+public class SimulationImpl implements Simulation {
+ private Map<String, Path> paths;
+
+ public SimulationImpl() {
+ this.paths = new HashMap<String, Path>();
+ }
+
+ public Map<String, Path> getPaths() {
+ return this.paths;
+ }
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/Simulator.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/Simulator.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/Simulator.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,221 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation.impl;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.drools.StatefulSession;
+import org.drools.command.Command;
+import org.drools.command.Context;
+import org.drools.command.ContextManager;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.NewStatefulKnowledgeSessionCommand;
+import org.drools.command.builder.KnowledgeBuilderAddCommand;
+import org.drools.command.impl.ContextImpl;
+import org.drools.command.impl.GenericCommand;
+import org.drools.impl.StatefulKnowledgeSessionImpl;
+import org.drools.reteoo.ReteooStatefulSession;
+import org.drools.reteoo.ReteooWorkingMemory;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.simulation.Path;
+import org.drools.simulation.Simulation;
+import org.drools.simulation.Step;
+import org.drools.time.SessionPseudoClock;
+
+public class Simulator
+ implements
+ ContextManager {
+
+ private PriorityQueue<Step> queue;
+ private SimulationImpl simulation;
+ // private SessionPseudoClock clock;
+ private long startTime;
+
+ private Context root;
+ private Map<String, Context> contexts;
+
+ private String ROOT = "ROOT";
+
+ private Set<StatefulKnowledgeSession> ksessions;
+
+ private CommandExecutionHandler executionHandler = new DefaultCommandExecutionHandler();
+
+ public Simulator(Simulation simulation,
+ //SessionPseudoClock clock,
+ long startTime) {
+ // this.clock = clock;
+ this.ksessions = new HashSet<StatefulKnowledgeSession>();
+
+ this.startTime = startTime;
+ this.simulation = (SimulationImpl) simulation;
+ this.root = new ContextImpl( ROOT,
+ this );
+
+ this.contexts = new HashMap<String, Context>();
+ this.contexts.put( ROOT,
+ this.root );
+
+ Map<String, Path> paths = this.simulation.getPaths();
+
+ // calculate capacity
+ int capacity = 0;
+ for ( Path path : paths.values() ) {
+ this.contexts.put( path.getName(),
+ new ContextImpl( path.getName(),
+ this,
+ root ) );
+
+ capacity += path.getSteps().size();
+ }
+
+ if ( capacity == 0 ) {
+ return;
+ }
+
+ this.queue = new PriorityQueue( capacity,
+ new Comparator<Step>() {
+ public int compare(Step s1,
+ Step s2) {
+ return (int) (s1.getTemporalDistance() - s2.getTemporalDistance());
+ }
+ } );
+
+ for ( Path path : paths.values() ) {
+ for ( Step step : path.getSteps() )
+ this.queue.add( step );
+ }
+ }
+
+ public void run() {
+ Step step;
+ while ( (step = executeNextStep()) != null ) {
+
+ }
+ }
+
+ public Step executeNextStep() {
+ if ( this.queue.isEmpty() ) {
+ return null;
+ }
+ StepImpl step = (StepImpl) this.queue.remove();
+ PathImpl path = (PathImpl) step.getPath();
+
+ Context pathContext = this.contexts.get( path.getName() );
+
+ // increment the clock for all the registered ksessions
+ for ( StatefulKnowledgeSession ksession : this.ksessions ) {
+ SessionPseudoClock clock = (SessionPseudoClock) ksession.getSessionClock();
+
+ long newTime = this.startTime + step.getTemporalDistance();
+ long currentTime = clock.getCurrentTime();
+ clock.advanceTime( (currentTime + (newTime - currentTime)),
+ TimeUnit.MICROSECONDS );
+ }
+
+ for ( Command cmd : step.getCommands() ) {
+ if ( cmd instanceof KnowledgeContextResolveFromContextCommand) {
+ if ( ((KnowledgeContextResolveFromContextCommand)cmd).getCommand() instanceof NewStatefulKnowledgeSessionCommand ) {
+ // instantiate the ksession, set it's clock and register it
+ StatefulKnowledgeSession ksession = ( StatefulKnowledgeSession ) executionHandler.execute( (GenericCommand) cmd, pathContext );
+ if ( ksession != null ) {
+ SessionPseudoClock clock = (SessionPseudoClock) ksession.getSessionClock();
+ if ( clock.getCurrentTime() == 0 ) {
+ clock.advanceTime( startTime,
+ TimeUnit.MILLISECONDS );
+ }
+ this.ksessions.add( ksession );
+ }
+ } else if ( cmd instanceof GenericCommand) {
+ executionHandler.execute( (GenericCommand) cmd, pathContext );
+ }
+ } else if ( cmd instanceof GenericCommand) {
+ executionHandler.execute( (GenericCommand) cmd, pathContext );
+ }
+ }
+
+ return step;
+ }
+
+ public void setCommandExecutionHandler(CommandExecutionHandler executionHandler) {
+ this.executionHandler = executionHandler;
+ }
+
+ public Context getContext(String identifier) {
+ return this.contexts.get( identifier );
+ }
+
+ public Context getDefaultContext() {
+ return this.root;
+ }
+
+ public Simulation getSimulation() {
+ return this.simulation;
+ }
+
+ public static interface CommandExecutionHandler {
+ public Object execute(GenericCommand command, Context context);
+ }
+
+ public static class DefaultCommandExecutionHandler implements CommandExecutionHandler {
+ public Object execute(GenericCommand command, Context context) {
+ return command.execute( context );
+ }
+ }
+
+
+// public static interface CommandExecutorService<T> {
+// T execute(Command command);
+// }
+//
+// public static class SimulatorCommandExecutorService<T> implements CommandExecutorService {
+// Map map = new HashMap() {
+// {
+// put( KnowledgeBuilderAddCommand.class, null);
+// }
+// };
+//
+// public T execute(Command command) {
+// return null;
+// }
+// }
+//
+// public static interface CommandContextAdapter {
+// Context getContext();
+// }
+//
+// public static class KnowledgeBuilderCommandContextAdapter implements CommandContextAdapter {
+//
+// public Context getContext() {
+// return new KnowledgeBuilderCommandContext();
+// }
+//
+// }
+
+ // public void runUntil(Step step) {
+ //
+ // }
+ //
+ // public void runForTemporalDistance(long distance) {
+ //
+ // }
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/StepImpl.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/StepImpl.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/StepImpl.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.drools.command.Command;
+import org.drools.simulation.Path;
+import org.drools.simulation.Step;
+
+public class StepImpl
+ implements
+ Step {
+ private Path path;
+ private Collection<Command> commands;
+ private long distance;
+
+ public StepImpl(Path path,
+ Collection<Command> commands,
+ long distance) {
+ this.path = path;
+ this.commands = commands;
+ this.distance = distance;
+ }
+
+ public StepImpl(Path path,
+ Command command,
+ long distance) {
+ this.path = path;
+ commands = new ArrayList<Command>();
+ ((List<Command>)this.commands).add( command );
+ this.distance = distance;
+ }
+
+ public Collection<Command> getCommands() {
+ return commands;
+ }
+
+ public long getTemporalDistance() {
+ return distance;
+ }
+
+ public Path getPath() {
+ return this.path;
+ }
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/TestGroupCommand.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/TestGroupCommand.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/main/java/org/drools/simulation/impl/TestGroupCommand.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.simulation.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.command.Command;
+import org.drools.command.Context;
+import org.drools.command.impl.GenericCommand;
+import org.drools.command.impl.KnowledgeCommandContext;
+import org.drools.impl.StatefulKnowledgeSessionImpl;
+import org.drools.reteoo.ReteooWorkingMemory;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.rule.AgendaFilter;
+import org.mvel2.MVEL;
+
+public class TestGroupCommand
+ implements
+ GenericCommand<Void> {
+
+ private String name;
+ private List<Command> commands;
+
+ public TestGroupCommand(String name,
+ List<Command> commands) {
+ super();
+ this.name = name;
+ this.commands = commands;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<Command> getCommands() {
+ return commands;
+ }
+
+ public Void execute(Context context) {
+ for ( Command command : commands ) {
+ ((GenericCommand) command).execute( context );
+ }
+ return null;
+ }
+
+ public String toString() {
+ return "test";
+ }
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Address.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Address.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Address.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,58 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools;
+
+import java.io.Serializable;
+
+public class Address implements Serializable {
+
+ private static final long serialVersionUID = 510l;
+
+ private String street;
+ private String suburb;
+ private String zipCode;
+
+ public Address() {
+
+ }
+
+ public Address(String street) {
+ this.street = street;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+ public void setStreet(String street) {
+ this.street = street;
+ }
+ public String getSuburb() {
+ return suburb;
+ }
+ public void setSuburb(String suburb) {
+ this.suburb = suburb;
+ }
+
+ public String getZipCode() {
+ return zipCode;
+ }
+
+ public void setZipCode(String zipCode) {
+ this.zipCode = zipCode;
+ }
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Cheese.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Cheese.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Cheese.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools;
+
+import java.io.Serializable;
+import java.util.Date;
+
+
+public class Cheese
+ implements
+ Serializable {
+
+ public static final String STILTON = "stilton";
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 510l;
+ private String type;
+ private int price;
+ private int oldPrice;
+ private Date usedBy;
+ private double doublePrice;
+
+ public Cheese() {
+
+ }
+
+ public Cheese(final String type) {
+ super();
+ this.type = type;
+ this.price = 0;
+ }
+
+ public Cheese(final String type,
+ final int price) {
+ super();
+ this.type = type;
+ this.price = price;
+ }
+
+ public Cheese(final String type,
+ final int price,
+ final int oldPrice ) {
+ super();
+ this.type = type;
+ this.price = price;
+ this.oldPrice = oldPrice;
+ }
+
+ public int getPrice() {
+ return this.price;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public void setPrice(final int price) {
+ this.price = price;
+ }
+
+ public String toString() {
+ return "Cheese( type='" + this.type + "', price=" + this.price + " )";
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + price;
+ result = PRIME * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final Cheese other = (Cheese) obj;
+ if ( price != other.price ) return false;
+ if ( type == null ) {
+ if ( other.type != null ) return false;
+ } else if ( !type.equals( other.type ) ) return false;
+ return true;
+ }
+
+ public int getOldPrice() {
+ return oldPrice;
+ }
+
+ public void setOldPrice(int oldPrice) {
+ this.oldPrice = oldPrice;
+ }
+
+ public Date getUsedBy() {
+ return usedBy;
+ }
+
+ public void setUsedBy(Date usedBy) {
+ this.usedBy = usedBy;
+ }
+
+ public synchronized double getDoublePrice() {
+ return doublePrice;
+ }
+
+ public synchronized void setDoublePrice(double doublePrice) {
+ this.doublePrice = doublePrice;
+ }
+
+
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Person.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Person.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/Person.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,290 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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 = 510l;
+ 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;
+ }
+
+}
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/PersonInterface.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/PersonInterface.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/PersonInterface.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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
Added: labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java
===================================================================
--- labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java (rev 0)
+++ labs/jbossrules/tags/5.2.0.M1/drools-simulator/src/test/java/org/drools/simulation/impl/SimulationTest.java 2011-02-24 17:53:29 UTC (rev 36713)
@@ -0,0 +1,414 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.command.KnowledgeBaseAddKnowledgePackagesCommand;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.NewKnowledgeBaseCommand;
+import org.drools.command.NewStatefulKnowledgeSessionCommand;
+import org.drools.command.SetVariableCommand;
+import org.drools.command.assertion.AssertEquals;
+import org.drools.command.builder.KnowledgeBuilderAddCommand;
+import org.drools.command.builder.NewKnowledgeBuilderCommand;
+import org.drools.command.runtime.GetGlobalCommand;
+import org.drools.command.runtime.SetGlobalCommand;
+import org.drools.command.runtime.rule.FireAllRulesCommand;
+import org.drools.command.runtime.rule.InsertObjectCommand;
+import org.drools.io.ResourceFactory;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.conf.ClockTypeOption;
+import org.drools.simulation.Simulation;
+import org.drools.simulation.Step;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+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, null ) );
+
+ cmds.add( new SetVariableCommand( "path1",
+ "kbase",
+ new NewKnowledgeBaseCommand( null ) ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
+ "kbuilder",
+ "kbase",
+ null, null ) );
+
+ KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+ ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );
+
+ cmds.add( new SetVariableCommand( "path1",
+ "ksession",
+ new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
+ "kbuilder",
+ "kbase",
+ null, null ) ) );
+
+ List list = new ArrayList();
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
+ list ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ steps.add( new StepImpl( path,
+ cmds,
+ 0 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
+ 97 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 2000 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
+ 98 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ 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", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "darth",
+ 97 ),
+ new GetGlobalCommand( "list" ),
+ "get( 0 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "yoda",
+ 98 ),
+ new GetGlobalCommand( "list" ),
+ "get( 1 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ 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, null ) );
+
+ cmds.add( new SetVariableCommand( "ROOT",
+ "kbase",
+ new NewKnowledgeBaseCommand( null ) ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
+ "kbuilder",
+ "kbase",
+ null, null ) );
+
+ KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+ ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );
+
+ cmds.add( new SetVariableCommand( "ROOT",
+ "ksession",
+ new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
+ "kbuilder",
+ "kbase",
+ null, null ) ) );
+
+ List list = new ArrayList();
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
+ list ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ steps.add( new StepImpl( path,
+ cmds,
+ 0 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
+ 97 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 2000 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
+ 98 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ 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", null ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 1500 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "luke",
+ 30 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ steps.add( new StepImpl( path,
+ cmds,
+ 2200 ) );
+
+ cmds = new ArrayList<Command>();
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "ben",
+ 150 ) ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+ 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", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "bobba",
+ 77 ),
+ new GetGlobalCommand( "list" ),
+ "get( 0 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "darth",
+ 97 ),
+ new GetGlobalCommand( "list" ),
+ "get( 1 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "luke",
+ 30 ),
+ new GetGlobalCommand( "list" ),
+ "get( 2 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "yoda",
+ 98 ),
+ new GetGlobalCommand( "list" ),
+ "get( 3 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
+ new Person( "ben",
+ 150 ),
+ new GetGlobalCommand( "list" ),
+ "get( 4 )" ),
+ "kbuilder",
+ "kbase",
+ "ksession", null ) );
+
+ 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