[jboss-svn-commits] JBL Code SVN: r18604 - in labs/jbosslabs/labs-3.0-build: services/credential and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Feb 27 11:02:46 EST 2008


Author: szimano
Date: 2008-02-27 11:02:46 -0500 (Wed, 27 Feb 2008)
New Revision: 18604

Added:
   labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserServiceTest.java
Removed:
   labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserTest.java
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/pom.xml
   labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.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
Log:
userservice tests

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-27 12:50:50 UTC (rev 18603)
+++ labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java	2008-02-27 16:02:46 UTC (rev 18604)
@@ -206,4 +206,6 @@
 	 * @throws NoSuchUserException If the user doesn't exist.
 	 */
 	public void removeUser(Principal user) throws NoSuchUserException;
+	
+	public UserRole getCommonRoleForProject(String projectID);
 }

Modified: labs/jbosslabs/labs-3.0-build/services/credential/pom.xml
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/pom.xml	2008-02-27 12:50:50 UTC (rev 18603)
+++ labs/jbosslabs/labs-3.0-build/services/credential/pom.xml	2008-02-27 16:02:46 UTC (rev 18604)
@@ -66,30 +66,6 @@
 			<version>1.4</version>
 			<scope>provided</scope>
 		</dependency>
-		<dependency>
-			<groupId>jboss.jboss-embeddable-ejb3</groupId>
-			<artifactId>jboss-ejb3-all</artifactId>
-			<version>1.0.0.Alpha9</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>jboss.jboss-embeddable-ejb3</groupId>
-			<artifactId>hibernate-all</artifactId>
-			<version>1.0.0.Alpha9</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>jboss.jboss-embeddable-ejb3</groupId>
-			<artifactId>thirdparty-all</artifactId>
-			<version>1.0.0.Alpha9</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>hibernate-commons-annotations</groupId>
-			<artifactId>hibernate-commons-annotations</artifactId>
-			<version>3.0.0.GA</version>
-			<scope>test</scope>
-		</dependency>
 	</dependencies>
 	<build>
 		<plugins>

Modified: labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.java	2008-02-27 12:50:50 UTC (rev 18603)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.java	2008-02-27 16:02:46 UTC (rev 18604)
@@ -36,6 +36,8 @@
 	
 	public static final String GLOBAL_PROJECT = "Labs::Global::Project";
 	
+	public static final String COMMON_ROLE_SUFIX = "_USERS";
+	
 	public static String countMD5(String password) {
 		try {
 			
@@ -58,4 +60,8 @@
 	public static <E extends Enum<E>> String getServiceRoleID(E serviceRole) {
 		return getServiceID(serviceRole) + "." + serviceRole.toString();
 	}
+	
+	public static String getCommonProjectId(String projectId) {
+		return projectId + COMMON_ROLE_SUFIX;
+	}
 }

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-27 12:50:50 UTC (rev 18603)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java	2008-02-27 16:02:46 UTC (rev 18604)
@@ -32,7 +32,6 @@
 import javax.ejb.Stateless;
 import javax.interceptor.Interceptors;
 import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
 
 import org.apache.log4j.Logger;
 import org.jboss.labs.auth.AuthHelper;
@@ -49,12 +48,13 @@
 import org.jboss.labs.injection.ejb3.LabsInjectionInterceptor;
 
 import com.google.inject.Inject;
+import com.google.inject.name.Named;
 
 @Stateless
 @Interceptors({LabsInjectionInterceptor.class})
 public class UserServiceImpl implements UserService {
 
-	@PersistenceContext(name = "auth_model")
+	@Inject @Named("auth_model")
 	private EntityManager manager;
 
 	@Inject
@@ -335,5 +335,25 @@
 		
 		manager.remove(userEn);
 	}
+
+	/* (non-Javadoc)
+	 * @see org.jboss.labs.auth.UserService#getCommonRoleForProject(java.lang.String)
+	 */
+	public UserRole getCommonRoleForProject(String projectId) {
+		UserRole u = null;
+		
+		try {
+			u = getUserRole(AuthHelper.getCommonProjectId(projectId));
+		} catch (NoSuchUserRoleException e) {
+			u = new UserRole(AuthHelper.getCommonProjectId(projectId), "Common role for project: "+projectId);
+			try {
+				addUserRole(u);
+			} catch (RoleExistsException e1) {
+				// not going to happen
+			}
+		}
+		
+		return u;
+	}
 	
 }

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-27 12:50:50 UTC (rev 18603)
+++ labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/CredentialTest.java	2008-02-27 16:02:46 UTC (rev 18604)
@@ -3,10 +3,17 @@
  */
 package org.jboss.labs.test.credential;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.jboss.labs.auth.AuthenticationService;
 import org.jboss.labs.auth.RoleBinderService;
 import org.jboss.labs.auth.UserService;
+import org.jboss.labs.core.model.auth.User;
+import org.jboss.labs.core.model.auth.UserRole;
 import org.jboss.labs.exception.auth.NoSuchUserException;
+import org.jboss.labs.exception.auth.NoSuchUserRoleException;
+import org.jboss.labs.exception.auth.UserExistsException;
 import org.jboss.labs.test.LabsTest;
 
 import com.google.inject.Inject;
@@ -49,6 +56,17 @@
 	@Inject
 	protected AuthenticationService authService;
 	
+	private final static String USER_ID = "TestUser";
+	
+	private final static String ROLE_ID = "TestRole";
+	
+	private Set<User> usersToDelete;
+	private Set<UserRole> rolesToDelete;
+	
+	protected String getUniqueUserID() {
+		return getUniqueUserID(USER_ID);
+	}
+	
 	protected String getUniqueUserID(String prefix) {
 		String newpref = prefix;
 		try {
@@ -64,4 +82,61 @@
 			return newpref;
 		}
 	}
+	
+	protected String getUniqueRoleID() {
+		return getUniqueRoleID(ROLE_ID);
+	}
+	
+	protected String getUniqueRoleID(String prefix) {
+		String newpref = prefix;
+		try {
+			userService.getUserRole(newpref);
+			
+			int i = 0;
+			while (true) {
+				newpref = prefix + i;
+				userService.getUserRole(newpref);
+				i++;
+			}
+		} catch (NoSuchUserRoleException e) {
+			return newpref;
+		}
+	}
+	
+	protected User getNewUser() throws UserExistsException {
+		User u = new User(getUniqueUserID(USER_ID));
+		
+		userService.addNewUser(u);
+		usersToDelete.add(u);
+		
+		return u;
+	}
+
+	protected UserRole getNewUserRole() {
+		String id = getUniqueRoleID(ROLE_ID);
+		
+		UserRole ur = new UserRole(id, "test role "+id);
+		rolesToDelete.add(ur);
+		
+		return ur;
+	}
+	
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		
+		for (User u : usersToDelete) {
+			userService.removeUser(u);
+		}
+		
+		for (UserRole ur : rolesToDelete) {
+			userService.removeUserRole(ur);
+		}
+	}
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		
+		usersToDelete = new HashSet<User>();
+		rolesToDelete = new HashSet<UserRole>();
+	}
 }

Copied: labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserServiceTest.java (from rev 18602, 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/UserServiceTest.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserServiceTest.java	2008-02-27 16:02:46 UTC (rev 18604)
@@ -0,0 +1,116 @@
+/**
+ * 
+ */
+package org.jboss.labs.test.credential;
+
+import org.jboss.labs.core.model.auth.User;
+import org.jboss.labs.core.model.auth.UserRole;
+import org.jboss.labs.exception.auth.NoSuchUserException;
+import org.jboss.labs.exception.auth.NoSuchUserRoleException;
+import org.jboss.labs.exception.auth.RoleExistsException;
+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.
+ * 
+ * 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.
+ * 
+ * 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
+ */
+
+/**
+ * @author tomaszszymanski
+ * 
+ */
+public class UserServiceTest extends CredentialTest {
+
+	public void testAddDelUser() throws UserExistsException, NoSuchUserException {
+		String login = getUniqueUserID();
+
+		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
+		}
+	}
+	
+	public void testAddDelRole() throws RoleExistsException, NoSuchUserRoleException {
+		String roleid = getUniqueRoleID();
+		
+		try {
+			userService.getUserRole(roleid);
+			
+			//shouldn't exist !
+			fail("Role with id: '"+roleid+"' already exists");
+		} catch (NoSuchUserRoleException e) {
+			// expected
+		}
+		
+		// create role
+		UserRole ur = new UserRole(roleid, "test role "+roleid);
+
+		// add role
+		userService.addUserRole(ur);
+ 
+		// try to get her
+		ur = userService.getUserRole(roleid);
+
+		// remove user
+		userService.removeUserRole(ur);
+
+		// see if he was removed
+		try {
+			userService.getUserRole(roleid);
+			
+			//shouldn't exist !
+			fail("Role with id: '"+roleid+"' already exists");
+		} catch (NoSuchUserRoleException e) {
+			// expected
+		}
+	}
+	
+	@Test
+	public void testRolesAndUsers() {
+		
+	}
+
+}

Deleted: 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-27 12:50:50 UTC (rev 18603)
+++ labs/jbosslabs/labs-3.0-build/views/labs-test/src/main/java/org/jboss/labs/test/credential/UserTest.java	2008-02-27 16:02:46 UTC (rev 18604)
@@ -1,74 +0,0 @@
-/**
- * 
- */
-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.
- * 
- * 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.
- * 
- * 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
- */
-
-/**
- * @author tomaszszymanski
- * 
- */
-public class UserTest extends CredentialTest {
-
-	@Test
-	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