Search in sources :

Example 16 with JSONObject

use of org.json.JSONObject in project spring-boot-admin by codecentric.

the class ApplicationTest method test_1_5_json_format.

@Test
public void test_1_5_json_format() throws Exception {
    String json = new JSONObject().put("name", "test").put("managementUrl", "http://test").put("healthUrl", "http://health").put("serviceUrl", "http://service").put("metadata", new JSONObject().put("labels", "foo,bar")).toString();
    Application value = objectMapper.readValue(json, Application.class);
    assertThat(value.getName(), is("test"));
    assertThat(value.getManagementUrl(), is("http://test"));
    assertThat(value.getHealthUrl(), is("http://health"));
    assertThat(value.getServiceUrl(), is("http://service"));
    assertThat(value.getMetadata(), is(Collections.singletonMap("labels", "foo,bar")));
}
Also used : JSONObject(org.json.JSONObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 17 with JSONObject

use of org.json.JSONObject in project spring-boot-admin by codecentric.

the class ApplicationTest method test_healthUrl_expected.

@Test(expected = IllegalArgumentException.class)
public void test_healthUrl_expected() throws Exception {
    String json = new JSONObject().put("name", "test").put("managementUrl", "http://test").put("healthUrl", "").put("serviceUrl", "http://service").toString();
    objectMapper.readValue(json, Application.class);
}
Also used : JSONObject(org.json.JSONObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 18 with JSONObject

use of org.json.JSONObject in project spring-boot-admin by codecentric.

the class ApplicationTest method test_1_4_json_format.

@Test
public void test_1_4_json_format() throws Exception {
    String json = new JSONObject().put("name", "test").put("managementUrl", "http://test").put("healthUrl", "http://health").put("serviceUrl", "http://service").put("statusInfo", new JSONObject().put("status", "UNKNOWN")).toString();
    Application value = objectMapper.readValue(json, Application.class);
    assertThat(value.getName(), is("test"));
    assertThat(value.getManagementUrl(), is("http://test"));
    assertThat(value.getHealthUrl(), is("http://health"));
    assertThat(value.getServiceUrl(), is("http://service"));
}
Also used : JSONObject(org.json.JSONObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 19 with JSONObject

use of org.json.JSONObject in project coinbase-bitmonet-sdk by coinbase.

the class JSONUtils method extractIntValueFromJSONResponse.

public static int extractIntValueFromJSONResponse(HttpResponse response, String key) throws JSONException, IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String json = reader.readLine();
    // Extract access token, refresh token and the refresh time
    JSONObject jObject = new JSONObject(json);
    try {
        return jObject.getInt(key);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    UserProfileSettings.getInstance().saveCoinbaseOAuthStatus(false);
    return -1;
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.JSONObject) BufferedReader(java.io.BufferedReader) JSONException(org.json.JSONException)

Example 20 with JSONObject

use of org.json.JSONObject in project coinbase-bitmonet-sdk by coinbase.

the class OAuthHelperUtils method extractOAuthParamatersFromJSON.

private void extractOAuthParamatersFromJSON(HttpResponse response) throws JSONException, IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String json = reader.readLine();
    // Extract access token, refresh token and the refresh time
    JSONObject jObject = new JSONObject(json);
    try {
        UserProfileSettings.getInstance().saveAccessToken(jObject.getString(Constants.ACCESS_TOKEN));
        UserProfileSettings.getInstance().saveRefreshToken(jObject.getString(Constants.REFRESH_TOKEN));
        UserProfileSettings.getInstance().saveRefreshTime(jObject.getInt(Constants.ACCESS_TOKEN_EXPIRY_TIME));
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.JSONObject) BufferedReader(java.io.BufferedReader) JSONException(org.json.JSONException)

Aggregations

JSONObject (org.json.JSONObject)3855 JSONException (org.json.JSONException)1520 JSONArray (org.json.JSONArray)1084 Test (org.junit.Test)494 IOException (java.io.IOException)425 ArrayList (java.util.ArrayList)375 HashMap (java.util.HashMap)282 Test (org.testng.annotations.Test)173 File (java.io.File)137 Date (java.util.Date)137 ServiceException (org.b3log.latke.service.ServiceException)125 VolleyError (com.android.volley.VolleyError)103 Bundle (android.os.Bundle)102 Map (java.util.Map)95 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)92 InputStreamReader (java.io.InputStreamReader)84 Response (com.android.volley.Response)83 BufferedReader (java.io.BufferedReader)83 List (java.util.List)76 InputStream (java.io.InputStream)70