use of org.pentaho.agilebi.modeler.models.annotations.CreateMeasure 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();
}
Aggregations