Package org.drools.workbench.models.testscenarios.shared

Examples of org.drools.workbench.models.testscenarios.shared.Scenario


    }

    @Test
    public void testIntegrationWithModify() throws Exception {
        Scenario sc = new Scenario();
        sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));

        sc.getFixtures().add(new FactData("Cheese",
                "c1",
                Arrays.<Field>asList(new FieldData("price",
                        "1")),
                false));

        sc.getFixtures().add(new ExecutionTrace());

        sc.getFixtures().add(new VerifyFact("c1",
                ls(new VerifyField("type",
                        "rule1",
                        "=="))));

        sc.getFixtures().add(new FactData("Cheese",
                "c1",
                Arrays.<Field>asList(new FieldData("price",
                        "42")),
                true));
        sc.getFixtures().add(new ExecutionTrace());

        sc.getFixtures().add(new VerifyFact("c1",
                ls(new VerifyField("type",
                        "rule3",
                        "=="))));

        KieSession ksession = getKieSession("test_stateful.drl");
        ScenarioRunner run = new ScenarioRunner(ksession);

        run.run(sc);

        assertTrue(sc.wasSuccessful());
    }
View Full Code Here


        assertTrue(sc.wasSuccessful());
    }

    @Test
    public void testIntegrationWithRetract() throws Exception {
        Scenario sc = new Scenario();
        sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));

        sc.getFixtures().add(new FactData("Cheese",
                "c1",
                Arrays.<Field>asList(new FieldData("price",
                        "46"),
                        new FieldData("type",
                                "XXX")),
                false));
        sc.getFixtures().add(new FactData("Cheese",
                "c2",
                Arrays.<Field>asList(new FieldData("price",
                        "42")),
                false));
        sc.getFixtures().add(new ExecutionTrace());

        sc.getFixtures().add(new VerifyFact("c1",
                ls(new VerifyField("type",
                        "XXX",
                        "=="))));

        sc.getFixtures().add(new RetractFact("c2"));
        sc.getFixtures().add(new ExecutionTrace());

        sc.getFixtures().add(new VerifyFact("c1",
                ls(new VerifyField("type",
                        "rule4",
                        "=="))));

        KieSession ksession = getKieSession("test_stateful.drl");
        ScenarioRunner run = new ScenarioRunner(ksession);
        run.run(sc);

        assertTrue(sc.wasSuccessful());
    }
View Full Code Here

        assertTrue(sc.wasSuccessful());
    }

    @Test
    public void testIntegrationWithFailure() throws Exception {
        Scenario sc = new Scenario();
        sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
        sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Person"));

        Expectation[] assertions = populateScenarioForFailure(sc);

        KieSession ksession = getKieSession("test_rules2.drl");

        ScenarioRunner run = new ScenarioRunner(ksession);

        run.run(sc);

        assertFalse(sc.wasSuccessful());

        VerifyFact vf = (VerifyFact) assertions[1];
        assertFalse((vf.getFieldValues().get(0)).getSuccessResult());
        assertEquals("XXX",
                vf.getFieldValues().get(0).getExpected());
View Full Code Here

        KieSession ksession = getKieSession("test_rules2.drl");

        ScenarioRunner run = new ScenarioRunner(ksession);

        Scenario scenario = new Scenario();
        scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
        scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheesery"));

        run.run(scenario);

    }
View Full Code Here

    }

    @Test
    public void testImports() throws Exception {

        Scenario scenario = new Scenario();
        scenario.setPackageName("org.drools.workbench.models.testscenarios.backend");

        ScenarioRunner runner = new ScenarioRunner(ksession);

        scenario.getFixtures().add(
                new FactData(
                        "Cheese",
                        "f1",
                        Collections.EMPTY_LIST,
                        false
                ));

        runner.run(scenario);

        assertTrue(scenario.wasSuccessful());

    }
View Full Code Here

    }

    @Test
    public void testPopulateFactsWithInterfaces() throws Exception {
        Scenario sc = new Scenario();
        sc.getImports().addImport(new Import("java.util.List"));
        List facts = ls(new FactData("List",
                "ls",
                new ArrayList(),
                false));

        List globals = ls(new FactData("List",
                "ls",
                new ArrayList(),
                false));
        sc.getFixtures().addAll(facts);
        sc.getGlobals().addAll(globals);

        ScenarioRunner runner = new ScenarioRunner(ksession);
        runner.run(sc);

    }
View Full Code Here

    }

    @Test
    public void testVerifyFacts() throws Exception {

        Scenario scenario = new Scenario();
        scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
        scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Person"));

        ScenarioRunner runner = new ScenarioRunner(ksession);

        scenario.getFixtures().add(
                new FactData(
                        "Cheese",
                        "f1",
                        Arrays.<Field>asList(
                                new FieldData(
                                        "type",
                                        "cheddar"),
                                new FieldData(
                                        "price",
                                        "42")),
                        false
                ));

        scenario.getFixtures().add(
                new FactData(
                        "Person",
                        "f2",
                        Arrays.<Field>asList(
                                new FieldData(
                                        "name",
                                        "michael"),
                                new FieldData(
                                        "age",
                                        "33")),
                        false
                ));

        // test all true
        VerifyFact verifyCheddar = new VerifyFact();
        verifyCheddar.setName("f1");
        verifyCheddar.setFieldValues(
                asList(
                        new VerifyField(
                                "type",
                                "cheddar",
                                "=="),
                        new VerifyField(
                                "price",
                                "42",
                                "==")));

        scenario.getFixtures().add(verifyCheddar);

        VerifyFact michaelVerifyFact = new VerifyFact();
        michaelVerifyFact.setName("f2");
        michaelVerifyFact.setFieldValues(
                asList(
                        new VerifyField(
                                "name",
                                "michael",
                                "=="),
                        new VerifyField(
                                "age",
                                "33",
                                "==")));

        scenario.getFixtures().add(michaelVerifyFact);

        // test one false
        VerifyFact markVerifyFact = new VerifyFact();
        markVerifyFact.setName("f2");
        markVerifyFact.setFieldValues(
                asList(
                        new VerifyField(
                                "name",
                                "mark",
                                "=="),
                        new VerifyField(
                                "age",
                                "33",
                                "==")));

        scenario.getFixtures().add(markVerifyFact);

        // test 2 false
        VerifyFact mark2VerifyFact = new VerifyFact();
        mark2VerifyFact.setName("f2");
        mark2VerifyFact.setFieldValues(
                asList(
                        new VerifyField(
                                "name",
                                "mark",
                                "=="),
                        new VerifyField(
                                "age",
                                "32",
                                "==")));

        scenario.getFixtures().add(mark2VerifyFact);

        runner.run(scenario);

        for (VerifyField verifyField : verifyCheddar.getFieldValues()) {
            assertTrue(verifyField.getSuccessResult());
View Full Code Here

                "f1",
                Arrays.<Field>asList(cheeseType),
                false
        );

        Scenario scenario = new Scenario();
        scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
        scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.CheeseType"));
        scenario.getFixtures().add(cheeseFactData);
        scenario.getFixtures().add(f1);

        ScenarioRunner runner = new ScenarioRunner(ksession);

        VerifyFact vf = new VerifyFact();
        vf.setName("f1");
        VerifyField verifyField = new VerifyField(
                "cheeseType",
                "CheeseType.CHEDDAR",
                "==");
        verifyField.setNature(VerifyField.TYPE_ENUM);
        vf.setFieldValues(ls(verifyField));
        scenario.getFixtures().add(vf);

        runner.run(scenario);

        for (VerifyField field : vf.getFieldValues()) {
            assertTrue(field.getSuccessResult());
View Full Code Here

        }
    }

    @Test
    public void testTestingEventListener() throws Exception {
        Scenario sc = new Scenario();
        sc.getRules().add("foo");
        sc.getRules().add("bar");
        ExecutionTrace ext = new ExecutionTrace();

        sc.getFixtures().add(ext);

        PseudoClockScheduler clock = new PseudoClockScheduler();
        long time = new Date().getTime();
        clock.setStartupTime(time);
        when(ksession.getSessionClock()).thenReturn(clock);

        ScenarioRunner run = new ScenarioRunner(ksession);
        run.run(sc);

        verify(ksession).addEventListener(any(TestingEventListener.class));
        assertEquals(2,
                sc.getRules().size());
        assertTrue(sc.getRules().contains("foo"));
        assertTrue(sc.getRules().contains("bar"));
    }
View Full Code Here

    /**
     * Check if global list is empty.
     */
    @Test
    public void testWithGlobalList() throws Exception {
        Scenario sc = new Scenario();
        sc.getImports().addImport(new Import("java.util.List"));
        ArrayList testList = new ArrayList();
        sc.getGlobals().add(new FactData("List",
                "testList",
                testList,
                false));

        Expectation[] assertions = new Expectation[2];

        assertions[0] = new VerifyFact("testList",
                ls(new VerifyField("empty",
                        "true",
                        "==")));
        assertions[1] = new VerifyFact("testList",
                ls(new VerifyField("size",
                        "0",
                        "==")));

        sc.getFixtures().addAll(Arrays.asList(assertions));

        ScenarioRunner run = new ScenarioRunner(ksession);
        run.run(sc);

        verify(ksession).setGlobal("testList", testList);
View Full Code Here

TOP

Related Classes of org.drools.workbench.models.testscenarios.shared.Scenario

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.