Package org.drools.simulation

Examples of org.drools.simulation.Simulation


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,
View Full Code Here


    }

    @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;

    }
View Full Code Here

        }

        try {
            for ( Method method : methods ) {

                Simulation simulation = (Simulation) method.invoke( object,
                                                                    null );

                for ( SimulationPath path : simulation.getPaths().values() ) {
                    for ( SimulationStep step : path.getSteps() ) {
                        for ( Command command : step.getCommands() ) {
                            if ( command instanceof TestGroupCommand ) {
                                String testName = ((TestGroupCommand) command).getName();
                                Description testGroupDescr = Description.createTestDescription( cls,
View Full Code Here

        }

        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,
View Full Code Here

        }

        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,
View Full Code Here

        }

        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,
View Full Code Here

        }

        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,
View Full Code Here

@RunWith(JUnitSimulationRunner.class)
public class SimulationTest {

    @Test
    public Simulation testOnePathNoDSL() {
        Simulation simulation = new SimulationImpl();

        String str = "";
        str += "package org.drools \n";
        str += "import " + Person.class.getName() + ";\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";

        SimulationPathImpl path = new SimulationPathImpl( simulation,
                                      "path1" );

        List<SimulationStep> steps = new ArrayList<SimulationStep>();

        SimulationStepImpl step1 = new SimulationStepImpl(path, 0);
        List<Command> cmds1 = step1.getCommands();

        cmds1.add(new NewKnowledgeBuilderCommand( ) );
        cmds1.add(new SetVariableCommandFromLastReturn("path1",
                KnowledgeBuilder.class.getName()));

        cmds1.add(new KnowledgeBuilderAddCommand(ResourceFactory.newByteArrayResource(str.getBytes()),
                ResourceType.DRL,
                null));

        cmds1.add(new NewKnowledgeBaseCommand(null));
        cmds1.add(new SetVariableCommandFromLastReturn("path1",
                KnowledgeBase.class.getName()));

        cmds1.add(new KnowledgeBaseAddKnowledgePackagesCommand());

        KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        ksessionConf.setOption(ClockTypeOption.get("pseudo"));

        cmds1.add(new NewStatefulKnowledgeSessionCommand(ksessionConf));
        cmds1.add( new SetVariableCommandFromLastReturn( "path1",
                                          StatefulKnowledgeSession.class.getName() ) );

        List list = new ArrayList();

        cmds1.add(new SetGlobalCommand("list",
                list));

        steps.add(step1);


        SimulationStepImpl step2 = new SimulationStepImpl(path, 2000);
        List<Command> cmds2 = step2.getCommands();
        cmds2.add(new InsertObjectCommand(new Person("darth",
                97)));
        cmds2.add(new FireAllRulesCommand());
        steps.add( step2 );


        SimulationStepImpl step3 = new SimulationStepImpl(path, 4000);
        List<Command> cmds3 = step3.getCommands();
        cmds3.add( new InsertObjectCommand( new Person( "yoda",
                                                       98 ) ) );
        cmds3.add(new FireAllRulesCommand());
        steps.add( step3 );


        SimulationStepImpl step4 = new SimulationStepImpl(path, 5000);
        List<Command> cmds4 = new ArrayList<Command>();

        cmds4.add( new AssertEquals( "Check List size",
                                    2,
                                    new GetGlobalCommand( "list" ),
                                    "size()" ) );
       
        cmds4.add( new AssertEquals( "Check Person",
                                    new Person( "darth",
                                                97 ),
                                    new GetGlobalCommand( "list" ),
                                    "get( 0 )" ) );

        cmds4.add(new AssertEquals("Check Person",
                new Person("yoda",
                        98),
                new GetGlobalCommand("list"),
                "get( 1 )"));

        step4.getCommands().add(new TestGroupCommand( "test1", cmds4));
        steps.add( step4 );


        path.setSteps( steps );
        simulation.getPaths().put( "path1",
                                   path );

        return simulation;
    }
View Full Code Here

        return simulation;
    }

    @Test
    public Simulation testTwoPathsNoDSL() {
        Simulation simulation = new SimulationImpl();

        String str = "";
        str += "package org.drools \n";
        str += "import " + Person.class.getName() + ";\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";

        SimulationPathImpl path1 = new SimulationPathImpl( simulation,
                                      "path1" );

        List<SimulationStep> steps1 = new ArrayList<SimulationStep>();

        SimulationStepImpl step11 = new SimulationStepImpl(path1,
                0);
        List<Command> cmds11 = step11.getCommands();

        cmds11.add(new NewKnowledgeBuilderCommand( ) );
        cmds11.add(new SetVariableCommandFromLastReturn(World.ROOT,
                KnowledgeBuilder.class.getName()));

        cmds11.add(new KnowledgeBuilderAddCommand(ResourceFactory.newByteArrayResource(str.getBytes()),
                ResourceType.DRL,
                null));

        cmds11.add(new NewKnowledgeBaseCommand(null));

        cmds11.add(new SetVariableCommandFromLastReturn(World.ROOT,
                KnowledgeBase.class.getName()));

        cmds11.add(new KnowledgeBaseAddKnowledgePackagesCommand());

        KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        ksessionConf.setOption(ClockTypeOption.get("pseudo"));

        cmds11.add(new NewStatefulKnowledgeSessionCommand(ksessionConf));
        cmds11.add(new SetVariableCommandFromLastReturn(World.ROOT,
                StatefulKnowledgeSession.class.getName()));

        List list = new ArrayList();
        cmds11.add(new SetGlobalCommand("list",
                list));

        steps1.add(step11);


        SimulationStepImpl step12 = new SimulationStepImpl(path1,
                2000);
        List<Command> cmds12 = step12.getCommands();
        cmds12.add( new InsertObjectCommand( new Person( "darth",
                                                       97 ) ) );
        cmds12.add( new FireAllRulesCommand() );
        steps1.add(step12);


        SimulationStepImpl step13 = new SimulationStepImpl(path1,
                4000);
        List<Command> cmds13 = step13.getCommands();
        cmds13.add( new InsertObjectCommand( new Person( "yoda",
                                                       98 ) ) );
        cmds13.add(new FireAllRulesCommand());

        steps1.add(step13);


        path1.setSteps(steps1);
        simulation.getPaths().put( "path1",
                                   path1 );

        SimulationPathImpl path2 = new SimulationPathImpl( simulation,
                             "path2" );

        List<SimulationStep> steps2 = new ArrayList<SimulationStep>();


        SimulationStepImpl step21 = new SimulationStepImpl(path2,
                1500);
        List<Command> cmds21 = step21.getCommands();
        cmds21.add( new InsertObjectCommand( new Person( "bobba",
                                                       77 ) ) );
        cmds21.add(new FireAllRulesCommand());
        steps2.add(step21);


        SimulationStepImpl step22 = new SimulationStepImpl(path2,
                2200);
        List<Command> cmds22 = step22.getCommands();
        cmds22.add(new InsertObjectCommand(new Person("luke",
                30)));
        cmds22.add(new FireAllRulesCommand());
        steps2.add(step22);


        SimulationStepImpl step23 = new SimulationStepImpl(path2,
                4500);
        List<Command> cmds23 = step23.getCommands();
        cmds23.add(new InsertObjectCommand(new Person("ben",
                150)));
        cmds23.add(new FireAllRulesCommand());

        steps2.add(step23);


        SimulationStepImpl step24 = new SimulationStepImpl(path2,
                5000);
        List<Command> cmds24 = new ArrayList<Command>();
        cmds24.add(new AssertEquals("Check List size",
                5,
                new GetGlobalCommand("list"),
                "size()"));

        cmds24.add(new AssertEquals("Check Person",
                new Person("bobba",
                        77),
                new GetGlobalCommand("list"),
                "get( 0 )" ) );

        cmds24.add(new AssertEquals("Check Person",
                new Person("darth",
                        97),
                new GetGlobalCommand("list"),
                "get( 1 )"));

        cmds24.add(new AssertEquals("Check Person",
                new Person("luke",
                        30),
                new GetGlobalCommand("list"),
                "get( 2 )"));

        cmds24.add(new AssertEquals("Check Person",
                new Person("yoda",
                        98),
                new GetGlobalCommand("list"),
                "get( 3 )"));

        cmds24.add(new AssertEquals("Check Person",
                new Person("ben",
                        150),
                new GetGlobalCommand("list"),
                "get( 4 )"));
        step24.getCommands().add(new TestGroupCommand("test2", cmds24));
        steps2.add(step24);


        path2.setSteps(steps2);
        simulation.getPaths().put( "path2",
                                   path2 );

        return simulation;
    }
View Full Code Here

public class SimulationTest {

    @Test
    public Simulation testOnePathNoDSL() {

        Simulation simulation = new SimulationImpl();

        String str = "";
        str += "package org.drools \n";
        str += "import " + Person.class.getName() + ";\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 NewKnowledgeBuilderCommand( null ) );
        cmds.add( new SetVariableCommandFromLastReturn( "path1",
                                          KnowledgeBuilder.class.getName() ) );

        cmds.add( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                                  ResourceType.DRL,
                                                  null ) );

        cmds.add( new NewKnowledgeBaseCommand( null ) );
        cmds.add( new SetVariableCommandFromLastReturn( "path1",
                                          KnowledgeBase.class.getName() ) );

        cmds.add( new KnowledgeBaseAddKnowledgePackagesCommand() );

        KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );

        cmds.add( new NewStatefulKnowledgeSessionCommand( ksessionConf ) );
        cmds.add( new SetVariableCommandFromLastReturn( "path1",
                                          StatefulKnowledgeSession.class.getName() ) );

        List list = new ArrayList();

        cmds.add( new SetGlobalCommand( "list",
                                        list ) );

        steps.add( new StepImpl( path,
                                 cmds,
                                 0 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new InsertObjectCommand( new Person( "darth",
                                                       97 ) ) );
        cmds.add( new FireAllRulesCommand() );

        steps.add( new StepImpl( path,
                                 cmds,
                                 2000 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new InsertObjectCommand( new Person( "yoda",
                                                       98 ) ) );

        cmds.add( new FireAllRulesCommand() );

        steps.add( new StepImpl( path,
                                 cmds,
                                 4000 ) );

        cmds = new ArrayList<Command>();

        cmds.add( new AssertEquals( "Check List size",
                                    2,
                                    new GetGlobalCommand( "list" ),
                                    "size()" ) );
       
        cmds.add( new AssertEquals( "Check Person",
                                    new Person( "darth",
                                                97 ),
                                    new GetGlobalCommand( "list" ),
                                    "get( 0 )" ) );

        cmds.add( new AssertEquals( "Check Person",
                                    new Person( "yoda",
                                                98 ),
                                    new GetGlobalCommand( "list" ),
                                    "get( 1 )" ) );

        steps.add( new StepImpl( path,
                                 new TestGroupCommand( "test1",
                                                       cmds ),
                                 5000 ) );

        path.setSteps( steps );

        simulation.getPaths().put( "path1",
                                   path );

        return simulation;
    }
View Full Code Here

TOP

Related Classes of org.drools.simulation.Simulation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.