List of usage examples for org.json JSONArray getJSONObject
public JSONObject getJSONObject(int index) throws JSONException
From source file:com.example.klaudia.myapplication.Searcher.java
public HashMap<String, Bitmap> getRecipesTitlesmagesFromArray(JSONArray array) { HashMap<String, Bitmap> result = new HashMap<String, Bitmap>(); try {//from w ww. j av a 2 s . c om for (int i = 0; i < array.length(); i++) { JSONObject recipe = array.getJSONObject(i); String title = recipe.getString("title"); Bitmap tmp = new DownloadImageTask().execute(recipe.getString("image")).get(); Bitmap scaled = Bitmap.createScaledBitmap(tmp, 50, 50, true); result.put(title, scaled); } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
private void setCanvasAccoutId() throws IOException, JSONException { String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/course_accounts"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); String accountId = apiResponseArray.getJSONObject(0).getString("id"); connectorProperties.put("accountId", accountId); }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCourses method with Mandatory Parameters. */// w w w.j av a 2 s .com @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateCourseWithMandatoryParameters", "testCreateCourseWithOptionalParameters" }, description = "canvas {listCourses} integration test with mandatory parameters.") public void testListCoursesWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCourses"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCourses_mandatory.json"); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/courses"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(esbResponseArray.length(), apiResponseArray.length()); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("id"), apiResponseArray.getJSONObject(0).getString("id")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("name"), apiResponseArray.getJSONObject(0).getString("name")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("course_code"), apiResponseArray.getJSONObject(0).getString("course_code")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("start_at"), apiResponseArray.getJSONObject(0).getString("start_at")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("end_at"), apiResponseArray.getJSONObject(0).getString("end_at")); }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCourses method with Optional Parameters. *//*ww w.ja v a 2s. c o m*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateCourseWithMandatoryParameters", "testCreateCourseWithOptionalParameters" }, description = "canvas {listCourses} integration test with optional parameters.") public void testListCoursesWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCourses"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCourses_optional.json"); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/courses" + "?include[]=term&include[]=sections"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(esbResponseArray.length(), apiResponseArray.length()); // Term details Assert.assertEquals(esbResponseArray.getJSONObject(0).getJSONObject("term").getString("id"), apiResponseArray.getJSONObject(0).getJSONObject("term").getString("id")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getJSONObject("term").getString("name"), apiResponseArray.getJSONObject(0).getJSONObject("term").getString("name")); // Section details Assert.assertEquals( esbResponseArray.getJSONObject(0).getJSONArray("sections").getJSONObject(0).getString("id"), apiResponseArray.getJSONObject(0).getJSONArray("sections").getJSONObject(0).getString("id")); Assert.assertEquals( esbResponseArray.getJSONObject(0).getJSONArray("sections").getJSONObject(0).getString("name"), apiResponseArray.getJSONObject(0).getJSONArray("sections").getJSONObject(0).getString("name")); }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCourseUsers method with Mandatory Parameters. *//* w ww . j av a2 s . c o m*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateCourseWithMandatoryParameters" }, description = "canvas {listCourseUsers} integration test with mandatory parameters.") public void testListCourseUsersWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCourseUsers"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCourseUsers_mandatory.json"); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); connectorProperties.put("userId", esbResponseArray.getJSONObject(0).getString("id")); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/courses/" + connectorProperties.getProperty("courseId") + "/users"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(esbResponseArray.length(), apiResponseArray.length()); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("id"), apiResponseArray.getJSONObject(0).getString("id")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("name"), apiResponseArray.getJSONObject(0).getString("name")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("sortable_name"), apiResponseArray.getJSONObject(0).getString("sortable_name")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("login_id"), apiResponseArray.getJSONObject(0).getString("login_id")); }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCourseUsers method with Optional Parameters. *//*from www . j ava 2s .c o m*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateCourseWithOptionalParameters" }, description = "canvas {listCourseUsers} integration test with optional parameters.") public void testListCourseUsersWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCourseUsers"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCourseUsers_optional.json"); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/courses/" + connectorProperties.getProperty("courseIdOptional") + "/users" + "?include[]=email&include[]=enrollments"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(esbResponseArray.length(), apiResponseArray.length()); // ID and Email details Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("id"), apiResponseArray.getJSONObject(0).getString("id")); Assert.assertEquals(esbResponseArray.getJSONObject(0).getString("email"), apiResponseArray.getJSONObject(0).getString("email")); // Enrollment details Assert.assertEquals( esbResponseArray.getJSONObject(0).getJSONArray("enrollments").getJSONObject(0).getString("role"), apiResponseArray.getJSONObject(0).getJSONArray("enrollments").getJSONObject(0).getString("role")); Assert.assertEquals( esbResponseArray.getJSONObject(0).getJSONArray("enrollments").getJSONObject(0) .getString("course_id"), apiResponseArray.getJSONObject(0).getJSONArray("enrollments").getJSONObject(0) .getString("course_id")); }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCalendarEvents method with Mandatory Parameters. *//* w w w . ja v a2s . co m*/ @Test(priority = 1, dependsOnMethods = { "testCreateCalendarEventWithMandatoryParameters" }, description = "Canvas {listCalendarEvents} integration test with mandatory parameters.") public void testListCalendarEventsWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCalendarEvents"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCalendarEvents_mandatory.json"); final String apiUrl = connectorProperties.getProperty("apiUrl") + "/api/v1/calendar_events?start_date=" + connectorProperties.getProperty("calenderEventStartDate") + "T00:00:00Z"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiUrl, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("title"), esbFirstResult.getString("title")); Assert.assertEquals(apiFirstResult.getString("context_code"), esbFirstResult.getString("context_code")); } }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCalendarEvents method with Optional Parameters. *///w w w . j a v a 2 s. co m @Test(priority = 1, dependsOnMethods = { "testCreateCalendarEventWithMandatoryParameters" }, description = "Canvas {listCalendarEvents} integration test with optional parameters.") public void testListCalendarEventsWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCalendarEvents"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCalendarEvents_optional.json"); final String apiUrl = connectorProperties.getProperty("apiUrl") + "/api/v1/calendar_events?all_events=true&per_page=4&start_date=" + connectorProperties.getProperty("calenderEventStartDate") + "T00:00:00Z"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiUrl, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("title"), esbFirstResult.getString("title")); Assert.assertEquals(apiFirstResult.getString("context_code"), esbFirstResult.getString("context_code")); } }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test search method with Optional Parameters. *//*from w w w . ja v a 2 s.c om*/ @Test(priority = 1, dependsOnMethods = { "testCreateCalendarEventWithMandatoryParameters" }, description = "Canvas {search} integration test with optional parameters.") public void testSearchWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:search"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_search_optional.json"); final String apiUrl = connectorProperties.getProperty("apiUrl") + "/api/v1/search/recipients?context=" + connectorProperties.getProperty("contextCode"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiUrl, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("name"), esbFirstResult.getString("name")); Assert.assertEquals(apiFirstResult.getString("avatar_url"), esbFirstResult.getString("avatar_url")); } }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Positive test case for listDiscussionTopics method with mandatory parameters. *//* w ww . j a v a 2 s. c om*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateCourseWithMandatoryParameters" }, description = "Canvas {listDiscussionTopics} integration test with mandatory parameters.") public void testListDiscussionTopicsWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listDiscussionTopics"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listDiscussionTopics_mandatory.json"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/courses/" + connectorProperties.getProperty("courseId") + "/discussion_topics"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("title"), esbFirstResult.getString("title")); Assert.assertEquals(apiFirstResult.getString("message"), esbFirstResult.getString("message")); } }