Package org.drools.fluent.test.impl

Examples of org.drools.fluent.test.impl.ReflectiveMatcherFactory


        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.newKnowledgeBuilder()
            .add( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                   ResourceType.DRL )
            .end()
        .newStatefulKnowledgeSession()
            .insert( new Person( "yoda", 150 ) ).set( "y" )
            .fireAllRules()
            // show testing inside of ksession execution
            .test( "y.name == 'yoda'" )
            .test( "y.age == 160" )

            // test hamcrest
            .test( rf.assertThat( "y.name",
                                  matcher( "equalTo",
                                           "'yoda'" ) ) )
            .test( rf.assertThat( "y.name, equalTo('yoda')" ) )
            .test( rf.assertThat( "y.age",
                                  matcher( "equalTo",
                                           "160" ) ) )
            .test( rf.assertThat( "y.age, equalTo(160)" ) )

            // @ FIXME commented out until hamsandwich works in the build
            //             // test hamsandwich
            //             .test( rf.assertThat( "y", matcher( "allOf", matcher("name",  matcher( "equalTo", "'yoda'" ) ),
            //                                                          matcher("age",  matcher( "equalTo", "160" ) )
            //                                                )) )
            .end()

        // show complex testing after the ksession has finished
        .test( "y.name == 'yoda'" )
        .test( "y.age == 160" )

        // test hamcrest
        .test( rf.assertThat( "y.name",
                              matcher( "equalTo",
                                       "'yoda'" ) ) )
        .test( rf.assertThat( "y.age",
                              matcher( "equalTo",
                                       "160" ) ) )
        .runSimulation();

        // @ FIXME commented out until hamsandwich works in the build     
View Full Code Here


        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.newKnowledgeBuilder()
            .add( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                   ResourceType.DRL )
            .end()
        .newStatefulKnowledgeSession()
            .insert( new Person( "yoda", 150 ) ).set( "y" )
            .fireAllRules()
            // show testing inside of ksession execution
            .test( "y.age == 110" );
        // @formatter:on   

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

        f = new DefaultSimulationFluent();
        // @formatter:off       
        f.newKnowledgeBuilder()
            .add( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                    ResourceType.DRL )
            .end()
        .newStatefulKnowledgeSession()
             .insert( new Person( "yoda", 150 ) ).set( "y" )
             .fireAllRules()
             // show testing inside of ksession execution
             .test( rf.assertThat( "y.age", matcher( "equalTo", "120" ) ) )
             .test( rf.assertThat( "y.age, equalTo(120)" ) );       
        // @formatter:on   
       

        fail = false;
        try {
View Full Code Here

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

        imports.add( "org.hamcrest.MatcherAssert.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" +
                     "global java.util.List list\n" +
                     "rule setTime when then list.add( kcontext.getKnowledgeRuntime().getSessionClock().getCurrentTime() );\n end\n " +
View Full Code Here

        imports.add( "org.hamcrest.MatcherAssert.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 str1 = "package org.drools.simulation.test\n" +
                     "import " + Person.class.getName() + "\n" +
                     "global java.util.List list\n" +
                     "rule setTime when then list.add( kcontext.getKnowledgeRuntime().getSessionClock().getCurrentTime() );\n end\n " +
View Full Code Here

        imports.add( "org.hamcrest.MatcherAssert.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" +
                     "global java.util.List list\n" +
                     "rule setTime when then list.add( kcontext.getKnowledgeRuntime().getSessionClock().getCurrentTime() );\n end\n " +
View Full Code Here

        imports.add( "org.hamcrest.MatcherAssert.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" +
                "global java.util.List list\n" +
                "rule setTime\n" +
View Full Code Here

        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",
                                     150 ) ).set( "y" )
                .fireAllRules()
                // show testing inside of ksession execution
                .test( "y.name == 'yoda'" )
                .test( "y.age == 160" )

                // test hamcrest        
                .test( rf.assertThat( "y.name",
                                      matcher( "equalTo",
                                               "'yoda'" ) ) )
                .test( rf.assertThat( "y.name, equalTo('yoda')" ) )
                .test( rf.assertThat( "y.age",
                                      matcher( "equalTo",
                                               "160" ) ) )
                .test( rf.assertThat( "y.age, equalTo(160)" ) )

                // @ FIXME commented out until hamsandwich works in the build            
                //             // test hamsandwich
                //             .test( rf.assertThat( "y", matcher( "allOf", matcher("name",  matcher( "equalTo", "'yoda'" ) ),
                //                                                          matcher("age",  matcher( "equalTo", "160" ) )
                //                                                )) )           
                .end()

                // show complex testing after the ksession has finished
                .test( "y.name == 'yoda'" )
                .test( "y.age == 160" )

                // test hamcrest        
                .test( rf.assertThat( "y.name",
                                      matcher( "equalTo",
                                               "'yoda'" ) ) )
                .test( rf.assertThat( "y.age",
                                      matcher( "equalTo",
                                               "160" ) ) );

        // @ FIXME commented out until hamsandwich works in the build     
        //         // test hamsandwich
View Full Code Here

        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" )
             .fireAllRules()
             // show testing inside of ksession execution
             .test( rf.assertThat( "y.age", matcher( "equalTo", "120" ) ) )
             .test( rf.assertThat( "y.age, equalTo(120)" ) );       
        // @formatter:on   
       

        fail = false;
        try {
View Full Code Here

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

TOP

Related Classes of org.drools.fluent.test.impl.ReflectiveMatcherFactory

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.