Search in sources :

Example 1 with ObjectPropertyImpl

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

the class RemovePropertyCommandTest method execute.

@Test
public void execute() {
    DataObject dataObject = new DataObjectImpl("org.test", "TestDataObject");
    dataObject.addProperty(new ObjectPropertyImpl("testProperty", Integer.class.getName(), false));
    DataModelChangeNotifier notifier = mock(DataModelChangeNotifier.class);
    RemovePropertyCommand command = new RemovePropertyCommand(new DataModelerContext(), "source", dataObject, "testProperty", notifier);
    command.execute();
    assertNull(dataObject.getProperty("testProperty"));
    verify(notifier, times(1)).notifyChange(any(DataObjectFieldDeletedEvent.class));
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectFieldDeletedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectFieldDeletedEvent) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) Test(org.junit.Test)

Example 2 with ObjectPropertyImpl

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

the class DataObjectBrowserViewImplTest method addPropertyTypeBrowseColumn.

@Test
public void addPropertyTypeBrowseColumn() {
    FieldMetadataProvider fieldMetadataProvider = objectProperty -> {
        if ("testField".equals(objectProperty.getName())) {
            ImageWrapper imageWrapper = new ImageWrapper("testUri", "testDescription");
            FieldMetadata fieldMetadata = new FieldMetadata(imageWrapper);
            return Optional.of(fieldMetadata);
        }
        return Optional.empty();
    };
    Instance<FieldMetadataProvider> fieldMetadataProviderInstance = new MockInstanceImpl<>(fieldMetadataProvider);
    view = new DataObjectBrowserViewImpl(validationPopup, fieldMetadataProviderInstance);
    Column<ObjectProperty, List<ImageWrapper>> column = view.createPropertyTypeBrowseColumn();
    ObjectProperty matchingObjectProperty = new ObjectPropertyImpl("testField", "className", false);
    List<ImageWrapper> imageWrapperList = column.getValue(matchingObjectProperty);
    assertEquals(1, imageWrapperList.size());
    ObjectProperty nonMatchingObjectProperty = new ObjectPropertyImpl("nonMatchingTestField", "className", false);
    imageWrapperList = column.getValue(nonMatchingObjectProperty);
    assertEquals(0, imageWrapperList.size());
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) FieldMetadata(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadata) Mock(org.mockito.Mock) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) FieldMetadataProvider(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadataProvider) ValidationPopup(org.kie.workbench.common.widgets.client.popups.validation.ValidationPopup) ImageWrapper(org.kie.workbench.common.screens.datamodeller.model.editor.ImageWrapper) Mockito(org.mockito.Mockito) List(java.util.List) Column(com.google.gwt.user.cellview.client.Column) Optional(java.util.Optional) MockInstanceImpl(org.uberfire.mocks.MockInstanceImpl) Assert(org.junit.Assert) Collections(java.util.Collections) Instance(javax.enterprise.inject.Instance) Command(org.uberfire.mvp.Command) Before(org.junit.Before) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) FieldMetadataProvider(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadataProvider) FieldMetadata(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadata) ImageWrapper(org.kie.workbench.common.screens.datamodeller.model.editor.ImageWrapper) MockInstanceImpl(org.uberfire.mocks.MockInstanceImpl) List(java.util.List) Test(org.junit.Test)

Example 3 with ObjectPropertyImpl

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

the class DataModelerEventTest method createEvent.

@Test
public void createEvent() {
    DataObject currentDataObject = new DataObjectImpl();
    ObjectProperty currentField = new ObjectPropertyImpl();
    Method currentMethod = new MethodImpl();
    Module currentModule = new Module();
    String source = "testSource";
    String contextId = "testContextId";
    Path path = new PathFactory.PathImpl();
    DataModelerEvent event = new DataModelerEvent().withCurrentDataObject(currentDataObject).withCurrentField(currentField).withCurrentMethod(currentMethod).withCurrentProject(currentModule).withSource(source).withContextId(contextId).withPath(path);
    assertEquals(currentDataObject, event.getCurrentDataObject());
    assertEquals(currentField, event.getCurrentField());
    assertEquals(currentMethod, event.getCurrentMethod());
    assertEquals(currentModule, event.getCurrentModule());
    assertEquals(source, event.getSource());
    assertEquals(contextId, event.getContextId());
    assertEquals(path, event.getPath());
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Path(org.uberfire.backend.vfs.Path) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) Method(org.kie.workbench.common.services.datamodeller.core.Method) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

Example 4 with ObjectPropertyImpl

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

the class DataModelTestUtil method addProperty.

public ObjectProperty addProperty(DataObject dataObject, String name, String className, boolean baseType, boolean multiple, String bag) {
    // TODO set modifiers.
    ObjectProperty property = new ObjectPropertyImpl(name, className, multiple, bag, Visibility.PUBLIC, false, false);
    dataObject.addProperty(property);
    return property;
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)

Example 5 with ObjectPropertyImpl

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

the class AddPropertyCommand method execute.

@Override
public void execute() {
    // extra check
    boolean multiple = isMultiple && !getContext().getHelper().isPrimitiveType(propertyType);
    property = new ObjectPropertyImpl(propertyName, propertyType, multiple);
    if (propertyLabel != null && !"".equals(propertyLabel)) {
        Annotation annotation = new AnnotationImpl(getContext().getAnnotationDefinitions().get(MainDomainAnnotations.LABEL_ANNOTATION));
        annotation.setValue(MainDomainAnnotations.VALUE_PARAM, propertyLabel);
        property.addAnnotation(annotation);
    }
    dataObject.addProperty(property);
    if (!property.isBaseType()) {
        getContext().getHelper().dataObjectReferenced(property.getClassName(), dataObject.getClassName());
    }
    notifyChange(new DataObjectFieldCreatedEvent(getContext().getContextId(), getSource(), getDataObject(), property));
}
Also used : ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObjectFieldCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectFieldCreatedEvent) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Aggregations

ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)18 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)14 Test (org.junit.Test)11 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)10 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)7 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)6 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)5 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)5 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 FieldSource (org.jboss.forge.roaster.model.source.FieldSource)2 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)2 MethodSource (org.jboss.forge.roaster.model.source.MethodSource)2 DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)2 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)2 Command (org.uberfire.mvp.Command)2 Column (com.google.gwt.user.cellview.client.Column)1 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1