Search in sources :

Example 46 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testSmartEnumsDependingOnSeveralFields1.

@Test
public void testSmartEnumsDependingOnSeveralFields1() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("field1", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field3", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field4", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("Fact", "field1", new String[] { "a1", "a2" }).addEnum("Fact", "field2", new String[] { "b1", "b2" }).addEnum("Fact", "field3[field1=a1,field2=b1]", new String[] { "c1", "c2", "c3" }).addEnum("Fact", "field4[field1=a1]", new String[] { "d1", "d2" }).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).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.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    Map<String, String> currentValueMap = new HashMap<>();
    currentValueMap.put("field1", "a1");
    currentValueMap.put("field2", "b1");
    String[] field3Result = oracle.getEnums("Fact", "field3", currentValueMap).getFixedList();
    assertEquals(3, field3Result.length);
    assertEquals("c1", field3Result[0]);
    assertEquals("c2", field3Result[1]);
    assertEquals("c3", field3Result[2]);
    String[] field4Result = oracle.getEnums("Fact", "field4", currentValueMap).getFixedList();
    assertEquals(2, field4Result.length);
    assertEquals("d1", field4Result[0]);
    assertEquals("d2", field4Result[1]);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) HashMap(java.util.HashMap) 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) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 47 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testJavaEnum2.

@Test
public void testJavaEnum2() throws IOException {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestJavaEnum2.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(projectLoader).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.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(2, oracle.getFactTypes().length);
    assertEquals(TestJavaEnum2.class.getSimpleName(), oracle.getFactTypes()[1]);
    final DropDownData dd = oracle.getEnums(TestJavaEnum2.class.getSimpleName(), "field1");
    assertNotNull(dd);
    assertEquals(3, dd.getFixedList().length);
    assertEquals("TestExternalEnum.ZERO=TestExternalEnum.ZERO", dd.getFixedList()[0]);
    assertEquals("TestExternalEnum.ONE=TestExternalEnum.ONE", dd.getFixedList()[1]);
    assertEquals("TestExternalEnum.TWO=TestExternalEnum.TWO", dd.getFixedList()[2]);
    final String[] ddValues = oracle.getEnumValues(TestJavaEnum2.class.getSimpleName(), "field1");
    assertNotNull(ddValues);
    assertEquals(3, ddValues.length);
    assertEquals("TestExternalEnum.ZERO=TestExternalEnum.ZERO", ddValues[0]);
    assertEquals("TestExternalEnum.ONE=TestExternalEnum.ONE", ddValues[1]);
    assertEquals("TestExternalEnum.TWO=TestExternalEnum.TWO", ddValues[2]);
}
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) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) TestJavaEnum2(org.kie.workbench.common.widgets.client.datamodel.testclasses.TestJavaEnum2) 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 48 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testDataHasEnums.

@Test
public void testDataHasEnums() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("field1", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("'Fact.field1' : ['val1', 'val2'], 'Fact.field2[field1=val1]' : ['f1val1a', 'f1val1b'], 'Fact.field2[field1=val2]' : ['f1val2a', 'f1val2b']", Thread.currentThread().getContextClassLoader()).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).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.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    // Fact.field1 has explicit enumerations
    assertTrue(oracle.hasEnums("Fact.field1"));
    assertTrue(oracle.hasEnums("Fact", "field1"));
    // Fact.field2 has explicit enumerations dependent upon Fact.field1
    assertTrue(oracle.hasEnums("Fact.field2"));
    assertTrue(oracle.hasEnums("Fact", "field2"));
}
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) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 49 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testDependentEnums.

@Test
public void testDependentEnums() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("field1", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field3", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field4", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("'Fact.field1' : ['val1', 'val2']", Thread.currentThread().getContextClassLoader()).addEnum("'Fact.field2[field1=val1]' : ['f1val1a', 'f1val1b']", Thread.currentThread().getContextClassLoader()).addEnum("'Fact.field2[field1=val2]' : ['f1val2a', 'f1val2b']", Thread.currentThread().getContextClassLoader()).addEnum("'Fact.field3[field2=f1val1a]' : ['f1val1a1a', 'f1val1a1b']", Thread.currentThread().getContextClassLoader()).addEnum("'Fact.field3[field2=f1val1b]' : ['f1val1b1a', 'f1val1b1b']", Thread.currentThread().getContextClassLoader()).addEnum("'Fact.field3[field2=f1val2a]' : ['f1val2a1a', 'f1val2a1b']", Thread.currentThread().getContextClassLoader()).addEnum("'Fact.field3[field2=f1val2b]' : ['f1val2a2a', 'f1val2b2b']", Thread.currentThread().getContextClassLoader()).addEnum("'Fact.field4' : ['f4val1', 'f4val2']", Thread.currentThread().getContextClassLoader()).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).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.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertTrue(oracle.isDependentEnum("Fact", "field1", "field2"));
    assertTrue(oracle.isDependentEnum("Fact", "field1", "field3"));
    assertTrue(oracle.isDependentEnum("Fact", "field2", "field3"));
    assertFalse(oracle.isDependentEnum("Fact", "field1", "field4"));
}
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) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 50 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testNestedClass.

@Test
public void testNestedClass() throws IOException {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSuperClass.NestedClass.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.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"));
}
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) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Aggregations

PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)55 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)55 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)55 Path (org.uberfire.backend.vfs.Path)55 Test (org.junit.Test)54 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)46 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)38 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)31 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)12 PackageDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)12 ClassFactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)12 ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 URL (java.net.URL)9 Set (java.util.Set)9 Annotation (org.kie.soup.project.datamodel.oracle.Annotation)9 HasImports (org.kie.soup.project.datamodel.imports.HasImports)6 MethodInfo (org.kie.soup.project.datamodel.oracle.MethodInfo)6 Import (org.kie.soup.project.datamodel.imports.Import)5