Search in sources :

Example 1 with Volunteer

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");
}
Also used : Volunteer(pinkpanthers.pinkshelters.Model.Volunteer) Test(org.junit.Test)

Example 2 with Volunteer

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();
    }
}
Also used : Context(android.content.Context) Homeless(pinkpanthers.pinkshelters.Model.Homeless) SharedPreferences(android.content.SharedPreferences) Volunteer(pinkpanthers.pinkshelters.Model.Volunteer) NoSuchUserException(pinkpanthers.pinkshelters.Model.NoSuchUserException) Editable(android.text.Editable) Intent(android.content.Intent) Admin(pinkpanthers.pinkshelters.Model.Admin)

Example 3 with Volunteer

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);
}
Also used : Volunteer(pinkpanthers.pinkshelters.Model.Volunteer) Test(org.junit.Test)

Example 4 with Volunteer

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);
}
Also used : Volunteer(pinkpanthers.pinkshelters.Model.Volunteer) Test(org.junit.Test)

Example 5 with Volunteer

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());
}
Also used : Homeless(pinkpanthers.pinkshelters.Model.Homeless) Volunteer(pinkpanthers.pinkshelters.Model.Volunteer) Test(org.junit.Test)

Aggregations

Volunteer (pinkpanthers.pinkshelters.Model.Volunteer)5 Test (org.junit.Test)4 Homeless (pinkpanthers.pinkshelters.Model.Homeless)2 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Editable (android.text.Editable)1 Admin (pinkpanthers.pinkshelters.Model.Admin)1 NoSuchUserException (pinkpanthers.pinkshelters.Model.NoSuchUserException)1