use of org.kie.workbench.common.widgets.client.datamodel.testclasses.TestDelegatedClass in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testDelegatedClass.
@Test
public void testDelegatedClass() throws IOException {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestDelegatedClass.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);
assertEquals(1, oracle.getFactTypes().length);
assertEquals(TestDelegatedClass.class.getSimpleName(), oracle.getFactTypes()[0]);
oracle.getFieldCompletions(TestDelegatedClass.class.getSimpleName(), new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(3, fields.length);
for (ModelField field : fields) {
if ("this".equals(field.getName())) {
assertEquals(ModelField.FIELD_ORIGIN.SELF, field.getOrigin());
} else if ("field1".equals(field.getName())) {
assertEquals(ModelField.FIELD_ORIGIN.DELEGATED, field.getOrigin());
} else if ("list".equals(field.getName())) {
assertEquals(ModelField.FIELD_ORIGIN.DELEGATED, field.getOrigin());
}
}
}
});
assertEquals(DataType.TYPE_THIS, oracle.getFieldType(TestDelegatedClass.class.getSimpleName(), "this"));
assertEquals(TestDelegatedClass.class.getSimpleName(), oracle.getFieldClassName(TestDelegatedClass.class.getSimpleName(), "this"));
assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestDelegatedClass.class.getSimpleName(), "field1"));
assertEquals(String.class.getName(), oracle.getFieldClassName(TestDelegatedClass.class.getSimpleName(), "field1"));
assertEquals(DataType.TYPE_COLLECTION, oracle.getFieldType(TestDelegatedClass.class.getSimpleName(), "list"));
assertEquals(List.class.getName(), oracle.getFieldClassName(TestDelegatedClass.class.getSimpleName(), "list"));
assertEquals(String.class.getName(), oracle.getParametricFieldType(TestDelegatedClass.class.getSimpleName(), "list"));
}
Aggregations