use of com.epam.pipeline.manager.metadata.writer.MetadataWriter in project cloud-pipeline by epam.
the class MetadataDownloadManager method getInputStream.
public InputStream getInputStream(final Long folderId, final String entityClass, final String fileExtension) {
final MetadataFileFormat fileFormat = retrieveMetadataFileFormat(fileExtension);
final List<MetadataEntity> entities = retrieveMetadataEntities(folderId, entityClass);
final StringWriter stringWriter = new StringWriter();
final MetadataWriter metadataWriter = metadataWriterProvider.getMetadataWriter(stringWriter, fileFormat);
metadataWriter.writeEntities(entityClass, entities);
try {
return new StringInputStream(stringWriter.toString());
} catch (IOException e) {
throw new MetadataWriterException(messageHelper.getMessage(MessageConstants.ERROR_METADATA_ENTITY_WRITING_BAD_ENCODING), e);
}
}
use of com.epam.pipeline.manager.metadata.writer.MetadataWriter in project cloud-pipeline by epam.
the class MetadataDownloadManagerTest method getInputStreamShouldRetrieveMetadataWriterFromProvider.
@Test
public void getInputStreamShouldRetrieveMetadataWriterFromProvider() {
final List<MetadataEntity> entities = Collections.singletonList(new MetadataEntity());
when(metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(FOLDER_ID, SAMPLE)).thenReturn(entities);
final MetadataWriter metadataWriter = mock(MetadataWriter.class);
when(metadataWriterProvider.getMetadataWriter(any(), any())).thenReturn(metadataWriter);
manager.getInputStream(FOLDER_ID, SAMPLE, TSV);
verify(metadataWriter).writeEntities(eq(SAMPLE), eq(entities));
}
use of com.epam.pipeline.manager.metadata.writer.MetadataWriter in project cloud-pipeline by epam.
the class MetadataDownloadManagerTest method getInputStreamShouldReadFromWriterThatWasPassedToMetadataWriter.
@Test
public void getInputStreamShouldReadFromWriterThatWasPassedToMetadataWriter() {
final List<MetadataEntity> entities = Collections.singletonList(new MetadataEntity());
when(metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(FOLDER_ID, SAMPLE)).thenReturn(entities);
final MetadataWriter metadataWriter = mock(MetadataWriter.class);
final ArgumentCaptor<Writer> writerCaptor = ArgumentCaptor.forClass(Writer.class);
when(metadataWriterProvider.getMetadataWriter(writerCaptor.capture(), any())).thenReturn(metadataWriter);
doAnswer(invocation -> writeMessageAndReturnNothing(writerCaptor.getValue(), "message")).when(metadataWriter).writeEntities(any(), any());
final InputStream actualInputStream = manager.getInputStream(FOLDER_ID, SAMPLE, TSV);
Assert.assertEquals("message", inputStreamAsString(actualInputStream));
}
Aggregations