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));
}
}
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);
}
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();
}
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);
}
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());
}
Aggregations