Package org.drools.fluent.simulation

Examples of org.drools.fluent.simulation.SimulationFluent


public class PolicyApprovalRulesTest {

    @Test
    public void approvePolicyRequest() {
        SimulationFluent simulationFluent = new DefaultSimulationFluent();

        Driver john = new Driver("John", "Smith", new LocalDate(1970, 1, 1));
        Car mini = new Car("MINI-01", CarType.SMALL, false, new BigDecimal("10000.00"));
        PolicyRequest johnMiniPolicyRequest = new PolicyRequest(john, mini);
        johnMiniPolicyRequest.addCoverageRequest(new CoverageRequest(CoverageType.COLLISION));
        johnMiniPolicyRequest.addCoverageRequest(new CoverageRequest(CoverageType.COMPREHENSIVE));


        // @formatter:off         
        simulationFluent
        .newKnowledgeBuilder()
            .add(ResourceFactory.newClassPathResource("org/drools/examples/carinsurance/rule/policyRequestApprovalRules.drl"),
                    ResourceType.DRL)
            .end()
        .newKnowledgeBase()
View Full Code Here


        // @formatter:on
    }

    @Test
    public void rejectMinors() {
        SimulationFluent simulationFluent = new DefaultSimulationFluent();

        Driver john = new Driver("John", "Smith", new LocalDate().minusYears(10));
        Car mini = new Car("MINI-01", CarType.SMALL, false, new BigDecimal("10000.00"));
        PolicyRequest johnMiniPolicyRequest = new PolicyRequest(john, mini);
        johnMiniPolicyRequest.addCoverageRequest(new CoverageRequest(CoverageType.COLLISION));
        johnMiniPolicyRequest.addCoverageRequest(new CoverageRequest(CoverageType.COMPREHENSIVE));


        // @formatter:off
        simulationFluent
        .newKnowledgeBuilder()
            .add(ResourceFactory.newClassPathResource("org/drools/examples/carinsurance/rule/policyRequestApprovalRules.drl"),
                    ResourceType.DRL)
            .end()
        .newKnowledgeBase()
View Full Code Here

        // @formatter:on
    }

    @Test(expected = AssertionError.class)
    public void rejectMinorsFailingAssertion() {
        SimulationFluent simulationFluent = new DefaultSimulationFluent();

        Driver john = new Driver("John", "Smith", new LocalDate().minusYears(10));
        Car mini = new Car("MINI-01", CarType.SMALL, false, new BigDecimal("10000.00"));
        PolicyRequest johnMiniPolicyRequest = new PolicyRequest(john, mini);
        johnMiniPolicyRequest.addCoverageRequest(new CoverageRequest(CoverageType.COLLISION));
        johnMiniPolicyRequest.addCoverageRequest(new CoverageRequest(CoverageType.COMPREHENSIVE));


        // @formatter:off
        simulationFluent
        .newKnowledgeBuilder()
            .add(ResourceFactory.newClassPathResource("org/drools/examples/carinsurance/rule/policyRequestApprovalRules.drl"),
                    ResourceType.DRL)
            .end()
        .newKnowledgeBase()
View Full Code Here

    //        }
    //    }

    @Test
    public void testSimpleForAllAssertionsTypes() {
        SimulationFluent f = new DefaultSimulationFluent();

        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.newKnowledgeBuilder()
            .add( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                   ResourceType.DRL )
            .end()
        .newStatefulKnowledgeSession()
            .insert( new Person( "yoda", 150 ) ).set( "y" )
View Full Code Here

        // @formatter:on
    }

    @Test
    public void testAssertionsFail() {
        SimulationFluent f = new DefaultSimulationFluent();

        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.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 {
            f.runSimulation();
        } catch ( AssertionError e) {
            fail = true;
        }
        assertTrue( "Assertion should have failed", fail );
View Full Code Here

        //        }         
    }

    @Test @Ignore("Doing newKSession on the same path twice doesn't make the second one the active one") // TODO FIXME
    public void testMultipleKsessionsWithSteps() {
        SimulationFluent f = new DefaultSimulationFluent();

        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.newKnowledgeBuilder()
            .add( ResourceFactory.newByteArrayResource( str1.getBytes() ),
                                   ResourceType.DRL )
            .end()
        .newRelativeStep( 100 )
        .newStatefulKnowledgeSession()
View Full Code Here

public class StandardjBPM5FluentTest {

    @Test
    public void testUsingImplicit() {
        SimulationFluent f = new DefaultSimulationFluent();
       
        VariableContext<Person> pc = f.<Person> getVariableContext();

        List<String> imports = new ArrayList<String>();
        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" +
                "  when\n" +
                "  then\n" +
                "    list.add( kcontext.getKnowledgeRuntime().getSessionClock().getCurrentTime() );\n" +
                "end\n" +
                "rule updateAge no-loop\n" +
                "  when\n" +
                "    $p : Person()\n" +
                "  then\n" +
                "    list.add( kcontext.getKnowledgeRuntime().getSessionClock().getCurrentTime() );\n" +
                "    modify( $p ) {\n" +
                "      setAge( $p.getAge() + 10 )\n" +
                "    };\n" +
                "end\n";
        String strProcess = "<definitions id='Definition' "
                + "targetNamespace='http://www.jboss.org/drools' "
                + "typeLanguage='http://www.java.com/javaTypes' "
                + "expressionLanguage='http://www.mvel.org/2.0' "
                + "xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL' "
                + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
                + "xsi:schemaLocation='http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd' "
                + "xmlns:g='http://www.jboss.org/drools/flow/gpd' "
                + "xmlns:bpmndi='http://www.omg.org/spec/BPMN/20100524/DI' "
                + "xmlns:dc='http://www.omg.org/spec/DD/20100524/DC' "
                + "xmlns:di='http://www.omg.org/spec/DD/20100524/DI' "
                + "xmlns:tns='http://www.jboss.org/drools'>"
                            + " <process id='DummyProcess' name='Sample Process'>"
                                    + "<startEvent id='_1' name='StartProcess' />"
                                    + "<scriptTask id='_2' name='Script 1' >"
                                       + "<script>System.out.println('Script 1 - Executing .. ');</script> "
                                    + "</scriptTask>"
                                    + "<scriptTask id='_3' name='Script 2' >"
                                        + "<script>System.out.println('Script 2 - Executing .. ');</script>"
                                    + "</scriptTask>"
                                    + "<endEvent id='_4' name='End' >"
                                        + "<terminateEventDefinition/>"
                                    + "</endEvent>"
                                    + "<sequenceFlow id='_1-_2' sourceRef='_1' targetRef='_2' />"
                                    + "<sequenceFlow id='_2-_3' sourceRef='_2' targetRef='_3' />"
                                    + "<sequenceFlow id='_3-_4' sourceRef='_3' targetRef='_4' />"
                            + "</process>"
                + "</definitions>";
       
        List list = new ArrayList();
       
        VariableContext<?> vc = f.getVariableContext();
        // @formatter:off         
        f.newPath("init")
            .newStep( 0 )
                .newKnowledgeBuilder()
                    .add( ResourceFactory.newByteArrayResource( str.getBytes() ),
                          ResourceType.DRL )
                    .add( ResourceFactory.newByteArrayResource( strProcess.getBytes() ),
View Full Code Here

TOP

Related Classes of org.drools.fluent.simulation.SimulationFluent

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.