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

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


        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 testIndexTestScenario() throws IOException, InterruptedException {
        //Add test files
        final Path path1 = basePath.resolve( "scenario1.scenario" );
        final Scenario model1 = TestScenarioFactory.makeTestScenarioWithVerifyFact( "org.drools.workbench.screens.testscenario.backend.server.indexing",
                                                                                    new ArrayList<Import>() {{
                                                                                        add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant" ) );
                                                                                        add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage" ) );
                                                                                    }},
                                                                                    "scenario1" );
        final String xml1 = ScenarioXMLPersistence.getInstance().marshal( model1 );
        ioService().write( path1,
                           xml1 );
        final Path path2 = basePath.resolve( "scenario2.scenario" );
        final Scenario model2 = TestScenarioFactory.makeTestScenarioWithoutVerifyFact( "org.drools.workbench.screens.testscenario.backend.server.indexing",
                                                                                       new ArrayList<Import>() {{
                                                                                           add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant" ) );
                                                                                           add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage" ) );
                                                                                       }},
                                                                                       "scenario2" );
View Full Code Here

public class TestScenarioFactory {

    public static Scenario makeTestScenarioWithVerifyFact( final String packageName,
                                                           final Collection<Import> imports,
                                                           final String name ) {
        final Scenario model = new Scenario();
        model.getImports().getImports().addAll( imports );
        model.setPackageName( packageName );
        model.setName( name );

        model.getFixtures().add( new FactData( "Applicant",
                                               "$a",
                                               new ArrayList<Field>() {{
                                                   add( new FieldData( "age",
                                                                       "33" ) );
                                               }},
                                               false ) );
        model.getFixtures().add( new VerifyFact( "Mortgage",
                                                 new ArrayList<VerifyField>() {{
                                                     add( new VerifyField( "amount",
                                                                           "10000",
                                                                           "==" ) );
                                                 }},
View Full Code Here

    }

    public static Scenario makeTestScenarioWithoutVerifyFact( final String packageName,
                                                              final Collection<Import> imports,
                                                              final String name ) {
        final Scenario model = new Scenario();
        model.getImports().getImports().addAll( imports );
        model.setPackageName( packageName );
        model.setName( name );

        model.getFixtures().add( new FactData( "Applicant",
                                               "$a",
                                               new ArrayList<Field>() {{
                                                   add( new FieldData( "age",
                                                                       "33" ) );
                                               }},
View Full Code Here

    @Test
    public void testIndexTestScenario() throws IOException, InterruptedException {
        //Add test files
        final Path path1 = basePath.resolve( "scenario1.scenario" );
        final Scenario model1 = TestScenarioFactory.makeTestScenarioWithVerifyFact( "org.drools.workbench.screens.testscenario.backend.server.indexing",
                                                                                    new ArrayList<Import>() {{
                                                                                        add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant" ) );
                                                                                        add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage" ) );
                                                                                    }},
                                                                                    "scenario1" );
        final String xml1 = ScenarioXMLPersistence.getInstance().marshal( model1 );
        ioService().write( path1,
                           xml1 );
        final Path path2 = basePath.resolve( "scenario2.scenario" );
        final Scenario model2 = TestScenarioFactory.makeTestScenarioWithoutVerifyFact( "org.drools.workbench.screens.testscenario.backend.server.indexing",
                                                                                       new ArrayList<Import>() {{
                                                                                           add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant" ) );
                                                                                           add( new Import( "org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage" ) );
                                                                                       }},
                                                                                       "scenario2" );
View Full Code Here

        String s = xt.toXML(sc);
        return s;
    }

    public Scenario unmarshal(String xml) {
        if (xml == null) return new Scenario();
        if (xml.trim().equals("")) return new Scenario();
        Object o = xt.fromXML(xml);

        Scenario scenario = (Scenario) o;

        if (scenario.getImports() == null) {
            scenario.setImports(new Imports());
        }

        return scenario;
    }
View Full Code Here

        service.call(
                getSuccessCallback( presenter ),
                new HasBusyIndicatorDefaultErrorCallback( busyIndicatorView ) ).create( pkg.getPackageTestResourcesPath(),
                                                                                        buildFileName( baseFileName,
                                                                                                       resourceType ),
                                                                                        new Scenario( pkg.getPackageName(),
                                                                                                      baseFileName ),
                                                                                        "" );
    }
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

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.