use of com.vodafone360.people.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.
the class LoginEngineTest method testPublicFunctions.
// @MediumTest
// public void testSmsResponse(){
// LoginDetails loginDetails = new LoginDetails();
// loginDetails.mMobileNo = "123456789";
// loginDetails.mUsername = "bob";
// loginDetails.mPassword = "ajob";
//
// mState = LoginTestState.LOGIN_REQUEST;
// NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
// synchronized(mEngineTester){
// mEng.addUiLoginRequest(loginDetails);
//
// ServiceStatus status = mEngineTester.waitForEvent();
// assertEquals(ServiceStatus.SUCCESS, status);
// }
// // test actually receiving the SMS
// mState = LoginTestState.SMS_RESPONSE_SIGNIN;
//
// mEng.handleSmsResponse();
//
// ServiceStatus status = mEngineTester.waitForEvent(30000);
// assertEquals(ServiceStatus.SUCCESS, status);
// }
@MediumTest
public void testPublicFunctions() {
mEng.getLoginRequired();
NetworkAgent.setAgentState(NetworkAgent.AgentState.DISCONNECTED);
mEng.getNewPublicKey();
NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
mEng.getNewPublicKey();
mEng.isDeactivated();
mEng.setActivatedSession(new AuthSessionHolder());
}
use of com.vodafone360.people.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.
the class NowPlusStateTableTest method testSetFetchSession.
/*
* set and fetch session
*/
public void testSetFetchSession() {
final String fnName = "testSetFetchSession";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "test setting and fetching session");
SQLiteDatabase writableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
AuthSessionHolder session = new AuthSessionHolder();
session.sessionID = TestModule.generateRandomString();
session.sessionSecret = TestModule.generateRandomString();
session.userID = TestModule.generateRandomInt();
session.userName = TestModule.generateRandomString();
ServiceStatus status = StateTable.setSession(session, writableDb);
assertNull(status);
AuthSessionHolder fetchedSession = StateTable.fetchSession(readableDb);
assertNull(fetchedSession);
createTable();
status = StateTable.setSession(session, writableDb);
assertEquals(ServiceStatus.SUCCESS, status);
fetchedSession = StateTable.fetchSession(readableDb);
assertEquals(session.toString(), fetchedSession.toString());
Log.i(LOG_TAG, "*************************************");
Log.i(LOG_TAG, "testSetFetchSession has completed successfully");
Log.i(LOG_TAG, "**************************************");
}
use of com.vodafone360.people.datatypes.AuthSessionHolder 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.datatypes.AuthSessionHolder 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.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.
the class LoginEngine method handleCreateSessionAutoResponse.
/**
* Called when a response to the GetSessionByCredentials API is received
* (auto login). In case of success, moves to the logged in state
*
* @param data The received data
*/
private void handleCreateSessionAutoResponse(List<BaseDataType> data) {
LogUtils.logD("LoginEngine.handleCreateSessionResponse()");
ServiceStatus errorStatus = getResponseStatus(BaseDataType.AUTH_SESSION_HOLDER_TYPE, data);
if (errorStatus == ServiceStatus.SUCCESS && (data.size() > 0)) {
clearTimeout();
setActivatedSession((AuthSessionHolder) data.get(0));
newState(State.LOGGED_ON);
} else {
LogUtils.logE("LoginEngine.handleCreateSessionResponse() - Auto Login Failed Error " + errorStatus);
// mAreLoginDetailsValid = false;
if (errorStatus == ServiceStatus.ERROR_INVALID_PASSWORD) {
mAreLoginDetailsValid = false;
newState(State.LOGIN_FAILED_WRONG_CREDENTIALS);
} else {
newState(State.LOGIN_FAILED);
}
// }
}
}
Aggregations