Search in sources :

Example 31 with JSONObject

use of net.minidev.json.JSONObject in project runwar by cfmlprojects.

the class TestGetTrayConfig method testGetTrayConfig.

@Test
public void testGetTrayConfig() {
    final String statusText = " Awesome server on 127.0.0.1:8099 PID:323423";
    HashMap<String, String> variableMap = new HashMap<String, String>();
    variableMap.put("defaultTitle", statusText);
    variableMap.put("runwar.port", "8099");
    variableMap.put("runwar.processName", "Awesome");
    variableMap.put("runwar.host", "localhost");
    variableMap.put("runwar.stopsocket", "2343");
    final String menuJSON = "{\"title\" : \"${defaultTitle}\", \"items\": [" + "{label:\"Blank Item\", disabled:\"true\"}" + "{label:\"Stop Server (${runwar.processName})\", action:\"stopserver\"}" + ",{label:\"Open Browser\", action:\"openbrowser\", url:\"http://${runwar.host}:${runwar.port}/\"}" + "]}";
    final String menuJSONTooltip = "{\"title\" : \"${defaultTitle}\",\"tooltip\" : \"Cooltool ${runwar.host}\", \"items\": [" + "{label:\"Blank Item\", disabled:\"true\"}" + "{label:\"Stop Server (${runwar.processName})\", action:\"stopserver\"}" + ",{label:\"Open Browser\", action:\"openbrowser\", url:\"http://${runwar.host}:${runwar.port}/\"}" + "]}";
    final String legacyMenuJSON = "[" + "{label:\"Stop Server (${runwar.processName})\", action:\"stopserver\"}" + ",{label:\"Open Browser\", action:\"openbrowser\", url:\"http://${runwar.host}:${runwar.port}/\"}" + "]";
    final String menuJSONnoActions = "{\"title\" : \"${defaultTitle}\", \"items\": [" + "{label:\"Stop Server (${runwar.processName})\"}" + ",{label:\"Open Browser\", url:\"http://${runwar.host}:${runwar.port}/\"}" + "]}";
    JSONObject menu;
    menu = Tray.getTrayConfig(menuJSON, statusText, variableMap);
    assertEquals(statusText, menu.get("title").toString());
    assertEquals(statusText, menu.get("tooltip").toString());
    assertEquals(3, ((JSONArray) menu.get("items")).size());
    assertEquals("http://localhost:8099/", ((JSONObject) ((JSONArray) menu.get("items")).get(2)).get("url").toString());
    assertEquals("true", ((JSONObject) ((JSONArray) menu.get("items")).get(0)).get("disabled").toString());
    menu = Tray.getTrayConfig(menuJSONTooltip, statusText, variableMap);
    assertEquals("Cooltool localhost", menu.get("tooltip").toString());
    assertEquals(statusText, menu.get("title").toString());
    assertEquals(3, ((JSONArray) menu.get("items")).size());
    menu = Tray.getTrayConfig(legacyMenuJSON, statusText, variableMap);
    assertEquals(statusText, menu.get("title").toString());
    assertEquals(2, ((JSONArray) menu.get("items")).size());
    menu = Tray.getTrayConfig(menuJSONnoActions, statusText, variableMap);
    assertEquals(statusText, menu.get("title").toString());
    assertEquals(2, ((JSONArray) menu.get("items")).size());
    assertEquals("http://localhost:8099/", ((JSONObject) ((JSONArray) menu.get("items")).get(1)).get("url").toString());
    assertEquals("openbrowser", ((JSONObject) ((JSONArray) menu.get("items")).get(1)).get("action").toString());
}
Also used : JSONObject(net.minidev.json.JSONObject) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 32 with JSONObject

use of net.minidev.json.JSONObject in project runwar by cfmlprojects.

the class HTTP2Test method http2testProxiedRequest.

@Test
public void http2testProxiedRequest() throws IOException {
    final TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/dumprunwarrequest");
        client.setRedirectStrategy(new LaxRedirectStrategy());
        HttpResponse result = client.execute(get);
        assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        JSONObject responseData = (JSONObject) JSONValue.parse(HttpClientUtils.readResponse(result));
        assertTrue(Boolean.parseBoolean(responseData.get("isHTTP2").toString()), get.getURI().toString() + " failed to be http2");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : JSONObject(net.minidev.json.JSONObject) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) TestHttpClient(testutils.TestHttpClient) Test(org.junit.jupiter.api.Test)

Example 33 with JSONObject

use of net.minidev.json.JSONObject in project runwar by cfmlprojects.

the class ProxyPeerAddressTest method testForwardForHostPort.

@Test
public void testForwardForHostPort() throws IOException {
    String forwardFor = "localhost";
    String forwardPort = "8765";
    assertTrue(DefaultServer.getServerOptions().isProxyPeerAddressEnabled());
    final TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/dumprunwarrequest");
        get.addHeader(Headers.X_FORWARDED_FOR_STRING, forwardFor);
        get.addHeader(Headers.X_FORWARDED_HOST_STRING, forwardFor);
        get.addHeader(Headers.X_FORWARDED_PORT_STRING, forwardPort);
        HttpResponse result = client.execute(get);
        assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        JSONObject responseData = (JSONObject) JSONValue.parse(HttpClientUtils.readResponse(result));
        assertEquals(forwardFor + ":" + forwardPort, responseData.get("host"));
        assertEquals(forwardFor, responseData.get("remoteHost"));
        assertEquals(forwardFor, ((JSONObject) responseData.get("headers")).get(Headers.X_FORWARDED_FOR_STRING));
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : JSONObject(net.minidev.json.JSONObject) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(testutils.TestHttpClient) Test(org.junit.jupiter.api.Test)

Example 34 with JSONObject

use of net.minidev.json.JSONObject in project elastest-torm by elastest.

the class TestLinkService method getTestExecFields.

public String getTestExecFields(Execution exec) {
    JSONObject fields = new JSONObject();
    JSONObject plan = new JSONObject();
    JSONObject build = new JSONObject();
    plan.put("id", exec.getTestPlanId());
    build.put("id", exec.getBuildId());
    fields.put("plan", plan);
    fields.put("build", build);
    return fields.toString();
}
Also used : JSONObject(net.minidev.json.JSONObject)

Example 35 with JSONObject

use of net.minidev.json.JSONObject in project molgenis by molgenis.

the class RestControllerV2APIIT method testCreateEntities.

// FIXME
@Test(enabled = false)
public void testCreateEntities() {
    // @Transactional
    // @PostMapping(value = "/{entityName}", produces = APPLICATION_JSON_VALUE)
    // @ResponseBody
    // public EntityCollectionBatchCreateResponseBodyV2 createEntities(@PathVariable("entityName") String entityName,
    // @RequestBody @Valid EntityCollectionBatchRequestV2 request, HttpServletResponse response) throws Exception
    JSONObject jsonObject = new JSONObject();
    JSONArray entities = new JSONArray();
    JSONObject entity1 = new JSONObject();
    entity1.put("value", "ref55");
    entity1.put("label", "label55");
    entities.add(entity1);
    JSONObject entity2 = new JSONObject();
    entity2.put("value", "ref57");
    entity2.put("label", "label57");
    entities.add(entity2);
    jsonObject.put("entities", entities);
    given().log().all().body(jsonObject.toJSONString()).contentType(APPLICATION_JSON).header(X_MOLGENIS_TOKEN, testUserToken).post(API_V2 + "V2_API_TypeTestAPIV2").then().log().all().statusCode(CREATED).body("location", Matchers.equalTo("/api/v2/V2_API_TypeTestv2?q=id=in=(\"55\",\"57\")"), "resources[0].href", Matchers.equalTo("/api/v2/V2_API_TypeTestAPIV2/55"), "resources[1].href", Matchers.equalTo("/api/v2/V2_API_TypeTestAPIV2/57"));
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) Test(org.testng.annotations.Test)

Aggregations

JSONObject (net.minidev.json.JSONObject)254 JSONArray (net.minidev.json.JSONArray)49 Test (org.junit.Test)39 Test (org.testng.annotations.Test)38 JSONParser (net.minidev.json.parser.JSONParser)23 HashMap (java.util.HashMap)22 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)14 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)13 ParseException (net.minidev.json.parser.ParseException)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 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)9 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)9