diff options
Diffstat (limited to 'SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc')
48 files changed, 7658 insertions, 0 deletions
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AlertTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AlertTest.java new file mode 100644 index 000000000..2f365ea1e --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AlertTest.java @@ -0,0 +1,83 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created by enikolsky on 2013-10-23. + */ +public class AlertTest extends TestCase { + private static final String PROGRESS_INDICATOR = "progressIndicator"; + + public void testSerialization() throws JSONException { + Alert msg = new Alert(); + assertNotNull(msg); + + final boolean progressIndicator = true; + + msg.setProgressIndicator(progressIndicator); + + JSONObject jsonObject = msg.serializeJSON((byte) 2); + assertEquals(1, jsonObject.length()); + assertEquals(progressIndicator, + jsonObject.getBoolean(PROGRESS_INDICATOR)); + } + + public void testNullDeserialization() throws JSONException { + JSONObject jsonObject = new JSONObject(); + Alert msg = new Alert(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertNull(msg.getProgressIndicator()); + } + + public void testProgressIndicatorAPI() { + Alert msg = new Alert(); + + final Boolean progressIndicator = true; + msg.setProgressIndicator(progressIndicator); + + assertEquals(progressIndicator, msg.getProgressIndicator()); + } + + public void testRemoveProgressIndicator() { + Alert msg = new Alert(); + msg.setProgressIndicator(true); + msg.setProgressIndicator(null); + assertNull(msg.getProgressIndicator()); + } + + public void testGetProgressIndicator() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Boolean progressIndicator = true; + jsonObject.put(PROGRESS_INDICATOR, progressIndicator); + + Alert msg = new Alert(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertEquals(progressIndicator, msg.getProgressIndicator()); + } + + public void testGetProgressIndicatorIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(PROGRESS_INDICATOR, 42); + + Alert msg = new Alert(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertNull(msg.getProgressIndicator()); + } + + private JSONObject paramsToRequestObject(JSONObject paramsObject) + throws JSONException { + JSONObject jsonObject = new JSONObject(); + JSONObject requestObject = new JSONObject(); + jsonObject.put("request", requestObject); + requestObject.put("parameters", paramsObject); + return jsonObject; + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AudioPassThruCapabilitiesTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AudioPassThruCapabilitiesTest.java new file mode 100644 index 000000000..5a694684a --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AudioPassThruCapabilitiesTest.java @@ -0,0 +1,195 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.AudioType; +import com.ford.syncV4.proxy.rpc.enums.BitsPerSample; +import com.ford.syncV4.proxy.rpc.enums.SamplingRate; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for AudioPassThruCapabilities struct. + * + * Created by enikolsky on 2014-02-14. + */ +public class AudioPassThruCapabilitiesTest extends TestCase { + private static final String AUDIO_TYPE = "audioType"; + private static final String BITS_PER_SAMPLE = "bitsPerSample"; + private static final String SAMPLING_RATE = "samplingRate"; + + public void testMessageShouldBeCreated() { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + + final SamplingRate samplingRate = SamplingRate._22KHZ; + final BitsPerSample bitsPerSample = BitsPerSample._16_BIT; + final AudioType audioType = AudioType.PCM; + + msg.setSamplingRate(samplingRate); + msg.setBitsPerSample(bitsPerSample); + msg.setAudioType(audioType); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.getString(SAMPLING_RATE), + is(samplingRate.toString())); + assertThat(jsonObject.getString(BITS_PER_SAMPLE), + is(bitsPerSample.toString())); + assertThat(jsonObject.getString(AUDIO_TYPE), is(audioType.toString())); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + AudioPassThruCapabilities msg = new AudioPassThruCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getSamplingRate(), nullValue()); + assertThat(msg.getBitsPerSample(), nullValue()); + assertThat(msg.getAudioType(), nullValue()); + } + + /// samplingRate + public void testSamplingRateGetterShouldReturnSetValue() + throws JSONException { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + + final SamplingRate samplingRate = SamplingRate._22KHZ; + msg.setSamplingRate(samplingRate); + + assertThat(msg.getSamplingRate(), is(samplingRate)); + } + + public void testSettingNullSamplingRateShouldRemoveValue() + throws JSONException { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + + msg.setSamplingRate(SamplingRate._8KHZ); + msg.setSamplingRate(null); + + assertThat(msg.getSamplingRate(), nullValue()); + } + + public void testDeserializedSamplingRateAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final SamplingRate samplingRate = SamplingRate._22KHZ; + jsonObject.put(SAMPLING_RATE, samplingRate.toString()); + + AudioPassThruCapabilities msg = new AudioPassThruCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getSamplingRate(), is(samplingRate)); + } + + public void testDeserializedSamplingRateAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SAMPLING_RATE, 0); + + AudioPassThruCapabilities msg = new AudioPassThruCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getSamplingRate(), nullValue()); + } + + /// bitsPerSample + public void testBitsPerSampleGetterShouldReturnSetValue() + throws JSONException { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + + final BitsPerSample bitsPerSample = BitsPerSample._8_BIT; + msg.setBitsPerSample(bitsPerSample); + + assertThat(msg.getBitsPerSample(), is(bitsPerSample)); + } + + public void testSettingNullBitsPerSampleShouldRemoveValue() + throws JSONException { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + + msg.setBitsPerSample(BitsPerSample._8_BIT); + msg.setBitsPerSample(null); + + assertThat(msg.getBitsPerSample(), nullValue()); + } + + public void testDeserializedBitsPerSampleAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final BitsPerSample bitsPerSample = BitsPerSample._16_BIT; + jsonObject.put(BITS_PER_SAMPLE, bitsPerSample.toString()); + + AudioPassThruCapabilities msg = new AudioPassThruCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getBitsPerSample(), is(bitsPerSample)); + } + + public void testDeserializedBitsPerSampleAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(BITS_PER_SAMPLE, 0); + + AudioPassThruCapabilities msg = new AudioPassThruCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getBitsPerSample(), nullValue()); + } + + /// audioType + public void testAudioTypeGetterShouldReturnSetValue() throws JSONException { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + + final AudioType audioType = AudioType.PCM; + msg.setAudioType(audioType); + + assertThat(msg.getAudioType(), is(audioType)); + } + + public void testSettingNullAudioTypeShouldRemoveValue() + throws JSONException { + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + + msg.setAudioType(AudioType.PCM); + msg.setAudioType(null); + + assertThat(msg.getAudioType(), nullValue()); + } + + public void testDeserializedAudioTypeAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final AudioType audioType = AudioType.PCM; + jsonObject.put(AUDIO_TYPE, audioType.toString()); + + AudioPassThruCapabilities msg = new AudioPassThruCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getAudioType(), is(audioType)); + } + + public void testDeserializedAudioTypeAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(AUDIO_TYPE, 0); + + AudioPassThruCapabilities msg = new AudioPassThruCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getAudioType(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ChoiceTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ChoiceTest.java new file mode 100644 index 000000000..7a283cc26 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ChoiceTest.java @@ -0,0 +1,96 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.proxy.RPCRequestFactory; +import com.ford.syncV4.proxy.constants.Names; +import com.ford.syncV4.proxy.rpc.enums.ImageType; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Vector; + +/** + * Created by Andrew Batutin on 10/3/13. + */ +public class ChoiceTest extends TestCase { + + public void testSecondaryTextShouldBeSet() throws Exception { + Choice choice = new Choice(); + assertNotNull(choice); + String testData = "text"; + choice.setSecondaryText(testData); + JSONObject obj = getChoiceJSONObject(choice); + String realData = (String) obj.get(Names.secondaryText); + assertEquals("Deserialized message should match original one", testData, realData); + } + + private JSONObject getChoiceJSONObject(Choice choice) throws JSONException { + CreateInteractionChoiceSet choiceSet = createCreateInteractionChoiceSet(choice); + JSONObject choiceSetJSON = choiceSet.serializeJSON((byte) 2); + JSONArray choiceJSONList = (JSONArray) choiceSetJSON.getJSONArray("choiceSet"); + return (JSONObject) choiceJSONList.get(0); + } + + public void testGetSecondaryTextShouldReturnSecondaryText() throws Exception { + Choice choice = new Choice(); + String testData = "text"; + choice.setSecondaryText(testData); + String realData = choice.getSecondaryText(); + assertEquals("Get ext should be == set text", testData, realData); + } + + private CreateInteractionChoiceSet createCreateInteractionChoiceSet(Choice choice) { + Vector<Choice> choiceVector = new Vector<Choice>(); + choiceVector.add(choice); + CreateInteractionChoiceSet choiceSet = RPCRequestFactory.buildCreateInteractionChoiceSet(); + choiceSet.setChoiceSet(choiceVector); + return choiceSet; + } + + public void testSetTertiaryTextSetsTertiaryText() throws Exception { + Choice choice = new Choice(); + assertNotNull(choice); + String testData = "text"; + choice.setTertiaryText(testData); + JSONObject obj = getChoiceJSONObject(choice); + String realData = (String) obj.get(Names.tertiaryText); + assertEquals("Deserialized message should match original one", testData, realData); + } + + public void testGetTertiaryTextReturnsTertiaryText() throws Exception { + Choice choice = new Choice(); + String testData = "text"; + choice.setTertiaryText(testData); + String realData = choice.getTertiaryText(); + assertEquals("Get text should be == set text", testData, realData); + } + + public void testSetSecondaryImageSetsSecondaryImage() throws Exception { + Choice choice = new Choice(); + assertNotNull(choice); + Image testImage = new Image(); + ImageType testData = ImageType.DYNAMIC; + testImage.setImageType(ImageType.DYNAMIC); + byte[] bulkData = new byte[100]; + testImage.setBulkData(bulkData); + choice.setSecondaryImage(testImage); + JSONObject obj = getChoiceJSONObject(choice); + JSONObject realImage = (JSONObject) obj.get(Names.secondaryImage); + ImageType realData = (ImageType) realImage.get(Names.imageType); + assertEquals("Deserialized message should match original one", testData, realData); + } + + public void testGetSecondaryImageReturnsSecondaryImage() throws Exception { + Choice choice = new Choice(); + Image testImage = new Image(); + String testData = "Value"; + testImage.setValue(testData); + choice.setSecondaryImage(testImage); + Image realImage = choice.getSecondaryImage(); + String realData = realImage.getValue(); + assertEquals("Get ext should be == set text", testData, realData); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DIDResultTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DIDResultTest.java new file mode 100644 index 000000000..a011741ea --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DIDResultTest.java @@ -0,0 +1,191 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.VehicleDataResultCode; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for DIDResult struct. + * + * Created by enikolsky on 2014-02-13. + */ +public class DIDResultTest extends TestCase { + private static final String RESULT_CODE = "resultCode"; + private static final String DID_LOCATION = "didLocation"; + private static final String DATA = "data"; + + public void testMessageShouldBeCreated() { + DIDResult msg = new DIDResult(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + DIDResult msg = new DIDResult(); + + final VehicleDataResultCode code = + VehicleDataResultCode.DATA_ALREADY_SUBSCRIBED; + final int didLocation = 1234; + final String data = "Atlas Shrugged"; + + msg.setResultCode(code); + msg.setDidLocation(didLocation); + msg.setData(data); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.getString(RESULT_CODE), is(code.toString())); + assertThat(jsonObject.getInt(DID_LOCATION), is(didLocation)); + assertThat(jsonObject.getString(DATA), is(data)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + DIDResult msg = new DIDResult( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getResultCode(), nullValue()); + assertThat(msg.getDidLocation(), nullValue()); + assertThat(msg.getData(), nullValue()); + } + + /// resultCode + public void testResultCodeGetterShouldReturnSetValue() + throws JSONException { + DIDResult msg = new DIDResult(); + + final VehicleDataResultCode code = VehicleDataResultCode.IGNORED; + msg.setResultCode(code); + + assertThat(msg.getResultCode(), is(code)); + } + + public void testSettingNullResultCodeShouldRemoveValue() + throws JSONException { + DIDResult msg = new DIDResult(); + + msg.setResultCode(VehicleDataResultCode.DISALLOWED); + msg.setResultCode(null); + + assertThat(msg.getResultCode(), nullValue()); + } + + public void testDeserializedResultCodeAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final VehicleDataResultCode code = + VehicleDataResultCode.DATA_ALREADY_SUBSCRIBED; + jsonObject.put(RESULT_CODE, code.toString()); + + DIDResult msg = new DIDResult( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResultCode(), is(code)); + } + + public void testDeserializedResultCodeAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(RESULT_CODE, 4); + + DIDResult msg = new DIDResult( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResultCode(), nullValue()); + } + + /// didLocation + public void testDidLocationGetterShouldReturnSetValue() + throws JSONException { + DIDResult msg = new DIDResult(); + + final int didLocation = 1234; + msg.setDidLocation(didLocation); + + assertThat(msg.getDidLocation(), is(didLocation)); + } + + public void testSettingNullDidLocationShouldRemoveValue() + throws JSONException { + DIDResult msg = new DIDResult(); + + msg.setDidLocation(12345); + msg.setDidLocation(null); + + assertThat(msg.getDidLocation(), nullValue()); + } + + public void testDeserializedDidLocationAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int didLocation = 1234; + jsonObject.put(DID_LOCATION, didLocation); + + DIDResult msg = new DIDResult( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getDidLocation(), is(didLocation)); + } + + public void testDeserializedDidLocationAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(DID_LOCATION, "123"); + + DIDResult msg = new DIDResult( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getDidLocation(), nullValue()); + } + + /// data + public void testDataGetterShouldReturnSetValue() throws JSONException { + DIDResult msg = new DIDResult(); + + final String data = "Atlas Shrugged"; + msg.setData(data); + + assertThat(msg.getData(), is(data)); + } + + public void testSettingNullDataShouldRemoveValue() throws JSONException { + DIDResult msg = new DIDResult(); + + msg.setData("You Will Obey"); + msg.setData(null); + + assertThat(msg.getData(), nullValue()); + } + + public void testDeserializedDataAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final String data = "Atlas Shrugged"; + jsonObject.put(DATA, data); + + DIDResult msg = new DIDResult( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getData(), is(data)); + } + + public void testDeserializedDataAsIntShouldBeNull() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(DATA, 432); + + DIDResult msg = new DIDResult( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getData(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageResponseTest.java new file mode 100644 index 000000000..d3801c7b1 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageResponseTest.java @@ -0,0 +1,117 @@ +package com.ford.syncV4.proxy.rpc; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Arrays; +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for DiagnosticMessageResponse response. + * + * Created by enikolsky on 2014-02-17. + */ +public class DiagnosticMessageResponseTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String MESSAGE_DATA_RESULT = "messageDataResult"; + + public void testMessageShouldBeCreated() { + DiagnosticMessageResponse msg = new DiagnosticMessageResponse(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + DiagnosticMessageResponse msg = new DiagnosticMessageResponse(); + + final Vector<Integer> messageDataResult = + new Vector<Integer>(Arrays.asList(22, 11)); + + msg.setMessageDataResult(messageDataResult); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + final JSONArray messageDataResultJsonArray = + jsonObject.getJSONArray(MESSAGE_DATA_RESULT); + assertThat(messageDataResultJsonArray.length(), + is(messageDataResult.size())); + assertThat(messageDataResultJsonArray.getInt(0), + is(messageDataResult.get(0))); + assertThat(messageDataResultJsonArray.getInt(1), + is(messageDataResult.get(1))); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + DiagnosticMessageResponse msg = new DiagnosticMessageResponse( + TestCommon.deserializeJSONRequestObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getMessageDataResult(), nullValue()); + } + + /// messageDataResult + public void testGetMessageDataResultShouldReturnSetValue() + throws JSONException { + DiagnosticMessageResponse msg = new DiagnosticMessageResponse(); + + final Vector<Integer> messageDataResult = + new Vector<Integer>(Arrays.asList(22, 11)); + msg.setMessageDataResult(messageDataResult); + + assertThat(msg.getMessageDataResult(), is(messageDataResult)); + } + + public void testSettingNullMessageDataResultShouldRemoveValue() + throws JSONException { + DiagnosticMessageResponse msg = new DiagnosticMessageResponse(); + + msg.setMessageDataResult(new Vector<Integer>()); + msg.setMessageDataResult(null); + + assertThat(msg.getMessageDataResult(), nullValue()); + } + + public void testDeserializedMessageDataResultAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<Integer> messageDataResult = + new Vector<Integer>(Arrays.asList(22, 11)); + jsonObject.put(MESSAGE_DATA_RESULT, messageDataResult); + + DiagnosticMessageResponse msg = new DiagnosticMessageResponse( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageDataResult(), is(messageDataResult)); + } + + public void testDeserializedMessageDataResultAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MESSAGE_DATA_RESULT, 88); + + DiagnosticMessageResponse msg = new DiagnosticMessageResponse( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageDataResult(), nullValue()); + } + + public void testDeserializedMessageDataResultAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MESSAGE_DATA_RESULT, "88"); + + DiagnosticMessageResponse msg = new DiagnosticMessageResponse( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageDataResult(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageTest.java new file mode 100644 index 000000000..ef98cf241 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageTest.java @@ -0,0 +1,210 @@ +package com.ford.syncV4.proxy.rpc; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Arrays; +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for DiagnosticMessage request. + * + * Created by enikolsky on 2014-02-17. + */ +public class DiagnosticMessageTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String TARGET_ID = "targetID"; + private static final String MESSAGE_LENGTH = "messageLength"; + private static final String MESSAGE_DATA = "messageData"; + + public void testMessageShouldBeCreated() { + DiagnosticMessage msg = new DiagnosticMessage(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + DiagnosticMessage msg = new DiagnosticMessage(); + + final int targetID = 88; + final int messageLength = 44; + final Vector<Integer> messageData = + new Vector<Integer>(Arrays.asList(22, 11)); + + msg.setTargetID(targetID); + msg.setMessageLength(messageLength); + msg.setMessageData(messageData); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getInt(TARGET_ID), is(targetID)); + assertThat(jsonObject.getInt(MESSAGE_LENGTH), is(messageLength)); + final JSONArray messageDataJsonArray = + jsonObject.getJSONArray(MESSAGE_DATA); + assertThat(messageDataJsonArray.length(), is(messageData.size())); + assertThat(messageDataJsonArray.getInt(0), is(messageData.get(0))); + assertThat(messageDataJsonArray.getInt(1), is(messageData.get(1))); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getTargetID(), nullValue()); + assertThat(msg.getMessageLength(), nullValue()); + assertThat(msg.getMessageData(), nullValue()); + } + + /// targetID + public void testGetTargetIDShouldReturnSetValue() throws JSONException { + DiagnosticMessage msg = new DiagnosticMessage(); + + final int targetID = 88; + msg.setTargetID(targetID); + + assertThat(msg.getTargetID(), is(targetID)); + } + + public void testSettingNullTargetIDShouldRemoveValue() + throws JSONException { + DiagnosticMessage msg = new DiagnosticMessage(); + + msg.setTargetID(42); + msg.setTargetID(null); + + assertThat(msg.getTargetID(), nullValue()); + } + + public void testDeserializedTargetIDAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int targetID = 88; + jsonObject.put(TARGET_ID, targetID); + + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTargetID(), is(targetID)); + } + + public void testDeserializedTargetIDAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(TARGET_ID, "88"); + + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTargetID(), nullValue()); + } + + /// messageLength + public void testGetMessageLengthShouldReturnSetValue() + throws JSONException { + DiagnosticMessage msg = new DiagnosticMessage(); + + final int messageLength = 44; + msg.setMessageLength(messageLength); + + assertThat(msg.getMessageLength(), is(messageLength)); + } + + public void testSettingNullMessageLengthShouldRemoveValue() + throws JSONException { + DiagnosticMessage msg = new DiagnosticMessage(); + + msg.setMessageLength(44); + msg.setMessageLength(null); + + assertThat(msg.getMessageLength(), nullValue()); + } + + public void testDeserializedMessageLengthAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int messageLength = 44; + jsonObject.put(MESSAGE_LENGTH, messageLength); + + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageLength(), is(messageLength)); + } + + public void testDeserializedMessageLengthAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MESSAGE_LENGTH, "88"); + + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageLength(), nullValue()); + } + + /// messageData + public void testGetMessageDataShouldReturnSetValue() throws JSONException { + DiagnosticMessage msg = new DiagnosticMessage(); + + final Vector<Integer> messageData = + new Vector<Integer>(Arrays.asList(22, 11)); + msg.setMessageData(messageData); + + assertThat(msg.getMessageData(), is(messageData)); + } + + public void testSettingNullMessageDataShouldRemoveValue() + throws JSONException { + DiagnosticMessage msg = new DiagnosticMessage(); + + msg.setMessageData(new Vector<Integer>()); + msg.setMessageData(null); + + assertThat(msg.getMessageData(), nullValue()); + } + + public void testDeserializedMessageDataAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<Integer> messageData = + new Vector<Integer>(Arrays.asList(22, 11)); + jsonObject.put(MESSAGE_DATA, messageData); + + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageData(), is(messageData)); + } + + public void testDeserializedMessageDataAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MESSAGE_DATA, 88); + + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageData(), nullValue()); + } + + public void testDeserializedMessageDataAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MESSAGE_DATA, "88"); + + DiagnosticMessage msg = new DiagnosticMessage( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMessageData(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DisplayCapabilitiesTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DisplayCapabilitiesTest.java new file mode 100644 index 000000000..ef192dae3 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DisplayCapabilitiesTest.java @@ -0,0 +1,358 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Arrays; +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for DisplayCapabilities struct (new parameters only). + * + * Created by enikolsky on 2014-02-07. + */ +public class DisplayCapabilitiesTest extends TestCase { + private static final String IMAGE_FIELDS = "imageFields"; + private static final String GRAPHIC_SUPPORTED = "graphicSupported"; + private static final String TEMPLATES_AVAILABLE = "templatesAvailable"; + private static final String NUM_CUSTOM_PRESETS_AVAILABLE = + "numCustomPresetsAvailable"; + private static final String SCREEN_PARAMS = "screenParams"; + + public void testMessageShouldBeCreated() { + DisplayCapabilities msg = new DisplayCapabilities(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + final Vector<ImageField> imageFields = + new Vector<ImageField>(Arrays.asList(new ImageField())); + final boolean graphicSupported = true; + final Vector<String> templatesAvailable = + new Vector<String>(Arrays.asList("ABC", "ZYX")); + final int numCustomPresetsAvailable = 45; + final ScreenParams screenParams = new ScreenParams(); + + msg.setImageFields(imageFields); + msg.setGraphicSupported(graphicSupported); + msg.setTemplatesAvailable(templatesAvailable); + msg.setNumCustomPresetsAvailable(numCustomPresetsAvailable); + msg.setScreenParams(screenParams); + + JSONObject jsonObject = msg.serializeJSON(); + final JSONArray imgsJsonArray = jsonObject.getJSONArray(IMAGE_FIELDS); + assertThat(imgsJsonArray.length(), is(imageFields.size())); + assertThat(jsonObject.getBoolean(GRAPHIC_SUPPORTED), + is(graphicSupported)); + final JSONArray tmplsJsonArray = + jsonObject.getJSONArray(TEMPLATES_AVAILABLE); + assertThat(tmplsJsonArray.length(), is(templatesAvailable.size())); + assertThat(jsonObject.getInt(NUM_CUSTOM_PRESETS_AVAILABLE), + is(numCustomPresetsAvailable)); + assertThat(jsonObject.has(SCREEN_PARAMS), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getImageFields(), nullValue()); + assertThat(msg.getGraphicSupported(), nullValue()); + assertThat(msg.getTemplatesAvailable(), nullValue()); + assertThat(msg.getNumCustomPresetsAvailable(), nullValue()); + assertThat(msg.getScreenParams(), nullValue()); + } + + public void testImageFieldsGetterShouldReturnSetValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + final Vector<ImageField> imageFields = + new Vector<ImageField>(Arrays.asList(new ImageField())); + msg.setImageFields(imageFields); + + assertThat(msg.getImageFields(), is(imageFields)); + } + + public void testSettingNullImageFieldsShouldRemoveValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + msg.setImageFields( + new Vector<ImageField>(Arrays.asList(new ImageField()))); + msg.setImageFields(null); + + assertThat(msg.getImageFields(), nullValue()); + } + + public void testDeserializedImageFieldsAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<ImageField> imageFields = + new Vector<ImageField>(Arrays.asList(new ImageField())); + jsonObject.put(IMAGE_FIELDS, imageFields); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageFields(), is(imageFields)); + } + + public void testDeserializedImageFieldsAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(IMAGE_FIELDS, "image"); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageFields(), nullValue()); + } + + public void testDeserializedImageFieldsAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(IMAGE_FIELDS, 1); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageFields(), nullValue()); + } + + public void testGraphicSupportedGetterShouldReturnSetValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + final boolean graphicSupported = true; + msg.setGraphicSupported(graphicSupported); + + assertThat(msg.getGraphicSupported(), is(graphicSupported)); + } + + public void testSettingNullGraphicSupportedShouldRemoveValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + msg.setGraphicSupported(true); + msg.setGraphicSupported(null); + + assertThat(msg.getGraphicSupported(), nullValue()); + } + + public void testDeserializedGraphicSupportedAsBooleanShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final boolean graphicSupported = true; + jsonObject.put(GRAPHIC_SUPPORTED, graphicSupported); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getGraphicSupported(), is(graphicSupported)); + } + + public void testDeserializedGraphicSupportedAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(GRAPHIC_SUPPORTED, "true"); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getGraphicSupported(), nullValue()); + } + + public void testDeserializedGraphicSupportedAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(GRAPHIC_SUPPORTED, 1); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getGraphicSupported(), nullValue()); + } + + public void testTemplatesAvailableGetterShouldReturnSetValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + final Vector<String> templatesAvailable = + new Vector<String>(Arrays.asList("ABC", "ZYX")); + msg.setTemplatesAvailable(templatesAvailable); + + assertThat(msg.getTemplatesAvailable(), is(templatesAvailable)); + } + + public void testSettingNullTemplatesAvailableShouldRemoveValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + msg.setTemplatesAvailable(new Vector<String>(Arrays.asList("ASDF"))); + msg.setTemplatesAvailable(null); + + assertThat(msg.getTemplatesAvailable(), nullValue()); + } + + public void testDeserializedTemplatesAvailableAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<String> templatesAvailable = + new Vector<String>(Arrays.asList("ABC", "ZYX")); + jsonObject.put(TEMPLATES_AVAILABLE, templatesAvailable); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTemplatesAvailable(), is(templatesAvailable)); + } + + public void testDeserializedTemplatesAvailableAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(TEMPLATES_AVAILABLE, "image"); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTemplatesAvailable(), nullValue()); + } + + public void testDeserializedTemplatesAvailableAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(TEMPLATES_AVAILABLE, 1); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTemplatesAvailable(), nullValue()); + } + + public void testScreenParamsGetterShouldReturnSetValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + final ScreenParams screenParams = new ScreenParams(); + msg.setScreenParams(screenParams); + + assertThat(msg.getScreenParams(), is(screenParams)); + } + + public void testSettingNullScreenParamsShouldRemoveValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + msg.setScreenParams(new ScreenParams()); + msg.setScreenParams(null); + + assertThat(msg.getScreenParams(), nullValue()); + } + + public void testDeserializedScreenParamsAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ScreenParams screenParams = new ScreenParams(); + jsonObject.put(SCREEN_PARAMS, screenParams); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getScreenParams(), is(screenParams)); + } + + public void testDeserializedScreenParamsAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SCREEN_PARAMS, "image"); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getScreenParams(), nullValue()); + } + + public void testDeserializedScreenParamsAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SCREEN_PARAMS, 1); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getScreenParams(), nullValue()); + } + + public void testNumCustomPresetsAvailableGetterShouldReturnSetValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + final int numCustomPresetsAvailable = 45; + msg.setNumCustomPresetsAvailable(numCustomPresetsAvailable); + + assertThat(msg.getNumCustomPresetsAvailable(), + is(numCustomPresetsAvailable)); + } + + public void testSettingNullNumCustomPresetsAvailableShouldRemoveValue() + throws JSONException { + DisplayCapabilities msg = new DisplayCapabilities(); + + msg.setNumCustomPresetsAvailable(30); + msg.setNumCustomPresetsAvailable(null); + + assertThat(msg.getNumCustomPresetsAvailable(), nullValue()); + } + + public void testDeserializedNumCustomPresetsAvailableAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int numCustomPresetsAvailable = 45; + jsonObject.put(NUM_CUSTOM_PRESETS_AVAILABLE, numCustomPresetsAvailable); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getNumCustomPresetsAvailable(), + is(numCustomPresetsAvailable)); + } + + public void testDeserializedNumCustomPresetsAvailableAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(NUM_CUSTOM_PRESETS_AVAILABLE, "42"); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getNumCustomPresetsAvailable(), nullValue()); + } + + public void testDeserializedNumCustomPresetsAvailableAsBooleanShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(NUM_CUSTOM_PRESETS_AVAILABLE, true); + + DisplayCapabilities msg = new DisplayCapabilities( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getNumCustomPresetsAvailable(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/GetVehicleDataResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/GetVehicleDataResponseTest.java new file mode 100644 index 000000000..a26ac7108 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/GetVehicleDataResponseTest.java @@ -0,0 +1,97 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for GetVehicleDataResponse response (new params only). + * + * Created by enikolsky on 2014-01-27. + */ +public class GetVehicleDataResponseTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String STEERING_WHEEL_ANGLE = "steeringWheelAngle"; + + public void testMessageShouldBeCreated() { + GetVehicleDataResponse msg = new GetVehicleDataResponse(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + GetVehicleDataResponse msg = new GetVehicleDataResponse(); + + final float swa = 1.0f; + + msg.setSteeringWheelAngle(swa); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getDouble(STEERING_WHEEL_ANGLE), + is((double) swa)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + GetVehicleDataResponse msg = new GetVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testSteeringWheelAngleGetterShouldReturnSetValue() + throws JSONException { + GetVehicleDataResponse msg = new GetVehicleDataResponse(); + + final float swa = 2.0f; + msg.setSteeringWheelAngle(swa); + + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testSettingNullSteeringWheelAngleShouldRemoveValue() + throws JSONException { + GetVehicleDataResponse msg = new GetVehicleDataResponse(); + + msg.setSteeringWheelAngle(-3.14f); + msg.setSteeringWheelAngle(null); + + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final float swa = 4.0f; + jsonObject.put(STEERING_WHEEL_ANGLE, swa); + + GetVehicleDataResponse msg = new GetVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testDeserializedSteeringWheelAngleAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, "4.0f"); + + GetVehicleDataResponse msg = new GetVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/HeadLampStatusTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/HeadLampStatusTest.java new file mode 100644 index 000000000..5f0041fca --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/HeadLampStatusTest.java @@ -0,0 +1,166 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.AmbientLightStatus; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for HeadLampStatus struct (new params only). + * + * Created by enikolsky on 2014-02-07. + */ +public class HeadLampStatusTest extends TestCase { + private static final String AMBIENT_LIGHT_SENSOR_STATUS = + "ambientLightSensorStatus"; + private static final String LOW_BEAMS_ON = "lowBeamsOn"; + + public void testMessageShouldBeCreated() { + HeadLampStatus msg = new HeadLampStatus(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + HeadLampStatus msg = new HeadLampStatus(); + + final AmbientLightStatus als = AmbientLightStatus.NIGHT; + final boolean lowBeamsOn = true; + + msg.setAmbientLightSensorStatus(als); + msg.setLowBeamsOn(lowBeamsOn); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.getString(AMBIENT_LIGHT_SENSOR_STATUS), + is(als.toString())); + assertThat(jsonObject.getBoolean(LOW_BEAMS_ON), is(lowBeamsOn)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + HeadLampStatus msg = new HeadLampStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getAmbientLightSensorStatus(), nullValue()); + assertThat(msg.getLowBeamsOn(), nullValue()); + } + + public void testAmbientLightSensorStatusGetterShouldReturnSetValue() + throws JSONException { + HeadLampStatus msg = new HeadLampStatus(); + + final AmbientLightStatus als = AmbientLightStatus.INVALID; + msg.setAmbientLightSensorStatus(als); + + assertThat(msg.getAmbientLightSensorStatus(), is(als)); + } + + public void testSettingNullAmbientLightSensorStatusShouldRemoveValue() + throws JSONException { + HeadLampStatus msg = new HeadLampStatus(); + + msg.setAmbientLightSensorStatus(AmbientLightStatus.NIGHT); + msg.setAmbientLightSensorStatus(null); + + assertThat(msg.getAmbientLightSensorStatus(), nullValue()); + } + + public void testDeserializedAmbientLightSensorStatusShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final AmbientLightStatus als = AmbientLightStatus.TWILIGHT_1; + jsonObject.put(AMBIENT_LIGHT_SENSOR_STATUS, als); + + HeadLampStatus msg = new HeadLampStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getAmbientLightSensorStatus(), is(als)); + } + + public void testDeserializedAmbientLightSensorStatusAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final AmbientLightStatus als = AmbientLightStatus.TWILIGHT_2; + jsonObject.put(AMBIENT_LIGHT_SENSOR_STATUS, als.toString()); + + HeadLampStatus msg = new HeadLampStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getAmbientLightSensorStatus(), is(als)); + } + + public void testDeserializedAmbientLightSensorStatusAsFloatShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(AMBIENT_LIGHT_SENSOR_STATUS, 4.0f); + + HeadLampStatus msg = new HeadLampStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getAmbientLightSensorStatus(), nullValue()); + } + + public void testLowBeamsOnGetterShouldReturnSetValue() + throws JSONException { + HeadLampStatus msg = new HeadLampStatus(); + + final boolean lowBeamsOn = true; + msg.setLowBeamsOn(lowBeamsOn); + + assertThat(msg.getLowBeamsOn(), is(lowBeamsOn)); + } + + public void testSettingNullLowBeamsOnShouldRemoveValue() + throws JSONException { + HeadLampStatus msg = new HeadLampStatus(); + + msg.setLowBeamsOn(true); + msg.setLowBeamsOn(null); + + assertThat(msg.getLowBeamsOn(), nullValue()); + } + + public void testDeserializedLowBeamsOnBooleanShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final boolean lowBeamsOn = true; + jsonObject.put(LOW_BEAMS_ON, lowBeamsOn); + + HeadLampStatus msg = new HeadLampStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getLowBeamsOn(), is(lowBeamsOn)); + } + + public void testDeserializedLowBeamsOnAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(LOW_BEAMS_ON, 4); + + HeadLampStatus msg = new HeadLampStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getLowBeamsOn(), nullValue()); + } + + public void testDeserializedLowBeamsOnAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(LOW_BEAMS_ON, "4"); + + HeadLampStatus msg = new HeadLampStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getLowBeamsOn(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageFieldTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageFieldTest.java new file mode 100644 index 000000000..4ccbe3ede --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageFieldTest.java @@ -0,0 +1,241 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.FileType; +import com.ford.syncV4.proxy.rpc.enums.ImageFieldName; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Arrays; +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for ImageField struct. + * + * Created by enikolsky on 2014-02-07. + */ +public class ImageFieldTest extends TestCase { + private static final String NAME = "name"; + private static final String IMAGE_TYPE_SUPPORTED = "imageTypeSupported"; + private static final String IMAGE_RESOLUTION = "imageResolution"; + + public void testMessageShouldBeCreated() { + ImageField msg = new ImageField(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + ImageField msg = new ImageField(); + + final ImageFieldName name = ImageFieldName.choiceImage; + final FileType fileType = FileType.AUDIO_MP3; + final Vector<FileType> fileTypes = + new Vector<FileType>(Arrays.asList(fileType)); + final ImageResolution resolution = new ImageResolution(); + + msg.setName(name); + msg.setImageTypeSupported(fileTypes); + msg.setImageResolution(resolution); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.getString(NAME), is(name.toString())); + final JSONArray jsonArray = + jsonObject.getJSONArray(IMAGE_TYPE_SUPPORTED); + assertThat(jsonArray.length(), is(fileTypes.size())); + assertThat(jsonArray.getString(0), is(fileType.toString())); + assertThat(jsonObject.has(IMAGE_RESOLUTION), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getName(), nullValue()); + assertThat(msg.getImageTypeSupported(), nullValue()); + assertThat(msg.getImageResolution(), nullValue()); + } + + public void testNameGetterShouldReturnSetValue() throws JSONException { + ImageField msg = new ImageField(); + + final ImageFieldName name = ImageFieldName.choiceImage; + msg.setName(name); + + assertThat(msg.getName(), is(name)); + } + + public void testSettingNullNameShouldRemoveValue() throws JSONException { + ImageField msg = new ImageField(); + + msg.setName(ImageFieldName.softButtonImage); + msg.setName(null); + + assertThat(msg.getName(), nullValue()); + } + + public void testDeserializedNameAsEnumShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ImageFieldName name = ImageFieldName.choiceImage; + jsonObject.put(NAME, name); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getName(), is(name)); + } + + public void testDeserializedNameAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ImageFieldName name = ImageFieldName.choiceImage; + jsonObject.put(NAME, name.toString()); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getName(), is(name)); + } + + public void testDeserializedNameAsIntShouldBeNull() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(NAME, 1); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getName(), nullValue()); + } + + public void testImageTypeSupportedGetterShouldReturnSetValue() + throws JSONException { + ImageField msg = new ImageField(); + + final FileType fileType = FileType.AUDIO_MP3; + final Vector<FileType> fileTypes = + new Vector<FileType>(Arrays.asList(fileType)); + msg.setImageTypeSupported(fileTypes); + + assertThat(msg.getImageTypeSupported(), is(fileTypes)); + } + + public void testSettingNullImageTypeSupportedShouldRemoveValue() + throws JSONException { + ImageField msg = new ImageField(); + + msg.setImageTypeSupported(new Vector<FileType>()); + msg.setImageTypeSupported(null); + + assertThat(msg.getImageTypeSupported(), nullValue()); + } + + public void testDeserializedImageTypeSupportedAsEnumShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final FileType fileType = FileType.AUDIO_MP3; + final Vector<FileType> fileTypes = + new Vector<FileType>(Arrays.asList(fileType)); + jsonObject.put(IMAGE_TYPE_SUPPORTED, fileTypes); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageTypeSupported(), is(fileTypes)); + } + + public void testDeserializedImageTypeSupportedAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(IMAGE_TYPE_SUPPORTED, "IMAGE"); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageTypeSupported(), nullValue()); + } + + public void testDeserializedImageTypeSupportedAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(IMAGE_TYPE_SUPPORTED, 1); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageTypeSupported(), nullValue()); + } + + public void testImageResolutionGetterShouldReturnSetValue() + throws JSONException { + ImageField msg = new ImageField(); + + final ImageResolution resolution = new ImageResolution(); + resolution.setResolutionWidth(100); + resolution.setResolutionHeight(122); + msg.setImageResolution(resolution); + + assertThat(msg.getImageResolution(), is(resolution)); + } + + public void testSettingNullImageResolutionShouldRemoveValue() + throws JSONException { + ImageField msg = new ImageField(); + + msg.setImageResolution(new ImageResolution()); + msg.setImageResolution(null); + + assertThat(msg.getImageResolution(), nullValue()); + } + + public void testDeserializedImageResolutionAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ImageResolution resolution = new ImageResolution(); + resolution.setResolutionWidth(100); + resolution.setResolutionHeight(122); + jsonObject.put(IMAGE_RESOLUTION, resolution); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageResolution(), is(resolution)); + } + + public void testDeserializedImageResolutionAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ImageResolution resolution = new ImageResolution(); + resolution.setResolutionWidth(100); + resolution.setResolutionHeight(122); + jsonObject.put(IMAGE_RESOLUTION, resolution.toString()); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageResolution(), nullValue()); + } + + public void testDeserializedImageResolutionAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(IMAGE_RESOLUTION, 1); + + ImageField msg = new ImageField( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getImageResolution(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageResolutionTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageResolutionTest.java new file mode 100644 index 000000000..d4c87b96f --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageResolutionTest.java @@ -0,0 +1,140 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for ImageResolution struct. + * + * Created by enikolsky on 2014-02-07. + */ +public class ImageResolutionTest extends TestCase { + private static final String RESOLUTION_WIDTH = "resolutionWidth"; + private static final String RESOLUTION_HEIGHT = "resolutionHeight"; + + public void testMessageShouldBeCreated() { + ImageResolution msg = new ImageResolution(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + ImageResolution msg = new ImageResolution(); + + final Integer width = 100; + final Integer height = 200; + + msg.setResolutionWidth(width); + msg.setResolutionHeight(height); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.getInt(RESOLUTION_WIDTH), is(width)); + assertThat(jsonObject.getInt(RESOLUTION_HEIGHT), is(height)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + ImageResolution msg = new ImageResolution( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getResolutionWidth(), nullValue()); + assertThat(msg.getResolutionHeight(), nullValue()); + } + + public void testResolutionWidthGetterShouldReturnSetValue() + throws JSONException { + ImageResolution msg = new ImageResolution(); + + final Integer width = 100; + msg.setResolutionWidth(width); + + assertThat(msg.getResolutionWidth(), is(width)); + } + + public void testSettingNullResolutionWidthShouldRemoveValue() + throws JSONException { + ImageResolution msg = new ImageResolution(); + + msg.setResolutionWidth(1); + msg.setResolutionWidth(null); + + assertThat(msg.getResolutionWidth(), nullValue()); + } + + public void testDeserializedResolutionWidthAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Integer width = 100; + jsonObject.put(RESOLUTION_WIDTH, width); + + ImageResolution msg = new ImageResolution( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResolutionWidth(), is(width)); + } + + public void testDeserializedResolutionWidthAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(RESOLUTION_WIDTH, "1"); + + ImageResolution msg = new ImageResolution( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResolutionWidth(), nullValue()); + } + + public void testResolutionHeightGetterShouldReturnSetValue() + throws JSONException { + ImageResolution msg = new ImageResolution(); + + final Integer height = 100; + msg.setResolutionHeight(height); + + assertThat(msg.getResolutionHeight(), is(height)); + } + + public void testSettingNullResolutionHeightShouldRemoveValue() + throws JSONException { + ImageResolution msg = new ImageResolution(); + + msg.setResolutionHeight(1); + msg.setResolutionHeight(null); + + assertThat(msg.getResolutionHeight(), nullValue()); + } + + public void testDeserializedResolutionHeightAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Integer Height = 100; + jsonObject.put(RESOLUTION_HEIGHT, Height); + + ImageResolution msg = new ImageResolution( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResolutionHeight(), is(Height)); + } + + public void testDeserializedResolutionHeightAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(RESOLUTION_HEIGHT, "1"); + + ImageResolution msg = new ImageResolution( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResolutionHeight(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/KeyboardPropertiesTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/KeyboardPropertiesTest.java new file mode 100644 index 000000000..f590d4914 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/KeyboardPropertiesTest.java @@ -0,0 +1,302 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.KeyboardLayout; +import com.ford.syncV4.proxy.rpc.enums.KeypressMode; +import com.ford.syncV4.proxy.rpc.enums.Language; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Vector; + +/** + * Created by enikolsky on 2013-10-02. + */ +public class KeyboardPropertiesTest extends TestCase { + private static final String LANGUAGE = "language"; + private static final String KEYBOARD_LAYOUT = "keyboardLayout"; + private static final String KEYPRESS_MODE = "keypressMode"; + private static final String LIMITED_CHARACTER_LIST = "limitedCharacterList"; + private static final String AUTO_COMPLETE_TEXT = "autoCompleteText"; + private static final String KEYPRESS_MODE_DEFAULT = "RESEND_CURRENT_ENTRY"; + + public void testSerialization() throws JSONException { + KeyboardProperties msg = new KeyboardProperties(); + assertNotNull(msg); + + final Language lang = Language.AR_SA; + final KeyboardLayout kbdLayout = KeyboardLayout.QWERTZ; + final KeypressMode keypressMode = KeypressMode.SINGLE_KEYPRESS; + final boolean sendDynamicEntry = true; + final Vector<String> charList = new Vector<String>() {{ + add("A"); + add("B"); + }}; + final String autoCompleteText = "1234"; + + msg.setLanguage(lang); + msg.setKeyboardLayout(kbdLayout); + msg.setKeypressMode(keypressMode); + + msg.setLimitedCharacterList(charList); + msg.setAutoCompleteText(autoCompleteText); + + JSONObject jsonObject = msg.serializeJSON(); + assertEquals(5, jsonObject.length()); + assertEquals(lang.toString(), jsonObject.getString(LANGUAGE)); + assertEquals(kbdLayout.toString(), + jsonObject.getString(KEYBOARD_LAYOUT)); + assertEquals(keypressMode.toString(), + jsonObject.getString(KEYPRESS_MODE)); + assertTrue(jsonObject.has(LIMITED_CHARACTER_LIST)); + assertEquals(autoCompleteText, + jsonObject.getString(AUTO_COMPLETE_TEXT)); + } + + public void testNullDeserialization() throws JSONException { + JSONObject jsonObject = new JSONObject(); + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertNull(msg.getLanguage()); + assertNull(msg.getKeyboardLayout()); + assertEquals("Incorrect default message", KEYPRESS_MODE_DEFAULT, + msg.getKeypressMode().toString()); + + assertNull(msg.getLimitedCharacterList()); + assertNull(msg.getAutoCompleteText()); + } + + public void testLanguageAPI() { + KeyboardProperties msg = new KeyboardProperties(); + + final Language lang = Language.CS_CZ; + msg.setLanguage(lang); + + assertEquals(lang, msg.getLanguage()); + } + + public void testRemoveLanguage() { + KeyboardProperties msg = new KeyboardProperties(); + msg.setLanguage(Language.DA_DK); + msg.setLanguage(null); + assertNull(msg.getLanguage()); + } + + public void testGetLanguage() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Language lang = Language.DE_DE; + jsonObject.put(LANGUAGE, lang); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(lang, msg.getLanguage()); + } + + public void testGetLanguageFromString() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Language lang = Language.DE_DE; + jsonObject.put(LANGUAGE, lang.toString()); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(lang, msg.getLanguage()); + } + + public void testGetLanguageIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(LANGUAGE, 42); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertNull(msg.getLanguage()); + } + + public void testKeyboardLayoutAPI() { + KeyboardProperties msg = new KeyboardProperties(); + + final KeyboardLayout keyboardLayout = KeyboardLayout.AZERTY; + msg.setKeyboardLayout(keyboardLayout); + + assertEquals(keyboardLayout, msg.getKeyboardLayout()); + } + + public void testRemoveKeyboardLayout() { + KeyboardProperties msg = new KeyboardProperties(); + msg.setKeyboardLayout(KeyboardLayout.QWERTY); + msg.setKeyboardLayout(null); + assertNull(msg.getKeyboardLayout()); + } + + public void testGetKeyboardLayout() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final KeyboardLayout keyboardLayout = KeyboardLayout.QWERTZ; + jsonObject.put(KEYBOARD_LAYOUT, keyboardLayout); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(keyboardLayout, msg.getKeyboardLayout()); + } + + public void testGetKeyboardLayoutFromString() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final KeyboardLayout keyboardLayout = KeyboardLayout.AZERTY; + jsonObject.put(KEYBOARD_LAYOUT, keyboardLayout.toString()); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(keyboardLayout, msg.getKeyboardLayout()); + } + + public void testGetKeyboardLayoutIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(KEYBOARD_LAYOUT, 42); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertNull(msg.getKeyboardLayout()); + } + + public void testKeypressModeAPI() { + KeyboardProperties msg = new KeyboardProperties(); + + final KeypressMode keypressMode = KeypressMode.QUEUE_KEYPRESSES; + msg.setKeypressMode(keypressMode); + + assertEquals(keypressMode, msg.getKeypressMode()); + } + + public void testRemoveKeypressMode() { + KeyboardProperties msg = new KeyboardProperties(); + msg.setKeypressMode(KeypressMode.SINGLE_KEYPRESS); + msg.setKeypressMode(null); + assertEquals("Incorrect default message", KEYPRESS_MODE_DEFAULT, + msg.getKeypressMode().toString()); + } + + public void testGetKeypressMode() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final KeypressMode keypressMode = KeypressMode.SINGLE_KEYPRESS; + jsonObject.put(KEYPRESS_MODE, keypressMode); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(keypressMode, msg.getKeypressMode()); + } + + public void testGetKeypressModeFromString() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final KeypressMode keypressMode = KeypressMode.QUEUE_KEYPRESSES; + jsonObject.put(KEYPRESS_MODE, keypressMode.toString()); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(keypressMode, msg.getKeypressMode()); + } + + public void testGetKeypressModeIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(KEYPRESS_MODE, 42); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals("Incorrect default message", KEYPRESS_MODE_DEFAULT, + msg.getKeypressMode().toString()); + } + + public void testLimitedCharacterListAPI() { + KeyboardProperties msg = new KeyboardProperties(); + + final Vector<String> limitedCharacterList = new Vector<String>() {{ + add("A"); + add("B"); + }}; + msg.setLimitedCharacterList(limitedCharacterList); + + assertEquals(limitedCharacterList, msg.getLimitedCharacterList()); + } + + public void testRemoveLimitedCharacterList() { + KeyboardProperties msg = new KeyboardProperties(); + final Vector<String> charList = new Vector<String>() {{ + add("A"); + add("B"); + }}; + msg.setLimitedCharacterList(charList); + msg.setLimitedCharacterList(null); + assertNull(msg.getLimitedCharacterList()); + } + + public void testGetLimitedCharacterList() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<String> limitedCharacterList = new Vector<String>() {{ + add("q"); + add("w"); + }}; + jsonObject.put(LIMITED_CHARACTER_LIST, limitedCharacterList); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(limitedCharacterList, msg.getLimitedCharacterList()); + } + + public void testGetLimitedCharacterListIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(LIMITED_CHARACTER_LIST, 42); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertNull(msg.getLimitedCharacterList()); + } + + public void testAutoCompleteTextAPI() { + KeyboardProperties msg = new KeyboardProperties(); + + final String autoCompleteText = "123456"; + msg.setAutoCompleteText(autoCompleteText); + + assertEquals(autoCompleteText, msg.getAutoCompleteText()); + } + + public void testRemoveAutoCompleteText() { + KeyboardProperties msg = new KeyboardProperties(); + msg.setAutoCompleteText("asdf"); + msg.setAutoCompleteText(null); + assertNull(msg.getAutoCompleteText()); + } + + public void testGetAutoCompleteText() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final String autoCompleteText = "qwer"; + jsonObject.put(AUTO_COMPLETE_TEXT, autoCompleteText); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertEquals(autoCompleteText, msg.getAutoCompleteText()); + } + + public void testGetAutoCompleteTextIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(AUTO_COMPLETE_TEXT, 42); + + KeyboardProperties msg = new KeyboardProperties( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertNotNull(msg); + assertNull(msg.getAutoCompleteText()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/MenuParamsTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/MenuParamsTest.java new file mode 100644 index 000000000..245640a19 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/MenuParamsTest.java @@ -0,0 +1,188 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for MenuParams struct. + * + * Created by enikolsky on 2014-02-12. + */ +public class MenuParamsTest extends TestCase { + private static final String PARENT_ID = "parentID"; + private static final String POSITION = "position"; + private static final String MENU_NAME = "menuName"; + + public void testMessageShouldBeCreated() { + MenuParams msg = new MenuParams(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + MenuParams msg = new MenuParams(); + + final int parentID = 1; + final int position = 34; + final String menuName = "abcd"; + + msg.setParentID(parentID); + msg.setPosition(position); + msg.setMenuName(menuName); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.getInt(PARENT_ID), is(parentID)); + assertThat(jsonObject.getInt(POSITION), is(position)); + assertThat(jsonObject.getString(MENU_NAME), is(menuName)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + MenuParams msg = new MenuParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getParentID(), nullValue()); + assertThat(msg.getPosition(), nullValue()); + assertThat(msg.getMenuName(), nullValue()); + } + + /// parentID + public void testParentIDGetterShouldReturnSetValue() throws JSONException { + MenuParams msg = new MenuParams(); + + final int parentID = 1; + msg.setParentID(parentID); + + assertThat(msg.getParentID(), is(parentID)); + } + + public void testSettingNullParentIDShouldRemoveValue() + throws JSONException { + MenuParams msg = new MenuParams(); + + msg.setParentID(2); + msg.setParentID(null); + + assertThat(msg.getParentID(), nullValue()); + } + + public void testDeserializedParentIDAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int parentID = 1; + jsonObject.put(PARENT_ID, parentID); + + MenuParams msg = new MenuParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getParentID(), is(parentID)); + } + + public void testDeserializedParentIDAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(PARENT_ID, "4"); + + MenuParams msg = new MenuParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getParentID(), nullValue()); + } + + /// position + public void testPositionGetterShouldReturnSetValue() throws JSONException { + MenuParams msg = new MenuParams(); + + final int position = 34; + msg.setPosition(position); + + assertThat(msg.getPosition(), is(position)); + } + + public void testSettingNullPositionShouldRemoveValue() + throws JSONException { + MenuParams msg = new MenuParams(); + + msg.setPosition(2); + msg.setPosition(null); + + assertThat(msg.getPosition(), nullValue()); + } + + public void testDeserializedPositionAsIntShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int position = 34; + jsonObject.put(POSITION, position); + + MenuParams msg = new MenuParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getPosition(), is(position)); + } + + public void testDeserializedPositionAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(POSITION, "4"); + + MenuParams msg = new MenuParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getPosition(), nullValue()); + } + + /// menuName + public void testMenuNameGetterShouldReturnSetValue() throws JSONException { + MenuParams msg = new MenuParams(); + + final String menuName = "abcd"; + msg.setMenuName(menuName); + + assertThat(msg.getMenuName(), is(menuName)); + } + + public void testSettingNullMenuNameShouldRemoveValue() + throws JSONException { + MenuParams msg = new MenuParams(); + + msg.setMenuName("123"); + msg.setMenuName(null); + + assertThat(msg.getMenuName(), nullValue()); + } + + public void testDeserializedMenuNameAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final String menuName = "abcd"; + jsonObject.put(MENU_NAME, menuName); + + MenuParams msg = new MenuParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMenuName(), is(menuName)); + } + + public void testDeserializedMenuNameAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MENU_NAME, 123); + + MenuParams msg = new MenuParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getMenuName(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnHashChangeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnHashChangeTest.java new file mode 100644 index 000000000..bc1e3e850 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnHashChangeTest.java @@ -0,0 +1,95 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.proxy.constants.Names; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Created with Android Studio. + * Author: Chernyshov Yuriy - Mobile Development + * Date: 2/25/14 + * Time: 1:50 PM + */ +public class OnHashChangeTest extends TestCase { + + private static final byte PROTOCOL_VERSION = (byte) 2; + + private String mLegalHashId = "1234567890qwertyuiop"; + private String mIllegalHashId = "dG8f5887951261W2a578o4L65X484eVl38tWr1n5474727m9iF6n2p" + + "620335PM18z322B28Q3XG38257kY5Pn8n3584596rU7J8ldG8f5887951261W2a578o4L65X484eVl" + + "38tWr1n5474727m9iF6n2p620335PM18z322B28Q3XG38257kY5Pn8n3584596rU7J8l"; + + public void testNotificationShouldBeCreated() { + OnHashChange onHashChange = new OnHashChange(); + assertThat(onHashChange, notNullValue()); + } + + public void testSerializedNotificationShouldContainAllSetFields() throws JSONException { + OnHashChange onHashChange = new OnHashChange(); + onHashChange.setHashID(mLegalHashId); + + JSONObject jsonObject = onHashChange.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getString(Names.hashID), is(mLegalHashId)); + } + + public void testDeserializedNotificationWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + OnHashChange onHashChange = new OnHashChange(TestCommon.deserializeJSONRequestObject( + jsonObject)); + + assertThat(onHashChange, notNullValue()); + assertThat(onHashChange.getHashID(), nullValue()); + } + + public void testGetHashIdShouldReturnSetValue() throws JSONException { + OnHashChange onHashChange = new OnHashChange(); + onHashChange.setHashID(mLegalHashId); + assertThat(onHashChange.getHashID(), is(mLegalHashId)); + } + + public void testSettingNullHashIdShouldRemoveValue() throws JSONException { + OnHashChange onHashChange = new OnHashChange(); + onHashChange.setHashID(mLegalHashId); + onHashChange.setHashID(null); + assertThat(onHashChange.getHashID(), nullValue()); + } + + public void testDeserializedHashIdShouldContainValue() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(Names.hashID, mLegalHashId); + + OnHashChange onHashChange = new OnHashChange(TestCommon.deserializeJSONRequestObject( + jsonObject)); + assertThat(onHashChange, notNullValue()); + assertThat(onHashChange.getHashID(), is(mLegalHashId)); + } + + public void testDeserializedHashIdAsIntShouldBeNull() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(Names.hashID, 1); + + OnHashChange onHashChange = new OnHashChange(TestCommon.deserializeJSONRequestObject( + jsonObject)); + assertThat(onHashChange, notNullValue()); + assertThat(onHashChange.getHashID(), nullValue()); + } + + public void testSetIllegalHashId() { + OnHashChange onHashChange = new OnHashChange(); + try { + onHashChange.setHashID(mIllegalHashId); + fail(); + } catch (IllegalArgumentException e) { + /* expected */ + } + } +}
\ No newline at end of file diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnSystemRequestTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnSystemRequestTest.java new file mode 100644 index 000000000..e1550f592 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnSystemRequestTest.java @@ -0,0 +1,362 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.proxy.constants.Names; +import com.ford.syncV4.proxy.rpc.enums.FileType; +import com.ford.syncV4.proxy.rpc.enums.RequestType; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for OnSystemRequest class. + * + * Created by enikolsky on 2014-01-24. + */ +public class OnSystemRequestTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String REQUEST_TYPE = "requestType"; + private static final String FILE_TYPE = "fileType"; + private static final String OFFSET = "offset"; + private static final String LENGTH = "length"; + private static final String URL = "url"; + + public void testMessageShouldBeCreated() { + OnSystemRequest msg = new OnSystemRequest(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final RequestType requestType = RequestType.AUTH_REQUEST; + final Vector<String> urls = new Vector<String>(); + urls.add("https://example.com/"); + final FileType fileType = FileType.GRAPHIC_PNG; + final int offset = 0; + final int length = 1500; + + msg.setRequestType(requestType); + msg.setUrl(urls); + msg.setFileType(fileType); + msg.setOffset(offset); + msg.setLength(length); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getString(REQUEST_TYPE), + is(requestType.toString())); + final JSONArray urlJSONArray = jsonObject.getJSONArray(URL); + assertThat(urlJSONArray.length(), is(urls.size())); + assertThat(urlJSONArray.getString(0), is(urls.get(0))); + assertThat(jsonObject.getString(FILE_TYPE), is(fileType.toString())); + assertThat(jsonObject.getInt(OFFSET), is(offset)); + assertThat(jsonObject.getInt(LENGTH), is(length)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), nullValue()); + assertThat(msg.getUrl(), nullValue()); + assertThat(msg.getFileType(), nullValue()); + assertThat(msg.getOffset(), nullValue()); + assertThat(msg.getLength(), nullValue()); + } + + public void testGetRequestTypeShouldReturnSetValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final RequestType requestType = RequestType.AUTH_ACK; + msg.setRequestType(requestType); + + assertThat(msg.getRequestType(), is(requestType)); + } + + public void testSettingNullRequestTypeShouldRemoveValue() + throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + msg.setRequestType(RequestType.AUTH_CHALLENGE); + msg.setRequestType(null); + + assertThat(msg.getRequestType(), nullValue()); + } + + public void testDeserializedRequestTypeShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final RequestType requestType = RequestType.AUTH_ACK; + jsonObject.put(REQUEST_TYPE, requestType); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), is(requestType)); + } + + public void testDeserializedRequestTypeAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final RequestType requestType = RequestType.AUTH_ACK; + jsonObject.put(REQUEST_TYPE, requestType.toString()); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), is(requestType)); + } + + public void testDeserializedRequestTypeAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(REQUEST_TYPE, 1); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), nullValue()); + } + + public void testGetUrlShouldReturnSetValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final Vector<String> urls = new Vector<String>(); + urls.add("https://d.android.com/"); + msg.setUrl(urls); + + assertThat(msg.getUrl(), is(urls)); + } + + public void testSettingNullUrlShouldRemoveValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final Vector<String> urls = new Vector<String>(); + urls.add("https://d.android.com/"); + msg.setUrl(urls); + msg.setUrl(null); + + assertThat(msg.getUrl(), nullValue()); + } + + public void testDeserializedUrlShouldContainValue() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<String> urls = new Vector<String>(); + urls.add("https://d.android.com/"); + jsonObject.put(URL, urls); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getUrl(), is(urls)); + } + + public void testDeserializedUrlAsStringShouldBeNull() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(URL, "https://d.android.com/"); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getUrl(), nullValue()); + } + + public void testDeserializedUrlAsIntShouldBeNull() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(URL, 1); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getUrl(), nullValue()); + } + + public void testGetFileTypeShouldReturnSetValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final FileType fileType = FileType.GRAPHIC_PNG; + msg.setFileType(fileType); + + assertThat(msg.getFileType(), is(fileType)); + } + + public void testSettingNullFileTypeShouldRemoveValue() + throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + msg.setFileType(FileType.AUDIO_AAC); + msg.setFileType(null); + + assertThat(msg.getFileType(), nullValue()); + } + + public void testDeserializedFileTypeShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final FileType fileType = FileType.AUDIO_MP3; + jsonObject.put(FILE_TYPE, fileType); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getFileType(), is(fileType)); + } + + public void testDeserializedFileTypeAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final FileType fileType = FileType.AUDIO_WAVE; + jsonObject.put(FILE_TYPE, fileType.toString()); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getFileType(), is(fileType)); + } + + public void testDeserializedFileTypeAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(FILE_TYPE, 1); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getFileType(), nullValue()); + } + + public void testGetOffsetShouldReturnSetValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final int offset = 88; + msg.setOffset(offset); + + assertThat(msg.getOffset(), is(offset)); + } + + public void testSettingNullOffsetShouldRemoveValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + msg.setOffset(12); + msg.setOffset(null); + + assertThat(msg.getOffset(), nullValue()); + } + + public void testDeserializedOffsetShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int Offset = 88; + jsonObject.put(OFFSET, Offset); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getOffset(), is(Offset)); + } + + public void testDeserializedOffsetAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(OFFSET, "88"); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getOffset(), nullValue()); + } + + public void testGetLengthShouldReturnSetValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final int length = 88; + msg.setLength(length); + + assertThat(msg.getLength(), is(length)); + } + + public void testSettingNullLengthShouldRemoveValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + msg.setLength(12); + msg.setLength(null); + + assertThat(msg.getLength(), nullValue()); + } + + public void testDeserializedLengthShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final int length = 88; + jsonObject.put(LENGTH, length); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getLength(), is(length)); + } + + public void testDeserializedLengthAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(LENGTH, "88"); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getLength(), nullValue()); + } + + public void testDeserializedTimeoutShouldBeNil() throws Exception { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(Names.timeout, "88"); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTimeout(), nullValue()); + } + + public void testDeserializedTimeoutShouldContainValue() throws Exception { + JSONObject jsonObject = new JSONObject(); + int timeout = 666; + jsonObject.put(Names.timeout, timeout); + + OnSystemRequest msg = new OnSystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTimeout(), is(timeout)); + } + + public void testGetTimeoutShouldReturnSetValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + final int timeout = 88; + msg.setTimeout(timeout); + + assertThat(msg.getTimeout(), is(timeout)); + } + + public void testSettingNullTimeoutShouldRemoveValue() throws JSONException { + OnSystemRequest msg = new OnSystemRequest(); + + msg.setTimeout(12); + msg.setTimeout(null); + + assertThat(msg.getLength(), nullValue()); + } + +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnVehicleDataTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnVehicleDataTest.java new file mode 100644 index 000000000..74ed091ee --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnVehicleDataTest.java @@ -0,0 +1,470 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for OnVehicleData notification (new params only). + * + * Created by enikolsky on 2014-01-27. + */ +public class OnVehicleDataTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String STEERING_WHEEL_ANGLE = "steeringWheelAngle"; + private static final String HEAD_LAMP_STATUS = "headLampStatus"; + private static final String E_CALL_INFO = "eCallInfo"; + private static final String AIRBAG_STATUS = "airbagStatus"; + private static final String EMERGENCY_EVENT = "emergencyEvent"; + private static final String CLUSTER_MODE_STATUS = "clusterModeStatus"; + private static final String MY_KEY = "myKey"; + + public void testMessageShouldBeCreated() { + OnVehicleData msg = new OnVehicleData(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final float swa = 1.0f; + final HeadLampStatus status = new HeadLampStatus(); + final ECallInfo eCallInfo = new ECallInfo(); + final AirbagStatus airbagStatus = new AirbagStatus(); + final EmergencyEvent emergencyEvent = new EmergencyEvent(); + final ClusterModeStatus clusterModeStatus = new ClusterModeStatus(); + final MyKey myKey = new MyKey(); + + msg.setSteeringWheelAngle(swa); + msg.setHeadLampStatus(status); + msg.setECallInfo(eCallInfo); + msg.setAirbagStatus(airbagStatus); + msg.setEmergencyEvent(emergencyEvent); + msg.setClusterModeStatus(clusterModeStatus); + msg.setMyKey(myKey); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getDouble(STEERING_WHEEL_ANGLE), + is((double) swa)); + assertThat(jsonObject.has(HEAD_LAMP_STATUS), is(true)); + assertThat(jsonObject.has(E_CALL_INFO), is(true)); + assertThat(jsonObject.has(AIRBAG_STATUS), is(true)); + assertThat(jsonObject.has(EMERGENCY_EVENT), is(true)); + assertThat(jsonObject.has(CLUSTER_MODE_STATUS), is(true)); + assertThat(jsonObject.has(MY_KEY), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + assertThat(msg.getHeadLampStatus(), nullValue()); + assertThat(msg.getECallInfo(), nullValue()); + assertThat(msg.getAirbagStatus(), nullValue()); + assertThat(msg.getEmergencyEvent(), nullValue()); + assertThat(msg.getClusterModeStatus(), nullValue()); + assertThat(msg.getMyKey(), nullValue()); + } + + public void testSteeringWheelAngleGetterShouldReturnSetValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final float swa = 2.0f; + msg.setSteeringWheelAngle(swa); + + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testSettingNullSteeringWheelAngleShouldRemoveValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + msg.setSteeringWheelAngle(-3.14f); + msg.setSteeringWheelAngle(null); + + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final float swa = 4.0f; + jsonObject.put(STEERING_WHEEL_ANGLE, swa); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testDeserializedSteeringWheelAngleAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, "4.0f"); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testHeadLampStatusGetterShouldReturnSetValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final HeadLampStatus status = new HeadLampStatus(); + msg.setHeadLampStatus(status); + + assertThat(msg.getHeadLampStatus(), is(status)); + } + + public void testSettingNullHeadLampStatusShouldRemoveValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + msg.setHeadLampStatus(new HeadLampStatus()); + msg.setHeadLampStatus(null); + + assertThat(msg.getHeadLampStatus(), nullValue()); + } + + public void testDeserializedHeadLampStatusAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final HeadLampStatus status = new HeadLampStatus(); + jsonObject.put(HEAD_LAMP_STATUS, status); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getHeadLampStatus(), is(status)); + } + + public void testDeserializedHeadLampStatusAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(HEAD_LAMP_STATUS, "4.0f"); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getHeadLampStatus(), nullValue()); + } + + public void testDeserializedHeadLampStatusAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(HEAD_LAMP_STATUS, 32); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getHeadLampStatus(), nullValue()); + } + + /////////// ECallInfo + public void testECallInfoGetterShouldReturnSetValue() throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final ECallInfo eCallInfo = new ECallInfo(); + msg.setECallInfo(eCallInfo); + + assertThat(msg.getECallInfo(), is(eCallInfo)); + } + + public void testSettingNullECallInfoShouldRemoveValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + msg.setECallInfo(new ECallInfo()); + msg.setECallInfo(null); + + assertThat(msg.getECallInfo(), nullValue()); + } + + public void testDeserializedECallInfoAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ECallInfo eCallInfo = new ECallInfo(); + jsonObject.put(E_CALL_INFO, eCallInfo); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getECallInfo(), is(eCallInfo)); + } + + public void testDeserializedECallInfoAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(E_CALL_INFO, "4.0f"); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getECallInfo(), nullValue()); + } + + public void testDeserializedECallInfoAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(E_CALL_INFO, 32); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getECallInfo(), nullValue()); + } + + /////////// AirbagStatus + public void testAirbagStatusGetterShouldReturnSetValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final AirbagStatus airbagStatus = new AirbagStatus(); + msg.setAirbagStatus(airbagStatus); + + assertThat(msg.getAirbagStatus(), is(airbagStatus)); + } + + public void testSettingNullAirbagStatusShouldRemoveValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + msg.setAirbagStatus(new AirbagStatus()); + msg.setAirbagStatus(null); + + assertThat(msg.getAirbagStatus(), nullValue()); + } + + public void testDeserializedAirbagStatusAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final AirbagStatus airbagStatus = new AirbagStatus(); + jsonObject.put(AIRBAG_STATUS, airbagStatus); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getAirbagStatus(), is(airbagStatus)); + } + + public void testDeserializedAirbagStatusAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(AIRBAG_STATUS, "4.0f"); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getAirbagStatus(), nullValue()); + } + + public void testDeserializedAirbagStatusAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(AIRBAG_STATUS, 32); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getAirbagStatus(), nullValue()); + } + + /////////// EmergencyEvent + public void testEmergencyEventGetterShouldReturnSetValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final EmergencyEvent emergencyEvent = new EmergencyEvent(); + msg.setEmergencyEvent(emergencyEvent); + + assertThat(msg.getEmergencyEvent(), is(emergencyEvent)); + } + + public void testSettingNullEmergencyEventShouldRemoveValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + msg.setEmergencyEvent(new EmergencyEvent()); + msg.setEmergencyEvent(null); + + assertThat(msg.getEmergencyEvent(), nullValue()); + } + + public void testDeserializedEmergencyEventAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final EmergencyEvent emergencyEvent = new EmergencyEvent(); + jsonObject.put(EMERGENCY_EVENT, emergencyEvent); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getEmergencyEvent(), is(emergencyEvent)); + } + + public void testDeserializedEmergencyEventAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(EMERGENCY_EVENT, "4.0f"); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getEmergencyEvent(), nullValue()); + } + + public void testDeserializedEmergencyEventAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(EMERGENCY_EVENT, 32); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getEmergencyEvent(), nullValue()); + } + + /////////// ClusterModeStatus + public void testClusterModeStatusGetterShouldReturnSetValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final ClusterModeStatus clusterModeStatus = new ClusterModeStatus(); + msg.setClusterModeStatus(clusterModeStatus); + + assertThat(msg.getClusterModeStatus(), is(clusterModeStatus)); + } + + public void testSettingNullClusterModeStatusShouldRemoveValue() + throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + msg.setClusterModeStatus(new ClusterModeStatus()); + msg.setClusterModeStatus(null); + + assertThat(msg.getClusterModeStatus(), nullValue()); + } + + public void testDeserializedClusterModeStatusAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ClusterModeStatus clusterModeStatus = new ClusterModeStatus(); + jsonObject.put(CLUSTER_MODE_STATUS, clusterModeStatus); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getClusterModeStatus(), is(clusterModeStatus)); + } + + public void testDeserializedClusterModeStatusAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(CLUSTER_MODE_STATUS, "4.0f"); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getClusterModeStatus(), nullValue()); + } + + public void testDeserializedClusterModeStatusAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(CLUSTER_MODE_STATUS, 32); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getClusterModeStatus(), nullValue()); + } + + /////////// MyKey + public void testMyKeyGetterShouldReturnSetValue() throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + final MyKey myKey = new MyKey(); + msg.setMyKey(myKey); + + assertThat(msg.getMyKey(), is(myKey)); + } + + public void testSettingNullMyKeyShouldRemoveValue() throws JSONException { + OnVehicleData msg = new OnVehicleData(); + + msg.setMyKey(new MyKey()); + msg.setMyKey(null); + + assertThat(msg.getMyKey(), nullValue()); + } + + public void testDeserializedMyKeyAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final MyKey myKey = new MyKey(); + jsonObject.put(MY_KEY, myKey); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getMyKey(), is(myKey)); + } + + public void testDeserializedMyKeyAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MY_KEY, "4.0f"); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getMyKey(), nullValue()); + } + + public void testDeserializedMyKeyAsIntShouldBeNull() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MY_KEY, 32); + + OnVehicleData msg = new OnVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getMyKey(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/PutFileTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/PutFileTest.java new file mode 100644 index 000000000..c77c5ab65 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/PutFileTest.java @@ -0,0 +1,186 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.RPCRequestFactory; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for PutFile class (only new parameters at the moment). + * + * Created by enikolsky on 2014-01-20. + */ +public class PutFileTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String SYSTEM_FILE = "systemFile"; + private static final String OFFSET = "offset"; + private static final String LENGTH = "length"; + + public void testMessageShouldBeCreated() { + PutFile msg = RPCRequestFactory.buildPutFile(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + PutFile msg = RPCRequestFactory.buildPutFile(); + + final boolean systemFile = true; + final Integer offset = 531; + final Integer length = 1000; + + msg.setSystemFile(systemFile); + msg.setOffset(offset); + msg.setLength(length); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getBoolean(SYSTEM_FILE), is(systemFile)); + assertThat(jsonObject.getInt(OFFSET), is(offset)); + assertThat(jsonObject.getInt(LENGTH), is(length)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + PutFile msg = new PutFile(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSystemFile(), nullValue()); + assertThat(msg.getOffset(), nullValue()); + assertThat(msg.getLength(), nullValue()); + } + + public void testSystemFileGetterShouldReturnSetValue() + throws JSONException { + PutFile msg = RPCRequestFactory.buildPutFile(); + + final boolean systemFile = true; + msg.setSystemFile(systemFile); + + assertThat(msg.getSystemFile(), is(systemFile)); + } + + public void testSettingNullSystemFileShouldRemoveValue() + throws JSONException { + PutFile msg = RPCRequestFactory.buildPutFile(); + + msg.setSystemFile(true); + msg.setSystemFile(null); + + assertThat(msg.getSystemFile(), nullValue()); + } + + public void testDeserializedSystemFileShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final boolean systemFile = true; + jsonObject.put(SYSTEM_FILE, systemFile); + + PutFile msg = new PutFile(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSystemFile(), is(systemFile)); + } + + public void testDeserializedSystemFileAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SYSTEM_FILE, 42); + + PutFile msg = new PutFile(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSystemFile(), nullValue()); + } + + public void testOffsetGetterShouldReturnSetValue() throws JSONException { + PutFile msg = RPCRequestFactory.buildPutFile(); + + final Integer offset = 333; + msg.setOffset(offset); + + assertThat(msg.getOffset(), is(offset)); + } + + public void testSettingNullOffsetShouldRemoveValue() throws JSONException { + PutFile msg = RPCRequestFactory.buildPutFile(); + + msg.setOffset(333); + msg.setOffset(null); + + assertThat(msg.getOffset(), nullValue()); + } + + public void testDeserializedOffsetShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Integer offset = 333; + jsonObject.put(OFFSET, offset); + + PutFile msg = new PutFile(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getOffset(), is(offset)); + } + + public void testDeserializedOffsetAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(OFFSET, "333"); + + PutFile msg = new PutFile(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getOffset(), nullValue()); + } + + public void testLengthGetterShouldReturnSetValue() throws JSONException { + PutFile msg = RPCRequestFactory.buildPutFile(); + + final Integer length = 333; + msg.setLength(length); + + assertThat(msg.getLength(), is(length)); + } + + public void testSettingNullLengthShouldRemoveValue() throws JSONException { + PutFile msg = RPCRequestFactory.buildPutFile(); + + msg.setLength(333); + msg.setLength(null); + + assertThat(msg.getLength(), nullValue()); + } + + public void testDeserializedLengthShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Integer length = 333; + jsonObject.put(LENGTH, length); + + PutFile msg = new PutFile(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getLength(), is(length)); + } + + public void testDeserializedLengthAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(LENGTH, "333"); + + PutFile msg = new PutFile(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getLength(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ReadDIDResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ReadDIDResponseTest.java new file mode 100644 index 000000000..c4fdf797e --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ReadDIDResponseTest.java @@ -0,0 +1,114 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Arrays; +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for ReadDIDResponse response. + * + * Created by enikolsky on 2014-02-13. + */ +public class ReadDIDResponseTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String DID_RESULT = "didResult"; + + public void testMessageShouldBeCreated() { + ReadDIDResponse msg = new ReadDIDResponse(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + ReadDIDResponse msg = new ReadDIDResponse(); + + final Vector<DIDResult> results = + new Vector<DIDResult>(Arrays.asList(new DIDResult())); + + msg.setDidResult(results); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.has(DID_RESULT), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + ReadDIDResponse msg = new ReadDIDResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getDidResult(), nullValue()); + } + + // didResult + public void testDidResultGetterShouldReturnSetValue() throws JSONException { + ReadDIDResponse msg = new ReadDIDResponse(); + + final Vector<DIDResult> results = + new Vector<DIDResult>(Arrays.asList(new DIDResult())); + msg.setDidResult(results); + + assertThat(msg.getDidResult(), is(results)); + } + + public void testSettingNullDidResultShouldRemoveValue() + throws JSONException { + ReadDIDResponse msg = new ReadDIDResponse(); + + msg.setDidResult(new Vector<DIDResult>(Arrays.asList(new DIDResult()))); + msg.setDidResult(null); + + assertThat(msg.getDidResult(), nullValue()); + } + + public void testDeserializedDidResultAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<DIDResult> results = + new Vector<DIDResult>(Arrays.asList(new DIDResult())); + jsonObject.put(DID_RESULT, results); + + ReadDIDResponse msg = new ReadDIDResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getDidResult(), is(results)); + } + + public void testDeserializedDidResultAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(DID_RESULT, "4.0f"); + + ReadDIDResponse msg = new ReadDIDResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getDidResult(), nullValue()); + } + + public void testDeserializedDidResultAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(DID_RESULT, 12); + + ReadDIDResponse msg = new ReadDIDResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getDidResult(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceResponseTest.java new file mode 100644 index 000000000..529279e9b --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceResponseTest.java @@ -0,0 +1,271 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.PrerecordedSpeech; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Arrays; +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for RegisterAppInterfaceResponse response (new params only). + * + * Created by enikolsky on 2014-02-11. + */ +public class RegisterAppInterfaceResponseTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String PRERECORDED_SPEECH = "prerecordedSpeech"; + private static final String AUDIO_PASS_THRU_CAPABILITIES = + "audioPassThruCapabilities"; + private static final String SUPPORTED_DIAG_MODES = "supportedDiagModes"; + + public void testMessageShouldBeCreated() { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + final Vector<PrerecordedSpeech> speech = new Vector<PrerecordedSpeech>( + Arrays.asList(PrerecordedSpeech.HELP_JINGLE, + PrerecordedSpeech.INITIAL_JINGLE)); + final Vector<AudioPassThruCapabilities> audioPassThruCapabilities = + new Vector<AudioPassThruCapabilities>( + Arrays.asList(new AudioPassThruCapabilities())); + final Vector<Integer> supportedDiagModes = + new Vector<Integer>(Arrays.asList(0x00, 0xFF)); + + msg.setPrerecordedSpeech(speech); + msg.setAudioPassThruCapabilities(audioPassThruCapabilities); + msg.setSupportedDiagModes(supportedDiagModes); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + final JSONArray speechJsonArray = + jsonObject.getJSONArray(PRERECORDED_SPEECH); + assertThat(speechJsonArray.length(), is(speech.size())); + assertThat(speechJsonArray.getString(0), is(speech.get(0).toString())); + assertThat(speechJsonArray.getString(1), is(speech.get(1).toString())); + assertThat( + jsonObject.getJSONArray(AUDIO_PASS_THRU_CAPABILITIES).length(), + is(audioPassThruCapabilities.size())); + final JSONArray modesJsonArray = + jsonObject.getJSONArray(SUPPORTED_DIAG_MODES); + assertThat(modesJsonArray.length(), is(supportedDiagModes.size())); + assertThat(modesJsonArray.getInt(0), is(supportedDiagModes.get(0))); + assertThat(modesJsonArray.getInt(1), is(supportedDiagModes.get(1))); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getPrerecordedSpeech(), nullValue()); + assertThat(msg.getAudioPassThruCapabilities(), nullValue()); + assertThat(msg.getSupportedDiagModes(), nullValue()); + } + + /// prerecordedSpeech + public void testPrerecordedSpeechGetterShouldReturnSetValue() + throws JSONException { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + final Vector<PrerecordedSpeech> speech = new Vector<PrerecordedSpeech>( + Arrays.asList(PrerecordedSpeech.HELP_JINGLE, + PrerecordedSpeech.INITIAL_JINGLE)); + msg.setPrerecordedSpeech(speech); + + assertThat(msg.getPrerecordedSpeech(), is(speech)); + } + + public void testSettingNullPrerecordedSpeechShouldRemoveValue() + throws JSONException { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + msg.setPrerecordedSpeech(new Vector<PrerecordedSpeech>( + Arrays.asList(PrerecordedSpeech.LISTEN_JINGLE))); + msg.setPrerecordedSpeech(null); + + assertThat(msg.getPrerecordedSpeech(), nullValue()); + } + + public void testDeserializedPrerecordedSpeechAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<PrerecordedSpeech> speech = new Vector<PrerecordedSpeech>( + Arrays.asList(PrerecordedSpeech.HELP_JINGLE, + PrerecordedSpeech.INITIAL_JINGLE)); + jsonObject.put(PRERECORDED_SPEECH, speech); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getPrerecordedSpeech(), is(speech)); + } + + public void testDeserializedPrerecordedSpeechAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(PRERECORDED_SPEECH, "INITIAL_JINGLE"); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getPrerecordedSpeech(), nullValue()); + } + + public void testDeserializedPrerecordedSpeechAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(PRERECORDED_SPEECH, 5); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getPrerecordedSpeech(), nullValue()); + } + + /// audioPassThruCapabilities + public void testAudioPassThruCapabilitiesGetterShouldReturnSetValue() + throws JSONException { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + final Vector<AudioPassThruCapabilities> audioPassThruCapabilities = + new Vector<AudioPassThruCapabilities>( + Arrays.asList(new AudioPassThruCapabilities())); + msg.setAudioPassThruCapabilities(audioPassThruCapabilities); + + assertThat(msg.getAudioPassThruCapabilities(), + is(audioPassThruCapabilities)); + } + + public void testSettingNullAudioPassThruCapabilitiesShouldRemoveValue() + throws JSONException { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + msg.setAudioPassThruCapabilities(new Vector<AudioPassThruCapabilities>( + Arrays.asList(new AudioPassThruCapabilities()))); + msg.setAudioPassThruCapabilities(null); + + assertThat(msg.getAudioPassThruCapabilities(), nullValue()); + } + + public void testDeserializedAudioPassThruCapabilitiesAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<AudioPassThruCapabilities> audioPassThruCapabilities = + new Vector<AudioPassThruCapabilities>( + Arrays.asList(new AudioPassThruCapabilities())); + jsonObject.put(AUDIO_PASS_THRU_CAPABILITIES, audioPassThruCapabilities); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getAudioPassThruCapabilities(), + is(audioPassThruCapabilities)); + } + + public void testDeserializedAudioPassThruCapabilitiesAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(AUDIO_PASS_THRU_CAPABILITIES, "INITIAL_JINGLE"); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getAudioPassThruCapabilities(), nullValue()); + } + + public void testDeserializedAudioPassThruCapabilitiesAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(AUDIO_PASS_THRU_CAPABILITIES, 5); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getAudioPassThruCapabilities(), nullValue()); + } + + /// supportedDiagModes + public void testSupportedDiagModesGetterShouldReturnSetValue() + throws JSONException { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + final Vector<Integer> supportedDiagModes = + new Vector<Integer>(Arrays.asList(0x00, 0xFF)); + msg.setSupportedDiagModes(supportedDiagModes); + + assertThat(msg.getSupportedDiagModes(), is(supportedDiagModes)); + } + + public void testSettingNullSupportedDiagModesShouldRemoveValue() + throws JSONException { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + msg.setSupportedDiagModes( + new Vector<Integer>(Arrays.asList(0x00, 0xFF))); + msg.setSupportedDiagModes(null); + + assertThat(msg.getSupportedDiagModes(), nullValue()); + } + + public void testDeserializedSupportedDiagModesAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<Integer> supportedDiagModes = + new Vector<Integer>(Arrays.asList(0x00, 0xFF)); + jsonObject.put(SUPPORTED_DIAG_MODES, supportedDiagModes); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSupportedDiagModes(), is(supportedDiagModes)); + } + + public void testDeserializedSupportedDiagModesAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SUPPORTED_DIAG_MODES, "INITIAL_JINGLE"); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSupportedDiagModes(), nullValue()); + } + + public void testDeserializedSupportedDiagModesAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SUPPORTED_DIAG_MODES, 5); + + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSupportedDiagModes(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceTest.java new file mode 100644 index 000000000..9b5410ff4 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceTest.java @@ -0,0 +1,115 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.constants.Names; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created with Android Studio. + * Author: Chernyshov Yuriy - Mobile Development + * Date: 2/25/14 + * Time: 11:55 AM + */ +public class RegisterAppInterfaceTest extends TestCase { + + private static final String TAG = "RegisterAppInterfaceTest"; + + private String mLegalHashId_Empty = ""; + private String mLegalHashId_Digits = "1234567890"; + private String mLegalHashId_Letters = "qwertyuiop"; + private String mLegalHashId_Symbols = "!@#$%^&*(){}><?/|_"; + private String mIllegalHashId = "dG8f5887951261W2a578o4L65X484eVl38tWr1n5474727m9iF6n2p" + + "620335PM18z322B28Q3XG38257kY5Pn8n3584596rU7J8ldG8f5887951261W2a578o4L65X484eVl" + + "38tWr1n5474727m9iF6n2p620335PM18z322B28Q3XG38257kY5Pn8n3584596rU7J8l"; + + public void testSetLegalHashId_Empty() { + RegisterAppInterface registerAppInterface = new RegisterAppInterface(); + registerAppInterface.setHashID(mLegalHashId_Empty); + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Empty); + } + + public void testSetLegalHashId_Digits() { + RegisterAppInterface registerAppInterface = new RegisterAppInterface(); + registerAppInterface.setHashID(mLegalHashId_Digits); + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Digits); + } + + public void testSetLegalHashId_Letters() { + RegisterAppInterface registerAppInterface = new RegisterAppInterface(); + registerAppInterface.setHashID(mLegalHashId_Letters); + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Letters); + } + + public void testSetLegalHashId_Symbols() { + RegisterAppInterface registerAppInterface = new RegisterAppInterface(); + registerAppInterface.setHashID(mLegalHashId_Symbols); + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Symbols); + } + + public void testSetLegalHashId_Empty_WithConstructor() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(Names.hashID, mLegalHashId_Empty); + + RegisterAppInterface registerAppInterface = new RegisterAppInterface( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Empty); + } + + public void testSetLegalHashId_Digits_WithConstructor() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(Names.hashID, mLegalHashId_Digits); + + RegisterAppInterface registerAppInterface = new RegisterAppInterface( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Digits); + } + + public void testSetLegalHashId_Letters_WithConstructor() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(Names.hashID, mLegalHashId_Letters); + + RegisterAppInterface registerAppInterface = new RegisterAppInterface( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Letters); + } + + public void testSetLegalHashId_Symbols_WithConstructor() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(Names.hashID, mLegalHashId_Symbols); + + RegisterAppInterface registerAppInterface = new RegisterAppInterface( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Symbols); + } + + public void testSetIllegalHashId_Symbols() { + RegisterAppInterface registerAppInterface = new RegisterAppInterface(); + try { + registerAppInterface.setHashID(mIllegalHashId); + fail(); + } catch (IllegalArgumentException e) { + /* expected */ + } + } + + public void testRemoveHashId() { + RegisterAppInterface registerAppInterface = new RegisterAppInterface(); + registerAppInterface.setHashID(mLegalHashId_Digits); + assertEquals(registerAppInterface.getHashID(), mLegalHashId_Digits); + + registerAppInterface.setHashID(null); + assertNull(registerAppInterface.getHashID()); + } +}
\ No newline at end of file diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ResetGlobalPropertiesTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ResetGlobalPropertiesTest.java new file mode 100644 index 000000000..6da6c4555 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ResetGlobalPropertiesTest.java @@ -0,0 +1,56 @@ +package com.ford.syncV4.proxy.rpc; + +import android.test.AndroidTestCase; + +import com.ford.syncV4.proxy.rpc.enums.GlobalProperty; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Vector; + +/** + * Created by Andrew Batutin on 11/18/13. + */ +public class ResetGlobalPropertiesTest extends AndroidTestCase{ + + public void testSerialization() throws JSONException { + ResetGlobalProperties msg = new ResetGlobalProperties(); + + Vector<GlobalProperty> properties = new Vector<GlobalProperty>(); + assertNotNull(msg); + properties.add(GlobalProperty.HELPPROMPT); + properties.add(GlobalProperty.MENUICON); + + msg.setProperties(properties); + + JSONObject jsonObject = msg.serializeJSON((byte) 2); + assertEquals(1, jsonObject.length()); + JSONArray result = jsonObject.getJSONArray("properties"); + assertEquals(GlobalProperty.HELPPROMPT, result.get(0)); + assertEquals(GlobalProperty.MENUICON, result.get(1)); + } + + public void testMenuIconIsSet() throws Exception { + ResetGlobalProperties msg = new ResetGlobalProperties(); + Vector<GlobalProperty> properties = new Vector<GlobalProperty>(); + assertNotNull(msg); + properties.add(GlobalProperty.MENUICON); + msg.setProperties(properties); + JSONObject jsonObject = msg.serializeJSON((byte) 2); + JSONArray result = jsonObject.getJSONArray("properties"); + assertEquals(GlobalProperty.MENUICON, result.get(0)); + } + + public void testMenuNameIsSet() throws Exception { + ResetGlobalProperties msg = new ResetGlobalProperties(); + Vector<GlobalProperty> properties = new Vector<GlobalProperty>(); + assertNotNull(msg); + properties.add(GlobalProperty.MENUNAME); + msg.setProperties(properties); + JSONObject jsonObject = msg.serializeJSON((byte) 2); + JSONArray result = jsonObject.getJSONArray("properties"); + assertEquals(GlobalProperty.MENUNAME, result.get(0)); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ScreenParamsTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ScreenParamsTest.java new file mode 100644 index 000000000..9e9b1acf7 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ScreenParamsTest.java @@ -0,0 +1,165 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for ScreenParams struct. + * + * Created by enikolsky on 2014-02-10. + */ +public class ScreenParamsTest extends TestCase { + private static final String RESOLUTION = "resolution"; + private static final String TOUCH_EVENT_AVAILABLE = "touchEventAvailable"; + + public void testMessageShouldBeCreated() { + ScreenParams msg = new ScreenParams(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + ScreenParams msg = new ScreenParams(); + + final ImageResolution resolution = new ImageResolution(); + final TouchEventCapabilities capabilities = + new TouchEventCapabilities(); + + msg.setResolution(resolution); + msg.setTouchEventAvailable(capabilities); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.has(RESOLUTION), is(true)); + assertThat(jsonObject.has(TOUCH_EVENT_AVAILABLE), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + ScreenParams msg = new ScreenParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getResolution(), nullValue()); + assertThat(msg.getTouchEventAvailable(), nullValue()); + } + + public void testResolutionGetterShouldReturnSetValue() + throws JSONException { + ScreenParams msg = new ScreenParams(); + + final ImageResolution resolution = new ImageResolution(); + msg.setResolution(resolution); + + assertThat(msg.getResolution(), is(resolution)); + } + + public void testSettingNullResolutionShouldRemoveValue() + throws JSONException { + ScreenParams msg = new ScreenParams(); + + msg.setResolution(new ImageResolution()); + msg.setResolution(null); + + assertThat(msg.getResolution(), nullValue()); + } + + public void testDeserializedResolutionAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final ImageResolution resolution = new ImageResolution(); + jsonObject.put(RESOLUTION, resolution); + + ScreenParams msg = new ScreenParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResolution(), is(resolution)); + } + + public void testDeserializedResolutionAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(RESOLUTION, "4"); + + ScreenParams msg = new ScreenParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResolution(), nullValue()); + } + + public void testDeserializedResolutionAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(RESOLUTION, 4); + + ScreenParams msg = new ScreenParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getResolution(), nullValue()); + } + + public void testTouchEventAvailableGetterShouldReturnSetValue() + throws JSONException { + ScreenParams msg = new ScreenParams(); + + final TouchEventCapabilities capabilities = + new TouchEventCapabilities(); + msg.setTouchEventAvailable(capabilities); + + assertThat(msg.getTouchEventAvailable(), is(capabilities)); + } + + public void testSettingNullTouchEventAvailableShouldRemoveValue() + throws JSONException { + ScreenParams msg = new ScreenParams(); + + msg.setTouchEventAvailable(new TouchEventCapabilities()); + msg.setTouchEventAvailable(null); + + assertThat(msg.getTouchEventAvailable(), nullValue()); + } + + public void testDeserializedTouchEventAvailableAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final TouchEventCapabilities capabilities = + new TouchEventCapabilities(); + jsonObject.put(TOUCH_EVENT_AVAILABLE, capabilities); + + ScreenParams msg = new ScreenParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTouchEventAvailable(), is(capabilities)); + } + + public void testDeserializedTouchEventAvailableAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(TOUCH_EVENT_AVAILABLE, "4"); + + ScreenParams msg = new ScreenParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTouchEventAvailable(), nullValue()); + } + + public void testDeserializedTouchEventAvailableAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(TOUCH_EVENT_AVAILABLE, 4); + + ScreenParams msg = new ScreenParams( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getTouchEventAvailable(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetDisplayLayoutResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetDisplayLayoutResponseTest.java new file mode 100644 index 000000000..98a054d19 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetDisplayLayoutResponseTest.java @@ -0,0 +1,320 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Arrays; +import java.util.Vector; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for SetDisplayLayoutResponse response. + * + * Created by enikolsky on 2014-02-10. + */ +public class SetDisplayLayoutResponseTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String DISPLAY_CAPABILITIES = "displayCapabilities"; + private static final String BUTTON_CAPABILITIES = "buttonCapabilities"; + private static final String SOFT_BUTTON_CAPABILITIES = + "softButtonCapabilities"; + private static final String PRESET_BANK_CAPABILITIES = + "presetBankCapabilities"; + + public void testMessageShouldBeCreated() { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + final DisplayCapabilities capabilities = new DisplayCapabilities(); + final Vector<ButtonCapabilities> buttonCapabilities = + new Vector<ButtonCapabilities>( + Arrays.asList(new ButtonCapabilities())); + final Vector<SoftButtonCapabilities> softButtonCapabilities = + new Vector<SoftButtonCapabilities>( + Arrays.asList(new SoftButtonCapabilities())); + final PresetBankCapabilities presetBankCapabilities = + new PresetBankCapabilities(); + + msg.setDisplayCapabilities(capabilities); + msg.setButtonCapabilities(buttonCapabilities); + msg.setSoftButtonCapabilities(softButtonCapabilities); + msg.setPresetBankCapabilities(presetBankCapabilities); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.has(DISPLAY_CAPABILITIES), is(true)); + assertThat(jsonObject.getJSONArray(BUTTON_CAPABILITIES).length(), + is(buttonCapabilities.size())); + assertThat(jsonObject.getJSONArray(SOFT_BUTTON_CAPABILITIES).length(), + is(softButtonCapabilities.size())); + assertThat(jsonObject.has(PRESET_BANK_CAPABILITIES), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getDisplayCapabilities(), nullValue()); + assertThat(msg.getButtonCapabilities(), nullValue()); + assertThat(msg.getSoftButtonCapabilities(), nullValue()); + assertThat(msg.getPresetBankCapabilities(), nullValue()); + } + + // displayCapabilities + public void testDisplayCapabilitiesGetterShouldReturnSetValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + final DisplayCapabilities capabilities = new DisplayCapabilities(); + msg.setDisplayCapabilities(capabilities); + + assertThat(msg.getDisplayCapabilities(), is(capabilities)); + } + + public void testSettingNullDisplayCapabilitiesShouldRemoveValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + msg.setDisplayCapabilities(new DisplayCapabilities()); + msg.setDisplayCapabilities(null); + + assertThat(msg.getDisplayCapabilities(), nullValue()); + } + + public void testDeserializedDisplayCapabilitiesAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final DisplayCapabilities capabilities = new DisplayCapabilities(); + jsonObject.put(DISPLAY_CAPABILITIES, capabilities); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getDisplayCapabilities(), is(capabilities)); + } + + public void testDeserializedDisplayCapabilitiesAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(DISPLAY_CAPABILITIES, "4.0f"); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getDisplayCapabilities(), nullValue()); + } + + public void testDeserializedDisplayCapabilitiesAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(DISPLAY_CAPABILITIES, 5); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getDisplayCapabilities(), nullValue()); + } + + // buttonCapabilities + public void testButtonCapabilitiesGetterShouldReturnSetValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + final Vector<ButtonCapabilities> buttonCapabilities = + new Vector<ButtonCapabilities>( + Arrays.asList(new ButtonCapabilities())); + msg.setButtonCapabilities(buttonCapabilities); + + assertThat(msg.getButtonCapabilities(), is(buttonCapabilities)); + } + + public void testSettingNullButtonCapabilitiesShouldRemoveValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + msg.setButtonCapabilities(new Vector<ButtonCapabilities>()); + msg.setButtonCapabilities(null); + + assertThat(msg.getButtonCapabilities(), nullValue()); + } + + public void testDeserializedButtonCapabilitiesAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<ButtonCapabilities> buttonCapabilities = + new Vector<ButtonCapabilities>( + Arrays.asList(new ButtonCapabilities())); + jsonObject.put(BUTTON_CAPABILITIES, buttonCapabilities); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getButtonCapabilities(), is(buttonCapabilities)); + } + + public void testDeserializedButtonCapabilitiesAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(BUTTON_CAPABILITIES, "4.0f"); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getButtonCapabilities(), nullValue()); + } + + public void testDeserializedButtonCapabilitiesAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(BUTTON_CAPABILITIES, 5); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getButtonCapabilities(), nullValue()); + } + + // softButtonCapabilities + public void testSoftButtonCapabilitiesGetterShouldReturnSetValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + final Vector<SoftButtonCapabilities> softButtonCapabilities = + new Vector<SoftButtonCapabilities>( + Arrays.asList(new SoftButtonCapabilities())); + msg.setSoftButtonCapabilities(softButtonCapabilities); + + assertThat(msg.getSoftButtonCapabilities(), is(softButtonCapabilities)); + } + + public void testSettingNullSoftButtonCapabilitiesShouldRemoveValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + msg.setSoftButtonCapabilities(new Vector<SoftButtonCapabilities>()); + msg.setSoftButtonCapabilities(null); + + assertThat(msg.getSoftButtonCapabilities(), nullValue()); + } + + public void testDeserializedSoftButtonCapabilitiesAsVectorShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Vector<SoftButtonCapabilities> softButtonCapabilities = + new Vector<SoftButtonCapabilities>( + Arrays.asList(new SoftButtonCapabilities())); + jsonObject.put(SOFT_BUTTON_CAPABILITIES, softButtonCapabilities); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSoftButtonCapabilities(), is(softButtonCapabilities)); + } + + public void testDeserializedSoftButtonCapabilitiesAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SOFT_BUTTON_CAPABILITIES, "4.0f"); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSoftButtonCapabilities(), nullValue()); + } + + public void testDeserializedSoftButtonCapabilitiesAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SOFT_BUTTON_CAPABILITIES, 5); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSoftButtonCapabilities(), nullValue()); + } + + // presetBankCapabilities + public void testPresetBankCapabilitiesGetterShouldReturnSetValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + final PresetBankCapabilities capabilities = + new PresetBankCapabilities(); + msg.setPresetBankCapabilities(capabilities); + + assertThat(msg.getPresetBankCapabilities(), is(capabilities)); + } + + public void testSettingNullPresetBankCapabilitiesShouldRemoveValue() + throws JSONException { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + msg.setPresetBankCapabilities(new PresetBankCapabilities()); + msg.setPresetBankCapabilities(null); + + assertThat(msg.getPresetBankCapabilities(), nullValue()); + } + + public void testDeserializedPresetBankCapabilitiesAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final PresetBankCapabilities capabilities = + new PresetBankCapabilities(); + jsonObject.put(PRESET_BANK_CAPABILITIES, capabilities); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getPresetBankCapabilities(), is(capabilities)); + } + + public void testDeserializedPresetBankCapabilitiesAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(PRESET_BANK_CAPABILITIES, "4.0f"); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getPresetBankCapabilities(), nullValue()); + } + + public void testDeserializedPresetBankCapabilitiesAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(PRESET_BANK_CAPABILITIES, 5); + + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getPresetBankCapabilities(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetGlobalPropertiesTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetGlobalPropertiesTest.java new file mode 100644 index 000000000..1021e7e88 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetGlobalPropertiesTest.java @@ -0,0 +1,166 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created by enikolsky on 2013-10-02. + */ +public class SetGlobalPropertiesTest extends TestCase { + private static final String MENU_TITLE = "menuTitle"; + private static final String MENU_ICON = "menuIcon"; + private static final String KEYBOARD_PROPERTIES = "keyboardProperties"; + + public void testSerialization() throws JSONException { + SetGlobalProperties msg = new SetGlobalProperties(); + assertNotNull(msg); + + final String menuTitle = "title"; + final Image menuImage = new Image(); + final KeyboardProperties kbdProperties = new KeyboardProperties(); + + msg.setMenuTitle(menuTitle); + msg.setMenuIcon(menuImage); + msg.setKeyboardProperties(kbdProperties); + + JSONObject jsonObject = msg.serializeJSON((byte) 2); + assertEquals(3, jsonObject.length()); + assertEquals(menuTitle, jsonObject.getString(MENU_TITLE)); + assertTrue(jsonObject.has(MENU_ICON)); + assertTrue(jsonObject.has(KEYBOARD_PROPERTIES)); + } + + public void testNullDeserialization() throws JSONException { + JSONObject jsonObject = new JSONObject(); + SetGlobalProperties msg = new SetGlobalProperties(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertNull(msg.getMenuTitle()); + assertNull(msg.getMenuIcon()); + assertNull(msg.getKeyboardProperties()); + } + + public void testMenuTitleAPI() { + SetGlobalProperties msg = new SetGlobalProperties(); + + final String menuTitle = "111"; + msg.setMenuTitle(menuTitle); + + assertEquals(menuTitle, msg.getMenuTitle()); + } + + public void testRemoveMenuTitle() { + SetGlobalProperties msg = new SetGlobalProperties(); + msg.setMenuTitle("42"); + msg.setMenuTitle(null); + assertNull(msg.getMenuTitle()); + } + + public void testGetMenuTitle() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final String menuTitle = "asdf"; + jsonObject.put(MENU_TITLE, menuTitle); + + SetGlobalProperties msg = new SetGlobalProperties(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertEquals(menuTitle, msg.getMenuTitle()); + } + + public void testGetMenuTitleIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MENU_TITLE, 42); + + SetGlobalProperties msg = new SetGlobalProperties(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertNull(msg.getMenuTitle()); + } + + private JSONObject paramsToRequestObject(JSONObject paramsObject) + throws JSONException { + JSONObject jsonObject = new JSONObject(); + JSONObject requestObject = new JSONObject(); + jsonObject.put("request", requestObject); + requestObject.put("parameters", paramsObject); + return jsonObject; + } + + public void testMenuIconAPI() { + SetGlobalProperties msg = new SetGlobalProperties(); + + final Image menuIcon = new Image(); + msg.setMenuIcon(menuIcon); + + assertEquals(menuIcon, msg.getMenuIcon()); + } + + public void testRemoveMenuIcon() { + SetGlobalProperties msg = new SetGlobalProperties(); + msg.setMenuIcon(new Image()); + msg.setMenuIcon(null); + assertNull(msg.getMenuIcon()); + } + + public void testGetMenuIcon() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Image menuIcon = new Image(); + jsonObject.put(MENU_ICON, menuIcon); + + SetGlobalProperties msg = new SetGlobalProperties(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertEquals(menuIcon, msg.getMenuIcon()); + } + + public void testGetMenuIconIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(MENU_ICON, 42); + + SetGlobalProperties msg = new SetGlobalProperties(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertNull(msg.getMenuIcon()); + } + + public void testKeyboardPropertiesAPI() { + SetGlobalProperties msg = new SetGlobalProperties(); + + final KeyboardProperties keyboardProperties = new KeyboardProperties(); + msg.setKeyboardProperties(keyboardProperties); + + assertEquals(keyboardProperties, msg.getKeyboardProperties()); + } + + public void testRemoveKeyboardProperties() { + SetGlobalProperties msg = new SetGlobalProperties(); + msg.setKeyboardProperties(new KeyboardProperties()); + msg.setKeyboardProperties(null); + assertNull(msg.getKeyboardProperties()); + } + + public void testGetKeyboardProperties() throws JSONException { + JSONObject jsonObject = new JSONObject(); + final KeyboardProperties keyboardProperties = new KeyboardProperties(); + jsonObject.put(KEYBOARD_PROPERTIES, keyboardProperties); + + SetGlobalProperties msg = new SetGlobalProperties(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertEquals(keyboardProperties, msg.getKeyboardProperties()); + } + + public void testGetKeyboardPropertiesIncorrect() throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(KEYBOARD_PROPERTIES, 42); + + SetGlobalProperties msg = new SetGlobalProperties(JsonRPCMarshaller + .deserializeJSONObject(paramsToRequestObject(jsonObject))); + assertNotNull(msg); + assertNull(msg.getKeyboardProperties()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetMediaClockTimerTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetMediaClockTimerTest.java new file mode 100644 index 000000000..64ffb38d9 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetMediaClockTimerTest.java @@ -0,0 +1,106 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for SetMediaClockTimer request. + * + * Created by enikolsky on 2014-02-12. + */ +public class SetMediaClockTimerTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String END_TIME = "endTime"; + + public void testMessageShouldBeCreated() { + SetMediaClockTimer msg = new SetMediaClockTimer(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + SetMediaClockTimer msg = new SetMediaClockTimer(); + + final StartTime endTime = new StartTime(); + + msg.setEndTime(endTime); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.has(END_TIME), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + SetMediaClockTimer msg = new SetMediaClockTimer( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getEndTime(), nullValue()); + } + + public void testEndTimeGetterShouldReturnSetValue() throws JSONException { + SetMediaClockTimer msg = new SetMediaClockTimer(); + + final StartTime endTime = new StartTime(); + msg.setEndTime(endTime); + + assertThat(msg.getEndTime(), is(endTime)); + } + + public void testSettingNullEndTimeShouldRemoveValue() throws JSONException { + SetMediaClockTimer msg = new SetMediaClockTimer(); + + msg.setEndTime(new StartTime()); + msg.setEndTime(null); + + assertThat(msg.getEndTime(), nullValue()); + } + + public void testDeserializedEndTimeAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final StartTime endTime = new StartTime(); + jsonObject.put(END_TIME, endTime); + + SetMediaClockTimer msg = new SetMediaClockTimer( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getEndTime(), is(endTime)); + } + + public void testDeserializedEndTimeAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(END_TIME, 4); + + SetMediaClockTimer msg = new SetMediaClockTimer( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getEndTime(), nullValue()); + } + + public void testDeserializedEndTimeAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(END_TIME, "4.0f"); + + SetMediaClockTimer msg = new SetMediaClockTimer( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getEndTime(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ShowTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ShowTest.java new file mode 100644 index 000000000..353448486 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ShowTest.java @@ -0,0 +1,105 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for Show request (new params only). + * + * Created by enikolsky on 2014-02-13. + */ +public class ShowTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String SECONDARY_GRAPHIC = "secondaryGraphic"; + + public void testMessageShouldBeCreated() { + Show msg = new Show(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + Show msg = new Show(); + + final Image graphic = new Image(); + + msg.setSecondaryGraphic(graphic); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.has(SECONDARY_GRAPHIC), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + Show msg = new Show(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSecondaryGraphic(), nullValue()); + } + + // secondaryGraphic + public void testSecondaryGraphicGetterShouldReturnSetValue() + throws JSONException { + Show msg = new Show(); + + final Image graphic = new Image(); + msg.setSecondaryGraphic(graphic); + + assertThat(msg.getSecondaryGraphic(), is(graphic)); + } + + public void testSettingNullSecondaryGraphicShouldRemoveValue() + throws JSONException { + Show msg = new Show(); + + msg.setSecondaryGraphic(new Image()); + msg.setSecondaryGraphic(null); + + assertThat(msg.getSecondaryGraphic(), nullValue()); + } + + public void testDeserializedSecondaryGraphicAsStructShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final Image graphic = new Image(); + jsonObject.put(SECONDARY_GRAPHIC, graphic); + + Show msg = new Show(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSecondaryGraphic(), is(graphic)); + } + + public void testDeserializedSecondaryGraphicAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SECONDARY_GRAPHIC, 42); + + Show msg = new Show(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSecondaryGraphic(), nullValue()); + } + + public void testDeserializedSecondaryGraphicAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SECONDARY_GRAPHIC, "true"); + + Show msg = new Show(JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSecondaryGraphic(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataResponseTest.java new file mode 100644 index 000000000..dea07c486 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataResponseTest.java @@ -0,0 +1,111 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.VehicleDataResultCode; +import com.ford.syncV4.proxy.rpc.enums.VehicleDataType; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for SubscribeVehicleDataResponse response (new params only). + * + * Created by enikolsky on 2014-01-27. + */ +public class SubscribeVehicleDataResponseTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String STEERING_WHEEL_ANGLE = "steeringWheelAngle"; + + public void testMessageShouldBeCreated() { + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse(); + + msg.setSteeringWheelAngle(new VehicleDataResult()); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.has(STEERING_WHEEL_ANGLE), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testSteeringWheelAngleGetterShouldReturnSetValue() + throws JSONException { + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse(); + + final VehicleDataResult swa = new VehicleDataResult(); + swa.setResultCode(VehicleDataResultCode.DATA_ALREADY_SUBSCRIBED); + msg.setSteeringWheelAngle(swa); + + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testSettingNullSteeringWheelAngleShouldRemoveValue() + throws JSONException { + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse(); + + msg.setSteeringWheelAngle(new VehicleDataResult()); + msg.setSteeringWheelAngle(null); + + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final VehicleDataResult swa = new VehicleDataResult(); + swa.setResultCode(VehicleDataResultCode.DATA_NOT_AVAILABLE); + swa.setDataType(VehicleDataType.VEHICLEDATA_STEERINGWHEEL); + jsonObject.put(STEERING_WHEEL_ANGLE, swa); + + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testDeserializedSteeringWheelAngleAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, 42); + + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, "true"); + + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataTest.java new file mode 100644 index 000000000..7ce85dc52 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataTest.java @@ -0,0 +1,108 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for SubscribeVehicleData request (new params only). + * + * Created by enikolsky on 2014-01-27. + */ +public class SubscribeVehicleDataTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String STEERING_WHEEL_ANGLE = "steeringWheelAngle"; + + public void testMessageShouldBeCreated() { + SubscribeVehicleData msg = new SubscribeVehicleData(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + SubscribeVehicleData msg = new SubscribeVehicleData(); + + final boolean swa = true; + + msg.setSteeringWheelAngle(swa); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getBoolean(STEERING_WHEEL_ANGLE), is(swa)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + SubscribeVehicleData msg = new SubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testSteeringWheelAngleGetterShouldReturnSetValue() + throws JSONException { + SubscribeVehicleData msg = new SubscribeVehicleData(); + + final boolean swa = true; + msg.setSteeringWheelAngle(swa); + + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testSettingNullSteeringWheelAngleShouldRemoveValue() + throws JSONException { + SubscribeVehicleData msg = new SubscribeVehicleData(); + + msg.setSteeringWheelAngle(true); + msg.setSteeringWheelAngle(null); + + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final boolean swa = true; + jsonObject.put(STEERING_WHEEL_ANGLE, swa); + + SubscribeVehicleData msg = new SubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testDeserializedSteeringWheelAngleAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, 42); + + SubscribeVehicleData msg = new SubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, "true"); + + SubscribeVehicleData msg = new SubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SystemRequestTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SystemRequestTest.java new file mode 100644 index 000000000..91316d655 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SystemRequestTest.java @@ -0,0 +1,105 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.proxy.rpc.enums.RequestType; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for SystemRequest class. + * + * Created by enikolsky on 2014-01-23. + */ +public class SystemRequestTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String REQUEST_TYPE = "requestType"; + + public void testMessageShouldBeCreated() { + SystemRequest msg = new SystemRequest(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + SystemRequest msg = new SystemRequest(); + + final RequestType requestType = RequestType.AUTH_REQUEST; + + msg.setRequestType(requestType); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getString(REQUEST_TYPE), + is(requestType.toString())); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + SystemRequest msg = new SystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), nullValue()); + } + + public void testGetRequestTypeShouldReturnSetValue() throws JSONException { + SystemRequest msg = new SystemRequest(); + + final RequestType requestType = RequestType.AUTH_ACK; + msg.setRequestType(requestType); + + assertThat(msg.getRequestType(), is(requestType)); + } + + public void testSettingNullRequestTypeShouldRemoveValue() + throws JSONException { + SystemRequest msg = new SystemRequest(); + + msg.setRequestType(RequestType.AUTH_CHALLENGE); + msg.setRequestType(null); + + assertThat(msg.getRequestType(), nullValue()); + } + + public void testDeserializedRequestTypeShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final RequestType requestType = RequestType.AUTH_ACK; + jsonObject.put(REQUEST_TYPE, requestType); + + SystemRequest msg = new SystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), is(requestType)); + } + + public void testDeserializedRequestTypeAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final RequestType requestType = RequestType.AUTH_ACK; + jsonObject.put(REQUEST_TYPE, requestType.toString()); + + SystemRequest msg = new SystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), is(requestType)); + } + + public void testDeserializedRequestTypeAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(REQUEST_TYPE, 1); + + SystemRequest msg = new SystemRequest( + TestCommon.deserializeJSONRequestObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getRequestType(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TestCommon.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TestCommon.java new file mode 100644 index 000000000..96dce2bee --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TestCommon.java @@ -0,0 +1,90 @@ +package com.ford.syncV4.proxy.rpc; + +import android.test.InstrumentationTestCase; + +import com.ford.syncV4.exception.SyncException; +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.protocol.ProtocolMessage; +import com.ford.syncV4.protocol.WiProProtocol; +import com.ford.syncV4.protocol.enums.FunctionID; +import com.ford.syncV4.proxy.SyncProxyALM; +import com.ford.syncV4.proxy.interfaces.IProxyListenerALM; +import com.ford.syncV4.syncConnection.SyncConnection; +import com.ford.syncV4.util.TestConfig; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; +import java.util.Random; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Common methods for testing classes. + * + * Created by enikolsky on 2013-10-29. + */ +public class TestCommon { + public static JSONObject paramsToRequestObject(JSONObject paramsObject) + throws JSONException { + JSONObject jsonObject = new JSONObject(); + JSONObject requestObject = new JSONObject(); + jsonObject.put("request", requestObject); + requestObject.put("parameters", paramsObject); + return jsonObject; + } + + public static void setupMocking(InstrumentationTestCase testCase) { + System.setProperty("dexmaker.dexcache", testCase.getInstrumentation() + .getTargetContext() + .getCacheDir() + .getPath()); + } + + public static SyncProxyALM getSyncProxyALMNoTransport( + IProxyListenerALM proxyListener) throws SyncException { + SyncConnection connectionMock = mock(SyncConnection.class); + when(connectionMock.getIsConnected()).thenReturn(true); + WiProProtocol protocolMock = mock(WiProProtocol.class); + when(connectionMock.getWiProProtocol()).thenReturn(protocolMock); + + return new SyncProxyALM(proxyListener, null, "!", null, null, true, + null, null, null, null, null, null, false, false, 2, null, + connectionMock, new TestConfig()); + } + + public static byte[] getRandomBytes(int dataSize) { + // to simplify matching if bytes mess up + final byte[] data = new byte[dataSize]; + new Random().nextBytes(data); + return data; + } + + public static Hashtable<String, Object> deserializeJSONRequestObject( + JSONObject jsonObject) throws JSONException { + return JsonRPCMarshaller.deserializeJSONObject( + paramsToRequestObject(jsonObject)); + } + + public static ProtocolMessage createProtocolMessage( + final String functionName, final Hashtable<String, Object> params, + final byte rpcType, final int corrID) throws JSONException { + ProtocolMessage pm = new ProtocolMessage(); + pm.setCorrID(corrID); + + if (params != null) { + JSONObject paramsObject = + JsonRPCMarshaller.serializeHashtable(params); + byte[] paramsData = paramsObject.toString().getBytes(); + pm.setData(paramsData, paramsData.length); + pm.setJsonSize(paramsData.length); + } + + pm.setFunctionID(FunctionID.getFunctionID(functionName)); + pm.setRPCType(rpcType); + + return pm; + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TireStatusTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TireStatusTest.java new file mode 100644 index 000000000..ec19ca01e --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TireStatusTest.java @@ -0,0 +1,105 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.WarningLightStatus; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for TireStatus struct (only new parameters). + * + * Created by enikolsky on 2014-02-07. + */ +public class TireStatusTest extends TestCase { + private static final String PRESSURE_TELLTALE = "pressureTelltale"; + + public void testMessageShouldBeCreated() { + TireStatus msg = new TireStatus(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + TireStatus msg = new TireStatus(); + + final WarningLightStatus wls = WarningLightStatus.FLASH; + + msg.setPressureTelltale(wls); + + JSONObject jsonObject = msg.serializeJSON(); + assertThat(jsonObject.getString(PRESSURE_TELLTALE), is(wls.toString())); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + TireStatus msg = new TireStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + + assertThat(msg, notNullValue()); + assertThat(msg.getPressureTelltale(), nullValue()); + } + + public void testPressureTelltaleGetterShouldReturnSetValue() + throws JSONException { + TireStatus msg = new TireStatus(); + + final WarningLightStatus wls = WarningLightStatus.FLASH; + msg.setPressureTelltale(wls); + + assertThat(msg.getPressureTelltale(), is(wls)); + } + + public void testSettingNullPressureTelltaleShouldRemoveValue() + throws JSONException { + TireStatus msg = new TireStatus(); + + msg.setPressureTelltale(WarningLightStatus.NOT_USED); + msg.setPressureTelltale(null); + + assertThat(msg.getPressureTelltale(), nullValue()); + } + + public void testDeserializedPressureTelltaleShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final WarningLightStatus wls = WarningLightStatus.FLASH; + jsonObject.put(PRESSURE_TELLTALE, wls); + + TireStatus msg = new TireStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getPressureTelltale(), is(wls)); + } + + public void testDeserializedPressureTelltaleAsStringShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final WarningLightStatus wls = WarningLightStatus.FLASH; + jsonObject.put(PRESSURE_TELLTALE, wls.toString()); + + TireStatus msg = new TireStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getPressureTelltale(), is(wls)); + } + + public void testDeserializedPressureTelltaleAsFloatShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(PRESSURE_TELLTALE, 4.0f); + + TireStatus msg = new TireStatus( + JsonRPCMarshaller.deserializeJSONObject(jsonObject)); + assertThat(msg, notNullValue()); + assertThat(msg.getPressureTelltale(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataResponseTest.java new file mode 100644 index 000000000..42734874d --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataResponseTest.java @@ -0,0 +1,115 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; +import com.ford.syncV4.proxy.rpc.enums.VehicleDataResultCode; +import com.ford.syncV4.proxy.rpc.enums.VehicleDataType; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for UnsubscribeVehicleDataResponse response (new params only). + * + * Created by enikolsky on 2014-01-27. + */ +public class UnsubscribeVehicleDataResponseTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String STEERING_WHEEL_ANGLE = "steeringWheelAngle"; + + public void testMessageShouldBeCreated() { + UnsubscribeVehicleDataResponse msg = + new UnsubscribeVehicleDataResponse(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + UnsubscribeVehicleDataResponse msg = + new UnsubscribeVehicleDataResponse(); + + msg.setSteeringWheelAngle(new VehicleDataResult()); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.has(STEERING_WHEEL_ANGLE), is(true)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + UnsubscribeVehicleDataResponse msg = new UnsubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testSteeringWheelAngleGetterShouldReturnSetValue() + throws JSONException { + UnsubscribeVehicleDataResponse msg = + new UnsubscribeVehicleDataResponse(); + + final VehicleDataResult swa = new VehicleDataResult(); + swa.setResultCode(VehicleDataResultCode.DATA_ALREADY_SUBSCRIBED); + msg.setSteeringWheelAngle(swa); + + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testSettingNullSteeringWheelAngleShouldRemoveValue() + throws JSONException { + UnsubscribeVehicleDataResponse msg = + new UnsubscribeVehicleDataResponse(); + + msg.setSteeringWheelAngle(new VehicleDataResult()); + msg.setSteeringWheelAngle(null); + + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final VehicleDataResult swa = new VehicleDataResult(); + swa.setResultCode(VehicleDataResultCode.DATA_NOT_AVAILABLE); + swa.setDataType(VehicleDataType.VEHICLEDATA_STEERINGWHEEL); + jsonObject.put(STEERING_WHEEL_ANGLE, swa); + + UnsubscribeVehicleDataResponse msg = new UnsubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testDeserializedSteeringWheelAngleAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, 42); + + UnsubscribeVehicleDataResponse msg = new UnsubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, "true"); + + UnsubscribeVehicleDataResponse msg = new UnsubscribeVehicleDataResponse( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataTest.java new file mode 100644 index 000000000..01c1089a8 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataTest.java @@ -0,0 +1,108 @@ +package com.ford.syncV4.proxy.rpc; + +import com.ford.syncV4.marshal.JsonRPCMarshaller; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for UnubscribeVehicleData request (new params only). + * + * Created by enikolsky on 2014-01-27. + */ +public class UnsubscribeVehicleDataTest extends TestCase { + private static final byte PROTOCOL_VERSION = (byte) 2; + private static final String STEERING_WHEEL_ANGLE = "steeringWheelAngle"; + + public void testMessageShouldBeCreated() { + UnsubscribeVehicleData msg = new UnsubscribeVehicleData(); + assertThat(msg, notNullValue()); + } + + public void testSerializedMessageShouldContainAllSetFields() + throws JSONException { + UnsubscribeVehicleData msg = new UnsubscribeVehicleData(); + + final boolean swa = true; + + msg.setSteeringWheelAngle(swa); + + JSONObject jsonObject = msg.serializeJSON(PROTOCOL_VERSION); + assertThat(jsonObject.getBoolean(STEERING_WHEEL_ANGLE), is(swa)); + } + + public void testDeserializedMessageWithoutParamsShouldContainNullFields() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + UnsubscribeVehicleData msg = new UnsubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testSteeringWheelAngleGetterShouldReturnSetValue() + throws JSONException { + UnsubscribeVehicleData msg = new UnsubscribeVehicleData(); + + final boolean swa = true; + msg.setSteeringWheelAngle(swa); + + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testSettingNullSteeringWheelAngleShouldRemoveValue() + throws JSONException { + UnsubscribeVehicleData msg = new UnsubscribeVehicleData(); + + msg.setSteeringWheelAngle(true); + msg.setSteeringWheelAngle(null); + + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleShouldContainValue() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + final boolean swa = true; + jsonObject.put(STEERING_WHEEL_ANGLE, swa); + + UnsubscribeVehicleData msg = new UnsubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), is(swa)); + } + + public void testDeserializedSteeringWheelAngleAsIntShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, 42); + + UnsubscribeVehicleData msg = new UnsubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } + + public void testDeserializedSteeringWheelAngleAsStringShouldBeNull() + throws JSONException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(STEERING_WHEEL_ANGLE, "true"); + + UnsubscribeVehicleData msg = new UnsubscribeVehicleData( + JsonRPCMarshaller.deserializeJSONObject( + TestCommon.paramsToRequestObject(jsonObject))); + assertThat(msg, notNullValue()); + assertThat(msg.getSteeringWheelAngle(), nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/AmbientLightStatusTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/AmbientLightStatusTest.java new file mode 100644 index 000000000..a5b0a699b --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/AmbientLightStatusTest.java @@ -0,0 +1,107 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for AmbientLightStatus enum. + * + * Created by enikolsky on 2014-02-07. + */ +public class AmbientLightStatusTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(AmbientLightStatus.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + AmbientLightStatus.NIGHT, AmbientLightStatus.TWILIGHT_1, + AmbientLightStatus.TWILIGHT_2, + AmbientLightStatus.TWILIGHT_3, + AmbientLightStatus.TWILIGHT_4, AmbientLightStatus.DAY, + AmbientLightStatus.UNKNOWN, + AmbientLightStatus.INVALID)); + } + + public void testValueForStringNIGHTShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("NIGHT"), + is(AmbientLightStatus.NIGHT)); + } + + public void testValueForStringTWILIGHT_1ShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("TWILIGHT_1"), + is(AmbientLightStatus.TWILIGHT_1)); + } + + public void testValueForStringTWILIGHT_2ShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("TWILIGHT_2"), + is(AmbientLightStatus.TWILIGHT_2)); + } + + public void testValueForStringTWILIGHT_3ShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("TWILIGHT_3"), + is(AmbientLightStatus.TWILIGHT_3)); + } + + public void testValueForStringTWILIGHT_4ShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("TWILIGHT_4"), + is(AmbientLightStatus.TWILIGHT_4)); + } + + public void testValueForStringDAYShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("DAY"), + is(AmbientLightStatus.DAY)); + } + + public void testValueForStringUNKNOWNShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("UNKNOWN"), + is(AmbientLightStatus.UNKNOWN)); + } + + public void testValueForStringINVALIDShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.valueForString("INVALID"), + is(AmbientLightStatus.INVALID)); + } + + public void testNIGHTToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.NIGHT.toString(), is("NIGHT")); + } + + public void testTWILIGHT_1ToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.TWILIGHT_1.toString(), is("TWILIGHT_1")); + } + + public void testTWILIGHT_2ToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.TWILIGHT_2.toString(), is("TWILIGHT_2")); + } + + public void testTWILIGHT_3ToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.TWILIGHT_3.toString(), is("TWILIGHT_3")); + } + + public void testTWILIGHT_4ToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.TWILIGHT_4.toString(), is("TWILIGHT_4")); + } + + public void testDAYToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.DAY.toString(), is("DAY")); + } + + public void testUNKNOWNToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.UNKNOWN.toString(), is("UNKNOWN")); + } + + public void testINVALIDToStringShouldReturnCorrectValue() { + assertThat(AmbientLightStatus.INVALID.toString(), is("INVALID")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + AmbientLightStatus.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ButtonNameTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ButtonNameTest.java new file mode 100644 index 000000000..f54f3a626 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ButtonNameTest.java @@ -0,0 +1,120 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for ButtonName enum. + * + * Created by enikolsky on 2014-01-31. + */ +public class ButtonNameTest extends TestCase { + public void testAllValuesShouldBeDefined() { + assertThat(ButtonName.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + ButtonName.OK, ButtonName.SEEKLEFT, + ButtonName.SEEKRIGHT, ButtonName.TUNEUP, + ButtonName.TUNEDOWN, ButtonName.PRESET_0, + ButtonName.PRESET_1, ButtonName.PRESET_2, + ButtonName.PRESET_3, ButtonName.PRESET_4, + ButtonName.PRESET_5, ButtonName.PRESET_6, + ButtonName.PRESET_7, ButtonName.PRESET_8, + ButtonName.PRESET_9, ButtonName.CUSTOM_BUTTON, + ButtonName.SEARCH)); + } + + public void testValueForStringOKShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("OK"), is(ButtonName.OK)); + } + + public void testValueForStringSeekLeftShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("SEEKLEFT"), is(ButtonName.SEEKLEFT)); + } + + public void testValueForStringSeekRightShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("SEEKRIGHT"), is(ButtonName.SEEKRIGHT)); + } + + public void testValueForStringTuneUpShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("TUNEUP"), is(ButtonName.TUNEUP)); + } + + public void testValueForStringTuneDownShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("TUNEDOWN"), is(ButtonName.TUNEDOWN)); + } + + public void testValueForStringPreset0ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_0"), is(ButtonName.PRESET_0)); + } + + public void testValueForStringPreset1ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_1"), is(ButtonName.PRESET_1)); + } + + public void testValueForStringPreset2ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_2"), is(ButtonName.PRESET_2)); + } + + public void testValueForStringPreset3ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_3"), is(ButtonName.PRESET_3)); + } + + public void testValueForStringPreset4ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_4"), is(ButtonName.PRESET_4)); + } + + public void testValueForStringPreset5ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_5"), is(ButtonName.PRESET_5)); + } + + public void testValueForStringPreset6ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_6"), is(ButtonName.PRESET_6)); + } + + public void testValueForStringPreset7ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_7"), is(ButtonName.PRESET_7)); + } + + public void testValueForStringPreset8ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_8"), is(ButtonName.PRESET_8)); + } + + public void testValueForStringPreset9ShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("PRESET_9"), is(ButtonName.PRESET_9)); + } + + public void testValueForStringCustomButtonShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("CUSTOM_BUTTON"), + is(ButtonName.CUSTOM_BUTTON)); + } + + public void testValueForStringSearchShouldReturnCorrectValue() { + assertThat(ButtonName.valueOf("SEARCH"), is(ButtonName.SEARCH)); + } + + public void testValueForStringUnknownShouldReturnNull() { + assertThat(ButtonName.valueForString("Unknown"), nullValue()); + } + + public void testIndexForPresetButton0ShouldReturn0() { + assertThat(ButtonName.indexForPresetButton(ButtonName.PRESET_0), is(0)); + } + + public void testIndexForPresetButton1ShouldReturn1() { + assertThat(ButtonName.indexForPresetButton(ButtonName.PRESET_1), is(1)); + } + + public void testIndexForPresetButton9ShouldReturn9() { + assertThat(ButtonName.indexForPresetButton(ButtonName.PRESET_9), is(9)); + } + + public void testIndexForPresetButtonCustomButtonShouldReturnNull() { + assertThat(ButtonName.indexForPresetButton(ButtonName.CUSTOM_BUTTON), + nullValue()); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/DisplayTypeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/DisplayTypeTest.java new file mode 100644 index 000000000..4ae6d84c6 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/DisplayTypeTest.java @@ -0,0 +1,117 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for DisplayType enum. + * + * Created by enikolsky on 2014-02-06. + */ +public class DisplayTypeTest extends TestCase { + public void testAllValuesShouldBeDefined() { + assertThat(DisplayType.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + DisplayType.CID, DisplayType.TYPE2, DisplayType.TYPE5, + DisplayType.NGN, DisplayType.GEN2_8_DMA, + DisplayType.GEN2_6_DMA, DisplayType.MFD3, + DisplayType.MFD4, DisplayType.MFD5, + DisplayType.GEN3_8_INCH)); + } + + public void testValueForStringCIDShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("CID"), is(DisplayType.CID)); + } + + public void testValueForStringTYPE2ShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("TYPE2"), is(DisplayType.TYPE2)); + } + + public void testValueForStringTYPE5ShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("TYPE5"), is(DisplayType.TYPE5)); + } + + public void testValueForStringNGNShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("NGN"), is(DisplayType.NGN)); + } + + public void testValueForStringGEN2_8_DMAShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("GEN2_8_DMA"), + is(DisplayType.GEN2_8_DMA)); + } + + public void testValueForStringGEN2_6_DMAShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("GEN2_6_DMA"), + is(DisplayType.GEN2_6_DMA)); + } + + public void testValueForStringMFD3ShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("MFD3"), is(DisplayType.MFD3)); + } + + public void testValueForStringMFD4ShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("MFD4"), is(DisplayType.MFD4)); + } + + public void testValueForStringMFD5ShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("MFD5"), is(DisplayType.MFD5)); + } + + public void testValueForStringGEN3_8minusINCHShouldReturnCorrectValue() { + assertThat(DisplayType.valueForString("GEN3_8-INCH"), + is(DisplayType.GEN3_8_INCH)); + } + + public void testCIDToStringShouldReturnCorrectValue() { + assertThat(DisplayType.CID.toString(), is("CID")); + } + + public void testTYPE2ToStringShouldReturnCorrectValue() { + assertThat(DisplayType.TYPE2.toString(), is("TYPE2")); + } + + public void testTYPE5ToStringShouldReturnCorrectValue() { + assertThat(DisplayType.TYPE5.toString(), is("TYPE5")); + } + + public void testNGNToStringShouldReturnCorrectValue() { + assertThat(DisplayType.NGN.toString(), is("NGN")); + } + + public void testGEN2_8_DMAToStringShouldReturnCorrectValue() { + assertThat(DisplayType.GEN2_8_DMA.toString(), is("GEN2_8_DMA")); + } + + public void testGEN2_6_DMAToStringShouldReturnCorrectValue() { + assertThat(DisplayType.GEN2_6_DMA.toString(), is("GEN2_6_DMA")); + } + + public void testMFD3ToStringShouldReturnCorrectValue() { + assertThat(DisplayType.MFD3.toString(), is("MFD3")); + } + + public void testMFD4ToStringShouldReturnCorrectValue() { + assertThat(DisplayType.MFD4.toString(), is("MFD4")); + } + + public void testMFD5ToStringShouldReturnCorrectValue() { + assertThat(DisplayType.MFD5.toString(), is("MFD5")); + } + + public void testGEN3_8_INCHToStringShouldReturnCorrectValue() { + assertThat(DisplayType.GEN3_8_INCH.toString(), is("GEN3_8-INCH")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + DisplayType.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ECallConfirmationStatusTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ECallConfirmationStatusTest.java new file mode 100644 index 000000000..f1c1f637a --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ECallConfirmationStatusTest.java @@ -0,0 +1,110 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for ECallConfirmationStatus enum. + * + * Created by enikolsky on 2014-02-11. + */ +public class ECallConfirmationStatusTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(ECallConfirmationStatus.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + ECallConfirmationStatus.NORMAL, + ECallConfirmationStatus.CALL_IN_PROGRESS, + ECallConfirmationStatus.CALL_CANCELLED, + ECallConfirmationStatus.CALL_COMPLETED, + ECallConfirmationStatus.CALL_UNSUCCESSFUL, + ECallConfirmationStatus.ECALL_CONFIGURED_OFF, + ECallConfirmationStatus.CALL_COMPLETE_DTMF_TIMEOUT)); + } + + + public void testValueForStringNORMALShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.valueForString("NORMAL"), + is(ECallConfirmationStatus.NORMAL)); + } + + public void testValueForStringCALL_IN_PROGRESSShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.valueForString("CALL_IN_PROGRESS"), + is(ECallConfirmationStatus.CALL_IN_PROGRESS)); + } + + public void testValueForStringCALL_CANCELLEDShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.valueForString("CALL_CANCELLED"), + is(ECallConfirmationStatus.CALL_CANCELLED)); + } + + public void testValueForStringCALL_COMPLETEDShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.valueForString("CALL_COMPLETED"), + is(ECallConfirmationStatus.CALL_COMPLETED)); + } + + public void testValueForStringCALL_UNSUCCESSFULShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.valueForString("CALL_UNSUCCESSFUL"), + is(ECallConfirmationStatus.CALL_UNSUCCESSFUL)); + } + + public void testValueForStringECALL_CONFIGURED_OFFShouldReturnCorrectValue() { + assertThat( + ECallConfirmationStatus.valueForString("ECALL_CONFIGURED_OFF"), + is(ECallConfirmationStatus.ECALL_CONFIGURED_OFF)); + } + + public void testValueForStringCALL_COMPLETE_DTMF_TIMEOUTShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.valueForString( + "CALL_COMPLETE_DTMF_TIMEOUT"), + is(ECallConfirmationStatus.CALL_COMPLETE_DTMF_TIMEOUT)); + } + + + public void testNORMALToStringShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.NORMAL.toString(), is("NORMAL")); + } + + public void testCALL_IN_PROGRESSToStringShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.CALL_IN_PROGRESS.toString(), + is("CALL_IN_PROGRESS")); + } + + public void testCALL_CANCELLEDToStringShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.CALL_CANCELLED.toString(), + is("CALL_CANCELLED")); + } + + public void testCALL_COMPLETEDToStringShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.CALL_COMPLETED.toString(), + is("CALL_COMPLETED")); + } + + public void testCALL_UNSUCCESSFULToStringShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.CALL_UNSUCCESSFUL.toString(), + is("CALL_UNSUCCESSFUL")); + } + + public void testECALL_CONFIGURED_OFFToStringShouldReturnCorrectValue() { + assertThat(ECallConfirmationStatus.ECALL_CONFIGURED_OFF.toString(), + is("ECALL_CONFIGURED_OFF")); + } + + public void testCALL_COMPLETE_DTMF_TIMEOUTToStringShouldReturnCorrectValue() { + assertThat( + ECallConfirmationStatus.CALL_COMPLETE_DTMF_TIMEOUT.toString(), + is("CALL_COMPLETE_DTMF_TIMEOUT")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + ECallConfirmationStatus.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/FileTypeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/FileTypeTest.java new file mode 100644 index 000000000..aa6df7f32 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/FileTypeTest.java @@ -0,0 +1,103 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for FileType enum. + * + * Created by enikolsky on 2014-02-11. + */ +public class FileTypeTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(FileType.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + FileType.GRAPHIC_BMP, FileType.GRAPHIC_JPEG, + FileType.GRAPHIC_PNG, FileType.AUDIO_WAVE, + FileType.AUDIO_MP3, FileType.AUDIO_AAC, FileType.BINARY, + FileType.JSON)); + } + + public void testValueForStringGRAPHIC_BMPShouldReturnCorrectValue() { + assertThat(FileType.valueForString("GRAPHIC_BMP"), + is(FileType.GRAPHIC_BMP)); + } + + public void testValueForStringGRAPHIC_JPEGShouldReturnCorrectValue() { + assertThat(FileType.valueForString("GRAPHIC_JPEG"), + is(FileType.GRAPHIC_JPEG)); + } + + public void testValueForStringGRAPHIC_PNGShouldReturnCorrectValue() { + assertThat(FileType.valueForString("GRAPHIC_PNG"), + is(FileType.GRAPHIC_PNG)); + } + + public void testValueForStringAUDIO_WAVEShouldReturnCorrectValue() { + assertThat(FileType.valueForString("AUDIO_WAVE"), + is(FileType.AUDIO_WAVE)); + } + + public void testValueForStringAUDIO_MP3ShouldReturnCorrectValue() { + assertThat(FileType.valueForString("AUDIO_MP3"), + is(FileType.AUDIO_MP3)); + } + + public void testValueForStringAUDIO_AACShouldReturnCorrectValue() { + assertThat(FileType.valueForString("AUDIO_AAC"), + is(FileType.AUDIO_AAC)); + } + + public void testValueForStringBINARYShouldReturnCorrectValue() { + assertThat(FileType.valueForString("BINARY"), is(FileType.BINARY)); + } + + public void testValueForStringJSONShouldReturnCorrectValue() { + assertThat(FileType.valueForString("JSON"), is(FileType.JSON)); + } + + public void testGRAPHIC_BMPToStringShouldReturnCorrectValue() { + assertThat(FileType.GRAPHIC_BMP.toString(), is("GRAPHIC_BMP")); + } + + public void testGRAPHIC_JPEGToStringShouldReturnCorrectValue() { + assertThat(FileType.GRAPHIC_JPEG.toString(), is("GRAPHIC_JPEG")); + } + + public void testGRAPHIC_PNGToStringShouldReturnCorrectValue() { + assertThat(FileType.GRAPHIC_PNG.toString(), is("GRAPHIC_PNG")); + } + + public void testAUDIO_WAVEToStringShouldReturnCorrectValue() { + assertThat(FileType.AUDIO_WAVE.toString(), is("AUDIO_WAVE")); + } + + public void testAUDIO_MP3ToStringShouldReturnCorrectValue() { + assertThat(FileType.AUDIO_MP3.toString(), is("AUDIO_MP3")); + } + + public void testAUDIO_AACToStringShouldReturnCorrectValue() { + assertThat(FileType.AUDIO_AAC.toString(), is("AUDIO_AAC")); + } + + public void testBINARYToStringShouldReturnCorrectValue() { + assertThat(FileType.BINARY.toString(), is("BINARY")); + } + + public void testJSONToStringShouldReturnCorrectValue() { + assertThat(FileType.JSON.toString(), is("JSON")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + FileType.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ImageFieldNameTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ImageFieldNameTest.java new file mode 100644 index 000000000..0554fd93a --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ImageFieldNameTest.java @@ -0,0 +1,140 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for ImageFieldName enum. + * + * Created by enikolsky on 2014-02-07. + */ +public class ImageFieldNameTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(ImageFieldName.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + ImageFieldName.softButtonImage, + ImageFieldName.choiceImage, + ImageFieldName.choiceSecondaryImage, + ImageFieldName.vrHelpItem, ImageFieldName.turnIcon, + ImageFieldName.menuIcon, ImageFieldName.cmdIcon, + ImageFieldName.appIcon, ImageFieldName.graphic, + ImageFieldName.showConstantTBTIcon, + ImageFieldName.showConstantTBTNextTurnIcon)); + } + + public void testValueForStringsoftButtonImageShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("softButtonImage"), + is(ImageFieldName.softButtonImage)); + } + + public void testValueForStringchoiceImageShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("choiceImage"), + is(ImageFieldName.choiceImage)); + } + + public void testValueForStringchoiceSecondaryImageShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("choiceSecondaryImage"), + is(ImageFieldName.choiceSecondaryImage)); + } + + public void testValueForStringvrHelpItemShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("vrHelpItem"), + is(ImageFieldName.vrHelpItem)); + } + + public void testValueForStringturnIconShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("turnIcon"), + is(ImageFieldName.turnIcon)); + } + + public void testValueForStringmenuIconShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("menuIcon"), + is(ImageFieldName.menuIcon)); + } + + public void testValueForStringcmdIconShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("cmdIcon"), + is(ImageFieldName.cmdIcon)); + } + + public void testValueForStringappIconShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("appIcon"), + is(ImageFieldName.appIcon)); + } + + public void testValueForStringgraphicShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("graphic"), + is(ImageFieldName.graphic)); + } + + public void testValueForStringshowConstantTBTIconShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("showConstantTBTIcon"), + is(ImageFieldName.showConstantTBTIcon)); + } + + public void testValueForStringshowConstantTBTNextTurnIconShouldReturnCorrectValue() { + assertThat(ImageFieldName.valueForString("showConstantTBTNextTurnIcon"), + is(ImageFieldName.showConstantTBTNextTurnIcon)); + } + + public void testsoftButtonImageToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.softButtonImage.toString(), + is("softButtonImage")); + } + + public void testchoiceImageToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.choiceImage.toString(), is("choiceImage")); + } + + public void testchoiceSecondaryImageToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.choiceSecondaryImage.toString(), + is("choiceSecondaryImage")); + } + + public void testvrHelpItemToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.vrHelpItem.toString(), is("vrHelpItem")); + } + + public void testturnIconToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.turnIcon.toString(), is("turnIcon")); + } + + public void testmenuIconToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.menuIcon.toString(), is("menuIcon")); + } + + public void testcmdIconToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.cmdIcon.toString(), is("cmdIcon")); + } + + public void testappIconToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.appIcon.toString(), is("appIcon")); + } + + public void testgraphicToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.graphic.toString(), is("graphic")); + } + + public void testshowConstantTBTIconToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.showConstantTBTIcon.toString(), + is("showConstantTBTIcon")); + } + + public void testshowConstantTBTNextTurnIconToStringShouldReturnCorrectValue() { + assertThat(ImageFieldName.showConstantTBTNextTurnIcon.toString(), + is("showConstantTBTNextTurnIcon")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + ImageFieldName.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PRNDLTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PRNDLTest.java new file mode 100644 index 000000000..83b3a2834 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PRNDLTest.java @@ -0,0 +1,162 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for PRNDL enum. + * + * Created by enikolsky on 2014-02-06. + */ +public class PRNDLTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(PRNDL.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + PRNDL.PARK, PRNDL.REVERSE, PRNDL.NEUTRAL, PRNDL.DRIVE, + PRNDL.SPORT, PRNDL.LOWGEAR, PRNDL.FIRST, PRNDL.SECOND, + PRNDL.THIRD, PRNDL.FOURTH, PRNDL.FIFTH, PRNDL.SIXTH, + PRNDL.SEVENTH, PRNDL.EIGHTH, PRNDL.UNKNOWN, + PRNDL.FAULT)); + } + + public void testValueForStringPARKShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("PARK"), is(PRNDL.PARK)); + } + + public void testValueForStringREVERSEShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("REVERSE"), is(PRNDL.REVERSE)); + } + + public void testValueForStringNEUTRALShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("NEUTRAL"), is(PRNDL.NEUTRAL)); + } + + public void testValueForStringDRIVEShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("DRIVE"), is(PRNDL.DRIVE)); + } + + public void testValueForStringSPORTShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("SPORT"), is(PRNDL.SPORT)); + } + + public void testValueForStringLOWGEARShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("LOWGEAR"), is(PRNDL.LOWGEAR)); + } + + public void testValueForStringFIRSTShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("FIRST"), is(PRNDL.FIRST)); + } + + public void testValueForStringSECONDShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("SECOND"), is(PRNDL.SECOND)); + } + + public void testValueForStringTHIRDShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("THIRD"), is(PRNDL.THIRD)); + } + + public void testValueForStringFOURTHShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("FOURTH"), is(PRNDL.FOURTH)); + } + + public void testValueForStringFIFTHShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("FIFTH"), is(PRNDL.FIFTH)); + } + + public void testValueForStringSIXTHShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("SIXTH"), is(PRNDL.SIXTH)); + } + + public void testValueForStringSEVENTHShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("SEVENTH"), is(PRNDL.SEVENTH)); + } + + public void testValueForStringEIGHTHShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("EIGHTH"), is(PRNDL.EIGHTH)); + } + + public void testValueForStringUNKNOWNShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("UNKNOWN"), is(PRNDL.UNKNOWN)); + } + + public void testValueForStringFAULTShouldReturnCorrectValue() { + assertThat(PRNDL.valueForString("FAULT"), is(PRNDL.FAULT)); + } + + public void testPARKToStringShouldReturnCorrectValue() { + assertThat(PRNDL.PARK.toString(), is("PARK")); + } + + public void testREVERSEToStringShouldReturnCorrectValue() { + assertThat(PRNDL.REVERSE.toString(), is("REVERSE")); + } + + public void testNEUTRALToStringShouldReturnCorrectValue() { + assertThat(PRNDL.NEUTRAL.toString(), is("NEUTRAL")); + } + + public void testDRIVEToStringShouldReturnCorrectValue() { + assertThat(PRNDL.DRIVE.toString(), is("DRIVE")); + } + + public void testSPORTToStringShouldReturnCorrectValue() { + assertThat(PRNDL.SPORT.toString(), is("SPORT")); + } + + public void testLOWGEARToStringShouldReturnCorrectValue() { + assertThat(PRNDL.LOWGEAR.toString(), is("LOWGEAR")); + } + + public void testFIRSTToStringShouldReturnCorrectValue() { + assertThat(PRNDL.FIRST.toString(), is("FIRST")); + } + + public void testSECONDToStringShouldReturnCorrectValue() { + assertThat(PRNDL.SECOND.toString(), is("SECOND")); + } + + public void testTHIRDToStringShouldReturnCorrectValue() { + assertThat(PRNDL.THIRD.toString(), is("THIRD")); + } + + public void testFOURTHToStringShouldReturnCorrectValue() { + assertThat(PRNDL.FOURTH.toString(), is("FOURTH")); + } + + public void testFIFTHToStringShouldReturnCorrectValue() { + assertThat(PRNDL.FIFTH.toString(), is("FIFTH")); + } + + public void testSIXTHToStringShouldReturnCorrectValue() { + assertThat(PRNDL.SIXTH.toString(), is("SIXTH")); + } + + public void testSEVENTHToStringShouldReturnCorrectValue() { + assertThat(PRNDL.SEVENTH.toString(), is("SEVENTH")); + } + + public void testEIGHTHToStringShouldReturnCorrectValue() { + assertThat(PRNDL.EIGHTH.toString(), is("EIGHTH")); + } + + public void testUNKNOWNToStringShouldReturnCorrectValue() { + assertThat(PRNDL.UNKNOWN.toString(), is("UNKNOWN")); + } + + public void testFAULTToStringShouldReturnCorrectValue() { + assertThat(PRNDL.FAULT.toString(), is("FAULT")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + PRNDL.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PredefinedLayoutTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PredefinedLayoutTest.java new file mode 100644 index 000000000..e653d157b --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PredefinedLayoutTest.java @@ -0,0 +1,250 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for PredefinedLayout enum. + * + * Created by enikolsky on 2014-02-17. + */ +public class PredefinedLayoutTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(PredefinedLayout.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + PredefinedLayout.DEFAULT, PredefinedLayout.MEDIA, + PredefinedLayout.NON_MEDIA, + PredefinedLayout.ONSCREEN_PRESETS, + PredefinedLayout.NAV_FULLSCREEN_MAP, + PredefinedLayout.NAV_LIST, + PredefinedLayout.NAV_KEYBOARD, + PredefinedLayout.GRAPHIC_WITH_TEXT, + PredefinedLayout.TEXT_WITH_GRAPHIC, + PredefinedLayout.TILES_ONLY, + PredefinedLayout.TEXTBUTTONS_ONLY, + PredefinedLayout.GRAPHIC_WITH_TILES, + PredefinedLayout.TILES_WITH_GRAPHIC, + PredefinedLayout.GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS, + PredefinedLayout.TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC, + PredefinedLayout.GRAPHIC_WITH_TEXTBUTTONS, + PredefinedLayout.TEXTBUTTONS_WITH_GRAPHIC, + PredefinedLayout.LARGE_GRAPHIC_WITH_SOFTBUTTONS, + PredefinedLayout.DOUBLE_GRAPHIC_WITH_SOFTBUTTONS, + PredefinedLayout.LARGE_GRAPHIC_ONLY)); + } + + public void testValueForStringDEFAULTShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("DEFAULT"), + is(PredefinedLayout.DEFAULT)); + } + + public void testValueForStringMEDIAShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("MEDIA"), + is(PredefinedLayout.MEDIA)); + } + + public void testValueForStringNONminusMEDIAShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("NON-MEDIA"), + is(PredefinedLayout.NON_MEDIA)); + } + + public void testValueForStringONSCREEN_PRESETSShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("ONSCREEN_PRESETS"), + is(PredefinedLayout.ONSCREEN_PRESETS)); + } + + public void testValueForStringNAV_FULLSCREEN_MAPShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("NAV_FULLSCREEN_MAP"), + is(PredefinedLayout.NAV_FULLSCREEN_MAP)); + } + + public void testValueForStringNAV_LISTShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("NAV_LIST"), + is(PredefinedLayout.NAV_LIST)); + } + + public void testValueForStringNAV_KEYBOARDShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("NAV_KEYBOARD"), + is(PredefinedLayout.NAV_KEYBOARD)); + } + + public void testValueForStringGRAPHIC_WITH_TEXTShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("GRAPHIC_WITH_TEXT"), + is(PredefinedLayout.GRAPHIC_WITH_TEXT)); + } + + public void testValueForStringTEXT_WITH_GRAPHICShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("TEXT_WITH_GRAPHIC"), + is(PredefinedLayout.TEXT_WITH_GRAPHIC)); + } + + public void testValueForStringTILES_ONLYShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("TILES_ONLY"), + is(PredefinedLayout.TILES_ONLY)); + } + + public void testValueForStringTEXTBUTTONS_ONLYShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("TEXTBUTTONS_ONLY"), + is(PredefinedLayout.TEXTBUTTONS_ONLY)); + } + + public void testValueForStringGRAPHIC_WITH_TILESShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("GRAPHIC_WITH_TILES"), + is(PredefinedLayout.GRAPHIC_WITH_TILES)); + } + + public void testValueForStringTILES_WITH_GRAPHICShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("TILES_WITH_GRAPHIC"), + is(PredefinedLayout.TILES_WITH_GRAPHIC)); + } + + public void testValueForStringGRAPHIC_WITH_TEXT_AND_SOFTBUTTONSShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString( + "GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS"), + is(PredefinedLayout.GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS)); + } + + public void testValueForStringTEXT_AND_SOFTBUTTONS_WITH_GRAPHICShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString( + "TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC"), + is(PredefinedLayout.TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC)); + } + + public void testValueForStringGRAPHIC_WITH_TEXTBUTTONSShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("GRAPHIC_WITH_TEXTBUTTONS"), + is(PredefinedLayout.GRAPHIC_WITH_TEXTBUTTONS)); + } + + public void testValueForStringTEXTBUTTONS_WITH_GRAPHICShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("TEXTBUTTONS_WITH_GRAPHIC"), + is(PredefinedLayout.TEXTBUTTONS_WITH_GRAPHIC)); + } + + public void testValueForStringLARGE_GRAPHIC_WITH_SOFTBUTTONSShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString( + "LARGE_GRAPHIC_WITH_SOFTBUTTONS"), + is(PredefinedLayout.LARGE_GRAPHIC_WITH_SOFTBUTTONS)); + } + + public void testValueForStringDOUBLE_GRAPHIC_WITH_SOFTBUTTONSShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString( + "DOUBLE_GRAPHIC_WITH_SOFTBUTTONS"), + is(PredefinedLayout.DOUBLE_GRAPHIC_WITH_SOFTBUTTONS)); + } + + public void testValueForStringLARGE_GRAPHIC_ONLYShouldReturnCorrectValue() { + assertThat(PredefinedLayout.valueForString("LARGE_GRAPHIC_ONLY"), + is(PredefinedLayout.LARGE_GRAPHIC_ONLY)); + } + + + public void testDEFAULTToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.DEFAULT.toString(), is("DEFAULT")); + } + + public void testMEDIAToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.MEDIA.toString(), is("MEDIA")); + } + + public void testNONminusMEDIAToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.NON_MEDIA.toString(), is("NON-MEDIA")); + } + + public void testONSCREEN_PRESETSToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.ONSCREEN_PRESETS.toString(), + is("ONSCREEN_PRESETS")); + } + + public void testNAV_FULLSCREEN_MAPToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.NAV_FULLSCREEN_MAP.toString(), + is("NAV_FULLSCREEN_MAP")); + } + + public void testNAV_LISTToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.NAV_LIST.toString(), is("NAV_LIST")); + } + + public void testNAV_KEYBOARDToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.NAV_KEYBOARD.toString(), + is("NAV_KEYBOARD")); + } + + public void testGRAPHIC_WITH_TEXTToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.GRAPHIC_WITH_TEXT.toString(), + is("GRAPHIC_WITH_TEXT")); + } + + public void testTEXT_WITH_GRAPHICToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.TEXT_WITH_GRAPHIC.toString(), + is("TEXT_WITH_GRAPHIC")); + } + + public void testTILES_ONLYToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.TILES_ONLY.toString(), is("TILES_ONLY")); + } + + public void testTEXTBUTTONS_ONLYToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.TEXTBUTTONS_ONLY.toString(), + is("TEXTBUTTONS_ONLY")); + } + + public void testGRAPHIC_WITH_TILESToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.GRAPHIC_WITH_TILES.toString(), + is("GRAPHIC_WITH_TILES")); + } + + public void testTILES_WITH_GRAPHICToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.TILES_WITH_GRAPHIC.toString(), + is("TILES_WITH_GRAPHIC")); + } + + public void testGRAPHIC_WITH_TEXT_AND_SOFTBUTTONSToStringShouldReturnCorrectValue() { + assertThat( + PredefinedLayout.GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS.toString(), + is("GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS")); + } + + public void testTEXT_AND_SOFTBUTTONS_WITH_GRAPHICToStringShouldReturnCorrectValue() { + assertThat( + PredefinedLayout.TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC.toString(), + is("TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC")); + } + + public void testGRAPHIC_WITH_TEXTBUTTONSToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.GRAPHIC_WITH_TEXTBUTTONS.toString(), + is("GRAPHIC_WITH_TEXTBUTTONS")); + } + + public void testTEXTBUTTONS_WITH_GRAPHICToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.TEXTBUTTONS_WITH_GRAPHIC.toString(), + is("TEXTBUTTONS_WITH_GRAPHIC")); + } + + public void testLARGE_GRAPHIC_WITH_SOFTBUTTONSToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.LARGE_GRAPHIC_WITH_SOFTBUTTONS.toString(), + is("LARGE_GRAPHIC_WITH_SOFTBUTTONS")); + } + + public void testDOUBLE_GRAPHIC_WITH_SOFTBUTTONSToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.DOUBLE_GRAPHIC_WITH_SOFTBUTTONS.toString(), + is("DOUBLE_GRAPHIC_WITH_SOFTBUTTONS")); + } + + public void testLARGE_GRAPHIC_ONLYToStringShouldReturnCorrectValue() { + assertThat(PredefinedLayout.LARGE_GRAPHIC_ONLY.toString(), + is("LARGE_GRAPHIC_ONLY")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + PredefinedLayout.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PrerecordedSpeechTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PrerecordedSpeechTest.java new file mode 100644 index 000000000..5086af259 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PrerecordedSpeechTest.java @@ -0,0 +1,50 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for PrerecordedSpeech enum. + * + * Created by enikolsky on 2014-01-31. + */ +public class PrerecordedSpeechTest extends TestCase { + public void testAllValuesShouldBeDefined() { + assertThat(PrerecordedSpeech.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + PrerecordedSpeech.HELP_JINGLE, + PrerecordedSpeech.INITIAL_JINGLE, + PrerecordedSpeech.LISTEN_JINGLE, + PrerecordedSpeech.POSITIVE_JINGLE, + PrerecordedSpeech.NEGATIVE_JINGLE)); + } + + public void testValueForStringHelpJingleShouldReturnCorrectValue() { + assertThat(PrerecordedSpeech.valueOf("HELP_JINGLE"), + is(PrerecordedSpeech.HELP_JINGLE)); + } + + public void testValueForStringInitialJingleShouldReturnCorrectValue() { + assertThat(PrerecordedSpeech.valueOf("INITIAL_JINGLE"), + is(PrerecordedSpeech.INITIAL_JINGLE)); + } + + public void testValueForStringListenJingleShouldReturnCorrectValue() { + assertThat(PrerecordedSpeech.valueOf("LISTEN_JINGLE"), + is(PrerecordedSpeech.LISTEN_JINGLE)); + } + + public void testValueForStringPositiveJingleShouldReturnCorrectValue() { + assertThat(PrerecordedSpeech.valueOf("POSITIVE_JINGLE"), + is(PrerecordedSpeech.POSITIVE_JINGLE)); + } + + public void testValueForStringNegativeJingleShouldReturnCorrectValue() { + assertThat(PrerecordedSpeech.valueOf("NEGATIVE_JINGLE"), + is(PrerecordedSpeech.NEGATIVE_JINGLE)); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/RequestTypeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/RequestTypeTest.java new file mode 100644 index 000000000..82c3ee211 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/RequestTypeTest.java @@ -0,0 +1,76 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for RequestType enum. + * + * Created by enikolsky on 2014-02-10. + */ +public class RequestTypeTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(RequestType.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + RequestType.HTTP, RequestType.FILE_RESUME, + RequestType.AUTH_REQUEST, RequestType.AUTH_CHALLENGE, + RequestType.AUTH_ACK)); + } + + public void testValueForStringHTTPShouldReturnCorrectValue() { + assertThat(RequestType.valueForString("HTTP"), is(RequestType.HTTP)); + } + + public void testValueForStringFILE_RESUMEShouldReturnCorrectValue() { + assertThat(RequestType.valueForString("FILE_RESUME"), + is(RequestType.FILE_RESUME)); + } + + public void testValueForStringAUTH_REQUESTShouldReturnCorrectValue() { + assertThat(RequestType.valueForString("AUTH_REQUEST"), + is(RequestType.AUTH_REQUEST)); + } + + public void testValueForStringAUTH_CHALLENGEShouldReturnCorrectValue() { + assertThat(RequestType.valueForString("AUTH_CHALLENGE"), + is(RequestType.AUTH_CHALLENGE)); + } + + public void testValueForStringAUTH_ACKShouldReturnCorrectValue() { + assertThat(RequestType.valueForString("AUTH_ACK"), + is(RequestType.AUTH_ACK)); + } + + public void testHTTPToStringShouldReturnCorrectValue() { + assertThat(RequestType.HTTP.toString(), is("HTTP")); + } + + public void testFILE_RESUMEToStringShouldReturnCorrectValue() { + assertThat(RequestType.FILE_RESUME.toString(), is("FILE_RESUME")); + } + + public void testAUTH_REQUESTToStringShouldReturnCorrectValue() { + assertThat(RequestType.AUTH_REQUEST.toString(), is("AUTH_REQUEST")); + } + + public void testAUTH_CHALLENGEToStringShouldReturnCorrectValue() { + assertThat(RequestType.AUTH_CHALLENGE.toString(), is("AUTH_CHALLENGE")); + } + + public void testAUTH_ACKToStringShouldReturnCorrectValue() { + assertThat(RequestType.AUTH_ACK.toString(), is("AUTH_ACK")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + RequestType.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TextFieldNameTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TextFieldNameTest.java new file mode 100644 index 000000000..d5559baa3 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TextFieldNameTest.java @@ -0,0 +1,256 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for TextFieldName enum. + * + * Created by enikolsky on 2014-02-06. + */ +public class TextFieldNameTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(TextFieldName.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + TextFieldName.mainField1, TextFieldName.mainField2, + TextFieldName.mainField3, TextFieldName.mainField4, + TextFieldName.statusBar, TextFieldName.mediaClock, + TextFieldName.mediaTrack, TextFieldName.alertText1, + TextFieldName.alertText2, TextFieldName.alertText3, + TextFieldName.scrollableMessageBody, + TextFieldName.initialInteractionText, + TextFieldName.navigationText1, + TextFieldName.navigationText2, TextFieldName.ETA, + TextFieldName.totalDistance, + TextFieldName.audioPassThruDisplayText1, + TextFieldName.audioPassThruDisplayText2, + TextFieldName.sliderHeader, TextFieldName.sliderFooter, + TextFieldName.menuName, TextFieldName.secondaryText, + TextFieldName.tertiaryText)); + } + + public void testValueForStringmainField1ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("mainField1"), + is(TextFieldName.mainField1)); + } + + public void testValueForStringmainField2ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("mainField2"), + is(TextFieldName.mainField2)); + } + + public void testValueForStringmainField3ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("mainField3"), + is(TextFieldName.mainField3)); + } + + public void testValueForStringmainField4ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("mainField4"), + is(TextFieldName.mainField4)); + } + + public void testValueForStringstatusBarShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("statusBar"), + is(TextFieldName.statusBar)); + } + + public void testValueForStringmediaClockShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("mediaClock"), + is(TextFieldName.mediaClock)); + } + + public void testValueForStringmediaTrackShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("mediaTrack"), + is(TextFieldName.mediaTrack)); + } + + public void testValueForStringalertText1ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("alertText1"), + is(TextFieldName.alertText1)); + } + + public void testValueForStringalertText2ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("alertText2"), + is(TextFieldName.alertText2)); + } + + public void testValueForStringalertText3ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("alertText3"), + is(TextFieldName.alertText3)); + } + + public void testValueForStringscrollableMessageBodyShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("scrollableMessageBody"), + is(TextFieldName.scrollableMessageBody)); + } + + public void testValueForStringinitialInteractionTextShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("initialInteractionText"), + is(TextFieldName.initialInteractionText)); + } + + public void testValueForStringnavigationText1ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("navigationText1"), + is(TextFieldName.navigationText1)); + } + + public void testValueForStringnavigationText2ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("navigationText2"), + is(TextFieldName.navigationText2)); + } + + public void testValueForStringETAShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("ETA"), is(TextFieldName.ETA)); + } + + public void testValueForStringtotalDistanceShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("totalDistance"), + is(TextFieldName.totalDistance)); + } + + public void testValueForStringaudioPassThruDisplayText1ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("audioPassThruDisplayText1"), + is(TextFieldName.audioPassThruDisplayText1)); + } + + public void testValueForStringaudioPassThruDisplayText2ShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("audioPassThruDisplayText2"), + is(TextFieldName.audioPassThruDisplayText2)); + } + + public void testValueForStringsliderHeaderShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("sliderHeader"), + is(TextFieldName.sliderHeader)); + } + + public void testValueForStringsliderFooterShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("sliderFooter"), + is(TextFieldName.sliderFooter)); + } + + public void testValueForStringmenuNameShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("menuName"), + is(TextFieldName.menuName)); + } + + public void testValueForStringsecondaryTextShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("secondaryText"), + is(TextFieldName.secondaryText)); + } + + public void testValueForStringtertiaryTextShouldReturnCorrectValue() { + assertThat(TextFieldName.valueForString("tertiaryText"), + is(TextFieldName.tertiaryText)); + } + + public void testmainField1ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.mainField1.toString(), is("mainField1")); + } + + public void testmainField2ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.mainField2.toString(), is("mainField2")); + } + + public void testmainField3ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.mainField3.toString(), is("mainField3")); + } + + public void testmainField4ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.mainField4.toString(), is("mainField4")); + } + + public void teststatusBarToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.statusBar.toString(), is("statusBar")); + } + + public void testmediaClockToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.mediaClock.toString(), is("mediaClock")); + } + + public void testmediaTrackToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.mediaTrack.toString(), is("mediaTrack")); + } + + public void testalertText1ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.alertText1.toString(), is("alertText1")); + } + + public void testalertText2ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.alertText2.toString(), is("alertText2")); + } + + public void testalertText3ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.alertText3.toString(), is("alertText3")); + } + + public void testscrollableMessageBodyToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.scrollableMessageBody.toString(), + is("scrollableMessageBody")); + } + + public void testinitialInteractionTextToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.initialInteractionText.toString(), + is("initialInteractionText")); + } + + public void testnavigationText1ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.navigationText1.toString(), + is("navigationText1")); + } + + public void testnavigationText2ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.navigationText2.toString(), + is("navigationText2")); + } + + public void testETAToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.ETA.toString(), is("ETA")); + } + + public void testtotalDistanceToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.totalDistance.toString(), is("totalDistance")); + } + + public void testaudioPassThruDisplayText1ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.audioPassThruDisplayText1.toString(), + is("audioPassThruDisplayText1")); + } + + public void testaudioPassThruDisplayText2ToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.audioPassThruDisplayText2.toString(), + is("audioPassThruDisplayText2")); + } + + public void testsliderHeaderToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.sliderHeader.toString(), is("sliderHeader")); + } + + public void testsliderFooterToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.sliderFooter.toString(), is("sliderFooter")); + } + + public void testmenuNameToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.menuName.toString(), is("menuName")); + } + + public void testsecondaryTextToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.secondaryText.toString(), is("secondaryText")); + } + + public void testtertiaryTextToStringShouldReturnCorrectValue() { + assertThat(TextFieldName.tertiaryText.toString(), is("tertiaryText")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + TextFieldName.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TriggerSourceTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TriggerSourceTest.java new file mode 100644 index 000000000..e829370a0 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TriggerSourceTest.java @@ -0,0 +1,48 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for TriggerSource enum. + * + * Created by enikolsky on 2014-01-31. + */ +public class TriggerSourceTest extends TestCase { + private static final String VR = "VR"; + private static final String MENU = "MENU"; + private static final String KEYBOARD = "KEYBOARD"; + + public void testValueForStringMenuShouldReturnMenuItem() { + assertThat(TriggerSource.valueForString(MENU), + is(TriggerSource.TS_MENU)); + } + + public void testValueForStringVrShouldReturnVrItem() { + assertThat(TriggerSource.valueForString(VR), is(TriggerSource.TS_VR)); + } + + public void testValueForStringKeyboardShouldReturnKeyboardItem() { + assertThat(TriggerSource.valueForString(KEYBOARD), + is(TriggerSource.TS_KEYBOARD)); + } + + public void testValueForStringUnknownShouldReturnNull() { + assertThat(TriggerSource.valueForString("Unknown"), nullValue()); + } + + public void testMenuItemShouldHaveMenuName() { + assertThat(TriggerSource.TS_MENU.toString(), is(MENU)); + } + + public void testVrItemShouldHaveVrName() { + assertThat(TriggerSource.TS_VR.toString(), is(VR)); + } + + public void testKeyboardItemShouldHaveKeyboardName() { + assertThat(TriggerSource.TS_KEYBOARD.toString(), is(KEYBOARD)); + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataNotificationStatusTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataNotificationStatusTest.java new file mode 100644 index 000000000..22699084d --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataNotificationStatusTest.java @@ -0,0 +1,75 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for VehicleDataNotificationStatus enum. + * + * Created by enikolsky on 2014-02-07. + */ +public class VehicleDataNotificationStatusTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(VehicleDataNotificationStatus.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + VehicleDataNotificationStatus.NOT_SUPPORTED, + VehicleDataNotificationStatus.NORMAL, + VehicleDataNotificationStatus.ACTIVE, + VehicleDataNotificationStatus.NOT_USED)); + } + + public void testValueForStringNOT_SUPPORTEDShouldReturnCorrectValue() { + assertThat(VehicleDataNotificationStatus.valueForString( + "VDNS_NOT_SUPPORTED"), + is(VehicleDataNotificationStatus.NOT_SUPPORTED)); + } + + public void testValueForStringNORMALShouldReturnCorrectValue() { + assertThat(VehicleDataNotificationStatus.valueForString("VDNS_NORMAL"), + is(VehicleDataNotificationStatus.NORMAL)); + } + + public void testValueForStringACTIVEShouldReturnCorrectValue() { + assertThat(VehicleDataNotificationStatus.valueForString("VDNS_ACTIVE"), + is(VehicleDataNotificationStatus.ACTIVE)); + } + + public void testValueForStringNOT_USEDShouldReturnCorrectValue() { + assertThat( + VehicleDataNotificationStatus.valueForString("VDNS_NOT_USED"), + is(VehicleDataNotificationStatus.NOT_USED)); + } + + public void testNOT_SUPPORTEDToStringShouldReturnCorrectValue() { + assertThat(VehicleDataNotificationStatus.NOT_SUPPORTED.toString(), + is("VDNS_NOT_SUPPORTED")); + } + + public void testNORMALToStringShouldReturnCorrectValue() { + assertThat(VehicleDataNotificationStatus.NORMAL.toString(), + is("VDNS_NORMAL")); + } + + public void testACTIVEToStringShouldReturnCorrectValue() { + assertThat(VehicleDataNotificationStatus.ACTIVE.toString(), + is("VDNS_ACTIVE")); + } + + public void testNOT_USEDToStringShouldReturnCorrectValue() { + assertThat(VehicleDataNotificationStatus.NOT_USED.toString(), + is("VDNS_NOT_USED")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + VehicleDataNotificationStatus.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataTypeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataTypeTest.java new file mode 100644 index 000000000..6eb43043f --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataTypeTest.java @@ -0,0 +1,320 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for VehicleDataType enum. + * + * Created by enikolsky on 2014-02-11. + */ +public class VehicleDataTypeTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(VehicleDataType.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + VehicleDataType.VEHICLEDATA_GPS, + VehicleDataType.VEHICLEDATA_SPEED, + VehicleDataType.VEHICLEDATA_RPM, + VehicleDataType.VEHICLEDATA_FUELLEVEL, + VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE, + VehicleDataType.VEHICLEDATA_FUELCONSUMPTION, + VehicleDataType.VEHICLEDATA_EXTERNTEMP, + VehicleDataType.VEHICLEDATA_VIN, + VehicleDataType.VEHICLEDATA_PRNDL, + VehicleDataType.VEHICLEDATA_TIREPRESSURE, + VehicleDataType.VEHICLEDATA_ODOMETER, + VehicleDataType.VEHICLEDATA_BELTSTATUS, + VehicleDataType.VEHICLEDATA_BODYINFO, + VehicleDataType.VEHICLEDATA_DEVICESTATUS, + VehicleDataType.VEHICLEDATA_ECALLINFO, + VehicleDataType.VEHICLEDATA_AIRBAGSTATUS, + VehicleDataType.VEHICLEDATA_EMERGENCYEVENT, + VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS, + VehicleDataType.VEHICLEDATA_MYKEY, + VehicleDataType.VEHICLEDATA_BRAKING, + VehicleDataType.VEHICLEDATA_WIPERSTATUS, + VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS, + VehicleDataType.VEHICLEDATA_BATTVOLTAGE, + VehicleDataType.VEHICLEDATA_ENGINETORQUE, + VehicleDataType.VEHICLEDATA_ACCPEDAL, + VehicleDataType.VEHICLEDATA_STEERINGWHEEL)); + } + + + public void testValueForStringVEHICLEDATA_GPSShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_GPS"), + is(VehicleDataType.VEHICLEDATA_GPS)); + } + + public void testValueForStringVEHICLEDATA_SPEEDShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_SPEED"), + is(VehicleDataType.VEHICLEDATA_SPEED)); + } + + public void testValueForStringVEHICLEDATA_RPMShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_RPM"), + is(VehicleDataType.VEHICLEDATA_RPM)); + } + + public void testValueForStringVEHICLEDATA_FUELLEVELShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_FUELLEVEL"), + is(VehicleDataType.VEHICLEDATA_FUELLEVEL)); + } + + public void testValueForStringVEHICLEDATA_FUELLEVEL_STATEShouldReturnCorrectValue() { + assertThat( + VehicleDataType.valueForString("VEHICLEDATA_FUELLEVEL_STATE"), + is(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE)); + } + + public void testValueForStringVEHICLEDATA_FUELCONSUMPTIONShouldReturnCorrectValue() { + assertThat( + VehicleDataType.valueForString("VEHICLEDATA_FUELCONSUMPTION"), + is(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION)); + } + + public void testValueForStringVEHICLEDATA_EXTERNTEMPShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_EXTERNTEMP"), + is(VehicleDataType.VEHICLEDATA_EXTERNTEMP)); + } + + public void testValueForStringVEHICLEDATA_VINShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_VIN"), + is(VehicleDataType.VEHICLEDATA_VIN)); + } + + public void testValueForStringVEHICLEDATA_PRNDLShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_PRNDL"), + is(VehicleDataType.VEHICLEDATA_PRNDL)); + } + + public void testValueForStringVEHICLEDATA_TIREPRESSUREShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_TIREPRESSURE"), + is(VehicleDataType.VEHICLEDATA_TIREPRESSURE)); + } + + public void testValueForStringVEHICLEDATA_ODOMETERShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_ODOMETER"), + is(VehicleDataType.VEHICLEDATA_ODOMETER)); + } + + public void testValueForStringVEHICLEDATA_BELTSTATUSShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_BELTSTATUS"), + is(VehicleDataType.VEHICLEDATA_BELTSTATUS)); + } + + public void testValueForStringVEHICLEDATA_BODYINFOShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_BODYINFO"), + is(VehicleDataType.VEHICLEDATA_BODYINFO)); + } + + public void testValueForStringVEHICLEDATA_DEVICESTATUSShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_DEVICESTATUS"), + is(VehicleDataType.VEHICLEDATA_DEVICESTATUS)); + } + + public void testValueForStringVEHICLEDATA_ECALLINFOShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_ECALLINFO"), + is(VehicleDataType.VEHICLEDATA_ECALLINFO)); + } + + public void testValueForStringVEHICLEDATA_AIRBAGSTATUSShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_AIRBAGSTATUS"), + is(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS)); + } + + public void testValueForStringVEHICLEDATA_EMERGENCYEVENTShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_EMERGENCYEVENT"), + is(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT)); + } + + public void testValueForStringVEHICLEDATA_CLUSTERMODESTATUSShouldReturnCorrectValue() { + assertThat( + VehicleDataType.valueForString("VEHICLEDATA_CLUSTERMODESTATUS"), + is(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS)); + } + + public void testValueForStringVEHICLEDATA_MYKEYShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_MYKEY"), + is(VehicleDataType.VEHICLEDATA_MYKEY)); + } + + public void testValueForStringVEHICLEDATA_BRAKINGShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_BRAKING"), + is(VehicleDataType.VEHICLEDATA_BRAKING)); + } + + public void testValueForStringVEHICLEDATA_WIPERSTATUSShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_WIPERSTATUS"), + is(VehicleDataType.VEHICLEDATA_WIPERSTATUS)); + } + + public void testValueForStringVEHICLEDATA_HEADLAMPSTATUSShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_HEADLAMPSTATUS"), + is(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS)); + } + + public void testValueForStringVEHICLEDATA_BATTVOLTAGEShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_BATTVOLTAGE"), + is(VehicleDataType.VEHICLEDATA_BATTVOLTAGE)); + } + + public void testValueForStringVEHICLEDATA_ENGINETORQUEShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_ENGINETORQUE"), + is(VehicleDataType.VEHICLEDATA_ENGINETORQUE)); + } + + public void testValueForStringVEHICLEDATA_ACCPEDALShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_ACCPEDAL"), + is(VehicleDataType.VEHICLEDATA_ACCPEDAL)); + } + + public void testValueForStringVEHICLEDATA_STEERINGWHEELShouldReturnCorrectValue() { + assertThat(VehicleDataType.valueForString("VEHICLEDATA_STEERINGWHEEL"), + is(VehicleDataType.VEHICLEDATA_STEERINGWHEEL)); + } + + + public void testVEHICLEDATA_GPSToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_GPS.toString(), + is("VEHICLEDATA_GPS")); + } + + public void testVEHICLEDATA_SPEEDToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_SPEED.toString(), + is("VEHICLEDATA_SPEED")); + } + + public void testVEHICLEDATA_RPMToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_RPM.toString(), + is("VEHICLEDATA_RPM")); + } + + public void testVEHICLEDATA_FUELLEVELToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_FUELLEVEL.toString(), + is("VEHICLEDATA_FUELLEVEL")); + } + + public void testVEHICLEDATA_FUELLEVEL_STATEToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE.toString(), + is("VEHICLEDATA_FUELLEVEL_STATE")); + } + + public void testVEHICLEDATA_FUELCONSUMPTIONToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION.toString(), + is("VEHICLEDATA_FUELCONSUMPTION")); + } + + public void testVEHICLEDATA_EXTERNTEMPToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_EXTERNTEMP.toString(), + is("VEHICLEDATA_EXTERNTEMP")); + } + + public void testVEHICLEDATA_VINToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_VIN.toString(), + is("VEHICLEDATA_VIN")); + } + + public void testVEHICLEDATA_PRNDLToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_PRNDL.toString(), + is("VEHICLEDATA_PRNDL")); + } + + public void testVEHICLEDATA_TIREPRESSUREToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_TIREPRESSURE.toString(), + is("VEHICLEDATA_TIREPRESSURE")); + } + + public void testVEHICLEDATA_ODOMETERToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_ODOMETER.toString(), + is("VEHICLEDATA_ODOMETER")); + } + + public void testVEHICLEDATA_BELTSTATUSToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_BELTSTATUS.toString(), + is("VEHICLEDATA_BELTSTATUS")); + } + + public void testVEHICLEDATA_BODYINFOToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_BODYINFO.toString(), + is("VEHICLEDATA_BODYINFO")); + } + + public void testVEHICLEDATA_DEVICESTATUSToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_DEVICESTATUS.toString(), + is("VEHICLEDATA_DEVICESTATUS")); + } + + public void testVEHICLEDATA_ECALLINFOToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_ECALLINFO.toString(), + is("VEHICLEDATA_ECALLINFO")); + } + + public void testVEHICLEDATA_AIRBAGSTATUSToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS.toString(), + is("VEHICLEDATA_AIRBAGSTATUS")); + } + + public void testVEHICLEDATA_EMERGENCYEVENTToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT.toString(), + is("VEHICLEDATA_EMERGENCYEVENT")); + } + + public void testVEHICLEDATA_CLUSTERMODESTATUSToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS.toString(), + is("VEHICLEDATA_CLUSTERMODESTATUS")); + } + + public void testVEHICLEDATA_MYKEYToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_MYKEY.toString(), + is("VEHICLEDATA_MYKEY")); + } + + public void testVEHICLEDATA_BRAKINGToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_BRAKING.toString(), + is("VEHICLEDATA_BRAKING")); + } + + public void testVEHICLEDATA_WIPERSTATUSToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_WIPERSTATUS.toString(), + is("VEHICLEDATA_WIPERSTATUS")); + } + + public void testVEHICLEDATA_HEADLAMPSTATUSToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS.toString(), + is("VEHICLEDATA_HEADLAMPSTATUS")); + } + + public void testVEHICLEDATA_BATTVOLTAGEToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_BATTVOLTAGE.toString(), + is("VEHICLEDATA_BATTVOLTAGE")); + } + + public void testVEHICLEDATA_ENGINETORQUEToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_ENGINETORQUE.toString(), + is("VEHICLEDATA_ENGINETORQUE")); + } + + public void testVEHICLEDATA_ACCPEDALToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_ACCPEDAL.toString(), + is("VEHICLEDATA_ACCPEDAL")); + } + + public void testVEHICLEDATA_STEERINGWHEELToStringShouldReturnCorrectValue() { + assertThat(VehicleDataType.VEHICLEDATA_STEERINGWHEEL.toString(), + is("VEHICLEDATA_STEERINGWHEEL")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + VehicleDataType.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/WarningLightStatusTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/WarningLightStatusTest.java new file mode 100644 index 000000000..fc6849952 --- /dev/null +++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/WarningLightStatusTest.java @@ -0,0 +1,67 @@ +package com.ford.syncV4.proxy.rpc.enums; + +import junit.framework.TestCase; + +import org.hamcrest.collection.IsArrayContainingInAnyOrder; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * Tests for WarningLightStatus enum. + * + * Created by enikolsky on 2014-02-07. + */ +public class WarningLightStatusTest extends TestCase { + public void testAllValuesFromSpecificationShouldBeDefined() { + assertThat(WarningLightStatus.values(), + IsArrayContainingInAnyOrder.arrayContainingInAnyOrder( + WarningLightStatus.OFF, WarningLightStatus.ON, + WarningLightStatus.FLASH, WarningLightStatus.NOT_USED)); + } + + public void testValueForStringOFFShouldReturnCorrectValue() { + assertThat(WarningLightStatus.valueForString("WLS_OFF"), + is(WarningLightStatus.OFF)); + } + + public void testValueForStringONShouldReturnCorrectValue() { + assertThat(WarningLightStatus.valueForString("WLS_ON"), + is(WarningLightStatus.ON)); + } + + public void testValueForStringFLASHShouldReturnCorrectValue() { + assertThat(WarningLightStatus.valueForString("WLS_FLASH"), + is(WarningLightStatus.FLASH)); + } + + public void testValueForStringNOT_USEDShouldReturnCorrectValue() { + assertThat(WarningLightStatus.valueForString("WLS_NOT_USED"), + is(WarningLightStatus.NOT_USED)); + } + + public void testOFFToStringShouldReturnCorrectValue() { + assertThat(WarningLightStatus.OFF.toString(), is("WLS_OFF")); + } + + public void testONToStringShouldReturnCorrectValue() { + assertThat(WarningLightStatus.ON.toString(), is("WLS_ON")); + } + + public void testFLASHToStringShouldReturnCorrectValue() { + assertThat(WarningLightStatus.FLASH.toString(), is("WLS_FLASH")); + } + + public void testNOT_USEDToStringShouldReturnCorrectValue() { + assertThat(WarningLightStatus.NOT_USED.toString(), is("WLS_NOT_USED")); + } + + public void testValueForStringUnknownShouldThrowIllegalArgumentException() { + try { + WarningLightStatus.valueForString("Unknown"); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } +} |