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());
}
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();
}
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;
}
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());
}
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;
}
Aggregations