use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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"));
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testImportedNestedClassMethodInformation.
@Test
public void testImportedNestedClassMethodInformation() 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.setMethodInformation(packageLoader.getModuleMethodInformation());
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);
}
});
oracle.getMethodInfos("TestSuperClass.NestedClass", new Callback<List<MethodInfo>>() {
@Override
public void callback(final List<MethodInfo> methodInfos) {
assertNotNull(methodInfos);
assertEquals(3, methodInfos.size());
// Use SimpleName as the return type has been imported
final MethodInfo mf0 = new MethodInfo("methodDoingSomethingThatReturnsAnInnerClass", new ArrayList<String>(), "TestSuperClass.NestedClass", null, "TestSuperClass.NestedClass");
// Use FQCN as the return type has not been imported
final MethodInfo mf1 = new MethodInfo("methodDoingSomethingWithNestedField1", new ArrayList<String>(), String.class, null, DataType.TYPE_STRING);
// Use FQCN as the return type has not been imported
final MethodInfo mf2 = new MethodInfo("methodDoingSomethingThatReturnsAnOuterClass", new ArrayList<String>(), Product.class.getName(), null, Product.class.getName());
assertTrue(methodInfos.contains(mf0));
assertTrue(methodInfos.contains(mf1));
assertTrue(methodInfos.contains(mf2));
}
});
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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(DataType.TYPE_THIS, 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"));
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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"));
}
use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.
the class PackageDataModelParametricTypesTest method testParametricMethod.
@Test
public void testParametricMethod() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(Purchase.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("Product", oracle.getParametricFieldType("Purchase", "customerPurchased(Integer)"));
}
Aggregations