Search in sources :

Example 1 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class CreateAnnotationWizardTest method testAnnotationCreated.

@Test
public void testAnnotationCreated() {
    // emulate the user is searching the javax.persistence.Entity annotation.
    AnnotationDefinitionRequest request = new AnnotationDefinitionRequest(Entity.class.getName());
    // the response has a definition
    AnnotationDefinitionResponse response = new AnnotationDefinitionResponse(DriverUtils.buildAnnotationDefinition(Entity.class));
    when(searchView.getClassName()).thenReturn(Entity.class.getName());
    when(modelerService.resolveDefinitionRequest(request, kieModule)).thenReturn(response);
    // when the search is performed the ValuePairEditor pages will be automatically created
    // so we also emulate the corresponding ValuePairEditors for the given value pairs.
    AnnotationValuePairDefinition valuePairDefinition = response.getAnnotationDefinition().getValuePair("name");
    when(valuePairEditorProvider.getValuePairEditor(valuePairDefinition)).thenReturn(valuePairEditor);
    // the wizard pages corresponding to the value pairs are also created dynamically, se we need also emulate
    // the ValuePairEditorPage instantiation
    when(iocManager.lookupBean(ValuePairEditorPage.class)).thenReturn(beanDef);
    when(beanDef.getInstance()).thenReturn(editorPage);
    // emulate the user click on the search button
    searchPage.onSearchClass();
    // the page should have been completed, since the modelerService returned the annotation definition as expected
    WizardTestUtil.assertPageComplete(true, searchPage);
    // now emulate the parameter completion in the value pair page.
    // emulate a change in the internal ValuePairEditor with a valid value.
    when(editorView.getValuePairEditor()).thenReturn(valuePairEditor);
    when(valuePairEditor.getValue()).thenReturn("TheEntityName");
    when(valuePairEditor.isValid()).thenReturn(true);
    editorPage.onValueChange();
    // the value pair editor page shoud have been completed.
    WizardTestUtil.assertPageComplete(true, searchPage);
    // emulates the user clicking on the finish button.
    createAnnotationWizard.complete();
    // finally if the Wizard has been completed successfuly an annotation should be created.
    Annotation expectedAnnotation = new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class));
    expectedAnnotation.setValue("name", "TheEntityName");
    assertEquals(expectedAnnotation, createdAnnotation);
}
Also used : Entity(javax.persistence.Entity) AnnotationDefinitionRequest(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 2 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl 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 3 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class DataModelerEventObserverTest method init.

@Before
public void init() {
    eventObserver = createObserver();
    descriptorModel = createModel();
    dataObject = new DataObjectImpl("package1", "PersistableObject");
    dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class)));
    when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH);
    when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath);
    when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) Path(org.uberfire.backend.vfs.Path) Module(org.guvnor.common.services.project.model.Module) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Before(org.junit.Before)

Example 4 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class JPADataObjectEditor method addByDefaultId.

private void addByDefaultId(DataObject dataObject) {
    // add the by default id field
    String idFieldName = generateIdFieldName(dataObject);
    commandBuilder.buildAddPropertyCommand(getContext(), getName(), dataObject, idFieldName, null, Long.class.getName(), false).execute();
    ObjectProperty idField = dataObject.getProperty(idFieldName);
    commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), dataObject, idField, JPADomainAnnotations.JAVAX_PERSISTENCE_ID_ANNOTATION).execute();
    // set the by default generated value annotation.
    String generatorName = dataObject.getName().toUpperCase() + "_ID_GENERATOR";
    Annotation generatedValue = new AnnotationImpl(context.getAnnotationDefinition(JPADomainAnnotations.JAVAX_PERSISTENCE_GENERATED_VALUE_ANNOTATION));
    generatedValue.setValue("generator", generatorName);
    generatedValue.setValue("strategy", "AUTO");
    commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), dataObject, idField, generatedValue).execute();
    // set by default sequence generator
    String sequenceName = dataObject.getName().toUpperCase() + "_ID_SEQ";
    Annotation sequenceGenerator = SequenceGeneratorValueHandler.createAnnotation(generatorName, sequenceName, context.getAnnotationDefinitions());
    commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), dataObject, idField, sequenceGenerator).execute();
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 5 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class CreateAnnotationWizard method doComplete.

private void doComplete() {
    Annotation annotation = null;
    if (annotationDefinition != null) {
        annotation = new AnnotationImpl(annotationDefinition);
        if (!annotationDefinition.isMarker()) {
            for (ValuePairEditorPage valuePairEditor : filterValuePairEditorPages()) {
                if (valuePairEditor.getCurrentValue() != null) {
                    annotation.setValue(valuePairEditor.getValuePairDefinition().getName(), valuePairEditor.getCurrentValue());
                }
            }
        }
    }
    clearCurrentValuePairEditorPages();
    invokeOnCloseCallback(annotation);
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Aggregations

AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)34 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)24 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)11 Test (org.junit.Test)10 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)10 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)7 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)5 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)4 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)4 Entity (javax.persistence.Entity)2 Before (org.junit.Before)2 AnnotationDefinitionImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Id (javax.persistence.Id)1 AnnotationMetaModel (org.drools.workbench.screens.factmodel.model.AnnotationMetaModel)1 Module (org.guvnor.common.services.project.model.Module)1 ValuePair (org.jboss.forge.roaster.model.ValuePair)1 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)1