use of pinkpanthers.pinkshelters.Model.Volunteer in project pink-panthers by MrTrai.
the class DbUnitTest method testUsernameUpdateAccount.
// not supposed to update the username
@Test(expected = NoSuchUserException.class)
public void testUsernameUpdateAccount() throws SQLException, NoSuchUserException {
account = new Volunteer("test123", "test123", "test", "blocked", "test123@", 55);
db.updateAccount(account);
account = db.getAccountByUsername("test123");
}
use of pinkpanthers.pinkshelters.Model.Volunteer in project pink-panthers by MrTrai.
the class LoginActivity method logIn.
/**
* Check for user name, password and log the user in.
* Success: Direct User to Home Page
* Fail: Display Error
*
* @param view current view of the app
*/
public void logIn(@SuppressWarnings("unused") View view) {
txtView = findViewById(R.id.validationWarn);
try {
Editable userText = username.getText();
String user = userText.toString();
user = user.toLowerCase();
Editable passText = password.getText();
String pass = passText.toString();
account = db.getAccountByUsername(user);
txtView.setText("");
String blocked = "blocked";
String correctPass = account.getPassword();
String accountState = account.getAccountState();
if (correctPass.equals(pass) && !accountState.equals(blocked) && !accountState.equals("not_verified")) {
// correct password
Context context = getApplicationContext();
SharedPreferences preferences = context.getSharedPreferences("com.example.sp.LoginPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (account instanceof Homeless) {
editor.putString("USER_TYPE", "Homeless");
} else if (account instanceof Admin) {
editor.putString("USER_TYPE", "Admin");
} else if (account instanceof Volunteer) {
editor.putString("USER_TYPE", "Volunteer");
}
editor.putString("UserID", ((Integer) account.getUserId()).toString());
editor.putString("NAME", account.getName());
// get name to use for shelter details
editor.putString("USERNAME", account.getUsername());
editor.apply();
// active account is set to this static variable when
// logged in for quick access to current user
// Db.activeAccount = account;
db.logAction(account, "Logged in");
Intent homePageIntent = new Intent(this, HomePageActivity.class);
homePageIntent.putExtra("username", user);
startActivity(homePageIntent);
} else {
// incorrect password
loginTrial++;
checkLoginTrial();
}
} catch (NoSuchUserException e) {
// User doesn't exist
loginTrial++;
checkLoginTrial();
}
}
use of pinkpanthers.pinkshelters.Model.Volunteer in project pink-panthers by MrTrai.
the class DbUnitTest method testNegIdUpdateAccount.
// account with invalid id (negative)
@Test(expected = NoSuchUserException.class)
public void testNegIdUpdateAccount() throws SQLException, NoSuchUserException {
account = new Volunteer("test123", "test123", "test", "blocked", "test123@", -1);
db.updateAccount(account);
}
use of pinkpanthers.pinkshelters.Model.Volunteer in project pink-panthers by MrTrai.
the class DbUnitTest method testPosInvalidIdUpdateAccount.
// account with invalid id (positive)
@Test(expected = NoSuchUserException.class)
public void testPosInvalidIdUpdateAccount() throws SQLException, NoSuchUserException {
account = new Volunteer("test123", "test123", "test", "blocked", "test123@", 1000);
db.updateAccount(account);
}
use of pinkpanthers.pinkshelters.Model.Volunteer in project pink-panthers by MrTrai.
the class DbUnitTest method testNotHomelessUpdateAccount.
@Test
public void testNotHomelessUpdateAccount() throws SQLException, NoSuchUserException {
account = new Volunteer("test123", "test123", "test", "blocked", "test123@", 54);
db.updateAccount(account);
// correct username ad userId 54
account = db.getAccountByUsername("testcase5");
assertFalse("Account is not instance of Volunteer: ", account instanceof Volunteer);
assertTrue(account instanceof Homeless);
assertEquals(0, ((Homeless) account).getFamilyMemberNumber());
assertEquals(0, ((Homeless) account).getShelterId());
String[] expectedRestriction = { "" };
List<String> restrictionsMatch = ((Homeless) account).getRestrictionsMatch();
assertArrayEquals(expectedRestriction, restrictionsMatch.toArray());
}
Aggregations