Search in sources :

Example 11 with DecoderThread

use of com.vodafone360.people.service.transport.DecoderThread 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 12 with DecoderThread

use of com.vodafone360.people.service.transport.DecoderThread 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 13 with DecoderThread

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

the class ResponseReaderThreadTest method testSetInputstream.

@MediumTest
public void testSetInputstream() {
    DecoderThread decoder = new DecoderThread();
    MockTcpConnectionThread mockThread = new MockTcpConnectionThread(decoder, null);
    MockResponseReaderThread respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
    null);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 });
    respReader.setInputStream(new BufferedInputStream(bais));
    DataInputStream dis = (DataInputStream) respReader.getInputStream();
    assertNotNull(dis);
    // let's test all the bytes...
    if (null != dis) {
        boolean areBytesCorrect = true;
        for (int i = 1; i < 6; i++) {
            try {
                int j = dis.readByte();
                if (-1 == j) {
                    fail("Unexpected end of the DataInputStream");
                    areBytesCorrect = false;
                } else if (i != j) {
                    fail("Characters differ: i: " + i + " vs. j: " + j);
                    areBytesCorrect = false;
                }
            } catch (IOException e) {
            }
        }
        assertTrue(areBytesCorrect);
    }
    respReader.setInputStream(null);
    assertNull(respReader.getInputStream());
}
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) DataInputStream(java.io.DataInputStream) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 14 with DecoderThread

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

the class DecoderThread method startThread.

/**
     * Start decoder thread
     */
protected void startThread() {
    mRunning = true;
    Thread decoderThread = new Thread(this);
    decoderThread.setName(THREAD_NAME);
    decoderThread.start();
}
Also used : HttpConnectionThread(com.vodafone360.people.service.transport.http.HttpConnectionThread)

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