use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelMethodsTest method testMethodsOnJavaClass_ArrayList.
@Test
public void testMethodsOnJavaClass_ArrayList() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(ArrayList.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "java.util").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 MockHasImports(), oracle, dataModel);
oracle.getMethodInfos(ArrayList.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.", checkDenyList(methodInfo.getName()));
}
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelMethodsTest method testMethodsOnJavaClass_TreeMap.
@Test
public void testMethodsOnJavaClass_TreeMap() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TreeMap.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "java.util").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 MockHasImports(), oracle, dataModel);
oracle.getFieldCompletions(TreeMap.class.getSimpleName(), FieldAccessorsAndMutators.ACCESSOR, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] getters) {
assertEquals(2, getters.length);
assertEquals("empty", getters[0].getName());
assertEquals("this", getters[1].getName());
}
});
oracle.getMethodInfos(TreeMap.class.getSimpleName(), new Callback<List<MethodInfo>>() {
@Override
public void callback(final List<MethodInfo> mis) {
assertContains("ceilingEntry", mis);
assertContains("ceilingKey", mis);
assertContains("clear", mis);
assertContains("clone", mis);
assertContains("comparator", mis);
assertContains("containsKey", mis);
assertContains("containsValue", mis);
assertContains("descendingKeySet", mis);
assertContains("descendingMap", mis);
assertContains("firstEntry", mis);
assertContains("firstKey", mis);
assertContains("floorEntry", mis);
assertContains("floorKey", mis);
assertContains("get", mis);
assertContains("headMap", mis);
assertContains("headMap", mis);
assertContains("higherEntry", mis);
assertContains("higherKey", mis);
assertContains("lastEntry", mis);
assertContains("lastKey", mis);
assertContains("lowerEntry", mis);
assertContains("lowerKey", mis);
assertContains("navigableKeySet", mis);
assertContains("pollFirstEntry", mis);
assertContains("pollLastEntry", mis);
assertContains("put", mis);
assertContains("remove", mis);
assertContains("size", mis);
assertContains("subMap", mis);
assertContains("subMap", mis);
assertContains("tailMap", mis);
assertContains("tailMap", mis);
assertContains("values", mis);
}
});
oracle.getFieldCompletions(TreeMap.class.getSimpleName(), FieldAccessorsAndMutators.MUTATOR, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] setters) {
assertEquals(0, setters.length);
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleCompletionsTest method testFactFieldOperatorCompletions.
@Test
public void testFactFieldOperatorCompletions() {
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().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);
Callback<String[]> personCallback = spy(new Callback<String[]>() {
@Override
public void callback(final String[] personThisOperators) {
assertArrayEquals(new String[] { "==", "!=", "== null", "!= null", "memberOf", "not memberOf" }, personThisOperators);
}
});
oracle.getOperatorCompletions("Person", "this", personCallback);
verify(personCallback).callback(any(String[].class));
Callback<String[]> personAgeCallback = spy(new Callback<String[]>() {
@Override
public void callback(final String[] personAgeOperators) {
assertArrayEquals(new String[] { "==", "!=", "<", ">", "<=", ">=", "== null", "!= null", "memberOf", "not memberOf", "in", "not in" }, personAgeOperators);
}
});
oracle.getOperatorCompletions("Person", "age", personAgeCallback);
verify(personAgeCallback).callback(any(String[].class));
Callback<String[]> personRankCallback = spy(new Callback<String[]>() {
@Override
public void callback(final String[] personRankOperators) {
assertArrayEquals(new String[] { "==", "!=", "<", ">", "<=", ">=", "== null", "!= null", "memberOf", "not memberOf" }, personRankOperators);
}
});
oracle.getOperatorCompletions("Person", "rank", personRankCallback);
verify(personRankCallback).callback(any(String[].class));
Callback<String[]> personNameCallback = spy(new Callback<String[]>() {
@Override
public void callback(final String[] personNameOperators) {
assertArrayEquals(new String[] { "==", "!=", "<", ">", "<=", ">=", "contains", "not contains", "matches", "not matches", "soundslike", "not soundslike", "memberOf", "not memberOf", "== null", "!= null", "in", "not in" }, personNameOperators);
}
});
oracle.getOperatorCompletions("Person", "name", personNameCallback);
verify(personNameCallback).callback(any(String[].class));
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleCompletionsTest method testFactFieldCompletions.
@Test
public void testFactFieldCompletions() {
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().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);
Callback<ModelField[]> callback = spy(new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(4, fields.length);
assertEquals("age", fields[0].getName());
assertEquals("name", fields[1].getName());
assertEquals("rank", fields[2].getName());
assertEquals("this", fields[3].getName());
}
});
oracle.getFieldCompletions("Person", callback);
verify(callback).callback(any(ModelField[].class));
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testImportedNestedClass.
@Test
public void testImportedNestedClass() throws IOException {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSuperClass.NestedClass.class).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.setFieldParametersType(packageLoader.getModuleFieldParametersType());
final HasImports hasImports = new HasImports() {
final Imports imports = new Imports();
{
imports.addImport(new Import("org.kie.workbench.common.widgets.client.datamodel.testclasses.TestSuperClass.NestedClass"));
}
@Override
public Imports getImports() {
return imports;
}
@Override
public void setImports(Imports imports) {
}
};
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), hasImports, oracle, dataModel);
assertEquals(1, oracle.getFactTypes().length);
assertEquals("TestSuperClass.NestedClass", oracle.getFactTypes()[0]);
oracle.getFieldCompletions("TestSuperClass.NestedClass", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(2, fields.length);
}
});
assertEquals("TestSuperClass.NestedClass", oracle.getFieldType("TestSuperClass.NestedClass", "this"));
assertEquals("TestSuperClass.NestedClass", oracle.getFieldClassName("TestSuperClass.NestedClass", "this"));
assertEquals(DataType.TYPE_STRING, oracle.getFieldType("TestSuperClass.NestedClass", "nestedField1"));
assertEquals(String.class.getName(), oracle.getFieldClassName("TestSuperClass.NestedClass", "nestedField1"));
}
Aggregations