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