Package org.drools.fluent.compact.imp

Examples of org.drools.fluent.compact.imp.FluentCompactSimulationImpl


    //        }
    //    }

    @Test
    public void testSimpleForAllAssertionsTypes() {
        FluentCompactSimulation f = new FluentCompactSimulationImpl();

        VariableContext<Person> pc = f.<Person> getVariableContext();

        List<String> imports = new ArrayList<String>();
        imports.add( "org.junit.Assert.assertThat" );
        imports.add( "org.hamcrest.CoreMatchers.is" );
        imports.add( "org.hamcrest.CoreMatchers.equalTo" );
        imports.add( "org.hamcrest.CoreMatchers.allOf" );
        //        imports.add( PersonMatchers.class.getName() + ".name" );
        //        imports.add( PersonMatchers.class.getName() + ".age" );

        ReflectiveMatcherFactory rf = new ReflectiveMatcherFactory( imports );

        String str = "package org.drools.simulation.test\n" +
                     "import " + Person.class.getName() + "\n" +
                     "rule updateAge no-loop when  $p : Person() then modify( $p ) { setAge( $p.getAge() + 10 ) }; end\n";

        // @formatter:off       
        f.newStatefulKnowledgeSession()
                .getKnowledgeBase()
                .addKnowledgePackages( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                       ResourceType.DRL )
                .end()
                .insert( new Person( "yoda",
View Full Code Here


        runSimulation( f );
    }

    @Test
    public void testAssertionsFail() {
        FluentCompactSimulation f = new FluentCompactSimulationImpl();

        VariableContext<Person> pc = f.<Person> getVariableContext();

        List<String> imports = new ArrayList<String>();
        imports.add( "org.junit.Assert.assertThat" );
        imports.add( "org.hamcrest.CoreMatchers.is" );
        imports.add( "org.hamcrest.CoreMatchers.equalTo" );
        imports.add( "org.hamcrest.CoreMatchers.allOf" );

        ReflectiveMatcherFactory rf = new ReflectiveMatcherFactory( imports );

        String str = "package org.drools.simulation.test\n" +
                     "import " + Person.class.getName() + "\n" +
                     "rule updateAge no-loop when  $p : Person() then modify( $p ) { setAge( $p.getAge() + 10 ) }; end\n";

        // @formatter:off       
        f.newStatefulKnowledgeSession()
                .getKnowledgeBase()
                .addKnowledgePackages( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                       ResourceType.DRL )
                .end()
                .insert( new Person( "yoda",
                                     150 ) ).set( "y" )
                .fireAllRules()
                // show testing inside of ksession execution
                .test( "y.age == 110" );
        // @formatter:on   

        boolean fail = false;
        try {
            runSimulation( f );
        } catch ( AssertionError e ) {
            fail = true;
        }
        assertTrue( "Assertion should have failed",
                    fail );

        f = new FluentCompactSimulationImpl();
        // @formatter:off       
        f.newStatefulKnowledgeSession()
             .getKnowledgeBase()
                 .addKnowledgePackages( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                        ResourceType.DRL )
             .end()
             .insert( new Person( "yoda", 150 ) ).set( "y" )
View Full Code Here

        //        }         
    }

    @Test
    public void testMultipleKsessionsWithSteps() {
        FluentCompactSimulation f = new FluentCompactSimulationImpl();

        VariableContext<Person> pc = f.<Person> getVariableContext();

        List<String> imports = new ArrayList<String>();
        imports.add( "org.junit.Assert.assertThat" );
        imports.add( "org.hamcrest.CoreMatchers.is" );
        imports.add( "org.hamcrest.CoreMatchers.equalTo" );
        imports.add( "org.hamcrest.CoreMatchers.allOf" );
        //        imports.add( PersonMatchers.class.getName() + ".name" );
        //        imports.add( PersonMatchers.class.getName() + ".age" );

        ReflectiveMatcherFactory rf = new ReflectiveMatcherFactory( imports );

        String str1 = "package org.drools.simulation.test\n" +
                      "import " + Person.class.getName() + "\n" +
                      "rule updateAge1 no-loop when  $p : Person() then modify( $p ) { setAge( $p.getAge() + 10 ) }; end\n";

        String str2 = "package org.drools.simulation.test\n" +
                      "import " + Person.class.getName() + "\n" +
                      "rule updateAge2 no-loop when  $p : Person() then modify( $p ) { setAge( $p.getAge() + 20 ) }; end\n";

        // @formatter:off
        f.
                newStatefulKnowledgeSession()
                .getKnowledgeBase()
                .addKnowledgePackages( ResourceFactory.newByteArrayResource( str1.getBytes() ),
                                       ResourceType.DRL )
                .end()
View Full Code Here

TOP

Related Classes of org.drools.fluent.compact.imp.FluentCompactSimulationImpl

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.