Search in sources :

Example 1 with MethodParser

use of com.microsoft.azure.sdk.iot.deps.serializer.MethodParser in project azure-iot-sdk-java by Azure.

the class MethodParserTest method fromJson_response_succeed.

/* Tests_SRS_METHODPARSER_21_006: [The fromJson shall parse the json and fill the method collection.] */
/* Tests_SRS_METHODPARSER_21_007: [The json can contain values `null`, `"null"`, and `""`, which represents null, the string null, and empty string respectively.] */
/**
     * Tests_SRS_METHODPARSER_21_011: [If the json contains the `status` identification, the fromJson shall parse both status and payload, and set the operation as `response`.]
     *  Ex:
     *  {
     *      "status": 201,
     *      "payload": {"AnyValidPayload" : "" }
     *  }
     */
@Test
public void fromJson_response_succeed() {
    // Arrange
    MethodParser methodParser = new MethodParser();
    for (TestMethod testCase : successTestResult) {
        // Act
        methodParser.fromJson(testCase.jsonResult);
        // Assert
        assertMethod(methodParser, null, null, null, testCase.status, testCase.payload, "response");
    }
}
Also used : MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) Test(org.junit.Test)

Example 2 with MethodParser

use of com.microsoft.azure.sdk.iot.deps.serializer.MethodParser in project azure-iot-sdk-java by Azure.

the class MethodParserTest method getResults_succeed.

/* Tests_SRS_METHODPARSER_21_012: [The getStatus shall return an Integer with the status in the parsed json.] */
/* Tests_SRS_METHODPARSER_21_013: [The getPayload shall return an Object with the Payload in the parsed json.] */
@Test
public void getResults_succeed() {
    // Arrange
    MethodParser methodParser = new MethodParser();
    methodParser.fromJson("{\"status\":201,\"payload\":{\"myPar1\":\"myVal1\",\"myPar2\":\"myVal2\"}}");
    // Act
    // Assert
    assertEquals(methodParser.getStatus(), (Integer) 201);
    assertEquals(methodParser.getPayload(), STANDARD_PAYLOAD);
}
Also used : MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) Test(org.junit.Test)

Example 3 with MethodParser

use of com.microsoft.azure.sdk.iot.deps.serializer.MethodParser in project azure-iot-sdk-java by Azure.

the class MethodParserTest method toJson_response_succeed.

/* Tests_SRS_METHODPARSER_21_024: [The class toJson include status as `status` in the json.] */
/* Tests_SRS_METHODPARSER_21_025: [If the status is null, the toJson shall include `status` as `null`.] */
/**
     * Tests_SRS_METHODPARSER_21_027: [If the method operation is `response`, the toJson shall parse both status and payload.]
     *  Ex:
     *  {
     *      "status": 201,
     *      "payload": {"AnyValidPayload" : "" }
     *  }
     */
@Test
public void toJson_response_succeed() {
    // Arrange
    MethodParser methodParser = new MethodParser();
    for (TestMethod testCase : successTestResult) {
        // Arrange
        methodParser.fromJson(testCase.jsonResult);
        // Act
        String json = methodParser.toJson();
        // Assert
        Helpers.assertJson(json, testCase.jsonResult);
    }
}
Also used : MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) Test(org.junit.Test)

Example 4 with MethodParser

use of com.microsoft.azure.sdk.iot.deps.serializer.MethodParser in project azure-iot-sdk-java by Azure.

the class MethodParserTest method getResults_failed.

/* Tests_SRS_METHODPARSER_21_035: [If the operation is not `response`, the getStatus shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void getResults_failed() {
    // Arrange
    MethodParser methodParser = new MethodParser();
    // Act
    methodParser.getStatus();
}
Also used : MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) Test(org.junit.Test)

Example 5 with MethodParser

use of com.microsoft.azure.sdk.iot.deps.serializer.MethodParser in project azure-iot-sdk-java by Azure.

the class MethodParserTest method toJson_Method_succeed.

/* Tests_SRS_METHODPARSER_21_014: [The toJson shall create a String with the full information in the method collection using json format.] */
/* Tests_SRS_METHODPARSER_21_015: [The toJson shall include name as `methodName` in the json.] */
/* Tests_SRS_METHODPARSER_21_016: [The toJson shall include responseTimeout in seconds as `responseTimeoutInSeconds` in the json.] */
/* Tests_SRS_METHODPARSER_21_017: [If the responseTimeout is null, the toJson shall not include the `responseTimeoutInSeconds` in the json.] */
/* Tests_SRS_METHODPARSER_21_031: [The toJson shall include connectTimeout in seconds as `connectTimeoutInSeconds` in the json.] */
/* Tests_SRS_METHODPARSER_21_032: [If the connectTimeout is null, the toJson shall not include the `connectTimeoutInSeconds` in the json.] */
/* Tests_SRS_METHODPARSER_21_018: [The class toJson include payload as `payload` in the json.] */
/* Tests_SRS_METHODPARSER_21_019: [If the payload is null, the toJson shall include `payload` with value `null`.] */
/**
     *  Tests_SRS_METHODPARSER_21_026: [If the method operation is `invoke`, the toJson shall include the full method information in the json.]
     *  Ex:
     *  {
     *      "methodName": "reboot",
     *      "responseTimeoutInSeconds": 200,
     *      "connectTimeoutInSeconds": 5,
     *      "payload":
     *      {
     *          "input1": "someInput",
     *          "input2": "anotherInput"
     *      }
     *  }
     */
@Test
public void toJson_Method_succeed() {
    for (TestMethod testCase : successTestMethod) {
        // Arrange
        MethodParser methodParser = new MethodParser(testCase.name, testCase.responseTimeout, testCase.connectTimeout, testCase.payload);
        // Act
        String json = methodParser.toJson();
        // Assert
        Helpers.assertJson(json, testCase.json);
    }
}
Also used : MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) Test(org.junit.Test)

Aggregations

MethodParser (com.microsoft.azure.sdk.iot.deps.serializer.MethodParser)13 Test (org.junit.Test)12 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 HttpResponse (com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse)1 URL (java.net.URL)1