Search in sources :

Example 21 with JsonObject

use of javax.json.JsonObject in project azure-iot-sdk-java by Azure.

the class ToolsTest method getValueFromJsonObject_input_key_null.

// Tests_SRS_SERVICE_SDK_JAVA_TOOLS_12_010: [The function shall return empty string if any of the input is null]
@Test
public void getValueFromJsonObject_input_key_null() {
    // Arrange
    String jsonString = "{\"deviceId\":\"xxx-device\",\"generationId\":\"111111111111111111\",\"etag\":\"MA==\",\"connectionState\":\"Disconnected\",\"status\":\"disabled\",\"statusReason\":null,\"connectionStateUpdatedTime\":\"0001-01-01T00:00:00\",\"statusUpdatedTime\":\"0001-01-01T00:00:00\",\"lastActivityTime\":\"0001-01-01T00:00:00\",\"cloudToDeviceMessageCount\":0,\"authentication\":{\"symmetricKey\":{\"primaryKey\":\"AAABBBCCC111222333444000\",\"secondaryKey\":\"111222333444555AAABBBCCC\"}}}";
    StringReader stringReader = new StringReader(jsonString);
    JsonReader jsonReader = Json.createReader(stringReader);
    JsonObject jsonObject = jsonReader.readObject();
    String key = null;
    String expResult = "";
    // Act
    String result = Tools.getValueFromJsonObject(jsonObject, key);
    // Assert
    assertEquals(expResult, result);
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 22 with JsonObject

use of javax.json.JsonObject in project azure-iot-sdk-java by Azure.

the class ToolsTest method getNumberValueFromJsonObject_input_object_null.

// Tests_SRS_SERVICE_SDK_JAVA_TOOLS_12_018: [The function shall return zero if any of the input is null]
@Test
public void getNumberValueFromJsonObject_input_object_null() {
    // Arrange
    String jsonString = "{\"deviceId\":\"xxx-device\",\"generationId\":\"111111111111111111\",\"etag\":\"MA==\",\"connectionState\":\"Disconnected\",\"status\":\"disabled\",\"statusReason\":null,\"connectionStateUpdatedTime\":\"0001-01-01T00:00:00\",\"statusUpdatedTime\":\"0001-01-01T00:00:00\",\"lastActivityTime\":\"0001-01-01T00:00:00\",\"cloudToDeviceMessageCount\":0,\"authentication\":{\"symmetricKey\":{\"primaryKey\":\"AAABBBCCC111222333444000\",\"secondaryKey\":\"111222333444555AAABBBCCC\"}}}";
    StringReader stringReader = new StringReader(jsonString);
    JsonReader jsonReader = Json.createReader(stringReader);
    JsonObject jsonObject = jsonReader.readObject();
    String key = "";
    long expResult = 0;
    // Act
    long result = Tools.getNumberValueFromJsonObject(null, key);
    // Assert
    assertEquals(expResult, result);
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 23 with JsonObject

use of javax.json.JsonObject in project azure-iot-sdk-java by Azure.

the class ToolsTest method getNumberValueFromJsonObject_jsonvalue_null.

// Tests_SRS_SERVICE_SDK_JAVA_TOOLS_12_019: [The function shall get the JsonValue of the key and return zero if it is null]
// Tests_SRS_SERVICE_SDK_JAVA_TOOLS_12_020: [The function shall get the JsonNumber from the JsonValue and return zero if it is null]
// Tests_SRS_SERVICE_SDK_JAVA_TOOLS_12_020: [The function shall get the JsonNumber from the JsonValue and return zero if it is null]
@Test
public void getNumberValueFromJsonObject_jsonvalue_null() {
    // Arrange
    String jsonString = "{\"deviceId\":\"xxx-device\",\"generationId\":null,\"etag\":\"MA==\",\"connectionState\":\"Disconnected\",\"status\":\"disabled\",\"statusReason\":null,\"connectionStateUpdatedTime\":\"0001-01-01T00:00:00\",\"statusUpdatedTime\":\"0001-01-01T00:00:00\",\"lastActivityTime\":\"0001-01-01T00:00:00\",\"cloudToDeviceMessageCount\":0,\"authentication\":{\"symmetricKey\":{\"primaryKey\":\"AAABBBCCC111222333444000\",\"secondaryKey\":\"111222333444555AAABBBCCC\"}}}";
    StringReader stringReader = new StringReader(jsonString);
    JsonReader jsonReader = Json.createReader(stringReader);
    JsonObject jsonObject = jsonReader.readObject();
    String key = "generationId";
    long expResult = 0;
    // Act
    long result = Tools.getNumberValueFromJsonObject(jsonObject, key);
    // Assert
    assertEquals(expResult, result);
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 24 with JsonObject

use of javax.json.JsonObject in project drill by apache.

the class ProfileParser method parseFragProfiles.

private void parseFragProfiles() {
    JsonArray frags = getFragmentProfile();
    for (JsonObject fragProfile : frags.getValuesAs(JsonObject.class)) {
        int mId = fragProfile.getInt("majorFragmentId");
        FragInfo major = fragments.get(mId);
        major.parse(fragProfile);
    }
}
Also used : JsonArray(javax.json.JsonArray) JsonObject(javax.json.JsonObject)

Example 25 with JsonObject

use of javax.json.JsonObject in project drill by apache.

the class ProfileParser method getOpInfo.

/**
   * We often run test queries single threaded to make analysis of the profile
   * easier. For a single-threaded (single slice) query, get a map from
   * operator ID to operator information as preparation for additional
   * analysis.
   *
   * @return
   */
public Map<Integer, OperatorProfile> getOpInfo() {
    Map<Integer, String> ops = getOperators();
    Map<Integer, OperatorProfile> info = new HashMap<>();
    JsonArray frags = getFragmentProfile();
    JsonObject fragProfile = frags.getJsonObject(0).getJsonArray("minorFragmentProfile").getJsonObject(0);
    JsonArray opList = fragProfile.getJsonArray("operatorProfile");
    for (JsonObject opProfile : opList.getValuesAs(JsonObject.class)) {
        parseOpProfile(ops, info, opProfile);
    }
    return info;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject)

Aggregations

JsonObject (javax.json.JsonObject)214 Test (org.junit.Test)101 JsonArray (javax.json.JsonArray)58 StringReader (java.io.StringReader)52 Credentials (org.apache.commons.httpclient.Credentials)52 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)52 ArrayList (java.util.ArrayList)51 HashMap (java.util.HashMap)47 NameValuePair (org.apache.commons.httpclient.NameValuePair)43 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)41 JsonString (javax.json.JsonString)31 JsonReader (javax.json.JsonReader)25 HashSet (java.util.HashSet)16 Map (java.util.Map)12 Response (javax.ws.rs.core.Response)12 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 NameValuePairList (org.apache.sling.commons.testing.integration.NameValuePairList)11 StringWriter (java.io.StringWriter)10 JsonException (javax.json.JsonException)10 JsonArrayBuilder (javax.json.JsonArrayBuilder)9