use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testSuperClass.
@Test
public void testSuperClass() throws IOException {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSuperClass.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(TestSuperClass.class.getSimpleName(), oracle.getFactTypes()[0]);
oracle.getFieldCompletions(TestSuperClass.class.getSimpleName(), new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(3, fields.length);
}
});
assertEquals("TestSuperClass", oracle.getFieldType(TestSuperClass.class.getSimpleName(), "this"));
assertEquals(TestSuperClass.class.getSimpleName(), oracle.getFieldClassName(TestSuperClass.class.getSimpleName(), "this"));
assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestSuperClass.class.getSimpleName(), "field1"));
assertEquals(String.class.getName(), oracle.getFieldClassName(TestSuperClass.class.getSimpleName(), "field1"));
assertEquals(DataType.TYPE_COLLECTION, oracle.getFieldType(TestSuperClass.class.getSimpleName(), "list"));
assertEquals(List.class.getName(), oracle.getFieldClassName(TestSuperClass.class.getSimpleName(), "list"));
assertEquals(String.class.getName(), oracle.getParametricFieldType(TestSuperClass.class.getSimpleName(), "list"));
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testSubClass.
@Test
public void testSubClass() throws IOException {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSubClass.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(TestSubClass.class.getSimpleName(), oracle.getFactTypes()[0]);
oracle.getFieldCompletions(TestSubClass.class.getSimpleName(), new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(4, 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.INHERITED, field.getOrigin());
} else if ("field2".equals(field.getName())) {
assertEquals(ModelField.FIELD_ORIGIN.DECLARED, field.getOrigin());
} else if ("list".equals(field.getName())) {
assertEquals(ModelField.FIELD_ORIGIN.DELEGATED, field.getOrigin());
}
}
}
});
assertEquals("TestSubClass", oracle.getFieldType(TestSubClass.class.getSimpleName(), "this"));
assertEquals(TestSubClass.class.getSimpleName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "this"));
assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestSubClass.class.getSimpleName(), "field1"));
assertEquals(String.class.getName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "field1"));
assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestSubClass.class.getSimpleName(), "field2"));
assertEquals(String.class.getName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "field2"));
assertEquals(DataType.TYPE_COLLECTION, oracle.getFieldType(TestSubClass.class.getSimpleName(), "list"));
assertEquals(List.class.getName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "list"));
assertEquals(String.class.getName(), oracle.getParametricFieldType(TestSubClass.class.getSimpleName(), "list"));
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleTest method testImportedNestedClassMethodInformationImportBothTypes.
@Test
public void testImportedNestedClassMethodInformationImportBothTypes() 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"));
imports.addImport(new Import("org.kie.workbench.common.widgets.client.datamodel.testclasses.Product"));
}
@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 SimpleName as the return type has been imported
final MethodInfo mf1 = new MethodInfo("methodDoingSomethingThatReturnsAnOuterClass", new ArrayList<String>(), Product.class.getSimpleName(), null, Product.class.getSimpleName());
// Use FQCN as the return type has not been imported
final MethodInfo mf2 = new MethodInfo("methodDoingSomethingWithNestedField1", new ArrayList<String>(), String.class, null, DataType.TYPE_STRING);
assertTrue(methodInfos.contains(mf0));
assertTrue(methodInfos.contains(mf1));
assertTrue(methodInfos.contains(mf2));
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelServiceTest method testModuleDataModelOracle.
@Test
public void testModuleDataModelOracle() throws Exception {
final Bean dataModelServiceBean = (Bean) beanManager.getBeans(DataModelService.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(dataModelServiceBean);
final DataModelService dataModelService = (DataModelService) beanManager.getReference(dataModelServiceBean, DataModelService.class, cc);
final URL packageUrl = this.getClass().getResource("/DataModelBackendTest1/src/main/java/t3p1");
final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
final Path packagePath = paths.convert(nioPackagePath);
final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
final ModuleDataModelOracle moduleLoader = dataModelService.getModuleDataModel(packagePath);
// 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.setModelFields(moduleLoader.getModuleModelFields());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertNotNull(oracle);
assertEquals(3, oracle.getAllFactTypes().length);
assertContains("t3p1.Bean1", oracle.getAllFactTypes());
assertContains("t3p2.Bean2", oracle.getAllFactTypes());
assertContains("java.lang.String", oracle.getAllFactTypes());
oracle.getFieldCompletions("t3p1.Bean1", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(3, fields.length);
assertContains("this", fields);
assertContains("field1", fields);
assertContains("field2", fields);
}
});
oracle.getFieldCompletions("t3p2.Bean2", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(2, fields.length);
assertContains("this", fields);
assertContains("field1", fields);
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelServiceTest method testPackageDataModelOracle.
@Test
public void testPackageDataModelOracle() throws Exception {
final Bean dataModelServiceBean = (Bean) beanManager.getBeans(DataModelService.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(dataModelServiceBean);
final DataModelService dataModelService = (DataModelService) beanManager.getReference(dataModelServiceBean, DataModelService.class, cc);
final URL packageUrl = this.getClass().getResource("/DataModelBackendTest1/src/main/java/t3p1");
final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
final Path packagePath = paths.convert(nioPackagePath);
final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
// 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("t3p1");
dataModel.setModelFields(packageLoader.getModuleModelFields());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertNotNull(oracle);
assertEquals(3, oracle.getAllFactTypes().length);
assertContains("t3p1.Bean1", oracle.getAllFactTypes());
assertContains("t3p2.Bean2", oracle.getAllFactTypes());
assertContains("java.lang.String", oracle.getAllFactTypes());
assertEquals(1, oracle.getFactTypes().length);
assertContains("Bean1", oracle.getFactTypes());
oracle.getFieldCompletions("Bean1", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(3, fields.length);
assertContains("this", fields);
assertContains("field1", fields);
assertContains("field2", fields);
}
});
assertEquals(2, oracle.getExternalFactTypes().length);
assertContains("t3p2.Bean2", oracle.getExternalFactTypes());
assertContains("java.lang.String", oracle.getExternalFactTypes());
}
Aggregations