Search in sources :

Example 41 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceDialogTest method testBuilderTransMeta.

@Test
public void testBuilderTransMeta() throws Exception {
    final DataServiceDelegate mockDelegate = mock(DataServiceDelegate.class);
    final DataServiceDialog dialog = mock(DataServiceDialog.class);
    when(dialog.getController()).thenReturn(controller);
    // Intercept actual creation so we can inject our mock
    DataServiceDialog.Builder builder = new DataServiceDialog.Builder(transMeta) {

        @Override
        protected DataServiceDialog createDialog(DataServiceDelegate delegate) {
            assertThat(delegate, sameInstance(mockDelegate));
            assertThat(super.createDialog(delegate), isA(DataServiceDialog.class));
            return dialog;
        }
    };
    builder.serviceStep("step");
    builder.serviceStep("");
    builder.serviceStep(null);
    DataServiceMeta dataService = mock(DataServiceMeta.class);
    when(dataService.getName()).thenReturn("Service");
    when(dataService.getStepname()).thenReturn("OUTPUT");
    ArrayList<PushDownOptimizationMeta> optimizations = Lists.newArrayList(mock(PushDownOptimizationMeta.class));
    when(dataService.getPushDownOptimizationMeta()).thenReturn(optimizations);
    builder.edit(dataService);
    Shell shell = mock(Shell.class);
    ArrayList<PushDownFactory> factories = Lists.newArrayList(mock(PushDownFactory.class));
    when(mockDelegate.getShell()).thenReturn(shell);
    when(mockDelegate.getPushDownFactories()).thenReturn(factories);
    assertThat(builder.build(mockDelegate), sameInstance(dialog));
    verify(controller).setDataService(dataService);
    verify(dialog).loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class));
    verify(dialog).initOptimizations(factories);
    Throwable xulException = new XulException();
    when(dialog.loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class))).thenThrow(xulException);
    try {
        builder.build(mockDelegate);
        fail("Expected exception was not thrown");
    } catch (KettleException e) {
        assertThat(e.getCause(), equalTo(xulException));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) SwtXulRunner(org.pentaho.ui.xul.swt.SwtXulRunner) Test(org.junit.Test)

Example 42 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceDialogControllerTest method testError.

@Test
public void testError() throws Exception {
    UndefinedDataServiceException undefinedException = new UndefinedDataServiceException(dataServiceMeta);
    doThrow(undefinedException).doReturn(dataServiceMeta).when(delegate).checkDefined(dataServiceMeta);
    DataServiceAlreadyExistsException alreadyExistsException = new DataServiceAlreadyExistsException(dataServiceMeta);
    doThrow(alreadyExistsException).doReturn(dataServiceMeta).when(delegate).checkConflict(dataServiceMeta, null);
    MetaStoreException metaStoreException = new MetaStoreException();
    doThrow(metaStoreException).doNothing().when(delegate).save(dataServiceMeta);
    controller.saveAndClose();
    verify(messageBox).setMessage(undefinedException.getMessage());
    controller.saveAndClose();
    verify(messageBox).setMessage(alreadyExistsException.getMessage());
    verify(delegate, never()).save(any(DataServiceMeta.class));
    controller.saveAndClose();
    verify(messageBox, times(3)).open();
    verify(logChannel).logError(anyString(), same(metaStoreException));
    verify(dialog, never()).dispose();
    controller.saveAndClose();
    verify(dialog).dispose();
    verifyNoMoreInteractions(logChannel);
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UndefinedDataServiceException(org.pentaho.di.trans.dataservice.serialization.UndefinedDataServiceException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) DataServiceAlreadyExistsException(org.pentaho.di.trans.dataservice.serialization.DataServiceAlreadyExistsException) Test(org.junit.Test)

Example 43 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceDialogControllerTest method testSaveAndClose.

@Test
public void testSaveAndClose() throws Exception {
    DataServiceMeta editingDataService = mock(DataServiceMeta.class);
    controller.setDataService(editingDataService);
    when(editingDataService.getName()).thenReturn(EDITING_SERVICE_NAME);
    when(delegate.checkDefined(dataServiceMeta)).thenReturn(dataServiceMeta);
    when(delegate.checkConflict(dataServiceMeta, EDITING_SERVICE_NAME)).thenReturn(dataServiceMeta);
    controller.saveAndClose();
    verify(delegate).save(dataServiceMeta);
    verify(delegate).removeDataService(editingDataService);
    verify(synchronizationListener).install(transMeta);
    verify(dialog).dispose();
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) Test(org.junit.Test)

Example 44 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceResolverDelegateTest method testGetDataServiceWithName.

@Test
public void testGetDataServiceWithName() {
    DataServiceMeta returnDataServiceMeta = dataServiceResolverDelegate.getDataService(DATA_SERVICE_NAME);
    assertEquals(returnDataServiceMeta, dataServiceMeta);
    verify(resolver).getDataService(DATA_SERVICE_NAME);
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) Test(org.junit.Test)

Example 45 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class TransientResolverTest method testGetDataServiceDisconnected.

@Test
public void testGetDataServiceDisconnected() throws Exception {
    when(kettleRepositoryLocator.getRepository()).thenReturn(null);
    File localFolder = temporaryFolder.newFolder("local");
    File localFile = new File(localFolder, "name.ktr");
    Files.write(transMeta.getXML().getBytes(StandardCharsets.UTF_8), localFile);
    String transientId = TransientResolver.buildTransient(localFile.getPath(), "data_service");
    DataServiceMeta dataServiceMeta = transientResolver.getDataService(transientId);
    assertNotNull(dataServiceMeta);
    assertThat(dataServiceMeta.getStepname(), is("data_service"));
    assertFalse(dataServiceMeta.isUserDefined());
    assertThat(dataServiceMeta, hasServiceCacheOptimization());
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) File(java.io.File) Test(org.junit.Test)

Aggregations

DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)52 Test (org.junit.Test)29 TransMeta (org.pentaho.di.trans.TransMeta)16 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)9 KettleException (org.pentaho.di.core.exception.KettleException)8 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)6 DataServiceDelegate (org.pentaho.di.trans.dataservice.ui.DataServiceDelegate)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Before (org.junit.Before)4 RowMeta (org.pentaho.di.core.row.RowMeta)4 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)4 MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)4 ModelAnnotationGroup (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2