use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelFactFieldsAnnotationsTest method testCorrectPackageDMOAnnotationAttributes.
@Test
public void testCorrectPackageDMOAnnotationAttributes() throws Exception {
// Build ModuleDMO
final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, SmurfHouse.class, false, type -> TypeSource.JAVA_PROJECT);
cb.build(moduleLoader);
// Build PackageDMO
final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations");
packageBuilder.setModuleOracle(moduleLoader);
final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(1, oracle.getFactTypes().length);
assertEquals("SmurfHouse", oracle.getFactTypes()[0]);
oracle.getTypeFieldsAnnotations("SmurfHouse", new Callback<Map<String, Set<Annotation>>>() {
@Override
public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
assertNotNull(fieldsAnnotations);
assertEquals(2, fieldsAnnotations.size());
assertTrue(fieldsAnnotations.containsKey("occupant"));
final Set<Annotation> occupantAnnotations = fieldsAnnotations.get("occupant");
assertNotNull(occupantAnnotations);
assertEquals(1, occupantAnnotations.size());
final Annotation annotation = occupantAnnotations.iterator().next();
assertEquals("org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations.SmurfFieldDescriptor", annotation.getQualifiedTypeName());
assertEquals("blue", annotation.getParameters().get("colour"));
assertEquals("M", annotation.getParameters().get("gender"));
assertEquals("Brains", annotation.getParameters().get("description"));
assertTrue(fieldsAnnotations.containsKey("positionedOccupant"));
final Set<Annotation> posOccupantAnnotations = fieldsAnnotations.get("positionedOccupant");
assertNotNull(posOccupantAnnotations);
assertEquals(1, posOccupantAnnotations.size());
final Annotation annotation2 = posOccupantAnnotations.iterator().next();
assertEquals("org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations.SmurfFieldPositionDescriptor", annotation2.getQualifiedTypeName());
assertEquals(1, annotation2.getParameters().get("value"));
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.
the class PackageDataModelFactFieldsAnnotationsTest method testCorrectPackageDMOZeroAnnotationAttributes.
@Test
public void testCorrectPackageDMOZeroAnnotationAttributes() throws Exception {
// Build ModuleDMO
final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Product.class, false, type -> TypeSource.JAVA_PROJECT);
cb.build(moduleLoader);
// Build PackageDMO
final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
packageBuilder.setModuleOracle(moduleLoader);
final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(1, oracle.getFactTypes().length);
assertEquals("Product", oracle.getFactTypes()[0]);
oracle.getTypeFieldsAnnotations("Product", new Callback<Map<String, Set<Annotation>>>() {
@Override
public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
assertNotNull(fieldsAnnotations);
assertEquals(0, fieldsAnnotations.size());
}
});
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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);
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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"));
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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]);
}
Aggregations