Code example for Principal

Methods: getName

0
        } 
    } 
     
    public void testCreateUserPrincipal() throws IOException 
    { 
        _database.createPrincipal(PRINCIPAL, PASSWORD.toCharArray());
        Principal newPrincipal = _database.getUser(PRINCIPAL_USERNAME);
        assertNotNull(newPrincipal);
        assertEquals(PRINCIPAL.getName(), newPrincipal.getName());
    } 
     
    public void testVerifyPassword() throws IOException, AccountNotFoundException 
    { 
        testCreateUserPrincipal(); 
        //assertFalse(_pwdDB.verifyPassword(_username, null)); 
        assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, new char[]{}));
        assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, (PASSWORD+"z").toCharArray()));
        assertTrue(_database.verifyPassword(PRINCIPAL_USERNAME, PASSWORD.toCharArray()));
         
        try 
        { 
            _database.verifyPassword("made.up.username", PASSWORD.toCharArray());
            fail("Should not have been able to verify this non-existant users password.");
        } 
        catch (AccountNotFoundException e)
        { 
            // pass 
        } 
    } 
     
    public void testUpdatePassword() throws IOException, AccountNotFoundException  
    { 
        testCreateUserPrincipal(); 
        char[] newPwd = "newpassword".toCharArray();
        _database.updatePassword(PRINCIPAL, newPwd);
        assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, PASSWORD.toCharArray()));
        assertTrue(_database.verifyPassword(PRINCIPAL_USERNAME, newPwd));
    } 
 
}