use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.
the class ValuePairEditorPageTest method testInvalidValueChange.
@Test
public void testInvalidValueChange() {
modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
ValuePairEditorPage editorPage = new ValuePairEditorPage(view, valuePairEditorProvider, modelerServiceCaller, wizardPageStatusChangeEvent);
editorPage.prepareView();
AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(Entity.class);
AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("name");
when(valuePairEditorProvider.getValuePairEditor(valuePairDefinition)).thenReturn(valuePairEditor);
editorPage.init(annotationDefinition, valuePairDefinition, ElementType.FIELD, kieModule);
// emulate a change in the internal ValuePairEditor with a valid value.
when(view.getValuePairEditor()).thenReturn(valuePairEditor);
when(valuePairEditor.getValue()).thenReturn(null);
when(valuePairEditor.isValid()).thenReturn(false);
editorPage.onValueChange();
// the view should be properly initialized with the corresponding editor.
verify(view, times(1)).setValuePairEditor(valuePairEditor);
verify(valuePairEditor, times(1)).getValue();
verify(valuePairEditor, times(1)).isValid();
WizardTestUtil.assertPageComplete(false, editorPage);
}
use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.
the class ValuePairEditorPageTest method testValidValueChange.
@Test
public void testValidValueChange() {
modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
ValuePairEditorPage editorPage = new ValuePairEditorPage(view, valuePairEditorProvider, modelerServiceCaller, wizardPageStatusChangeEvent);
editorPage.prepareView();
AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(Entity.class);
AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("name");
when(valuePairEditorProvider.getValuePairEditor(valuePairDefinition)).thenReturn(valuePairEditor);
editorPage.init(annotationDefinition, valuePairDefinition, ElementType.FIELD, kieModule);
// emulate a change in the internal ValuePairEditor with a valid value.
when(view.getValuePairEditor()).thenReturn(valuePairEditor);
when(valuePairEditor.getValue()).thenReturn("TheEntityName");
when(valuePairEditor.isValid()).thenReturn(true);
editorPage.onValueChange();
// the view should be properly initialized with the corresponding editor.
verify(view, times(1)).setValuePairEditor(valuePairEditor);
verify(valuePairEditor, times(1)).getValue();
verify(valuePairEditor, times(1)).isValid();
assertEquals("TheEntityName", editorPage.getCurrentValue());
WizardTestUtil.assertPageComplete(true, editorPage);
}
use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.
the class DataModelerEditorsTestHelper method createAnnotation.
public static Annotation createAnnotation(Class cls, Pair<String, Object>... valuePairs) {
AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(cls);
Annotation annotation = new AnnotationImpl(annotationDefinition);
for (Pair<String, Object> valuePair : valuePairs) {
annotation.setValue(valuePair.getK1(), valuePair.getK2());
}
return annotation;
}
use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.
the class DataModelerServiceWeldTest method testDataModelerService.
@Test
public void testDataModelerService() throws Exception {
KieModule module = loadProjectFromResources("/DataModelerTest1");
final Map<String, AnnotationDefinition> systemAnnotations = dataModelService.getAnnotationDefinitions();
DataModel dataModelOriginal = new DataModelTestUtil(systemAnnotations).createModel(Pojo1.class, Pojo2.class);
org.kie.workbench.common.services.datamodeller.core.DataModel dataModel = dataModelService.loadModel(module);
Map<String, DataObject> objectsMap = new HashMap<>();
assertNotNull(dataModel);
assertEquals(dataModelOriginal.getDataObjects().size(), dataModel.getDataObjects().size());
for (DataObject dataObject : dataModel.getDataObjects()) {
objectsMap.put(dataObject.getClassName(), dataObject);
}
for (DataObject dataObject : dataModelOriginal.getDataObjects()) {
org.kie.workbench.common.services.datamodeller.DataModelerAssert.assertEqualsDataObject(dataObject, objectsMap.get(dataObject.getClassName()));
}
}
use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method resolveDefinitionRequest.
@Override
public AnnotationDefinitionResponse resolveDefinitionRequest(AnnotationDefinitionRequest definitionRequest, KieModule kieModule) {
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(kieModule);
ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(classLoader);
AnnotationDefinitionResponse definitionResponse = new AnnotationDefinitionResponse();
try {
AnnotationDefinition annotationDefinition = modelDriver.buildAnnotationDefinition(definitionRequest.getClassName(), classTypeResolver);
definitionResponse.withAnnotationDefinition(annotationDefinition);
} catch (ModelDriverException e) {
DriverError driverError = new DriverError(e.getMessage());
definitionResponse.addError(driverError);
}
return definitionResponse;
}
Aggregations