Search in sources :

Example 31 with BinaryContent

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

the class TestGeoJsonMetacardTransformer method testwithPolygonGeoNoHole.

@Test
public void testwithPolygonGeoNoHole() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))");
    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(Polygon.TYPE));
    List<List> listOfRings = (List<List>) geometryMap.get(CompositeGeometry.COORDINATES_KEY);
    assertThat(listOfRings.size(), is(1));
    List<List> exteriorRing = listOfRings.get(0);
    testPopularPolygon(exteriorRing);
    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)

Example 32 with BinaryContent

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

the class ConfigurationStore method getDocument.

@GET
@Path("/config")
public Response getDocument(@Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
    Response response;
    Map<String, Object> config = new HashMap<>();
    config.put("branding", getProductName());
    config.put("version", getProductVersion());
    config.put("showWelcome", isSignIn);
    config.put("showTask", isTask);
    config.put("format", format);
    config.put("timeout", timeout);
    config.put("resultCount", resultCount);
    config.put("typeNameMapping", typeNameMapping);
    config.put("terrainProvider", proxiedTerrainProvider);
    config.put("imageryProviders", getProxiedImageryProviders());
    config.put("gazetteer", isGazetteer);
    config.put("showIngest", isIngest);
    config.put("projection", projection);
    config.put("helpUrl", helpUrl);
    config.put("bingKey", bingKey);
    config.put("externalAuthentication", isExternalAuthentication);
    String configJson = toJson(config);
    BinaryContent content = new BinaryContentImpl(new ByteArrayInputStream(configJson.getBytes(StandardCharsets.UTF_8)), jsonMimeType);
    response = Response.ok(content.getInputStream(), content.getMimeTypeValue()).build();
    return response;
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) BinaryContent(ddf.catalog.data.BinaryContent) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 33 with BinaryContent

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

the class TestXmlResponseQueueTransformer method testEmptySourceResponse.

/**
     * @throws CatalogTransformerException
     */
@Test
public void testEmptySourceResponse() throws CatalogTransformerException, IOException, XpathException, SAXException {
    // given
    transformer.setThreshold(-1);
    SourceResponse response = new SourceResponseImpl(null, Collections.<Result>emptyList());
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    String output = new String(binaryContent.getByteArray());
    LOGGER.info(output);
    assertXpathEvaluatesTo("", "/mc:metacards", output);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 34 with BinaryContent

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

the class TestXmlResponseQueueTransformer method testNoId.

@Test
public void testNoId() throws CatalogTransformerException, IOException, XpathException, SAXException {
    // given
    transformer.setThreshold(2);
    SourceResponse response = givenSourceResponse(DEFAULT_SOURCE_ID, 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);
    assertXpathEvaluatesTo(DEFAULT_SOURCE_ID, "/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 35 with BinaryContent

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

the class TestXmlResponseQueueTransformer method testMetacardTypeNameNull.

/**
     * No {@link MetacardType} name should use the default name.
     *
     * @throws CatalogTransformerException
     * @throws IOException
     * @throws SAXException
     * @throws XpathException
     */
@Test
public void testMetacardTypeNameNull() throws CatalogTransformerException, IOException, XpathException, SAXException {
    // given
    transformer.setThreshold(2);
    SourceResponse response = givenMetacardTypeName(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);
    assertXpathEvaluatesTo(DEFAULT_TYPE_NAME, "/mc:metacards/mc:metacard/mc:type", output);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)214 Test (org.junit.Test)164 Metacard (ddf.catalog.data.Metacard)87 SourceResponse (ddf.catalog.operation.SourceResponse)78 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)51 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)44 HashMap (java.util.HashMap)42 Result (ddf.catalog.data.Result)41 Map (java.util.Map)39 Serializable (java.io.Serializable)33 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)27 ResultImpl (ddf.catalog.data.impl.ResultImpl)26 LineString (ddf.geo.formatter.LineString)21 MultiLineString (ddf.geo.formatter.MultiLineString)21 Date (java.util.Date)21 File (java.io.File)20 JSONObject (org.json.simple.JSONObject)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 FileOutputStream (java.io.FileOutputStream)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17