summaryrefslogtreecommitdiff
path: root/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4
diff options
context:
space:
mode:
Diffstat (limited to 'SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4')
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PolicyTableSnapshot_Test.java304
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PutFile_Test.java570
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/PutFileRequestSendingTest.java242
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/BinaryFrameHeaderTest.java64
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderFactoryTest.java170
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderTest.java37
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolMessageConverterTest.java36
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/UnregisterWithoutDisconnectTest.java96
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolTest.java714
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolUSBTest.java178
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FrameDataControlFrameTypeTest.java102
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FunctionIDTest.java50
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/ServiceTypeTest.java60
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/heartbeat/HeartbeatMonitorTest.java188
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/LanguageChangeTest.java171
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionResponseTest.java52
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionTest.java59
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageHandlerTest.java21
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageTest.java164
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/ShowConstantTBTTest.java100
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMProxyListenerTest.java122
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMTest.java451
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBaseTest.java580
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBase_OnSystemRequestTest.java562
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/DefaultRPCRequestConverterTest.java263
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SyncRPCRequestConverterFactoryTest.java96
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SystemPutFileRPCRequestConverterTest.java377
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/enums/GlobalPropertyTest.java39
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AlertTest.java83
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/AudioPassThruCapabilitiesTest.java195
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ChoiceTest.java96
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DIDResultTest.java191
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageResponseTest.java117
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DiagnosticMessageTest.java210
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/DisplayCapabilitiesTest.java358
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/GetVehicleDataResponseTest.java97
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/HeadLampStatusTest.java166
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageFieldTest.java241
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ImageResolutionTest.java140
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/KeyboardPropertiesTest.java302
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/MenuParamsTest.java188
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnHashChangeTest.java95
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnSystemRequestTest.java362
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/OnVehicleDataTest.java470
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/PutFileTest.java186
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ReadDIDResponseTest.java114
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceResponseTest.java271
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/RegisterAppInterfaceTest.java115
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ResetGlobalPropertiesTest.java56
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ScreenParamsTest.java165
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetDisplayLayoutResponseTest.java320
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetGlobalPropertiesTest.java166
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SetMediaClockTimerTest.java106
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/ShowTest.java105
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataResponseTest.java111
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SubscribeVehicleDataTest.java108
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/SystemRequestTest.java105
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TestCommon.java90
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/TireStatusTest.java105
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataResponseTest.java115
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/UnsubscribeVehicleDataTest.java108
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/AmbientLightStatusTest.java107
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ButtonNameTest.java120
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/DisplayTypeTest.java117
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ECallConfirmationStatusTest.java110
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/FileTypeTest.java103
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/ImageFieldNameTest.java140
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PRNDLTest.java162
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PredefinedLayoutTest.java250
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/PrerecordedSpeechTest.java50
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/RequestTypeTest.java76
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TextFieldNameTest.java256
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/TriggerSourceTest.java48
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataNotificationStatusTest.java75
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/VehicleDataTypeTest.java320
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/rpc/enums/WarningLightStatusTest.java67
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/session/MobileNavSessionTest.java52
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/service/ServiceTest.java31
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/session/SessionTest.java100
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/H264PacketizerTest.java325
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/MobileNaviDataFrameTest.java63
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionTest.java346
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionUSBTest.java79
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/transport/usb/USBTransportTest.java50
-rw-r--r--SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/util/CommonUtilsTest.java70
85 files changed, 14642 insertions, 0 deletions
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PolicyTableSnapshot_Test.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PolicyTableSnapshot_Test.java
new file mode 100644
index 000000000..fcfe2c28d
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PolicyTableSnapshot_Test.java
@@ -0,0 +1,304 @@
+package com.ford.syncV4.integrationtest;
+
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+
+import com.ford.syncV4.marshal.IJsonRPCMarshaller;
+import com.ford.syncV4.marshal.JsonRPCMarshaller;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.MessageType;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.proxy.RPCNotification;
+import com.ford.syncV4.proxy.RPCRequest;
+import com.ford.syncV4.proxy.RPCResponse;
+import com.ford.syncV4.proxy.SyncProxyALM;
+import com.ford.syncV4.proxy.SyncProxyBase;
+import com.ford.syncV4.proxy.converter.IRPCRequestConverterFactory;
+import com.ford.syncV4.proxy.converter.SystemPutFileRPCRequestConverter;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALMTesting;
+import com.ford.syncV4.proxy.rpc.OnSystemRequest;
+import com.ford.syncV4.proxy.rpc.PutFileResponse;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.FileType;
+import com.ford.syncV4.proxy.rpc.enums.RequestType;
+import com.ford.syncV4.proxy.rpc.enums.Result;
+import com.ford.syncV4.proxy.systemrequest.IOnSystemRequestHandler;
+import com.ford.syncV4.proxy.systemrequest.ISystemRequestProxy;
+import com.ford.syncV4.syncConnection.SyncConnection;
+import com.ford.syncV4.util.TestConfig;
+
+import org.hamcrest.core.IsNull;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.mockito.ArgumentCaptor;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.notNull;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+/**
+ * This is an integration test of the mobile side reaction on Policy Table Snapshot
+ * APPLINK-5540
+ *
+ * Created by Yuriy Chernyshov on 2014-02-11.
+ */
+public class OnSystemRequest_PolicyTableSnapshot_Test extends InstrumentationTestCase {
+
+ private static final String TAG = "PolicyTableSnapshot_Test";
+
+ private static final byte PROTOCOL_VERSION = (byte) 2;
+ private static final int PUTFILE_FUNCTIONID = 32;
+ private static final int ONSYSTEMREQUEST_FUNCTIONID = 32781;
+ private static final String OFFSET = "offset";
+ private static final String LENGTH = "length";
+ private static final String SYNC_FILENAME = "syncFileName";
+ private static final String SYSTEM_FILE = "systemFile";
+ private static final String FILE_TYPE = "fileType";
+ private static final int WAIT_TIMEOUT = 200;
+ private IJsonRPCMarshaller marshaller;
+ private IProxyListenerALMTesting proxyListenerMock;
+ private WiProProtocol protocolMock;
+ private SyncConnection connectionMock;
+ private SyncProxyALM proxy;
+ private int maxDataSize;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ marshaller = new JsonRPCMarshaller();
+
+ // we have to use the special IProxyListenerALMTesting here to allow to
+ // send messages at any time
+ proxyListenerMock = mock(IProxyListenerALMTesting.class);
+ protocolMock = mock(WiProProtocol.class);
+ connectionMock = createNewSyncConnectionMock();
+
+ proxy = new SyncProxyALM(proxyListenerMock, null, "a", null, null,
+ false, null, null, null, null, null, null, false, false, 2,
+ null, connectionMock, new TestConfig());
+
+ final SystemPutFileRPCRequestConverter converter = new SystemPutFileRPCRequestConverter();
+ maxDataSize = 64;
+ converter.setMaxDataSize(maxDataSize);
+ IRPCRequestConverterFactory factoryMock = mock(IRPCRequestConverterFactory.class);
+ when(factoryMock.getConverterForRequest(notNull(RPCRequest.class))).thenReturn(converter);
+ proxy.setRpcRequestConverterFactory(factoryMock);
+ }
+
+ public void testOnSystemRequestWithPTS() throws Exception {
+ final FileType fileType = FileType.JSON;
+ final int extraDataSize = 10;
+ final int dataSize = (maxDataSize * 2) + extraDataSize;
+ final byte[] dataSnapshot = TestCommon.getRandomBytes(dataSize);
+
+ final String filename = "PolicyTableUpdate";
+
+ IOnSystemRequestHandler handlerMock = mock(IOnSystemRequestHandler.class);
+ doAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
+ assertNotNull(invocationOnMock.getArguments());
+ assertEquals(2, invocationOnMock.getArguments().length);
+ byte[] data = (byte[]) invocationOnMock.getArguments()[1];
+ assertNotNull(data);
+ assertEquals(dataSize, data.length);
+
+ final ISystemRequestProxy proxy =
+ (ISystemRequestProxy) invocationOnMock.getArguments()[0];
+ proxy.putPolicyTableUpdateFile(filename, data);
+ return null;
+ }
+ }).when(handlerMock)
+ .onPolicyTableSnapshotRequest(notNull(ISystemRequestProxy.class), eq(dataSnapshot));
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ // emulate incoming OnSystemRequest notification with HTTP
+ OnSystemRequest onSystemRequest = new OnSystemRequest();
+ onSystemRequest.setRequestType(RequestType.HTTP);
+ onSystemRequest.setBulkData(dataSnapshot);
+ onSystemRequest.setFileType(fileType);
+
+ ProtocolMessage incomingOnSysRequest = createNotificationProtocolMessage(onSystemRequest,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingOnSysRequest);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> argumentCaptor = ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(argumentCaptor.capture());
+
+ // set another connection mock to be able to verify the second time below
+ //final SyncConnection connectionMock2 = createNewSyncConnectionMock();
+ //setSyncConnection(proxy, connectionMock2);
+
+ final ProtocolMessage protocolMessage = argumentCaptor.getValue();
+ assertThat(protocolMessage.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkPutFileJSON(protocolMessage.getData(), fileType);
+ final byte[] data = Arrays.copyOfRange(dataSnapshot, 0, maxDataSize);
+ assertThat(protocolMessage.getBulkData(), is(data));
+ final int putFileRequestCorrID = protocolMessage.getCorrID();
+
+ // the listener should not be called for OnSystemRequest
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response
+ PutFileResponse putFileResponse = new PutFileResponse();
+ putFileResponse.setResultCode(Result.SUCCESS);
+ putFileResponse.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponse = createResponseProtocolMessage(putFileResponse,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponse);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the second part of PutFile to be sent
+ /*ArgumentCaptor<ProtocolMessage> pmCaptor1 = ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock2, times(1)).sendMessage(pmCaptor1.capture());
+
+ // set another connection mock to be able to verify the third time below
+ final SyncConnection connectionMock3 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock3);
+
+ final ProtocolMessage pm1 = pmCaptor1.getValue();
+ assertThat(pm1.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkPutFileJSON(pm1.getData(), maxDataSize, maxDataSize, filename, fileType);
+ final byte[] data1 = Arrays.copyOfRange(dataSnapshot, maxDataSize, maxDataSize * 2);
+ assertThat(pm1.getBulkData(), is(data1));
+ assertThat(pm1.getCorrID(), is(putFileRequestCorrID));
+
+ // the listener should not be called for PutFile
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for second part
+ PutFileResponse putFileResponse2 = new PutFileResponse();
+ putFileResponse2.setResultCode(Result.SUCCESS);
+ putFileResponse2.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM2 = createResponseProtocolMessage(putFileResponse2,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM2);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the third part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor2 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock3, times(1)).sendMessage(pmCaptor2.capture());
+
+ final ProtocolMessage pm2 = pmCaptor2.getValue();
+ assertThat(pm2.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkPutFileJSON(pm2.getData(), maxDataSize * 2, extraDataSize,
+ filename, fileType);
+ final byte[] data2 = Arrays.copyOfRange(dataSnapshot, maxDataSize * 2,
+ (maxDataSize * 2) + extraDataSize);
+ assertThat(pm2.getBulkData(), is(data2));
+ assertThat(pm2.getCorrID(), is(putFileRequestCorrID));
+
+ // the listener should not be called for PutFile
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for third part
+ PutFileResponse putFileResponse3 = new PutFileResponse();
+ putFileResponse3.setResultCode(Result.SUCCESS);
+ putFileResponse3.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM3 =
+ createResponseProtocolMessage(putFileResponse3,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM3);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+ */
+
+ // the listener should not be called for PutFile or OnSystemRequest
+ verify(proxyListenerMock, never()).onPutFileResponse(any(PutFileResponse.class));
+ verify(proxyListenerMock, never()).onOnSystemRequest(any(OnSystemRequest.class));
+ }
+
+ // TODO check the rest is not sent after reconnect
+
+ private SyncConnection createNewSyncConnectionMock() {
+ SyncConnection connectionMock2 = mock(SyncConnection.class);
+ when(connectionMock2.getIsConnected()).thenReturn(true);
+ when(connectionMock2.getWiProProtocol()).thenReturn(protocolMock);
+ return connectionMock2;
+ }
+
+ private ProtocolMessage createResponseProtocolMessage(RPCResponse response,
+ int correlationID,
+ int functionID) {
+ ProtocolMessage incomingPM0 = new ProtocolMessage();
+ incomingPM0.setVersion(PROTOCOL_VERSION);
+ byte[] msgBytes = marshaller.marshall(response, PROTOCOL_VERSION);
+ incomingPM0.setData(msgBytes);
+ incomingPM0.setJsonSize(msgBytes.length);
+ incomingPM0.setMessageType(MessageType.RPC);
+ incomingPM0.setSessionType(ServiceType.RPC);
+ incomingPM0.setFunctionID(functionID);
+ incomingPM0.setRPCType(ProtocolMessage.RPCTYPE_RESPONSE);
+ incomingPM0.setCorrID(correlationID);
+ return incomingPM0;
+ }
+
+ private ProtocolMessage createNotificationProtocolMessage(RPCNotification notification,
+ int functionID) {
+ ProtocolMessage incomingPM0 = new ProtocolMessage();
+ incomingPM0.setVersion(PROTOCOL_VERSION);
+ byte[] msgBytes = marshaller.marshall(notification, PROTOCOL_VERSION);
+ incomingPM0.setJsonSize(msgBytes.length);
+ incomingPM0.setData(msgBytes);
+ incomingPM0.setBulkData(notification.getBulkData());
+ incomingPM0.setMessageType(MessageType.RPC);
+ incomingPM0.setSessionType(ServiceType.RPC);
+ incomingPM0.setFunctionID(functionID);
+ incomingPM0.setRPCType(ProtocolMessage.RPCTYPE_NOTIFICATION);
+ return incomingPM0;
+ }
+
+ private void emulateIncomingMessage(SyncProxyALM proxy, ProtocolMessage protocolMessage)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field interfaceBroker = SyncProxyBase.class.getDeclaredField("_interfaceBroker");
+ interfaceBroker.setAccessible(true);
+ SyncProxyBase.SyncInterfaceBroker broker =
+ (SyncProxyBase.SyncInterfaceBroker) interfaceBroker.get(proxy);
+ broker.onProtocolMessageReceived(protocolMessage);
+ }
+
+ private void setSyncConnection(SyncProxyALM proxy, SyncConnection connection)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field syncConnection = SyncProxyBase.class.getDeclaredField("mSyncConnection");
+ syncConnection.setAccessible(true);
+ syncConnection.set(proxy, connection);
+ }
+
+ private void checkPutFileJSON(byte[] data, FileType fileType)
+ throws JSONException {
+ assertThat("JSON data must not be null", data, IsNull.notNullValue());
+ JSONObject jsonObject = new JSONObject(new String(data, Charset.defaultCharset()));
+ assertThat("fileType must be set", jsonObject.getString(FILE_TYPE), is(fileType.toString()));
+ }
+} \ No newline at end of file
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PutFile_Test.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PutFile_Test.java
new file mode 100644
index 000000000..0a8a33ed5
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/OnSystemRequest_PutFile_Test.java
@@ -0,0 +1,570 @@
+package com.ford.syncV4.integrationtest;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.marshal.IJsonRPCMarshaller;
+import com.ford.syncV4.marshal.JsonRPCMarshaller;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.MessageType;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.proxy.RPCNotification;
+import com.ford.syncV4.proxy.RPCRequest;
+import com.ford.syncV4.proxy.RPCResponse;
+import com.ford.syncV4.proxy.SyncProxyALM;
+import com.ford.syncV4.proxy.SyncProxyBase;
+import com.ford.syncV4.proxy.converter.IRPCRequestConverterFactory;
+import com.ford.syncV4.proxy.converter.SystemPutFileRPCRequestConverter;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALMTesting;
+import com.ford.syncV4.proxy.rpc.OnSystemRequest;
+import com.ford.syncV4.proxy.rpc.PutFileResponse;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.FileType;
+import com.ford.syncV4.proxy.rpc.enums.RequestType;
+import com.ford.syncV4.proxy.rpc.enums.Result;
+import com.ford.syncV4.proxy.systemrequest.IOnSystemRequestHandler;
+import com.ford.syncV4.proxy.systemrequest.ISystemRequestProxy;
+import com.ford.syncV4.syncConnection.SyncConnection;
+import com.ford.syncV4.util.TestConfig;
+
+import org.hamcrest.core.IsNull;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.mockito.ArgumentCaptor;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Vector;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.notNull;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+/**
+ * This is an integration test for how the OnSystemRequest notification and the
+ * PutFile request interact to provide system updates to SDL.
+ *
+ * Created by enikolsky on 2014-02-03.
+ */
+public class OnSystemRequest_PutFile_Test extends InstrumentationTestCase {
+ private static final byte PROTOCOL_VERSION = (byte) 2;
+ private static final int PUTFILE_FUNCTIONID = 32;
+ private static final int ONSYSTEMREQUEST_FUNCTIONID = 32781;
+ private static final String OFFSET = "offset";
+ private static final String LENGTH = "length";
+ private static final String SYNC_FILENAME = "syncFileName";
+ private static final String SYSTEM_FILE = "systemFile";
+ private static final String FILE_TYPE = "fileType";
+ // TODO may cause test failure depending on device
+ private static final int WAIT_TIMEOUT = 20;
+ private IJsonRPCMarshaller marshaller;
+ private IProxyListenerALMTesting proxyListenerMock;
+ private WiProProtocol protocolMock;
+ private SyncConnection connectionMock;
+ private SyncProxyALM proxy;
+ private int maxDataSize;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ marshaller = new JsonRPCMarshaller();
+
+ // we have to use the special IProxyListenerALMTesting here to allow to
+ // send messages at any time
+ proxyListenerMock = mock(IProxyListenerALMTesting.class);
+ protocolMock = mock(WiProProtocol.class);
+ connectionMock = createNewSyncConnectionMock();
+
+ proxy = new SyncProxyALM(proxyListenerMock, null, "a", null, null,
+ false, null, null, null, null, null, null, false, false, 2,
+ null, connectionMock, new TestConfig());
+
+ final SystemPutFileRPCRequestConverter converter =
+ new SystemPutFileRPCRequestConverter();
+ maxDataSize = 64;
+ converter.setMaxDataSize(maxDataSize);
+ IRPCRequestConverterFactory factoryMock =
+ mock(IRPCRequestConverterFactory.class);
+ when(factoryMock.getConverterForRequest(
+ notNull(RPCRequest.class))).thenReturn(converter);
+ proxy.setRpcRequestConverterFactory(factoryMock);
+ }
+
+ public void testOnSystemRequestRequestTypeHTTPShouldSendPartialPutFile()
+ throws Exception {
+ // fake data for PutFile
+ final int extraDataSize = 10;
+ final int dataSize = (maxDataSize * 2) + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String filename = "fake";
+ final List<String> urls = Arrays.asList("http://example.com/");
+ final FileType fileType = FileType.GRAPHIC_PNG;
+
+ IOnSystemRequestHandler handlerMock =
+ mock(IOnSystemRequestHandler.class);
+ doAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocationOnMock)
+ throws Throwable {
+ final ISystemRequestProxy proxy =
+ (ISystemRequestProxy) invocationOnMock.getArguments()[0];
+ proxy.putSystemFile(filename, data, fileType);
+ return null;
+ }
+ }).when(handlerMock)
+ .onFilesDownloadRequest(notNull(ISystemRequestProxy.class), eq(urls),
+ eq(fileType));
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ // emulate incoming OnSystemRequest notification with HTTP
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+
+ ProtocolMessage incomingOnSysRqPM0 =
+ createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingOnSysRqPM0);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the first part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor0 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(pmCaptor0.capture());
+
+ // set another connection mock to be able to verify the second time below
+ final SyncConnection connectionMock2 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock2);
+
+ final ProtocolMessage pm0 = pmCaptor0.getValue();
+ assertThat(pm0.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm0.getData(), 0, maxDataSize, filename,
+ fileType);
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm0.getBulkData(), is(data0));
+ final int putFileRequestCorrID = pm0.getCorrID();
+
+ // the listener should not be called for OnSystemRequest
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for first part
+ PutFileResponse putFileResponse1 = new PutFileResponse();
+ putFileResponse1.setResultCode(Result.SUCCESS);
+ putFileResponse1.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM1 =
+ createResponseProtocolMessage(putFileResponse1,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM1);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the second part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor1 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock2, times(1)).sendMessage(pmCaptor1.capture());
+
+ // set another connection mock to be able to verify the third time below
+ final SyncConnection connectionMock3 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock3);
+
+ final ProtocolMessage pm1 = pmCaptor1.getValue();
+ assertThat(pm1.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm1.getData(), maxDataSize, maxDataSize,
+ filename, fileType);
+ final byte[] data1 =
+ Arrays.copyOfRange(data, maxDataSize, maxDataSize * 2);
+ assertThat(pm1.getBulkData(), is(data1));
+ assertThat(pm1.getCorrID(), is(putFileRequestCorrID));
+
+ // the listener should not be called for PutFile
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for second part
+ PutFileResponse putFileResponse2 = new PutFileResponse();
+ putFileResponse2.setResultCode(Result.SUCCESS);
+ putFileResponse2.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM2 =
+ createResponseProtocolMessage(putFileResponse2,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM2);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the third part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor2 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock3, times(1)).sendMessage(pmCaptor2.capture());
+
+ final ProtocolMessage pm2 = pmCaptor2.getValue();
+ assertThat(pm2.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm2.getData(), maxDataSize * 2, extraDataSize,
+ filename, fileType);
+ final byte[] data2 = Arrays.copyOfRange(data, maxDataSize * 2,
+ (maxDataSize * 2) + extraDataSize);
+ assertThat(pm2.getBulkData(), is(data2));
+ assertThat(pm2.getCorrID(), is(putFileRequestCorrID));
+
+ // the listener should not be called for PutFile
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for third part
+ PutFileResponse putFileResponse3 = new PutFileResponse();
+ putFileResponse3.setResultCode(Result.SUCCESS);
+ putFileResponse3.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM3 =
+ createResponseProtocolMessage(putFileResponse3,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM3);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // the listener should not be called for PutFile or OnSystemRequest
+ verify(proxyListenerMock, never()).onPutFileResponse(
+ any(PutFileResponse.class));
+ verify(proxyListenerMock, never()).onOnSystemRequest(
+ any(OnSystemRequest.class));
+
+ // phew, done
+ }
+
+ public void testSystemPutFileShouldStopOnErrorResponse() throws Exception {
+ // fake data for PutFile
+ final int extraDataSize = 10;
+ final int dataSize = (maxDataSize * 2) + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String filename = "fake";
+ final List<String> urls = Arrays.asList("http://example.com/");
+ final FileType fileType = FileType.GRAPHIC_PNG;
+
+ IOnSystemRequestHandler handlerMock =
+ mock(IOnSystemRequestHandler.class);
+ doAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocationOnMock)
+ throws Throwable {
+ final ISystemRequestProxy proxy =
+ (ISystemRequestProxy) invocationOnMock.getArguments()[0];
+ proxy.putSystemFile(filename, data, fileType);
+ return null;
+ }
+ }).when(handlerMock)
+ .onFilesDownloadRequest(notNull(ISystemRequestProxy.class), eq(urls),
+ eq(fileType));
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ // emulate incoming OnSystemRequest notification with HTTP
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+
+ ProtocolMessage incomingOnSysRqPM0 =
+ createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingOnSysRqPM0);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the first part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor0 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(pmCaptor0.capture());
+
+ // set another connection mock to be able to verify the second time below
+ final SyncConnection connectionMock2 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock2);
+
+ final ProtocolMessage pm0 = pmCaptor0.getValue();
+ assertThat(pm0.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm0.getData(), 0, maxDataSize, filename,
+ fileType);
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm0.getBulkData(), is(data0));
+ final int putFileRequestCorrID = pm0.getCorrID();
+
+ // the listener should not be called for OnSystemRequest
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile error response for first part
+ final Result resultCode1 = Result.INVALID_DATA;
+ PutFileResponse putFileResponse1 = new PutFileResponse();
+ putFileResponse1.setResultCode(resultCode1);
+ putFileResponse1.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM1 =
+ createResponseProtocolMessage(putFileResponse1,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM1);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT * 2);
+
+ // expect the second part of PutFile not to be sent
+ verify(connectionMock2, never()).sendMessage(
+ any(ProtocolMessage.class));
+
+ // the listener should not be called for PutFile or OnSystemRequest
+ verify(proxyListenerMock, never()).onPutFileResponse(
+ any(PutFileResponse.class));
+ verify(proxyListenerMock, never()).onOnSystemRequest(
+ any(OnSystemRequest.class));
+
+ // phew, done
+ }
+
+ public void testOnSystemRequestRequestTypeFileResumeShouldSendPartialPutFile()
+ throws Exception {
+ // fake data for PutFile
+ final int extraDataSize = 30;
+ final int dataSize = (maxDataSize * 2) + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String filename = "fake";
+ final List<String> filenames = Arrays.asList(filename);
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 4000;
+
+ IOnSystemRequestHandler handlerMock =
+ mock(IOnSystemRequestHandler.class);
+ doAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocationOnMock)
+ throws Throwable {
+ final ISystemRequestProxy proxy =
+ (ISystemRequestProxy) invocationOnMock.getArguments()[0];
+ proxy.putSystemFile(filename, data, offset, fileType);
+ return null;
+ }
+ }).when(handlerMock)
+ .onFileResumeRequest(notNull(ISystemRequestProxy.class), eq(filename),
+ eq(offset), eq(dataSize), eq(fileType));
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ // emulate incoming OnSystemRequest notification with FILE_RESUME
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setUrl(new Vector<String>(filenames));
+ onSysRq.setFileType(fileType);
+ onSysRq.setOffset(offset);
+ onSysRq.setLength(dataSize);
+
+ ProtocolMessage incomingOnSysRqPM0 =
+ createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingOnSysRqPM0);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the first part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor0 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(pmCaptor0.capture());
+
+ // set another connection mock to be able to verify the second time below
+ final SyncConnection connectionMock2 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock2);
+
+ final ProtocolMessage pm0 = pmCaptor0.getValue();
+ assertThat(pm0.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm0.getData(), offset, maxDataSize, filename,
+ fileType);
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm0.getBulkData(), is(data0));
+ final int putFileRequestCorrID = pm0.getCorrID();
+
+ // the listener should not be called for OnSystemRequest
+ verify(proxyListenerMock, never()).onOnSystemRequest(
+ any(OnSystemRequest.class));
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for first part
+ PutFileResponse putFileResponse1 = new PutFileResponse();
+ putFileResponse1.setResultCode(Result.SUCCESS);
+ putFileResponse1.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM1 =
+ createResponseProtocolMessage(putFileResponse1,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM1);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the second part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor1 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock2, times(1)).sendMessage(pmCaptor1.capture());
+
+ // set another connection mock to be able to verify the third time below
+ final SyncConnection connectionMock3 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock3);
+
+ final ProtocolMessage pm1 = pmCaptor1.getValue();
+ assertThat(pm1.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm1.getData(), offset + maxDataSize, maxDataSize,
+ filename, fileType);
+ final byte[] data1 =
+ Arrays.copyOfRange(data, maxDataSize, maxDataSize * 2);
+ assertThat(pm1.getBulkData(), is(data1));
+ assertThat(pm1.getCorrID(), is(putFileRequestCorrID));
+
+ // the listener should not be called for PutFile
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for second part
+ PutFileResponse putFileResponse2 = new PutFileResponse();
+ putFileResponse2.setResultCode(Result.SUCCESS);
+ putFileResponse2.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM2 =
+ createResponseProtocolMessage(putFileResponse2,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM2);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the third part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor2 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock3, times(1)).sendMessage(pmCaptor2.capture());
+
+ final ProtocolMessage pm2 = pmCaptor2.getValue();
+ assertThat(pm2.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm2.getData(), offset + (maxDataSize * 2),
+ extraDataSize, filename, fileType);
+ final byte[] data2 = Arrays.copyOfRange(data, maxDataSize * 2,
+ (maxDataSize * 2) + extraDataSize);
+ assertThat(pm2.getBulkData(), is(data2));
+ assertThat(pm2.getCorrID(), is(putFileRequestCorrID));
+
+ // the listener should not be called for PutFile
+ verifyZeroInteractions(proxyListenerMock);
+
+ // emulate incoming PutFile response for third part
+ PutFileResponse putFileResponse3 = new PutFileResponse();
+ putFileResponse3.setResultCode(Result.SUCCESS);
+ putFileResponse3.setCorrelationID(putFileRequestCorrID);
+
+ ProtocolMessage incomingPutFileResponsePM3 =
+ createResponseProtocolMessage(putFileResponse3,
+ putFileRequestCorrID, PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPutFileResponsePM3);
+
+ // wait for processing
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // the listener should not be called for PutFile or OnSystemRequest
+ verify(proxyListenerMock, never()).onPutFileResponse(
+ any(PutFileResponse.class));
+ verify(proxyListenerMock, never()).onOnSystemRequest(
+ any(OnSystemRequest.class));
+
+ // phew, done
+ }
+
+ // TODO check the rest is not sent after reconnect
+
+ private SyncConnection createNewSyncConnectionMock() {
+ SyncConnection connectionMock2 = mock(SyncConnection.class);
+ when(connectionMock2.getIsConnected()).thenReturn(true);
+ when(connectionMock2.getWiProProtocol()).thenReturn(protocolMock);
+ return connectionMock2;
+ }
+
+ private ProtocolMessage createResponseProtocolMessage(RPCResponse response,
+ int correlationID,
+ int functionID) {
+ ProtocolMessage incomingPM0 = new ProtocolMessage();
+ incomingPM0.setVersion(PROTOCOL_VERSION);
+ byte[] msgBytes = marshaller.marshall(response, PROTOCOL_VERSION);
+ incomingPM0.setData(msgBytes);
+ incomingPM0.setJsonSize(msgBytes.length);
+ incomingPM0.setMessageType(MessageType.RPC);
+ incomingPM0.setSessionType(ServiceType.RPC);
+ incomingPM0.setFunctionID(functionID);
+ incomingPM0.setRPCType(ProtocolMessage.RPCTYPE_RESPONSE);
+ incomingPM0.setCorrID(correlationID);
+ return incomingPM0;
+ }
+
+ private ProtocolMessage createNotificationProtocolMessage(
+ RPCNotification notification, int functionID) {
+ ProtocolMessage incomingPM0 = new ProtocolMessage();
+ incomingPM0.setVersion(PROTOCOL_VERSION);
+ byte[] msgBytes = marshaller.marshall(notification, PROTOCOL_VERSION);
+ incomingPM0.setData(msgBytes);
+ incomingPM0.setJsonSize(msgBytes.length);
+ incomingPM0.setMessageType(MessageType.RPC);
+ incomingPM0.setSessionType(ServiceType.RPC);
+ incomingPM0.setFunctionID(functionID);
+ incomingPM0.setRPCType(ProtocolMessage.RPCTYPE_NOTIFICATION);
+ return incomingPM0;
+ }
+
+ private void emulateIncomingMessage(SyncProxyALM proxy, ProtocolMessage pm)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field interfaceBroker =
+ SyncProxyBase.class.getDeclaredField("_interfaceBroker");
+ interfaceBroker.setAccessible(true);
+ SyncProxyBase.SyncInterfaceBroker broker =
+ (SyncProxyBase.SyncInterfaceBroker) interfaceBroker.get(proxy);
+ broker.onProtocolMessageReceived(pm);
+ }
+
+ private void setSyncConnection(SyncProxyALM proxy,
+ SyncConnection connection)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field syncConnection =
+ SyncProxyBase.class.getDeclaredField("mSyncConnection");
+ syncConnection.setAccessible(true);
+ syncConnection.set(proxy, connection);
+ }
+
+ private void checkSystemPutFileJSON(byte[] data, int offset, int length,
+ String filename, FileType fileType)
+ throws JSONException {
+ assertThat("JSON data must not be null", data, IsNull.notNullValue());
+
+ JSONObject jsonObject =
+ new JSONObject(new String(data, Charset.defaultCharset()));
+ assertThat("offset doesn't match", jsonObject.getInt(OFFSET),
+ is(offset));
+ assertThat("length doesn't match", jsonObject.getInt(LENGTH),
+ is(length));
+ assertThat("filename must be set", jsonObject.getString(SYNC_FILENAME),
+ is(filename));
+ assertThat("systemFile must be true",
+ jsonObject.getBoolean(SYSTEM_FILE), is(true));
+ assertThat("fileType must be set", jsonObject.getString(FILE_TYPE),
+ is(fileType.toString()));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/PutFileRequestSendingTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/PutFileRequestSendingTest.java
new file mode 100644
index 000000000..f8764d024
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/integrationtest/PutFileRequestSendingTest.java
@@ -0,0 +1,242 @@
+package com.ford.syncV4.integrationtest;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.marshal.IJsonRPCMarshaller;
+import com.ford.syncV4.marshal.JsonRPCMarshaller;
+import com.ford.syncV4.protocol.IProtocolListener;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.MessageType;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.proxy.RPCRequestFactory;
+import com.ford.syncV4.proxy.RPCResponse;
+import com.ford.syncV4.proxy.SyncProxyALM;
+import com.ford.syncV4.proxy.SyncProxyBase;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALMTesting;
+import com.ford.syncV4.proxy.rpc.PutFile;
+import com.ford.syncV4.proxy.rpc.PutFileResponse;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.Result;
+import com.ford.syncV4.syncConnection.SyncConnection;
+import com.ford.syncV4.util.TestConfig;
+
+import org.hamcrest.CoreMatchers;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.mockito.ArgumentCaptor;
+
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * This is a integration test for how the PutFile request is broken down into
+ * protocol frames to be sent.
+ *
+ * Created by enikolsky on 2014-01-20.
+ */
+public class PutFileRequestSendingTest extends InstrumentationTestCase {
+ private static final byte PROTOCOL_VERSION = (byte) 2;
+ private static final int PUTFILE_FUNCTIONID = 32;
+ private static final String OFFSET = "offset";
+ private static final String LENGTH = "length";
+ private static final int WAIT_TIMEOUT = 20;
+ private IJsonRPCMarshaller marshaller;
+ private IProxyListenerALMTesting proxyListenerMock;
+ private WiProProtocol protocolMock;
+ private SyncConnection connectionMock;
+ private SyncProxyALM proxy;
+ private int maxDataSize;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ marshaller = new JsonRPCMarshaller();
+
+ // we have to use the special IProxyListenerALMTesting here to allow to
+ // send messages at any time
+ proxyListenerMock = mock(IProxyListenerALMTesting.class);
+ protocolMock = mock(WiProProtocol.class);
+ connectionMock = createNewSyncConnectionMock();
+
+ proxy = new SyncProxyALM(proxyListenerMock, null, "a", null, null,
+ false, null, null, null, null, null, null, false, false, 2,
+ null, connectionMock, new TestConfig());
+
+ WiProProtocol protocol =
+ new WiProProtocol(mock(IProtocolListener.class));
+ protocol.setVersion(PROTOCOL_VERSION);
+ maxDataSize = WiProProtocol.MAX_DATA_SIZE;
+ }
+
+ public void testBigPutFileRequestShouldNotBeSentInPartsAndProxyListenerShouldBeCalledOnce()
+ throws Exception {
+ final int extraDataSize = 10;
+ final int dataSize = maxDataSize + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+ final int correlationID = 0;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setCorrelationID(correlationID);
+ proxy.sendRPCRequest(msg);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // we expect the whole PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor0 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(pmCaptor0.capture());
+
+ final ProtocolMessage pm0 = pmCaptor0.getValue();
+ checkNoOffsetAndLengthInJSON(pm0.getData());
+ assertThat(pm0.getBulkData(), is(data));
+
+
+ SyncConnection connectionMock2 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock2);
+
+ // emulate incoming PutFile response
+ PutFileResponse response = new PutFileResponse();
+ response.setResultCode(Result.SUCCESS);
+ response.setCorrelationID(correlationID);
+
+ ProtocolMessage incomingPM0 =
+ createResponseProtocolMessage(response, correlationID,
+ PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPM0);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // the listener should be called now
+ ArgumentCaptor<PutFileResponse> responseCaptor =
+ ArgumentCaptor.forClass(PutFileResponse.class);
+ verify(proxyListenerMock, times(1)).onPutFileResponse(
+ responseCaptor.capture());
+ final PutFileResponse putFileResponse = responseCaptor.getValue();
+ assertThat(putFileResponse.getResultCode(), is(Result.SUCCESS));
+ assertThat(putFileResponse.getCorrelationID(), is(correlationID));
+
+ // we expect no other PutFile to be sent
+ verify(connectionMock2, never()).sendMessage(
+ any(ProtocolMessage.class));
+ }
+
+ public void testProxyListenerShouldBeCalledOnceOnBigPutFileErrorResponse()
+ throws Exception {
+ final int extraDataSize = 10;
+ final int dataSize = maxDataSize + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+ final int correlationID = 0;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setCorrelationID(correlationID);
+ proxy.sendRPCRequest(msg);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // we expect the whole PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor0 =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(pmCaptor0.capture());
+
+ final ProtocolMessage pm0 = pmCaptor0.getValue();
+ checkNoOffsetAndLengthInJSON(pm0.getData());
+ assertThat(pm0.getBulkData(), is(data));
+
+
+ SyncConnection connectionMock2 = createNewSyncConnectionMock();
+ setSyncConnection(proxy, connectionMock2);
+
+ // emulate incoming PutFile response
+ PutFileResponse response = new PutFileResponse();
+ final Result resultCode = Result.INVALID_DATA;
+ response.setResultCode(resultCode);
+ response.setCorrelationID(correlationID);
+
+ ProtocolMessage incomingPM0 =
+ createResponseProtocolMessage(response, correlationID,
+ PUTFILE_FUNCTIONID);
+ emulateIncomingMessage(proxy, incomingPM0);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // the listener should be called now
+ ArgumentCaptor<PutFileResponse> responseCaptor =
+ ArgumentCaptor.forClass(PutFileResponse.class);
+ verify(proxyListenerMock, times(1)).onPutFileResponse(
+ responseCaptor.capture());
+ final PutFileResponse putFileResponse = responseCaptor.getValue();
+ assertThat(putFileResponse.getResultCode(), is(resultCode));
+ assertThat(putFileResponse.getCorrelationID(), is(correlationID));
+
+ // we expect no other PutFile to be sent
+ verify(connectionMock2, never()).sendMessage(
+ any(ProtocolMessage.class));
+ }
+
+ private SyncConnection createNewSyncConnectionMock() {
+ SyncConnection connectionMock2 = mock(SyncConnection.class);
+ when(connectionMock2.getIsConnected()).thenReturn(true);
+ when(connectionMock2.getWiProProtocol()).thenReturn(protocolMock);
+ return connectionMock2;
+ }
+
+ private ProtocolMessage createResponseProtocolMessage(RPCResponse response,
+ int correlationID,
+ int functionID) {
+ ProtocolMessage incomingPM0 = new ProtocolMessage();
+ incomingPM0.setVersion(PROTOCOL_VERSION);
+ byte[] msgBytes = marshaller.marshall(response, PROTOCOL_VERSION);
+ incomingPM0.setData(msgBytes);
+ incomingPM0.setJsonSize(msgBytes.length);
+ incomingPM0.setMessageType(MessageType.RPC);
+ incomingPM0.setSessionType(ServiceType.RPC);
+ incomingPM0.setFunctionID(functionID);
+ incomingPM0.setRPCType(ProtocolMessage.RPCTYPE_RESPONSE);
+ incomingPM0.setCorrID(correlationID);
+ return incomingPM0;
+ }
+
+ private void emulateIncomingMessage(SyncProxyALM proxy, ProtocolMessage pm)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field interfaceBroker =
+ SyncProxyBase.class.getDeclaredField("_interfaceBroker");
+ interfaceBroker.setAccessible(true);
+ SyncProxyBase.SyncInterfaceBroker broker =
+ (SyncProxyBase.SyncInterfaceBroker) interfaceBroker.get(proxy);
+ broker.onProtocolMessageReceived(pm);
+ }
+
+ private void setSyncConnection(SyncProxyALM proxy,
+ SyncConnection connection)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field syncConnection =
+ SyncProxyBase.class.getDeclaredField("mSyncConnection");
+ syncConnection.setAccessible(true);
+ syncConnection.set(proxy, connection);
+ }
+
+ private void checkNoOffsetAndLengthInJSON(byte[] data)
+ throws JSONException {
+ assertThat("JSON data must not be null", data,
+ CoreMatchers.notNullValue());
+
+ JSONObject jsonObject =
+ new JSONObject(new String(data, Charset.defaultCharset()));
+ assertThat(jsonObject.has(OFFSET), is(false));
+ assertThat(jsonObject.has(LENGTH), is(false));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/BinaryFrameHeaderTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/BinaryFrameHeaderTest.java
new file mode 100644
index 000000000..0a2856322
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/BinaryFrameHeaderTest.java
@@ -0,0 +1,64 @@
+package com.ford.syncV4.protocol;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class BinaryFrameHeaderTest extends TestCase {
+ public void testParseJsonSizeZeroShouldReturnCorrectJsonSize() {
+ final byte[] bytes =
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00 };
+ BinaryFrameHeader header = BinaryFrameHeader.parseBinaryHeader(bytes);
+ Assert.assertEquals("Parsed json size is incorrect", 0,
+ header.getJsonSize());
+ }
+
+ public void testParseJsonSizeOneShouldReturnCorrectSize() {
+ final byte[] bytes =
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00 };
+ BinaryFrameHeader header = BinaryFrameHeader.parseBinaryHeader(bytes);
+ Assert.assertEquals("Parsed json size is incorrect", 1,
+ header.getJsonSize());
+ }
+
+ public void testParseJsonSizeHalfMaxShouldThrowOutOfMemory() {
+ try {
+ final byte maxByte = (byte) 0xFF;
+ final byte[] bytes =
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F,
+ maxByte, maxByte, maxByte };
+ BinaryFrameHeader.parseBinaryHeader(bytes);
+ fail("Should have thrown OutOfMemoryError");
+ } catch (OutOfMemoryError e) {
+ // success
+ }
+ }
+
+ public void testParseJsonSizeHalfMaxPlusOneShouldThrowOutOfMemory() {
+ // this 0x80000000 number is also the first negative number after
+ // 0x7FFFFFFF
+ try {
+ final byte[] bytes =
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ (byte) 0x80, 0x00, 0x00, 0x00 };
+ BinaryFrameHeader.parseBinaryHeader(bytes);
+ fail("Should have thrown OutOfMemoryError");
+ } catch (OutOfMemoryError e) {
+ // success
+ }
+ }
+
+ public void testParseJsonSizeMaxShouldThrowOutOfMemory() {
+ try {
+ final byte maxByte = (byte) 0xFF;
+ final byte[] bytes =
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, maxByte,
+ maxByte, maxByte, maxByte, 0x00 };
+ BinaryFrameHeader.parseBinaryHeader(bytes);
+ fail("Should have thrown OutOfMemoryError");
+ } catch (OutOfMemoryError e) {
+ // success
+ }
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderFactoryTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderFactoryTest.java
new file mode 100644
index 000000000..81680ba8b
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderFactoryTest.java
@@ -0,0 +1,170 @@
+package com.ford.syncV4.protocol;
+
+import android.test.AndroidTestCase;
+
+import com.ford.syncV4.protocol.enums.FrameDataControlFrameType;
+import com.ford.syncV4.protocol.enums.FrameType;
+import com.ford.syncV4.protocol.enums.ServiceType;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Created by Andrew Batutin on 8/20/13.
+ */
+public class ProtocolFrameHeaderFactoryTest extends AndroidTestCase {
+ static final byte SESSION_TYPE_RPC = 0x07;
+ static final byte PROTOCOL_VERSION = 0x02;
+ static final byte FRAME_HEARTBEAT = 0x00;
+ static final byte FRAME_HEARTBEAT_ACK = (byte) 0xFF;
+
+ public void testMobileNavStartSessionFrameCreation() throws Exception {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createMobileNavStartSession(48,
+ (byte) 48, (byte) 2);
+ assertEquals(header.getServiceType(), ServiceType.Mobile_Nav);
+ assertEquals(header.getFrameType(), FrameType.Control);
+ assertEquals(header.getFrameData(),
+ FrameDataControlFrameType.StartService.getValue());
+ assertEquals(header.getVersion(), (byte) 2);
+ assertEquals(header.isCompressed(), false);
+ assertEquals(header.getDataSize(), 0x00);
+ assertTrue(header.getMessageID() == 48);
+ assertTrue(header.getSessionID() == (byte) 48);
+ }
+
+ public void testSessionStartACKFrameCreation() throws Exception {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createStartSessionACK(
+ ServiceType.RPC, (byte) 48, 48, (byte) 2);
+ byte[] data = header.assembleHeaderBytes();
+ assertNotNull("data should not be null", data);
+ }
+
+ public void testSessionStartNACKFrameCreation() throws Exception {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createStartSessionNACK(
+ ServiceType.Mobile_Nav, (byte) 48, 48, (byte) 2);
+ byte[] data = header.assembleHeaderBytes();
+ assertNotNull("data should not be null", data);
+ }
+
+ public void testMobileNavStartSessionACKFrameCreation() throws Exception {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createStartSessionACK(
+ ServiceType.Mobile_Nav, (byte) 48, 48, (byte) 2);
+ assertEquals(header.getServiceType(), ServiceType.Mobile_Nav);
+ assertEquals(header.getFrameType(), FrameType.Control);
+ assertEquals(header.getFrameData(),
+ FrameDataControlFrameType.StartServiceACK.getValue());
+ assertEquals(header.getVersion(), (byte) 2);
+ assertEquals(header.isCompressed(), false);
+ assertEquals(header.getDataSize(), 0x00);
+ assertTrue(header.getMessageID() == 48);
+ assertTrue(header.getSessionID() == (byte) 48);
+ }
+
+ public void testMobileNavEndSessionFrameCreation() throws Exception {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createEndSession(
+ ServiceType.Mobile_Nav, (byte) 48, 48, (byte) 2, 0);
+ assertEquals(header.getServiceType(), ServiceType.Mobile_Nav);
+ assertEquals(header.getFrameType(), FrameType.Control);
+ assertEquals(header.getFrameData(),
+ FrameDataControlFrameType.EndService.getValue());
+ assertEquals(header.getVersion(), (byte) 2);
+ assertEquals(header.isCompressed(), false);
+ assertEquals(header.getDataSize(), 0x00);
+ assertTrue(header.getMessageID() == 48);
+ assertTrue(header.getSessionID() == (byte) 48);
+ }
+
+ public void testMobileNavDataSessionFrameCreation() throws Exception {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createSingleSendData(
+ ServiceType.Mobile_Nav, (byte) 48, 10, 48, (byte) 2);
+ assertEquals(header.getServiceType(), ServiceType.Mobile_Nav);
+ assertEquals(header.getFrameType(), FrameType.Single);
+ assertEquals(header.getFrameData(), 0x00);
+ assertEquals(header.getVersion(), (byte) 2);
+ assertEquals(header.isCompressed(), false);
+ assertEquals(header.getDataSize(), 10);
+ assertTrue(header.getMessageID() == 48);
+ assertTrue(header.getSessionID() == (byte) 48);
+ }
+
+ public void testMobileNavAckFrameCreation() throws Exception {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createMobileNaviAck(
+ ServiceType.Mobile_Nav, (byte) 48, 48, (byte) 2);
+ assertEquals(header.getServiceType(), ServiceType.Mobile_Nav);
+ assertEquals(header.getFrameType(), FrameType.Control);
+ assertEquals(header.getFrameData(),
+ FrameDataControlFrameType.MobileNaviACK.getValue());
+ assertEquals(header.getVersion(), (byte) 2);
+ assertEquals(header.isCompressed(), false);
+ assertEquals(header.getDataSize(), 0);
+ assertTrue(header.getMessageID() == 48);
+ assertTrue(header.getSessionID() == (byte) 48);
+ }
+
+ public void testCreatedHeartbeatShouldHaveCorrectBytes() {
+ ProtocolFrameHeader header = ProtocolFrameHeaderFactory.createHeartbeat(
+ ServiceType.valueOf(SESSION_TYPE_RPC), PROTOCOL_VERSION);
+
+ final byte[] correct =
+ new byte[]{ 0x20, SESSION_TYPE_RPC, FRAME_HEARTBEAT, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ assertThat("Wrong binary header", header.assembleHeaderBytes(),
+ is(correct));
+ }
+
+ public void testCreatedHeartbeatShouldHaveCorrectHeaderValues() {
+ ProtocolFrameHeader header = ProtocolFrameHeaderFactory.createHeartbeat(
+ ServiceType.Heartbeat, PROTOCOL_VERSION);
+
+ assertThat("Wrong version", header.getVersion(), is(PROTOCOL_VERSION));
+ assertThat("Wrong compression flag", header.isCompressed(), is(false));
+ assertThat("Wrong frame type", header.getFrameType(),
+ is(FrameType.Control));
+ assertThat("Wrong currentSession type", header.getServiceType(),
+ is(ServiceType.Heartbeat));
+ assertThat("Wrong frame data", header.getFrameData(),
+ is(FrameDataControlFrameType.Heartbeat.value()));
+ assertThat("Wrong currentSession id", header.getSessionID(), is((byte) 0));
+ assertThat("Wrong data size", header.getDataSize(), is(0));
+ assertThat("Wrong message id", header.getMessageID(), is(0));
+ }
+
+ public void testCreatedHeartbeatACKShouldHaveCorrectBytes() {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createHeartbeatACK(
+ ServiceType.valueOf(SESSION_TYPE_RPC),
+ PROTOCOL_VERSION);
+
+ final byte[] correct =
+ new byte[]{ 0x20, SESSION_TYPE_RPC, FRAME_HEARTBEAT_ACK, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ assertThat("Wrong binary header", header.assembleHeaderBytes(),
+ is(correct));
+ }
+
+ public void testCreatedHeartbeatACKShouldHaveCorrectHeaderValues() {
+ ProtocolFrameHeader header =
+ ProtocolFrameHeaderFactory.createHeartbeatACK(
+ ServiceType.valueOf(SESSION_TYPE_RPC),
+ PROTOCOL_VERSION);
+
+ assertThat("Wrong version", header.getVersion(), is(PROTOCOL_VERSION));
+ assertThat("Wrong compression flag", header.isCompressed(), is(false));
+ assertThat("Wrong frame type", header.getFrameType(),
+ is(FrameType.Control));
+ assertThat("Wrong currentSession type", header.getServiceType(),
+ is(ServiceType.RPC));
+ assertThat("Wrong frame data", header.getFrameData(),
+ is(FrameDataControlFrameType.HeartbeatACK.value()));
+ assertThat("Wrong currentSession id", header.getSessionID(), is((byte) 0));
+ assertThat("Wrong data size", header.getDataSize(), is(0));
+ assertThat("Wrong message id", header.getMessageID(), is(0));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderTest.java
new file mode 100644
index 000000000..43eca87c5
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolFrameHeaderTest.java
@@ -0,0 +1,37 @@
+package com.ford.syncV4.protocol;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class ProtocolFrameHeaderTest extends TestCase {
+ public void testParseDataSizeZero() {
+ final byte[] bytes =
+ { 0x20, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00 };
+ ProtocolFrameHeader header =
+ ProtocolFrameHeader.parseWiProHeader(bytes);
+ Assert.assertEquals("Parsed data size is incorrect", 0,
+ header.getDataSize());
+ }
+
+ public void testParseDataSizeOne() {
+ final byte[] bytes =
+ { 0x20, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00 };
+ ProtocolFrameHeader header =
+ ProtocolFrameHeader.parseWiProHeader(bytes);
+ Assert.assertEquals("Parsed data size is incorrect", 1,
+ header.getDataSize());
+ }
+
+ public void testParseDataSizeMax() {
+ final byte maxByte = (byte) 0xFF;
+ final byte[] bytes =
+ { 0x20, 0x07, 0x01, 0x01, maxByte, maxByte, maxByte, maxByte,
+ 0x00, 0x00, 0x00, 0x00 };
+ ProtocolFrameHeader header =
+ ProtocolFrameHeader.parseWiProHeader(bytes);
+ Assert.assertEquals("Parsed data size is incorrect", 0xFFFFFFFF,
+ header.getDataSize());
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolMessageConverterTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolMessageConverterTest.java
new file mode 100644
index 000000000..dc1119c92
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/ProtocolMessageConverterTest.java
@@ -0,0 +1,36 @@
+package com.ford.syncV4.protocol;
+
+import android.test.AndroidTestCase;
+
+import com.ford.syncV4.protocol.enums.ServiceType;
+
+import java.util.Arrays;
+
+/**
+ * Created by Andrew Batutin on 8/21/13.
+ */
+public class ProtocolMessageConverterTest extends AndroidTestCase {
+
+ public ProtocolMessageConverterTest() {
+ }
+
+ public void testMobileNavDataPayloadCreation() throws Exception {
+ byte [] frame = new byte[]{1,2,3,4,5,7};
+ ProtocolMessage message = new ProtocolMessage();
+ message.setData(frame);
+ message.setSessionType(ServiceType.Mobile_Nav);
+ ProtocolMessageConverter converter = new ProtocolMessageConverter(message, 2);
+ byte[] result = converter.generate().getData();
+ assertTrue("for mobile nav data should be same as ProtocolMessage.data", Arrays.equals(result, frame));
+ }
+
+ public void testAudioServiceDataPayloadCreation() throws Exception {
+ byte [] frame = new byte[]{1,2,3,4,5,7};
+ ProtocolMessage message = new ProtocolMessage();
+ message.setData(frame);
+ message.setSessionType(ServiceType.Audio_Service);
+ ProtocolMessageConverter converter = new ProtocolMessageConverter(message, 2);
+ byte[] result = converter.generate().getData();
+ assertTrue("for audio service data should be same as ProtocolMessage.data", Arrays.equals(result, frame));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/UnregisterWithoutDisconnectTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/UnregisterWithoutDisconnectTest.java
new file mode 100644
index 000000000..15ef6f3c5
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/UnregisterWithoutDisconnectTest.java
@@ -0,0 +1,96 @@
+package com.ford.syncV4.protocol;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.exception.SyncException;
+import com.ford.syncV4.proxy.SyncProxyALM;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALM;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.syncConnection.SyncConnection;
+import com.ford.syncV4.transport.SyncTransport;
+import com.ford.syncV4.util.TestConfig;
+
+import static org.mockito.Matchers.anyByte;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Tests for the case when the app wants to unregister itself without closing
+ * its connection.
+ *
+ * Created by enikolsky on 2013-11-15.
+ */
+public class UnregisterWithoutDisconnectTest extends InstrumentationTestCase {
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+ }
+
+ public void testResetProxyShouldDisconnectTransport() throws Exception {
+ SyncTransport transportMock = mock(SyncTransport.class);
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+
+ SyncConnection connection = spy(new SyncConnection(null));
+ connection.init(null, transportMock);
+
+ SyncProxyALM syncProxy =
+ new SyncProxyALM(proxyListenerMock, null, "test", null, null,
+ false, null, null, null, null, null, null, false, false,
+ 2, null, connection, new TestConfig());
+ assertNotNull(syncProxy);
+
+ syncProxy.resetProxy();
+
+ // FIXME: unfortunately, I can't verify that
+ // SyncProxyBase.unregisterAppInterfacePrivate() is called because it's
+ // protected. And I couldn't add the PowerMock library to the project
+ // due to errors during 'dexTest' step
+
+ verify(connection).closeConnection(anyByte(), eq(false));
+ verify(transportMock).disconnect();
+ }
+
+ public void testCloseSessionWithKeepingConnectionShouldNotDisconnectTransport()
+ throws SyncException {
+ SyncTransport transportMock = mock(SyncTransport.class);
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+
+ SyncConnection connection = spy(new SyncConnection(null));
+ connection.init(null, transportMock);
+
+ SyncProxyALM syncProxy =
+ new SyncProxyALM(proxyListenerMock, null, "test", null, null,
+ false, null, null, null, null, null, null, false, false,
+ 2, null, connection, new TestConfig());
+ assertNotNull(syncProxy);
+
+ syncProxy.closeSession(true);
+
+ verify(connection).closeConnection(anyByte(), eq(true));
+ verify(transportMock, never()).disconnect();
+ }
+
+ public void testCloseSessionWithoutKeepingConnectionShouldDisconnectTransport()
+ throws SyncException {
+ SyncTransport transportMock = mock(SyncTransport.class);
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+
+ SyncConnection connection = spy(new SyncConnection(null));
+ connection.init(null, transportMock);
+
+ SyncProxyALM syncProxy =
+ new SyncProxyALM(proxyListenerMock, null, "test", null, null,
+ false, null, null, null, null, null, null, false, false,
+ 2, null, connection, new TestConfig());
+ assertNotNull(syncProxy);
+
+ syncProxy.closeSession(false);
+
+ verify(connection).closeConnection(anyByte(), eq(false));
+ verify(transportMock).disconnect();
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolTest.java
new file mode 100644
index 000000000..bfe94e6ab
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolTest.java
@@ -0,0 +1,714 @@
+package com.ford.syncV4.protocol;
+
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+
+import com.ford.syncV4.protocol.enums.FrameDataControlFrameType;
+import com.ford.syncV4.protocol.enums.FrameType;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.service.Service;
+import com.ford.syncV4.session.Session;
+import com.ford.syncV4.util.BitConverter;
+
+import junit.framework.Assert;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Hashtable;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyByte;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+/**
+ * Created by Andrew Batutin on 8/21/13.
+ */
+public class WiProProtocolTest extends InstrumentationTestCase {
+
+ public static final byte VERSION = (byte) 2;
+ public static final int MESSAGE_ID = 1;
+ public static final byte SESSION_ID = (byte) 48;
+ public static final byte FRAME_SEQUENCE_NUMBER = (byte) 1;
+ public static final int FRAME_SIZE_SHIFT = 100;
+ public static final IProtocolListener DUMMY_PROTOCOL_LISTENER =
+ new IProtocolListener() {
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes,
+ int offset,
+ int length) {
+ }
+
+ @Override
+ public void onProtocolMessageReceived(ProtocolMessage msg) {
+ }
+
+ @Override
+ public void onProtocolSessionStarted(Session session,
+ byte version,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolServiceEnded(ServiceType serviceType,
+ byte sessionID,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolHeartbeatACK() {
+ }
+
+ @Override
+ public void onResetHeartbeat() {
+
+ }
+
+ @Override
+ public void onProtocolError(String info, Exception e) {
+ }
+
+ @Override
+ public void onMobileNavAckReceived(int frameReceivedNumber) {
+
+ }
+
+ @Override
+ public void onProtocolAppUnregistered() {
+
+ }
+
+ @Override
+ public void onProtocolServiceStarted(ServiceType serviceType, byte sessionID, byte version, String correlationID) {
+
+ }
+
+ @Override
+ public void onStartServiceNackReceived(ServiceType serviceType) {
+
+ }
+ };
+ private static final String TAG = WiProProtocolTest.class.getSimpleName();
+ Method currentCheckMethod;
+ private WiProProtocol sut;
+ private ProtocolFrameHeader currentFrameHeader;
+ private byte[] currentData;
+
+ public WiProProtocolTest() {
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());
+ sut = new WiProProtocol(mock(IProtocolListener.class)) {
+
+
+ @Override
+ public void SendMessage(ProtocolMessage protocolMsg) {
+ prepareMockItems();
+ super.SendMessage(protocolMsg);
+ }
+
+ private void prepareMockItems() {
+ _messageLocks = mock(Hashtable.class);
+ when(_messageLocks.get(anyByte())).thenReturn("mockLock");
+ doThrow(new IllegalStateException("should not get protocol error")).when(_protocolListener).onProtocolError(anyString(), any(Exception.class));
+ }
+
+ @Override
+ protected void handleProtocolFrameToSend(ProtocolFrameHeader header, byte[] data, int offset, int length) {
+ super.handleProtocolFrameToSend(header, data, offset, length);
+ callCheck(currentCheckMethod, data, header, offset, length);
+ }
+ };
+ sut.setVersion((byte) 2);
+ }
+
+ public void testSendMobileNavSmallFrameProtocolMessageSucceed() throws Exception {
+ ProtocolMessage message = generateMobileNavProtocolMessage(8);
+ currentData = generateByteArray(0, 8);
+ currentFrameHeader = ProtocolFrameHeaderFactory.createSingleSendData(ServiceType.Mobile_Nav, SESSION_ID, currentData.length, MESSAGE_ID, VERSION);
+ currentCheckMethod = generateCurrentCheckMethod("checkCurrentArgumentsSmallFrame");
+ sut.SendMessage(message);
+ }
+
+ public void testSendMobileNavFirstBigFrameProtocolMessageSucceed() throws Exception {
+ ProtocolMessage message = generateMobileNavProtocolMessage(WiProProtocol.MAX_DATA_SIZE * 2);
+ currentData = generateByteArray(0, WiProProtocol.MAX_DATA_SIZE * 2);
+ currentFrameHeader = ProtocolFrameHeaderFactory.createMultiSendDataFirst(ServiceType.Mobile_Nav, SESSION_ID, MESSAGE_ID, VERSION);
+ currentCheckMethod = generateCurrentCheckMethod("checkCurrentArgumentsFirstBigFrame");
+ sut.SendMessage(message);
+ }
+
+ public void testSendMobileNavConsecutiveBigFrameProtocolMessageSucceed() throws Exception {
+ ProtocolMessage message = generateMobileNavProtocolMessage(WiProProtocol.MAX_DATA_SIZE * 3);
+ currentData = generateByteArray(0, WiProProtocol.MAX_DATA_SIZE);
+ currentFrameHeader = ProtocolFrameHeaderFactory.createMultiSendDataRest(ServiceType.Mobile_Nav, SESSION_ID, currentData.length, FRAME_SEQUENCE_NUMBER, MESSAGE_ID, VERSION);
+ currentCheckMethod = generateCurrentCheckMethod("checkCurrentArgumentsSecondBigFrame");
+ sut.SendMessage(message);
+ }
+
+ public void testSendMobileNavLastBigFrameProtocolMessageSucceed() throws Exception {
+ ProtocolMessage message = generateMobileNavProtocolMessage(WiProProtocol.MAX_DATA_SIZE * 3);
+ currentData = generateByteArray(WiProProtocol.MAX_DATA_SIZE * 2, WiProProtocol.MAX_DATA_SIZE);
+ currentFrameHeader = ProtocolFrameHeaderFactory.createMultiSendDataRest(ServiceType.Mobile_Nav, SESSION_ID, currentData.length, (byte) 0, MESSAGE_ID, VERSION);
+ currentCheckMethod = generateCurrentCheckMethod("checkCurrentArgumentsLastBigFrame");
+ sut.SendMessage(message);
+ }
+
+ public void testSendMobileNabLastUnAlightedBigFrameProtocolMessageSucceed() throws Exception {
+ ProtocolMessage message = generateMobileNavProtocolMessage(WiProProtocol.MAX_DATA_SIZE * 3 + FRAME_SIZE_SHIFT);
+ currentData = generateByteArray(WiProProtocol.MAX_DATA_SIZE * 3, FRAME_SIZE_SHIFT);
+ currentFrameHeader = ProtocolFrameHeaderFactory.createMultiSendDataRest(ServiceType.Mobile_Nav, SESSION_ID, currentData.length, (byte) 0, MESSAGE_ID, VERSION);
+ currentCheckMethod = generateCurrentCheckMethod("checkCurrentArgumentsLastUnAlightedBigFrame");
+ sut.SendMessage(message);
+ }
+
+ private Method generateCurrentCheckMethod(String checkMethodName) throws NoSuchMethodException {
+ Class[] parameterTypes = new Class[4];
+ parameterTypes[0] = byte[].class;
+ parameterTypes[1] = ProtocolFrameHeader.class;
+ parameterTypes[2] = int.class;
+ parameterTypes[3] = int.class;
+ return WiProProtocolTest.class.getMethod(checkMethodName, parameterTypes);
+ }
+
+ private ProtocolMessage generateMobileNavProtocolMessage(int i) {
+ byte[] frame = generateByteArray(0, i);
+ ProtocolMessage message = new ProtocolMessage();
+ message.setData(frame);
+ message.setVersion((byte) 2);
+ message.setSessionID((byte) 48);
+ message.setSessionType(ServiceType.Mobile_Nav);
+ return message;
+ }
+
+ private byte[] generateByteArray(int offset, int size) {
+ byte[] b = new byte[size];
+ for (int i = 0; i < size; i++) {
+ b[i] = (byte) (i + offset);
+ }
+ return b;
+ }
+
+ private void callCheck(Method method, byte[] data, ProtocolFrameHeader messageHeader, int offset, int length) {
+ Object[] parameters = new Object[4];
+ parameters[0] = data;
+ parameters[1] = messageHeader;
+ parameters[2] = offset;
+ parameters[3] = length;
+ try {
+ method.invoke(WiProProtocolTest.this, parameters);
+ } catch (IllegalAccessException e) {
+ Log.e("SyncProxyTester", e.toString());
+ } catch (InvocationTargetException e) {
+ reconstructAssertionError(e);
+ }
+ }
+
+ private void reconstructAssertionError(InvocationTargetException e) {
+ String methodName = getMethodName(e);
+ assertNull("Should not get here. " + e.getCause().getMessage() + " " + methodName, e);
+ }
+
+ private String getMethodName(InvocationTargetException e) {
+ String methodName = "";
+ if (e.getCause() != null && e.getCause().getStackTrace() != null && e.getCause().getStackTrace().length > 0) {
+ for (int i = 0; i < e.getCause().getStackTrace().length; i++) {
+ if (e.getCause().getStackTrace()[i].toString().contains(this.getClass().getName())) {
+ methodName = e.getCause().getStackTrace()[i].toString();
+ break;
+ }
+ }
+ }
+ return methodName;
+ }
+
+ public void checkCurrentArgumentsSmallFrame(byte[] data, ProtocolFrameHeader messageHeader, int offset, int length) throws Exception {
+ assertTrue(Arrays.equals(currentData, data));
+ assertEquals("ServiceType should be equal.", currentFrameHeader.getServiceType(), messageHeader.getServiceType());
+ assertEquals("FrameType should be equal.", currentFrameHeader.getFrameType(), messageHeader.getFrameType());
+ assertEquals("FrameData should be equal.", currentFrameHeader.getFrameData(), messageHeader.getFrameData());
+ assertEquals("Version should be equal.", currentFrameHeader.getVersion(), messageHeader.getVersion());
+ assertEquals("Compressed state should be equal.", currentFrameHeader.isCompressed(), messageHeader.isCompressed());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getDataSize(), messageHeader.getDataSize());
+ assertEquals("DataSize should be equal.", currentFrameHeader.getMessageID(), messageHeader.getMessageID());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getSessionID(), messageHeader.getSessionID());
+ }
+
+ public void checkCurrentArgumentsFirstBigFrame(byte[] data, ProtocolFrameHeader messageHeader, int offset, int length) throws Exception {
+ if (messageHeader.getFrameType() == FrameType.First) {
+ byte[] firstFrameData = getFirstFrameData(currentData);
+ assertTrue("Arrays should be equal.", Arrays.equals(firstFrameData, data));
+ assertEquals("ServiceType should be equal.", currentFrameHeader.getServiceType(), messageHeader.getServiceType());
+ assertEquals("FrameType should be equal.", currentFrameHeader.getFrameType(), messageHeader.getFrameType());
+ assertEquals("FrameData should be equal.", currentFrameHeader.getFrameData(), messageHeader.getFrameData());
+ assertEquals("Version should be equal.", currentFrameHeader.getVersion(), messageHeader.getVersion());
+ assertEquals("Compressed state should be equal.", currentFrameHeader.isCompressed(), messageHeader.isCompressed());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getDataSize(), messageHeader.getDataSize());
+ assertEquals("DataSize should be equal.", currentFrameHeader.getMessageID(), messageHeader.getMessageID());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getSessionID(), messageHeader.getSessionID());
+ }
+ }
+
+ public void checkCurrentArgumentsSecondBigFrame(byte[] data, ProtocolFrameHeader messageHeader, int offset, int length) throws Exception {
+ if (messageHeader.getFrameType() == FrameType.Consecutive && messageHeader.getFrameData() == (byte) 1) {
+ assertTrue("Length of data should be less then WiProProtocol.MAX_DATA_SIZE", length <= WiProProtocol.MAX_DATA_SIZE);
+ byte[] res = getDataToCheck(data, offset, length);
+ assertTrue("Arrays should be equal.", Arrays.equals(currentData, res));
+ assertTrue("Offset should be 0 for second frame", offset == 0);
+ assertEquals("ServiceType should be equal.", currentFrameHeader.getServiceType(), messageHeader.getServiceType());
+ assertEquals("FrameType should be equal.", currentFrameHeader.getFrameType(), messageHeader.getFrameType());
+ assertEquals("FrameData should be equal.", currentFrameHeader.getFrameData(), messageHeader.getFrameData());
+ assertEquals("Version should be equal.", currentFrameHeader.getVersion(), messageHeader.getVersion());
+ assertEquals("Compressed state should be equal.", currentFrameHeader.isCompressed(), messageHeader.isCompressed());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getDataSize(), messageHeader.getDataSize());
+ assertEquals("DataSize should be equal.", currentFrameHeader.getMessageID(), messageHeader.getMessageID());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getSessionID(), messageHeader.getSessionID());
+ }
+ }
+
+ private byte[] getDataToCheck(byte[] data, int offset, int length) {
+ byte[] res = new byte[length];
+ System.arraycopy(data, offset, res, 0, length);
+ return res;
+ }
+
+ public void checkCurrentArgumentsLastBigFrame(byte[] data, ProtocolFrameHeader messageHeader, int offset, int length) throws Exception {
+ if (messageHeader.getFrameType() == FrameType.Consecutive && messageHeader.getFrameData() == (byte) 0) {
+ assertTrue("Length of data should be less then WiProProtocol.MAX_DATA_SIZE", length <= WiProProtocol.MAX_DATA_SIZE);
+ byte[] res = getDataToCheck(data, offset, length);
+ assertTrue("Arrays should be equal.", Arrays.equals(currentData, res));
+ assertTrue("Offset should be 2976 for last frame", offset == WiProProtocol.MAX_DATA_SIZE * 3 - length);
+ assertEquals("ServiceType should be equal.", currentFrameHeader.getServiceType(), messageHeader.getServiceType());
+ assertEquals("FrameType should be equal.", currentFrameHeader.getFrameType(), messageHeader.getFrameType());
+ assertEquals("FrameData should be equal.", currentFrameHeader.getFrameData(), messageHeader.getFrameData());
+ assertEquals("Version should be equal.", currentFrameHeader.getVersion(), messageHeader.getVersion());
+ assertEquals("Compressed state should be equal.", currentFrameHeader.isCompressed(), messageHeader.isCompressed());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getDataSize(), messageHeader.getDataSize());
+ assertEquals("DataSize should be equal.", currentFrameHeader.getMessageID(), messageHeader.getMessageID());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getSessionID(), messageHeader.getSessionID());
+ }
+ }
+
+ public void checkCurrentArgumentsLastUnAlightedBigFrame(byte[] data, ProtocolFrameHeader messageHeader, int offset, int length) throws Exception {
+ if (messageHeader.getFrameType() == FrameType.Consecutive && messageHeader.getFrameData() == (byte) 0) {
+ assertTrue("Length of data should be == 100", length == FRAME_SIZE_SHIFT);
+ assertTrue("Offset of data should be == 4464", offset == WiProProtocol.MAX_DATA_SIZE * 3);
+ byte[] res = getDataToCheck(data, offset, length);
+ assertTrue("Arrays should be equal.", Arrays.equals(currentData, res));
+ assertEquals("ServiceType should be equal.", currentFrameHeader.getServiceType(), messageHeader.getServiceType());
+ assertEquals("FrameType should be equal.", currentFrameHeader.getFrameType(), messageHeader.getFrameType());
+ assertEquals("FrameData should be equal.", currentFrameHeader.getFrameData(), messageHeader.getFrameData());
+ assertEquals("Version should be equal.", currentFrameHeader.getVersion(), messageHeader.getVersion());
+ assertEquals("Compressed state should be equal.", currentFrameHeader.isCompressed(), messageHeader.isCompressed());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getDataSize(), messageHeader.getDataSize());
+ assertEquals("DataSize should be equal.", currentFrameHeader.getMessageID(), messageHeader.getMessageID());
+ assertEquals("Frame headers should be equal.", currentFrameHeader.getSessionID(), messageHeader.getSessionID());
+ }
+ }
+
+ private byte[] getFirstFrameData(byte[] data) {
+ int frameCount = data.length / WiProProtocol.MAX_DATA_SIZE;
+ if (data.length % WiProProtocol.MAX_DATA_SIZE > 0) {
+ frameCount++;
+ }
+ byte[] firstFrameData = new byte[8];
+ // First four bytes are data size.
+ System.arraycopy(BitConverter.intToByteArray(data.length), 0, firstFrameData, 0, 4);
+ // Second four bytes are frame count.
+ System.arraycopy(BitConverter.intToByteArray(frameCount), 0, firstFrameData, 4, 4);
+ return firstFrameData;
+ }
+
+ public byte[] extractByteArrayPart(final byte[] src, int offset,
+ int length) {
+ final byte[] dst = new byte[length];
+ System.arraycopy(src, offset, dst, 0, length);
+ return dst;
+ }
+
+ public void testReadingHashIDFromStartSessionACK() throws Throwable {
+ // null as a listener won't work
+ final WiProProtocol protocol =
+ new WiProProtocol(DUMMY_PROTOCOL_LISTENER);
+ final ByteArrayOutputStream StartSessionACKMessageStream =
+ new ByteArrayOutputStream(12);
+
+ final byte[] msgFirstBytes = new byte[]{0x20, 0x07, 0x02, 0x00};
+ StartSessionACKMessageStream.write(msgFirstBytes);
+ final byte[] msgDataSize = new byte[]{0x00, 0x00, 0x00, 0x00};
+ StartSessionACKMessageStream.write(msgDataSize);
+ final byte[] msgHashID =
+ new byte[]{0x12, 0x34, (byte) 0xCD, (byte) 0xEF};
+ StartSessionACKMessageStream.write(msgHashID);
+
+ final byte[] StartSessionACKMessage =
+ StartSessionACKMessageStream.toByteArray();
+ protocol.HandleReceivedBytes(StartSessionACKMessage,
+ StartSessionACKMessage.length);
+ Assert.assertEquals("HashID is incorrect", 0x1234CDEF, protocol.hashID);
+ }
+
+ public void testSendingHashIDWithEndSession() throws IOException {
+ final IProtocolListener protocolListener = new IProtocolListener() {
+ private int sendCount = 0;
+
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes,
+ int offset, int length) {
+ // This method is called twice, sending header and then data
+ final byte[] expectedMsgMessageID =
+ new byte[]{(byte) 0xCD, (byte) 0xEF, 0x12, 0x34};
+
+ switch (sendCount) {
+ case 0:
+ final byte[] msgDataSize =
+ extractByteArrayPart(msgBytes, 4, 4);
+ final byte[] expectedMsgDataSize =
+ new byte[]{0x00, 0x00, 0x00, 0x04};
+ Assert.assertEquals("Data Size is incorrect",
+ BitConverter
+ .intFromByteArray(expectedMsgDataSize,
+ 0),
+ BitConverter.intFromByteArray(msgDataSize, 0));
+
+ final byte[] msgMessageID =
+ extractByteArrayPart(msgBytes, 8, 4);
+ Assert.assertEquals("Message ID should be hash ID",
+ BitConverter
+ .intFromByteArray(expectedMsgMessageID,
+ 0),
+ BitConverter.intFromByteArray(msgMessageID, 0));
+ break;
+
+ case 1:
+ final byte[] msgData =
+ extractByteArrayPart(msgBytes, 0, 4);
+ final byte[] expectedMsgData = expectedMsgMessageID;
+ assertEquals("Data should contain hash ID", BitConverter
+ .intFromByteArray(expectedMsgData, 0),
+ BitConverter.intFromByteArray(msgData, 0));
+ break;
+
+ default:
+ Assert.assertTrue(String.format(
+ "onProtocolMessageBytesToSend is called too many times: %d",
+ sendCount), false);
+ }
+
+ ++sendCount;
+ }
+
+ @Override
+ public void onProtocolMessageReceived(ProtocolMessage msg) {
+ }
+
+ @Override
+ public void onProtocolSessionStarted(Session session,
+ byte version,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolServiceEnded(ServiceType sessionType,
+ byte sessionID,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolHeartbeatACK() {
+ }
+
+ @Override
+ public void onResetHeartbeat() {
+
+ }
+
+ @Override
+ public void onProtocolError(String info, Exception e) {
+ }
+
+ @Override
+ public void onMobileNavAckReceived(int frameReceivedNumber) {
+
+ }
+
+ @Override
+ public void onProtocolAppUnregistered() {
+
+ }
+
+ @Override
+ public void onProtocolServiceStarted(ServiceType serviceType, byte sessionID, byte version, String correlationID) {
+
+ }
+
+ @Override
+ public void onStartServiceNackReceived(ServiceType serviceType) {
+
+ }
+ };
+
+ final WiProProtocol protocol = new WiProProtocol(protocolListener);
+ protocol.hashID = 0xCDEF1234;
+ protocol._version = 2;
+ protocol.EndProtocolService(ServiceType.RPC, (byte) 0x01);
+ }
+
+ public void testEndSessionACKFrameReceived() throws Exception {
+ ProtocolFrameHeader frameHeader = new ProtocolFrameHeader();
+ frameHeader.setFrameData(FrameDataControlFrameType.EndServiceACK.getValue());
+ frameHeader.setFrameType(FrameType.Control);
+ frameHeader.setSessionID(SESSION_ID);
+ frameHeader.setServiceType(ServiceType.RPC);
+ frameHeader.setDataSize(0);
+ IProtocolListener mock = mock(IProtocolListener.class);
+ WiProProtocol.MessageFrameAssembler messageFrameAssembler = new WiProProtocol(mock).new MessageFrameAssembler();
+ ArgumentCaptor<ServiceType> sessionTypeCaptor = ArgumentCaptor.forClass(ServiceType.class);
+ ArgumentCaptor<Byte> sessionIdCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<String> correlationIdCaptor = ArgumentCaptor.forClass(String.class);
+ messageFrameAssembler.handleFrame(frameHeader, new byte[0]);
+ Mockito.verify(mock).onProtocolServiceEnded(sessionTypeCaptor.capture(), sessionIdCaptor.capture(), correlationIdCaptor.capture());
+ assertEquals(ServiceType.RPC, sessionTypeCaptor.getValue());
+ assertEquals(SESSION_ID, sessionIdCaptor.getValue().byteValue());
+ assertEquals("", correlationIdCaptor.getValue());
+ }
+
+ public void testStartServiceWithSessionId() throws Exception {
+ final byte id = 13;
+ WiProProtocol protocol = new WiProProtocol(mock(IProtocolListener.class)) {
+ @Override
+ protected void handleProtocolFrameToSend(ProtocolFrameHeader header, byte[] data, int offset, int length) {
+ super.handleProtocolFrameToSend(header, data, offset, length);
+ assertEquals("Session ID should be same", id, header.getSessionID());
+ }
+ };
+ Session session = new Session();
+ session.setSessionId(id);
+ protocol.StartProtocolService(ServiceType.Mobile_Nav, session);
+ }
+
+ public void testStartSessionWithSessionId() throws Exception {
+ final byte id = 13;
+ WiProProtocol protocol = new WiProProtocol(mock(IProtocolListener.class)) {
+ @Override
+ protected void handleProtocolFrameToSend(ProtocolFrameHeader header, byte[] data, int offset, int length) {
+ super.handleProtocolFrameToSend(header, data, offset, length);
+ assertEquals("Session ID should be same", id, header.getSessionID());
+ }
+ };
+ protocol.StartProtocolSession(id);
+ }
+
+ public void testStartSessionNavigationWith0SessionIDThrowsExp() throws Exception {
+ WiProProtocol protocol = new WiProProtocol(mock(IProtocolListener.class));
+ try {
+ Session session = new Session();
+ session.setSessionId((byte) 0);
+ protocol.StartProtocolService(ServiceType.Mobile_Nav, session);
+ assertTrue("Should not get here", false);
+ } catch (IllegalArgumentException exp) {
+ assertNotNull("Should get and exception", exp);
+ }
+ }
+
+ public void testHandleProtocolSessionStartedYieldsService() throws Exception {
+ final boolean[] passed = {false};
+ WiProProtocol protocol = new WiProProtocol(new IProtocolListener() {
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes, int offset, int length) {
+
+ }
+
+ @Override
+ public void onProtocolMessageReceived(ProtocolMessage msg) {
+
+ }
+
+ @Override
+ public void onProtocolSessionStarted(Session session, byte version, String correlationID) {
+ assertEquals("currentSession id should be SESSION_ID", SESSION_ID, session.getSessionId());
+ Service service = session.getServiceList().get(0);
+ assertEquals("should be RPC service", ServiceType.RPC, service.getServiceType());
+ assertEquals("service should belong to the currentSession", session, service.getSession());
+ passed[0] = true;
+ }
+
+ @Override
+ public void onProtocolServiceEnded(ServiceType serviceType, byte sessionID, String correlationID) {
+
+ }
+
+ @Override
+ public void onProtocolHeartbeatACK() {
+
+ }
+
+ @Override
+ public void onResetHeartbeat() {
+
+ }
+
+ @Override
+ public void onProtocolError(String info, Exception e) {
+
+ }
+
+ @Override
+ public void onMobileNavAckReceived(int frameReceivedNumber) {
+
+ }
+
+ @Override
+ public void onProtocolAppUnregistered() {
+
+ }
+
+ @Override
+ public void onProtocolServiceStarted(ServiceType serviceType, byte sessionID, byte version, String correlationID) {
+
+ }
+
+ @Override
+ public void onStartServiceNackReceived(ServiceType serviceType) {
+
+ }
+ });
+ protocol.handleProtocolSessionStarted(ServiceType.RPC, SESSION_ID, VERSION, "");
+ assertTrue("test should pass", passed[0]);
+ }
+
+
+ public void testStartServiceACK_RPC_FrameReceived() throws Exception {
+ ProtocolFrameHeader frameHeader = new ProtocolFrameHeader();
+ frameHeader.setFrameData(FrameDataControlFrameType.StartServiceACK.getValue());
+ frameHeader.setFrameType(FrameType.Control);
+ frameHeader.setSessionID((byte) 0);
+ frameHeader.setServiceType(ServiceType.RPC);
+ frameHeader.setDataSize(0);
+ IProtocolListener mock = mock(IProtocolListener.class);
+ WiProProtocol.MessageFrameAssembler messageFrameAssembler = new WiProProtocol(mock).new MessageFrameAssembler();
+ ArgumentCaptor<Session> sessionTypeCaptor = ArgumentCaptor.forClass(Session.class);
+ ArgumentCaptor<Byte> versionCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<String> correlationIdCaptor = ArgumentCaptor.forClass(String.class);
+ messageFrameAssembler.handleFrame(frameHeader, new byte[0]);
+ Mockito.verify(mock).onProtocolSessionStarted(sessionTypeCaptor.capture(), versionCaptor.capture(), correlationIdCaptor.capture());
+ assertEquals(0, sessionTypeCaptor.getValue().getSessionId());
+ assertEquals(ServiceType.RPC, sessionTypeCaptor.getValue().getServiceList().get(0).getServiceType());
+ }
+
+ public void testStartServiceACK_Mobile_Nav_FrameReceived() throws Exception {
+ ProtocolFrameHeader frameHeader = new ProtocolFrameHeader();
+ frameHeader.setFrameData(FrameDataControlFrameType.StartServiceACK.getValue());
+ frameHeader.setFrameType(FrameType.Control);
+ frameHeader.setSessionID(SESSION_ID);
+ frameHeader.setVersion((byte) 2);
+ frameHeader.setServiceType(ServiceType.Mobile_Nav);
+ frameHeader.setDataSize(0);
+ IProtocolListener mock = mock(IProtocolListener.class);
+ WiProProtocol protocol = new WiProProtocol(mock);
+ protocol.setVersion((byte) 2);
+ WiProProtocol.MessageFrameAssembler messageFrameAssembler = protocol.new MessageFrameAssembler();
+ ArgumentCaptor<ServiceType> serviceTypeCaptor = ArgumentCaptor.forClass(ServiceType.class);
+ ArgumentCaptor<Byte> sessionIDCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<Byte> versionCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<String> correlationIdCaptor = ArgumentCaptor.forClass(String.class);
+ messageFrameAssembler.handleFrame(frameHeader, new byte[0]);
+ Mockito.verify(mock).onProtocolServiceStarted(serviceTypeCaptor.capture(), sessionIDCaptor.capture(), versionCaptor.capture(), correlationIdCaptor.capture());
+ assertEquals(ServiceType.Mobile_Nav, serviceTypeCaptor.getValue());
+ assertEquals(SESSION_ID, sessionIDCaptor.getValue().byteValue());
+ assertEquals(2, versionCaptor.getValue().byteValue());
+ assertEquals("", correlationIdCaptor.getValue());
+ }
+
+ public void testStartServiceACK_RPC_SessionID0_NotthorwExp() throws Exception {
+ ProtocolFrameHeader frameHeader = new ProtocolFrameHeader();
+ frameHeader.setFrameData(FrameDataControlFrameType.StartServiceACK.getValue());
+ frameHeader.setFrameType(FrameType.Control);
+ frameHeader.setSessionID(SESSION_ID);
+ frameHeader.setVersion((byte) 2);
+ frameHeader.setServiceType(ServiceType.RPC);
+ frameHeader.setDataSize(0);
+ IProtocolListener mock = mock(IProtocolListener.class);
+ WiProProtocol protocol = new WiProProtocol(mock);
+ protocol.setVersion((byte) 2);
+ WiProProtocol.MessageFrameAssembler messageFrameAssembler = protocol.new MessageFrameAssembler();
+ try {
+ messageFrameAssembler.handleFrame(frameHeader, new byte[0]);
+ }catch (IllegalArgumentException exp){
+ assertTrue(" should not get here",false);
+ }
+ }
+
+ public void testStartServiceACK_Navi_SessionID0_thorwExp() throws Exception {
+ ProtocolFrameHeader frameHeader = new ProtocolFrameHeader();
+ frameHeader.setFrameData(FrameDataControlFrameType.StartServiceACK.getValue());
+ frameHeader.setFrameType(FrameType.Control);
+ frameHeader.setSessionID((byte) 0);
+ frameHeader.setVersion((byte) 2);
+ frameHeader.setServiceType(ServiceType.Mobile_Nav);
+ frameHeader.setDataSize(0);
+ IProtocolListener mock = mock(IProtocolListener.class);
+ WiProProtocol protocol = new WiProProtocol(mock);
+ protocol.setVersion((byte) 2);
+ WiProProtocol.MessageFrameAssembler messageFrameAssembler = protocol.new MessageFrameAssembler();
+ try {
+ messageFrameAssembler.handleFrame(frameHeader, new byte[0]);
+ assertTrue(" should not get here",false);
+ }catch (IllegalArgumentException exp){
+ assertNotNull(exp);
+ }
+ }
+
+
+ public void testStartServiceACK_AudioService_FrameReceived() throws Exception {
+ ProtocolFrameHeader frameHeader = new ProtocolFrameHeader();
+ frameHeader.setFrameData(FrameDataControlFrameType.StartServiceACK.getValue());
+ frameHeader.setFrameType(FrameType.Control);
+ frameHeader.setSessionID(SESSION_ID);
+ frameHeader.setVersion((byte) 2);
+ frameHeader.setServiceType(ServiceType.Audio_Service);
+ frameHeader.setDataSize(0);
+ IProtocolListener mock = mock(IProtocolListener.class);
+ WiProProtocol protocol = new WiProProtocol(mock);
+ protocol.setVersion((byte) 2);
+ WiProProtocol.MessageFrameAssembler messageFrameAssembler = protocol.new MessageFrameAssembler();
+ ArgumentCaptor<ServiceType> serviceTypeCaptor = ArgumentCaptor.forClass(ServiceType.class);
+ ArgumentCaptor<Byte> sessionIDCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<Byte> versionCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<String> correlationIdCaptor = ArgumentCaptor.forClass(String.class);
+ messageFrameAssembler.handleFrame(frameHeader, new byte[0]);
+ Mockito.verify(mock).onProtocolServiceStarted(serviceTypeCaptor.capture(), sessionIDCaptor.capture(), versionCaptor.capture(), correlationIdCaptor.capture());
+ assertEquals(ServiceType.Audio_Service, serviceTypeCaptor.getValue());
+ assertEquals(SESSION_ID, sessionIDCaptor.getValue().byteValue());
+ assertEquals(2, versionCaptor.getValue().byteValue());
+ assertEquals("", correlationIdCaptor.getValue());
+ }
+
+
+ public void testHeartBeatMonitorResetOnMessageSent() throws Exception {
+ IProtocolListener protocolListener = mock(IProtocolListener.class);
+ WiProProtocol protocol = new WiProProtocol(protocolListener);
+ ProtocolFrameHeader frameHeader = new ProtocolFrameHeader();
+ frameHeader.setFrameData(FrameDataControlFrameType.StartServiceACK.getValue());
+ frameHeader.setFrameType(FrameType.Control);
+ frameHeader.setSessionID(SESSION_ID);
+ frameHeader.setVersion((byte) 2);
+ frameHeader.setServiceType(ServiceType.RPC);
+ frameHeader.setDataSize(0);
+ protocol.handleProtocolFrameToSend(frameHeader, null,0,0 );
+ verify(protocolListener).onResetHeartbeat();
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolUSBTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolUSBTest.java
new file mode 100644
index 000000000..702a3fb2a
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/WiProProtocolUSBTest.java
@@ -0,0 +1,178 @@
+package com.ford.syncV4.protocol;
+
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.session.Session;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by u on 2013-09-30.
+ */
+public class WiProProtocolUSBTest extends TestCase {
+ private boolean requiredMethodCalled;
+
+ public void testUnregisterAppInterfaceResponseCallsProtocolListener() {
+ final IProtocolListener protocolListener = new IProtocolListener() {
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes,
+ int offset, int length) {
+ }
+
+ @Override
+ public void onProtocolMessageReceived(ProtocolMessage msg) {
+ }
+
+ @Override
+ public void onProtocolSessionStarted(Session session,
+ byte version,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolServiceEnded(ServiceType sessionType,
+ byte sessionID,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolHeartbeatACK() {
+ }
+
+ @Override
+ public void onResetHeartbeat() {
+
+ }
+
+ @Override
+ public void onProtocolError(String info, Exception e) {
+ }
+
+ @Override
+ public void onMobileNavAckReceived(int frameReceivedNumber) {
+ }
+
+ @Override
+ public void onProtocolAppUnregistered() {
+ requiredMethodCalled = true;
+ }
+
+ @Override
+ public void onProtocolServiceStarted(ServiceType serviceType, byte sessionID, byte version, String correlationID) {
+
+ }
+
+ @Override
+ public void onStartServiceNackReceived(ServiceType serviceType) {
+
+ }
+ };
+
+ requiredMethodCalled = false;
+ final WiProProtocol protocol = new WiProProtocol(protocolListener);
+ protocol._version = 2;
+
+ byte[] unregisterAppInterfaceResponse = new byte[]{
+ // first bytes
+ 0x21, 0x07, 0x00, 0x01,
+ // data size
+ 0x00, 0x00, 0x00, 14,
+ // message ID
+ 0x00, 0x00, 0x00, 0x01,
+ // RPC type and function ID
+ 0x10, 0x00, 0x00, 0x02,
+ // correlation ID
+ 0x00, 0x00, 0x00, 0x01,
+ // JSON size
+ 0x00, 0x00, 0x00, 0x02,
+ // JSON
+ '{', '}'
+ };
+
+ protocol.HandleReceivedBytes(unregisterAppInterfaceResponse,
+ unregisterAppInterfaceResponse.length);
+ assertTrue("onProtocolAppUnregistered() method isn't called",
+ requiredMethodCalled);
+ }
+
+ public void testUnregisterAppInterfaceRequestDoesntCallProtocolListener() {
+ final IProtocolListener protocolListener = new IProtocolListener() {
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes,
+ int offset, int length) {
+ }
+
+ @Override
+ public void onProtocolMessageReceived(ProtocolMessage msg) {
+ }
+
+ @Override
+ public void onProtocolSessionStarted(Session session,
+ byte version,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolServiceEnded(ServiceType sessionType,
+ byte sessionID,
+ String correlationID) {
+ }
+
+ @Override
+ public void onProtocolHeartbeatACK() {
+ }
+
+ @Override
+ public void onResetHeartbeat() {
+
+ }
+
+ @Override
+ public void onProtocolError(String info, Exception e) {
+ }
+
+ @Override
+ public void onMobileNavAckReceived(int frameReceivedNumber) {
+ }
+
+ @Override
+ public void onProtocolAppUnregistered() {
+ assertFalse(
+ "Incoming UnregisterAppInterface request shouldn't " +
+ "trigger the method", true);
+ }
+
+ @Override
+ public void onProtocolServiceStarted(ServiceType serviceType, byte sessionID, byte version, String correlationID) {
+
+ }
+
+ @Override
+ public void onStartServiceNackReceived(ServiceType serviceType) {
+
+ }
+ };
+
+ final WiProProtocol protocol = new WiProProtocol(protocolListener);
+ protocol._version = 2;
+
+ byte[] unregisterAppInterfaceRequest = new byte[]{
+ // first bytes
+ 0x21, 0x07, 0x00, 0x01,
+ // data size
+ 0x00, 0x00, 0x00, 14,
+ // message ID
+ 0x00, 0x00, 0x00, 0x01,
+ // RPC type and function ID
+ 0x00, 0x00, 0x00, 0x02,
+ // correlation ID
+ 0x00, 0x00, 0x00, 0x01,
+ // JSON size
+ 0x00, 0x00, 0x00, 0x02,
+ // JSON
+ '{', '}'
+ };
+
+ protocol.HandleReceivedBytes(unregisterAppInterfaceRequest,
+ unregisterAppInterfaceRequest.length);
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FrameDataControlFrameTypeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FrameDataControlFrameTypeTest.java
new file mode 100644
index 000000000..79c8f2027
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FrameDataControlFrameTypeTest.java
@@ -0,0 +1,102 @@
+package com.ford.syncV4.protocol.enums;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItemInArray;
+
+/**
+ * Tests for FrameDataControlFrameType class.
+ *
+ * Created by enikolsky on 2013-12-31.
+ */
+public class FrameDataControlFrameTypeTest extends TestCase {
+
+ public void testHeartbeatTypeValueShouldBe0x00() {
+ assertThat(FrameDataControlFrameType.Heartbeat.getValue(),
+ is((byte) 0x00));
+ }
+
+ public void testHeartbeatTypeNameShouldMatchLiteral() {
+ assertThat(FrameDataControlFrameType.Heartbeat.getName(),
+ is("Heartbeat"));
+ }
+
+ public void testHeartbeatACKTypeValueShouldBe0xFF() {
+ assertThat(FrameDataControlFrameType.HeartbeatACK.getValue(),
+ is((byte) 0xFF));
+ }
+
+ public void testHeartbeatACKTypeNameShouldMatchLiteral() {
+ assertThat(FrameDataControlFrameType.HeartbeatACK.getName(),
+ is("HeartbeatACK"));
+ }
+
+ public void testListShouldContainHeartbeat() {
+ assertThat(FrameDataControlFrameType.getList(),
+ hasItem(FrameDataControlFrameType.Heartbeat));
+ }
+
+ public void testListShouldContainHeartbeatACK() {
+ assertThat(FrameDataControlFrameType.getList(),
+ hasItem(FrameDataControlFrameType.HeartbeatACK));
+ }
+
+ public void testValuesShouldContainHeartbeat() {
+ assertThat(FrameDataControlFrameType.values(),
+ hasItemInArray(FrameDataControlFrameType.Heartbeat));
+ }
+
+ public void testValuesShouldContainHeartbeatACK() {
+ assertThat(FrameDataControlFrameType.values(),
+ hasItemInArray(FrameDataControlFrameType.HeartbeatACK));
+ }
+
+ public void testValueOfHeartbeatShouldReturnObject() {
+ assertThat(FrameDataControlFrameType.valueOf("Heartbeat"),
+ is(FrameDataControlFrameType.Heartbeat));
+ }
+
+ public void testValueOfHeartbeatACKShouldReturnObject() {
+ assertThat(FrameDataControlFrameType.valueOf("HeartbeatACK"),
+ is(FrameDataControlFrameType.HeartbeatACK));
+ }
+
+ public void testFrameDataEndSession() throws Exception {
+ assertNotNull("enum should have EndService value", FrameDataControlFrameType.EndService);
+ }
+
+ public void testFrameDataEndSessionACK() throws Exception {
+ assertNotNull("enum should have EndService value", FrameDataControlFrameType.EndServiceACK);
+ }
+
+ public void testEndSessionACKValueIs0x005() throws Exception {
+ assertEquals("EndServiceACK should have 0x005 value", (byte) 0x05, FrameDataControlFrameType.EndServiceACK.getValue());
+ }
+
+ public void testGetValueReturnsEndSessionACK() throws Exception {
+ assertEquals("value of EndServiceACK string should be FrameData.EndServiceACK", FrameDataControlFrameType.EndServiceACK, FrameDataControlFrameType.valueOf("EndServiceACK"));
+ }
+
+ public void testFrameDataValuesHasEndSessionACKValue() throws Exception {
+ assertTrue("FrameData list should have EndServiceACK value", Arrays.asList(FrameDataControlFrameType.values()).contains(FrameDataControlFrameType.EndServiceACK));
+ }
+
+ public void testMobileNaviACKIs0xFE() throws Exception {
+ assertThat(FrameDataControlFrameType.MobileNaviACK.getValue(),
+ is((byte) 0xFE));
+ }
+
+ public void testEndSessionNACKValueIs0x06() throws Exception {
+ assertThat(FrameDataControlFrameType.EndServiceNACK.getValue(),
+ is((byte) 0x06));
+ }
+
+ public void testFrameDataValuesHasEndSessionNACKValue() throws Exception {
+ assertTrue("FrameData list should have EndServiceNACK value", Arrays.asList(FrameDataControlFrameType.values()).contains(FrameDataControlFrameType.EndServiceNACK));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FunctionIDTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FunctionIDTest.java
new file mode 100644
index 000000000..12d00a4db
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/FunctionIDTest.java
@@ -0,0 +1,50 @@
+package com.ford.syncV4.protocol.enums;
+
+import junit.framework.TestCase;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Tests for FunctionID class, like correct IDs for function names.
+ *
+ * Created by enikolsky on 2014-01-23.
+ */
+public class FunctionIDTest extends TestCase {
+ private static final String SYSTEM_REQUEST = "SystemRequest";
+ private static final String ON_SYSTEM_REQUEST = "OnSystemRequest";
+ private static final String DIAGNOSTIC_MESSAGE = "DiagnosticMessage";
+ private static final int SYSTEM_REQUEST_ID = 38;
+ private static final int ON_SYSTEM_REQUEST_ID = 32781;
+ private static final int DIAGNOSTIC_MESSAGE_ID = 37;
+
+ public void testSystemRequestIDShouldBe38() {
+ assertThat(FunctionID.getFunctionID(SYSTEM_REQUEST),
+ is(SYSTEM_REQUEST_ID));
+ }
+
+ public void testID38ShouldBeSystemRequest() {
+ assertThat(FunctionID.getFunctionName(SYSTEM_REQUEST_ID),
+ is(SYSTEM_REQUEST));
+ }
+
+ public void testOnSystemRequestIDShouldBe32781() {
+ assertThat(FunctionID.getFunctionID(ON_SYSTEM_REQUEST),
+ is(ON_SYSTEM_REQUEST_ID));
+ }
+
+ public void testID32781ShouldBeOnSystemRequest() {
+ assertThat(FunctionID.getFunctionName(ON_SYSTEM_REQUEST_ID),
+ is(ON_SYSTEM_REQUEST));
+ }
+
+ public void testDiagnosticMessageIDShouldBe37() {
+ assertThat(FunctionID.getFunctionID(DIAGNOSTIC_MESSAGE),
+ is(DIAGNOSTIC_MESSAGE_ID));
+ }
+
+ public void testID37ShouldBeDiagnosticMessageID() {
+ assertThat(FunctionID.getFunctionName(DIAGNOSTIC_MESSAGE_ID),
+ is(DIAGNOSTIC_MESSAGE));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/ServiceTypeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/ServiceTypeTest.java
new file mode 100644
index 000000000..0e3cfda92
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/enums/ServiceTypeTest.java
@@ -0,0 +1,60 @@
+package com.ford.syncV4.protocol.enums;
+
+import android.test.AndroidTestCase;
+
+import java.util.Vector;
+
+/**
+ * Created by Andrew Batutin on 8/20/13.
+ */
+public class ServiceTypeTest extends AndroidTestCase {
+
+ public ServiceTypeTest() {
+ }
+
+ public void testServiceTypeMobNavNameIsMobile_Nav() throws Exception {
+ String name = ServiceType.Mobile_Nav.getName();
+ assertEquals(name, "Mobile_Nav");
+ }
+
+ public void testServiceTypeMobNavValueIs0x0B() throws Exception {
+ byte value = ServiceType.Mobile_Nav.getValue();
+ assertEquals(value, (byte) 0x0B);
+ }
+
+ public void testMobileNavIsInServiceTypeList() throws Exception {
+ Vector sessionTypes = ServiceType.getList();
+ assertTrue(sessionTypes.contains(ServiceType.Mobile_Nav));
+ }
+
+ public void testServiceTypeAudioNameIsAudio_Service() throws Exception {
+ String name = ServiceType.Audio_Service.getName();
+ assertEquals(name, "Audio_Service");
+ }
+
+ public void testServiceTypeAudioServiceValueIs10() throws Exception {
+ byte value = ServiceType.Audio_Service.getValue();
+ assertEquals(value, (byte) 10);
+ }
+
+ public void testAudioServiceIsInServiceTypeList() throws Exception {
+ Vector sessionTypes = ServiceType.getList();
+ assertTrue(sessionTypes.contains(ServiceType.Audio_Service));
+ }
+
+ public void testServiceTypeHeartbeatNameIsHeartbeat_Service() throws Exception {
+ String name = ServiceType.Heartbeat.getName();
+ assertEquals(name, "Heartbeat_Service");
+ }
+
+ public void testServiceTypeHeartbeatValueIs0() throws Exception {
+ byte value = ServiceType.Heartbeat.getValue();
+ assertEquals(value, (byte) 0);
+ }
+
+ public void testHeartbeatIsInServiceTypeList() throws Exception {
+ Vector sessionTypes = ServiceType.getList();
+ assertTrue(sessionTypes.contains(ServiceType.Heartbeat));
+ }
+
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/heartbeat/HeartbeatMonitorTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/heartbeat/HeartbeatMonitorTest.java
new file mode 100644
index 000000000..7c37fe0c1
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/protocol/heartbeat/HeartbeatMonitorTest.java
@@ -0,0 +1,188 @@
+package com.ford.syncV4.protocol.heartbeat;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.proxy.rpc.TestCommon;
+
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Tests for HeartbeatMonitor class.
+ *
+ * Created by enikolsky on 2013-12-26.
+ */
+public class HeartbeatMonitorTest extends InstrumentationTestCase {
+ private static final int MAX_TIMER_DRIFT = 20;
+ private static final int HEARTBEAT_TEST_INTERVAL = 30;
+ private IHeartbeatMonitorListener listenerMock;
+ private HeartbeatMonitor heartbeatMonitor;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ listenerMock = Mockito.mock(IHeartbeatMonitorListener.class);
+ heartbeatMonitor = new HeartbeatMonitor();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ listenerMock = null;
+ heartbeatMonitor = null;
+
+ super.tearDown();
+ }
+
+ public void testListenerShouldBeSet() {
+ heartbeatMonitor.setListener(listenerMock);
+ assertThat(heartbeatMonitor.getListener(), is(listenerMock));
+ }
+
+ public void testStartedMonitorShouldAskToSendHeartbeatAfterTimeout()
+ throws InterruptedException {
+ heartbeatMonitor.setListener(listenerMock);
+
+ heartbeatMonitor.setInterval(HEARTBEAT_TEST_INTERVAL);
+ heartbeatMonitor.start();
+
+ verify(listenerMock, timeout(HEARTBEAT_TEST_INTERVAL + MAX_TIMER_DRIFT))
+ .sendHeartbeat(heartbeatMonitor);
+ heartbeatMonitor.stop();
+ }
+
+ public void testMonitorShouldTimeoutOnSecondHeartbeatAndNoACK()
+ throws InterruptedException {
+ heartbeatMonitor.setListener(listenerMock);
+
+ heartbeatMonitor.setInterval(HEARTBEAT_TEST_INTERVAL);
+ heartbeatMonitor.start();
+
+ verify(listenerMock, timeout(HEARTBEAT_TEST_INTERVAL + MAX_TIMER_DRIFT))
+ .sendHeartbeat(heartbeatMonitor);
+
+ verify(listenerMock, timeout(HEARTBEAT_TEST_INTERVAL + MAX_TIMER_DRIFT))
+ .heartbeatTimedOut(heartbeatMonitor);
+
+ heartbeatMonitor.stop();
+ }
+
+ public void testStartedAndStoppedMonitorShouldNotSendHeartbeats()
+ throws InterruptedException {
+ heartbeatMonitor.setListener(listenerMock);
+
+ heartbeatMonitor.setInterval(HEARTBEAT_TEST_INTERVAL);
+ heartbeatMonitor.start();
+ Thread.sleep(5);
+ heartbeatMonitor.stop();
+
+ // this does not work:
+// verify(listenerMock, timeout(HEARTBEAT_TEST_INTERVAL * 3 +
+// MAX_TIMER_DRIFT).never()).sendHeartbeat(
+// Matchers.<IHeartbeatMonitor>any());
+
+ Thread.sleep(HEARTBEAT_TEST_INTERVAL * 2 + MAX_TIMER_DRIFT);
+ verify(listenerMock, never()).sendHeartbeat(
+ Matchers.<IHeartbeatMonitor>any());
+ }
+
+ public void testStartedAndStoppedImmediatelyMonitorShouldNotSendHeartbeats()
+ throws InterruptedException {
+ heartbeatMonitor.setListener(listenerMock);
+
+ heartbeatMonitor.setInterval(HEARTBEAT_TEST_INTERVAL);
+ heartbeatMonitor.start();
+ heartbeatMonitor.stop();
+
+ Thread.sleep(HEARTBEAT_TEST_INTERVAL * 2 + MAX_TIMER_DRIFT);
+ verify(listenerMock, never()).sendHeartbeat(
+ Matchers.<IHeartbeatMonitor>any());
+ }
+
+ public void testTransportActivityShouldResetHeartbeat()
+ throws InterruptedException {
+ heartbeatMonitor.setListener(listenerMock);
+
+ final int INTERVAL = 50;
+ heartbeatMonitor.setInterval(INTERVAL);
+ heartbeatMonitor.start();
+
+ final int ACTIVITY_DELAY = 40;
+ Thread.sleep(ACTIVITY_DELAY);
+ heartbeatMonitor.notifyTransportActivity();
+
+ Thread.sleep(INTERVAL - ACTIVITY_DELAY + 10);
+ verify(listenerMock, never()).sendHeartbeat(
+ Matchers.<IHeartbeatMonitor>any());
+ verify(listenerMock, timeout(INTERVAL + MAX_TIMER_DRIFT)).sendHeartbeat(
+ heartbeatMonitor);
+ heartbeatMonitor.stop();
+ }
+
+ public void testReceivedHeartbeatACKShouldNotResetHeartbeat()
+ throws InterruptedException {
+ heartbeatMonitor.setListener(listenerMock);
+
+ final int INTERVAL = 50;
+ heartbeatMonitor.setInterval(INTERVAL);
+ heartbeatMonitor.start();
+
+ final int ACK_DELAY = 40;
+ Thread.sleep(ACK_DELAY);
+ heartbeatMonitor.heartbeatACKReceived();
+
+ Thread.sleep(INTERVAL - ACK_DELAY + 10);
+ verify(listenerMock, atLeastOnce()).sendHeartbeat(
+ Matchers.<IHeartbeatMonitor>any());
+ verify(listenerMock, timeout(INTERVAL + MAX_TIMER_DRIFT)).sendHeartbeat(
+ heartbeatMonitor);
+ heartbeatMonitor.stop();
+ }
+
+ public void testReceivedHeartbeatACKShouldResetHeartbeatThenTimeout()
+ throws InterruptedException {
+ heartbeatMonitor.setListener(listenerMock);
+
+ final int INTERVAL = 50;
+ heartbeatMonitor.setInterval(INTERVAL);
+ heartbeatMonitor.start();
+
+ verify(listenerMock, timeout(INTERVAL + MAX_TIMER_DRIFT)).sendHeartbeat(
+ heartbeatMonitor);
+
+ IHeartbeatMonitorListener listenerMock2 =
+ Mockito.mock(IHeartbeatMonitorListener.class);
+ heartbeatMonitor.setListener(listenerMock2);
+
+ verify(listenerMock2, never()).heartbeatTimedOut(
+ Matchers.<IHeartbeatMonitor>any());
+
+ final int ACK_DELAY = 10;
+ Thread.sleep(ACK_DELAY);
+ heartbeatMonitor.heartbeatACKReceived();
+
+ verify(listenerMock2,
+ timeout(INTERVAL + MAX_TIMER_DRIFT)).sendHeartbeat(
+ heartbeatMonitor);
+
+ // NOTE: I had to decrease the ACK_DELAY from 40 ms. because sometimes
+ // the test had failed here. Probably due to imprecision of scheduling,
+ // heartbeatTimedOut() was called before heartbeatACKReceived().
+ verify(listenerMock2, never()).heartbeatTimedOut(
+ Matchers.<IHeartbeatMonitor>any());
+ verify(listenerMock2,
+ timeout(INTERVAL + MAX_TIMER_DRIFT)).heartbeatTimedOut(
+ heartbeatMonitor);
+
+ heartbeatMonitor.stop();
+ }
+
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/LanguageChangeTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/LanguageChangeTest.java
new file mode 100644
index 000000000..4117eb9e5
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/LanguageChangeTest.java
@@ -0,0 +1,171 @@
+package com.ford.syncV4.proxy;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.exception.SyncException;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.proxy.constants.Names;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALM;
+import com.ford.syncV4.proxy.rpc.OnLanguageChange;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.AppInterfaceUnregisteredReason;
+import com.ford.syncV4.proxy.rpc.enums.Language;
+
+import org.json.JSONException;
+import org.mockito.ArgumentCaptor;
+
+import java.util.Hashtable;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Tests for the case when the app is unregistered due to language change.
+ *
+ * Created by enikolsky on 2013-11-14.
+ */
+public class LanguageChangeTest extends InstrumentationTestCase {
+ private static final int CALLBACK_WAIT_TIMEOUT = 500;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+ }
+
+ public void testCorrectLanguageChange()
+ throws SyncException, JSONException {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+
+ // send OnLanguageChange first
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final Language lang = Language.AR_SA;
+ params.put(Names.language, lang);
+ final Language hmiLang = Language.CS_CZ;
+ params.put(Names.hmiDisplayLanguage, hmiLang);
+ proxy.dispatchIncomingMessage(
+ TestCommon.createProtocolMessage(Names.OnLanguageChange, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ // send OnAppInterfaceUnregistered second
+ params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.LANGUAGE_CHANGE;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 2));
+
+ ArgumentCaptor<OnLanguageChange> argument =
+ ArgumentCaptor.forClass(OnLanguageChange.class);
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT)).onAppUnregisteredAfterLanguageChange(
+ argument.capture());
+ assertEquals(lang, argument.getValue().getLanguage());
+ assertEquals(hmiLang, argument.getValue().getHmiDisplayLanguage());
+ }
+
+ public void testLanguageChangeDifferentReason()
+ throws SyncException, JSONException {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+
+ // send OnLanguageChange first
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final Language lang = Language.AR_SA;
+ params.put(Names.language, lang);
+ final Language hmiLang = Language.CS_CZ;
+ params.put(Names.hmiDisplayLanguage, hmiLang);
+ proxy.dispatchIncomingMessage(
+ TestCommon.createProtocolMessage(Names.OnLanguageChange, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ // send OnAppInterfaceUnregistered second
+ params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.MASTER_RESET;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 2));
+
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT).never()).onAppUnregisteredAfterLanguageChange(
+ null);
+ }
+
+ public void testAppUnregisteredWithoutLanguageChange()
+ throws SyncException, JSONException {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+
+ // send OnAppInterfaceUnregistered
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.LANGUAGE_CHANGE;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT)).onAppUnregisteredAfterLanguageChange(
+ null);
+ }
+
+ public void testMessagesBetweenLanguageChangeAndAppUnregistered()
+ throws JSONException, SyncException {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+
+ // send OnLanguageChange first
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final Language lang = Language.AR_SA;
+ params.put(Names.language, lang);
+ final Language hmiLang = Language.CS_CZ;
+ params.put(Names.hmiDisplayLanguage, hmiLang);
+ proxy.dispatchIncomingMessage(
+ TestCommon.createProtocolMessage(Names.OnLanguageChange, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ // send something in between
+ proxy.dispatchIncomingMessage(
+ TestCommon.createProtocolMessage(Names.OnCommand, null,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 2));
+ proxy.dispatchIncomingMessage(
+ TestCommon.createProtocolMessage(Names.Alert, null,
+ ProtocolMessage.RPCTYPE_RESPONSE, 3));
+
+ // send OnAppInterfaceUnregistered last
+ params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.LANGUAGE_CHANGE;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 4));
+
+ ArgumentCaptor<OnLanguageChange> argument =
+ ArgumentCaptor.forClass(OnLanguageChange.class);
+ verify(proxyListenerMock, timeout(CALLBACK_WAIT_TIMEOUT)).
+ onAppUnregisteredAfterLanguageChange(
+ argument.capture());
+ assertEquals(lang, argument.getValue().getLanguage());
+ assertEquals(hmiLang, argument.getValue().getHmiDisplayLanguage());
+ }
+
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionResponseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionResponseTest.java
new file mode 100644
index 000000000..53588c4eb
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionResponseTest.java
@@ -0,0 +1,52 @@
+package com.ford.syncV4.proxy;
+
+import com.ford.syncV4.proxy.rpc.PerformInteractionResponse;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by enikolsky on 2013-10-02.
+ */
+public class PerformInteractionResponseTest extends TestCase {
+ private static final String MANUAL_TEXT_ENTRY = "manualTextEntry";
+
+ public void testManualTextEntryAPI() {
+ PerformInteractionResponse msg = new PerformInteractionResponse();
+ assertNotNull(msg);
+
+ final String text = "0xdeadbeef";
+ msg.setManualTextEntry(text);
+
+ assertEquals(text, msg.getManualTextEntry());
+ }
+
+ public void testRemoveManualTextEntry() {
+ PerformInteractionResponse msg = new PerformInteractionResponse();
+ msg.setManualTextEntry("abcdef");
+ msg.setManualTextEntry(null);
+ assertNull(msg.getManualTextEntry());
+ }
+
+ public void testSetManualTextEntry() {
+ PerformInteractionResponse msg = new PerformInteractionResponse();
+ final String text = "012345";
+ msg.setManualTextEntry(text);
+ assertEquals(text, msg.parameters.get(MANUAL_TEXT_ENTRY));
+ }
+
+ public void testGetManualTextEntry() {
+ PerformInteractionResponse msg = new PerformInteractionResponse();
+ final String text = "098765";
+ msg.parameters.put(MANUAL_TEXT_ENTRY, text);
+ assertEquals(text, msg.getManualTextEntry());
+ }
+
+ /*
+ // Throws java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
+ public void testGetManualTextEntryIncorrect() {
+ PerformInteractionResponse msg = new PerformInteractionResponse();
+ msg.parameters.put(MANUAL_TEXT_ENTRY, 42);
+ assertNull(msg.getManualTextEntry());
+ }
+ */
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionTest.java
new file mode 100644
index 000000000..40ac6dd4c
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/PerformInteractionTest.java
@@ -0,0 +1,59 @@
+package com.ford.syncV4.proxy;
+
+import com.ford.syncV4.proxy.rpc.PerformInteraction;
+import com.ford.syncV4.proxy.rpc.enums.LayoutMode;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by enikolsky on 2013-10-02.
+ */
+public class PerformInteractionTest extends TestCase {
+ private static final String INTERACTION_LAYOUT = "interactionLayout";
+
+ public void testInteractionLayoutAPI() {
+ PerformInteraction msg = new PerformInteraction();
+ assertNotNull(msg);
+
+ final LayoutMode layoutMode = LayoutMode.ICON_ONLY;
+ msg.setInteractionLayout(layoutMode);
+
+ assertEquals(layoutMode, msg.getInteractionLayout());
+ }
+
+ public void testRemoveInteractionLayout() {
+ PerformInteraction msg = new PerformInteraction();
+
+ final LayoutMode layoutMode = LayoutMode.KEYBOARD;
+ msg.setInteractionLayout(layoutMode);
+
+ msg.setInteractionLayout(null);
+ assertNull(msg.getInteractionLayout());
+ }
+
+ public void testSetInteractionLayout() {
+ PerformInteraction msg = new PerformInteraction();
+ final LayoutMode layoutMode = LayoutMode.ICON_WITH_SEARCH;
+ msg.setInteractionLayout(layoutMode);
+ assertEquals(layoutMode, msg.parameters.get(INTERACTION_LAYOUT));
+ }
+
+ public void testGetInteractionLayout() {
+ PerformInteraction msg = new PerformInteraction();
+ final LayoutMode layoutMode = LayoutMode.LIST_WITH_SEARCH;
+ msg.parameters.put(INTERACTION_LAYOUT, layoutMode);
+ assertEquals(layoutMode, msg.getInteractionLayout());
+ }
+
+ public void testGetInteractionLayoutFromString() {
+ PerformInteraction msg = new PerformInteraction();
+ msg.parameters.put(INTERACTION_LAYOUT, "KEYBOARD");
+ assertEquals(LayoutMode.KEYBOARD, msg.getInteractionLayout());
+ }
+
+ public void testGetInteractionLayoutIncorrect() {
+ PerformInteraction msg = new PerformInteraction();
+ msg.parameters.put(INTERACTION_LAYOUT, 42);
+ assertNull(msg.getInteractionLayout());
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageHandlerTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageHandlerTest.java
new file mode 100644
index 000000000..ecaa15a7c
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageHandlerTest.java
@@ -0,0 +1,21 @@
+package com.ford.syncV4.proxy;
+
+import android.test.AndroidTestCase;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * Created by Andrew Batutin on 2/10/14.
+ */
+public class RPCMessageHandlerTest extends AndroidTestCase {
+
+ public void testRPCMessageHandlerCreated() throws Exception {
+ RPCMessageHandler rpcMessageHandler = new RPCMessageHandler(mock(SyncProxyBase.class));
+ assertNotNull("rpcMessageHandler should not be bull", rpcMessageHandler);
+ }
+
+ public void testHandleRPCMessageWIthNullHashTableDoNotThrowNPE() throws Exception {
+ RPCMessageHandler rpcMessageHandler = new RPCMessageHandler(mock(SyncProxyBase.class));
+ rpcMessageHandler.handleRPCMessage(null);
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageTest.java
new file mode 100644
index 000000000..2df27ff22
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/RPCMessageTest.java
@@ -0,0 +1,164 @@
+package com.ford.syncV4.proxy;
+
+import com.ford.syncV4.proxy.constants.Names;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Hashtable;
+import java.util.Random;
+
+/**
+ * Created with Android Studio.
+ * Author: Chernyshov Yuriy - Mobile Development
+ * Date: 12/13/13
+ * Time: 12:18 PM
+ */
+public class RPCMessageTest extends TestCase {
+
+ private static final int CORRELATION_ID = 123;
+ private static final String FUNCTION_NAME = Names.OnAudioPassThru;
+ private static final byte[] BULK_DATA = new byte[Byte.MAX_VALUE];
+ private Hashtable<String, Object> parametersHashTable;
+ private Hashtable<Object, Object> messageHashTable;
+ private Hashtable<Object, Object> dataHashTable;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ if (parametersHashTable != null) {
+ parametersHashTable.clear();
+ } else {
+ parametersHashTable = new Hashtable<String, Object>();
+ }
+ parametersHashTable.put(Names.name, Names.OnAudioPassThru);
+ parametersHashTable.put(Names.correlationID, CORRELATION_ID);
+
+ if (messageHashTable != null) {
+ messageHashTable.clear();
+ } else {
+ messageHashTable = new Hashtable<Object, Object>();
+ }
+
+ if (dataHashTable != null) {
+ dataHashTable.clear();
+ } else {
+ dataHashTable = new Hashtable<Object, Object>();
+ }
+ }
+
+ public void testCreateMessage_SetRequestTypeFirst() {
+ messageHashTable.put(Names.request, getRandomData());
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+
+ RPCMessage message = new RPCMessage(messageHashTable);
+ assertNotNull(message);
+ }
+
+ public void testCreateMessage_SetResponseTypeFirst() {
+ messageHashTable.put(Names.response, getRandomData());
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+
+ RPCMessage message = new RPCMessage(messageHashTable);
+ assertNotNull(message);
+ }
+
+ public void testCreateMessage_SetNotificationTypeFirst() {
+ messageHashTable.put(Names.notification, getRandomData());
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+
+ RPCMessage message = new RPCMessage(messageHashTable);
+ assertNotNull(message);
+ }
+
+ public void testCreateMessage_SetBulkDataFirst_NotificationTypeSecond() {
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+ messageHashTable.put(Names.notification, getRandomData());
+
+ RPCMessage message = new RPCMessage(messageHashTable);
+ assertNotNull(message);
+ }
+
+ public void testCreateMessage_SetBulkDataFirst_ResponseTypeSecond() {
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+ messageHashTable.put(Names.response, getRandomData());
+
+ RPCMessage message = new RPCMessage(messageHashTable);
+ assertNotNull(message);
+ }
+
+ public void testCreateMessage_SetBulkDataFirst_RequestTypeSecond() {
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+ messageHashTable.put(Names.request, getRandomData());
+
+ RPCMessage message = new RPCMessage(messageHashTable);
+ assertNotNull(message);
+ }
+
+ public void testSerialize() throws JSONException {
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+ messageHashTable.put(Names.request, getData());
+
+ RPCMessage message = new RPCMessage(messageHashTable);
+ assertNotNull(message);
+
+ JSONObject jsonObject = message.serializeJSON((byte) 2);
+ assertEquals(2, jsonObject.length());
+ assertEquals(CORRELATION_ID, jsonObject.getInt(Names.correlationID));
+ assertEquals(FUNCTION_NAME, jsonObject.getString(Names.name));
+ }
+
+ private Hashtable<Object, Object> getRandomData() {
+ // The 3-rd one is empty
+ switch (randInt(0, 3)) {
+ case 0:
+ getData();
+ break;
+ case 1:
+ dataHashTable.put(Names.correlationID, CORRELATION_ID);
+ dataHashTable.put(Names.function_name, FUNCTION_NAME);
+ break;
+ case 2:
+ dataHashTable.put(Names.function_name, FUNCTION_NAME);
+ break;
+ }
+ return dataHashTable;
+ }
+
+ private Hashtable<Object, Object> getData() {
+ dataHashTable.put(Names.correlationID, CORRELATION_ID);
+ dataHashTable.put(Names.parameters, parametersHashTable);
+ dataHashTable.put(Names.function_name, FUNCTION_NAME);
+ return dataHashTable;
+ }
+
+ /**
+ * Returns a psuedo-random number between min and max, inclusive.
+ * The difference between min and max can be at most
+ * <code>Integer.MAX_VALUE - 1</code>.
+ *
+ * @param min Minimim value
+ * @param max Maximim value. Must be greater than min.
+ * @return Integer between min and max, inclusive.
+ * @see java.util.Random#nextInt(int)
+ */
+ public static int randInt(int min, int max) {
+ // Usually this can be a field rather than a method variable
+ Random rand = new Random();
+ // nextInt is normally exclusive of the top value,
+ // so add 1 to make it inclusive
+ return rand.nextInt((max - min) + 1) + min;
+ }
+
+ public void testRECMessageCopyConstructor() throws Exception {
+ messageHashTable.put(Names.bulkData, BULK_DATA);
+ messageHashTable.put(Names.request, getRandomData());
+ RPCMessage message = new RPCMessage(messageHashTable);
+ RPCMessage real = new RPCMessage(message);
+ assertEquals(message.getFunctionName(), real.getFunctionName());
+ assertEquals(message.getMessageType(), real.getMessageType());
+ }
+} \ No newline at end of file
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/ShowConstantTBTTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/ShowConstantTBTTest.java
new file mode 100644
index 000000000..48a50b7d6
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/ShowConstantTBTTest.java
@@ -0,0 +1,100 @@
+package com.ford.syncV4.proxy;
+
+import com.ford.syncV4.proxy.rpc.Image;
+import com.ford.syncV4.proxy.rpc.ShowConstantTBT;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by enikolsky on 2013-10-02.
+ */
+public class ShowConstantTBTTest extends TestCase {
+ private static final String TIME_TO_DESTINATION = "timeToDestination";
+ private static final String NEXT_TURN_ICON = "nextTurnIcon";
+
+ public void testTimeToDestinationAPI() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ assertNotNull(msg);
+
+ final String text = "123456";
+ msg.setTimeToDestination(text);
+
+ assertEquals(text, msg.getTimeToDestination());
+ }
+
+ public void testRemoveTimeToDestination() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+
+ final String text = "098765";
+ msg.setTimeToDestination(text);
+
+ msg.setTimeToDestination(null);
+ assertNull(msg.getTimeToDestination());
+ }
+
+ public void testSetTimeToDestination() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ final String text = "abcdef";
+ msg.setTimeToDestination(text);
+ assertEquals(text, msg.parameters.get(TIME_TO_DESTINATION));
+ }
+
+ public void testGetTimeToDestination() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ final String text = "ETA";
+ msg.parameters.put(TIME_TO_DESTINATION, text);
+ assertEquals(text, msg.getTimeToDestination());
+ }
+
+ /*
+ // Throws java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
+ public void testGetTimeToDestinationIncorrect() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ msg.parameters.put(TIME_TO_DESTINATION, 42);
+ assertNull(msg.getTimeToDestination());
+ }
+ */
+
+ public void testNextTurnIconAPI() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ assertNotNull(msg);
+
+ final Image image = new Image();
+ msg.setNextTurnIcon(image);
+
+ assertEquals(image, msg.getNextTurnIcon());
+ }
+
+ public void testRemoveNextTurnIcon() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+
+ final Image image = new Image();
+ msg.setNextTurnIcon(image);
+
+ msg.setNextTurnIcon(null);
+ assertNull(msg.getNextTurnIcon());
+ }
+
+ public void testSetNextTurnIcon() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ final Image image = new Image();
+ msg.setNextTurnIcon(image);
+ assertEquals(image, msg.parameters.get(NEXT_TURN_ICON));
+ }
+
+ public void testGetNextTurnIcon() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ final Image image = new Image();
+ msg.parameters.put(NEXT_TURN_ICON, image);
+ assertEquals(image, msg.getNextTurnIcon());
+ }
+
+ /*
+ // Throws java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
+ public void testGetNextTurnIconIncorrect() {
+ ShowConstantTBT msg = new ShowConstantTBT();
+ msg.parameters.put(NEXT_TURN_ICON, 42);
+ assertNull(msg.getNextTurnIcon());
+ }
+ */
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMProxyListenerTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMProxyListenerTest.java
new file mode 100644
index 000000000..42bd4bc22
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMProxyListenerTest.java
@@ -0,0 +1,122 @@
+package com.ford.syncV4.proxy;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.exception.SyncException;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.proxy.constants.Names;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALM;
+import com.ford.syncV4.proxy.rpc.OnHashChange;
+import com.ford.syncV4.proxy.rpc.OnSystemRequest;
+import com.ford.syncV4.proxy.rpc.SystemRequestResponse;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.FileType;
+import com.ford.syncV4.proxy.rpc.enums.RequestType;
+import com.ford.syncV4.proxy.rpc.enums.Result;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.mockito.ArgumentCaptor;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Matchers.contains;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Tests for SyncProxyALM class calling proxy listener for different responses.
+ *
+ * Created by enikolsky on 2014-01-24.
+ */
+public class SyncProxyALMProxyListenerTest extends InstrumentationTestCase {
+ private static final int CALLBACK_WAIT_TIMEOUT = 100;
+ private IProxyListenerALM proxyListenerMock;
+ private SyncProxyALM proxy;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ proxyListenerMock = mock(IProxyListenerALM.class);
+ proxy = TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ proxy._wiproVersion = 2;
+ }
+
+ public void testOnSystemRequestResponseShouldBeCalledOnResponse()
+ throws SyncException, JSONException {
+ // send SystemRequestResponse
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ params.put(Names.success, true);
+ params.put(Names.resultCode, Result.SUCCESS);
+ proxy.dispatchIncomingMessage(
+ TestCommon.createProtocolMessage(Names.SystemRequest, params,
+ ProtocolMessage.RPCTYPE_RESPONSE, 1));
+
+ ArgumentCaptor<SystemRequestResponse> responseCaptor =
+ ArgumentCaptor.forClass(SystemRequestResponse.class);
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT)).onSystemRequestResponse(
+ responseCaptor.capture());
+ assertThat(responseCaptor.getValue().getSuccess(), is(true));
+ assertThat(responseCaptor.getValue().getResultCode(),
+ is(Result.SUCCESS));
+ }
+
+ public void testOnOnSystemRequestShouldBeCalledOnNotification()
+ throws SyncException, JSONException {
+ final RequestType requestType = RequestType.AUTH_ACK;
+ final Vector<String> urls = new Vector<String>();
+ urls.add("https://x.y/");
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 10;
+ final int length = 1000;
+
+ // send OnSystemRequest
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ params.put(Names.requestType, requestType);
+ params.put(Names.url, urls);
+ params.put(Names.fileType, fileType);
+ params.put(Names.offset, offset);
+ params.put(Names.length, length);
+ proxy.dispatchIncomingMessage(
+ TestCommon.createProtocolMessage(Names.OnSystemRequest, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ ArgumentCaptor<OnSystemRequest> notificationCaptor =
+ ArgumentCaptor.forClass(OnSystemRequest.class);
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT)).onOnSystemRequest(
+ notificationCaptor.capture());
+ final OnSystemRequest notification = notificationCaptor.getValue();
+ assertThat(notification.getRequestType(), is(requestType));
+ assertThat(notification.getUrl(), is(urls));
+ assertThat(notification.getFileType(), is(fileType));
+ assertThat(notification.getOffset(), is(offset));
+ assertThat(notification.getLength(), is(length));
+ }
+
+ public void testOnHashChangeShouldBeCalledOnNotification() throws SyncException,
+ JSONException {
+ String hashId = "1234567890";
+
+ // send OnHashChange
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ params.put(Names.hashID, hashId);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(Names.OnHashChange,
+ params, ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ ArgumentCaptor<OnHashChange> notificationCaptor = ArgumentCaptor.forClass(OnHashChange.class);
+ verify(proxyListenerMock, timeout(CALLBACK_WAIT_TIMEOUT)).onHashChange(notificationCaptor.capture());
+
+ final OnHashChange notification = notificationCaptor.getValue();
+ assertThat(notification.getHashID(), is(hashId));
+ }
+} \ No newline at end of file
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMTest.java
new file mode 100644
index 000000000..5f591f319
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyALMTest.java
@@ -0,0 +1,451 @@
+package com.ford.syncV4.proxy;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.exception.SyncException;
+import com.ford.syncV4.protocol.IProtocolListener;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALM;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALMTesting;
+import com.ford.syncV4.proxy.rpc.SyncMsgVersion;
+import com.ford.syncV4.proxy.rpc.enums.Language;
+import com.ford.syncV4.proxy.rpc.enums.SyncInterfaceAvailability;
+import com.ford.syncV4.session.Session;
+import com.ford.syncV4.syncConnection.ISyncConnectionListener;
+import com.ford.syncV4.syncConnection.SyncConnection;
+import com.ford.syncV4.transport.SyncTransport;
+import com.ford.syncV4.transport.TCPTransportConfig;
+import com.ford.syncV4.transport.TransportType;
+import com.ford.syncV4.util.TestConfig;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+import java.lang.reflect.Field;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by Andrew Batutin on 8/22/13.
+ */
+public class SyncProxyALMTest extends InstrumentationTestCase {
+
+ public static final byte SESSION_ID = (byte) 48;
+ public static final byte VERSION = (byte) 2;
+ private SyncProxyALM sut;
+
+ public SyncProxyALMTest() {
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());
+ sut = getSyncProxyALM();
+ }
+
+ private SyncProxyALM getSyncProxyALM() throws SyncException {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ TCPTransportConfig conf = mock(TCPTransportConfig.class);
+ when(conf.getTransportType()).thenReturn(TransportType.TCP);
+ final IProxyListenerALM listenerALM = mock(IProxyListenerALM.class);
+ SyncProxyALM proxyALM = getSyncProxyALM(syncMsgVersion, conf, listenerALM);
+ return proxyALM;
+ }
+
+ private SyncProxyALM getSyncProxyALM(final SyncMsgVersion syncMsgVersion, final TCPTransportConfig conf, final IProxyListenerALM listenerALM) throws SyncException {
+ return new SyncProxyALM(listenerALM,
+ /*sync proxy configuration resources*/null,
+ /*enable advanced lifecycle management true,*/
+ "appName",
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/true,
+ /*App type*/null,
+ syncMsgVersion,
+ /*language desired*/Language.EN_US,
+ /*HMI Display Language Desired*/Language.EN_US,
+ /*App ID*/"8675308",
+ /*autoActivateID*/null,
+ /*callbackToUIThre1ad*/ false,
+ /*preRegister*/ false,
+ 2,
+ conf, new TestConfig()) {
+
+
+ @Override
+ public void initializeProxy() throws SyncException {
+ // Reset all of the flags and state variables
+ _haveReceivedFirstNonNoneHMILevel = false;
+ _haveReceivedFirstFocusLevel = false;
+ _haveReceivedFirstFocusLevelFull = false;
+ _syncIntefaceAvailablity = SyncInterfaceAvailability.SYNC_INTERFACE_UNAVAILABLE;
+
+ // Setup SyncConnection
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.closeConnection(currentSession.getSessionId(), false);
+ mSyncConnection = null;
+ }
+ mSyncConnection = mock(SyncConnection.class);
+ when(mSyncConnection.getIsConnected()).thenReturn(true);
+ }
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.startTransport();
+ }
+ }
+ }
+ };
+ }
+
+ public void testSyncProxyBaseShouldBeCreated() throws Exception {
+ SyncProxyALM syncProxy = getSyncProxyALM();
+ assertNotNull("Sync Proxy should not be null", syncProxy);
+ }
+
+ public void testOnMobileNavSessionStarted() throws Exception {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ TCPTransportConfig conf = mock(TCPTransportConfig.class);
+ when(conf.getTransportType()).thenReturn(TransportType.TCP);
+ final IProxyListenerALM listenerALM = mock(IProxyListenerALM.class);
+
+ SyncProxyALM proxyALM = new SyncProxyALM(listenerALM,
+ /*sync proxy configuration resources*/null,
+ /*enable advanced lifecycle management true,*/
+ "appName",
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/true,
+ /*app type*/null,
+ syncMsgVersion,
+ /*language desired*/Language.EN_US,
+ /*HMI Display Language Desired*/Language.EN_US,
+ /*App ID*/"8675308",
+ /*autoActivateID*/null,
+ /*callbackToUIThre1ad*/ false,
+ /*preRegister*/ false,
+ 2,
+ conf, new TestConfig()) {
+
+
+ @Override
+ public void initializeProxy() throws SyncException {
+ // Reset all of the flags and state variables
+ _haveReceivedFirstNonNoneHMILevel = false;
+ _haveReceivedFirstFocusLevel = false;
+ _haveReceivedFirstFocusLevelFull = false;
+ _syncIntefaceAvailablity = SyncInterfaceAvailability.SYNC_INTERFACE_UNAVAILABLE;
+
+ // Setup SyncConnection
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.closeConnection(currentSession.getSessionId(), false);
+ mSyncConnection = null;
+ }
+ mSyncConnection = mock(SyncConnection.class);
+ when(mSyncConnection.getIsConnected()).thenReturn(true);
+ }
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.startTransport();
+ }
+ }
+ }
+
+ @Override
+ protected void startMobileNaviService(byte sessionID, String correlationID) {
+ super.startMobileNaviService(sessionID, correlationID);
+ assertEquals("Session ID should be equal", currentSession.getSessionId(), (byte) 48);
+ }
+ };
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(Session.createSession(ServiceType.RPC, SESSION_ID), VERSION, "");
+ }
+
+ public void testReceivedMobileNavSessionIncomingMessage() throws Exception {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ TCPTransportConfig conf = mock(TCPTransportConfig.class);
+ when(conf.getTransportType()).thenReturn(TransportType.TCP);
+ final IProxyListenerALM listenerALM = mock(IProxyListenerALM.class);
+ SyncProxyALM proxyALM = new SyncProxyALM(listenerALM,
+ /*sync proxy configuration resources*/null,
+ /*enable advanced lifecycle management true,*/
+ "appName",
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/true,
+ /*app type*/null,
+ syncMsgVersion,
+ /*language desired*/Language.EN_US,
+ /*HMI Display Language Desired*/Language.EN_US,
+ /*App ID*/"8675308",
+ /*autoActivateID*/null,
+ /*callbackToUIThre1ad*/ false,
+ /*preRegister*/ false,
+ 2,
+ conf, new TestConfig()) {
+
+
+ @Override
+ public void initializeProxy() throws SyncException {
+ // Reset all of the flags and state variables
+ _haveReceivedFirstNonNoneHMILevel = false;
+ _haveReceivedFirstFocusLevel = false;
+ _haveReceivedFirstFocusLevelFull = false;
+ _syncIntefaceAvailablity = SyncInterfaceAvailability.SYNC_INTERFACE_UNAVAILABLE;
+
+ // Setup SyncConnection
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.closeConnection(currentSession.getSessionId(), false);
+ mSyncConnection = null;
+ }
+ mSyncConnection = mock(SyncConnection.class);
+ when(mSyncConnection.getIsConnected()).thenReturn(true);
+ }
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.startTransport();
+ }
+ }
+ }
+
+ @Override
+ protected void handleMobileNavMessage(ProtocolMessage message) {
+ super.handleMobileNavMessage(message);
+ assertEquals(message.getServiceType(), ServiceType.Mobile_Nav);
+ assertEquals(message.getVersion(), (byte) 2);
+ assertTrue(message.getSessionID() == (byte) 48);
+ }
+ };
+ ProtocolMessage message = new ProtocolMessage();
+ message.setVersion((byte) 2);
+ message.setSessionID((byte) 48);
+ message.setSessionType(ServiceType.Mobile_Nav);
+ proxyALM.dispatchIncomingMessage(message);
+ }
+
+ public void testSyncProxyBaseEndSessionCallbackTest() throws Exception {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ TCPTransportConfig conf = mock(TCPTransportConfig.class);
+ final IProxyListenerALM listenerALM = mock(IProxyListenerALM.class);
+ SyncProxyALM proxyALM = new SyncProxyALM(listenerALM,
+ /*sync proxy configuration resources*/null,
+ /*enable advanced lifecycle management true,*/
+ "appName",
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/true,
+ /*app type*/null,
+ syncMsgVersion,
+ /*language desired*/Language.EN_US,
+ /*HMI Display Language Desired*/Language.EN_US,
+ /*App ID*/"8675308",
+ /*autoActivateID*/null,
+ /*callbackToUIThre1ad*/ false,
+ /*preRegister*/ false,
+ 2,
+ conf, new TestConfig()) {
+
+
+ @Override
+ public void initializeProxy() throws SyncException {
+ // Reset all of the flags and state variables
+ _haveReceivedFirstNonNoneHMILevel = false;
+ _haveReceivedFirstFocusLevel = false;
+ _haveReceivedFirstFocusLevelFull = false;
+ _syncIntefaceAvailablity = SyncInterfaceAvailability.SYNC_INTERFACE_UNAVAILABLE;
+
+ // Setup SyncConnection
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.closeConnection(currentSession.getSessionId(), false);
+ mSyncConnection = null;
+ }
+ mSyncConnection = mock(SyncConnection.class);
+ when(mSyncConnection.getIsConnected()).thenReturn(true);
+ }
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.startTransport();
+ }
+ }
+ }
+
+ };
+ ArgumentCaptor<ServiceType> sessionTypeCaptor = ArgumentCaptor.forClass(ServiceType.class);
+ ArgumentCaptor<Byte> sessionIdCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<String> correlationIdCaptor = ArgumentCaptor.forClass(String.class);
+ proxyALM.handleEndServiceAck(ServiceType.RPC, SESSION_ID, "correlationID");
+ verify(listenerALM).onProtocolServiceEnded(sessionTypeCaptor.capture(), sessionIdCaptor.capture(), correlationIdCaptor.capture());
+ assertEquals(ServiceType.RPC, sessionTypeCaptor.getValue());
+ assertEquals(SESSION_ID, sessionIdCaptor.getValue().byteValue());
+ assertEquals("correlationID", correlationIdCaptor.getValue());
+ }
+
+
+ public void testSyncProxyBaseStartSessionCallbackTest() throws Exception {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ TCPTransportConfig conf = mock(TCPTransportConfig.class);
+ final IProxyListenerALM listenerALM = mock(IProxyListenerALM.class);
+ SyncProxyALM proxyALM = new SyncProxyALM(listenerALM,
+ /*sync proxy configuration resources*/null,
+ /*enable advanced lifecycle management true,*/
+ "appName",
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/true,
+ /*app type*/null,
+ syncMsgVersion,
+ /*language desired*/Language.EN_US,
+ /*HMI Display Language Desired*/Language.EN_US,
+ /*App ID*/"8675308",
+ /*autoActivateID*/null,
+ /*callbackToUIThre1ad*/ false,
+ /*preRegister*/ false,
+ 2,
+ conf, new TestConfig()) {
+
+
+ @Override
+ public void initializeProxy() throws SyncException {
+ // Reset all of the flags and state variables
+ _haveReceivedFirstNonNoneHMILevel = false;
+ _haveReceivedFirstFocusLevel = false;
+ _haveReceivedFirstFocusLevelFull = false;
+ _syncIntefaceAvailablity = SyncInterfaceAvailability.SYNC_INTERFACE_UNAVAILABLE;
+
+ // Setup SyncConnection
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.closeConnection(currentSession.getSessionId(), false);
+ mSyncConnection = null;
+ }
+ mSyncConnection = mock(SyncConnection.class);
+ when(mSyncConnection.getIsConnected()).thenReturn(true);
+ }
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.startTransport();
+ }
+ }
+ }
+
+ };
+ ArgumentCaptor<ServiceType> sessionTypeCaptor = ArgumentCaptor.forClass(ServiceType.class);
+ ArgumentCaptor<Byte> sessionIdCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<Byte> versionCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<String> correlationIdCaptor = ArgumentCaptor.forClass(String.class);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(Session.createSession(ServiceType.RPC, SESSION_ID), VERSION, "correlationID");
+ verify(listenerALM).onSessionStarted(sessionIdCaptor.capture(), correlationIdCaptor.capture());
+ assertEquals(SESSION_ID, sessionIdCaptor.getValue().byteValue());
+ assertEquals("correlationID", correlationIdCaptor.getValue());
+ }
+
+ public void testHeartBeatIsSet() throws Exception {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ TCPTransportConfig conf = mock(TCPTransportConfig.class);
+ final IProxyListenerALM listenerALM = mock(IProxyListenerALM.class);
+ SyncProxyALM proxyALM = new SyncProxyALM(listenerALM,
+ /*sync proxy configuration resources*/null,
+ /*enable advanced lifecycle management true,*/
+ "appName",
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/true,
+ /*app type*/null,
+ syncMsgVersion,
+ /*language desired*/Language.EN_US,
+ /*HMI Display Language Desired*/Language.EN_US,
+ /*App ID*/"8675308",
+ /*autoActivateID*/null,
+ /*callbackToUIThre1ad*/ false,
+ /*preRegister*/ false,
+ 2,
+ conf, new TestConfig()) {
+
+
+ @Override
+ public void initializeProxy() throws SyncException {
+ // Reset all of the flags and state variables
+ _haveReceivedFirstNonNoneHMILevel = false;
+ _haveReceivedFirstFocusLevel = false;
+ _haveReceivedFirstFocusLevelFull = false;
+ _syncIntefaceAvailablity = SyncInterfaceAvailability.SYNC_INTERFACE_UNAVAILABLE;
+
+ // Setup SyncConnection
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.closeConnection(currentSession.getSessionId(), false);
+ mSyncConnection = null;
+ }
+ mSyncConnection = mock(SyncConnection.class);
+ when(mSyncConnection.getIsConnected()).thenReturn(true);
+ }
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.startTransport();
+ }
+ }
+ }
+
+ };
+ SyncProxyALM.setHeartBeatInterval(50);
+ assertEquals("Heartbeat should be 50", 50, SyncProxyALM.getHeartBeatInterval());
+ }
+
+
+ public void testMaxJsonSizeInIncomingMessageShouldCallOnError()
+ throws SyncException, NoSuchFieldException, IllegalAccessException {
+ final WiProProtocol protocol =
+ new WiProProtocol(mock(IProtocolListener.class));
+ protocol.setVersion((byte) 0x02);
+ final SyncConnection syncConnectionMock = mock(SyncConnection.class);
+ when(syncConnectionMock.getWiProProtocol()).thenReturn(protocol);
+
+ IProxyListenerALMTesting proxyListenerMock =
+ mock(IProxyListenerALMTesting.class);
+ SyncProxyALM proxy =
+ new SyncProxyALM(proxyListenerMock, null, "a", null, null,
+ false, null, null, null, null, null, null, false, false,
+ 2, null, syncConnectionMock, new TestConfig());
+ SyncConnection connection =
+ new SyncConnection(proxy.getInterfaceBroker());
+ connection.init(null, mock(SyncTransport.class));
+ proxy.setSyncConnection(connection);
+
+ final byte maxByte = (byte) 0xFF;
+ final byte[] bytes =
+ { 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, maxByte, maxByte, maxByte, maxByte, 0x00 };
+ connection.onTransportBytesReceived(bytes, bytes.length);
+
+ ArgumentCaptor<Throwable> throwableArgumentCaptor =
+ ArgumentCaptor.forClass(Throwable.class);
+ verify(proxyListenerMock, timeout(100).times(1)).onError(anyString(),
+ throwableArgumentCaptor.capture());
+ assertThat(throwableArgumentCaptor.getValue().toString(),
+ containsString(OutOfMemoryError.class.getSimpleName()));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBaseTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBaseTest.java
new file mode 100644
index 000000000..4b0e0a969
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBaseTest.java
@@ -0,0 +1,580 @@
+package com.ford.syncV4.proxy;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.exception.SyncException;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.proxy.constants.Names;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALM;
+import com.ford.syncV4.proxy.rpc.RegisterAppInterface;
+import com.ford.syncV4.proxy.rpc.SyncMsgVersion;
+import com.ford.syncV4.proxy.rpc.TTSChunk;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.AppHMIType;
+import com.ford.syncV4.proxy.rpc.enums.AppInterfaceUnregisteredReason;
+import com.ford.syncV4.proxy.rpc.enums.Language;
+import com.ford.syncV4.proxy.rpc.enums.Result;
+import com.ford.syncV4.proxy.rpc.enums.SyncInterfaceAvailability;
+import com.ford.syncV4.service.Service;
+import com.ford.syncV4.session.Session;
+import com.ford.syncV4.syncConnection.SyncConnection;
+import com.ford.syncV4.transport.TCPTransportConfig;
+import com.ford.syncV4.util.TestConfig;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+import java.io.OutputStream;
+import java.io.PipedOutputStream;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.TimerTask;
+import java.util.Vector;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by Andrew Batutin on 1/13/14.
+ */
+public class SyncProxyBaseTest extends InstrumentationTestCase {
+
+ private static final int CALLBACK_WAIT_TIMEOUT = 500;
+ private static byte sessionID = (byte) 1;
+ public static final byte VERSION = (byte) 2;
+ private IProxyListenerALM listenerALM;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ listenerALM = mock(IProxyListenerALM.class);
+ }
+
+ public void testSyncProxyBaseHasServicePoolField() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ assertNotNull("should not be null", proxyALM.getServicePool());
+ }
+
+ public void testMobileNavSessionAddedToServicePoolOnStart() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Mobile_Nav, sessionID, VERSION, "");
+ List<Service> serviceList = proxyALM.getServicePool();
+ assertTrue(proxyALM.hasServiceInServicesPool(ServiceType.Mobile_Nav));
+ assertEquals(sessionID, serviceList.get(0).getSession().getSessionId());
+ }
+
+ public void testMobileNavSessionRemovedFromPoolListOnStop() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Mobile_Nav, sessionID, VERSION, "");
+ proxyALM.stopMobileNaviService();
+ assertEquals("pool should be empty", false, proxyALM.hasServiceInServicesPool(ServiceType.Mobile_Nav));
+ }
+
+ public void testMobileNavServiceEndedOnDispose() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Mobile_Nav, sessionID, VERSION, "");
+ proxyALM.dispose();
+ assertEquals("pool should be empty", 0, proxyALM.getServicePool().size());
+ }
+
+ public void testRPCServiceAddedToPoolOnStart() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ assertEquals("pool should has RPC service", 1, proxyALM.getServicePool().size());
+ }
+
+ public void testRPCServiceEndedOnDispose() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.dispose();
+ assertEquals("pool should be empty", 0, proxyALM.getServicePool().size());
+ }
+
+ public void testAllServicesEndedOnDispose() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Mobile_Nav, sessionID, VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Audio_Service, sessionID, VERSION, "");
+ proxyALM.dispose();
+ assertEquals("pool should be empty", 0, proxyALM.getServicePool().size());
+ }
+
+ public void testStopMobileNaviSessionForUnexcitingSessionDontThrowsException() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ try {
+ proxyALM.stopMobileNaviService();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ assertNull("exception should not be thrown", e);
+ }
+ }
+
+ private SyncProxyBase getSyncProxyBase() throws SyncException {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ TCPTransportConfig conf = mock(TCPTransportConfig.class);
+
+ return new SyncProxyALM(listenerALM,
+ /*sync proxy configuration resources*/null,
+ /*enable advanced lifecycle management true,*/
+ "appName",
+ /*ngn media app*/null,
+ /*vr synonyms*/null,
+ /*is media app*/true,
+ /*app type*/null,
+ syncMsgVersion,
+ /*language desired*/Language.EN_US,
+ /*HMI Display Language Desired*/Language.EN_US,
+ /*App ID*/"8675308",
+ /*autoActivateID*/null,
+ /*callbackToUIThre1ad*/ false,
+ /*preRegister*/ false,
+ 2,
+ conf, new TestConfig()) {
+ @Override
+ public void initializeProxy() throws SyncException {
+ // Reset all of the flags and state variables
+ _haveReceivedFirstNonNoneHMILevel = false;
+ _haveReceivedFirstFocusLevel = false;
+ _haveReceivedFirstFocusLevelFull = false;
+ _syncIntefaceAvailablity = SyncInterfaceAvailability.SYNC_INTERFACE_UNAVAILABLE;
+
+ // Setup SyncConnection
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.closeConnection(currentSession.getSessionId(), false);
+ mSyncConnection = null;
+ }
+ mSyncConnection = mock(SyncConnection.class);
+ when(mSyncConnection.getIsConnected()).thenReturn(true);
+ }
+ synchronized (CONNECTION_REFERENCE_LOCK) {
+ if (mSyncConnection != null) {
+ mSyncConnection.startTransport();
+ }
+ }
+ currentSession.setSessionId(sessionID);
+ }
+
+ @Override
+ public void setSyncConnection(SyncConnection syncConnection) {
+ if (syncConnection != null) {
+ super.setSyncConnection(syncConnection);
+ }
+ }
+ };
+ }
+
+ public void testOnAudioServiceStartServiceAddedToPool() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Audio_Service, session.getSessionId(), VERSION, "");
+ Service audioService = new Service();
+ audioService.setSession(session);
+ audioService.setServiceType(ServiceType.Audio_Service);
+ assertTrue("pool should have AudioService ", proxyALM.hasServiceInServicesPool(ServiceType.Audio_Service));
+ }
+
+ public void testOnAudioServiceStartServiceCallbackCalled() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Audio_Service, session.getSessionId(), VERSION, "");
+ Mockito.verify(listenerALM, times(1)).onAudioServiceStart();
+ }
+
+ public void testAudioServiceRemovedFromPoolOnStopAudioService() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Mobile_Nav, session.getSessionId(), VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Audio_Service, session.getSessionId(), VERSION, "");
+ proxyALM.stopAudioService();
+ Service mobileNaviService = new Service();
+ mobileNaviService.setSession(session);
+ mobileNaviService.setServiceType(ServiceType.Mobile_Nav);
+ assertTrue("pool should have Mobile nav service ", proxyALM.hasServiceInServicesPool(ServiceType.Mobile_Nav));
+ Service audioService = new Service();
+ audioService.setSession(session);
+ audioService.setServiceType(ServiceType.Audio_Service);
+ assertFalse("pool should not have Audio service ", proxyALM.getServicePool().contains(audioService));
+ }
+
+ public void testStartAudioDataTransferClassConnectionMethod() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ proxyALM.mSyncConnection = mock(SyncConnection.class);
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Audio_Service, session.getSessionId(), VERSION, "");
+ proxyALM.startAudioDataTransfer();
+ ArgumentCaptor<Byte> sessionIDCaptor = ArgumentCaptor.forClass(byte.class);
+ verify(proxyALM.mSyncConnection, times(1)).startAudioDataTransfer(sessionIDCaptor.capture());
+ }
+
+ public void testStartAudioDataTransferReturnsStream() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ proxyALM.mSyncConnection = mock(SyncConnection.class);
+ when(proxyALM.mSyncConnection.startAudioDataTransfer(sessionID)).thenReturn(new PipedOutputStream());
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Audio_Service, session.getSessionId(), VERSION, "");
+ OutputStream stream = proxyALM.startAudioDataTransfer();
+ assertNotNull("stream should not be null", stream);
+ }
+
+ public void testStopAudioDataTransferFiresCallback() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ proxyALM.mSyncConnection = mock(SyncConnection.class);
+ proxyALM.stopAudioDataTransfer();
+ verify(proxyALM.mSyncConnection, timeout(1)).stopAudioDataTransfer();
+ }
+
+ public void testCloseSessionCalledWithRightSessionID() throws Exception {
+ SyncProxyBase proxyALM = getSyncProxyBase();
+ proxyALM.mSyncConnection = mock(SyncConnection.class);
+ Session session = Session.createSession(ServiceType.RPC, sessionID);
+ proxyALM.getInterfaceBroker().onProtocolSessionStarted(session, VERSION, "");
+ proxyALM.closeSession(false);
+ ArgumentCaptor<Byte> sessionIDCaptor = ArgumentCaptor.forClass(byte.class);
+ ArgumentCaptor<Boolean> keepConnectionCaptor = ArgumentCaptor.forClass(Boolean.class);
+ verify(proxyALM.mSyncConnection, times(1)).closeConnection(sessionIDCaptor.capture(), keepConnectionCaptor.capture());
+ assertEquals("session id of closed RPC service should be same as initial session id", sessionID, sessionIDCaptor.getValue().byteValue());
+ assertFalse(keepConnectionCaptor.getValue());
+ }
+
+ public void testAppUnregisteredWithIgnitionOff() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+
+ // send OnAppInterfaceUnregistered
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.IGNITION_OFF;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT)).onAppUnregisteredReason(
+ reason);
+ }
+
+ public void testAppUnregisteredWithMasterReset() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+
+ // send OnAppInterfaceUnregistered
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.MASTER_RESET;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT)).onAppUnregisteredReason(
+ reason);
+ }
+
+ public void testAppUnregisteredWithFactoryDefaults() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+
+ // send OnAppInterfaceUnregistered
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.FACTORY_DEFAULTS;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+
+ verify(proxyListenerMock,
+ timeout(CALLBACK_WAIT_TIMEOUT)).onAppUnregisteredReason(
+ reason);
+ }
+
+ public void testScheduleInitializeProxyNotCalledIfServiceListIsEmpty() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+ proxy.currentSession = Session.createSession(ServiceType.RPC, sessionID);
+ proxy.currentSession.stopSession();
+ proxy.scheduleInitializeProxy();
+ TimerTask timerTask = proxy.getCurrentReconnectTimerTask();
+ assertNull("timerTask should be null", timerTask);
+ }
+
+ public void testScheduleInitializeProxyCalledIfServiceListIsNotEmpty() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+ proxy.currentSession = Session.createSession(ServiceType.RPC, sessionID);
+ proxy.scheduleInitializeProxy();
+ TimerTask timerTask = proxy.getCurrentReconnectTimerTask();
+ assertNotNull("timerTask should not be null", timerTask);
+ }
+
+ public void testInCaseSessionRestartedRpcServiceShouldBeRecreated() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+ proxy.currentSession = Session.createSession(ServiceType.RPC, sessionID);
+ proxy.closeSession(false);
+ proxy.setSyncConnection(mock(SyncConnection.class));
+ proxy.getInterfaceBroker().onProtocolSessionStarted(Session.createSession(ServiceType.RPC, sessionID), (byte) 2, "");
+ assertFalse(proxy.currentSession.isServicesEmpty());
+ assertTrue(proxy.currentSession.hasService(ServiceType.RPC));
+ }
+
+ public void testSessionHasOnlyOneRPCService() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+ proxy.currentSession = Session.createSession(ServiceType.RPC, sessionID);
+ proxy.closeSession(false);
+ proxy.setSyncConnection(mock(SyncConnection.class));
+ proxy.getInterfaceBroker().onProtocolSessionStarted(Session.createSession(ServiceType.RPC, sessionID), (byte) 2, "");
+ proxy.getInterfaceBroker().onProtocolSessionStarted(Session.createSession(ServiceType.RPC, sessionID), (byte) 2, "");
+ assertEquals("only one rpc service should be in service list", 1, proxy.currentSession.getServiceList().size());
+ }
+
+ public void testUnregisterAppResponseTriggersStopServicesAndSession() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ assertNotNull(proxy);
+ proxy._wiproVersion = 2;
+ proxy.getInterfaceBroker().onProtocolSessionStarted(Session.createSession(ServiceType.RPC, sessionID), (byte) 2, "");
+ proxy.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Mobile_Nav, sessionID, (byte) 2, "");
+ proxy.getInterfaceBroker().onProtocolServiceStarted(ServiceType.Audio_Service, sessionID, (byte) 2, "");
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+
+ params.put(Names.resultCode, Result.SUCCESS);
+ params.put(Names.success, true);
+ ProtocolMessage protocolMessage = TestCommon.createProtocolMessage(
+ Names.UnregisterAppInterface, params,
+ ProtocolMessage.RPCTYPE_RESPONSE, 1);
+ protocolMessage.setSessionID(sessionID);
+ proxy.dispatchIncomingMessage(protocolMessage);
+ verify(proxy.getSyncConnection(), times(1)).closeMobileNaviService(sessionID);
+ verify(proxy.getSyncConnection(), times(1)).closeAudioService(sessionID);
+ verify(proxy.getSyncConnection(), times(1)).closeConnection(sessionID, true);
+ assertNotNull(proxy.getSyncConnection());
+ assertEquals("Service pool should be empty", 0, proxy.getServicePool().size());
+ assertEquals("Session id should be 0", 0, proxy.currentSession.getSessionId());
+ }
+
+ public void testSyncMsgVersionRequestSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ proxy.setSyncMsgVersionRequest(syncMsgVersion);
+ SyncMsgVersion real = proxy.getSyncMsgVersionRequest();
+ assertEquals("msg version should be equal", real, syncMsgVersion);
+ }
+
+ public void testApplicationNameSetTest() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ String name = "name";
+ proxy.setApplicationName(name);
+ String real = proxy.getApplicationName();
+ assertEquals("names should be the same", real, name);
+ }
+
+ public void testTtsNameSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ Vector<TTSChunk> ttsChunkVector = new Vector<TTSChunk>();
+ TTSChunk ttsChunk = new TTSChunk();
+ ttsChunk.setText("Text");
+ ttsChunkVector.add(ttsChunk);
+ proxy.setTTSName(ttsChunkVector);
+ Vector<TTSChunk> real = proxy.getTTSName();
+ assertEquals(real, ttsChunkVector);
+ }
+
+ public void testNgnMediaScreenAppNameSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ String mediaScreenName = "name";
+ proxy.setNgnMediaScreenAppName(mediaScreenName);
+ String real = proxy.getNgnMediaScreenAppName();
+ assertEquals(real, mediaScreenName);
+ }
+
+ public void testVrSynonymsSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ Vector<String> vrSynonums = new Vector<String>();
+ vrSynonums.add("name");
+ proxy.setVrSynonyms(vrSynonums);
+ Vector<String> real = proxy.getVrSynonyms();
+ assertEquals(real, vrSynonums);
+ }
+
+ public void testIsMediaAppSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ Boolean isMediaApp = false;
+ proxy.setIsMediApp(isMediaApp);
+ Boolean real = proxy.getIsMediaApp();
+ assertEquals(real, isMediaApp);
+ }
+
+ public void testSyncLanguageDesiredSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ Language language = Language.AR_SA;
+ proxy.setSyncLanguageDesired(language);
+ Language real = proxy.getSyncLanguageDesired();
+ assertEquals(real, language);
+ }
+
+ public void testHmiDisplayLanguageDesiredSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ Language language = Language.AR_SA;
+ proxy.setHmiDisplayLanguageDesired(language);
+ Language real = proxy.getHmiDisplayLanguageDesired();
+ assertEquals(real, language);
+ }
+
+ public void testAppHMITypeSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ Vector<AppHMIType> appHMITypeVector = new Vector<AppHMIType>();
+ appHMITypeVector.add(AppHMIType.DEFAULT);
+ proxy.setAppHMIType(appHMITypeVector);
+ Vector<AppHMIType> real = proxy.getAppHMIType();
+ assertEquals(real, appHMITypeVector);
+ }
+
+ public void testAppIDSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ String appID = "appID";
+ proxy.setAppID(appID);
+ String real = proxy.getAppID();
+ assertEquals(real, appID);
+ }
+
+ public void testAutoActivateIdDesiredSet() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ String autoActivateIdDesired = "_autoActivateIdDesired";
+ proxy.setAutoActivateIdReturned(autoActivateIdDesired);
+ String real = proxy.getAutoActivateIdReturned();
+ assertEquals(real, autoActivateIdDesired);
+ }
+
+ public void testSyncConnectionSessionIdIsSetToNullAfterStopSession() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ proxy.getInterfaceBroker().onProtocolSessionStarted(Session.createSession(ServiceType.RPC, sessionID), (byte) 2, "");
+ proxy.closeSession(true);
+ byte realSessionId = proxy.getSyncConnection().getSessionId();
+ assertEquals(0, realSessionId);
+ }
+
+ public void testUpdateRegisterAppInterfaceParametersChangesRegisterParameters() throws Exception {
+ SyncMsgVersion syncMsgVersion = new SyncMsgVersion();
+ syncMsgVersion.setMajorVersion(2);
+ syncMsgVersion.setMinorVersion(2);
+ Vector<TTSChunk> ttsChunkVector = new Vector<TTSChunk>();
+ TTSChunk ttsChunk = new TTSChunk();
+ ttsChunk.setText("Text");
+ ttsChunkVector.add(ttsChunk);
+ Vector<String> vrSynonyms = new Vector<String>();
+ vrSynonyms.add("name");
+ Vector<AppHMIType> appHMITypeVector = new Vector<AppHMIType>();
+ appHMITypeVector.add(AppHMIType.DEFAULT);
+
+ RegisterAppInterface msg = RPCRequestFactory.buildRegisterAppInterface(
+ syncMsgVersion, "appName", ttsChunkVector, "ngnMediaScreenAppName", vrSynonyms, true,
+ Language.AR_SA, Language.CS_CZ, appHMITypeVector, "appID", 1, null);
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ proxy.updateRegisterAppInterfaceParameters(msg);
+
+ assertEquals(syncMsgVersion, proxy.getSyncMsgVersionRequest());
+ assertEquals("appName", proxy.getApplicationName());
+ assertEquals(ttsChunkVector, proxy.getTTSName());
+ // screen app name length is limited
+ assertEquals("ngnMe", proxy.getNgnMediaScreenAppName());
+ assertEquals(vrSynonyms, proxy.getVrSynonyms());
+ assertEquals((Boolean) true, proxy.getIsMediaApp());
+ assertEquals(Language.AR_SA, proxy.getSyncLanguageDesired());
+ assertEquals( Language.CS_CZ, proxy.getHmiDisplayLanguageDesired());
+ assertEquals( appHMITypeVector, proxy.getAppHMIType());
+ assertEquals( "appID", proxy.getAppID());
+ }
+
+ public void testRPCMessageHandlerIsSetAfterCreation() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ IRPCMessageHandler messageHandler = proxy.getRPCMessageHandler();
+ assertNotNull("message handler should be not null", messageHandler);
+ }
+
+ public void testRPCMessageHandlerCalledOnIncomingMessage() throws Exception {
+ IProxyListenerALM proxyListenerMock = mock(IProxyListenerALM.class);
+ SyncProxyALM proxy =
+ TestCommon.getSyncProxyALMNoTransport(proxyListenerMock);
+ proxy.setRPCMessageHandler(mock(IRPCMessageHandler.class));
+ // send OnAppInterfaceUnregistered
+ Hashtable<String, Object> params = new Hashtable<String, Object>();
+ final AppInterfaceUnregisteredReason reason =
+ AppInterfaceUnregisteredReason.IGNITION_OFF;
+ params.put(Names.reason, reason);
+ proxy.dispatchIncomingMessage(TestCommon.createProtocolMessage(
+ Names.OnAppInterfaceUnregistered, params,
+ ProtocolMessage.RPCTYPE_NOTIFICATION, 1));
+ verify(proxy.getRPCMessageHandler(), times(1)).handleRPCMessage(any(Hashtable.class));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBase_OnSystemRequestTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBase_OnSystemRequestTest.java
new file mode 100644
index 000000000..39768d25e
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/SyncProxyBase_OnSystemRequestTest.java
@@ -0,0 +1,562 @@
+package com.ford.syncV4.proxy;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.exception.SyncException;
+import com.ford.syncV4.marshal.IJsonRPCMarshaller;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.MessageType;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.proxy.converter.IRPCRequestConverterFactory;
+import com.ford.syncV4.proxy.converter.SystemPutFileRPCRequestConverter;
+import com.ford.syncV4.proxy.interfaces.IProxyListenerALMTesting;
+import com.ford.syncV4.proxy.rpc.OnSystemRequest;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.FileType;
+import com.ford.syncV4.proxy.rpc.enums.RequestType;
+import com.ford.syncV4.proxy.systemrequest.IOnSystemRequestHandler;
+import com.ford.syncV4.proxy.systemrequest.ISystemRequestProxy;
+import com.ford.syncV4.syncConnection.SyncConnection;
+import com.ford.syncV4.util.TestConfig;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.mockito.ArgumentCaptor;
+
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Vector;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyListOf;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Matchers.notNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests how the SyncProxyALM handles OnSystemRequest notifications.
+ *
+ * Created by enikolsky on 2014-02-03.
+ */
+public class SyncProxyBase_OnSystemRequestTest extends InstrumentationTestCase {
+ private static final byte PROTOCOL_VERSION = (byte) 2;
+ private static final int PUTFILE_FUNCTIONID = 32;
+ private static final int ONSYSTEMREQUEST_FUNCTIONID = 32781;
+ private static final int WAIT_TIMEOUT = 20;
+ private static final String OFFSET = "offset";
+ private static final String LENGTH = "length";
+ private static final String SYNC_FILENAME = "syncFileName";
+ private static final String SYSTEM_FILE = "systemFile";
+ private static final String FILE_TYPE = "fileType";
+ private IProxyListenerALMTesting proxyListenerMock;
+ private WiProProtocol protocolMock;
+ private SyncConnection connectionMock;
+ private SyncProxyALM proxy;
+ private IOnSystemRequestHandler handlerMock;
+ private IJsonRPCMarshaller marshaller;
+ private int maxDataSize;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ proxyListenerMock = mock(IProxyListenerALMTesting.class);
+ protocolMock = mock(WiProProtocol.class);
+ connectionMock = createNewSyncConnectionMock();
+
+ proxy = new SyncProxyALM(proxyListenerMock, null, "a", null, null,
+ false, null, null, null, null, null, null, false, false, 2,
+ null, connectionMock, new TestConfig());
+ marshaller = proxy.getJsonRPCMarshaller();
+
+ handlerMock = mock(IOnSystemRequestHandler.class);
+
+ final SystemPutFileRPCRequestConverter converter =
+ new SystemPutFileRPCRequestConverter();
+ maxDataSize = 32;
+ converter.setMaxDataSize(maxDataSize);
+ IRPCRequestConverterFactory factoryMock =
+ mock(IRPCRequestConverterFactory.class);
+ when(factoryMock.getConverterForRequest(
+ notNull(RPCRequest.class))).thenReturn(converter);
+ proxy.setRpcRequestConverterFactory(factoryMock);
+ }
+
+ public void testDefaultSystemRequestHandlerShouldBeNull() {
+ assertThat(proxy.getOnSystemRequestHandler(), nullValue());
+ }
+
+ public void testGetOnSystemRequestHandlerShouldReturnSetValue() {
+ proxy.setOnSystemRequestHandler(handlerMock);
+ assertThat(proxy.getOnSystemRequestHandler(),
+ sameInstance(handlerMock));
+ }
+
+ public void testOnSystemRequestWithRequestTypeHTTPShouldCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final List<String> urls = Arrays.asList("http://example.com/");
+ final FileType fileType = FileType.GRAPHIC_PNG;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, times(1)).onFilesDownloadRequest(
+ notNull(ISystemRequestProxy.class), eq(urls), eq(fileType));
+ }
+
+ public void testOnSystemRequestWithRequestTypeHTTPWithoutUrlShouldNotCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final FileType fileType = FileType.GRAPHIC_PNG;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+ onSysRq.setFileType(fileType);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, never()).onFilesDownloadRequest(
+ any(ISystemRequestProxy.class), anyListOf(String.class),
+ any(FileType.class));
+ }
+
+ public void testOnSystemRequestWithRequestTypeHTTPWithoutFileTypeShouldCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final List<String> urls = Arrays.asList("http://example.com/");
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+ onSysRq.setUrl(new Vector<String>(urls));
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, times(1)).onFilesDownloadRequest(
+ notNull(ISystemRequestProxy.class), eq(urls),
+ isNull(FileType.class));
+ }
+
+ public void testOnSystemRequestWithRequestTypeHTTPShouldNotCallProxyListener()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final List<String> urls = Arrays.asList("http://example.com/");
+ final FileType fileType = FileType.GRAPHIC_PNG;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verifyZeroInteractions(proxyListenerMock);
+ }
+
+ public void testOnSystemRequestWithRequestTypeHTTPWithoutParametersShouldNotCallProxyListener()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verifyZeroInteractions(proxyListenerMock);
+ }
+
+ public void testOnSystemRequestWithRequestTypeHTTPShouldNotCrashWhenHandlerNotSet()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(null);
+
+ final List<String> urls = Arrays.asList("http://example.com/");
+ final FileType fileType = FileType.GRAPHIC_PNG;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.HTTP);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeShouldCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final String filename = "dummy";
+ final List<String> urls = Arrays.asList(filename);
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 4000;
+ final int length = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+ onSysRq.setOffset(offset);
+ onSysRq.setLength(length);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, times(1)).onFileResumeRequest(
+ notNull(ISystemRequestProxy.class), eq(filename), eq(offset),
+ eq(length), eq(fileType));
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeWithoutFilenameShouldNotCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 4000;
+ final int length = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setFileType(fileType);
+ onSysRq.setOffset(offset);
+ onSysRq.setLength(length);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, never()).onFileResumeRequest(
+ any(ISystemRequestProxy.class), anyString(), anyInt(), anyInt(),
+ any(FileType.class));
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeWithoutOffsetShouldNotCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final String filename = "dummy";
+ final List<String> urls = Arrays.asList(filename);
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int length = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setFileType(fileType);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setLength(length);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, never()).onFileResumeRequest(
+ any(ISystemRequestProxy.class), anyString(), anyInt(), anyInt(),
+ any(FileType.class));
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeWithoutLengthShouldNotCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final String filename = "dummy";
+ final List<String> urls = Arrays.asList(filename);
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setFileType(fileType);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setOffset(offset);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, never()).onFileResumeRequest(
+ any(ISystemRequestProxy.class), anyString(), anyInt(), anyInt(),
+ any(FileType.class));
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeWithoutFileTypeShouldCallHandler()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final String filename = "dummy";
+ final List<String> urls = Arrays.asList(filename);
+ final int offset = 4000;
+ final int length = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setOffset(offset);
+ onSysRq.setLength(length);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, times(1)).onFileResumeRequest(
+ notNull(ISystemRequestProxy.class), eq(filename), eq(offset),
+ eq(length), isNull(FileType.class));
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeShouldNotCallProxyListener()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final String filename = "dummy";
+ final List<String> urls = Arrays.asList(filename);
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 4000;
+ final int length = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+ onSysRq.setOffset(offset);
+ onSysRq.setLength(length);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verifyZeroInteractions(proxyListenerMock);
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeWithoutParametersShouldNotCallProxyListener()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verifyZeroInteractions(proxyListenerMock);
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeShouldNotCrashWhenHandlerNotSet()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(null);
+
+ final String filename = "dummy";
+ final List<String> urls = Arrays.asList(filename);
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 4000;
+ final int length = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+ onSysRq.setOffset(offset);
+ onSysRq.setLength(length);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+ }
+
+ public void testOnSystemRequestWithRequestTypeFileResumeMultipleFilenamesShouldCallHandlerOnce()
+ throws InterruptedException {
+ proxy.setOnSystemRequestHandler(handlerMock);
+
+ final String filename0 = "whatchamacallit";
+ final String filename1 = "thingamajig";
+ final String filename2 = "doohickey";
+ final List<String> urls =
+ Arrays.asList(filename0, filename1, filename2);
+ final FileType fileType = FileType.GRAPHIC_PNG;
+ final int offset = 4000;
+ final int length = 8800;
+
+ OnSystemRequest onSysRq = new OnSystemRequest();
+ onSysRq.setRequestType(RequestType.FILE_RESUME);
+ onSysRq.setUrl(new Vector<String>(urls));
+ onSysRq.setFileType(fileType);
+ onSysRq.setOffset(offset);
+ onSysRq.setLength(length);
+
+ ProtocolMessage pm = createNotificationProtocolMessage(onSysRq,
+ ONSYSTEMREQUEST_FUNCTIONID);
+ emulateIncomingMessage(proxy, pm);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ verify(handlerMock, times(1)).onFileResumeRequest(
+ notNull(ISystemRequestProxy.class), eq(filename0), eq(offset),
+ eq(length), eq(fileType));
+ }
+
+ public void testPutSystemFileShouldSendCorrectFirstProtocolMessage()
+ throws InterruptedException, JSONException, SyncException {
+ // fake data for PutFile
+ final int extraDataSize = 10;
+ final int dataSize = maxDataSize + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String filename = "file";
+ final FileType fileType = FileType.GRAPHIC_JPEG;
+ proxy.putSystemFile(filename, data, fileType);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the first part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(pmCaptor.capture());
+
+ final ProtocolMessage pm = pmCaptor.getValue();
+ assertThat(pm.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm.getData(), 0, maxDataSize, filename,
+ fileType);
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm.getBulkData(), is(data0));
+ }
+
+ public void testPutSystemFileWithOffsetShouldSendCorrectFirstProtocolMessage()
+ throws InterruptedException, JSONException, SyncException {
+ // fake data for PutFile
+ final int extraDataSize = 10;
+ final int dataSize = maxDataSize + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String filename = "file";
+ final FileType fileType = FileType.GRAPHIC_JPEG;
+ final int offset = 4000;
+ proxy.putSystemFile(filename, data, offset, fileType);
+
+ Thread.sleep(WAIT_TIMEOUT);
+
+ // expect the first part of PutFile to be sent
+ ArgumentCaptor<ProtocolMessage> pmCaptor =
+ ArgumentCaptor.forClass(ProtocolMessage.class);
+ verify(connectionMock, times(1)).sendMessage(pmCaptor.capture());
+
+ final ProtocolMessage pm = pmCaptor.getValue();
+ assertThat(pm.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ checkSystemPutFileJSON(pm.getData(), offset, maxDataSize, filename,
+ fileType);
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm.getBulkData(), is(data0));
+ }
+
+ // TODO other request types
+ // TODO check on main thread
+
+ private SyncConnection createNewSyncConnectionMock() {
+ SyncConnection connectionMock = mock(SyncConnection.class);
+ when(connectionMock.getIsConnected()).thenReturn(true);
+ when(connectionMock.getWiProProtocol()).thenReturn(protocolMock);
+ return connectionMock;
+ }
+
+ private ProtocolMessage createNotificationProtocolMessage(
+ RPCNotification notification, int functionID) {
+ ProtocolMessage incomingPM0 = new ProtocolMessage();
+ incomingPM0.setVersion(PROTOCOL_VERSION);
+ byte[] msgBytes = marshaller.marshall(notification, PROTOCOL_VERSION);
+ incomingPM0.setData(msgBytes);
+ incomingPM0.setJsonSize(msgBytes.length);
+ incomingPM0.setMessageType(MessageType.RPC);
+ incomingPM0.setSessionType(ServiceType.RPC);
+ incomingPM0.setFunctionID(functionID);
+ incomingPM0.setRPCType(ProtocolMessage.RPCTYPE_NOTIFICATION);
+ return incomingPM0;
+ }
+
+ private void emulateIncomingMessage(SyncProxyALM proxy,
+ ProtocolMessage pm) {
+ // synchronous:
+// proxy.dispatchIncomingMessage(pm);
+ // asynchronous, more correct:
+ proxy.getInterfaceBroker().onProtocolMessageReceived(pm);
+ }
+
+ private void checkSystemPutFileJSON(byte[] data, int offset, int length,
+ String filename, FileType fileType)
+ throws JSONException {
+ assertThat("JSON data must not be null", data, notNullValue());
+
+ JSONObject jsonObject =
+ new JSONObject(new String(data, Charset.defaultCharset()));
+ assertThat("offset doesn't match", jsonObject.getInt(OFFSET),
+ is(offset));
+ assertThat("length doesn't match", jsonObject.getInt(LENGTH),
+ is(length));
+ assertThat("filename must be set", jsonObject.getString(SYNC_FILENAME),
+ is(filename));
+ assertThat("systemFile must be true",
+ jsonObject.getBoolean(SYSTEM_FILE), is(true));
+ assertThat("fileType must be set", jsonObject.getString(FILE_TYPE),
+ is(fileType.toString()));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/DefaultRPCRequestConverterTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/DefaultRPCRequestConverterTest.java
new file mode 100644
index 000000000..2487ec8a1
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/DefaultRPCRequestConverterTest.java
@@ -0,0 +1,263 @@
+package com.ford.syncV4.proxy.converter;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.marshal.JsonRPCMarshaller;
+import com.ford.syncV4.protocol.IProtocolListener;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.MessageType;
+import com.ford.syncV4.proxy.RPCRequestFactory;
+import com.ford.syncV4.proxy.rpc.PutFile;
+import com.ford.syncV4.proxy.rpc.Show;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.TextAlignment;
+
+import org.hamcrest.core.IsNull;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.nio.charset.Charset;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Tests for DefaultRPCRequestConverter class.
+ *
+ * Created by enikolsky on 2014-01-21.
+ */
+public class DefaultRPCRequestConverterTest extends InstrumentationTestCase {
+ private static final byte PROTOCOL_VERSION = (byte) 2;
+ private static final int PUTFILE_FUNCTIONID = 32;
+ private static final String OFFSET = "offset";
+ private static final String LENGTH = "length";
+ private static final String NUMBER_OF_OBJECTS_IS_INCORRECT =
+ "Number of objects is incorrect";
+ private DefaultRPCRequestConverter converter;
+ private JsonRPCMarshaller marshaller;
+ private int maxDataSize;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ converter = new DefaultRPCRequestConverter();
+ marshaller = new JsonRPCMarshaller();
+
+ WiProProtocol protocol =
+ new WiProProtocol(mock(IProtocolListener.class));
+ protocol.setVersion(PROTOCOL_VERSION);
+ maxDataSize = WiProProtocol.MAX_DATA_SIZE;
+ }
+
+ public void testGetProtocolMessagesForShowShouldReturnCorrectProtocolMessage()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ Show msg = new Show();
+ msg.setAlignment(TextAlignment.CENTERED);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(protocolMessages.size(), is(1));
+
+ ProtocolMessage pm = protocolMessages.get(0);
+ assertThat(pm.getData(), notNullValue());
+ assertThat(pm.getData().length, greaterThan(0));
+ assertThat(pm.getSessionID(), is(sessionID));
+ assertThat(pm.getMessageType(), is(MessageType.RPC));
+ assertThat(pm.getFunctionID(), is(13));
+ assertThat(pm.getCorrID(), is(correlationID));
+ assertThat(pm.getBulkData(), nullValue());
+ }
+
+ public void testGetProtocolMessagesForSmallPutFileShouldReturnCorrectProtocolMessage()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+ final byte[] data = TestCommon.getRandomBytes(32);
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setSyncFileName("file");
+ msg.setBulkData(data);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ ProtocolMessage pm = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm);
+ assertThat(pm.getData(), IsNull.notNullValue());
+ assertThat(pm.getJsonSize(), greaterThan(0));
+ assertThat(pm.getSessionID(), is(sessionID));
+ assertThat(pm.getCorrID(), is(correlationID));
+ assertThat(pm.getBulkData(), is(data));
+ }
+
+ // or should it?
+ public void testGetProtocolMessagesForPutFileWithoutBulkDataShouldReturnCorrectProtocolMessage()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setSyncFileName("file");
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ ProtocolMessage pm = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm);
+ assertThat(pm.getData(), notNullValue());
+ assertThat(pm.getJsonSize(), greaterThan(0));
+ assertThat(pm.getSessionID(), is(sessionID));
+ assertThat(pm.getCorrID(), is(correlationID));
+ assertThat(pm.getBulkData(), nullValue());
+ }
+
+ public void testMediumPutFileShouldNotBeSplitIntoTwoProtocolMessages()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ final int extraDataSize = 10;
+ final int dataSize = maxDataSize + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ ProtocolMessage pm0 = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm0);
+ final byte[] json0 = pm0.getData();
+ checkNoOffsetAndLengthInJSON(json0);
+ assertThat(pm0.getJsonSize(), is(json0.length));
+ assertThat(pm0.getSessionID(), is(sessionID));
+ assertThat(pm0.getCorrID(), is(correlationID));
+ assertThat(pm0.getBulkData(), is(data));
+ }
+
+ // check a corner case when "data size" == "max data size" * N
+ public void testPutFileWithDivisibleBulkDataSizeShouldNotBeSplitIntoTwoProtocolMessages()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ final int dataSize = maxDataSize * 2;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ ProtocolMessage pm0 = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm0);
+ final byte[] json0 = pm0.getData();
+ checkNoOffsetAndLengthInJSON(json0);
+ assertThat(pm0.getJsonSize(), is(json0.length));
+ assertThat(pm0.getSessionID(), is(sessionID));
+ assertThat(pm0.getCorrID(), is(correlationID));
+ assertThat(pm0.getBulkData(), is(data));
+ }
+
+ public void testBigPutFileShouldNotBeSplitIntoMultipleProtocolMessages()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ final int dataCopies = 12;
+ final int extraDataSize = 20;
+ final int dataSize = (maxDataSize * dataCopies) + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ final ProtocolMessage pm = protocolMessages.get(0);
+ final byte[] json = pm.getData();
+ checkNoOffsetAndLengthInJSON(json);
+ assertThat(pm.getBulkData(), is(data));
+ }
+
+ public void testGetProtocolMessagesShouldThrowNullPointerExceptionWhenRequestIsNull() {
+ try {
+ converter.getProtocolMessages(null, (byte) 0, marshaller,
+ PROTOCOL_VERSION);
+ fail("Should have thrown NullPointerException");
+ } catch (NullPointerException e) {
+ // success
+ }
+ }
+
+ public void testGetProtocolMessagesShouldThrowNullPointerExceptionWhenMarshallerIsNull() {
+ try {
+ Show msg = new Show();
+
+ converter.getProtocolMessages(msg, (byte) 0, null,
+ PROTOCOL_VERSION);
+ fail("Should have thrown NullPointerException");
+ } catch (NullPointerException e) {
+ // success
+ }
+ }
+
+ private void commonPutFileProtocolMessageAsserts(
+ ProtocolMessage protocolMessage) {
+ assertThat(protocolMessage.getVersion(), is(PROTOCOL_VERSION));
+ assertThat(protocolMessage.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ assertThat(protocolMessage.getMessageType(), is(MessageType.RPC));
+ }
+
+ private void checkNoOffsetAndLengthInJSON(byte[] data)
+ throws JSONException {
+ assertThat(data, notNullValue());
+
+ JSONObject jsonObject =
+ new JSONObject(new String(data, Charset.defaultCharset()));
+ assertThat(jsonObject.has(OFFSET), is(false));
+ assertThat(jsonObject.has(LENGTH), is(false));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SyncRPCRequestConverterFactoryTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SyncRPCRequestConverterFactoryTest.java
new file mode 100644
index 000000000..731f029ed
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SyncRPCRequestConverterFactoryTest.java
@@ -0,0 +1,96 @@
+package com.ford.syncV4.proxy.converter;
+
+import com.ford.syncV4.proxy.RPCRequest;
+import com.ford.syncV4.proxy.RPCRequestFactory;
+import com.ford.syncV4.proxy.rpc.PutFile;
+import com.ford.syncV4.proxy.rpc.Show;
+
+import junit.framework.TestCase;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Tests for SyncRPCRequestConverterFactory class.
+ *
+ * Created by enikolsky on 2014-01-21.
+ */
+public class SyncRPCRequestConverterFactoryTest extends TestCase {
+ private SyncRPCRequestConverterFactory factory;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ factory = new SyncRPCRequestConverterFactory();
+ }
+
+ public void testGetConverterShouldReturnDefaultConverterForUnknownRequest() {
+ AwesomeRequest msg = new AwesomeRequest();
+ assertThat(factory.getConverterForRequest(msg),
+ instanceOf(DefaultRPCRequestConverter.class));
+ }
+
+ public void testGetConverterShouldReturnDefaultConverterForKnownRequest() {
+ Show msg = new Show();
+ assertThat(factory.getConverterForRequest(msg),
+ instanceOf(DefaultRPCRequestConverter.class));
+ }
+
+ public void testGetConverterShouldReturnDefaultConverterForDefaultPutFile() {
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ assertThat(factory.getConverterForRequest(msg),
+ instanceOf(DefaultRPCRequestConverter.class));
+ }
+
+ public void testGetConverterShouldReturnDefaultConverterForNotSystemPutFile() {
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setSystemFile(false);
+ assertThat(factory.getConverterForRequest(msg),
+ instanceOf(DefaultRPCRequestConverter.class));
+ }
+
+ public void testGetConverterShouldReturnSystemPutFileConverterForSystemPutFile() {
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setSystemFile(true);
+ assertThat(factory.getConverterForRequest(msg),
+ instanceOf(SystemPutFileRPCRequestConverter.class));
+ }
+
+ public void testGetConverterShouldCacheDefaultConverterForKnownRequest() {
+ final RPCRequest msg = new Show();
+ final IRPCRequestConverter converter =
+ factory.getConverterForRequest(msg);
+ assertThat(factory.getConverterForRequest(msg),
+ sameInstance(converter));
+ }
+
+ public void testGetConverterShouldCacheSystemPutFileConverter() {
+ final PutFile msg1 = RPCRequestFactory.buildPutFile();
+ msg1.setSystemFile(true);
+
+ final PutFile msg2 = RPCRequestFactory.buildPutFile();
+ msg2.setSystemFile(true);
+
+ final IRPCRequestConverter converter =
+ factory.getConverterForRequest(msg1);
+ assertThat("SystemPutFileRPCRequestConverter isn't cached",
+ factory.getConverterForRequest(msg2), sameInstance(converter));
+ }
+
+ public void testGetConverterShouldThrowNullPointerExceptionWhenRequestIsNull() {
+ try {
+ factory.getConverterForRequest(null);
+ fail("Should have thrown NullPointerException");
+ } catch (NullPointerException e) {
+ // success
+ }
+ }
+
+ private class AwesomeRequest extends RPCRequest {
+ public AwesomeRequest() {
+ super("AwesomeRequest");
+ }
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SystemPutFileRPCRequestConverterTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SystemPutFileRPCRequestConverterTest.java
new file mode 100644
index 000000000..bd0f0a832
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/converter/SystemPutFileRPCRequestConverterTest.java
@@ -0,0 +1,377 @@
+package com.ford.syncV4.proxy.converter;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.marshal.JsonRPCMarshaller;
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.enums.MessageType;
+import com.ford.syncV4.proxy.RPCRequestFactory;
+import com.ford.syncV4.proxy.rpc.PutFile;
+import com.ford.syncV4.proxy.rpc.Show;
+import com.ford.syncV4.proxy.rpc.TestCommon;
+import com.ford.syncV4.proxy.rpc.enums.FileType;
+
+import org.hamcrest.MatcherAssert;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+
+/**
+ * Tests for SystemPutFileRPCRequestConverter class.
+ *
+ * Created by enikolsky on 2014-01-21.
+ */
+public class SystemPutFileRPCRequestConverterTest
+ extends InstrumentationTestCase {
+ private static final byte PROTOCOL_VERSION = (byte) 2;
+ private static final int PUTFILE_FUNCTIONID = 32;
+ private static final String NUMBER_OF_OBJECTS_IS_INCORRECT =
+ "Number of objects is incorrect";
+ private static final String OFFSET = "offset";
+ private static final String LENGTH = "length";
+ private static final String SYNC_FILENAME = "syncFileName";
+ private static final String SYSTEM_FILE = "systemFile";
+ private static final String FILE_TYPE = "fileType";
+ private SystemPutFileRPCRequestConverter converter;
+ private JsonRPCMarshaller marshaller;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ TestCommon.setupMocking(this);
+
+ converter = new SystemPutFileRPCRequestConverter();
+ marshaller = new JsonRPCMarshaller();
+ }
+
+ public void testDefaultMaxDataSizeShouldBeLargeEnough() {
+ // how much large is enough?
+ final int minMaxDataSize = 10000;
+
+ MatcherAssert.assertThat(converter.getMaxDataSize(),
+ greaterThanOrEqualTo(minMaxDataSize));
+ }
+
+ public void testGetProtocolMessagesShouldReturnEmptyListIfRequestIsNotPutFile() {
+ assertThat(
+ converter.getProtocolMessages(new Show(), (byte) 0, marshaller,
+ PROTOCOL_VERSION).size(), is(0));
+ }
+
+ public void testGetProtocolMessagesForSmallPutFileShouldReturnCorrectProtocolMessage()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+ final byte[] data = TestCommon.getRandomBytes(32);
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setSyncFileName("file");
+ msg.setBulkData(data);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ ProtocolMessage pm = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm);
+ assertThat(pm.getData(), notNullValue());
+ assertThat(pm.getJsonSize(), greaterThan(0));
+ assertThat(pm.getSessionID(), is(sessionID));
+ assertThat(pm.getCorrID(), is(correlationID));
+ assertThat(pm.getBulkData(), is(data));
+ }
+
+ // or should it?
+ public void testGetProtocolMessagesForPutFileWithoutBulkDataShouldReturnCorrectProtocolMessage()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setSyncFileName("file");
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ ProtocolMessage pm = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm);
+ assertThat(pm.getData(), notNullValue());
+ assertThat(pm.getJsonSize(), greaterThan(0));
+ assertThat(pm.getSessionID(), is(sessionID));
+ assertThat(pm.getCorrID(), is(correlationID));
+ assertThat(pm.getBulkData(), nullValue());
+ }
+
+ public void testMediumPutFileShouldBeSplitIntoTwoProtocolMessages()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ converter.setMaxDataSize(100);
+
+ final int extraDataSize = 10;
+ final int maxDataSize = converter.getMaxDataSize();
+ final int dataSize = maxDataSize + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String fileName = "file2";
+ final FileType fileType = FileType.AUDIO_MP3;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setSyncFileName(fileName);
+ msg.setFileType(fileType);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(2));
+
+ ProtocolMessage pm0 = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm0);
+ final byte[] json0 = pm0.getData();
+ checkSystemPutFileJSON(json0, 0, maxDataSize, fileName, fileType);
+ assertThat(pm0.getJsonSize(), is(json0.length));
+ assertThat(pm0.getSessionID(), is(sessionID));
+ assertThat(pm0.getCorrID(), is(correlationID));
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm0.getBulkData(), is(data0));
+
+ ProtocolMessage pm1 = protocolMessages.get(1);
+ commonPutFileProtocolMessageAsserts(pm1);
+ final byte[] json1 = pm1.getData();
+ checkSystemPutFileJSON(json1, maxDataSize, dataSize - maxDataSize,
+ fileName, fileType);
+ assertThat(pm1.getJsonSize(), is(json1.length));
+ assertThat(pm1.getSessionID(), is(sessionID));
+ assertThat(pm1.getCorrID(), is(correlationID));
+ final byte[] data1 = Arrays.copyOfRange(data, maxDataSize, dataSize);
+ assertThat(pm1.getBulkData(), is(data1));
+ }
+
+ // check a corner case when "data size" == "max data size" * N
+ public void testPutFileWithDivisibleBulkDataSizeShouldBeSplitIntoTwoProtocolMessages()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ converter.setMaxDataSize(100);
+
+ final int maxDataSize = converter.getMaxDataSize();
+ final int N = 2;
+ final int dataSize = maxDataSize * N;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String fileName = "file2";
+ final FileType fileType = FileType.AUDIO_MP3;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setSyncFileName(fileName);
+ msg.setFileType(fileType);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(2));
+
+ ProtocolMessage pm0 = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm0);
+ final byte[] json0 = pm0.getData();
+ checkSystemPutFileJSON(json0, 0, maxDataSize, fileName, fileType);
+ assertThat(pm0.getJsonSize(), is(json0.length));
+ assertThat(pm0.getSessionID(), is(sessionID));
+ assertThat(pm0.getCorrID(), is(correlationID));
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm0.getBulkData(), is(data0));
+
+ ProtocolMessage pm1 = protocolMessages.get(1);
+ commonPutFileProtocolMessageAsserts(pm1);
+ final byte[] json1 = pm1.getData();
+ checkSystemPutFileJSON(json1, maxDataSize, dataSize - maxDataSize,
+ fileName, fileType);
+ assertThat(pm1.getJsonSize(), is(json1.length));
+ assertThat(pm1.getSessionID(), is(sessionID));
+ assertThat(pm1.getCorrID(), is(correlationID));
+ final byte[] data1 = Arrays.copyOfRange(data, maxDataSize, dataSize);
+ assertThat(pm1.getBulkData(), is(data1));
+ }
+
+ public void testBigPutFileShouldBeSplitIntoMultipleProtocolMessages()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ final int maxDataSize = converter.getMaxDataSize();
+ final int dataCopies = 12;
+ final int extraDataSize = 20;
+ final int dataSize = (maxDataSize * dataCopies) + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String fileName = "file2";
+ final FileType fileType = FileType.AUDIO_MP3;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setSyncFileName(fileName);
+ msg.setFileType(fileType);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(dataCopies + 1));
+
+ for (int i = 0; i < dataCopies; ++i) {
+ final ProtocolMessage pm = protocolMessages.get(i);
+ final byte[] json = pm.getData();
+ checkSystemPutFileJSON(json, i * maxDataSize, maxDataSize, fileName,
+ fileType);
+ }
+
+ final ProtocolMessage pm = protocolMessages.get(dataCopies);
+ final byte[] json = pm.getData();
+ checkSystemPutFileJSON(json, dataCopies * maxDataSize, extraDataSize,
+ fileName, fileType);
+ }
+
+ public void testGetProtocolMessagesForSmallPutFileWithOffsetShouldReturnCorrectProtocolMessage()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+ final byte[] data = TestCommon.getRandomBytes(32);
+
+ final int offset = 4000;
+ final String fileName = "file";
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setSyncFileName(fileName);
+ msg.setBulkData(data);
+ msg.setOffset(offset);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(1));
+
+ ProtocolMessage pm = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm);
+ final byte[] data1 = pm.getData();
+ checkSystemPutFileJSON(data1, offset, data.length, fileName, null);
+ assertThat(pm.getJsonSize(), is(data1.length));
+ assertThat(pm.getSessionID(), is(sessionID));
+ assertThat(pm.getCorrID(), is(correlationID));
+ assertThat(pm.getBulkData(), is(data));
+ }
+
+ public void testMediumPutFileWithOffsetShouldBeSplitIntoTwoProtocolMessages()
+ throws Exception {
+ final int correlationID = 1;
+ final byte sessionID = (byte) 0;
+
+ converter.setMaxDataSize(100);
+
+ final int extraDataSize = 10;
+ final int maxDataSize = converter.getMaxDataSize();
+ final int dataSize = maxDataSize + extraDataSize;
+ final byte[] data = TestCommon.getRandomBytes(dataSize);
+
+ final String fileName = "file2";
+ final FileType fileType = FileType.AUDIO_MP3;
+ final int offset = 4000;
+
+ PutFile msg = RPCRequestFactory.buildPutFile();
+ msg.setBulkData(data);
+ msg.setSyncFileName(fileName);
+ msg.setFileType(fileType);
+ msg.setOffset(offset);
+ msg.setCorrelationID(correlationID);
+
+ final List<ProtocolMessage> protocolMessages =
+ converter.getProtocolMessages(msg, sessionID, marshaller,
+ PROTOCOL_VERSION);
+
+ assertThat(NUMBER_OF_OBJECTS_IS_INCORRECT, protocolMessages.size(),
+ is(2));
+
+ ProtocolMessage pm0 = protocolMessages.get(0);
+ commonPutFileProtocolMessageAsserts(pm0);
+ final byte[] json0 = pm0.getData();
+ checkSystemPutFileJSON(json0, offset, maxDataSize, fileName, fileType);
+ assertThat(pm0.getJsonSize(), is(json0.length));
+ assertThat(pm0.getSessionID(), is(sessionID));
+ assertThat(pm0.getCorrID(), is(correlationID));
+ final byte[] data0 = Arrays.copyOfRange(data, 0, maxDataSize);
+ assertThat(pm0.getBulkData(), is(data0));
+
+ ProtocolMessage pm1 = protocolMessages.get(1);
+ commonPutFileProtocolMessageAsserts(pm1);
+ final byte[] json1 = pm1.getData();
+ checkSystemPutFileJSON(json1, offset + maxDataSize,
+ dataSize - maxDataSize, fileName, fileType);
+ assertThat(pm1.getJsonSize(), is(json1.length));
+ assertThat(pm1.getSessionID(), is(sessionID));
+ assertThat(pm1.getCorrID(), is(correlationID));
+ final byte[] data1 = Arrays.copyOfRange(data, maxDataSize, dataSize);
+ assertThat(pm1.getBulkData(), is(data1));
+ }
+
+ private void checkSystemPutFileJSON(byte[] data, int offset, int length,
+ String filename, FileType fileType)
+ throws JSONException {
+ assertThat("JSON data must not be null", data, notNullValue());
+
+ JSONObject jsonObject =
+ new JSONObject(new String(data, Charset.defaultCharset()));
+ assertThat("offset doesn't match", jsonObject.getInt(OFFSET),
+ is(offset));
+ assertThat("length doesn't match", jsonObject.getInt(LENGTH),
+ is(length));
+ assertThat("filename must be set", jsonObject.getString(SYNC_FILENAME),
+ is(filename));
+ assertThat("systemFile must be true",
+ jsonObject.getBoolean(SYSTEM_FILE), is(true));
+
+ if (fileType != null) {
+ assertThat("fileType must be set", jsonObject.getString(FILE_TYPE),
+ is(fileType.toString()));
+ }
+ }
+
+ private void commonPutFileProtocolMessageAsserts(
+ ProtocolMessage protocolMessage) {
+ assertThat(protocolMessage.getVersion(), is(PROTOCOL_VERSION));
+ assertThat(protocolMessage.getFunctionID(), is(PUTFILE_FUNCTIONID));
+ assertThat(protocolMessage.getMessageType(), is(MessageType.RPC));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/enums/GlobalPropertyTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/enums/GlobalPropertyTest.java
new file mode 100644
index 000000000..3f44e0138
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/enums/GlobalPropertyTest.java
@@ -0,0 +1,39 @@
+package com.ford.syncV4.proxy.enums;
+
+import android.test.AndroidTestCase;
+
+import com.ford.syncV4.proxy.rpc.enums.GlobalProperty;
+
+/**
+ * Created by Andrew Batutin on 11/18/13.
+ */
+public class GlobalPropertyTest extends AndroidTestCase {
+
+ public void testGlobalPropertiesEnumHasHelppromtValue() throws Exception {
+ assertNotNull("", GlobalProperty.HELPPROMPT);
+ }
+
+ public void testGlobalPropertiesEnumHasTimeoutpromtValue() throws Exception {
+ assertNotNull("", GlobalProperty.TIMEOUTPROMPT);
+ }
+
+ public void testGlobalPropertiesEnumHasVrhelptitleValue() throws Exception {
+ assertNotNull("", GlobalProperty.VRHELPTITLE);
+ }
+
+ public void testGlobalPropertiesEnumHasVrhelpitemsValue() throws Exception {
+ assertNotNull("", GlobalProperty.VRHELPITEMS);
+ }
+
+ public void testGlobalPropertiesEnumHasMenunameValue() throws Exception {
+ assertNotNull("", GlobalProperty.MENUNAME);
+ }
+
+ public void testGlobalPropertiesEnumHasMenuiconValue() throws Exception {
+ assertNotNull("", GlobalProperty.MENUICON);
+ }
+
+ public void testGlobalPropertiesEnumHasKeyboardpropertiesValue() throws Exception {
+ assertNotNull("", GlobalProperty.KEYBOARDPROPERTIES);
+ }
+}
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
+ }
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/session/MobileNavSessionTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/session/MobileNavSessionTest.java
new file mode 100644
index 000000000..8ac2e38e9
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/proxy/session/MobileNavSessionTest.java
@@ -0,0 +1,52 @@
+package com.ford.syncV4.proxy.session;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.session.Session;
+
+import org.mockito.Mockito;
+
+import static org.mockito.Mockito.mock;
+
+
+/**
+ * Created by Andrew Batutin on 8/20/13.
+ */
+public class MobileNavSessionTest extends InstrumentationTestCase{
+
+ MobileNavSession _sut;
+ private WiProProtocol _protocol;
+
+ public MobileNavSessionTest() {
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());
+ _protocol = createMockWiProProtocol();
+ _sut = new MobileNavSession(_protocol);
+ }
+
+ private WiProProtocol createMockWiProProtocol(){
+ WiProProtocol wiProProtocol = mock(WiProProtocol.class);
+ Session session = new Session();
+ session.setSessionId((byte) 0x01);
+ Mockito.doThrow(new IllegalArgumentException("Can't call this method")).when(wiProProtocol).StartProtocolService(ServiceType.Mobile_Nav, session);
+ return wiProProtocol;
+ }
+
+ public void testMobileNavigationSessionCreation() throws Exception {
+ MobileNavSession mobileNavSessionSession = new MobileNavSession(_protocol);
+ assertNotNull("mobile Nav currentSession should be created", mobileNavSessionSession);
+ }
+
+ public void testMobileNavigationStartSession() throws Exception {
+ Session session = new Session();
+ session.setSessionId((byte)0x0A);
+ _sut.startSession(session);
+ assertTrue("should get here",true);
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/service/ServiceTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/service/ServiceTest.java
new file mode 100644
index 000000000..a4821e8a9
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/service/ServiceTest.java
@@ -0,0 +1,31 @@
+package com.ford.syncV4.service;
+
+import android.test.AndroidTestCase;
+
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.session.Session;
+
+/**
+ * Created by Andrew Batutin on 1/21/14.
+ */
+public class ServiceTest extends AndroidTestCase {
+
+ public void testServiceWasCreated() throws Exception {
+ Service service = new Service();
+ assertNotNull(service);
+ }
+
+ public void testServiceIdIsSet() throws Exception {
+ Service service = new Service();
+ Session session = new Session();
+ service.setSession(session);
+ assertEquals("service id should be 1", session, service.getSession());
+ }
+
+ public void testServiceTypeIsSet() throws Exception {
+ Service service = new Service();
+ service.setServiceType(ServiceType.RPC);
+ ServiceType serviceType = service.getServiceType();
+ assertEquals("Service type should be RPC", ServiceType.RPC, serviceType);
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/session/SessionTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/session/SessionTest.java
new file mode 100644
index 000000000..8aa965682
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/session/SessionTest.java
@@ -0,0 +1,100 @@
+package com.ford.syncV4.session;
+
+import android.test.AndroidTestCase;
+
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.service.Service;
+
+import java.util.List;
+
+/**
+ * Created by Andrew Batutin on 1/21/14.
+ */
+public class SessionTest extends AndroidTestCase{
+
+ public void testSessionIsCreated() throws Exception {
+ Session session = new Session();
+ assertNotNull("currentSession object should be created",session);
+ }
+
+ public void testSessionIdShouldBeSet() throws Exception {
+ Session session = new Session();
+ session.setSessionId((byte)1);
+ assertEquals("currentSession id should be 1", (byte)1, session.getSessionId());
+ }
+
+ public void testServiceAddedToServiceList() throws Exception {
+ Session session = new Session();
+ Service service = new Service();
+ session.addService(service);
+ List<Service> services = session.getServiceList();
+ assertEquals("service should be at list",service, services.get(0));
+ }
+
+ public void testServiceRemovedFromServiceList() throws Exception {
+ Session session = new Session();
+ Service service = new Service();
+ session.addService(service);
+ boolean res = session.removeService(service);
+ assertTrue("element should be removed", res);
+ assertEquals("service list should be empty",0, session.getServiceList().size());
+ }
+
+ public void testInitialSessionCreationCreatesRPCService() throws Exception {
+ Session session = Session.createSession(ServiceType.RPC, (byte) 0);
+ Service service = session.getServiceList().get(0);
+ assertEquals("currentSession id should be SESSION_ID", (byte) 0, session.getSessionId());
+ assertEquals("should be RPC service", ServiceType.RPC, service.getServiceType());
+ assertEquals("service should belong to the currentSession", session, service.getSession());
+ }
+
+ public void testRemoveServiceRemovesService() throws Exception {
+ Session session = Session.createSession(ServiceType.RPC, (byte) 0);
+ Service service = new Service();
+ service.setSession(session);
+ service.setServiceType(ServiceType.RPC);
+ assertTrue("service should be removed", session.removeService(service));
+ }
+
+ public void testStopSessionClearsServiceList() throws Exception {
+ Session session = Session.createSession(ServiceType.RPC, (byte) 10);
+ session.stopSession();
+ assertEquals("service list should be 0", 0, session.getServiceList().size());
+ assertEquals("session id should be 0",0, session.getSessionId());
+ }
+
+ public void testEmptyServicesList() {
+ Session session = new Session();
+ assertTrue(session.isServicesEmpty());
+ }
+
+ public void testEmptyServicesListWithNonEmptyList() {
+ Session session = new Session();
+ session.addService(session.createService(ServiceType.Audio_Service));
+ assertFalse(session.isServicesEmpty());
+ }
+
+ public void testHasServiceByCorrectType() {
+ Session session = new Session();
+ Service service = session.createService(ServiceType.Audio_Service);
+ session.addService(service);
+ assertTrue(session.hasService(ServiceType.Audio_Service));
+ }
+
+ public void testHasServiceByIncorrectType() {
+ Session session = new Session();
+ session.createService(ServiceType.Audio_Service);
+ assertFalse(session.hasService(ServiceType.Mobile_Nav));
+ }
+
+ public void testPreventAddServiceWithSameType() {
+ Session session = new Session();
+ Service service_A = session.createService(ServiceType.Audio_Service);
+ Service service_B = session.createService(ServiceType.Audio_Service);
+ Service service_C = session.createService(ServiceType.Audio_Service);
+ session.addService(service_A);
+ session.addService(service_B);
+ session.addService(service_C);
+ assertEquals(1, session.getServicesNumber());
+ }
+} \ No newline at end of file
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/H264PacketizerTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/H264PacketizerTest.java
new file mode 100644
index 000000000..c99ffcba6
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/H264PacketizerTest.java
@@ -0,0 +1,325 @@
+package com.ford.syncV4.streaming;
+
+import android.test.AndroidTestCase;
+
+import com.ford.syncV4.protocol.ProtocolMessage;
+import com.ford.syncV4.protocol.enums.ServiceType;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Random;
+import java.util.TreeMap;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * Created by Andrew Batutin on 9/30/13.
+ */
+
+public class H264PacketizerTest extends AndroidTestCase {
+
+ private H264Packetizer sut;
+ private PipedInputStream inputStream;
+ private PipedOutputStream outputStream;
+ private ByteBuffer buffer;
+ private byte[] sampleData;
+
+ private static byte[] combine(byte[] a, byte[] b) {
+ int length = a.length + b.length;
+ byte[] result = new byte[length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+ return result;
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ inputStream = new PipedInputStream();
+ outputStream = new PipedOutputStream();
+ inputStream.connect(outputStream);
+ sut = new H264Packetizer(null, inputStream, (byte) 0, ServiceType.Mobile_Nav);
+ sampleData = generateRandomBytes(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ buffer = ByteBuffer.allocate(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ }
+
+ private byte[] generateRandomBytes(int size) {
+ Random random = new Random(47);
+ byte[] data = new byte[size];
+ random.nextBytes(data);
+ return data;
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ inputStream.close();
+ outputStream.close();
+ }
+
+ public void testPacketizerWasCreated() throws Exception {
+ assertNotNull(sut);
+ }
+
+ public void testFixDataSizeFrameWasCreated() throws Exception {
+ outputStream.write(sampleData);
+ byte[] data = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE", Arrays.equals(sampleData, data));
+ }
+
+ public void testFixDataSizeFrameWasCreatedAfterTwoInputs() throws Exception {
+ byte[] data1 = generateRandomBytes(500);
+ outputStream.write(data1);
+ byte[] data2 = generateRandomBytes(500);
+ outputStream.write(data2);
+ byte[] combined = combine(data1, data2);
+ byte[] frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE; frame.length = " + frame.length, Arrays.equals(combined, frame));
+ }
+
+ public void testFixDataSizeFrameWasCreatedAfterShortInput() throws Exception {
+ byte[] data1 = generateRandomBytes(500);
+ outputStream.write(data1);
+ outputStream.close();
+ byte[] frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to 500; frame.length = " + frame.length, Arrays.equals(data1, frame));
+ }
+
+ public void testFixDataSizeFrameWasCreatedAfterInputMoreThanMOBILE_NAVI_DATA_SIZE() throws Exception {
+ byte[] data1 = generateRandomBytes(500);
+ byte[] data2 = generateRandomBytes(10);
+ outputStream.write(data1);
+ outputStream.write(data1);
+ outputStream.write(data2);
+ outputStream.close();
+ byte[] combined = combine(data1, data1);
+ byte[] frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE; frame.length = " + frame.length, Arrays.equals(combined, frame));
+ }
+
+ public void test2FixDataSizeFramesWereCreatedAfter1000_1010DataInput() throws Exception {
+ byte[] data1 = generateRandomBytes(500);
+ byte[] data2 = generateRandomBytes(10);
+ outputStream.write(data1);
+ outputStream.write(data1);
+ byte[] combined = combine(data1, data1);
+ byte[] frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE; frame.length = " + frame.length, Arrays.equals(combined, frame));
+ outputStream.write(data1);
+ outputStream.write(data1);
+ outputStream.write(data2);
+ combined = combine(data1, data1);
+ frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE; frame.length = " + frame.length, Arrays.equals(combined, frame));
+ outputStream.close();
+ frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to 10; frame.length = " + frame.length, Arrays.equals(data2, frame));
+ }
+
+ public void test3FixDataSizeFramesWereCreatedAfter1000_1010_1010DataInput() throws Exception {
+ byte[] data1 = generateRandomBytes(500);
+ byte[] data2 = generateRandomBytes(10);
+ byte[] combined = combine(data1, data1);
+ outputStream.write(data1);
+ outputStream.write(data1);
+ byte[] frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE; frame.length = " + frame.length, Arrays.equals(combined, frame));
+ outputStream.write(data1);
+ outputStream.write(data1);
+ outputStream.write(data2);
+ frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE; frame.length = " + frame.length, Arrays.equals(combined, frame));
+ outputStream.write(data1);
+ outputStream.write(data1);
+ outputStream.write(data2);
+ frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to MOBILE_NAVI_DATA_SIZE; frame.length = " + frame.length, frame.length == MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ outputStream.close();
+ combined = combine(Arrays.copyOfRange(data1, data1.length - 10, data1.length), data2);
+ frame = sut.readFrameData(buffer, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("data size should be equal to 20; frame.length = " + frame.length, Arrays.equals(combined, frame));
+ }
+
+ public void testCreateFrameWithNullDataParameterThrowsExp() throws Exception {
+ try {
+ outputStream.write(new byte[1000]);
+ byte[] frame = sut.readFrameData(buffer, null);
+ assertNull("should not get here", frame);
+ } catch (IllegalArgumentException e) {
+ assertNotNull("can't create frame with null data parameter", e.getMessage());
+ }
+ }
+
+ public void testCreateFrameWithNullInputStreamThrowsExp() throws Exception {
+ try {
+ H264Packetizer packetizer = new H264Packetizer(null, null, (byte) 0, ServiceType.Mobile_Nav);
+ byte[] frame = packetizer.readFrameData(buffer, new byte[10]);
+ assertNull("should not get here", frame);
+ } catch (IllegalArgumentException e) {
+ assertNotNull("can't create frame with null input stream", e.getMessage());
+ }
+ }
+
+ public void testRead_1_FrameDataFromOuptutStreamShouldReturn_1_Frame() throws Exception {
+ outputStream.write(sampleData);
+ byte[] frame = sut.readFrameData(buffer, sampleData);
+ assertTrue("Arrays written to output stream and get from packetizer should be same", Arrays.equals(sampleData, frame));
+ }
+
+ public void testRead_half_FrameDataFromOuptutStreamShouldReturn_half_Frame() throws Exception {
+ sampleData = generateRandomBytes(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE / 2);
+ buffer = ByteBuffer.allocate(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE / 2);
+ outputStream.write(sampleData);
+ byte[] frame = sut.readFrameData(buffer, sampleData);
+ assertTrue("Arrays written to output stream and get from packetizer should be same", Arrays.equals(sampleData, frame));
+ }
+
+ public void testProtocolFrameHeaderWasCreatedFormInputStream() throws Exception {
+ final byte[] data2 = generateRandomBytes(10);
+ final boolean[] isTestValid = {false};
+ outputStream.write(sampleData);
+ outputStream.write(data2);
+ final H264Packetizer packetizer = new H264Packetizer(new IStreamListener() {
+ private int count = 0;
+
+ @Override
+ public void sendH264(ProtocolMessage pm) {
+ if (count == 0 && pm != null && Arrays.equals(pm.getData(), sampleData)) {
+ isTestValid[0] = true;
+ count++;
+ } else if (count == 1 && pm != null && Arrays.equals(pm.getData(), data2)) {
+ isTestValid[0] = true;
+ count++;
+ } else {
+ isTestValid[0] = false;
+ }
+ }
+ }, inputStream, (byte) 0, ServiceType.Mobile_Nav);
+ outputStream.close();
+ packetizer.doDataReading();
+ assertTrue("ProtocolMessage should be created", isTestValid[0]);
+ }
+
+ public void testStressTest() throws Exception {
+ final int maxSize = 1024 * 10;
+ int currentSize = 0;
+ final ByteBuffer sampleDataBuffer = ByteBuffer.allocate(1024 * 10 + 1000);
+ ByteBuffer realDataBuffer = ByteBuffer.allocate(1024 * 10 + 1000);
+
+ Thread t = new Thread() {
+ int currentSize = 0;
+ @Override
+ public void run() {
+ super.run();
+ Random random = new Random(47);
+ do {
+ byte[] data = new byte[random.nextInt(1000)];
+ random.nextBytes(data);
+ sampleDataBuffer.put(data);
+ try {
+ outputStream.write(data);
+ outputStream.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ currentSize += data.length;
+ try {
+ synchronized (this) {
+ Thread.currentThread().wait(100);
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ } while (currentSize < 1024 * 10);
+ try {
+ outputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ t.start();
+ buffer = ByteBuffer.allocate(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ sampleData = new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE];
+ while (currentSize < 1024 * 10) {
+ try {
+ byte[] frame = sut.readFrameData(buffer, sampleData);
+ realDataBuffer.put(frame);
+ currentSize += frame.length;
+ } catch (IOException e) {
+ e.getMessage();
+ }
+ }
+ t.interrupt();
+ byte[] sample = sampleDataBuffer.array();
+ byte[] real = realDataBuffer.array();
+ Map<Integer, Byte> map = compareArrays(sample, real);
+ if (map.size() > 0) {
+ Integer minI = Collections.min(map.keySet());
+ }
+ assertTrue("Sample and real data should be the same", Arrays.equals(sample, real));
+ }
+
+ private Map<Integer, Byte> compareArrays(byte[] one, byte[] two) {
+ Map<Integer, Byte> map = new TreeMap<Integer, Byte>();
+ for (int i = 0; i < one.length; i++) {
+ if (one[i] != two[i]) {
+ map.put(i, one[i]);
+ }
+ }
+ return map;
+ }
+
+ public void testH264ServiceTypeIsSet() throws Exception {
+ OutputStream os = new PipedOutputStream();
+ InputStream is = new PipedInputStream((PipedOutputStream) os);
+ H264Packetizer audioPacketizer = new H264Packetizer(mock(IStreamListener.class), is, (byte) 0, ServiceType.Audio_Service);
+ assertEquals("service type should be Audio", ServiceType.Audio_Service, audioPacketizer.getServiceType());
+ }
+
+ public void testCreateProtocolMessageUsesSessionID() throws Exception {
+ OutputStream os = new PipedOutputStream();
+ InputStream is = new PipedInputStream((PipedOutputStream) os);
+ H264Packetizer audioPacketizer = new H264Packetizer(mock(IStreamListener.class), is, (byte) 10, ServiceType.Audio_Service);
+ ProtocolMessage message = audioPacketizer.createProtocolMessage( generateRandomBytes(10));
+ assertEquals("session id should be same", audioPacketizer.getSessionID(), message.getSessionID());
+ }
+
+ public void testCreateProtocolMessageUsesServiceType() throws Exception {
+ OutputStream os = new PipedOutputStream();
+ InputStream is = new PipedInputStream((PipedOutputStream) os);
+ H264Packetizer audioPacketizer = new H264Packetizer(mock(IStreamListener.class), is, (byte) 10, ServiceType.Audio_Service);
+ ProtocolMessage message = audioPacketizer.createProtocolMessage( generateRandomBytes(10));
+ assertEquals("session id should be same", audioPacketizer.getServiceType(), message.getServiceType());
+ }
+
+ public void testTwoPacketizersWorkProperly() throws Exception {
+ PipedInputStream inputStreamAudio = new PipedInputStream();
+ PipedOutputStream outputStreamAudio = new PipedOutputStream();
+ PipedInputStream inputStreamVideo = new PipedInputStream();
+ PipedOutputStream outputStreamVideo = new PipedOutputStream();
+ inputStreamAudio.connect(outputStreamAudio);
+ inputStreamVideo.connect(outputStreamVideo);
+ H264Packetizer packetizerAudio = new H264Packetizer(null, inputStreamAudio, (byte) 0, ServiceType.Audio_Service);
+ H264Packetizer packetizerVideo = new H264Packetizer(null, inputStreamVideo, (byte) 0, ServiceType.Mobile_Nav);
+ byte[] sampleDataAudio = generateRandomBytes(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ byte[] sampleDataVideo = generateRandomBytes(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ ByteBuffer bufferAudio = ByteBuffer.allocate(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ ByteBuffer bufferVideo = ByteBuffer.allocate(MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE);
+ outputStreamAudio.write(sampleDataAudio);
+ outputStreamVideo.write(sampleDataVideo);
+ byte[] dataAudio = packetizerAudio.readFrameData(bufferAudio, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ byte[] dataVideo = packetizerVideo.readFrameData(bufferVideo, new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertTrue("dataAudio should be == sampleDataAudio", Arrays.equals(sampleDataAudio, dataAudio));
+ assertTrue("dataVideo should be == sampleDataVideo", Arrays.equals(sampleDataVideo, dataVideo));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/MobileNaviDataFrameTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/MobileNaviDataFrameTest.java
new file mode 100644
index 000000000..96e4f30d6
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/streaming/MobileNaviDataFrameTest.java
@@ -0,0 +1,63 @@
+package com.ford.syncV4.streaming;
+
+import android.test.AndroidTestCase;
+
+import java.util.Arrays;
+
+/**
+ * Created by Andrew Batutin on 9/30/13.
+ */
+public class MobileNaviDataFrameTest extends AndroidTestCase {
+
+ MobileNaviDataFrame sut;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ sut = new MobileNaviDataFrame(new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ }
+
+ public void testSutWasCreated() throws Exception {
+ assertNotNull(sut);
+ }
+
+ public void testSutThrowsExptWithToBigDataSizeToCreate() throws Exception {
+ try {
+ MobileNaviDataFrame frame = new MobileNaviDataFrame(new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE + 10]);
+ assertNull("should not get here", frame);
+ } catch (IllegalArgumentException e) {
+ assertNotNull("frame should not be created with size more than MOBILE_NAVI_DATA_SIZE", e.getMessage());
+ }
+ }
+
+ public void testSutThrowsExpWithNullDataToCreate() throws Exception {
+ try {
+ MobileNaviDataFrame frame = new MobileNaviDataFrame(null);
+ assertNull("should not get here", frame);
+ } catch (IllegalArgumentException e) {
+ assertNotNull("frame should not be created with null data", e.getMessage());
+ }
+ }
+
+ public void testMobileNaviEndServiceFrameWasCreated() throws Exception {
+ MobileNaviDataFrame endFrame = MobileNaviDataFrame.createEndOfServiceFrame();
+ assertNotNull(endFrame);
+ }
+
+ public void testMobileNaviEndServiceFrameDataIsByteArrayWithNegOne() throws Exception {
+ byte[] endData = new byte[]{-1};
+ MobileNaviDataFrame frame = MobileNaviDataFrame.createEndOfServiceFrame();
+ assertTrue("end of currentSession array should have only single -1 value in it", Arrays.equals(endData, frame.getData()));
+ }
+
+ public void testMobileNaviEndServiceWasCreatedWithEndSessionType() throws Exception {
+ MobileNaviDataFrame frame = MobileNaviDataFrame.createEndOfServiceFrame();
+ MobileNaviDataFrameType type = frame.getType();
+ assertEquals("frame should have END_OS_SESSION_TYPE", type, MobileNaviDataFrameType.END_OS_SESSION_TYPE);
+ }
+
+ public void testMobileNaviDataFrameWasCreatedWithDATA_FRAME_TYPE() throws Exception {
+ sut = new MobileNaviDataFrame(new byte[MobileNaviDataFrame.MOBILE_NAVI_DATA_SIZE]);
+ assertEquals("Frmae should has DATA_FRAME_TYPE", sut.getType(), MobileNaviDataFrameType.DATA_FRAME_TYPE);
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionTest.java
new file mode 100644
index 000000000..8566de498
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionTest.java
@@ -0,0 +1,346 @@
+package com.ford.syncV4.syncConnection;
+
+import android.test.InstrumentationTestCase;
+
+import com.ford.syncV4.protocol.AbstractProtocol;
+import com.ford.syncV4.protocol.BinaryFrameHeader;
+import com.ford.syncV4.protocol.ProtocolFrameHeader;
+import com.ford.syncV4.protocol.ProtocolFrameHeaderFactory;
+import com.ford.syncV4.protocol.WiProProtocol;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.protocol.heartbeat.IHeartbeatMonitor;
+import com.ford.syncV4.session.Session;
+import com.ford.syncV4.streaming.H264Packetizer;
+import com.ford.syncV4.transport.SyncTransport;
+import com.ford.syncV4.transport.TCPTransportConfig;
+import com.ford.syncV4.transport.TransportType;
+import com.ford.syncV4.util.BitConverter;
+
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
+import org.mockito.ArgumentCaptor;
+
+import java.io.OutputStream;
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by Andrew Batutin on 8/22/13.
+ */
+public class SyncConnectionTest extends InstrumentationTestCase {
+
+ public static final byte VERSION = (byte) 2;
+ public static final byte SESSION_ID = (byte) 48;
+ public static final int MESSAGE_ID = 48;
+
+ private static final String LOG_TAG = "SyncConnectionTest";
+
+ private SyncConnection sut;
+ private TCPTransportConfig config;
+
+ public SyncConnectionTest() {
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());
+ config = mock(TCPTransportConfig.class);
+ when(config.getTransportType()).thenReturn(TransportType.TCP);
+ sut = new SyncConnection(mock(ISyncConnectionListener.class));
+ sut.init(config);
+ WiProProtocol protocol = (WiProProtocol) sut.getWiProProtocol();
+ protocol.setVersion(VERSION);
+ }
+
+ public void testSyncConnectionShouldBeCreated() throws Exception {
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(config);
+ assertNotNull("should not be null", connection);
+ }
+
+ public void testStartMobileNavServiceShouldSendAppropriateBytes() throws Exception {
+ final boolean[] passed = {false};
+ byte sessionID = 0x0A;
+ Session session = new Session();
+ session.setSessionId(sessionID);
+ ProtocolFrameHeader header = ProtocolFrameHeaderFactory.createStartSession(ServiceType.Mobile_Nav, sessionID, VERSION);
+ header.setSessionID(sessionID);
+ final ProtocolFrameHeader realHeader = header;
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class)) {
+
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes, int offset,
+ int length) {
+ super.onProtocolMessageBytesToSend(msgBytes, offset, length);
+ assertTrue("Arrays should be equal", Arrays.equals(msgBytes, realHeader.assembleHeaderBytes()));
+ assertEquals("Offset should be 0", offset, 0);
+ assertEquals("Length should be 12", length, 12);
+ passed[0] = true;
+ }
+ };
+ connection.init(config);
+ WiProProtocol protocol = (WiProProtocol) connection.getWiProProtocol();
+ protocol.setVersion(VERSION);
+ connection.startMobileNavService(session);
+ assertTrue(passed[0]);
+ }
+
+ public void testOnTransportBytesReceivedReturnedStartSessionACK() throws Exception {
+ final boolean[] passed = {false};
+ final ProtocolFrameHeader header = ProtocolFrameHeaderFactory.createStartSessionACK(ServiceType.Mobile_Nav, SESSION_ID, MESSAGE_ID, VERSION);
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class)) {
+
+ @Override
+ public void onProtocolServiceStarted(ServiceType serviceType, byte sessionID, byte version, String correlationID) {
+ super.onProtocolServiceStarted(serviceType,sessionID, version, correlationID);
+ assertEquals("Correlation ID is empty string so far", "", correlationID);
+ assertEquals("ServiceType should be equal.", header.getServiceType(), serviceType);
+ assertEquals("Frame headers should be equal.", header.getSessionID(), sessionID);
+ assertEquals("Version should be equal.", header.getVersion(), version);
+ passed[0] = true;
+ }
+ };
+ connection.init(config);
+ WiProProtocol protocol = (WiProProtocol) connection.getWiProProtocol();
+ protocol.setVersion(VERSION);
+ connection.onTransportBytesReceived(header.assembleHeaderBytes(), header.assembleHeaderBytes().length);
+ assertTrue(passed[0]);
+ }
+
+ public void testCloseMobileNavSessionShouldSendAppropriateBytes() throws Exception {
+ byte[] data = BitConverter.intToByteArray(0);
+ final ProtocolFrameHeader header = ProtocolFrameHeaderFactory.createEndSession(ServiceType.Mobile_Nav, SESSION_ID, 0, VERSION, data.length);
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class)) {
+
+ private int count = 0;
+
+ @Override
+ public void closeMobileNaviService(byte rpcSessionID) {
+ _transport = mock(SyncTransport.class);
+ when(_transport.getIsConnected()).thenReturn(true);
+ super.closeMobileNaviService(rpcSessionID);
+ }
+
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes, int offset,
+ int length) {
+ super.onProtocolMessageBytesToSend(msgBytes, offset, length);
+ if (count == 0) {
+ assertTrue("Arrays should be equal", Arrays.equals(msgBytes, header.assembleHeaderBytes()));
+ assertEquals("Offset should be 0", offset, 0);
+ assertEquals("Length should be 12", length, 12);
+ count++;
+ }
+ }
+ };
+ connection.init(config);
+ WiProProtocol protocol = (WiProProtocol) connection.getWiProProtocol();
+ protocol.setVersion(VERSION);
+ connection.closeMobileNaviService(SESSION_ID);
+ }
+
+ public void testStopTransportIsCalledForRPCService() throws Exception {
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class)) {
+ @Override
+ public Boolean getIsConnected() {
+ _transport = mock(SyncTransport.class);
+ return super.getIsConnected();
+ }
+ };
+ connection.init(config);
+ connection.getIsConnected();
+ connection.onProtocolServiceEnded(ServiceType.RPC, SESSION_ID, "");
+ verify(connection._transport, times(1)).stopReading();
+ }
+
+ public void testStopTransportNotCalledForNavigationService() throws Exception {
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class)) {
+ @Override
+ public Boolean getIsConnected() {
+ _transport = mock(SyncTransport.class);
+ return super.getIsConnected();
+ }
+ };
+ connection.init(config);
+ connection.getIsConnected();
+ connection.onProtocolServiceEnded(ServiceType.Mobile_Nav, SESSION_ID, "");
+ verify(connection._transport, never()).stopReading();
+
+ }
+
+ public void testStartAudioServiceShouldSendAppropriateBytes() throws Exception {
+ final boolean[] isPassed = {false};
+ byte sessionID = 0x0A;
+ Session session = new Session();
+ session.setSessionId(sessionID);
+ ProtocolFrameHeader header = ProtocolFrameHeaderFactory.createStartSession(ServiceType.Audio_Service, sessionID, VERSION);
+ header.setSessionID(sessionID);
+ final ProtocolFrameHeader realHeader = header;
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class)) {
+
+ @Override
+ public void onProtocolMessageBytesToSend(byte[] msgBytes, int offset,
+ int length) {
+ super.onProtocolMessageBytesToSend(msgBytes, offset, length);
+ isPassed[0] = true;
+ assertTrue("Arrays should be equal", Arrays.equals(msgBytes, realHeader.assembleHeaderBytes()));
+ assertEquals("Offset should be 0", offset, 0);
+ assertEquals("Length should be 12", length, 12);
+ }
+ };
+ connection.init(config);
+ WiProProtocol protocol = (WiProProtocol) connection.getWiProProtocol();
+ protocol.setVersion(VERSION);
+ connection.startAudioService(session);
+ assertTrue(isPassed[0]);
+ }
+
+ public void testStartAudioDataTransferReturnsOutputStream() throws Exception {
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(config);
+ OutputStream stream = connection.startAudioDataTransfer(SESSION_ID);
+ assertNotNull("output stream should be created", stream);
+ }
+
+ public void testStartAudioDataTransferCreatesAudioPacketizer() throws Exception {
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(config);
+ OutputStream stream = connection.startAudioDataTransfer(SESSION_ID);
+ assertNotNull("audio pacetizer should not be null", connection.mAudioPacketizer);
+ }
+
+/*
+ // FIXME this test fails with
+ // junit.framework.AssertionFailedError: expected:<RUNNABLE> but was:<WAITING>
+ public void testStartAudioDataTransferStartsPacetizer() throws Exception {
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(config);
+ OutputStream stream = connection.startAudioDataTransfer(SESSION_ID);
+ H264Packetizer packetizer = (H264Packetizer) connection.mAudioPacketizer;
+ assertEquals(Thread.State.RUNNABLE, packetizer.getThread().getState());
+ }
+*/
+
+ public void testStartAudioDataTransferSetsSessionID() throws Exception {
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(config);
+ OutputStream stream = connection.startAudioDataTransfer(SESSION_ID);
+ H264Packetizer packetizer = (H264Packetizer) connection.mAudioPacketizer;
+ assertEquals("session id should be equal SESSION_ID", SESSION_ID, packetizer.getSessionID());
+ }
+
+ public void testStopAudioDataTransferStopPacketizer() throws Exception {
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(config);
+ connection.mAudioPacketizer = mock(H264Packetizer.class);
+ connection.stopAudioDataTransfer();
+ verify(connection.mAudioPacketizer, times(1)).stop();
+ }
+
+ public void testCloseAudioServiceSendEndServiceMessage() throws Exception {
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(config);
+ connection._protocol = mock(WiProProtocol.class);
+ connection._transport = mock(SyncTransport.class);
+ when(connection._transport.getIsConnected()).thenReturn(true);
+ connection.closeAudioService(SESSION_ID);
+ ArgumentCaptor<ServiceType> serviceTypeCaptor = ArgumentCaptor.forClass(ServiceType.class);
+ ArgumentCaptor<Byte> sessionIDCaptor = ArgumentCaptor.forClass(byte.class);
+ verify(connection._protocol, times(1)).EndProtocolService(serviceTypeCaptor.capture(), sessionIDCaptor.capture());
+ assertEquals("should end audio service", ServiceType.Audio_Service, serviceTypeCaptor.getValue());
+ assertEquals("should end session with SESSION_ID", SESSION_ID, sessionIDCaptor.getValue().byteValue());
+ }
+
+ public void testStartSessionWithCorrectId() throws Exception {
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.setSessionId(SESSION_ID);
+ connection.init(config);
+ connection._protocol = mock(WiProProtocol.class);
+ connection._transport = mock(SyncTransport.class);
+ when(connection._transport.getIsConnected()).thenReturn(true);
+
+ connection.onTransportConnected();
+
+ ArgumentCaptor<Byte> sessionIDCaptor = ArgumentCaptor.forClass(byte.class);
+ verify(connection._protocol, times(1)).StartProtocolSession(sessionIDCaptor.capture());
+ assertEquals("Should start session with SESSION_ID", SESSION_ID, sessionIDCaptor.getValue().byteValue());
+ }
+
+ public void testOnCloseSessionAudioPacketizerStops() throws Exception {
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.setSessionId(SESSION_ID);
+ connection.init(config);
+ connection._protocol = mock(WiProProtocol.class);
+ connection._transport = mock(SyncTransport.class);
+ connection.mAudioPacketizer = mock(H264Packetizer.class);
+ when(connection._transport.getIsConnected()).thenReturn(true);
+ connection.closeConnection(SESSION_ID, false);
+ verify(connection.mAudioPacketizer, times(1)).stop();
+ }
+
+ public void testHeartbeatMonitorStoppedIfConnectionClosedWithoutKeepConnection() throws Exception {
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.setHeartbeatMonitor(mock(IHeartbeatMonitor.class));
+ assertNotNull(connection.getHeartbeatMonitor());
+ connection.closeConnection((byte) 0, false, true);
+ assertNull("heartbeat monitor should be stopped and null",connection.getHeartbeatMonitor());
+ }
+
+ public void testHeartbeatMonitorNotStoppedIfConnectionClosedWithKeepConnection() throws Exception {
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.setHeartbeatMonitor(mock(IHeartbeatMonitor.class));
+ assertNotNull(connection.getHeartbeatMonitor());
+ connection.closeConnection((byte) 0, true, true);
+ verify(connection.getHeartbeatMonitor(), never()).stop();
+ assertNotNull("heartbeat monitor should not be null",connection.getHeartbeatMonitor());
+ }
+
+ public void testHeartbeatMonitorResetOnHeartbeatReset() throws Exception {
+ IHeartbeatMonitor heartbeatMonitor = mock(IHeartbeatMonitor.class);
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.setHeartbeatMonitor(heartbeatMonitor);
+ connection.onResetHeartbeat();
+ verify(heartbeatMonitor).notifyTransportActivity();
+ }
+
+ public void testHeartbeatSendDoNotResetHeartbeat() throws Exception {
+ IHeartbeatMonitor heartbeatMonitor = mock(IHeartbeatMonitor.class);
+ SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.sendHeartbeat(heartbeatMonitor);
+ verify(heartbeatMonitor, never()).notifyTransportActivity();
+ }
+
+ public void testMaxJsonSizeInIncomingMessageShouldCallOnProtocolError() {
+ final ISyncConnectionListener connectionListenerMock =
+ mock(ISyncConnectionListener.class);
+ SyncConnection connection = new SyncConnection(connectionListenerMock);
+ connection.init(null, mock(SyncTransport.class));
+ final WiProProtocol protocol = new WiProProtocol(connection);
+ protocol.setVersion((byte) 0x02);
+ connection._protocol = protocol;
+
+ final byte maxByte = (byte) 0xFF;
+ final byte[] bytes =
+ { 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, maxByte, maxByte, maxByte, maxByte, 0x00 };
+ connection.onTransportBytesReceived(bytes, bytes.length);
+
+ ArgumentCaptor<Throwable> throwableArgumentCaptor =
+ ArgumentCaptor.forClass(Throwable.class);
+ verify(connectionListenerMock, timeout(100).times(1)).onProtocolError(
+ anyString(), throwableArgumentCaptor.capture());
+ assertThat(throwableArgumentCaptor.getValue().toString(),
+ containsString(OutOfMemoryError.class.getSimpleName()));
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionUSBTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionUSBTest.java
new file mode 100644
index 000000000..8c7d83b81
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/syncConnection/SyncConnectionUSBTest.java
@@ -0,0 +1,79 @@
+package com.ford.syncV4.syncConnection;
+
+import com.ford.syncV4.exception.SyncException;
+import com.ford.syncV4.protocol.enums.ServiceType;
+import com.ford.syncV4.transport.BTTransportConfig;
+import com.ford.syncV4.transport.ITransportListener;
+import com.ford.syncV4.transport.SyncTransport;
+import com.ford.syncV4.transport.TransportType;
+
+import junit.framework.TestCase;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * Created by u on 2013-09-30.
+ */
+public class SyncConnectionUSBTest extends TestCase {
+ private boolean requiredMethodCalled;
+
+ public void testOnProtocolAppUnregisteredStopsTransport() {
+ final ITransportListener transportListener = new ITransportListener() {
+ @Override
+ public void onTransportBytesReceived(byte[] receivedBytes,
+ int receivedBytesLength) {
+ }
+
+ @Override
+ public void onTransportConnected() {
+ }
+
+ @Override
+ public void onTransportDisconnected(String info) {
+ }
+
+ @Override
+ public void onTransportError(String info, Exception e) {
+ }
+
+ @Override
+ public void onServerSocketInit(int serverSocketPort) {
+
+ }
+ };
+
+ final SyncTransport fakeTransport =
+ new SyncTransport(transportListener) {
+ @Override
+ protected boolean sendBytesOverTransport(byte[] msgBytes,
+ int offset,
+ int length) {
+ return false;
+ }
+
+ @Override
+ public void openConnection() throws SyncException {
+ }
+
+ @Override
+ public void disconnect() {
+ }
+
+ @Override
+ public void stopReading() {
+ requiredMethodCalled = true;
+ }
+
+ @Override
+ public TransportType getTransportType() {
+ return null;
+ }
+ };
+
+ final SyncConnection connection = new SyncConnection(mock(ISyncConnectionListener.class));
+ connection.init(new BTTransportConfig());
+ connection._transport = fakeTransport;
+ connection.onProtocolServiceEnded(ServiceType.RPC, (byte) 0, "");
+ assertTrue("stopReading() isn't called", requiredMethodCalled);
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/transport/usb/USBTransportTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/transport/usb/USBTransportTest.java
new file mode 100644
index 000000000..12c3bf1ac
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/transport/usb/USBTransportTest.java
@@ -0,0 +1,50 @@
+package com.ford.syncV4.transport.usb;
+
+import android.test.AndroidTestCase;
+
+import com.ford.syncV4.transport.ITransportListener;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by Andrew Batutin on 1/8/14.
+ */
+public class USBTransportTest extends AndroidTestCase {
+
+ public void testStopReadingCausesReaderThreadToStop() throws Exception {
+
+ final ITransportListener transportListener = new ITransportListener() {
+ @Override
+ public void onTransportBytesReceived(byte[] receivedBytes,
+ int receivedBytesLength) {
+ }
+
+ @Override
+ public void onTransportConnected() {
+ }
+
+ @Override
+ public void onTransportDisconnected(String info) {
+ }
+
+ @Override
+ public void onTransportError(String info, Exception e) {
+ }
+
+ @Override
+ public void onServerSocketInit(int serverSocketPort) {
+
+ }
+ };
+
+ USBTransport usbTransport = new USBTransport(null, transportListener);
+ Thread thread = mock(Thread.class);
+ when(thread.isInterrupted()).thenReturn(true);
+ usbTransport.setReaderThread(thread);
+ usbTransport.setState(USBTransport.State.CONNECTED);
+ usbTransport.stopReading();
+ boolean isInterrupted = usbTransport.getReaderThread().isInterrupted();
+ assertEquals("thread should be interrupted", true, isInterrupted);
+ }
+}
diff --git a/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/util/CommonUtilsTest.java b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/util/CommonUtilsTest.java
new file mode 100644
index 000000000..bb7fb6e1d
--- /dev/null
+++ b/SDL_Core/mobile/android/SyncProxyAndroid/instrumentTest/java/com/ford/syncV4/util/CommonUtilsTest.java
@@ -0,0 +1,70 @@
+package com.ford.syncV4.util;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Created with Android Studio.
+ * Author: Chernyshov Yuriy - Mobile Development
+ * Date: 2/12/14
+ * Time: 10:31 AM
+ */
+public class CommonUtilsTest extends TestCase {
+
+ public void testIsUSBNoSuchDeviceError_True() {
+ String mErrorMessage = "java.io.IOException: write failed: ENODEV (No such device)";
+ assertTrue(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+
+ mErrorMessage = "IOException: write ENODEV (No such device";
+ assertTrue(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+
+ mErrorMessage = "IOExceptionENODEVNo such device";
+ assertTrue(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+
+ mErrorMessage = "Transport failure: Failed to send bytes over USB\n" +
+ " java.io.IOException: write failed: ENODEV (No such device)\n" +
+ " at libcore.io.IoBridge.write(IoBridge.java:506)\n" +
+ " at java.io.FileOutputStream.write(FileOutputStream.java:187)\n" +
+ " at com.ford.syncV4.transport.usb.USBTransport.sendBytesOverTransport(USBTransport.java:231)\n" +
+ " at com.ford.syncV4.transport.SyncTransport.sendBytes(SyncTransport.java:63)\n" +
+ " at com.ford.syncV4.syncConnection.SyncConnection.onProtocolMessageBytesToSend(SyncConnection.java:372)\n" +
+ " at com.ford.syncV4.protocol.AbstractProtocol.handleProtocolMessageBytesToSend(AbstractProtocol.java:177)\n" +
+ " at com.ford.syncV4.protocol.AbstractProtocol.handleProtocolFrameToSend(AbstractProtocol.java:93)\n" +
+ " at com.ford.syncV4.protocol.WiProProtocol.sendFrameToTransport(WiProProtocol.java:171)\n" +
+ " at com.ford.syncV4.protocol.WiProProtocol.StartProtocolSession(WiProProtocol.java:66)\n" +
+ " at com.ford.syncV4.syncConnection.SyncConnection.startProtocolSession(SyncConnection.java:336)\n" +
+ " at com.ford.syncV4.syncConnection.SyncConnection.initialiseSession(SyncConnection.java:329)\n" +
+ " at com.ford.syncV4.syncConnection.SyncConnection.onTransportConnected(SyncConnection.java:322)\n" +
+ " at com.ford.syncV4.transport.SyncTransport.handleTransportConnected(SyncTransport.java:80)\n" +
+ " at com.ford.syncV4.transport.usb.USBTransport.setState(USBTransport.java:205)\n" +
+ " at com.ford.syncV4.transport.usb.USBTransport$USBTransportReader.connect(USBTransport.java:691)\n" +
+ " at com.ford.syncV4.transport.usb.USBTransport$USBTransportReader.run(USBTransport.java:649)\n" +
+ " at java.lang.Thread.run(Thread.java:838)\n" +
+ " Caused by: libcore.io.ErrnoException: write failed: ENODEV (No such device)";
+ assertTrue(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+ }
+
+ public void testIsUSBNoSuchDeviceError_False() {
+ String mErrorMessage = "java.io.IOException: write failed: (No such device)";
+ assertFalse(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+
+ mErrorMessage = "java.io.IOException: write failed: ENODEV (No such )";
+ assertFalse(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+
+ mErrorMessage = "";
+ assertFalse(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+
+ mErrorMessage = null;
+ assertFalse(CommonUtils.isUSBNoSuchDeviceError(mErrorMessage));
+ }
+
+ 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;
+ }
+} \ No newline at end of file