Search in sources :

Example 96 with JSONObject

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);
    }
}
Also used : LinkedList(java.util.LinkedList) List(java.util.List) JSONObject(net.minidev.json.JSONObject)

Example 97 with JSONObject

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;
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONObject(net.minidev.json.JSONObject) BinaryContent(ddf.catalog.data.BinaryContent)

Example 98 with JSONObject

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);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) JSONObject(net.minidev.json.JSONObject) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) Test(org.junit.Test)

Example 99 with JSONObject

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"));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) Test(org.junit.Test)

Example 100 with JSONObject

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));
}
Also used : BrandingRegistryImpl(org.codice.ddf.branding.impl.BrandingRegistryImpl) BrandingPlugin(org.codice.ddf.branding.BrandingPlugin) JSONObject(net.minidev.json.JSONObject) JSONObject(net.minidev.json.JSONObject) Test(org.junit.Test)

Aggregations

JSONObject (net.minidev.json.JSONObject)257 JSONArray (net.minidev.json.JSONArray)51 Test (org.junit.Test)39 Test (org.testng.annotations.Test)38 JSONParser (net.minidev.json.parser.JSONParser)26 HashMap (java.util.HashMap)22 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)14 ParseException (net.minidev.json.parser.ParseException)14 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)13 JSONConverterException (org.btrplace.json.JSONConverterException)13 SignedJWT (com.nimbusds.jwt.SignedJWT)12 Node (org.btrplace.model.Node)12 VM (org.btrplace.model.VM)12 JWSHeader (com.nimbusds.jose.JWSHeader)10 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)10 ArrayList (java.util.ArrayList)10 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)9