Search in sources :

Example 1 with TestSubClass

use of org.kie.workbench.common.widgets.client.datamodel.testclasses.TestSubClass 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(DataType.TYPE_THIS, 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"));
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) TestSubClass(org.kie.workbench.common.widgets.client.datamodel.testclasses.TestSubClass) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)1 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)1 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)1 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)1 TestSubClass (org.kie.workbench.common.widgets.client.datamodel.testclasses.TestSubClass)1 Path (org.uberfire.backend.vfs.Path)1