diff options
Diffstat (limited to 'android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java')
-rw-r--r-- | android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java index aa7967c2a..d31ff4464 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java @@ -8,15 +8,22 @@ import com.smartdevicelink.proxy.rpc.Image; import com.smartdevicelink.proxy.rpc.MenuParams; import com.smartdevicelink.test.BaseRpcTests; import com.smartdevicelink.test.JsonUtils; -import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.TestValues; import com.smartdevicelink.test.Validator; import com.smartdevicelink.test.json.rpc.JsonFileReader; import org.json.JSONException; import org.json.JSONObject; +import org.junit.Test; import java.util.Hashtable; import java.util.List; +import static android.support.test.InstrumentationRegistry.getTargetContext; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertTrue; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertNull; /** * This is a unit test class for the SmartDeviceLink library project class : @@ -28,10 +35,10 @@ public class AddCommandTests extends BaseRpcTests{ protected RPCMessage createMessage(){ AddCommand msg = new AddCommand(); - msg.setCmdIcon(Test.GENERAL_IMAGE); - msg.setMenuParams(Test.GENERAL_MENUPARAMS); - msg.setVrCommands(Test.GENERAL_STRING_LIST); - msg.setCmdID(Test.GENERAL_INT); + msg.setCmdIcon(TestValues.GENERAL_IMAGE); + msg.setMenuParams(TestValues.GENERAL_MENUPARAMS); + msg.setVrCommands(TestValues.GENERAL_STRING_LIST); + msg.setCmdID(TestValues.GENERAL_INT); return msg; } @@ -51,12 +58,12 @@ public class AddCommandTests extends BaseRpcTests{ JSONObject result = new JSONObject(); try{ - result.put(AddCommand.KEY_CMD_ICON, Test.JSON_IMAGE); - result.put(AddCommand.KEY_MENU_PARAMS, Test.JSON_MENUPARAMS); - result.put(AddCommand.KEY_VR_COMMANDS, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); - result.put(AddCommand.KEY_CMD_ID, Test.GENERAL_INT); + result.put(AddCommand.KEY_CMD_ICON, TestValues.JSON_IMAGE); + result.put(AddCommand.KEY_MENU_PARAMS, TestValues.JSON_MENUPARAMS); + result.put(AddCommand.KEY_VR_COMMANDS, JsonUtils.createJsonArray(TestValues.GENERAL_STRING_LIST)); + result.put(AddCommand.KEY_CMD_ID, TestValues.GENERAL_INT); }catch(JSONException e){ - fail(Test.JSON_FAIL); + fail(TestValues.JSON_FAIL); } return result; @@ -65,6 +72,7 @@ public class AddCommandTests extends BaseRpcTests{ /** * Tests the expected values of the RPC message. */ + @Test public void testRpcValues () { // Test Values int testCmdId = ( (AddCommand) msg ).getCmdID(); @@ -73,62 +81,63 @@ public class AddCommandTests extends BaseRpcTests{ List<String> testVrCommands = ( (AddCommand) msg ).getVrCommands(); // Valid Tests - assertNotNull(Test.NOT_NULL, testMenuParams); - assertNotNull(Test.NOT_NULL, testImage); - assertNotNull(Test.NOT_NULL, testVrCommands); + assertNotNull(TestValues.NOT_NULL, testMenuParams); + assertNotNull(TestValues.NOT_NULL, testImage); + assertNotNull(TestValues.NOT_NULL, testVrCommands); - assertEquals(Test.MATCH, Test.GENERAL_INT, testCmdId); - assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), testVrCommands.size()); + assertEquals(TestValues.MATCH, TestValues.GENERAL_INT, testCmdId); + assertEquals(TestValues.MATCH, TestValues.GENERAL_STRING_LIST.size(), testVrCommands.size()); - assertTrue(Test.TRUE, Validator.validateMenuParams(Test.GENERAL_MENUPARAMS, testMenuParams)); - assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, testImage)); - assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, testVrCommands)); + assertTrue(TestValues.TRUE, Validator.validateMenuParams(TestValues.GENERAL_MENUPARAMS, testMenuParams)); + assertTrue(TestValues.TRUE, Validator.validateImage(TestValues.GENERAL_IMAGE, testImage)); + assertTrue(TestValues.TRUE, Validator.validateStringList(TestValues.GENERAL_STRING_LIST, testVrCommands)); // Invalid/Null Tests AddCommand msg = new AddCommand(); - assertNotNull(Test.NULL, msg); + assertNotNull(TestValues.NULL, msg); testNullBase(msg); - assertNull(Test.NULL, msg.getCmdIcon()); - assertNull(Test.NULL, msg.getCmdID()); - assertNull(Test.NULL, msg.getMenuParams()); - assertNull(Test.NULL, msg.getVrCommands()); + assertNull(TestValues.NULL, msg.getCmdIcon()); + assertNull(TestValues.NULL, msg.getCmdID()); + assertNull(TestValues.NULL, msg.getMenuParams()); + assertNull(TestValues.NULL, msg.getVrCommands()); } /** * Tests a valid JSON construction of this RPC message. */ + @Test public void testJsonConstructor () { - JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); - assertNotNull(Test.NOT_NULL, commandJson); + JSONObject commandJson = JsonFileReader.readId(getTargetContext(), getCommandType(), getMessageType()); + assertNotNull(TestValues.NOT_NULL, commandJson); try { Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); AddCommand cmd = new AddCommand(hash); JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); - assertNotNull(Test.NOT_NULL, body); + assertNotNull(TestValues.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()); + assertEquals(TestValues.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(TestValues.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); List<String> vrCommandsList = JsonUtils.readStringListFromJsonObject(parameters, AddCommand.KEY_VR_COMMANDS); List<String> testCommandsList = cmd.getVrCommands(); - assertEquals(Test.MATCH, vrCommandsList.size(), testCommandsList.size()); - assertTrue(Test.TRUE, Validator.validateStringList(vrCommandsList, testCommandsList)); + assertEquals(TestValues.MATCH, vrCommandsList.size(), testCommandsList.size()); + assertTrue(TestValues.TRUE, Validator.validateStringList(vrCommandsList, testCommandsList)); - assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AddCommand.KEY_CMD_ID), cmd.getCmdID()); + assertEquals(TestValues.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AddCommand.KEY_CMD_ID), cmd.getCmdID()); JSONObject menuParams = JsonUtils.readJsonObjectFromJsonObject(parameters, AddCommand.KEY_MENU_PARAMS); MenuParams referenceMenuParams = new MenuParams(JsonRPCMarshaller.deserializeJSONObject(menuParams)); - assertTrue(Test.TRUE, Validator.validateMenuParams(referenceMenuParams, cmd.getMenuParams())); + assertTrue(TestValues.TRUE, Validator.validateMenuParams(referenceMenuParams, cmd.getMenuParams())); JSONObject cmdIcon = JsonUtils.readJsonObjectFromJsonObject(parameters, AddCommand.KEY_CMD_ICON); Image referenceCmdIcon = new Image(JsonRPCMarshaller.deserializeJSONObject(cmdIcon)); - assertTrue(Test.TRUE, Validator.validateImage(referenceCmdIcon, cmd.getCmdIcon())); + assertTrue(TestValues.TRUE, Validator.validateImage(referenceCmdIcon, cmd.getCmdIcon())); } catch (JSONException e) { e.printStackTrace(); |