List of usage examples for org.json JSONObject getJSONObject
public JSONObject getJSONObject(String key) throws JSONException
From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java
/** * Positive test case for createEstimate method with mandatory parameters. *//* ww w .ja va 2 s . co m*/ @Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters", "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createEstimate} integration test with mandatory parameters.") public void testCreateEstimateWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createEstimate"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createEstimate_mandatory.json"); JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Estimate"); String estimateId = esbResponseObject.getString("Id"); connectorProperties.setProperty("estimateId", estimateId); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/estimate/" + estimateId; String OAuthHeader = getOAuthHeader("GET", apiEndPoint); apiRequestHeadersMap.put("Authorization", OAuthHeader); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Estimate"); Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"), apiResponseObject.getJSONObject("MetaData").getString("CreateTime")); Assert.assertEquals(esbResponseObject.getString("DocNumber"), apiResponseObject.getString("DocNumber")); Assert.assertEquals(esbResponseObject.getString("TxnDate"), apiResponseObject.getString("TxnDate")); }
From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java
/** * Positive test case for createEstimate method with optional parameters. */// www . j av a 2 s . c o m @Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters", "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createEstimate} integration test with optional parameters.") public void testCreateEstimateWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createEstimate"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createEstimate_optional.json"); JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Estimate"); String estimateId = esbResponseObject.getString("Id"); connectorProperties.setProperty("estimateIdOptional", estimateId); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/estimate/" + estimateId; String OAuthHeader = getOAuthHeader("GET", apiEndPoint); apiRequestHeadersMap.put("Authorization", OAuthHeader); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Estimate"); Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"), apiResponseObject.getJSONObject("MetaData").getString("CreateTime")); Assert.assertEquals(esbResponseObject.getString("DocNumber"), apiResponseObject.getString("DocNumber")); Assert.assertEquals(esbResponseObject.getString("ExpirationDate"), apiResponseObject.getString("ExpirationDate")); Assert.assertEquals(esbResponseObject.getJSONObject("BillAddr").getString("City"), apiResponseObject.getJSONObject("BillAddr").getString("City")); Assert.assertEquals(esbResponseObject.getString("ShipDate"), apiResponseObject.getString("ShipDate")); Assert.assertEquals(esbResponseObject.getJSONObject("BillEmail").getString("Address"), apiResponseObject.getJSONObject("BillEmail").getString("Address")); }
From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java
/** * Positive test case for createBillPayment method with mandatory parameters. *///from w w w . j a v a 2s . c om @Test(priority = 2, dependsOnMethods = { "testCreateAccountWithMandatoryParameters", "testCreateVendorWithOptionalParameters", "testCreateCustomerWithOptionalParameters", "testCreateBillWithMandatoryParameters", "testCreateBillWithOptionalParameters" }, description = "quickbooks {createBillPayment} integration test with mandatory parameters.") public void testCreateBillPaymentWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createBillPayment"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createBillPayment_mandatory.json"); JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("BillPayment"); String billPaymentId = esbResponseObject.getString("Id"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/billpayment/" + billPaymentId; String OAuthHeader = getOAuthHeader("GET", apiEndPoint); apiRequestHeadersMap.put("Authorization", OAuthHeader); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("BillPayment"); Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"), apiResponseObject.getJSONObject("MetaData").getString("CreateTime")); Assert.assertEquals(esbResponseObject.getString("domain"), apiResponseObject.getString("domain")); Assert.assertEquals(esbResponseObject.getString("SyncToken"), apiResponseObject.getString("SyncToken")); Assert.assertEquals(esbResponseObject.getString("TxnDate"), apiResponseObject.getString("TxnDate")); }
From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java
/** * Positive test case for createBillPayment method with optional parameters. *///w ww . ja v a2s .com @Test(priority = 2, dependsOnMethods = { "testCreateAccountWithMandatoryParameters", "testCreateVendorWithOptionalParameters", "testCreateCustomerWithOptionalParameters", "testCreateBillWithMandatoryParameters", "testCreateBillWithOptionalParameters" }, description = "quickbooks {createBillPayment} integration test with mandatory parameters.") public void testCreateBillPaymentWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createBillPayment"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createBillPayment_optional.json"); JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("BillPayment"); String billPaymentId = esbResponseObject.getString("Id"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/billpayment/" + billPaymentId; String OAuthHeader = getOAuthHeader("GET", apiEndPoint); apiRequestHeadersMap.put("Authorization", OAuthHeader); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("BillPayment"); Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"), apiResponseObject.getJSONObject("MetaData").getString("CreateTime")); Assert.assertEquals(esbResponseObject.getString("domain"), apiResponseObject.getString("domain")); Assert.assertEquals(esbResponseObject.getString("SyncToken"), apiResponseObject.getString("SyncToken")); Assert.assertEquals(esbResponseObject.getString("PrivateNote"), apiResponseObject.getString("PrivateNote")); Assert.assertEquals(esbResponseObject.getString("sparse"), apiResponseObject.getString("sparse")); }
From source file:networkedassets.Bamboo.java
public void fetchBamboo() throws IOException { JSONObject resp = Useful.readJsonFromUrl( String.format("%sbamboo/rest/api/latest/result/%s.json?expand=results.result&os_authType=basic", bambooUrl, bambooKey), bambooUser, bambooPass);//from ww w .j av a2 s . com int next_temp = nextBuildNumber; if (resp.getJSONObject("results").getInt("size") > 0) { lastResponse = resp.getJSONObject("results").getJSONArray("result").getJSONObject(0); nextBuildNumber = lastResponse.getInt("buildNumber") + 1; } else nextBuildNumber = 1; boolean build = fetchNextBuild(); if (build) for (BambooInterface in : listeners) in.projectIsBuilding(); else if (nextBuildNumber != next_temp) for (BambooInterface in : listeners) in.projectChanged(lastResponse); }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test createEntry method with Optional Parameters. *///from w ww . j av a2s .c o m @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateDiscussionTopicWithOptionalParameters" }, description = "Canvas {createEntry} integration test with optional parameters.") public void testCreateEntryWithOptionalParameters() throws IOException, JSONException { headersMap.put("Action", "urn:createEntry"); final String requestString = proxyUrl + "?courseId=" + connectorProperties.getProperty("courseId") + "&topicId=" + connectorProperties.getProperty("topicId") + "&apiUrl=" + connectorProperties.getProperty("apiUrl") + "&accessToken=" + connectorProperties.getProperty("accessToken"); MultipartFormdataProcessor multipartProcessor = new MultipartFormdataProcessor(requestString, headersMap); File file = new File(pathToResourcesDirectory + connectorProperties.getProperty("attachmentFileName")); multipartProcessor.addFileToRequest("attachment", file, URLConnection.guessContentTypeFromName(file.getName())); multipartProcessor.addFormDataToRequest("message", connectorProperties.getProperty("entryMessage")); RestResponse<JSONObject> esbRestResponse = multipartProcessor.processForJsonResponse(); String entryId = esbRestResponse.getBody().getString("id"); final String apiUrl = connectorProperties.getProperty("apiUrl") + "/api/v1/courses/" + connectorProperties.getProperty("courseId") + "/discussion_topics/" + connectorProperties.getProperty("topicId") + "/entry_list?ids[]=" + entryId; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiUrl, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); JSONObject apiFirstElement = apiResponseArray.getJSONObject(0); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Assert.assertEquals(connectorProperties.getProperty("entryMessage"), apiFirstElement.getString("message")); Assert.assertEquals(connectorProperties.getProperty("attachmentFileName"), apiFirstElement.getJSONObject("attachment").getString("filename")); Assert.assertEquals(apiFirstElement.getString("created_at").split("T")[0], sdf.format(new Date())); }
From source file:org.wso2.carbon.am.tests.rest.RestPeopleTestCase.java
@Test(groups = { "wso2.am" }, description = "Send request to rest backend service", dependsOnMethods = "addAPITestCase") public void invokeAPI() throws Exception { // publishing APILifeCycleStateRequest updateRequest = new APILifeCycleStateRequest(APIName, providerName, APILifeCycleState.PUBLISHED); apiPublisher.changeAPILifeCycleStatusTo(updateRequest); // create new application and subscribing apiStore.login(userName, password);// w ww. ja va 2 s .c om String appName = "NewApplication"; apiStore.addApplication(appName, "Unlimited", "some_url", "NewApp"); SubscriptionRequest subscriptionRequest = new SubscriptionRequest(APIName, providerName); subscriptionRequest.setApplicationName(appName); apiStore.subscribe(subscriptionRequest); //generate access token GenerateAppKeyRequest generateAppKeyRequest = new GenerateAppKeyRequest(appName); String responseString = apiStore.generateApplicationKey(generateAppKeyRequest).getData(); JSONObject response = new JSONObject(responseString); String accessToken = response.getJSONObject("data").getJSONObject("key").get("accessToken").toString(); Map<String, String> requestHeaders = new HashMap<String, String>(); requestHeaders.put("Authorization", "Bearer " + accessToken); Thread.sleep(2000); // invoke backend-service through api mgr assertTrue(HttpRequestUtil.doGet(apiInvocationURL + File.separator + "customers/123/", requestHeaders) .getResponseCode() == 200); assertTrue(HttpRequestUtil.doGet(apiInvocationURL + File.separator + "customers/123/", requestHeaders) .getData().contains("John")); }
From source file:org.zaizi.sensefy.api.utils.JSONHelper.java
public static Map<String, Object> getMap(JSONObject object, String key) throws JSONException { return toMap(object.getJSONObject(key)); }
From source file:com.nginious.http.application.Http11SerializerTestCase.java
private void testResponse(String body) throws Exception { JSONObject bean = new JSONObject(body); assertTrue(bean.has("testBean1")); bean = bean.getJSONObject("testBean1"); assertEquals(true, bean.getBoolean("first")); assertEquals(1.1d, bean.getDouble("second")); assertEquals(1.2f, (float) bean.getDouble("third")); assertEquals(2, bean.getInt("fourth")); assertEquals(5L, bean.getLong("fifth")); assertEquals((short) 3, (short) bean.getInt("sixth")); assertEquals("Seven", bean.getString("seventh")); assertTrue(bean.has("eight")); assertTrue(bean.has("ninth")); }
From source file:net.cellcloud.talk.HttpSpeaker.java
private void doDialogue(JSONObject data) throws JSONException { String identifier = data.getString(HttpDialogueHandler.Identifier); JSONObject primData = data.getJSONObject(HttpDialogueHandler.Primitive); // ?/*from w ww .j a va2 s. c o m*/ Primitive primitive = new Primitive(this.remoteTag); primitive.setCelletIdentifier(identifier); PrimitiveSerializer.read(primitive, primData); this.fireDialogue(identifier, primitive); }