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());
}
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();
}
}
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();
}
}
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();
}
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"));
}
Aggregations