use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testImports.
@Test
public void testImports() {
final String drl = "import java.util.ArrayList;\n" + "rule \"r0\"\n" + "dialect \"mvel\"" + "when\n" + "then\n" + "end\n";
PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
assertNotNull(m);
assertEquals(1, m.getImports().getImports().size());
assertEquals("java.util.ArrayList", m.getImports().getImports().get(0).getType());
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testFreeFormatDRLCondition.
@Test
public void testFreeFormatDRLCondition() {
final String drl = "rule \"r0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$a : Applicant( )\n" + "Here's something typed by the user as free-format DRL\n" + "$b : Bananna( )\n" + "then\n" + "end\n";
PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
assertNotNull(m);
// LHS
assertEquals(3, m.lhs.length);
// Condition line 1
assertTrue(m.lhs[0] instanceof FactPattern);
final FactPattern fp1 = (FactPattern) m.lhs[0];
assertEquals("$a", fp1.getBoundName());
assertEquals("Applicant", fp1.getFactType());
// Condition line 2
assertTrue(m.lhs[1] instanceof FreeFormLine);
final FreeFormLine ffl = (FreeFormLine) m.lhs[1];
assertEquals("Here's something typed by the user as free-format DRL", ffl.getText());
// Condition line 3
assertTrue(m.lhs[2] instanceof FactPattern);
final FactPattern fp2 = (FactPattern) m.lhs[2];
assertEquals("$b", fp2.getBoundName());
assertEquals("Bananna", fp2.getFactType());
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.
the class ScenarioTestEditorServiceImpl method constructContent.
@Override
protected TestScenarioModelContent constructContent(Path path, Overview overview) {
final Scenario scenario = load(path);
final String packageName = moduleService.resolvePackage(path).getPackageName();
final PackageDataModelOracle dataModelOracle = getDataModel(path);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
final Set<String> usedFullyQualifiedClassNames = getUsedFullyQualifiedClassNames(scenario, dataModelOracle);
DataModelOracleUtilities.populateDataModel(dataModelOracle, dataModel, usedFullyQualifiedClassNames);
// Signal opening to interested parties
resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
return new TestScenarioModelContent(scenario, overview, packageName, dataModel);
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle 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);
}
}
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.
the class GuidedDecisionTableEditorServiceImpl method loadDataModel.
@Override
public PackageDataModelOracleBaselinePayload loadDataModel(final Path path) {
try {
final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
// There are no classes to pre-load into the DMO when requesting a new Data Model only
DataModelOracleUtilities.populateDataModel(oracle, dataModel, new HashSet<String>());
return dataModel;
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
Aggregations