Search in sources :

Example 6 with MockTcpConnectionThread

use of com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread 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 7 with MockTcpConnectionThread

use of com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread 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)

Example 8 with MockTcpConnectionThread

use of com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread in project 360-Engine-for-Android by 360.

the class HeartbeatSenderThreadTest method testRun_exception.

@Suppress
@MediumTest
public void testRun_exception() {
    // IO Exception test
    MockByteArrayOutputStream baos = new MockByteArrayOutputStream();
    MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
    MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
    null);
    hbSender.setOutputStream(baos);
    try {
        baos.close();
    } catch (IOException e) {
    }
    hbSender.startConnection();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    assertTrue(connThread.getDidErrorOccur());
    hbSender.stopConnection();
    connThread = null;
    hbSender = null;
    // NP Exception test
    connThread = new MockTcpConnectionThread(new DecoderThread(), null);
    hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
    null);
    hbSender.setOutputStream(null);
    hbSender.startConnection();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    assertTrue(connThread.getDidErrorOccur());
    hbSender.stopConnection();
    connThread = null;
    hbSender = null;
}
Also used : DecoderThread(com.vodafone360.people.service.transport.DecoderThread) IOException(java.io.IOException) IOException(java.io.IOException) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 9 with MockTcpConnectionThread

use of com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread in project 360-Engine-for-Android by 360.

the class ResponseReaderThreadTest method testStopConnection.

@Suppress
@MediumTest
public void testStopConnection() {
    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));
    respReader.startConnection();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    Thread t = respReader.getConnectionThread();
    assertNotNull(t);
    if (null != t) {
        assertTrue(t.isAlive());
        assertTrue(respReader.getIsConnectionRunning());
    }
    // now comes the actual test
    respReader.stopConnection();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    assertNull(respReader.getInputStream());
    assertNull(respReader.getConnectionThread());
    assertFalse(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) MockTcpConnectionThread(com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread) DecoderThread(com.vodafone360.people.service.transport.DecoderThread) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 10 with MockTcpConnectionThread

use of com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread in project 360-Engine-for-Android by 360.

the class ResponseReaderThreadTest method testReadNextResponse.

/***
	 * Test DecoderThread.getResponse() call.
	 */
@Suppress
@MediumTest
public void testReadNextResponse() {
    /** Happy path test that runs through one whole response. **/
    MockDecoderThread decoder = new MockDecoderThread();
    MockTcpConnectionThread mockThread = new MockTcpConnectionThread(decoder, null);
    MockResponseReaderThread respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
    null);
    byte[] payload = new byte[] { /*** RPG header. **/
    ((byte) 0xFF), ((byte) 0xFF), 0x04, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, /** 5 bytes of payload. **/
    1, 2, 3, 4, 5 };
    ByteArrayInputStream bais = new ByteArrayInputStream(payload);
    respReader.setInputStream(new BufferedInputStream(bais));
    respReader.startConnection();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ie) {
    // Do nothing.
    }
    assertNotNull("The decoder response should not have been NULL", decoder.getResponse());
    assertTrue("Incorrect payload", Arrays.equals(payload, decoder.getResponse()));
    respReader.stopConnection();
    payload = null;
    respReader = null;
    mockThread = null;
    decoder = null;
    bais = null;
    /** Sad path test where the 2nd byte is not the delimiter. **/
    decoder = new MockDecoderThread();
    mockThread = new MockTcpConnectionThread(decoder, null);
    respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
    null);
    payload = new byte[] { 1, ((byte) 0xFF) };
    respReader.startConnection();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ie) {
    }
    assertNull(decoder.getResponse());
    respReader.stopConnection();
    payload = null;
    respReader = null;
    mockThread = null;
    decoder = null;
    bais = null;
}
Also used : 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)

Aggregations

MediumTest (android.test.suitebuilder.annotation.MediumTest)11 DecoderThread (com.vodafone360.people.service.transport.DecoderThread)10 Suppress (android.test.suitebuilder.annotation.Suppress)7 IOException (java.io.IOException)6 MockTcpConnectionThread (com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread)5 BufferedInputStream (java.io.BufferedInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1