Package org.drools.ide.common.client.modeldriven.testing

Examples of org.drools.ide.common.client.modeldriven.testing.VerifyRuleFired


        person.getFieldData().add( new FieldData( "cost",
                                                  "42" ) );

        sc.getFixtures().add( person );
        sc.getFixtures().add( new ExecutionTrace() );
        VerifyRuleFired vr = new VerifyRuleFired( "MyGoodRule",
                                                  1,
                                                  null );
        sc.getFixtures().add( vr );

        VerifyFact vf = new VerifyFact();
        vf.setName( "p" );

        vf.getFieldValues().add( new VerifyField( "cost",
                                                  "42",
                                                  "==" ) );
        sc.getFixtures().add( vf );

        ScenarioRunResult res = repositoryPackageService.runScenario( pkg.getName(),
                                                                      sc ).result;
        assertNull( res.getErrors() );
        assertNotNull( res.getScenario() );

        assertTrue( vf.wasSuccessful() );
        assertTrue( vr.wasSuccessful() );

        res = repositoryPackageService.runScenario( pkg.getName(),
                                                    sc ).result;

        assertNull( res.getErrors() );
        assertNotNull( res.getScenario() );

        assertTrue( vf.wasSuccessful() );
        assertTrue( vr.wasSuccessful() );

        RuleBaseCache.getInstance().clearCache();

        res = repositoryPackageService.runScenario( pkg.getName(),
                                                    sc ).result;
        assertNull( res.getErrors() );
        assertNotNull( res.getScenario() );
        assertTrue( vf.wasSuccessful() );
        assertTrue( vr.wasSuccessful() );

    }
View Full Code Here


        person.setName( "p" );
        person.setType( "Person" );

        sc.getFixtures().add( person );
        sc.getFixtures().add( new ExecutionTrace() );
        VerifyRuleFired vr = new VerifyRuleFired( "MyGoodRule",
                                                  1,
                                                  null );
        sc.getFixtures().add( vr );

        ScenarioRunResult res = null;
        try {
            res = repositoryPackageService.runScenario( pkg.getName(),
                                                        sc ).result;
        } catch ( ClassFormatError e ) {
            fail( "Probably failed when loading a source file instead of class file. " + e );
        }

        assertNull( res.getErrors() );
        assertNotNull( res.getScenario() );
        assertTrue( vr.wasSuccessful() );

        res = repositoryPackageService.runScenario( pkg.getName(),
                                                    sc ).result;

        assertNull( res.getErrors() );
        assertNotNull( res.getScenario() );
        assertTrue( vr.wasSuccessful() );

        RuleBaseCache.getInstance().clearCache();

        res = repositoryPackageService.runScenario( pkg.getName(),
                                                    sc ).result;

        assertNull( res.getErrors() );
        assertNotNull( res.getScenario() );
        assertTrue( vr.wasSuccessful() );

    }
View Full Code Here

        person.getFieldData().add( new FieldData( "name",
                                                  "michael" ) );

        sc.getFixtures().add( person );
        sc.getFixtures().add( new ExecutionTrace() );
        VerifyRuleFired vr = new VerifyRuleFired( "rule1",
                                                  1,
                                                  null );
        sc.getFixtures().add( vr );

        VerifyFact vf = new VerifyFact();
        vf.setName( "p" );
        vf.getFieldValues().add( new VerifyField( "name",
                                                  "michael",
                                                  "==" ) );
        vf.getFieldValues().add( new VerifyField( "age",
                                                  "42",
                                                  "==" ) );
        sc.getFixtures().add( vf );

        AssetItem scenario1 = pkg.addAsset( "scen1",
                                            "" );
        scenario1.updateFormat( AssetFormats.TEST_SCENARIO );
        scenario1.updateContent( ScenarioXMLPersistence.getInstance().marshal( sc ) );
        scenario1.checkin( "" );

        //now the bad scenario
        sc = new Scenario();
        person = new FactData();
        person.setName( "p" );
        person.setType( "Person" );
        person.getFieldData().add( new FieldData( "age",
                                                  "40" ) );
        person.getFieldData().add( new FieldData( "name",
                                                  "michael" ) );

        sc.getFixtures().add( person );
        sc.getFixtures().add( new ExecutionTrace() );
        vr = new VerifyRuleFired( "rule2",
                                  1,
                                  null );
        sc.getFixtures().add( vr );

        AssetItem scenario2 = pkg.addAsset( "scen2",
View Full Code Here

        l.add(new CallMethod("x","hello"));


        VerifyFact vf1 = new VerifyFact();
        VerifyFact vf2 = new VerifyFact();
        VerifyRuleFired vr1 = new VerifyRuleFired();
        VerifyRuleFired vr2 = new VerifyRuleFired();
        l.add(vf1);
        l.add(vf2);
        l.add(vr1);
        l.add(vr2);
View Full Code Here

public class ScenarioTest {

    @Test
    public void testInsertBetween() {
        Scenario sc = new Scenario();
        VerifyRuleFired vf = new VerifyRuleFired();
        sc.insertBetween( null,
                          vf );
        assertEquals( 1,
                      sc.getFixtures().size() );
        assertEquals( vf,
                      sc.getFixtures().get( 0 ) );

        VerifyRuleFired vf2 = new VerifyRuleFired();
        sc.getFixtures().add( vf2 );

        VerifyRuleFired vf3 = new VerifyRuleFired();
        sc.insertBetween( vf,
                          vf3 );
        assertEquals( 3,
                      sc.getFixtures().size() );
        assertEquals( vf,
                      sc.getFixtures().get( 0 ) );
        assertEquals( vf2,
                      sc.getFixtures().get( 1 ) );
        assertEquals( vf3,
                      sc.getFixtures().get( 2 ) );

        VerifyRuleFired vf4 = new VerifyRuleFired();
        sc.insertBetween( vf2,
                          vf4 );
        assertEquals( 4,
                      sc.getFixtures().size() );
        assertEquals( 3,
                      sc.getFixtures().indexOf( vf4 ) );
        assertEquals( 2,
                      sc.getFixtures().indexOf( vf3 ) );
        //assertEquals(vf4, sc.fixtures.get(3));
        assertEquals( 1,
                      sc.getFixtures().indexOf( vf2 ) );
        //assertEquals(vf2, sc.fixtures.get(2));
        assertEquals( 0,
                      sc.getFixtures().indexOf( vf ) );

        VerifyRuleFired vf5 = new VerifyRuleFired();
        sc.insertBetween( null,
                          vf5 );
        assertEquals( 5,
                      sc.getFixtures().size() );
        assertEquals( 4,
View Full Code Here

    @Test
    public void testRemoveFixture() {
        Scenario sc = new Scenario();

        VerifyRuleFired vf1 = new VerifyRuleFired();
        VerifyRuleFired vf2 = new VerifyRuleFired();
        VerifyRuleFired vf3 = new VerifyRuleFired();

        FactData fd = new FactData();

        sc.getFixtures().add( vf1 );
        sc.getFixtures().add( vf2 );
View Full Code Here

    @Test
    public void testCountSuccessFailures() {
        Scenario sc = new Scenario();
        sc.getFixtures().add( new FactData() );
        sc.getFixtures().add( new ExecutionTrace() );
        VerifyRuleFired vr = new VerifyRuleFired();
        vr.setSuccessResult( false );
        sc.getFixtures().add( vr );

        VerifyField vf = new VerifyField();
        vf.setSuccessResult( true );
        VerifyField vf2 = new VerifyField();
View Full Code Here

        // and baz, we leave out

        RuleFiredVerifier ruleFiredVerifier = new RuleFiredVerifier();
        ruleFiredVerifier.setFireCounter(firingCounts);

        VerifyRuleFired v = new VerifyRuleFired();
        v.setRuleName("foo");
        v.setExpectedFire(true);

        ruleFiredVerifier.verifyFiringCounts(v);
        assertTrue(v.getSuccessResult());
        assertEquals(2,
                v.getActualResult().intValue());

        v = new VerifyRuleFired();
        v.setRuleName("foo");
        v.setExpectedFire(false);
        ruleFiredVerifier.verifyFiringCounts(v);
        assertFalse(v.getSuccessResult());
        assertEquals(2,
                v.getActualResult().intValue());
        assertNotNull(v.getExplanation());

        v = new VerifyRuleFired();
        v.setRuleName("foo");
        v.setExpectedCount(2);

        ruleFiredVerifier.verifyFiringCounts(v);
        assertTrue(v.getSuccessResult());
        assertEquals(2,
                v.getActualResult().intValue());

    }
View Full Code Here

                1);
        // and baz, we leave out

        RuleFiredVerifier ruleFiredVerifier = new RuleFiredVerifier();
        ruleFiredVerifier.setFireCounter(firingCounts);
        VerifyRuleFired v = new VerifyRuleFired();
        v.setRuleName("foo");
        v.setExpectedFire(true);
        ruleFiredVerifier.verifyFiringCounts(v);
        assertTrue(v.getSuccessResult());
        assertEquals(2,
                v.getActualResult().intValue());
    }
View Full Code Here

    @Test
    public void testVerifyRuleFired() throws Exception {

        RuleFiredVerifier ruleFiredVerifier = new RuleFiredVerifier();

        VerifyRuleFired vr = new VerifyRuleFired("qqq",
                42,
                null);
        Map<String, Integer> f = new HashMap<String, Integer>();
        f.put("qqq",
                42);
        f.put("qaz",
                1);

        ruleFiredVerifier.setFireCounter(f);
        ruleFiredVerifier.verifyFiringCounts(vr);
        assertTrue(vr.wasSuccessful());
        assertEquals(42,
                vr.getActualResult().intValue());

        vr = new VerifyRuleFired("qqq",
                41,
                null);

        ruleFiredVerifier.setFireCounter(f);
        ruleFiredVerifier.verifyFiringCounts(vr);
        assertFalse(vr.wasSuccessful());
        assertEquals(42,
                vr.getActualResult().intValue());

        vr = new VerifyRuleFired("qaz",
                1,
                null);

        ruleFiredVerifier.setFireCounter(f);
        ruleFiredVerifier.verifyFiringCounts(vr);
        assertTrue(vr.wasSuccessful());
        assertEquals(1,
                vr.getActualResult().intValue());

        vr = new VerifyRuleFired("XXX",
                null,
                false);

        ruleFiredVerifier.setFireCounter(f);
        ruleFiredVerifier.verifyFiringCounts(vr);
        assertTrue(vr.wasSuccessful());
        assertEquals(0,
                vr.getActualResult().intValue());

        vr = new VerifyRuleFired("qqq",
                null,
                true);

        ruleFiredVerifier.setFireCounter(f);
        ruleFiredVerifier.verifyFiringCounts(vr);
        assertTrue(vr.wasSuccessful());
        assertEquals(42,
                vr.getActualResult().intValue());

        vr = new VerifyRuleFired("qqq",
                null,
                false);

        ruleFiredVerifier.setFireCounter(f);
        ruleFiredVerifier.verifyFiringCounts(vr);
        assertFalse(vr.wasSuccessful());
        assertEquals(42,
                vr.getActualResult().intValue());

    }
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.testing.VerifyRuleFired

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.