Search in sources :

Example 1 with Product

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);
}
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) Product(org.kie.workbench.common.widgets.client.datamodel.testclasses.Product) 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) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 2 with Product

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"));
}
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) Product(org.kie.workbench.common.widgets.client.datamodel.testclasses.Product) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Aggregations

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