Search in sources :

Example 6 with DecoderThread

use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.

the class ResponseReaderThreadTest method testRun_exception.

@Suppress
@MediumTest
public void testRun_exception() {
    DecoderThread decoder = new DecoderThread();
    MockTcpConnectionThread mockThread = new MockTcpConnectionThread(decoder, null);
    MockResponseReaderThread respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
    null);
    MockOTAInputStream mIs = new MockOTAInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
    respReader.setInputStream(new BufferedInputStream(mIs));
    // IO Exception test
    try {
        mIs.close();
    } catch (IOException e) {
    }
    respReader.startConnection();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    assertTrue(mockThread.getDidErrorOccur());
    respReader.stopConnection();
    mockThread = null;
    respReader = null;
    // NP Exception test
    mockThread = new MockTcpConnectionThread(new DecoderThread(), null);
    respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
    null);
    respReader.setInputStream(null);
    respReader.startConnection();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    assertTrue(mockThread.getDidErrorOccur());
    respReader.stopConnection();
    mockThread = null;
    respReader = null;
    // EOF Exception
    mockThread = new MockTcpConnectionThread(new DecoderThread(), null);
    respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
    null);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] { 1 });
    respReader.setInputStream(new BufferedInputStream(bais));
    respReader.startConnection();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    assertTrue(mockThread.getDidErrorOccur());
    respReader.stopConnection();
    mockThread = null;
    respReader = null;
}
Also used : DecoderThread(com.vodafone360.people.service.transport.DecoderThread) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) MockTcpConnectionThread(com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread) IOException(java.io.IOException) IOException(java.io.IOException) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 7 with DecoderThread

use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.

the class ResponseReaderThreadTest method testStartConnection.

@Suppress
@MediumTest
public void testStartConnection() {
    DecoderThread decoder = new DecoderThread();
    MockTcpConnectionThread mockThread = new MockTcpConnectionThread(decoder, null);
    MockResponseReaderThread respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value 
    null);
    MockOTAInputStream mIs = new MockOTAInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
    respReader.setInputStream(new BufferedInputStream(mIs));
    assertNull(respReader.getConnectionThread());
    respReader.startConnection();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    assertNotNull(respReader.getConnectionThread());
    if (null != respReader.getConnectionThread()) {
        assertTrue(respReader.getConnectionThread().isAlive());
    }
    assertTrue(respReader.getIsConnectionRunning());
}
Also used : DecoderThread(com.vodafone360.people.service.transport.DecoderThread) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) MockTcpConnectionThread(com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 8 with DecoderThread

use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.

the class RemoteServiceTest method testSignalConnectionManager.

/**
     * Test signalConnectionManager() from RemoteService.
     *
     * @throws Exception Any kind of mapping exception
     */
@MediumTest
public final void testSignalConnectionManager() throws Exception {
    /** Setup test preconditions (i.e. remoteService running). **/
    startService(new Intent(getContext(), RemoteService.class));
    RemoteService remoteService = getService();
    assertNotNull("RemoteService should not be NULL", remoteService);
    assertTrue("Expected mIsConnected to be TRUE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertNotNull("Expected mConnection to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection"));
    assertTrue("Expected mDecoder to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    assertEquals("Expected mConnection to be AuthenticationManager class", AuthenticationManager.class, FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection").getClass());
    /** Perform test (i.e. disconnect). **/
    remoteService.signalConnectionManager(false);
    /**
         * Test if signalConnectionManager() called
         * ConnectionManager.disconnect() and set mIsConnected to false.
         */
    assertFalse("Expecting mIsConnected to be FALSE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertNotNull("Expected mConnection not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection"));
    assertFalse("Expected mDecoder not to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    FrameworkUtils.set(remoteService, "mWorkerThread", null);
    /** Perform second test (i.e. connect). **/
    remoteService.signalConnectionManager(true);
    /**
         * Test if signalConnectionManager() called
         * ConnectionManager.connect(), kickWorkerThread() and set mIsConnected
         * to true.
         */
    assertTrue("Expecting mIsConnected to be TRUE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertTrue("Expected mDecoder to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    assertNotNull("Expecting workerThread not to be NULL", FrameworkUtils.get(remoteService, "mWorkerThread"));
}
Also used : RemoteService(com.vodafone360.people.service.RemoteService) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 9 with DecoderThread

use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.

the class HeartbeatSenderThreadTest method testSetOutputStream.

@MediumTest
public void testSetOutputStream() {
    MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
    MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
    null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    hbSender.setOutputStream(baos);
    assertEquals(baos, hbSender.getOutputStream());
}
Also used : DecoderThread(com.vodafone360.people.service.transport.DecoderThread) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 10 with DecoderThread

use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.

the class HeartbeatSenderThreadTest method testStartConnection.

@Suppress
@MediumTest
public void testStartConnection() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
    MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
    null);
    hbSender.setOutputStream(baos);
    hbSender.startConnection();
    assertTrue(hbSender.getIsActive());
    assertNotNull(hbSender.getConnectionThread());
    if (null != hbSender.getConnectionThread()) {
        assertTrue(hbSender.getConnectionThread().isAlive());
    }
    hbSender.stopConnection();
}
Also used : DecoderThread(com.vodafone360.people.service.transport.DecoderThread) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

MediumTest (android.test.suitebuilder.annotation.MediumTest)11 DecoderThread (com.vodafone360.people.service.transport.DecoderThread)11 IOException (java.io.IOException)7 Suppress (android.test.suitebuilder.annotation.Suppress)6 MockTcpConnectionThread (com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread)4 BufferedInputStream (java.io.BufferedInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 Intent (android.content.Intent)1 MainApplication (com.vodafone360.people.MainApplication)1 RemoteService (com.vodafone360.people.service.RemoteService)1 NetworkAgent (com.vodafone360.people.service.agent.NetworkAgent)1 RpgHeader (com.vodafone360.people.service.io.rpg.RpgHeader)1 HttpConnectionThread (com.vodafone360.people.service.transport.http.HttpConnectionThread)1 UserDataProtection (com.vodafone360.people.service.utils.UserDataProtection)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1