[jboss-svn-commits] JBL Code SVN: r18598 - in labs/jbosslabs/labs-3.0-build: services/credential/src/main/java/org/jboss/labs/auth/impl and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Feb 26 12:30:38 EST 2008
Author: szimano
Date: 2008-02-26 12:30:37 -0500 (Tue, 26 Feb 2008)
New Revision: 18598
Modified:
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java
labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java
labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/CredentialTest.java
labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserTest.java
Log:
user test
Modified: labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java 2008-02-26 17:02:34 UTC (rev 18597)
+++ labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java 2008-02-26 17:30:37 UTC (rev 18598)
@@ -167,21 +167,43 @@
* @return Set of global super users.
*/
public Set<User> getSuperusers();
-
- /** Adds a role to a user
- * @param role Role to add
- * @param user User
- * @throws NoSuchUserException If user doesn't exist
- * @throws NoSuchUserRoleException If the role doesn't exist
+
+ /**
+ * Adds a role to a user
+ *
+ * @param role
+ * Role to add
+ * @param user
+ * User
+ * @throws NoSuchUserException
+ * If user doesn't exist
+ * @throws NoSuchUserRoleException
+ * If the role doesn't exist
*/
- public void addUserRoleToUser(Principal user, UserRole role) throws NoSuchUserException, NoSuchUserRoleException;
-
- /** Removes set of roles from a user
- * @param user User
- * @param userRoles Roles to remove
- * @throws NoSuchUserException If the use doesn't exist
- * @throws NoSuchUserRoleException If the role doesn't exist
- * @throws NoSuchRoleForUserException If the user doesn't have one of the role
+ public void addUserRoleToUser(Principal user, UserRole role)
+ throws NoSuchUserException, NoSuchUserRoleException;
+
+ /**
+ * Removes set of roles from a user
+ *
+ * @param user
+ * User
+ * @param userRoles
+ * Roles to remove
+ * @throws NoSuchUserException
+ * If the use doesn't exist
+ * @throws NoSuchUserRoleException
+ * If the role doesn't exist
+ * @throws NoSuchRoleForUserException
+ * If the user doesn't have one of the role
*/
- public void removeRolesFromUser(Principal user, UserRole... userRoles) throws NoSuchUserException, NoSuchUserRoleException, NoSuchRoleForUserException;
+ public void removeRolesFromUser(Principal user, UserRole... userRoles)
+ throws NoSuchUserException, NoSuchUserRoleException,
+ NoSuchRoleForUserException;
+
+ /** Removes user from database.
+ * @param user User to remove.
+ * @throws NoSuchUserException If the user doesn't exist.
+ */
+ public void removeUser(Principal user) throws NoSuchUserException;
}
Modified: labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java 2008-02-26 17:02:34 UTC (rev 18597)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java 2008-02-26 17:30:37 UTC (rev 18598)
@@ -326,5 +326,14 @@
manager.persist(userEn);
}
+
+ /* (non-Javadoc)
+ * @see org.jboss.labs.auth.UserService#removeUser(java.security.Principal)
+ */
+ public void removeUser(Principal user) throws NoSuchUserException {
+ User userEn = getUser(user);
+
+ manager.remove(userEn);
+ }
}
Modified: labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/CredentialTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/CredentialTest.java 2008-02-26 17:02:34 UTC (rev 18597)
+++ labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/CredentialTest.java 2008-02-26 17:30:37 UTC (rev 18598)
@@ -50,11 +50,18 @@
protected AuthenticationService authService;
protected String getUniqueUserID(String prefix) {
+ String newpref = prefix;
try {
- userService.getUserByLogin(prefix);
+ userService.getUserByLogin(newpref);
+
+ int i = 0;
+ while (true) {
+ newpref = prefix + i;
+ userService.getUserByLogin(newpref);
+ i++;
+ }
} catch (NoSuchUserException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return newpref;
}
}
}
Modified: labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserTest.java 2008-02-26 17:02:34 UTC (rev 18597)
+++ labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserTest.java 2008-02-26 17:30:37 UTC (rev 18598)
@@ -3,40 +3,72 @@
*/
package org.jboss.labs.test.credential;
+import org.jboss.labs.core.model.auth.User;
+import org.jboss.labs.exception.auth.NoSuchUserException;
+import org.jboss.labs.exception.auth.UserExistsException;
import org.junit.Test;
/*
* JBoss Labs. http://labs.jboss.com/jbosslabs
*
- * Copyright © 2008 Red Hat Middleware, LLC. All rights reserved.
+ * Copyright © 2008 Red Hat Middleware, LLC. All rights reserved.
*
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
*
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*
- * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
- * Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik, Tomasz
+ * Szymanski, Adam Warski, Pawel Wrzeszcz
*/
/**
* @author tomaszszymanski
- *
+ *
*/
public class UserTest extends CredentialTest {
-
+
@Test
- public void addUser() {
-
+ public void addDelUser() throws UserExistsException, NoSuchUserException {
+ String login = getUniqueUserID("test-user");
+
+ try {
+ userService.getUserByLogin(login);
+
+ // it shouldn't exist !
+ fail("User with login '" + login + "' already exists");
+ } catch (NoSuchUserException e) {
+ // we expected this
+ }
+
+ // create user
+ User u = new User(login);
+
+ // add user
+ userService.addNewUser(u);
+
+ // try to get him
+ u = userService.getUserByLogin(login);
+
+ // remove user
+ userService.removeUser(u);
+
+ // see if he was removed
+ try {
+ userService.getUserByLogin(login);
+ fail("USer with login '" + login + "' wasn't properly removed");
+ } catch (NoSuchUserException e) {
+ // it's expected
+ }
}
}
More information about the jboss-svn-commits
mailing list