Search in sources :

Example 26 with Scenario

use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.

the class TestScenarioFactory method makeTestScenarioWithoutVerifyFact.

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"));
        }
    }, false));
    return model;
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 27 with Scenario

use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.

the class TestScenarioFactory method makeTestScenarioWithVerifyRuleFired.

// See https://bugzilla.redhat.com/show_bug.cgi?id=1179158
public static Scenario makeTestScenarioWithVerifyRuleFired(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 VerifyRuleFired("test", 1, true));
    return model;
}
Also used : VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 28 with Scenario

use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.

the class IndexTestScenarioTest method testIndexTestScenario.

@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");
    final String xml2 = ScenarioXMLPersistence.getInstance().marshal(model2);
    ioService().write(path2, xml2);
    final Path path3 = basePath.resolve("scenario3.scenario");
    final Scenario model3 = TestScenarioFactory.makeTestScenarioWithVerifyRuleFired("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"));
        }
    }, "scenario3");
    final String xml3 = ScenarioXMLPersistence.getInstance().marshal(model3);
    ioService().write(path3, xml3);
    final Path path4 = basePath.resolve("scenario4.scenario");
    final Scenario model4 = TestScenarioFactory.makeTestScenarioWithGlobalVerifyGlobal("org.drools.workbench.screens.testscenario.backend.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("java.util.Date"));
        }
    }, "scenario1");
    final String xml4 = ScenarioXMLPersistence.getInstance().marshal(model4);
    ioService().write(path4, xml4);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    // Test Scenarios using org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1, path2);
    }
    // Test Scenarios using org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path1);
    }
    // Test Scenarios using org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage#amount
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage", "amount", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
    // Test Scenarios using java.lang.Integer
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("java.lang.Integer", ResourceType.JAVA)).build();
        searchFor(index, query, 3, path1, path2);
    }
    // Test Scenarios expecting rule "test" to fire
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("test", ResourceType.RULE)).build();
        searchFor(index, query, 1, path3);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("java.util.Date", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path4);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValuePartReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm) Import(org.kie.soup.project.datamodel.imports.Import) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 29 with Scenario

use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.

the class ScenarioRunnerService method getKSessions.

private Map<String, KieSession> getKSessions(Path path, List<Scenario> scenarios) {
    Map<String, KieSession> ksessions = new HashMap<String, KieSession>();
    for (Scenario scenario : scenarios) {
        String ksessionName = getKSessionName(scenario.getKSessions());
        ksessions.put(ksessionName, loadKSession(moduleService.resolveModule(path), ksessionName));
    }
    return ksessions;
}
Also used : HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 30 with Scenario

use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.

the class TestScenarioFileIndexer method fillIndexBuilder.

@Override
public DefaultIndexBuilder fillIndexBuilder(final Path path) throws Exception {
    final String content = ioService.readAllString(path);
    final Scenario model = ScenarioXMLPersistence.getInstance().unmarshal(content);
    final ModuleDataModelOracle dmo = getModuleDataModelOracle(path);
    final Module project = moduleService.resolveModule(Paths.convert(path));
    final Package pkg = moduleService.resolvePackage(Paths.convert(path));
    final DefaultIndexBuilder builder = new DefaultIndexBuilder(Paths.convert(path).getFileName(), project, pkg);
    final TestScenarioIndexVisitor visitor = new TestScenarioIndexVisitor(dmo, builder, model);
    visitor.visit();
    addReferencedResourcesToIndexBuilder(builder, visitor);
    return builder;
}
Also used : ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) Package(org.guvnor.common.services.project.model.Package) DefaultIndexBuilder(org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder) Module(org.guvnor.common.services.project.model.Module) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Aggregations

Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)59 Test (org.junit.Test)45 FactData (org.drools.workbench.models.testscenarios.shared.FactData)24 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)20 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)17 KieSession (org.kie.api.runtime.KieSession)14 Import (org.kie.soup.project.datamodel.imports.Import)14 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)13 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)12 ArrayList (java.util.ArrayList)11 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)9 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)6 Path (org.uberfire.backend.vfs.Path)6 Field (org.drools.workbench.models.testscenarios.shared.Field)5 HashMap (java.util.HashMap)4 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)4 Failure (org.junit.runner.notification.Failure)4 RunListener (org.junit.runner.notification.RunListener)4 RunNotifier (org.junit.runner.notification.RunNotifier)4 Date (java.util.Date)3