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);
}
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());
}
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;
}
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<>();
}
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);
}
Aggregations