use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testBasicDependentEnums.
@Test
public void testBasicDependentEnums() {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("field1", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addFact("Driver").addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("'Fact.field1' : ['val1', 'val2'], 'Fact.field2' : ['val3', 'val4'], 'Fact.field2[field1=val1]' : ['f1val1a', 'f1val1b'], 'Fact.field2[field1=val2]' : ['f1val2a', 'f1val2b']", Thread.currentThread().getContextClassLoader()).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);
assertEquals("String", oracle.getFieldType("Fact", "field1"));
assertEquals("String", oracle.getFieldType("Fact", "field2"));
String[] field1Enums = oracle.getEnumValues("Fact", "field1");
assertEquals(2, field1Enums.length);
assertEquals("val1", field1Enums[0]);
assertEquals("val2", field1Enums[1]);
String[] field2Enums = oracle.getEnumValues("Fact", "field2");
assertEquals(2, field2Enums.length);
assertEquals("val3", field2Enums[0]);
assertEquals("val4", field2Enums[1]);
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testSmartLookupEnums.
@Test
public void testSmartLookupEnums() {
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[f1, f2]", new String[] { "select something from database where x=@{f1} and y=@{f2}" }).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);
Map<String, String> currentValueMap = new HashMap<>();
currentValueMap.put("f1", "f1val");
currentValueMap.put("f2", "f2val");
DropDownData dd = oracle.getEnums("Fact", "value", currentValueMap);
assertNull(dd.getFixedList());
assertNotNull(dd.getQueryExpression());
assertNotNull(dd.getValuePairs());
assertEquals(2, dd.getValuePairs().length);
assertEquals("select something from database where x=@{f1} and y=@{f2}", dd.getQueryExpression());
assertEquals("f1=f1val", dd.getValuePairs()[0]);
assertEquals("f2=f2val", dd.getValuePairs()[1]);
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testDataHasEnumsFieldSuffixes.
@Test
public void testDataHasEnumsFieldSuffixes() {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("field1", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2suffixed", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("'Fact.field1' : ['val1', 'val2'], 'Fact.field2[field1=val1]' : ['f1val1a', 'f1val1b']", Thread.currentThread().getContextClassLoader()).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);
// Fact.field1 has explicit enumerations
assertTrue(oracle.hasEnums("Fact.field1"));
assertTrue(oracle.hasEnums("Fact", "field1"));
// Fact.field2 has explicit enumerations dependent upon Fact.field1
assertTrue(oracle.hasEnums("Fact.field2"));
assertTrue(oracle.hasEnums("Fact", "field2"));
// Fact.field2suffixed has no enums
assertFalse(oracle.hasEnums("Fact.field2suffixed"));
assertFalse(oracle.hasEnums("Fact", "field2suffixed"));
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testIndirectRecursion.
@Test
public void testIndirectRecursion() throws Exception {
// Build ModuleDMO
final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, new HashMap<String, FactBuilder>(), TestIndirectRecursionClassA.class, false, TypeSource.JAVA_PROJECT);
cb.build(moduleLoader);
// Build PackageDMO
final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
packageBuilder.setModuleOracle(moduleLoader);
final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(1, oracle.getFactTypes().length);
assertEquals("TestIndirectRecursionClassA", oracle.getFactTypes()[0]);
oracle.getFieldCompletions("TestIndirectRecursionClassA", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] result) {
assertEquals(2, result.length);
assertEquals("TestIndirectRecursionClassB", result[0].getClassName());
assertEquals("recursiveField", result[0].getName());
assertEquals("TestIndirectRecursionClassA", result[1].getClassName());
assertEquals(DataType.TYPE_THIS, result[1].getName());
}
});
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testDirectRecursion.
@Test
public void testDirectRecursion() throws Exception {
// Build ModuleDMO
final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, new HashMap<String, FactBuilder>(), TestDirectRecursionClass.class, false, TypeSource.JAVA_PROJECT);
cb.build(moduleLoader);
// Build PackageDMO
final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
packageBuilder.setModuleOracle(moduleLoader);
final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(1, oracle.getFactTypes().length);
assertEquals("TestDirectRecursionClass", oracle.getFactTypes()[0]);
oracle.getFieldCompletions("TestDirectRecursionClass", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] result) {
assertEquals(2, result.length);
assertEquals("TestDirectRecursionClass", result[0].getClassName());
assertEquals("recursiveField", result[0].getName());
assertEquals("TestDirectRecursionClass", result[1].getClassName());
assertEquals(DataType.TYPE_THIS, result[1].getName());
}
});
}
Aggregations