use of net.minidev.json.JSONObject in project ddf by codice.
the class GeoJsonQueryResponseTransformerTest method verifyResponse.
@SuppressWarnings("rawtypes")
private void verifyResponse(JSONObject response, int count, long hits) {
assertThat(toString(response.get("hits")), is(Long.toString(hits)));
List results = (List) response.get("results");
assertThat(results.size(), is(count));
for (Object o : results) {
verifyResult((Map) o);
}
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class GeoJsonQueryResponseTransformerTest method transform.
private JSONObject transform(SourceResponse sourceResponse, GeoJsonQueryResponseTransformer geoJsonQRT) throws CatalogTransformerException, IOException, ParseException {
BinaryContent content = geoJsonQRT.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;
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class GeoJsonQueryResponseTransformerTest method testNullResults.
@Test
public void testNullResults() throws CatalogTransformerException, IOException, ParseException {
SourceResponse sourceResponse = new SourceResponseImpl(null, null, 0L);
JSONObject obj = transform(sourceResponse);
verifyResponse(obj, 0, 0);
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class GeoJsonQueryResponseTransformerTest method testCustomTransformerWithJsonArray.
@Test
public void testCustomTransformerWithJsonArray() throws ParseException, IOException, CatalogTransformerException {
GeoJsonQueryResponseTransformer geoJsonQRT = new GeoJsonQueryResponseTransformer(createCustomMetacardTransformer("[{\"id\":\"0\"},{\"id\":\"1\"}]"));
SourceResponse response = setupResponse(1, 1L);
JSONObject json = transform(response, geoJsonQRT);
JSONArray results = (JSONArray) json.get("results");
JSONObject firstResult = (JSONObject) results.get(0);
JSONArray metacard = (JSONArray) firstResult.get("metacard");
assertThat(((JSONObject) metacard.get(0)).get("id"), is("0"));
assertThat(((JSONObject) metacard.get(1)).get("id"), is("1"));
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class PlatformUiConfigurationTest method testConfig.
@Test
public void testConfig() throws IOException {
int timeout = 1234;
String wsOutput = configuration.getConfigAsJsonString();
// throws JSON Parse exception if not valid json.
Object obj = JSONValue.parse(wsOutput);
if (!(obj instanceof JSONObject)) {
fail("PlatformUiConfiguration is not a JSON Object.");
}
BrandingPlugin branding = mock(BrandingPlugin.class);
when(branding.getBase64FavIcon()).thenReturn(Base64.getEncoder().encodeToString("fav".getBytes()));
when(branding.getBase64ProductImage()).thenReturn(Base64.getEncoder().encodeToString("image".getBytes()));
when(branding.getBase64VendorImage()).thenReturn(Base64.getEncoder().encodeToString("vendorimage".getBytes()));
BrandingRegistryImpl brandingPlugin = mock(BrandingRegistryImpl.class);
when(brandingPlugin.getProductName()).thenReturn("product");
when(brandingPlugin.getBrandingPlugins()).thenReturn(Collections.singletonList(branding));
when(brandingPlugin.getAttributeFromBranding(any())).thenCallRealMethod();
configuration.setBranding(brandingPlugin);
configuration.setHeader("header");
configuration.setFooter("footer");
configuration.setBackground("background");
configuration.setColor("color");
configuration.setTimeout(timeout);
wsOutput = configuration.getConfigAsJsonString();
// throws JSON Parse exception if not valid json.
obj = JSONValue.parse(wsOutput);
if (!(obj instanceof JSONObject)) {
fail("PlatformUiConfiguration is not a JSON Object.");
}
JSONObject jsonObject = (JSONObject) obj;
assertEquals("header", jsonObject.get(PlatformUiConfiguration.HEADER_CONFIG_KEY));
assertEquals("footer", jsonObject.get(PlatformUiConfiguration.FOOTER_CONFIG_KEY));
assertEquals("background", jsonObject.get(PlatformUiConfiguration.BACKGROUND_CONFIG_KEY));
assertEquals("color", jsonObject.get(PlatformUiConfiguration.COLOR_CONFIG_KEY));
assertEquals("product", jsonObject.get(PlatformUiConfiguration.TITLE_CONFIG_KEY));
assertEquals("image", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.PRODUCT_IMAGE_CONFIG_KEY))));
assertEquals("vendorimage", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.VENDOR_IMAGE_CONFIG_KEY))));
assertEquals("fav", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.FAV_ICON_CONFIG_KEY))));
assertEquals(timeout, jsonObject.get(PlatformUiConfiguration.TIMEOUT_CONFIG_KEY));
}
Aggregations