001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestRoleUser.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.authentication.credentials;
009:
010: import com.uwyn.rife.site.ValidationError;
011: import java.util.Iterator;
012: import junit.framework.TestCase;
013:
014: public class TestRoleUser extends TestCase {
015: public TestRoleUser(String name) {
016: super (name);
017: }
018:
019: public void testInstantiation() {
020: RoleUser user = null;
021:
022: user = new RoleUser();
023:
024: assertNotNull(user);
025: }
026:
027: public void testInitialEmptyLogin() {
028: RoleUser user = new RoleUser();
029:
030: assertNull(user.getLogin());
031: }
032:
033: public void testInitialEmptyPassword() {
034: RoleUser user = new RoleUser();
035:
036: assertNull(user.getPassword());
037: }
038:
039: public void testInitialEmptyRole() {
040: RoleUser user = new RoleUser();
041:
042: assertNull(user.getRole());
043: }
044:
045: public void testPopulation() {
046: RoleUser user = new RoleUser();
047:
048: user.setLogin("the login");
049: user.setPassword("the password");
050: user.setRole("the role");
051:
052: assertEquals("the login", user.getLogin());
053: assertEquals("the password", user.getPassword());
054: assertEquals("the role", user.getRole());
055: }
056:
057: public void testValidation() {
058: RoleUser user = new RoleUser();
059:
060: Iterator<ValidationError> validationerrors_it = null;
061: ValidationError validationerror = null;
062:
063: assertTrue(false == user.validate());
064:
065: validationerrors_it = user.getValidationErrors().iterator();
066: assertTrue(validationerrors_it.hasNext());
067: validationerror = validationerrors_it.next();
068: assertEquals("MANDATORY", validationerror.getIdentifier());
069: assertEquals("login", validationerror.getSubject());
070: assertTrue(validationerrors_it.hasNext());
071: validationerror = validationerrors_it.next();
072: assertEquals("MANDATORY", validationerror.getIdentifier());
073: assertEquals("password", validationerror.getSubject());
074: assertTrue(false == validationerrors_it.hasNext());
075:
076: user.resetValidation();
077:
078: user.setLogin("e");
079: user.setPassword("f");
080:
081: assertTrue(false == user.validate());
082:
083: validationerrors_it = user.getValidationErrors().iterator();
084: assertTrue(validationerrors_it.hasNext());
085: validationerror = validationerrors_it.next();
086: assertEquals("WRONGLENGTH", validationerror.getIdentifier());
087: assertEquals("login", validationerror.getSubject());
088: assertTrue(validationerrors_it.hasNext());
089: validationerror = validationerrors_it.next();
090: assertEquals("WRONGLENGTH", validationerror.getIdentifier());
091: assertEquals("password", validationerror.getSubject());
092: assertTrue(false == validationerrors_it.hasNext());
093:
094: user.resetValidation();
095:
096: user.setLogin("alogin");
097: user.setPassword("apassword");
098:
099: assertTrue(user.validate());
100:
101: validationerrors_it = user.getValidationErrors().iterator();
102: assertTrue(false == validationerrors_it.hasNext());
103: }
104: }
|