Search in sources :

Example 91 with BinaryContent

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

the class TestGeoJsonMetacardTransformer method testwithBadGeo.

/**
     * Tests that improper WKT throws an exception
     *
     * @throws CatalogTransformerException
     * @throws IOException
     * @throws ParseException
     */
@Test(expected = CatalogTransformerException.class)
public void testwithBadGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    String badWktMissingComma = "MULTILINESTRING ((10 10, 20 20, 10 40)(40 40, 30 30, 40 20, 30 10))";
    metacard.setLocation(badWktMissingComma);
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
}
Also used : LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 92 with BinaryContent

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

the class TestGeoJsonQueryResponseTransformer method transform.

private JSONObject transform(SourceResponse sourceResponse, final int resultCount, final int hitCount) throws CatalogTransformerException, IOException, ParseException {
    BinaryContent content = new GeoJsonQueryResponseTransformer().transform(sourceResponse, null);
    assertEquals(content.getMimeTypeValue(), GeoJsonQueryResponseTransformer.DEFAULT_MIME_TYPE.getBaseType());
    String jsonText = new String(content.getByteArray());
    Object object = PARSER.parse(jsonText);
    JSONObject obj = (JSONObject) object;
    return obj;
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONObject(net.minidev.json.JSONObject) BinaryContent(ddf.catalog.data.BinaryContent)

Example 93 with BinaryContent

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

the class TestAttributeMetacardTransformer method simpleBytesTransform.

private void simpleBytesTransform(byte[] thumbnailBytes) throws CatalogTransformerException, IOException {
    Metacard mockMetacard = mock(Metacard.class);
    when(mockMetacard.getThumbnail()).thenReturn(thumbnailBytes);
    when(mockMetacard.getAttribute(Metacard.THUMBNAIL)).thenReturn(new AttributeImpl(Metacard.THUMBNAIL, thumbnailBytes));
    BinaryContent content = THUMBNAIL_TRANSFORMER.transform(mockMetacard, null);
    assertArrayEquals(thumbnailBytes, IOUtils.toByteArray(content.getInputStream()));
    assertEquals("Mime type failed to match.", jpegMimeType, content.getMimeType());
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) BinaryContent(ddf.catalog.data.BinaryContent)

Example 94 with BinaryContent

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

the class TestAttributeMetacardTransformer method simpleStringTransform.

private void simpleStringTransform(String metadata) throws CatalogTransformerException, IOException {
    Metacard mockMetacard = mock(Metacard.class);
    when(mockMetacard.getAttribute(isA(String.class))).thenReturn(new AttributeImpl(Metacard.METADATA, metadata));
    BinaryContent content = METADATA_TRANSFORMER.transform(mockMetacard, null);
    assertEquals(metadata, IOUtils.toString(content.getInputStream()));
    assertEquals("Mime type failed to match.", xmlMimeType, content.getMimeType());
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) BinaryContent(ddf.catalog.data.BinaryContent)

Example 95 with BinaryContent

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

the class TestGeoJsonMetacardTransformer method testwithLineStringGeo.

/**
     * Tests that a LineString Geography can be returned in JSON
     *
     * @throws CatalogTransformerException
     * @throws IOException
     * @throws ParseException
     */
@Test
public void testwithLineStringGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("LINESTRING (30 10, 10 30, 40 40)");
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    assertEquals(content.getMimeTypeValue(), GeoJsonMetacardTransformer.DEFAULT_MIME_TYPE.getBaseType());
    String jsonText = new String(content.getByteArray());
    LOGGER.debug(jsonText);
    Object object = PARSER.parse(jsonText);
    JSONObject obj2 = (JSONObject) object;
    Map geometryMap = (Map) obj2.get("geometry");
    assertThat(geometryMap.get(CompositeGeometry.TYPE_KEY).toString(), is(LineString.TYPE));
    List<List<Double>> coordsList = (List<List<Double>>) geometryMap.get(CompositeGeometry.COORDINATES_KEY);
    assertThat(coordsList.size(), is(3));
    for (List list : coordsList) {
        assertEquals(list.size(), 2);
    }
    assertThat(coordsList.get(0).get(0), equalTo(30.0));
    assertThat(coordsList.get(0).get(1), equalTo(10.0));
    assertThat(coordsList.get(1).get(0), equalTo(10.0));
    assertThat(coordsList.get(1).get(1), equalTo(30.0));
    assertThat(coordsList.get(2).get(0), equalTo(40.0));
    assertThat(coordsList.get(2).get(1), equalTo(40.0));
    verifyBasicMetacardJson(now, obj2);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) List(java.util.List) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) 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