Search in sources :

Example 6 with DataObject

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

the class JPADataObjectEditorTest method auditChangeTest.

@Test
public void auditChangeTest() {
    // enable audit option.
    when(jpaDomainHandler.isDataObjectAuditEnabled()).thenReturn(true);
    JPADataObjectEditor objectEditor = createObjectEditor();
    // load the editor
    objectEditor.onContextChange(context);
    // by construction the currently loaded data object org.test.TestObject1 is not audited.
    DataObject dataObject = context.getDataObject();
    // emulate user interaction setting TestObject1 as persistable
    objectEditor.onAuditedFieldChange("true");
    // the object should now be annotated as Audited.
    assertNotNull(dataObject.getAnnotation(Audited.class.getName()));
    assertEquals(RelationTargetAuditMode.NOT_AUDITED.name(), AnnotationValueHandler.getStringValue(dataObject, Audited.class.getName(), "targetAuditMode"));
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 7 with DataObject

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

the class MainDataObjectFieldEditorTest method valuesChangeTest.

@Test
public void valuesChangeTest() {
    MainDataObjectFieldEditor fieldEditor = createFieldEditor();
    DataObject dataObject = context.getDataObject();
    ObjectProperty field = dataObject.getProperty("field1");
    // emulates selection of field1 in current context.
    context.setObjectProperty(field);
    // The domain editors typically reacts upon DataModelerContext changes.
    // when the context changes the editor will typically be reloaded.
    fieldEditor.onContextChange(context);
    context.getEditorModelContent().setOriginalClassName(context.getDataObject().getClassName());
    context.getEditorModelContent().setPath(mock(Path.class));
    // emulate the user input
    when(view.getName()).thenReturn(NEW_FIELD_NAME);
    when(view.getDescription()).thenReturn(NEW_DESCRIPTION);
    when(view.getLabel()).thenReturn(NEW_LABEL);
    when(view.getType()).thenReturn(NEW_TYPE);
    Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
    validationResult.put(NEW_FIELD_NAME, true);
    when(validationService.evaluateJavaIdentifiers(any(String[].class))).thenReturn(validationResult);
    // notify the presenter about the changes in the UI
    fieldEditor.onNameChange();
    fieldEditor.onLabelChange();
    fieldEditor.onDescriptionChange();
    fieldEditor.onTypeChange();
    verify(showAssetUsagesDisplayer).showAssetPartUsages(anyString(), any(), anyString(), anyString(), any(), any(), any());
    // After the changes has been processed by the presenter the field should have been populated with the new values.
    field = context.getObjectProperty();
    assertEquals(NEW_FIELD_NAME, field.getName());
    assertEquals(NEW_LABEL, AnnotationValueHandler.getStringValue(field, Label.class.getName()));
    assertEquals(NEW_DESCRIPTION, AnnotationValueHandler.getStringValue(field, Description.class.getName()));
    assertEquals(NEW_TYPE, field.getClassName());
    verify(dataModelerEvent, times(4)).fire(any(DataModelerEvent.class));
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Path(org.uberfire.backend.vfs.Path) DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 8 with DataObject

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

the class DroolsDataObjectEditorTest method loadDataObjectTest.

@Test
public void loadDataObjectTest() {
    // The domain editors typically reacts upon DataModelerContext changes.
    // when the context changes the editor will typically be reloaded.
    objectEditor.onContextChange(context);
    DataObject dataObject = context.getDataObject();
    // the view should be populated with the values from the dataObject.
    verify(view, times(1)).setTypeSafe("true");
    verify(view, times(1)).setPropertyReactive(true);
    verify(view, times(1)).setRole("EVENT");
    verify(view, times(1)).setTimeStampField("field2");
    verify(view, times(1)).setDurationField("field3");
    verify(view, times(1)).setExpires("1h");
    verify(view, times(1)).setRemotable(true);
    assertFalse(objectEditor.isReadonly());
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 9 with DataObject

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

the class DroolsDataObjectEditorTest method valuesChangeTest.

@Test
public void valuesChangeTest() {
    // load the editor
    objectEditor.onContextChange(context);
    // emulate the user input
    when(view.getTypeSafe()).thenReturn("false");
    when(view.getPropertyReactive()).thenReturn(false);
    when(view.getRole()).thenReturn(null);
    when(view.getTimeStampField()).thenReturn(NEW_FIELD_NAME);
    when(view.getDurationField()).thenReturn(NEW_FIELD_NAME);
    // new timer expression
    when(view.getExpires()).thenReturn("100d");
    when(view.getRemotable()).thenReturn(false);
    when(validationService.isTimerIntervalValid("100d")).thenReturn(true);
    // notify the presenter about the changes in the UI
    objectEditor.onTypeSafeChange();
    objectEditor.onPropertyReactiveChange();
    objectEditor.onRoleChange();
    objectEditor.onTimeStampFieldChange();
    objectEditor.onDurationFieldChange();
    objectEditor.onExpiresChange();
    objectEditor.onRemotableChange();
    // After the changes has been processed by the presenter the dataObject should have been populated with the new values.
    DataObject dataObject = context.getDataObject();
    assertEquals("false", AnnotationValueHandler.getStringValue(dataObject, TypeSafe.class.getName(), "value"));
    assertNull(dataObject.getAnnotation(PropertyReactive.class.getName()));
    assertNull(dataObject.getAnnotation(Role.class.getName()));
    assertEquals(NEW_FIELD_NAME, AnnotationValueHandler.getStringValue(dataObject, Timestamp.class.getName(), "value"));
    assertEquals(NEW_FIELD_NAME, AnnotationValueHandler.getStringValue(dataObject, Duration.class.getName(), "value"));
    assertEquals("100d", AnnotationValueHandler.getStringValue(dataObject, Expires.class.getName(), "value"));
    assertNull(dataObject.getAnnotation(XmlRootElement.class.getName()));
    assertNull(dataObject.getAnnotation(Remotable.class.getName()));
    verify(dataModelerEvent, times(7)).fire(any(DataModelerEvent.class));
}
Also used : DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 10 with DataObject

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

the class JPADataObjectFieldEditorTest method valuesChangesTest.

@Test
public void valuesChangesTest() {
    JPADataObjectFieldEditor fieldEditor = createFieldEditor();
    DataObject dataObject = context.getDataObject();
    ObjectProperty field = dataObject.getProperty("field1");
    // emulates selection of field1 in current context.
    context.setObjectProperty(field);
    // The domain editors typically reacts upon DataModelerContext changes.
    // when the context changes the editor will typically be reloaded.
    fieldEditor.onContextChange(context);
    // emulates user interactions
    // changes related to the identifier category
    fieldEditor.onIdentifierFieldChange(createFieldInfo(JPADataObjectFieldEditorView.IDENTIFIER_FIELD, null), "true");
    fieldEditor.onGeneratedValueFieldChange(createFieldInfo(JPADataObjectFieldEditorView.GENERATED_VALUE_FIELD, new Pair<String, Object>("strategy", "SEQUENCE"), new Pair<String, Object>("generator", "TheGeneratorName")), "not_used");
    fieldEditor.onSequenceGeneratorFieldChange(createFieldInfo(JPADataObjectFieldEditorView.SEQUENCE_GENERATOR_FIELD, new Pair<String, Object>(SequenceGeneratorValueHandler.NAME, "TheGeneratorName"), new Pair<String, Object>(SequenceGeneratorValueHandler.SEQUENCE_NAME, "TheSequenceName"), new Pair<String, Object>(SequenceGeneratorValueHandler.INITIAL_VALUE, 1), new Pair<String, Object>(SequenceGeneratorValueHandler.ALLOCATION_SIZE, 100)), "not_used");
    // the field should have been updated according to the values entered on the ui
    assertNotNull(field.getAnnotation(Id.class.getName()));
    assertNotNull(field.getAnnotation(GeneratedValue.class.getName()));
    assertEquals("SEQUENCE", AnnotationValueHandler.getStringValue(field, GeneratedValue.class.getName(), "strategy"));
    assertEquals("TheGeneratorName", AnnotationValueHandler.getStringValue(field, GeneratedValue.class.getName(), "generator"));
    assertNotNull(field.getAnnotation(SequenceGenerator.class.getName()));
    assertEquals("TheGeneratorName", AnnotationValueHandler.getStringValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.NAME));
    assertEquals("TheSequenceName", AnnotationValueHandler.getStringValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.SEQUENCE_NAME));
    assertEquals(1, AnnotationValueHandler.getValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.INITIAL_VALUE));
    assertEquals(100, AnnotationValueHandler.getValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.ALLOCATION_SIZE));
    // changes related to the column category
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_NAME_FIELD, new Pair<String, Object>("name", "NewColumnName")), "NewColumnName");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_UNIQUE_FIELD, new Pair<String, Object>("unique", true)), "true");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_NULLABLE_FIELD, new Pair<String, Object>("nullable", false)), "false");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_INSERTABLE_FIELD, new Pair<String, Object>("insertable", false)), "false");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_UPDATABLE_FIELD, new Pair<String, Object>("updatable", false)), "false");
    // the field should have been updated according to the values entered on the ui
    assertNotNull(field.getAnnotation(Column.class.getName()));
    assertEquals("NewColumnName", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "name"));
    assertEquals("true", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "unique"));
    assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "nullable"));
    assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "insertable"));
    assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "updatable"));
    // changes related to the relationship
    List<CascadeType> cascadeTypes = new ArrayList<CascadeType>();
    cascadeTypes.add(CascadeType.ALL);
    fieldEditor.onRelationTypeFieldChange(createFieldInfo(JPADataObjectFieldEditorView.RELATIONSHIP_TYPE_FIELD, new Pair<String, Object>(RelationshipAnnotationValueHandler.RELATION_TYPE, RelationType.ONE_TO_MANY), new Pair<String, Object>(RelationshipAnnotationValueHandler.CASCADE, cascadeTypes), new Pair<String, Object>(RelationshipAnnotationValueHandler.FETCH, FetchMode.EAGER)), "not_used");
    // the field should have been updated according to the values entered on the ui
    List<String> expectedCascadeTypes = new ArrayList<String>();
    expectedCascadeTypes.add(CascadeType.ALL.name());
    assertNotNull(field.getAnnotation(OneToMany.class.getName()));
    assertEquals(expectedCascadeTypes, AnnotationValueHandler.getValue(field, OneToMany.class.getName(), RelationshipAnnotationValueHandler.CASCADE));
    assertEquals(FetchMode.EAGER.name(), AnnotationValueHandler.getValue(field, OneToMany.class.getName(), RelationshipAnnotationValueHandler.FETCH));
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) CascadeType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType) ArrayList(java.util.ArrayList) Pair(org.uberfire.commons.data.Pair) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Aggregations

DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)95 Test (org.junit.Test)45 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)40 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)29 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)28 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)21 ArrayList (java.util.ArrayList)17 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)17 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)17 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)17 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)17 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)17 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)17 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)16 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)15 MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)12 List (java.util.List)11 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)11 Method (org.kie.workbench.common.services.datamodeller.core.Method)10 Generated (javax.annotation.Generated)8