Search in sources :

Example 36 with Import

use of org.kie.soup.project.datamodel.imports.Import in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImplTest method checkScenarioRunnerIsRan.

@Test
public void checkScenarioRunnerIsRan() throws Exception {
    final Imports imports = new Imports() {

        {
            addImport(new Import("java.sql.ClientInfoStatus"));
        }
    };
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(scenario.getImports()).thenCallRealMethod();
    doCallRealMethod().when(scenario).setImports(any(Imports.class));
    scenario.setImports(imports);
    testEditorService.runScenario("userName", path, scenario);
    KieModule module = mock(KieModule.class);
    when(moduleService.resolveModule(path)).thenReturn(module);
    testEditorService.runScenario("userName", path, scenario);
    verify(scenarioRunner).run("userName", scenario, module);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) Imports(org.kie.soup.project.datamodel.imports.Imports) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 37 with Import

use of org.kie.soup.project.datamodel.imports.Import in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImplTest method checkDependentImportsWithPrimitiveTypes.

@Test
public void checkDependentImportsWithPrimitiveTypes() throws Exception {
    final ArrayList<Fixture> fixtures = new ArrayList<>();
    final Imports imports = new Imports() {

        {
            addImport(new Import("int"));
        }
    };
    final Map<String, ModelField[]> modelFields = new HashMap<String, ModelField[]>() {

        {
            put("java.sql.ClientInfoStatus", new ModelField[] { modelField("java.sql.JDBCType") });
        }
    };
    when(scenario.getFixtures()).thenReturn(fixtures);
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(modelOracle.getModuleModelFields()).thenReturn(modelFields);
    when(scenario.getImports()).thenCallRealMethod();
    doCallRealMethod().when(scenario).setImports(any(Imports.class));
    scenario.setImports(imports);
    testEditorService.addDependentImportsToScenario(scenario, path);
    assertEquals(1, scenario.getImports().getImports().size());
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) Imports(org.kie.soup.project.datamodel.imports.Imports) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 38 with Import

use of org.kie.soup.project.datamodel.imports.Import in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImplTest method checkSingleScenarioMultipleExecution.

@Test
public void checkSingleScenarioMultipleExecution() throws Exception {
    final ArrayList<Fixture> fixtures = new ArrayList<>();
    final Imports imports = new Imports() {

        {
            addImport(new Import("java.sql.ClientInfoStatus"));
        }
    };
    final Map<String, ModelField[]> modelFields = new HashMap<String, ModelField[]>() {

        {
            put("java.sql.ClientInfoStatus", new ModelField[] { modelField("java.sql.JDBCType") });
        }
    };
    when(scenario.getFixtures()).thenReturn(fixtures);
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(modelOracle.getModuleModelFields()).thenReturn(modelFields);
    when(scenario.getImports()).thenCallRealMethod();
    doCallRealMethod().when(scenario).setImports(any(Imports.class));
    scenario.setImports(imports);
    testEditorService.runScenario("userName", path, scenario);
    assertEquals(1, scenario.getImports().getImports().size());
    testEditorService.runScenario("userName", path, scenario);
    assertEquals(1, scenario.getImports().getImports().size());
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) Imports(org.kie.soup.project.datamodel.imports.Imports) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 39 with Import

use of org.kie.soup.project.datamodel.imports.Import in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImpl method addDependentImportsToScenario.

void addDependentImportsToScenario(final Scenario scenario, final Path path) {
    final PackageDataModelOracle dataModel = getDataModel(path);
    final Set<String> usedFullyQualifiedClassNames = getUsedFullyQualifiedClassNames(scenario, dataModel);
    for (String className : usedFullyQualifiedClassNames) {
        final Import imp = new Import(className);
        final List<Import> scenarioImports = scenario.getImports().getImports();
        if (!scenarioImports.contains(imp)) {
            scenarioImports.add(imp);
        }
    }
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)

Example 40 with Import

use of org.kie.soup.project.datamodel.imports.Import 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).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)

Aggregations

Import (org.kie.soup.project.datamodel.imports.Import)103 Test (org.junit.Test)79 Imports (org.kie.soup.project.datamodel.imports.Imports)26 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)25 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)14 ArrayList (java.util.ArrayList)12 Path (org.uberfire.java.nio.file.Path)12 Query (org.apache.lucene.search.Query)11 FactData (org.drools.workbench.models.testscenarios.shared.FactData)11 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)11 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)11 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)11 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)10 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)9 KieSession (org.kie.api.runtime.KieSession)9 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)9 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)9 Path (org.uberfire.backend.vfs.Path)9 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)8 Analyzer (org.drools.verifier.core.main.Analyzer)7