Search in sources :

Example 1 with PublishBatchMessagesEvent

use of org.guvnor.messageconsole.events.PublishBatchMessagesEvent in project kie-wb-common by kiegroup.

the class DataModelerScreenPresenterTest method loadFileUnSuccessfulTest.

/**
 * Tests that a java file with parse errors was successfully loaded.
 *
 * @param loadTypesInfo indicates if the types and annotations definitions loading should be simulated.
 */
private void loadFileUnSuccessfulTest(boolean loadTypesInfo) {
    EditorModelContent content = createContent(loadTypesInfo, true);
    // when there are parse errors the returned data object is null.
    content.setDataObject(null);
    when(versionRecordManager.getCurrentPath()).thenReturn(path);
    when(modelerService.loadContent(path, loadTypesInfo)).thenReturn(content);
    when(javaSourceEditor.getContent()).thenReturn(content.getSource());
    if (loadTypesInfo) {
        // types info is not loaded into the DataModelerWBContext.
        when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(false);
    } else {
        // types info is already into the DataModelerWBContext.
        when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(true);
    }
    // just for convenience, since the DataModelerContext is initialized by taking this definitions from the DMWC.
    when(dataModelerWBContext.getAnnotationDefinitions()).thenReturn(testAnnotationDefs);
    when(dataModelerWBContext.getPropertyTypes()).thenReturn(testTypeDefs);
    presenter.onStartup(path, placeRequest);
    // Verifications during and after model loading.
    verify(view, times(1)).showLoading();
    verify(view, times(1)).hideBusyIndicator();
    // presenter should ask the DataModelerWBContext if the types info is already loaded.
    verify(dataModelerWBContext, times(1)).isTypesInfoLoaded();
    if (loadTypesInfo) {
        // the types info should have been set into the DataModelerWBContext as part of the presenter loading.
        verify(dataModelerWBContext, times(1)).setPropertyTypes(testTypeDefs);
        verify(dataModelerWBContext, times(1)).setAnnotationDefinitions(testAnnotationDefs);
    } else {
        // the types info shouldn't have been set into the DataModelerWBContext as part of the presenter loading.
        verify(dataModelerWBContext, times(0)).setPropertyTypes(testTypeDefs);
        verify(dataModelerWBContext, times(0)).setAnnotationDefinitions(testAnnotationDefs);
    }
    // presenter should clear the system messages related to this editor.
    verify(unpublishMessagesEvent, times(1)).fire(any(UnpublishMessagesEvent.class));
    // presenter should read the expected path.
    verify(modelerService, times(1)).loadContent(path, loadTypesInfo);
    // parse errors should have been published.
    verify(publishBatchMessagesEvent, times(1)).fire(any(PublishBatchMessagesEvent.class));
    // parse errors dialog should have been raised.
    verify(view, times(1)).showParseErrorsDialog(Mockito.<String>any(), Mockito.<String>any(), Mockito.<Command>any());
    // at this point the parse errors popup is raised and waiting for the user to press the ok button.
    // emulate the user click on the button.
    presenter.getOnLoadParseErrorCommand().execute();
    // verify that the context created by the presenter was properly initialized.
    DataModelerContext context = presenter.context;
    assertEquals(testModel, context.getDataModel());
    assertEquals(null, context.getDataObject());
    assertEquals(kieModule, context.getCurrentProject());
    assertEquals(testPackages, context.getCurrentProjectPackages());
    assertEquals(testAnnotationDefs, context.getAnnotationDefinitions());
    assertEquals(content, context.getEditorModelContent());
    // parse errors wherer produced on server so the status should be PARSE_ERRORS
    assertEquals(DataModelerContext.ParseStatus.PARSE_ERRORS, context.getParseStatus());
    // the file wasn't parsed the editor should go to the source tab.
    assertEquals(DataModelerContext.EditionMode.SOURCE_MODE, context.getEditionMode());
    // file was just read, so the status should be NO_CHANGES.
    assertEquals(DataModelerContext.EditionStatus.NO_CHANGES, context.getEditionStatus());
    // context wasn't set on the view since there aren't a data object to show.
    verify(view, times(0)).setContext(context);
    // the source editor should have been initialized with the source returned form server.
    verify(javaSourceEditor, times(2)).setContent(testSource);
    // current context should have been activated
    verify(dataModelerWBContext, times(1)).setActiveContext(context);
    // and notifications should have been sent.
    verify(dataModelerFocusEvent, times(1)).fire(any(DataModelerWorkbenchFocusEvent.class));
}
Also used : PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent) EditorModelContent(org.kie.workbench.common.screens.datamodeller.model.EditorModelContent) DataModelerWorkbenchFocusEvent(org.kie.workbench.common.screens.datamodeller.client.context.DataModelerWorkbenchFocusEvent) UnpublishMessagesEvent(org.guvnor.messageconsole.events.UnpublishMessagesEvent)

Example 2 with PublishBatchMessagesEvent

use of org.guvnor.messageconsole.events.PublishBatchMessagesEvent in project kie-wb-common by kiegroup.

the class TestRunnerReportingPanelTest method onViewAlerts.

@Test
public void onViewAlerts() {
    screen.onViewAlerts();
    verify(event).fire(publishEventCaptor.capture());
    final PublishBatchMessagesEvent value = publishEventCaptor.getValue();
    assertTrue(value.isCleanExisting());
    assertTrue(value.getMessagesToPublish().isEmpty());
}
Also used : PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent) Test(org.junit.Test)

Example 3 with PublishBatchMessagesEvent

use of org.guvnor.messageconsole.events.PublishBatchMessagesEvent in project kie-wb-common by kiegroup.

the class TestRunnerReportingPanelTest method onViewAlertsSendMessage.

@Test
public void onViewAlertsSendMessage() {
    screen.onTestRun(createTRMWithFailures());
    screen.onViewAlerts();
    verify(event).fire(publishEventCaptor.capture());
    final PublishBatchMessagesEvent value = publishEventCaptor.getValue();
    assertFalse(value.getMessagesToPublish().isEmpty());
}
Also used : PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent) Test(org.junit.Test)

Example 4 with PublishBatchMessagesEvent

use of org.guvnor.messageconsole.events.PublishBatchMessagesEvent in project kie-wb-common by kiegroup.

the class TestRunnerReportingPanelTest method testEventGoesThroughCorrectly.

@Test
public void testEventGoesThroughCorrectly() {
    when(failure.getDisplayName()).thenReturn("Display name.");
    when(failure.getMessage()).thenReturn("Message");
    final Path path = mock(Path.class);
    when(failure.getPath()).thenReturn(path);
    screen.onTestRun(createTRMWithFailures());
    screen.onViewAlerts();
    verify(event).fire(publishEventCaptor.capture());
    final PublishBatchMessagesEvent value = publishEventCaptor.getValue();
    assertTrue(value.isCleanExisting());
    assertEquals(1, value.getMessagesToPublish().size());
    final SystemMessage systemMessage = value.getMessagesToPublish().get(0);
    assertEquals("TestResults", systemMessage.getMessageType());
    assertEquals(Level.ERROR, systemMessage.getLevel());
    assertEquals(path, systemMessage.getPath());
    assertEquals("Display name. : Message", systemMessage.getText());
}
Also used : Path(org.uberfire.backend.vfs.Path) SystemMessage(org.guvnor.messageconsole.events.SystemMessage) PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent) Test(org.junit.Test)

Example 5 with PublishBatchMessagesEvent

use of org.guvnor.messageconsole.events.PublishBatchMessagesEvent in project kie-wb-common by kiegroup.

the class TestRunnerReportingPanelTest method onViewAlerts_resetBetweenRuns.

@Test
public void onViewAlerts_resetBetweenRuns() {
    screen.onTestRun(createTRMWithFailures());
    screen.onTestRun(createTRMWithoutFailures(2500));
    screen.onViewAlerts();
    verify(event).fire(publishEventCaptor.capture());
    final PublishBatchMessagesEvent value = publishEventCaptor.getValue();
    assertTrue(value.getMessagesToPublish().isEmpty());
}
Also used : PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent) Test(org.junit.Test)

Aggregations

PublishBatchMessagesEvent (org.guvnor.messageconsole.events.PublishBatchMessagesEvent)8 Test (org.junit.Test)4 SystemMessage (org.guvnor.messageconsole.events.SystemMessage)3 UnpublishMessagesEvent (org.guvnor.messageconsole.events.UnpublishMessagesEvent)1 DataModelerWorkbenchFocusEvent (org.kie.workbench.common.screens.datamodeller.client.context.DataModelerWorkbenchFocusEvent)1 DataModelerError (org.kie.workbench.common.screens.datamodeller.model.DataModelerError)1 EditorModelContent (org.kie.workbench.common.screens.datamodeller.model.EditorModelContent)1 DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)1 Path (org.uberfire.backend.vfs.Path)1