Search in sources :

Example 1 with AnnotationDefinition

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);
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 2 with AnnotationDefinition

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);
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 3 with AnnotationDefinition

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;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 4 with AnnotationDefinition

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()));
    }
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) HashMap(java.util.HashMap) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 5 with AnnotationDefinition

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;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Aggregations

AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)21 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)8 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)6 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)4 DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)3 ArrayList (java.util.ArrayList)2 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 AnnotationDriver (org.kie.workbench.common.services.datamodeller.driver.AnnotationDriver)2 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)2 KieModule (org.kie.workbench.common.services.shared.project.KieModule)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Before (org.junit.Before)1 Description (org.kie.api.definition.type.Description)1 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)1 DomainHandler (org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler)1 DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)1