Search in sources :

Example 1 with DataServiceRemapNoStepsDialogController

use of org.pentaho.di.trans.dataservice.ui.controller.DataServiceRemapNoStepsDialogController in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceRemapNoStepsDialogTest method testOpen.

@Test
public void testOpen() throws XulException, KettleException {
    Shell shell = mock(Shell.class);
    final Document document = mock(Document.class);
    SwtDialog swtDialog = mock(SwtDialog.class);
    when(document.getElementById(DataServiceRemapNoStepsDialog.XUL_DIALOG_ID)).thenReturn(swtDialog);
    DataServiceRemapNoStepsDialogController controller = mock(DataServiceRemapNoStepsDialogController.class);
    DataServiceRemapNoStepsDialog dialog = spy(new DataServiceRemapNoStepsDialog(shell, controller));
    doAnswer(new Answer() {

        private int invocations = 0;

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            if (invocations == 0) {
                invocations++;
                return document;
            } else {
                throw new XulException("");
            }
        }
    }).when(dialog).initXul(same(shell), any(XulLoader.class), any(XulRunner.class));
    dialog.open();
    verify(dialog).initXul(same(shell), any(XulLoader.class), any(XulRunner.class));
    verify(swtDialog).show();
    try {
        dialog.open();
    } catch (Exception e) {
        Assert.assertTrue(e instanceof KettleException);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceRemapNoStepsDialogController(org.pentaho.di.trans.dataservice.ui.controller.DataServiceRemapNoStepsDialogController) XulLoader(org.pentaho.ui.xul.XulLoader) Document(org.pentaho.ui.xul.dom.Document) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) SwtDialog(org.pentaho.ui.xul.swt.tags.SwtDialog) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XulRunner(org.pentaho.ui.xul.XulRunner) Test(org.junit.Test)

Aggregations

Shell (org.eclipse.swt.widgets.Shell)1 Test (org.junit.Test)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 KettleException (org.pentaho.di.core.exception.KettleException)1 DataServiceRemapNoStepsDialogController (org.pentaho.di.trans.dataservice.ui.controller.DataServiceRemapNoStepsDialogController)1 XulException (org.pentaho.ui.xul.XulException)1 XulLoader (org.pentaho.ui.xul.XulLoader)1 XulRunner (org.pentaho.ui.xul.XulRunner)1 Document (org.pentaho.ui.xul.dom.Document)1 SwtDialog (org.pentaho.ui.xul.swt.tags.SwtDialog)1