summaryrefslogtreecommitdiff
path: root/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java
diff options
context:
space:
mode:
authorBilal Alsharifi <bilal.alsharifi@gmail.com>2019-03-04 11:54:25 -0500
committerBilal Alsharifi <bilal.alsharifi@gmail.com>2019-03-04 11:54:25 -0500
commit6aa38653411257300a77a885064dc9ddda4cd35f (patch)
tree72ea420e134ca6ef5d0b937a8656ca657055c6b4 /android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java
parente59b00f4443f7d3e90c86bae562cde3decd95127 (diff)
downloadsdl_android-6aa38653411257300a77a885064dc9ddda4cd35f.tar.gz
Move sdl_android to a subfolder
Diffstat (limited to 'android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java')
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java
new file mode 100644
index 000000000..a479da245
--- /dev/null
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java
@@ -0,0 +1,97 @@
+package com.smartdevicelink.test.rpc.responses;
+
+import java.util.Hashtable;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.smartdevicelink.marshal.JsonRPCMarshaller;
+import com.smartdevicelink.protocol.enums.FunctionID;
+import com.smartdevicelink.proxy.RPCMessage;
+import com.smartdevicelink.proxy.rpc.AlertResponse;
+import com.smartdevicelink.test.BaseRpcTests;
+import com.smartdevicelink.test.JsonUtils;
+import com.smartdevicelink.test.Test;
+import com.smartdevicelink.test.json.rpc.JsonFileReader;
+
+/**
+ * This is a unit test class for the SmartDeviceLink library project class :
+ * {@link com.smartdevicelink.rpc.AlertResponse}
+ */
+public class AlertResponseTests extends BaseRpcTests{
+
+ private static final int TRY_AGAIN_TIME = 400;
+
+ @Override
+ protected RPCMessage createMessage(){
+ AlertResponse alert = new AlertResponse();
+ alert.setTryAgainTime(TRY_AGAIN_TIME);
+ return alert;
+ }
+
+ @Override
+ protected String getMessageType(){
+ return RPCMessage.KEY_RESPONSE;
+ }
+
+ @Override
+ protected String getCommandType(){
+ return FunctionID.ALERT.toString();
+ }
+
+ @Override
+ protected JSONObject getExpectedParameters(int sdlVersion){
+ JSONObject result = new JSONObject();
+
+ try{
+ result.put(AlertResponse.KEY_TRY_AGAIN_TIME, TRY_AGAIN_TIME);
+ }catch(JSONException e){
+ fail(Test.JSON_FAIL);
+ }
+
+ return result;
+ }
+
+ /**
+ * Tests the expected values of the RPC message.
+ */
+ public void testRpcValues () {
+ // Test Values
+ int tryAgainTime = ( (AlertResponse) msg ).getTryAgainTime();
+
+ // Valid Tests
+ assertEquals(Test.MATCH, TRY_AGAIN_TIME, tryAgainTime);
+
+ // Invalid/Null Tests
+ AlertResponse msg = new AlertResponse();
+ assertNotNull(Test.NOT_NULL, msg);
+ testNullBase(msg);
+
+ assertNull(Test.NULL, msg.getTryAgainTime());
+ }
+
+ /**
+ * Tests a valid JSON construction of this RPC message.
+ */
+ public void testJsonConstructor () {
+ JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType());
+ assertNotNull(Test.NOT_NULL, commandJson);
+
+ try {
+ Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson);
+ AlertResponse cmd = new AlertResponse(hash);
+ JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType());
+ assertNotNull(Test.NOT_NULL, body);
+
+ // Test everything in the json body.
+ assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName());
+ assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID());
+
+ JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS);
+ assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AlertResponse.KEY_TRY_AGAIN_TIME), cmd.getTryAgainTime());
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+} \ No newline at end of file