use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testSmartEnums1.
@Test
public void testSmartEnums1() {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("type", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("value", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("Fact", "type", new String[] { "sex", "colour" }).addEnum("Fact", "value[type=sex]", new String[] { "M", "F" }).addEnum("Fact", "value[type=colour]", new String[] { "RED", "WHITE", "BLUE" }).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[] typeResult = oracle.getEnums("Fact", "type").getFixedList();
assertEquals(2, typeResult.length);
assertEquals("sex", typeResult[0]);
assertEquals("colour", typeResult[1]);
Map<String, String> currentValueMap = new HashMap<>();
currentValueMap.put("type", "sex");
String[] typeSexResult = oracle.getEnums("Fact", "value", currentValueMap).getFixedList();
assertEquals(2, typeSexResult.length);
assertEquals("M", typeSexResult[0]);
assertEquals("F", typeSexResult[1]);
currentValueMap.clear();
currentValueMap.put("type", "colour");
String[] typeColourResult = oracle.getEnums("Fact", "value", currentValueMap).getFixedList();
assertEquals(3, typeColourResult.length);
assertEquals("RED", typeColourResult[0]);
assertEquals("WHITE", typeColourResult[1]);
assertEquals("BLUE", typeColourResult[2]);
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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"));
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testJavaEnum1.
@Test
public void testJavaEnum1() throws IOException {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestJavaEnum1.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("TestJavaEnum1.TestEnum", oracle.getFactTypes()[1]);
final DropDownData dd = oracle.getEnums(TestJavaEnum1.class.getSimpleName(), "field1");
assertNotNull(dd);
assertEquals(3, dd.getFixedList().length);
assertEquals("TestJavaEnum1.TestEnum.ZERO=TestJavaEnum1.TestEnum.ZERO", dd.getFixedList()[0]);
assertEquals("TestJavaEnum1.TestEnum.ONE=TestJavaEnum1.TestEnum.ONE", dd.getFixedList()[1]);
assertEquals("TestJavaEnum1.TestEnum.TWO=TestJavaEnum1.TestEnum.TWO", dd.getFixedList()[2]);
final String[] ddValues = oracle.getEnumValues(TestJavaEnum1.class.getSimpleName(), "field1");
assertNotNull(ddValues);
assertEquals(3, ddValues.length);
assertEquals("TestJavaEnum1.TestEnum.ZERO=TestJavaEnum1.TestEnum.ZERO", ddValues[0]);
assertEquals("TestJavaEnum1.TestEnum.ONE=TestJavaEnum1.TestEnum.ONE", ddValues[1]);
assertEquals("TestJavaEnum1.TestEnum.TWO=TestJavaEnum1.TestEnum.TWO", ddValues[2]);
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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]);
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelGettersAndSettersTest method testGettersAndSettersOnJavaClass.
@Test
public void testGettersAndSettersOnJavaClass() throws Exception {
final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(Person.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel").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);
oracle.getFieldCompletions("Person", FieldAccessorsAndMutators.ACCESSOR, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] getters) {
assertEquals(2, getters.length);
assertEquals("age", getters[0].getName());
assertEquals(DataType.TYPE_THIS, getters[1].getName());
}
});
oracle.getFieldCompletions("Person", FieldAccessorsAndMutators.MUTATOR, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] setters) {
assertEquals(1, setters.length);
assertEquals("age", setters[0].getName());
}
});
}
Aggregations