Search in sources :

Example 11 with IncrementalDataModelService

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

the class PackageDataModelOracleCEPCompletionsTest method testCEPCompletions.

@Test
public void testCEPCompletions() {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("NotAnEvent").addField(new ModelField("dateField", Date.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_DATE)).end().addFact("AnEvent", true).addField(new ModelField("this", Object.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.SELF, FieldAccessorsAndMutators.BOTH, "AnEvent")).addField(new ModelField("dateField", Date.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_DATE)).end().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.setEventTypes(packageLoader.getModuleEventTypes());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    // Check completions
    String[] types = oracle.getFactTypes();
    assertEquals(2, types.length);
    PackageDataModelOracleTestUtils.assertContains("NotAnEvent", types);
    PackageDataModelOracleTestUtils.assertContains("AnEvent", types);
    oracle.getOperatorCompletions("NotAnEvent", "dateField", new Callback<String[]>() {

        @Override
        public void callback(final String[] notAnEventDateFieldOperators) {
            assertEquals(13, notAnEventDateFieldOperators.length);
            assertEquals(notAnEventDateFieldOperators[0], "==");
            assertEquals(notAnEventDateFieldOperators[1], "!=");
            assertEquals(notAnEventDateFieldOperators[2], "<");
            assertEquals(notAnEventDateFieldOperators[3], ">");
            assertEquals(notAnEventDateFieldOperators[4], "<=");
            assertEquals(notAnEventDateFieldOperators[5], ">=");
            assertEquals(notAnEventDateFieldOperators[6], "== null");
            assertEquals(notAnEventDateFieldOperators[7], "!= null");
            assertEquals(notAnEventDateFieldOperators[8], "in");
            assertEquals(notAnEventDateFieldOperators[9], "not in");
            assertEquals(notAnEventDateFieldOperators[10], "after");
            assertEquals(notAnEventDateFieldOperators[11], "before");
            assertEquals(notAnEventDateFieldOperators[12], "coincides");
        }
    });
    oracle.getOperatorCompletions("AnEvent", "this", new Callback<String[]>() {

        @Override
        public void callback(final String[] anEventThisOperators) {
            assertEquals(17, anEventThisOperators.length);
            assertEquals(anEventThisOperators[0], "==");
            assertEquals(anEventThisOperators[1], "!=");
            assertEquals(anEventThisOperators[2], "== null");
            assertEquals(anEventThisOperators[3], "!= null");
            assertEquals(anEventThisOperators[4], "after");
            assertEquals(anEventThisOperators[5], "before");
            assertEquals(anEventThisOperators[6], "coincides");
            assertEquals(anEventThisOperators[7], "during");
            assertEquals(anEventThisOperators[8], "finishes");
            assertEquals(anEventThisOperators[9], "finishedby");
            assertEquals(anEventThisOperators[10], "includes");
            assertEquals(anEventThisOperators[11], "meets");
            assertEquals(anEventThisOperators[12], "metby");
            assertEquals(anEventThisOperators[13], "overlaps");
            assertEquals(anEventThisOperators[14], "overlappedby");
            assertEquals(anEventThisOperators[15], "starts");
            assertEquals(anEventThisOperators[16], "startedby");
        }
    });
}
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 12 with IncrementalDataModelService

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

the class PackageDataModelOracleCompletionsTest method testFactCompletions.

@Test
public void testFactCompletions() {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("rank", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_COMPARABLE)).addField(new ModelField("name", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addFact("Vehicle").addField(new ModelField("make", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("type", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().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());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    String[] types = oracle.getFactTypes();
    assertEquals(2, types.length);
    assertContains("Person", types);
    assertContains("Vehicle", types);
}
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 13 with IncrementalDataModelService

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

the class PackageDataModelOracleCompletionsTest method testFactsAndFields.

@Test
public void testFactsAndFields() {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().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());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, oracle.getFieldType("Person", "age"));
    assertEquals(DataType.TYPE_STRING, oracle.getFieldType("Person", "sex"));
}
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 14 with IncrementalDataModelService

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

the class PackageDataModelOracleCompletionsTest method testFactFieldConnectiveOperatorCompletions.

@Test
public void testFactFieldConnectiveOperatorCompletions() {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("rank", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_COMPARABLE)).addField(new ModelField("name", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().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());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    Callback<String[]> personThisCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personThisConnectiveOperators) {
            assertEquals(3, personThisConnectiveOperators.length);
            assertEquals(personThisConnectiveOperators[0], "|| ==");
            assertEquals(personThisConnectiveOperators[1], "|| !=");
            assertEquals(personThisConnectiveOperators[2], "&& !=");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "this", personThisCallback);
    verify(personThisCallback).callback(any(String[].class));
    Callback<String[]> personAgeCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personAgeConnectiveOperators) {
            assertEquals(11, personAgeConnectiveOperators.length);
            assertEquals(personAgeConnectiveOperators[0], "|| ==");
            assertEquals(personAgeConnectiveOperators[1], "|| !=");
            assertEquals(personAgeConnectiveOperators[2], "&& !=");
            assertEquals(personAgeConnectiveOperators[3], "&& >");
            assertEquals(personAgeConnectiveOperators[4], "&& <");
            assertEquals(personAgeConnectiveOperators[5], "|| >");
            assertEquals(personAgeConnectiveOperators[6], "|| <");
            assertEquals(personAgeConnectiveOperators[7], "&& >=");
            assertEquals(personAgeConnectiveOperators[8], "&& <=");
            assertEquals(personAgeConnectiveOperators[9], "|| <=");
            assertEquals(personAgeConnectiveOperators[10], "|| >=");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "age", personAgeCallback);
    verify(personAgeCallback).callback(any(String[].class));
    Callback<String[]> personNameCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personRankConnectiveOperators) {
            assertEquals(11, personRankConnectiveOperators.length);
            assertEquals(personRankConnectiveOperators[0], "|| ==");
            assertEquals(personRankConnectiveOperators[1], "|| !=");
            assertEquals(personRankConnectiveOperators[2], "&& !=");
            assertEquals(personRankConnectiveOperators[3], "&& >");
            assertEquals(personRankConnectiveOperators[4], "&& <");
            assertEquals(personRankConnectiveOperators[5], "|| >");
            assertEquals(personRankConnectiveOperators[6], "|| <");
            assertEquals(personRankConnectiveOperators[7], "&& >=");
            assertEquals(personRankConnectiveOperators[8], "&& <=");
            assertEquals(personRankConnectiveOperators[9], "|| <=");
            assertEquals(personRankConnectiveOperators[10], "|| >=");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "rank", personNameCallback);
    verify(personAgeCallback).callback(any(String[].class));
    Callback<String[]> personNameCallback2 = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personNameConnectiveOperators) {
            assertEquals(13, personNameConnectiveOperators.length);
            assertEquals(personNameConnectiveOperators[0], "|| ==");
            assertEquals(personNameConnectiveOperators[1], "|| !=");
            assertEquals(personNameConnectiveOperators[2], "&& !=");
            assertEquals(personNameConnectiveOperators[3], "&& >");
            assertEquals(personNameConnectiveOperators[4], "&& <");
            assertEquals(personNameConnectiveOperators[5], "|| >");
            assertEquals(personNameConnectiveOperators[6], "|| <");
            assertEquals(personNameConnectiveOperators[7], "&& >=");
            assertEquals(personNameConnectiveOperators[8], "&& <=");
            assertEquals(personNameConnectiveOperators[9], "|| <=");
            assertEquals(personNameConnectiveOperators[10], "|| >=");
            assertEquals(personNameConnectiveOperators[11], "&& matches");
            assertEquals(personNameConnectiveOperators[12], "|| matches");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "name", personNameCallback2);
    verify(personNameCallback2).callback(any(String[].class));
}
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 15 with IncrementalDataModelService

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

the class PackageDataModelOracleEnumTest method testBasicEnums.

@Test
public void testBasicEnums() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addFact("Driver").addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("Person", "age", new String[] { "42", "43" }).addEnum("Person", "sex", new String[] { "M", "F" }).addEnum("Driver", "sex", new String[] { "M", "F" }).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);
    String[] personAgeEnum = oracle.getEnumValues("Person", "age");
    assertEquals(2, personAgeEnum.length);
    assertEquals("42", personAgeEnum[0]);
    assertEquals("43", personAgeEnum[1]);
    String[] personSexEnum = oracle.getEnumValues("Person", "sex");
    assertEquals(2, personSexEnum.length);
    assertEquals("M", personSexEnum[0]);
    assertEquals("F", personSexEnum[1]);
    String[] driverSexEnum = oracle.getEnumValues("Driver", "sex");
    assertEquals(2, driverSexEnum.length);
    assertEquals("M", driverSexEnum[0]);
    assertEquals("F", driverSexEnum[1]);
}
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