org.codehaus.jettison.json.JSONObject Java Examples
The following examples show how to use
org.codehaus.jettison.json.JSONObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestHsWebServicesJobs.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testJobAttemptsSlash() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("jobattempts/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("jobAttempts"); verifyHsJobAttempts(info, appContext.getJob(id)); } }
Example #2
Source File: AllPriceMapper.java From Crawer with MIT License | 6 votes |
/** * 对象转成json字符串 * @param mapper * @return * @throws JSONException */ private static String bean2Json(AllPriceMapper mapper) throws JSONException{ JSONArray ja = new JSONArray(); JSONObject jo = new JSONObject(); jo.put(DD_NET, mapper.getDD()==null?"":mapper.getDD()); jo.put(DB_NET, mapper.getDB()==null?"":mapper.getDB()); jo.put(AM_NET, mapper.getAM()==null?"":mapper.getAM()); jo.put(JD_NET, mapper.getJD()==null?"":mapper.getJD()); jo.put(PUB_NET, mapper.getPUB()==null?"":mapper.getPUB()); ja.put(jo); ja.put(new JSONObject()); return jo.toString(); }
Example #3
Source File: MainTest.java From batfish with Apache License 2.0 | 6 votes |
@Test public void testReadQuestionTemplateDuplicate() throws Exception { Map<String, String> questionTemplates = Maps.newHashMap(); // already existing question template with key duplicate_template questionTemplates.put(DUPLICATE_TEMPLATE_NAME, "template_body"); JSONObject testQuestion = new JSONObject(); testQuestion.put( "instance", new JSONObject() .put("instanceName", DUPLICATE_TEMPLATE_NAME) .put("description", "test question description")); Path questionJsonPath = _folder.newFile("testquestion.json").toPath(); CommonUtil.writeFile(questionJsonPath, testQuestion.toString()); readQuestionTemplate(questionJsonPath, questionTemplates); assertThat(questionTemplates.keySet(), hasSize(1)); // the value of the question template with key duplicate_template should be replaced now assertThat( questionTemplates, IsMapContaining.hasEntry( DUPLICATE_TEMPLATE_NAME, "{\"instance\":{\"instanceName\":\"duplicate_template\",\"description\":\"test question description\"}}")); }
Example #4
Source File: TestHsWebServicesJobsQuery.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testJobsQueryStartTimeInvalidformat() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").queryParam("startedTimeBegin", "efsd") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("RemoteException"); assertEquals("incorrect number of elements", 3, exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils .checkStringMatch( "exception message", "java.lang.Exception: Invalid number format: For input string: \"efsd\"", message); WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type); WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname); }
Example #5
Source File: SalesOrderHeaderODataIT.java From cloud-espm-v2 with Apache License 2.0 | 6 votes |
/** * Test Create Sales Order Header via URL. * * @throws IOException * @throws JSONException */ @Test public void testCreateSalesOrderHeaderViaREST() throws IOException, JSONException { String salesOrderHeaderXml = StreamHelper.readFromFile(SOH_FILENAME); String id = RequestExecutionHelper.createEntityViaREST(ENTITY_NAME, salesOrderHeaderXml, false); HttpResponse resp = RequestExecutionHelper.executeGetRequest( ENTITY_NAME + "?$format=json&$filter=SalesOrderId%20eq%20'" + id + "'", true); assertEquals("Sales Order not persisted", HttpURLConnection.HTTP_OK, resp.getResponseCode()); JSONArray ja = RequestExecutionHelper.getJSONArrayofResults(resp .getBody()); assertNotNull("Unable to parse JSON response", ja); JSONObject jo = (JSONObject) ja.get(0); assertEquals("Added Sales Order Header via REST not persisted in db", id, jo.getString("SalesOrderId")); resp = RequestExecutionHelper.executeDeleteRequest(ENTITY_NAME + "('" + id + "')", true); assertEquals( "Unable to delete Sales Order Header via REST or incorrect HTTP Response Code:" + resp.getResponseMessage(), HttpURLConnection.HTTP_NO_CONTENT, resp.getResponseCode()); }
Example #6
Source File: TestNMWebServices.java From big-c with Apache License 2.0 | 6 votes |
public void verifyNodeInfo(JSONObject json) throws JSONException, Exception { assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("nodeInfo"); assertEquals("incorrect number of elements", 16, info.length()); verifyNodeInfoGeneric(info.getString("id"), info.getString("healthReport"), info.getLong("totalVmemAllocatedContainersMB"), info.getLong("totalPmemAllocatedContainersMB"), info.getLong("totalVCoresAllocatedContainers"), info.getBoolean("vmemCheckEnabled"), info.getBoolean("pmemCheckEnabled"), info.getLong("lastNodeUpdateTime"), info.getBoolean("nodeHealthy"), info.getString("nodeHostName"), info.getString("hadoopVersionBuiltOn"), info.getString("hadoopBuildVersion"), info.getString("hadoopVersion"), info.getString("nodeManagerVersionBuiltOn"), info.getString("nodeManagerBuildVersion"), info.getString("nodeManagerVersion")); }
Example #7
Source File: AtlasClient.java From incubator-atlas with Apache License 2.0 | 6 votes |
/** * Get an entity given the entity id * @param entityType entity type name * @param attribute qualified name of the entity * @param value * @return result object * @throws AtlasServiceException */ public Referenceable getEntity(final String entityType, final String attribute, final String value) throws AtlasServiceException { JSONObject jsonResponse = callAPIWithRetries(API.GET_ENTITY, null, new ResourceCreator() { @Override public WebResource createResource() { WebResource resource = getResource(API.GET_ENTITY); resource = resource.queryParam(TYPE, entityType); resource = resource.queryParam(ATTRIBUTE_NAME, attribute); resource = resource.queryParam(ATTRIBUTE_VALUE, value); return resource; } }); try { String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION); return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true); } catch (JSONException e) { throw new AtlasServiceException(API.GET_ENTITY, e); } }
Example #8
Source File: TestAMWebServicesTasks.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testTasksSlash() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("tasks/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject tasks = json.getJSONObject("tasks"); JSONArray arr = tasks.getJSONArray("task"); assertEquals("incorrect number of elements", 2, arr.length()); verifyAMTask(arr, jobsMap.get(id), null); } }
Example #9
Source File: StramWebServices.java From attic-apex-core with Apache License 2.0 | 6 votes |
@POST @Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{opId:\\d+}/" + PATH_RECORDINGS_START) @Produces(MediaType.APPLICATION_JSON) public JSONObject startRecording(@PathParam("opId") int opId, String content) throws JSONException { init(); LOG.debug("Start recording on {} requested", opId); JSONObject response = new JSONObject(); long numWindows = 0; if (StringUtils.isNotBlank(content)) { JSONObject r = new JSONObject(content); numWindows = r.optLong("numWindows", 0); } String id = getTupleRecordingId(); dagManager.startRecording(id, opId, null, numWindows); response.put("id", id); return response; }
Example #10
Source File: TestAHSWebServices.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testSingleApp() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject app = json.getJSONObject("app"); assertEquals(appId.toString(), app.getString("appId")); assertEquals("test app", app.get("name")); assertEquals(round == 0 ? "test diagnostics info" : "", app.get("diagnosticsInfo")); assertEquals("test queue", app.get("queue")); assertEquals("user1", app.get("user")); assertEquals("test app type", app.get("type")); assertEquals(FinalApplicationStatus.UNDEFINED.toString(), app.get("finalAppStatus")); assertEquals(YarnApplicationState.FINISHED.toString(), app.get("appState")); }
Example #11
Source File: TestRMWebServicesApps.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testAppsQueryFinalStatus() throws JSONException, Exception { rm.start(); MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048); RMApp app1 = rm.submitApp(CONTAINER_MB); amNodeManager.nodeHeartbeat(true); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("apps").queryParam("finalStatus", FinalApplicationStatus.UNDEFINED.toString()) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); System.out.println(json.toString()); JSONObject apps = json.getJSONObject("apps"); assertEquals("incorrect number of elements", 1, apps.length()); JSONArray array = apps.getJSONArray("app"); assertEquals("incorrect number of elements", 1, array.length()); verifyAppInfo(array.getJSONObject(0), app1); rm.stop(); }
Example #12
Source File: ConvertProductBacklog.java From ezScrum with GNU General Public License v2.0 | 6 votes |
/**** * 更新story 至 Product Backlog * * @param boolean success * @return updateStoryResponse */ public String updateStory(boolean success) { JSONObject updateStoryResponse = new JSONObject(); try { if (success) { updateStoryResponse.put("status", "SUCCESS"); } else { updateStoryResponse.put("status", "FAILED"); } } catch (JSONException e) { return "{\"status\": \"FAILED\"}"; } return updateStoryResponse.toString(); }
Example #13
Source File: TestHsWebServicesTasks.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testTasksQueryReduce() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); String type = "r"; ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks") .queryParam("type", type).accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject tasks = json.getJSONObject("tasks"); JSONArray arr = tasks.getJSONArray("task"); assertEquals("incorrect number of elements", 1, arr.length()); verifyHsTask(arr, jobsMap.get(id), type); } }
Example #14
Source File: MetadataDiscoveryJerseyResourceIT.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Test public void testSearchByDSL() throws Exception { String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\""; MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add("query", dslQuery); JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams); Assert.assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); assertEquals(response.getString("query"), dslQuery); assertEquals(response.getString("queryType"), "dsl"); JSONArray results = response.getJSONArray(AtlasClient.RESULTS); assertNotNull(results); assertEquals(results.length(), 1); int numRows = response.getInt(AtlasClient.COUNT); assertEquals(numRows, 1); }
Example #15
Source File: TestAMWebServicesJobs.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testJobAttemptsDefault() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1") .path("mapreduce").path("jobs").path(jobId).path("jobattempts") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("jobAttempts"); verifyJobAttempts(info, jobsMap.get(id)); } }
Example #16
Source File: TestHsWebServicesAttempts.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testTaskAttemptsDefault() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid) .path("attempts").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyHsTaskAttempts(json, task); } } }
Example #17
Source File: TypeDiscoveryTest.java From attic-apex-core with Apache License 2.0 | 6 votes |
@Test public void testPortAttributes() throws JSONException, IllegalAccessException { JSONArray portAttributes = TypeDiscoverer.getPortAttributes().getJSONArray("attributes"); Map<String, JSONObject> attributesMap = Maps.newHashMap(); for (int i = 0; i < portAttributes.length(); i++) { attributesMap.put(portAttributes.getJSONObject(i).getString("name"), portAttributes.getJSONObject(i)); } JSONObject queueCapacityAttr = attributesMap.get("QUEUE_CAPACITY"); Assert.assertNotNull("queue capacity", queueCapacityAttr); Assert.assertEquals("queue capacity type", "java.lang.Integer", queueCapacityAttr.getString("type")); Assert.assertEquals("default queue capacity", "1024", queueCapacityAttr.getString("default")); JSONObject streamCodecAttr = attributesMap.get("STREAM_CODEC"); Assert.assertNotNull("stream codec", streamCodecAttr); Assert.assertEquals("stream codec type", "com.datatorrent.api.StreamCodec", streamCodecAttr.getString("type")); Assert.assertNotNull("type args", streamCodecAttr.getJSONArray("typeArgs")); }
Example #18
Source File: StramWebServices.java From Bats with Apache License 2.0 | 6 votes |
@GET @Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/attributes") @Produces(MediaType.APPLICATION_JSON) public JSONObject getOperatorAttributes(@PathParam("operatorName") String operatorName, @QueryParam("attributeName") String attributeName) { init(); OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName); if (logicalOperator == null) { throw new NotFoundException(); } HashMap<String, String> map = new HashMap<>(); for (Map.Entry<Attribute<?>, Object> entry : dagManager.getOperatorAttributes(operatorName).entrySet()) { if (attributeName == null || entry.getKey().getSimpleName().equals(attributeName)) { Map.Entry<Attribute<Object>, Object> entry1 = (Map.Entry<Attribute<Object>, Object>)(Map.Entry)entry; map.put(entry1.getKey().getSimpleName(), entry1.getKey().codec.toString(entry1.getValue())); } } return new JSONObject(map); }
Example #19
Source File: MappedXMLStreamReaderTest.java From jettison with Apache License 2.0 | 6 votes |
public void testStreamReaderNullTextAsNull() throws Exception { JSONObject obj = new JSONObject("{ " + "\"root\" : { " + "\"child1\" : \"null\"" + "} }"); Configuration c = new Configuration(); MappedNamespaceConvention con = new MappedNamespaceConvention(c); XMLStreamReader reader = new MappedXMLStreamReader(obj, con); assertEquals(XMLStreamReader.START_ELEMENT, reader.next()); assertEquals("root", reader.getName().getLocalPart()); assertEquals(XMLStreamReader.START_ELEMENT, reader.next()); assertEquals("child1", reader.getName().getLocalPart()); assertEquals(XMLStreamReader.CHARACTERS, reader.next()); assertEquals(null, reader.getText()); assertEquals(XMLStreamReader.END_ELEMENT, reader.next()); assertEquals("child1", reader.getName().getLocalPart()); assertEquals(XMLStreamReader.END_ELEMENT, reader.next()); assertEquals("root", reader.getName().getLocalPart()); }
Example #20
Source File: TestNMWebServicesApps.java From hadoop with Apache License 2.0 | 6 votes |
public void testNodeSingleAppHelper(String media) throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); HashMap<String, String> hash = addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); ClientResponse response = r.path("ws").path("v1").path("node").path("apps") .path(app.getAppId().toString()).accept(media) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyNodeAppInfo(json.getJSONObject("app"), app, hash); }
Example #21
Source File: TestRMWebServicesApps.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testAppsQueryStateNone() throws JSONException, Exception { rm.start(); MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048); rm.submitApp(CONTAINER_MB); amNodeManager.nodeHeartbeat(true); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("apps") .queryParam("state", YarnApplicationState.RUNNING.toString()) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); assertEquals("apps is not null", JSONObject.NULL, json.get("apps")); rm.stop(); }
Example #22
Source File: TestAMWebServicesTasks.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testTasksQueryReduce() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); String type = "r"; ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("tasks").queryParam("type", type) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject tasks = json.getJSONObject("tasks"); JSONArray arr = tasks.getJSONArray("task"); assertEquals("incorrect number of elements", 1, arr.length()); verifyAMTask(arr, jobsMap.get(id), type); } }
Example #23
Source File: TestAMWebServicesJobs.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testJobIdSlash() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId + "/").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("job"); verifyAMJob(info, jobsMap.get(id)); } }
Example #24
Source File: TestAMWebServicesJobs.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testJobId() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("job"); verifyAMJob(info, jobsMap.get(id)); } }
Example #25
Source File: TestHsWebServicesJobs.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testJobCountersForKilledJob() throws Exception { WebResource r = resource(); appContext = new MockHistoryContext(0, 1, 1, 1, true); injector = Guice.createInjector(new ServletModule() { @Override protected void configureServlets() { webApp = mock(HsWebApp.class); when(webApp.name()).thenReturn("hsmockwebapp"); bind(JAXBContextResolver.class); bind(HsWebServices.class); bind(GenericExceptionHandler.class); bind(WebApp.class).toInstance(webApp); bind(AppContext.class).toInstance(appContext); bind(HistoryContext.class).toInstance(appContext); bind(Configuration.class).toInstance(conf); serve("/*").with(GuiceContainer.class); } }); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("counters/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("jobCounters"); WebServicesTestUtils.checkStringMatch("id", MRApps.toString(id), info.getString("id")); assertTrue("Job shouldn't contain any counters", info.length() == 1); } }
Example #26
Source File: JsonWriter.java From vespa with Apache License 2.0 | 5 votes |
public void fillInJson(UnitAttributes attributes, JSONObject json) throws Exception { JSONObject attributesJson = new JSONObject(); for (Map.Entry<String, String> e : attributes.getAttributeValues().entrySet()) { attributesJson.put(e.getKey(), e.getValue()); } json.put("attributes", attributesJson); }
Example #27
Source File: TestAMWebServices.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testInfoSlash() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("info/").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); verifyAMInfo(json.getJSONObject("info"), appContext); }
Example #28
Source File: UserProfile.java From hadoop-arch-book with Apache License 2.0 | 5 votes |
public JSONObject getJSONObject() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("userId", userId); jsonObject.put("historicAvgSingleDaySpend", historicAvgSingleDaySpend); jsonObject.put("historicAvg90PercentSingleDaySpend", historicAvg90PercentSingleDaySpend); jsonObject.put("todayMaxSpend", todayMaxSpend); jsonObject.put("todayNumOfPurchases", todayNumOfPurchases); jsonObject.put("spendByLast100VenderId", new JSONObject(spendByLast100VenderId)); return jsonObject; }
Example #29
Source File: TestRMWebServices.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testClusterSlash() throws JSONException, Exception { WebResource r = resource(); // test with trailing "/" to make sure acts same as without slash ClientResponse response = r.path("ws").path("v1").path("cluster/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterInfo(json); }
Example #30
Source File: AdminResource.java From incubator-atlas with Apache License 2.0 | 5 votes |
/** * Fetches the version for this application. * * @return json representing the version. */ @GET @Path("version") @Produces(Servlets.JSON_MEDIA_TYPE) public Response getVersion() { if (LOG.isDebugEnabled()) { LOG.debug("==> AdminResource.getVersion()"); } if (version == null) { try { PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-buildinfo.properties"); JSONObject response = new JSONObject(); response.put("Version", configProperties.getString("build.version", "UNKNOWN")); response.put("Name", configProperties.getString("project.name", "apache-atlas")); response.put("Description", configProperties.getString("project.description", "Metadata Management and Data Governance Platform over Hadoop")); // todo: add hadoop version? // response.put("Hadoop", VersionInfo.getVersion() + "-r" + VersionInfo.getRevision()); version = Response.ok(response).build(); } catch (JSONException | ConfigurationException e) { throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); } } if (LOG.isDebugEnabled()) { LOG.debug("<== AdminResource.getVersion()"); } return version; }