Search in sources :

Example 1 with Imports

use of org.kie.soup.project.datamodel.imports.Imports in project drools by kiegroup.

the class RuleModelDRLPersistenceImpl method getRuleModel.

private RuleModel getRuleModel(final ExpandedDRLInfo expandedDRLInfo, final PackageDataModelOracle dmo, final Collection<RuleModelIActionPersistenceExtension> extensions) throws RuleModelDRLPersistenceException {
    // De-serialize model
    RuleDescr ruleDescr = parseDrl(expandedDRLInfo);
    RuleModel model = new RuleModel();
    model.name = ruleDescr.getName();
    model.parentName = ruleDescr.getParentName();
    for (AnnotationDescr annotation : ruleDescr.getAnnotations()) {
        model.addMetadata(new RuleMetadata(annotation.getName(), annotation.getValuesAsString()));
    }
    // De-serialize Package name
    final String packageName = PackageNameParser.parsePackageName(expandedDRLInfo.plainDrl);
    model.setPackageName(packageName);
    // De-serialize imports
    final Imports imports = ImportsParser.parseImports(expandedDRLInfo.plainDrl);
    for (Import item : imports.getImports()) {
        model.getImports().addImport(item);
    }
    boolean isJavaDialect = parseAttributes(model, ruleDescr.getAttributes());
    Map<String, String> boundParams = parseLhs(model, ruleDescr.getLhs(), isJavaDialect, expandedDRLInfo, dmo);
    parseRhs(model, expandedDRLInfo.consequence != null ? expandedDRLInfo.consequence : (String) ruleDescr.getConsequence(), isJavaDialect, boundParams, expandedDRLInfo, dmo, extensions);
    return model;
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) Imports(org.kie.soup.project.datamodel.imports.Imports) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) AnnotationDescr(org.drools.compiler.lang.descr.AnnotationDescr)

Example 2 with Imports

use of org.kie.soup.project.datamodel.imports.Imports in project drools by kiegroup.

the class ScenarioXMLPersistence method unmarshal.

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;
}
Also used : Imports(org.kie.soup.project.datamodel.imports.Imports) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 3 with Imports

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

the class ScenarioTestEditorServiceImpl method runScenario.

@Override
public TestScenarioResult runScenario(final String userName, final Path path, final Scenario scenario) {
    final Imports existingScenarioImports = new Imports(scenario.getImports().getImports());
    try {
        addDependentImportsToScenario(scenario, path);
        final TestScenarioResult result = scenarioRunner.run(userName, scenario, moduleService.resolveModule(path));
        return result;
    } catch (final Exception e) {
        throw ExceptionUtilities.handleException(e);
    } finally {
        scenario.setImports(existingScenarioImports);
    }
}
Also used : Imports(org.kie.soup.project.datamodel.imports.Imports) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 4 with Imports

use of org.kie.soup.project.datamodel.imports.Imports 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 5 with Imports

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

the class ScenarioTestEditorServiceImplTest method runScenarioWithDependentImports.

@Test
public void runScenarioWithDependentImports() throws Exception {
    final ArrayList<Fixture> fixtures = new ArrayList<Fixture>() {

        {
            add(factData("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()).thenReturn(new Imports());
    testEditorService.addDependentImportsToScenario(scenario, path);
    assertEquals(2, scenario.getImports().getImports().size());
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) Mockito.anyString(org.mockito.Mockito.anyString) Imports(org.kie.soup.project.datamodel.imports.Imports) Test(org.junit.Test)

Aggregations

Imports (org.kie.soup.project.datamodel.imports.Imports)17 Test (org.junit.Test)8 Import (org.kie.soup.project.datamodel.imports.Import)8 ArrayList (java.util.ArrayList)5 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)5 HashMap (java.util.HashMap)4 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)4 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)3 Mockito.anyString (org.mockito.Mockito.anyString)3 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)2 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)2 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)2 Before (org.junit.Before)2 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)2 URI (java.net.URI)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)1 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)1 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)1