use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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.", checkBlackList(methodInfo.getName()));
}
}
});
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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) {
assertEquals(4, personThisOperators.length);
assertEquals(personThisOperators[0], "==");
assertEquals(personThisOperators[1], "!=");
assertEquals(personThisOperators[2], "== null");
assertEquals(personThisOperators[3], "!= null");
}
});
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) {
assertEquals(10, personAgeOperators.length);
assertEquals(personAgeOperators[0], "==");
assertEquals(personAgeOperators[1], "!=");
assertEquals(personAgeOperators[2], "<");
assertEquals(personAgeOperators[3], ">");
assertEquals(personAgeOperators[4], "<=");
assertEquals(personAgeOperators[5], ">=");
assertEquals(personAgeOperators[6], "== null");
assertEquals(personAgeOperators[7], "!= null");
assertEquals(personAgeOperators[8], "in");
assertEquals(personAgeOperators[9], "not in");
}
});
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) {
assertEquals(8, personRankOperators.length);
assertEquals(personRankOperators[0], "==");
assertEquals(personRankOperators[1], "!=");
assertEquals(personRankOperators[2], "<");
assertEquals(personRankOperators[3], ">");
assertEquals(personRankOperators[4], "<=");
assertEquals(personRankOperators[5], ">=");
assertEquals(personRankOperators[6], "== null");
assertEquals(personRankOperators[7], "!= null");
}
});
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) {
assertEquals(14, personNameOperators.length);
assertEquals("==", personNameOperators[0]);
assertEquals("!=", personNameOperators[1]);
assertEquals("<", personNameOperators[2]);
assertEquals(">", personNameOperators[3]);
assertEquals("<=", personNameOperators[4]);
assertEquals(">=", personNameOperators[5]);
assertEquals("matches", personNameOperators[6]);
assertEquals("not matches", personNameOperators[7]);
assertEquals("soundslike", personNameOperators[8]);
assertEquals("not soundslike", personNameOperators[9]);
assertEquals("== null", personNameOperators[10]);
assertEquals("!= null", personNameOperators[11]);
assertEquals("in", personNameOperators[12]);
assertEquals("not in", personNameOperators[13]);
}
});
oracle.getOperatorCompletions("Person", "name", personNameCallback);
verify(personNameCallback).callback(any(String[].class));
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testJavaEnum1.
@Test
public void testJavaEnum1() throws IOException {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestJavaEnum1.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(projectLoader).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.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(2, oracle.getFactTypes().length);
assertEquals("TestJavaEnum1.TestEnum", oracle.getFactTypes()[1]);
final DropDownData dd = oracle.getEnums(TestJavaEnum1.class.getSimpleName(), "field1");
assertNotNull(dd);
assertEquals(3, dd.getFixedList().length);
assertEquals("TestJavaEnum1.TestEnum.ZERO=TestJavaEnum1.TestEnum.ZERO", dd.getFixedList()[0]);
assertEquals("TestJavaEnum1.TestEnum.ONE=TestJavaEnum1.TestEnum.ONE", dd.getFixedList()[1]);
assertEquals("TestJavaEnum1.TestEnum.TWO=TestJavaEnum1.TestEnum.TWO", dd.getFixedList()[2]);
final String[] ddValues = oracle.getEnumValues(TestJavaEnum1.class.getSimpleName(), "field1");
assertNotNull(ddValues);
assertEquals(3, ddValues.length);
assertEquals("TestJavaEnum1.TestEnum.ZERO=TestJavaEnum1.TestEnum.ZERO", ddValues[0]);
assertEquals("TestJavaEnum1.TestEnum.ONE=TestJavaEnum1.TestEnum.ONE", ddValues[1]);
assertEquals("TestJavaEnum1.TestEnum.TWO=TestJavaEnum1.TestEnum.TWO", ddValues[2]);
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testSmartEnums1.
@Test
public void testSmartEnums1() {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("type", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("value", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("Fact", "type", new String[] { "sex", "colour" }).addEnum("Fact", "value[type=sex]", new String[] { "M", "F" }).addEnum("Fact", "value[type=colour]", new String[] { "RED", "WHITE", "BLUE" }).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).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.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
String[] typeResult = oracle.getEnums("Fact", "type").getFixedList();
assertEquals(2, typeResult.length);
assertEquals("sex", typeResult[0]);
assertEquals("colour", typeResult[1]);
Map<String, String> currentValueMap = new HashMap<>();
currentValueMap.put("type", "sex");
String[] typeSexResult = oracle.getEnums("Fact", "value", currentValueMap).getFixedList();
assertEquals(2, typeSexResult.length);
assertEquals("M", typeSexResult[0]);
assertEquals("F", typeSexResult[1]);
currentValueMap.clear();
currentValueMap.put("type", "colour");
String[] typeColourResult = oracle.getEnums("Fact", "value", currentValueMap).getFixedList();
assertEquals(3, typeColourResult.length);
assertEquals("RED", typeColourResult[0]);
assertEquals("WHITE", typeColourResult[1]);
assertEquals("BLUE", typeColourResult[2]);
}
Aggregations