use of org.pentaho.di.trans.dataservice.ui.DataServiceDelegate in project pdi-dataservice-server-plugin by pentaho.
the class AnnotationsQueryServiceTest method testGetsAnnotationsDefinedByStream.
@Test
public void testGetsAnnotationsDefinedByStream() throws Exception {
final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
when(metastoreLocator.getMetastore()).thenReturn(null);
final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
URL resource = getClass().getClassLoader().getResource("showAnnotations.ktr");
@SuppressWarnings("ConstantConditions") final TransMeta transMeta = new TransMeta(resource.getPath(), "show annotations");
Document document = XMLHandler.loadXMLFile(resource);
transMeta.loadXML(document.getFirstChild(), null, true);
final DataServiceMeta dataServiceMeta = new DataServiceMeta(transMeta);
dataServiceMeta.setName("annotatedService");
dataServiceMeta.setStepname("Annotate Stream");
when(dataServiceResolver.getDataService("annotatedService")).thenReturn(dataServiceMeta);
Query query = queryService.prepareQuery("show annotations from annotatedService", 0, Collections.<String, String>emptyMap());
AnnotationsQueryService.AnnotationsQuery spy = (AnnotationsQueryService.AnnotationsQuery) Mockito.spy(query);
final ModelAnnotationGroup mag = new ModelAnnotationGroup(new ModelAnnotation<>(new CreateMeasure()));
when(spy.getTrans(transMeta)).then(new Answer<Trans>() {
@Override
public Trans answer(final InvocationOnMock invocationOnMock) throws Throwable {
Trans trans = (Trans) invocationOnMock.callRealMethod();
trans.getExtensionDataMap().put("KEY_MODEL_ANNOTATIONS", mag);
return trans;
}
});
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
spy.writeTo(outputStream);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray());
DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
ThinResultSet thinResultSet = new ThinResultFactory().loadResultSet(dataInputStream, null);
thinResultSet.next();
String output = thinResultSet.getString(1);
assertEquals(new ModelAnnotationGroupXmlWriter(mag).getXML().trim(), output);
verify(metastoreLocator).getMetastore();
assertEquals(0, query.getTransList().size());
thinResultSet.close();
}
use of org.pentaho.di.trans.dataservice.ui.DataServiceDelegate in project pdi-dataservice-server-plugin by pentaho.
the class AnnotationsQueryServiceTest method testNoAnnotationsReturnsEmpty.
@Test
public void testNoAnnotationsReturnsEmpty() throws Exception {
final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
when(metastoreLocator.getMetastore()).thenReturn(null);
final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
URL resource = getClass().getClassLoader().getResource("showAnnotations.ktr");
@SuppressWarnings("ConstantConditions") final TransMeta transMeta = new TransMeta(resource.getPath(), "show annotations");
Document document = XMLHandler.loadXMLFile(resource);
transMeta.loadXML(document.getFirstChild(), null, true);
final DataServiceMeta dataServiceMeta = new DataServiceMeta(transMeta);
dataServiceMeta.setName("gridService");
dataServiceMeta.setStepname("Data Grid");
when(dataServiceResolver.getDataService("gridService")).thenReturn(dataServiceMeta);
Query query = queryService.prepareQuery("show annotations from gridService", 0, Collections.<String, String>emptyMap());
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
query.writeTo(outputStream);
String output = getResultString(outputStream);
assertEquals("<annotations></annotations>", output.trim());
}
use of org.pentaho.di.trans.dataservice.ui.DataServiceDelegate in project pdi-dataservice-server-plugin by pentaho.
the class AnnotationsQueryServiceTest method testLogsExceptionOnWriteEror.
@Test
public void testLogsExceptionOnWriteEror() throws Exception {
final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
when(metastoreLocator.getMetastore()).thenReturn(null);
final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
Query query = queryService.prepareQuery("show annotations from annotatedService", 0, Collections.<String, String>emptyMap());
MetaStoreException metaStoreException = new MetaStoreException("Unable to load dataservice annotatedService");
when(dataServiceResolver.getDataService("annotatedService")).thenReturn(null);
try {
query.writeTo(new ByteArrayOutputStream());
fail("should have got exception");
} catch (IOException e) {
assertEquals("Error while executing 'show annotations from annotatedService'", e.getMessage());
}
}
use of org.pentaho.di.trans.dataservice.ui.DataServiceDelegate in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDialogControllerTest method testShowDriverDetails.
@Test
public void testShowDriverDetails() {
DataServiceDelegate delegate = mock(DataServiceDelegate.class);
controller = spy(new DataServiceDialogController(null, delegate));
SwtDialog dialog = mock(SwtDialog.class);
doReturn(dialog).when(controller).getDialog();
Shell shell = mock(Shell.class);
doReturn(shell).when(dialog).getShell();
doCallRealMethod().when(controller).showDriverDetailsDialog();
controller.showDriverDetailsDialog();
verify(delegate).showDriverDetailsDialog(shell);
}
use of org.pentaho.di.trans.dataservice.ui.DataServiceDelegate in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceRemapConfirmationDialogControllerTest method testRemapErrorOnNoSteps.
@Test
public void testRemapErrorOnNoSteps() {
DataServiceDelegate delegate = mock(DataServiceDelegate.class);
DataServiceRemapConfirmationDialogController controller = spy(new DataServiceRemapConfirmationDialogController(mock(DataServiceMeta.class), new ArrayList<String>(), delegate));
doReturn(mock(SwtDialog.class)).when(controller).getDialog();
Assert.assertEquals(controller.getAction(), DataServiceRemapConfirmationDialog.Action.CANCEL);
controller.remap();
verify(delegate, times(1)).showRemapNoStepsDialog(any(Shell.class));
}
Aggregations