Search in sources :

Example 11 with DataModelerContext

use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.

the class DataObjectBrowserTest method onDataObjectFieldDeleted.

@Test
public void onDataObjectFieldDeleted() {
    DataObjectBrowser dataObjectBrowser = spy(createBrowser());
    DataModelerContext context = createContext();
    context.setContextId("contextId");
    dataObjectBrowser.setContext(context);
    DataObject dataObject = mock(DataObject.class);
    dataObjectBrowser.setDataObject(dataObject);
    DataObjectFieldDeletedEvent event = new DataObjectFieldDeletedEvent();
    event.setContextId("contextId");
    Mockito.reset(dataObjectBrowser);
    dataObjectBrowser.onDataObjectFieldDeleted(event);
    verify(dataObjectBrowser, times(1)).setDataObject(dataObject);
}
Also used : 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) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 12 with DataModelerContext

use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.

the class DataObjectBrowserTest method addInvalidPropertyTest.

@Test
public void addInvalidPropertyTest() {
    DataObjectBrowser objectBrowser = createBrowser();
    DataModelerContext context = createContext();
    objectBrowser.setContext(context);
    // the dataObject has fields: field1, field2 and field3
    DataObject dataObject = context.getDataObject();
    // open the new property dialog.
    objectBrowser.onNewProperty();
    // check the new field popup is shown
    verify(newFieldPopupView, times(1)).show();
    // emulate the user data entering in the new field popup
    when(newFieldPopupView.getFieldName()).thenReturn("field4");
    when(newFieldPopupView.getSelectedType()).thenReturn("java.lang.String");
    when(newFieldPopupView.getIsMultiple()).thenReturn(false);
    // emulate that the provided field name is NOT correct
    Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
    validationResult.put("field4", false);
    when(validationService.evaluateJavaIdentifiers(new String[] { "field4" })).thenReturn(validationResult);
    // emulate the user pressing the create button in the new field popup
    newFieldPopup.onCreate();
    // the error message should have been set
    verify(newFieldPopupView, times(1)).setErrorMessage(anyString());
    verify(view, times(1)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(3));
    // no property should have been added.
    assertEquals(3, dataObject.getProperties().size());
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 13 with DataModelerContext

use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.

the class NewFieldPopupTest method doCreateFieldTest.

private void doCreateFieldTest(boolean createAndContinue) {
    DataModelerContext context = DataModelerEditorsTestHelper.createTestContext();
    NewFieldPopup newFieldPopup = new NewFieldPopup(view);
    PopupHandler handler = new PopupHandler();
    newFieldPopup.addPopupHandler(handler);
    // simulate the data entered by user
    when(view.getFieldName()).thenReturn("fieldName");
    when(view.getFieldLabel()).thenReturn("fieldLabel");
    when(view.getIsMultiple()).thenReturn(true);
    when(view.getSelectedType()).thenReturn("java.lang.Integer");
    newFieldPopup.init(context);
    newFieldPopup.show();
    // simulate the buttons clicking
    if (createAndContinue) {
        newFieldPopup.onCreateAndContinue();
    } else {
        newFieldPopup.onCreate();
    }
    verify(view, times(1)).getFieldName();
    verify(view, times(1)).getFieldLabel();
    verify(view, times(1)).getSelectedType();
    verify(view, times(1)).getIsMultiple();
    assertEquals("fieldName", handler.getFieldName());
    assertEquals("fieldLabel", handler.getFieldLabel());
    assertEquals(true, handler.isMultiple());
    assertEquals("java.lang.Integer", handler.getType());
    assertEquals(createAndContinue, handler.isCreateAndContinue());
    assertEquals(false, handler.isCanceled());
}
Also used : DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)

Example 14 with DataModelerContext

use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.

the class PackageSelectorTest method selectedPackageChange.

@Test
public void selectedPackageChange() {
    DataModelerContext context = createContext();
    List<Pair<String, String>> expectedPackageList = expectedPackageList();
    PackageSelector packageSelector = new PackageSelector(view);
    packageSelector.setContext(context);
    verify(view, times(1)).initPackageList(expectedPackageList, null, true);
    packageSelector.setCurrentPackage("package2");
    verify(view, times(1)).initPackageList(expectedPackageList, "package2", false);
}
Also used : DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) Pair(org.uberfire.commons.data.Pair) Test(org.junit.Test)

Example 15 with DataModelerContext

use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.

the class PackageSelectorTest method loadEditorTest.

@Test
public void loadEditorTest() {
    DataModelerContext context = createContext();
    List<Pair<String, String>> expectedPackageList = expectedPackageList();
    PackageSelector packageSelector = new PackageSelector(view);
    packageSelector.setContext(context);
    verify(view, times(1)).initPackageList(expectedPackageList, null, true);
}
Also used : DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) Pair(org.uberfire.commons.data.Pair) Test(org.junit.Test)

Aggregations

DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)15 Test (org.junit.Test)10 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)5 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)4 HashMap (java.util.HashMap)3 Pair (org.uberfire.commons.data.Pair)3 DataObjectFieldDeletedEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectFieldDeletedEvent)2 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)2 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)2 DataModelerEvent (org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent)1 EditorModelContent (org.kie.workbench.common.screens.datamodeller.model.EditorModelContent)1 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)1 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1