use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelGlobalsTest method testGlobalCollections.
@Test
public void testGlobalCollections() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(java.util.List.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.services.datamodel.backend.server.testclasses").setModuleOracle(moduleLoader).addGlobals("global java.util.List list;").build();
final HasImports imports = new MockHasImports();
imports.getImports().addImport(new Import("java.util.List"));
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setGlobalTypes(packageLoader.getPackageGlobals());
dataModel.setCollectionTypes(packageLoader.getModuleCollectionTypes());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), imports, oracle, dataModel);
assertNotNull(oracle);
assertEquals(1, oracle.getFactTypes().length);
assertEquals("List", oracle.getFactTypes()[0]);
assertEquals(1, oracle.getGlobalVariables().length);
assertEquals("list", oracle.getGlobalVariables()[0]);
assertEquals("List", oracle.getGlobalVariable("list"));
assertEquals(1, oracle.getGlobalCollections().length);
assertEquals("list", oracle.getGlobalCollections()[0]);
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelMethodsTest method testMethodsOnJavaClass_Number.
@Test
public void testMethodsOnJavaClass_Number() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(Number.class).addFact("int").end().build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "p0").setModuleOracle(moduleLoader).build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setMethodInformation(packageLoader.getModuleMethodInformation());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new HasImports() {
private Imports imports = new Imports() {
{
addImport(new Import("java.lang.Number"));
}
};
@Override
public Imports getImports() {
return imports;
}
@Override
public void setImports(final Imports imports) {
// Do nothing
}
}, oracle, dataModel);
oracle.getMethodInfos(Number.class.getSimpleName(), new Callback<List<MethodInfo>>() {
@Override
public void callback(final List<MethodInfo> methodInfos) {
assertNotNull(methodInfos);
assertFalse(methodInfos.isEmpty());
for (final MethodInfo methodInfo : methodInfos) {
assertFalse("Method " + methodInfo.getName() + " is not allowed.", checkBlackList(methodInfo.getName()));
}
}
});
oracle.getMethodInfos("int", new Callback<List<MethodInfo>>() {
@Override
public void callback(final List<MethodInfo> methodInfos) {
assertNotNull(methodInfos);
assertTrue(methodInfos.isEmpty());
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleCEPCompletionsTest method testCEPCompletions.
@Test
public void testCEPCompletions() {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("NotAnEvent").addField(new ModelField("dateField", Date.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_DATE)).end().addFact("AnEvent", true).addField(new ModelField("this", Object.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.SELF, FieldAccessorsAndMutators.BOTH, "AnEvent")).addField(new ModelField("dateField", Date.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_DATE)).end().build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(moduleLoader).build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setEventTypes(packageLoader.getModuleEventTypes());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
// Check completions
String[] types = oracle.getFactTypes();
assertEquals(2, types.length);
PackageDataModelOracleTestUtils.assertContains("NotAnEvent", types);
PackageDataModelOracleTestUtils.assertContains("AnEvent", types);
oracle.getOperatorCompletions("NotAnEvent", "dateField", new Callback<String[]>() {
@Override
public void callback(final String[] notAnEventDateFieldOperators) {
assertEquals(13, notAnEventDateFieldOperators.length);
assertEquals(notAnEventDateFieldOperators[0], "==");
assertEquals(notAnEventDateFieldOperators[1], "!=");
assertEquals(notAnEventDateFieldOperators[2], "<");
assertEquals(notAnEventDateFieldOperators[3], ">");
assertEquals(notAnEventDateFieldOperators[4], "<=");
assertEquals(notAnEventDateFieldOperators[5], ">=");
assertEquals(notAnEventDateFieldOperators[6], "== null");
assertEquals(notAnEventDateFieldOperators[7], "!= null");
assertEquals(notAnEventDateFieldOperators[8], "in");
assertEquals(notAnEventDateFieldOperators[9], "not in");
assertEquals(notAnEventDateFieldOperators[10], "after");
assertEquals(notAnEventDateFieldOperators[11], "before");
assertEquals(notAnEventDateFieldOperators[12], "coincides");
}
});
oracle.getOperatorCompletions("AnEvent", "this", new Callback<String[]>() {
@Override
public void callback(final String[] anEventThisOperators) {
assertEquals(17, anEventThisOperators.length);
assertEquals(anEventThisOperators[0], "==");
assertEquals(anEventThisOperators[1], "!=");
assertEquals(anEventThisOperators[2], "== null");
assertEquals(anEventThisOperators[3], "!= null");
assertEquals(anEventThisOperators[4], "after");
assertEquals(anEventThisOperators[5], "before");
assertEquals(anEventThisOperators[6], "coincides");
assertEquals(anEventThisOperators[7], "during");
assertEquals(anEventThisOperators[8], "finishes");
assertEquals(anEventThisOperators[9], "finishedby");
assertEquals(anEventThisOperators[10], "includes");
assertEquals(anEventThisOperators[11], "meets");
assertEquals(anEventThisOperators[12], "metby");
assertEquals(anEventThisOperators[13], "overlaps");
assertEquals(anEventThisOperators[14], "overlappedby");
assertEquals(anEventThisOperators[15], "starts");
assertEquals(anEventThisOperators[16], "startedby");
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleCompletionsTest method testFactCompletions.
@Test
public void testFactCompletions() {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("rank", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_COMPARABLE)).addField(new ModelField("name", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addFact("Vehicle").addField(new ModelField("make", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("type", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(moduleLoader).build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
String[] types = oracle.getFactTypes();
assertEquals(2, types.length);
assertContains("Person", types);
assertContains("Vehicle", types);
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleCompletionsTest method testFactsAndFields.
@Test
public void testFactsAndFields() {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(moduleLoader).build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(DataType.TYPE_NUMERIC_INTEGER, oracle.getFieldType("Person", "age"));
assertEquals(DataType.TYPE_STRING, oracle.getFieldType("Person", "sex"));
}
Aggregations