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 testStopConnection.
@Suppress
@MediumTest
public void testStopConnection() {
DataOutputStream dos = new DataOutputStream(new ByteArrayOutputStream());
MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
null);
hbSender.setOutputStream(dos);
hbSender.startConnection();
try {
Thread.sleep(500);
} catch (Exception e) {
}
hbSender.stopConnection();
try {
Thread.sleep(1000);
} catch (Exception e) {
}
assertNotNull(hbSender.getConnectionThread());
if (null != hbSender.getConnectionThread()) {
assertFalse(hbSender.getConnectionThread().isAlive());
try {
dos.write(1);
fail("Should not be able to write here!");
} catch (IOException e) {
assertTrue(true);
}
}
}
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 testSendHeartbeat_valid.
@MediumTest
public void testSendHeartbeat_valid() {
byte[] header = { (byte) 0xFF, (byte) 0xFF, (byte) 0x64 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
null);
AuthSessionHolder authHolder = new AuthSessionHolder();
authHolder.userID = 007;
authHolder.sessionID = "SESS_ID";
authHolder.sessionSecret = "SESS_SECRET";
authHolder.userName = "James_Bond";
LoginEngine.setTestSession(authHolder);
hbSender.setOutputStream(baos);
try {
hbSender.sendHeartbeat();
} catch (Exception e) {
fail("sendHeartbeatTest() should not throw an Exception here " + e.toString());
}
try {
baos.flush();
baos.close();
} catch (IOException ioe) {
}
byte[] payload = baos.toByteArray();
if (null != payload) {
boolean isHeaderOk = false, isEndingOk = false, isPayloadLenOk = false;
if ((header[0] == payload[0]) && (header[1] == payload[1]) && (header[2] == payload[2])) {
isHeaderOk = true;
} else {
fail("RPG Header was malformed!");
}
if (payload[payload.length - 1] == ((byte) 0x7A)) {
isPayloadLenOk = true;
} else {
fail("Message End was malformed! Char was: " + payload[payload.length - 1]);
}
int payloadSize = byteArrayToInt(new byte[] { payload[11], payload[12], payload[13], payload[14] }, 0);
if (payloadSize == (payload.length - 16)) {
isEndingOk = true;
} else {
fail("Payload length is not okay: " + payloadSize + " vs. " + (payload.length - 16));
}
assertTrue((isHeaderOk && isEndingOk && isPayloadLenOk));
} else {
fail("HB-Payload was 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 HeartbeatSenderThreadTest method testSendHeartbeat_exception.
@MediumTest
public void testSendHeartbeat_exception() {
MockByteArrayOutputStream baos = new MockByteArrayOutputStream();
MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
null);
AuthSessionHolder authHolder = new AuthSessionHolder();
authHolder.userID = 007;
authHolder.sessionID = "SESS_ID";
authHolder.sessionSecret = "SESS_SECRET";
authHolder.userName = "James_Bond";
LoginEngine.setTestSession(authHolder);
hbSender.setOutputStream(baos);
try {
baos.close();
} catch (IOException ioe) {
}
// IOException Test
try {
hbSender.sendHeartbeat();
} catch (IOException ioe) {
// we succeed because we expect an IOE to be thrown here!
assertTrue(true);
} catch (Exception e) {
fail("We should not have received a generic exception, but an IOException!");
}
baos = null;
// NullPointerException Test
hbSender.setOutputStream(null);
try {
hbSender.sendHeartbeat();
} catch (IOException ioe) {
fail("We should not have received an IOException, but a generic (NP-)Exception!");
} catch (Exception e) {
// we succeed because we expect an IOE to be thrown here!
assertTrue(true);
}
}
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 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;
}
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 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());
}
Aggregations