Search in sources :

Example 51 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestXmlResponseQueueTransformer method testNoIdNoSourceId.

@Test
public void testNoIdNoSourceId() throws CatalogTransformerException, IOException, XpathException, SAXException {
    // given
    transformer.setThreshold(2);
    SourceResponse response = givenSourceResponse(null, null);
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    assertThat(binaryContent.getMimeType(), is(mimeType));
    byte[] bytes = binaryContent.getByteArray();
    String output = new String(bytes);
    print(output, verboseDebug);
    assertXpathNotExists("/mc:metacards/mc:metacard/mc:source", output);
    assertXpathNotExists("/mc:metacards/mc:metacard/@gml:id", output);
    verifyDefaults("1", output);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 52 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestZipCompression method testCompressionWithDerivedContentInvalidURI.

@Test
public void testCompressionWithDerivedContentInvalidURI() throws Exception {
    String invalidUri = "^";
    SourceResponse sourceResponse = createSourceResponseWithURISchemes(CONTENT_SCHEME, invalidUri);
    BinaryContent binaryContent = zipCompression.transform(sourceResponse, filePathArgument);
    assertThat(binaryContent, notNullValue());
    assertZipContents(binaryContent, METACARD_RESULT_LIST_WITH_CONTENT);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 53 with BinaryContent

use of ddf.catalog.data.BinaryContent in project alliance by codice.

the class OverviewSupplierTest method setUp.

@Before
public void setUp() throws CatalogTransformerException {
    final BinaryContent overviewContent = mock(BinaryContent.class);
    doAnswer(invocationOnMock -> getClass().getClassLoader().getResourceAsStream("flower.jpg")).when(overviewContent).getInputStream();
    final MetacardTransformer resourceMetacardTransformer = mock(MetacardTransformer.class);
    doReturn(overviewContent).when(resourceMetacardTransformer).transform(argThat(isMetacardWithDerivedOverviewResource()), eq(Collections.singletonMap(ContentItem.QUALIFIER_KEYWORD, "overview")));
    doThrow(CatalogTransformerException.class).when(resourceMetacardTransformer).transform(argThat(not(isMetacardWithDerivedOverviewResource())), eq(Collections.singletonMap(ContentItem.QUALIFIER_KEYWORD, "overview")));
    supplier = new OverviewSupplier(resourceMetacardTransformer);
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) BinaryContent(ddf.catalog.data.BinaryContent) Before(org.junit.Before)

Example 54 with BinaryContent

use of ddf.catalog.data.BinaryContent in project alliance by codice.

the class OverviewSupplier method apply.

@Override
public Optional<BufferedImage> apply(Metacard metacard, Map<String, Serializable> arguments) {
    try {
        final Map<String, Serializable> resourceTransformerArguments = new HashMap<>();
        resourceTransformerArguments.put(ContentItem.QUALIFIER_KEYWORD, "overview");
        final BinaryContent overviewContent = resourceMetacardTransformer.transform(metacard, resourceTransformerArguments);
        try (final InputStream inputStream = overviewContent.getInputStream()) {
            return Optional.ofNullable(ImageIO.read(inputStream));
        }
    } catch (IOException | CatalogTransformerException e) {
        LOGGER.debug("Could not get the overview image.", e);
    }
    return Optional.empty();
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) BinaryContent(ddf.catalog.data.BinaryContent)

Example 55 with BinaryContent

use of ddf.catalog.data.BinaryContent in project alliance by codice.

the class CatalogOutputAdapterTest method testGrayscale.

@Test
public void testGrayscale() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    int originalWidth = 200;
    int originalHeight = 100;
    int chipWidth = 160;
    int chipHeight = 80;
    NitfSegmentsFlow nitfSegmentsFlow = createGenericNitfSegmentFlow(originalWidth, originalHeight);
    BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_BYTE_GRAY);
    BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, 0, 0);
    NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData();
    chipNitfSegmentFlow.forEachImageSegment(imageSegment1 -> {
        assertThat(imageSegment1.getPixelValueType(), is(PixelValueType.INTEGER));
        assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.MONOCHROME));
        assertThat(imageSegment1.getActualBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getNumberOfBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getImageBand(1).getImageRepresentation(), is("M"));
    });
}
Also used : NitfSegmentsFlow(org.codice.imaging.nitf.fluent.NitfSegmentsFlow) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) BinaryContent(ddf.catalog.data.BinaryContent) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)112 Test (org.junit.Test)79 Metacard (ddf.catalog.data.Metacard)42 SourceResponse (ddf.catalog.operation.SourceResponse)41 HashMap (java.util.HashMap)30 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)28 Map (java.util.Map)24 Result (ddf.catalog.data.Result)22 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)19 Matchers.anyString (org.mockito.Matchers.anyString)18 Serializable (java.io.Serializable)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 Date (java.util.Date)12 LineString (ddf.geo.formatter.LineString)11 MultiLineString (ddf.geo.formatter.MultiLineString)11 File (java.io.File)11 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)10 ResultImpl (ddf.catalog.data.impl.ResultImpl)10 IOException (java.io.IOException)10