Search in sources :

Example 6 with Imports

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

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

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

the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.

private GuidedDecisionTree visit(final String drl, final String baseFileName, final List<String> globals, final PackageDataModelOracle dmo) {
    PortablePreconditions.checkNotNull("drl", drl);
    PortablePreconditions.checkNotNull("baseFileName", baseFileName);
    PortablePreconditions.checkNotNull("globals", globals);
    PortablePreconditions.checkNotNull("dmo", dmo);
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName(baseFileName);
    // De-serialize Package name
    final String packageName = PackageNameParser.parsePackageName(drl);
    model.setPackageName(packageName);
    // De-serialize imports
    final Imports imports = ImportsParser.parseImports(drl);
    for (Import item : imports.getImports()) {
        model.getImports().addImport(item);
    }
    // Split DRL into separate rules
    final List<String> rules = new ArrayList<String>();
    final Pattern pattern = Pattern.compile("\\s?rule\\s(.+?)\\send\\s?", Pattern.DOTALL);
    final Matcher matcher = pattern.matcher(drl);
    while (matcher.find()) {
        rules.add(matcher.group());
    }
    // Build a linear Path of Nodes for each rule
    final List<GuidedDecisionTreeParserExtendedError> rulesParserContent = new ArrayList<GuidedDecisionTreeParserExtendedError>();
    for (String rule : rules) {
        final GuidedDecisionTreeParserExtendedError ruleParserContent = new GuidedDecisionTreeParserExtendedError();
        rulesParserContent.add(ruleParserContent);
        try {
            final RuleModel rm = RuleModelDRLPersistenceImpl.getInstance().unmarshal(rule, globals, dmo);
            ruleParserContent.setOriginalRuleName(rm.name);
            ruleParserContent.setOriginalDrl(rule);
            for (IPattern p : rm.lhs) {
                ruleParserContent.getNodes().addAll(visit(p, model, dmo, ruleParserContent.getMessages()));
            }
            for (IAction a : rm.rhs) {
                ruleParserContent.getNodes().addAll(visit(a, getTypesOnPath(ruleParserContent.getNodes()), model, dmo, ruleParserContent.getMessages()));
            }
        } catch (Exception e) {
            ruleParserContent.getMessages().add(new DefaultParserMessage(e.getMessage()));
        }
    }
    // Combine Paths into a single tree.
    for (GuidedDecisionTreeParserExtendedError ruleParserContent : rulesParserContent) {
        Node activeModelNode = null;
        boolean error = !ruleParserContent.getMessages().isEmpty();
        for (int index = 0; !error && index < ruleParserContent.getNodes().size(); index++) {
            final Node node = ruleParserContent.getNodes().get(index);
            switch(index) {
                case 0:
                    if (!(node instanceof TypeNode)) {
                        ruleParserContent.getMessages().add(new InvalidRootParserMessage());
                        error = true;
                        break;
                    }
                    final TypeNode root = (TypeNode) node;
                    if (model.getRoot() == null) {
                        model.setRoot(root);
                    } else if (!root.equals(model.getRoot())) {
                        ruleParserContent.getMessages().add(new AmbiguousRootParserMessage(root.getClassName()));
                        error = true;
                        break;
                    }
                    activeModelNode = model.getRoot();
                    break;
                default:
                    if (!activeModelNode.getChildren().contains(node)) {
                        // If the active node in the Model doesn't contain the child add it as a new child
                        activeModelNode.addChild(node);
                        activeModelNode = node;
                    } else {
                        // Otherwise swap out the Node in the Path for the existing one in the Model
                        activeModelNode = activeModelNode.getChildren().get(activeModelNode.getChildren().indexOf(node));
                    }
            }
        }
        if (!ruleParserContent.getMessages().isEmpty()) {
            model.getParserErrors().add(new GuidedDecisionTreeParserError(ruleParserContent.getOriginalRuleName(), ruleParserContent.getOriginalDrl(), ruleParserContent.getMessages()));
        }
    }
    return model;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) Pattern(java.util.regex.Pattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) Import(org.kie.soup.project.datamodel.imports.Import) IAction(org.drools.workbench.models.datamodel.rule.IAction) Matcher(java.util.regex.Matcher) InvalidRootParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.InvalidRootParserMessage) GuidedDecisionTreeParserError(org.drools.workbench.models.guided.dtree.shared.model.parser.GuidedDecisionTreeParserError) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ArrayList(java.util.ArrayList) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) DefaultParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DefaultParserMessage) Imports(org.kie.soup.project.datamodel.imports.Imports) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) AmbiguousRootParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.AmbiguousRootParserMessage)

Example 9 with Imports

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

the class GuidedDecisionTableSourceServiceTest method setUp.

@Before
public void setUp() throws Exception {
    service = new GuidedDecisionTableSourceService(resourceTypeDefinition, guidedDecisionTableEditorService, ioService, fileDiscoveryService, moduleService);
    // Simulates that no DSL files are present
    when(moduleService.resolvePackage(any())).thenReturn(packageMock);
    when(discoveryService.discoverFiles(any(), any())).thenReturn(new ArrayList<Path>());
    when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>());
    when(path.getFileSystem()).thenReturn(fileSystem);
    when(path.toString()).thenReturn("/");
    when(path.getFileName()).thenReturn(path);
    when(path.toUri()).thenReturn(new URI("/"));
    model = new GuidedDecisionTable52();
    model.setPackageName("com.sample");
    model.setImports(new Imports(Arrays.asList(new Import("com.sample.Person"))));
    model.setRowNumberCol(new RowNumberCol52());
    model.setDescriptionCol(new DescriptionCol52());
    pattern = new Pattern52();
    pattern.setBoundName("$p");
    pattern.setFactType("Person");
    nameEqualToLiteralCondition = new ConditionCol52();
    nameEqualToLiteralCondition.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    nameEqualToLiteralCondition.setHeader("name equals to");
    nameEqualToLiteralCondition.setFactField("name");
    nameEqualToLiteralCondition.setOperator("==");
    pattern.setChildColumns(Arrays.asList(nameEqualToLiteralCondition));
    model.setConditionPatterns(Arrays.asList(pattern));
    data = new ArrayList<>();
}
Also used : Path(org.uberfire.java.nio.file.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Import(org.kie.soup.project.datamodel.imports.Import) Imports(org.kie.soup.project.datamodel.imports.Imports) URI(java.net.URI) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Before(org.junit.Before)

Example 10 with Imports

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

the class BaseGuidedDecisionTableEditorPresenterTest method testActivateDocument.

@Test
public void testActivateDocument() {
    final GuidedDecisionTableView.Presenter dtPresenter = mock(GuidedDecisionTableView.Presenter.class);
    final Overview overview = mock(Overview.class);
    final AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
    final GuidedDecisionTable52 model = mock(GuidedDecisionTable52.class);
    final Imports imports = mock(Imports.class);
    final GuidedDecisionTablePresenter.Access access = mock(GuidedDecisionTablePresenter.Access.class);
    final MultiPageEditor pageEditor = mock(MultiPageEditor.class);
    final boolean isEditable = true;
    doReturn(overview).when(dtPresenter).getOverview();
    doReturn(oracle).when(dtPresenter).getDataModelOracle();
    doReturn(model).when(dtPresenter).getModel();
    doReturn(imports).when(model).getImports();
    doReturn(access).when(dtPresenter).getAccess();
    doReturn(isEditable).when(access).isEditable();
    doReturn(pageEditor).when(presenter).getKieEditorWrapperMultiPage();
    doNothing().when(presenter).activateDocument(any(), any(), any(), any(), anyBoolean());
    presenter.activateDocument(dtPresenter);
    verify(dtPresenter).activate();
    verify(presenter).enableMenus(true);
    verify(presenter).addColumnsTab();
    verify(presenter).enableColumnsTab(dtPresenter);
    verify(presenter).activateDocument(dtPresenter, overview, oracle, imports, !isEditable);
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) GuidedDecisionTablePresenter(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter) Overview(org.guvnor.common.services.shared.metadata.model.Overview) MultiPageEditor(org.uberfire.client.workbench.widgets.multipage.MultiPageEditor) Imports(org.kie.soup.project.datamodel.imports.Imports) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) 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