Author: glandais Date: 2008-03-18 20:03:23 +0000 (Tue, 18 Mar 2008) New Revision: 1401 Added: trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties trunk/simexplorer-is/simexplorer-is-security/src/test/fr/ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java Modified: trunk/simexplorer-is/simexplorer-is-security/pom.xml Log: ejb3unit tests Modified: trunk/simexplorer-is/simexplorer-is-security/pom.xml =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/pom.xml 2008-03-18 20:02:53 UTC (rev 1400) +++ trunk/simexplorer-is/simexplorer-is-security/pom.xml 2008-03-18 20:03:23 UTC (rev 1401) @@ -44,6 +44,17 @@ </plugins> </build--> + <repositories> + <repository> + <snapshots> + <enabled>false</enabled> + </snapshots> + <id>ejb3unit</id> + <name>ejb3unit repository</name> + <url>http://ejb3unit.sourceforge.net/maven2</url> + </repository> + </repositories> + <dependencies> <dependency> <groupId>javax.persistence</groupId> @@ -68,11 +79,13 @@ <artifactId>h2</artifactId> <version>1.0.64</version> </dependency> - <!--dependency> - <groupId>jboss</groupId> - <artifactId>jbossall-client</artifactId> - <version>4.2.2.GA</version> - <scope>provided</scope> - </dependency--> + + <dependency> + <groupId>com.bm</groupId> + <artifactId>ejb3unit</artifactId> + <version>1.2</version> + <scope>test</scope> + </dependency> + </dependencies> </project> Added: trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,3 @@ +### The ejb3unit configuration file ### +ejb3unit.inMemoryTest=true +ejb3unit.show_sql=false Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,279 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.credentials; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityTransaction; + +import com.bm.introspectors.EntityBeanIntrospector; +import com.bm.testsuite.dataloader.EntityInitialDataSet; +import com.bm.utils.UndoScriptGenerator; + +import fr.cemagref.simexplorer.is.security.entities.Actor; +import fr.cemagref.simexplorer.is.security.entities.Group; +import fr.cemagref.simexplorer.is.security.entities.LoginAction; +import fr.cemagref.simexplorer.is.security.entities.Permission; +import fr.cemagref.simexplorer.is.security.entities.User; + +public class CredentialDataSet extends EntityInitialDataSet { + + private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory + .getLog(CredentialDataSet.class); + + protected EntityManager entityManager = null; + + private User user3; + + public static final int N_PERMISSIONS_USER3 = 378; + + public CredentialDataSet() { + // ... + super(Actor.class); + } + + public CredentialDataSet(Class entityType) { + super(entityType); + throw new IllegalStateException(); + } + + public void setEntityManager(EntityManager em) { + this.entityManager = em; + } + + @Override + public void cleanup(EntityManager em) { + EntityTransaction tx = entityManager.getTransaction(); + tx.begin(); + List resultList = entityManager.createQuery("SELECT a FROM Actor a").getResultList(); + for (Object object : resultList) { + Actor actor = (Actor) object; + actor.getGroups().clear(); + entityManager.merge(actor); + } + tx.commit(); + + tx.begin(); + entityManager.createQuery("DELETE FROM LoginAction").executeUpdate(); + entityManager.createQuery("DELETE FROM Permission").executeUpdate(); + entityManager.createQuery("DELETE FROM Group").executeUpdate(); + entityManager.createQuery("DELETE FROM User").executeUpdate(); + entityManager.createQuery("DELETE FROM Actor").executeUpdate(); + tx.commit(); + } + + @Override + public void create() { + User user1 = new User(); + user1.setAdmin(false); + user1.setSuperAdmin(false); + user1.setGroups(new ArrayList<Group>()); + user1.setLogin("user1"); + user1.setMail("user1 at user.user"); + user1.setVisible(true); + entityManager.persist(user1); + + User user2 = new User(); + user2.setAdmin(false); + user2.setSuperAdmin(false); + user2.setGroups(new ArrayList<Group>()); + user2.setLogin("user2"); + user2.setMail("user2 at user.user"); + user2.setVisible(true); + entityManager.persist(user2); + + user3 = new User(); + user3.setAdmin(false); + user3.setSuperAdmin(false); + user3.setGroups(new ArrayList<Group>()); + user3.setLogin("user3"); + user3.setMail("user3 at user.user"); + user3.setVisible(true); + entityManager.persist(user3); + + User user4 = new User(); + user4.setAdmin(false); + user4.setSuperAdmin(false); + user4.setGroups(new ArrayList<Group>()); + user4.setLogin("user4"); + user4.setMail("user4 at user.user"); + user4.setVisible(true); + entityManager.persist(user4); + + User admin = new User(); + admin.setAdmin(true); + admin.setSuperAdmin(false); + admin.setGroups(new ArrayList<Group>()); + admin.setLogin("admin"); + admin.setMail("admin at admin.admin"); + admin.setVisible(true); + entityManager.persist(admin); + + User superadmin = new User(); + superadmin.setAdmin(true); + superadmin.setSuperAdmin(true); + superadmin.setGroups(new ArrayList<Group>()); + superadmin.setLogin("superadmin"); + superadmin.setMail("superadmin at superadmin.superadmin"); + superadmin.setVisible(true); + entityManager.persist(superadmin); + + LoginAction loginActionUser1 = new LoginAction(); + loginActionUser1.setLoggedUser(user1); + loginActionUser1.setLoginDate((new Date()).getTime()); + loginActionUser1.setToken("user1"); + entityManager.persist(loginActionUser1); + + LoginAction loginActionUser2 = new LoginAction(); + loginActionUser2.setLoggedUser(user2); + loginActionUser2.setLoginDate((new Date()).getTime()); + loginActionUser2.setToken("user2"); + entityManager.persist(loginActionUser2); + + LoginAction loginActionUser4 = new LoginAction(); + loginActionUser4.setLoggedUser(user4); + loginActionUser4.setLoginDate((new Date()).getTime()); + loginActionUser4.setToken("user4"); + entityManager.persist(loginActionUser4); + + LoginAction loginActionAdmin = new LoginAction(); + loginActionAdmin.setLoggedUser(admin); + loginActionAdmin.setLoginDate((new Date()).getTime()); + loginActionAdmin.setToken("admin"); + entityManager.persist(loginActionAdmin); + + LoginAction loginActionSuperAdmin = new LoginAction(); + loginActionSuperAdmin.setLoggedUser(superadmin); + loginActionSuperAdmin.setLoginDate((new Date()).getTime()); + loginActionSuperAdmin.setToken("superadmin"); + entityManager.persist(loginActionSuperAdmin); + + Group groupA = new Group(); + groupA.setGroups(new ArrayList<Group>()); + groupA.setName("groupA"); + groupA.setOwner(admin); + groupA.setVisible(true); + entityManager.persist(groupA); + + Group groupB = new Group(); + groupB.setGroups(new ArrayList<Group>()); + groupB.setName("groupB"); + groupB.setOwner(admin); + groupB.setVisible(true); + entityManager.persist(groupB); + + user1.getGroups().add(groupA); + entityManager.merge(user1); + + user2.getGroups().add(groupB); + entityManager.merge(user2); + + user4.getGroups().add(groupB); + entityManager.merge(user4); + + Group groupC = new Group(); + groupC.setGroups(new ArrayList<Group>()); + groupC.setName("groupC"); + groupC.setOwner(admin); + groupC.setVisible(true); + entityManager.persist(groupC); + + groupB.getGroups().add(groupC); + entityManager.merge(groupB); + + Permission[] p = new Permission[6]; + int i = 0; + + p[i] = new Permission(); + p[i].setActor(user1); + p[i].setBusinessId("b" + i); + p[i].setCanRead(true); + p[i].setCanAdmin(true); + p[i].setCanWrite(true); + p[i].setOwner(true); + + i++; + p[i] = new Permission(); + p[i].setActor(user2); + p[i].setBusinessId("b" + i); + p[i].setCanRead(true); + p[i].setCanAdmin(true); + p[i].setCanWrite(true); + p[i].setOwner(true); + + i++; + p[i] = new Permission(); + p[i].setActor(groupA); + p[i].setBusinessId("b" + i); + p[i].setCanRead(true); + p[i].setCanAdmin(true); + p[i].setCanWrite(true); + p[i].setOwner(true); + + i++; + p[i] = new Permission(); + p[i].setActor(groupB); + p[i].setBusinessId("b" + i); + p[i].setCanRead(true); + p[i].setCanAdmin(true); + p[i].setCanWrite(true); + p[i].setOwner(true); + + i++; + p[i] = new Permission(); + p[i].setActor(groupC); + p[i].setBusinessId("b" + i); + p[i].setCanRead(true); + p[i].setCanAdmin(true); + p[i].setCanWrite(true); + p[i].setOwner(true); + + i++; + p[i] = new Permission(); + p[i].setActor(user4); + p[i].setBusinessId("b" + i); + p[i].setCanRead(true); + p[i].setCanAdmin(true); + p[i].setCanWrite(true); + p[i].setOwner(true); + + for (Permission permission : p) { + entityManager.persist(permission); + } + + for (int j = 0; j < N_PERMISSIONS_USER3; j++) { + Permission permission = new Permission(); + permission.setActor(user3); + permission.setBusinessId("u3_" + j); + permission.setCanRead(true); + permission.setCanAdmin(true); + permission.setCanWrite(true); + permission.setOwner(true); + entityManager.persist(permission); + } + + } + + public User getUser3() { + return user3; + } + +} Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,153 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.credentials; + +import java.util.Collection; +import java.util.List; + +import com.bm.testsuite.BaseSessionBeanFixture; + +import fr.cemagref.simexplorer.is.security.entities.Actor; +import fr.cemagref.simexplorer.is.security.entities.Group; +import fr.cemagref.simexplorer.is.security.entities.LoginAction; +import fr.cemagref.simexplorer.is.security.entities.Permission; +import fr.cemagref.simexplorer.is.security.entities.User; + +/** + * The Class CredentialManagerTestbase. + */ +public class CredentialManagerTestbase extends BaseSessionBeanFixture<CredentialManagerImpl> { + + private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory + .getLog(CredentialManagerTestbase.class); + + /** The Constant usedEntityBeans. */ + private static final Class<?>[] usedEntityBeans = { Permission.class, User.class, Group.class, Actor.class, + LoginAction.class }; + + private static CredentialDataSet credentialDataSet = new CredentialDataSet(); + + /** + * Instantiates a new credential manager testbase. + */ + public CredentialManagerTestbase() { + super(CredentialManagerImpl.class, usedEntityBeans, credentialDataSet); + } + + private CredentialManager getCredentialManager() { + return (CredentialManager) getBeanToTest(); + } + + private static void assertPermissionOk(Permission p, boolean onlyOwner) { + log.info(p); + if (!onlyOwner) { + assertTrue(p.isCanRead()); + assertTrue(p.isCanWrite()); + assertTrue(p.isCanAdmin()); + } + assertTrue(p.isOwner()); + } + + public void testGetPermission() { + assertPermissionOk(getCredentialManager().getPermission("user1", "b0"), false); + assertPermissionOk(getCredentialManager().getPermission("user2", "b1"), false); + assertPermissionOk(getCredentialManager().getPermission("user1", "b2"), false); + assertPermissionOk(getCredentialManager().getPermission("user2", "b3"), false); + assertPermissionOk(getCredentialManager().getPermission("user2", "b4"), false); + } + + public void testGetPermissions() { + Permission[] permissions; + for (int i = 0; i < 5; i++) { + permissions = getCredentialManager().getPermissions("b" + i); + assertEquals(permissions.length, 1); + } + } + + public void testSaveElement() { + getCredentialManager().saveElement("user1", "s0"); + assertPermissionOk(getCredentialManager().getPermission("user1", "s0"), true); + } + + public void testSetPermissions() { + getEntityManager().getTransaction().begin(); + getCredentialManager().saveElement("user1", "s1"); + getCredentialManager().saveElement("user2", "s1"); + getEntityManager().getTransaction().commit(); + Permission[] permissions = getCredentialManager().getPermissions("s1"); + for (Permission permission : permissions) { + permission.setOwner(false); + permission.setCanAdmin(false); + permission.setCanWrite(false); + permission.setCanRead(true); + } + + getEntityManager().getTransaction().begin(); + getCredentialManager().setPermissions("s1", permissions); + getEntityManager().getTransaction().commit(); + + for (int i = 1; i < 3; i++) { + Permission permission = getCredentialManager().getPermission("user" + i, "s1"); + assertFalse(permission.isCanAdmin()); + assertFalse(permission.isCanWrite()); + assertFalse(permission.isOwner()); + assertTrue(permission.isCanRead()); + } + } + + public void testGetPermissionsOwnedBy() { + List<Permission> permissionsOwnedBy = getCredentialManager().getPermissionsOwnedBy( + credentialDataSet.getUser3(), 0, credentialDataSet.N_PERMISSIONS_USER3); + for (Permission permission : permissionsOwnedBy) { + assertTrue(credentialDataSet.getUser3().equals(permission.getActor())); + assertPermissionOk(permission, false); + } + } + + public void testGetPermissionsOwnedByCount() { + int permissionsOwnedByCount = getCredentialManager().getPermissionsOwnedByCount(credentialDataSet.getUser3()); + assertEquals(permissionsOwnedByCount, credentialDataSet.N_PERMISSIONS_USER3); + } + + public void testGetElementsVisibleBy() { + Collection<String> elementsVisibleBy = getCredentialManager().getElementsVisibleBy("user4"); + assertTrue(elementsVisibleBy.contains("b3")); + assertTrue(elementsVisibleBy.contains("b4")); + assertTrue(elementsVisibleBy.contains("b5")); + assertEquals(elementsVisibleBy.size(), 3); + } + + public void testGetUserFilter() { + assertNotNull(getCredentialManager().getUserFilter("user1")); + assertNotNull(getCredentialManager().getUserFilter("user2")); + assertNotNull(getCredentialManager().getUserFilter("admin")); + assertNotNull(getCredentialManager().getUserFilter("superadmin")); + } + + public void testIsCacheValidFor() { + getCredentialManager().saveElement("user1", "c1"); + assertFalse(getCredentialManager().isCacheValidFor("user1")); + getCredentialManager().getElementsVisibleBy("user1"); + assertTrue(getCredentialManager().isCacheValidFor("user1")); + Permission[] permissions = new Permission[0]; + getCredentialManager().setPermissions("c1", permissions); + assertFalse(getCredentialManager().isCacheValidFor("user1")); + getCredentialManager().getElementsVisibleBy("user1"); + assertTrue(getCredentialManager().isCacheValidFor("user1")); + } +} Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,32 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.entities; + +/** + * The Class GroupTest. + */ +public class GroupTest extends SecurityEntityTest { + + /** + * Instantiates a new group test. + */ + public GroupTest() { + super(Group.class, SPECIAL_GENERATORS); + } + +} Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,32 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.entities; + +/** + * The Class LoginActionTest. + */ +public class LoginActionTest extends SecurityEntityTest { + + /** + * Instantiates a new login action test. + */ + public LoginActionTest() { + super(LoginAction.class, SPECIAL_GENERATORS); + } + +} Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,32 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.entities; + +/** + * The Class PermissionTest. + */ +public class PermissionTest extends SecurityEntityTest { + + /** + * Instantiates a new permission test. + */ + public PermissionTest() { + super(Permission.class, SPECIAL_GENERATORS); + } + +} Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,139 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.entities; + +import java.util.List; + +import com.bm.datagen.Generator; +import com.bm.datagen.annotations.GeneratorType; +import com.bm.datagen.relation.BeanCollectionGenerator; +import com.bm.datagen.relation.SingleBeanGenerator; +import com.bm.testsuite.BaseEntityFixture; + +/** + * The Class SecurityEntityTest. + */ + at SuppressWarnings("unchecked") +public abstract class SecurityEntityTest extends BaseEntityFixture { + + /** The Constant SPECIAL_GENERATORS. */ + protected static final Generator<?>[] SPECIAL_GENERATORS = { new GroupCreator(), new GroupsCreator(), + new ActorCreator(), new UserCreator(), new LoginActionCreator(), new PermissionCreator() }; + + /** + * Should not be called... + */ + public SecurityEntityTest() { + super(null); + } + + /** + * Instantiates a new security entity test. + * + * @param entityToTest the entity to test + * @param additionalGenerators the additional generators + */ + public SecurityEntityTest(Class<?> entityToTest, Generator<?>[] additionalGenerators) { + super(entityToTest, additionalGenerators); + } + + /** + * The Class GroupCreator. + */ + @GeneratorType(className = Group.class) + protected static final class GroupCreator extends SingleBeanGenerator<Group> { + + /** + * Instantiates a new group creator. + */ + protected GroupCreator() { + super(Group.class); + } + } + + /** + * The Class GroupsCreator. + */ + @GeneratorType(className = List.class, field = "groups") + protected static final class GroupsCreator extends BeanCollectionGenerator<Group> { + + /** + * Instantiates a new groups creator. + */ + protected GroupsCreator() { + super(Group.class, 10); + } + } + + /** + * The Class UserCreator. + */ + @GeneratorType(className = User.class) + protected static final class UserCreator extends SingleBeanGenerator<User> { + + /** + * Instantiates a new user creator. + */ + protected UserCreator() { + super(User.class); + } + } + + /** + * The Class UserCreator. + */ + @GeneratorType(className = Actor.class) + protected static final class ActorCreator extends SingleBeanGenerator { + + /** + * Instantiates a new user creator. + */ + protected ActorCreator() { + super(User.class); + } + } + + /** + * The Class LoginActionCreator. + */ + @GeneratorType(className = LoginAction.class) + protected static final class LoginActionCreator extends SingleBeanGenerator<LoginAction> { + + /** + * Instantiates a new login action creator. + */ + protected LoginActionCreator() { + super(LoginAction.class); + } + } + + /** + * The Class PermissionCreator. + */ + @GeneratorType(className = Permission.class) + protected static final class PermissionCreator extends SingleBeanGenerator<Permission> { + + /** + * Instantiates a new permission creator. + */ + protected PermissionCreator() { + super(Permission.class); + } + } + +} Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,46 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.entities; + +import fr.cemagref.simexplorer.is.security.credentials.CredentialManagerTestbase; +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * The Class SecurityEntityTests. + */ +public class SecurityEntityTests { + + /** + * Suite. + * + * @return the test + */ + public static Test suite() { + TestSuite suite = new TestSuite("Test for fr.cemagref.simexplorer.is.security.entities"); + // $JUnit-BEGIN$ + suite.addTestSuite(CredentialManagerTestbase.class); + suite.addTestSuite(UserTest.class); + suite.addTestSuite(GroupTest.class); + suite.addTestSuite(PermissionTest.class); + suite.addTestSuite(LoginActionTest.class); + // $JUnit-END$ + return suite; + } + +} Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java 2008-03-18 20:03:23 UTC (rev 1401) @@ -0,0 +1,32 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.security.entities; + +/** + * The Class UserTest. + */ +public class UserTest extends SecurityEntityTest { + + /** + * Instantiates a new user test. + */ + public UserTest() { + super(User.class, SPECIAL_GENERATORS); + } + +}