Search in sources :

Example 1 with MetadataWriter

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);
    }
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) StringInputStream(com.amazonaws.util.StringInputStream) StringWriter(java.io.StringWriter) MetadataWriterException(com.epam.pipeline.manager.metadata.writer.MetadataWriterException) IOException(java.io.IOException) MetadataWriter(com.epam.pipeline.manager.metadata.writer.MetadataWriter) MetadataFileFormat(com.epam.pipeline.manager.metadata.writer.MetadataFileFormat)

Example 2 with MetadataWriter

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));
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataWriter(com.epam.pipeline.manager.metadata.writer.MetadataWriter) Test(org.junit.Test)

Example 3 with MetadataWriter

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));
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) InputStream(java.io.InputStream) MetadataWriter(com.epam.pipeline.manager.metadata.writer.MetadataWriter) MetadataWriter(com.epam.pipeline.manager.metadata.writer.MetadataWriter) Writer(java.io.Writer) Test(org.junit.Test)

Aggregations

MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)3 MetadataWriter (com.epam.pipeline.manager.metadata.writer.MetadataWriter)3 Test (org.junit.Test)2 StringInputStream (com.amazonaws.util.StringInputStream)1 MetadataFileFormat (com.epam.pipeline.manager.metadata.writer.MetadataFileFormat)1 MetadataWriterException (com.epam.pipeline.manager.metadata.writer.MetadataWriterException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1