use of org.kie.workbench.common.widgets.client.datamodel.testclasses.Product in project kie-wb-common by kiegroup.
the class PackageDataModelGlobalsTest method testGlobal.
@Test
public void testGlobal() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(Product.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(moduleLoader).addGlobals("global org.kie.workbench.common.widgets.client.datamodel.testclasses.Product g;").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.setGlobalTypes(packageLoader.getPackageGlobals());
dataModel.setCollectionTypes(packageLoader.getModuleCollectionTypes());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertNotNull(oracle);
assertEquals(2, oracle.getFactTypes().length);
assertEquals("Product", oracle.getFactTypes()[0]);
assertEquals("Product.Colour", oracle.getFactTypes()[1]);
assertEquals(1, oracle.getGlobalVariables().length);
assertEquals("g", oracle.getGlobalVariables()[0]);
assertEquals("Product", oracle.getGlobalVariable("g"));
oracle.getFieldCompletions("Product", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertNotNull(fields);
final String[] fieldNames = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
fieldNames[i] = fields[i].getName();
}
assertTrue(Arrays.asList(fieldNames).contains("this"));
assertTrue(Arrays.asList(fieldNames).contains("colour"));
}
});
assertEquals(0, oracle.getGlobalCollections().length);
}
use of org.kie.workbench.common.widgets.client.datamodel.testclasses.Product in project kie-wb-common by kiegroup.
the class PackageDataModelParametricTypesTest method testPackageDMOParametricReturnTypes.
@Test
public void testPackageDMOParametricReturnTypes() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(Purchase.class).addClass(Product.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").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());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertNotNull(oracle);
assertEquals(3, oracle.getFactTypes().length);
List<String> list = Arrays.asList(oracle.getFactTypes());
assertTrue(list.contains("Purchase"));
assertTrue(list.contains("Product"));
assertEquals("java.util.Collection", oracle.getFieldClassName("Purchase", "items"));
assertEquals(DataType.TYPE_COLLECTION, oracle.getFieldType("Purchase", "items"));
assertEquals("Product", oracle.getParametricFieldType("Purchase", "items"));
}
Aggregations