Author: bdaw
Date: 2009-11-18 10:27:05 -0500 (Wed, 18 Nov 2009)
New Revision: 1013
Added:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/HibernateTestSupport.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/IdentityTestPOJO.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/LDAPTestPOJO.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APILDAPTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestContext.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupQueryTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupTypeEnum.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/MinimalFlexibleConfigTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/ModelTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationLDAPTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/PersistenceManagerTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RelationshipManagerTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleManagerTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleQueryTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/SimpleTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/UserQueryTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/EvilBinaryTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateModelTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java
Removed:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/HibernateTestSupport.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/IdentityTestPOJO.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/LDAPTestPOJO.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APILDAPTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestContext.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupQueryTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupTypeEnum.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/MinimalFlexibleConfigTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/ModelTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationLDAPTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/PersistenceManagerTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RelationshipManagerTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleManagerTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleQueryTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/SimpleTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/UserQueryTest.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/EvilBinaryTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateModelTestCase.java
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java
Log:
rename
Copied: migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink (from
rev 1005, migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity)
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/HibernateTestSupport.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/HibernateTestSupport.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/HibernateTestSupport.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,134 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl;
-
-import
org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectRelationshipType;
-import org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectType;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
-import java.util.logging.Logger;
-import java.sql.Connection;
-import java.sql.DriverManager;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class HibernateTestSupport
-{
- private static Logger logger =
Logger.getLogger(HibernateTestSupport.class.getName());
-
- protected SessionFactory sessionFactory;
-
- private Connection connection;
-
- private final String databaseName;
-
- private final String hibernateConfiguration;
-
- public HibernateTestSupport(String databaseName, String hibernateConfiguration)
- {
- this.databaseName = databaseName;
- this.hibernateConfiguration = hibernateConfiguration;
- }
-
- public SessionFactory getSessionFactory()
- {
- return sessionFactory;
- }
-
-
- public void start() throws Exception {
- try {
- logger.info("Starting in-memory HSQL database for unit tests");
- Class.forName("org.hsqldb.jdbcDriver");
- connection = DriverManager.getConnection("jdbc:hsqldb:mem:" +
databaseName, "sa", "");
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- logger.fine("Exception during HSQL database startup.");
- throw ex;
- }
- try
- {
- logger.info("Building JPA EntityManager for unit tests");
- sessionFactory = new
Configuration().configure(hibernateConfiguration).buildSessionFactory();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- logger.fine("Exception during JPA EntityManager instanciation.");
- throw ex;
- }
- }
-
- public void stop() throws Exception {
- logger.info("Shuting down Hibernate JPA layer.");
- if (sessionFactory != null)
- {
- sessionFactory.close();
- }
-
- logger.info("Stopping in-memory HSQL database.");
- try
- {
- connection.createStatement().execute("SHUTDOWN");
- }
- catch (Exception ex) {
- throw ex;
- }
- }
-
- public void populateObjectTypes(String[] typeNames) throws Exception
- {
-
- sessionFactory.getCurrentSession().getTransaction().begin();
-
- for (String typeName : typeNames)
- {
- HibernateIdentityObjectType hibernateType = new
HibernateIdentityObjectType(typeName);
- sessionFactory.getCurrentSession().persist(hibernateType);
- }
-
- sessionFactory.getCurrentSession().getTransaction().commit();
-
- }
-
- public void populateRelationshipTypes(String[] typeNames) throws Exception
- {
-
- sessionFactory.getCurrentSession().getTransaction().begin();
-
- for (String typeName : typeNames)
- {
- HibernateIdentityObjectRelationshipType hibernateType = new
HibernateIdentityObjectRelationshipType(typeName);
- sessionFactory.getCurrentSession().persist(hibernateType);
- }
-
- sessionFactory.getCurrentSession().getTransaction().commit();
- }
-
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/HibernateTestSupport.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/HibernateTestSupport.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/HibernateTestSupport.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/HibernateTestSupport.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,134 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl;
+
+import org.picketlink.idm.impl.model.hibernate.HibernateIdentityObjectRelationshipType;
+import org.picketlink.idm.impl.model.hibernate.HibernateIdentityObjectType;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+import java.util.logging.Logger;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class HibernateTestSupport
+{
+ private static Logger logger =
Logger.getLogger(HibernateTestSupport.class.getName());
+
+ protected SessionFactory sessionFactory;
+
+ private Connection connection;
+
+ private final String databaseName;
+
+ private final String hibernateConfiguration;
+
+ public HibernateTestSupport(String databaseName, String hibernateConfiguration)
+ {
+ this.databaseName = databaseName;
+ this.hibernateConfiguration = hibernateConfiguration;
+ }
+
+ public SessionFactory getSessionFactory()
+ {
+ return sessionFactory;
+ }
+
+
+ public void start() throws Exception {
+ try {
+ logger.info("Starting in-memory HSQL database for unit tests");
+ Class.forName("org.hsqldb.jdbcDriver");
+ connection = DriverManager.getConnection("jdbc:hsqldb:mem:" +
databaseName, "sa", "");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ logger.fine("Exception during HSQL database startup.");
+ throw ex;
+ }
+ try
+ {
+ logger.info("Building JPA EntityManager for unit tests");
+ sessionFactory = new
Configuration().configure(hibernateConfiguration).buildSessionFactory();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ logger.fine("Exception during JPA EntityManager instanciation.");
+ throw ex;
+ }
+ }
+
+ public void stop() throws Exception {
+ logger.info("Shuting down Hibernate JPA layer.");
+ if (sessionFactory != null)
+ {
+ sessionFactory.close();
+ }
+
+ logger.info("Stopping in-memory HSQL database.");
+ try
+ {
+ connection.createStatement().execute("SHUTDOWN");
+ }
+ catch (Exception ex) {
+ throw ex;
+ }
+ }
+
+ public void populateObjectTypes(String[] typeNames) throws Exception
+ {
+
+ sessionFactory.getCurrentSession().getTransaction().begin();
+
+ for (String typeName : typeNames)
+ {
+ HibernateIdentityObjectType hibernateType = new
HibernateIdentityObjectType(typeName);
+ sessionFactory.getCurrentSession().persist(hibernateType);
+ }
+
+ sessionFactory.getCurrentSession().getTransaction().commit();
+
+ }
+
+ public void populateRelationshipTypes(String[] typeNames) throws Exception
+ {
+
+ sessionFactory.getCurrentSession().getTransaction().begin();
+
+ for (String typeName : typeNames)
+ {
+ HibernateIdentityObjectRelationshipType hibernateType = new
HibernateIdentityObjectRelationshipType(typeName);
+ sessionFactory.getCurrentSession().persist(hibernateType);
+ }
+
+ sessionFactory.getCurrentSession().getTransaction().commit();
+ }
+
+
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/IdentityTestPOJO.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/IdentityTestPOJO.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/IdentityTestPOJO.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,220 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl;
-
-import org.jboss.portal.test.framework.embedded.ConnectionManagerSupport;
-import org.jboss.portal.test.framework.embedded.DataSourceSupport;
-import org.jboss.portal.test.framework.embedded.HibernateSupport;
-import org.jboss.portal.test.framework.embedded.JNDISupport;
-import org.jboss.portal.test.framework.embedded.TransactionManagerSupport;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import junit.framework.TestCase;
-import org.hibernate.SessionFactory;
-
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class IdentityTestPOJO extends TestCase
-{
-
- protected String identityConfig = "test-identity-config.xml";
-
- private String realmName;
-
- private String dataSourceName = "hsqldb";
-
- private String hibernateConfig = "datasources/hibernates.xml";
-
- private String datasources = "datasources/datasources.xml";
-
- private JNDISupport jndiSupport;
-
- protected TransactionManagerSupport transactonManagerSupport;
-
- protected ConnectionManagerSupport connectionManagerSupport;
-
- protected DataSourceSupport dataSourceSupport;
-
- protected HibernateSupport hibernateSupport;
-
-
-
- public void start() throws Exception
- {
- overrideFromProperties();
-
- jndiSupport = new JNDISupport();
- jndiSupport.start();
- transactonManagerSupport = new TransactionManagerSupport();
- transactonManagerSupport.start();
- connectionManagerSupport = new ConnectionManagerSupport();
-
connectionManagerSupport.setTransactionManager(transactonManagerSupport.getTransactionManager());
- connectionManagerSupport.start();
-
-
-
- DataSourceSupport.Config dataSourceConfig =
DataSourceSupport.Config.obtainConfig(datasources, dataSourceName);
-
- HibernateSupport.Config hibernateSupportConfig =
HibernateSupport.getConfig(dataSourceName, hibernateConfig);
-
- dataSourceSupport = new DataSourceSupport();
-
dataSourceSupport.setTransactionManager(transactonManagerSupport.getTransactionManager());
-
dataSourceSupport.setConnectionManagerReference(connectionManagerSupport.getConnectionManagerReference());
- dataSourceSupport.setConfig(dataSourceConfig);
- dataSourceSupport.start();
-
-// hibernateSupport = new HibernateAnnotationsSupport();
- hibernateSupport = new HibernateSupport();
- hibernateSupport.setConfig(hibernateSupportConfig);
-
hibernateSupport.setJNDIName("java:/jbossidentity/HibernateStoreSessionFactory");
-
- String prefix = "mappings/";
-
- //Sybase support hack
- if (dataSourceName.startsWith("sybase-"))
- {
- prefix = "sybase-mappings/";
- }
-
- List<String> mappings = new LinkedList<String>();
- mappings.add(prefix + "HibernateIdentityObject.hbm.xml");
- mappings.add(prefix +
"HibernateIdentityObjectCredentialBinaryValue.hbm.xml");
- mappings.add(prefix +
"HibernateIdentityObjectAttributeBinaryValue.hbm.xml");
- mappings.add(prefix + "HibernateIdentityObjectAttribute.hbm.xml");
- mappings.add(prefix + "HibernateIdentityObjectCredential.hbm.xml");
- mappings.add(prefix + "HibernateIdentityObjectCredentialType.hbm.xml");
- mappings.add(prefix + "HibernateIdentityObjectRelationship.hbm.xml");
- mappings.add(prefix +
"HibernateIdentityObjectRelationshipName.hbm.xml");
- mappings.add(prefix +
"HibernateIdentityObjectRelationshipType.hbm.xml");
- mappings.add(prefix + "HibernateIdentityObjectType.hbm.xml");
- mappings.add(prefix + "HibernateRealm.hbm.xml");
-
- hibernateSupport.setMappings(mappings);
-
- hibernateSupport.start();
-
-
- }
-
- public void stop() throws Exception
- {
- hibernateSupport.getSessionFactory().getStatistics().logSummary();
- hibernateSupport.stop();
- dataSourceSupport.stop();
- connectionManagerSupport.stop();
- transactonManagerSupport.stop();
- jndiSupport.stop();
-
-
- }
-
- public void overrideFromProperties() throws Exception
- {
- String dsName = System.getProperties().getProperty("dataSourceName");
-
- if (dsName != null && !dsName.startsWith("$"))
- {
- setDataSourceName(dsName);
- }
-
- }
-
- public SessionFactory getSessionFactory()
- {
- return getHibernateSupport().getSessionFactory();
- }
-
- public void setDataSourceName(String dataSourceName)
- {
- this.dataSourceName = dataSourceName;
- }
-
- public void setHibernateConfig(String hibernateConfig)
- {
- this.hibernateConfig = hibernateConfig;
- }
-
- public void setDatasources(String datasources)
- {
- this.datasources = datasources;
- }
-
- public void setIdentityConfig(String identityConfig)
- {
- this.identityConfig = identityConfig;
- }
-
- public void setRealmName(String realmName)
- {
- this.realmName = realmName;
- }
-
- public String getDataSourceName()
- {
- return dataSourceName;
- }
-
- public String getHibernateConfig()
- {
- return hibernateConfig;
- }
-
- public String getDatasources()
- {
- return datasources;
- }
-
- public String getIdentityConfig()
- {
- return identityConfig;
- }
-
- public String getRealmName()
- {
- return realmName;
- }
-
- public HibernateSupport getHibernateSupport()
- {
- return hibernateSupport;
- }
-
- public void begin()
- {
- getHibernateSupport().openSession();
- }
-
- public void commit()
- {
- assertTrue(getHibernateSupport().commitTransaction());
- }
-
-
-
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/IdentityTestPOJO.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/IdentityTestPOJO.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/IdentityTestPOJO.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/IdentityTestPOJO.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,220 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl;
+
+import org.jboss.portal.test.framework.embedded.ConnectionManagerSupport;
+import org.jboss.portal.test.framework.embedded.DataSourceSupport;
+import org.jboss.portal.test.framework.embedded.HibernateSupport;
+import org.jboss.portal.test.framework.embedded.JNDISupport;
+import org.jboss.portal.test.framework.embedded.TransactionManagerSupport;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.hibernate.SessionFactory;
+
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class IdentityTestPOJO extends TestCase
+{
+
+ protected String identityConfig = "test-identity-config.xml";
+
+ private String realmName;
+
+ private String dataSourceName = "hsqldb";
+
+ private String hibernateConfig = "datasources/hibernates.xml";
+
+ private String datasources = "datasources/datasources.xml";
+
+ private JNDISupport jndiSupport;
+
+ protected TransactionManagerSupport transactonManagerSupport;
+
+ protected ConnectionManagerSupport connectionManagerSupport;
+
+ protected DataSourceSupport dataSourceSupport;
+
+ protected HibernateSupport hibernateSupport;
+
+
+
+ public void start() throws Exception
+ {
+ overrideFromProperties();
+
+ jndiSupport = new JNDISupport();
+ jndiSupport.start();
+ transactonManagerSupport = new TransactionManagerSupport();
+ transactonManagerSupport.start();
+ connectionManagerSupport = new ConnectionManagerSupport();
+
connectionManagerSupport.setTransactionManager(transactonManagerSupport.getTransactionManager());
+ connectionManagerSupport.start();
+
+
+
+ DataSourceSupport.Config dataSourceConfig =
DataSourceSupport.Config.obtainConfig(datasources, dataSourceName);
+
+ HibernateSupport.Config hibernateSupportConfig =
HibernateSupport.getConfig(dataSourceName, hibernateConfig);
+
+ dataSourceSupport = new DataSourceSupport();
+
dataSourceSupport.setTransactionManager(transactonManagerSupport.getTransactionManager());
+
dataSourceSupport.setConnectionManagerReference(connectionManagerSupport.getConnectionManagerReference());
+ dataSourceSupport.setConfig(dataSourceConfig);
+ dataSourceSupport.start();
+
+// hibernateSupport = new HibernateAnnotationsSupport();
+ hibernateSupport = new HibernateSupport();
+ hibernateSupport.setConfig(hibernateSupportConfig);
+
hibernateSupport.setJNDIName("java:/jbossidentity/HibernateStoreSessionFactory");
+
+ String prefix = "mappings/";
+
+ //Sybase support hack
+ if (dataSourceName.startsWith("sybase-"))
+ {
+ prefix = "sybase-mappings/";
+ }
+
+ List<String> mappings = new LinkedList<String>();
+ mappings.add(prefix + "HibernateIdentityObject.hbm.xml");
+ mappings.add(prefix +
"HibernateIdentityObjectCredentialBinaryValue.hbm.xml");
+ mappings.add(prefix +
"HibernateIdentityObjectAttributeBinaryValue.hbm.xml");
+ mappings.add(prefix + "HibernateIdentityObjectAttribute.hbm.xml");
+ mappings.add(prefix + "HibernateIdentityObjectCredential.hbm.xml");
+ mappings.add(prefix + "HibernateIdentityObjectCredentialType.hbm.xml");
+ mappings.add(prefix + "HibernateIdentityObjectRelationship.hbm.xml");
+ mappings.add(prefix +
"HibernateIdentityObjectRelationshipName.hbm.xml");
+ mappings.add(prefix +
"HibernateIdentityObjectRelationshipType.hbm.xml");
+ mappings.add(prefix + "HibernateIdentityObjectType.hbm.xml");
+ mappings.add(prefix + "HibernateRealm.hbm.xml");
+
+ hibernateSupport.setMappings(mappings);
+
+ hibernateSupport.start();
+
+
+ }
+
+ public void stop() throws Exception
+ {
+ hibernateSupport.getSessionFactory().getStatistics().logSummary();
+ hibernateSupport.stop();
+ dataSourceSupport.stop();
+ connectionManagerSupport.stop();
+ transactonManagerSupport.stop();
+ jndiSupport.stop();
+
+
+ }
+
+ public void overrideFromProperties() throws Exception
+ {
+ String dsName = System.getProperties().getProperty("dataSourceName");
+
+ if (dsName != null && !dsName.startsWith("$"))
+ {
+ setDataSourceName(dsName);
+ }
+
+ }
+
+ public SessionFactory getSessionFactory()
+ {
+ return getHibernateSupport().getSessionFactory();
+ }
+
+ public void setDataSourceName(String dataSourceName)
+ {
+ this.dataSourceName = dataSourceName;
+ }
+
+ public void setHibernateConfig(String hibernateConfig)
+ {
+ this.hibernateConfig = hibernateConfig;
+ }
+
+ public void setDatasources(String datasources)
+ {
+ this.datasources = datasources;
+ }
+
+ public void setIdentityConfig(String identityConfig)
+ {
+ this.identityConfig = identityConfig;
+ }
+
+ public void setRealmName(String realmName)
+ {
+ this.realmName = realmName;
+ }
+
+ public String getDataSourceName()
+ {
+ return dataSourceName;
+ }
+
+ public String getHibernateConfig()
+ {
+ return hibernateConfig;
+ }
+
+ public String getDatasources()
+ {
+ return datasources;
+ }
+
+ public String getIdentityConfig()
+ {
+ return identityConfig;
+ }
+
+ public String getRealmName()
+ {
+ return realmName;
+ }
+
+ public HibernateSupport getHibernateSupport()
+ {
+ return hibernateSupport;
+ }
+
+ public void begin()
+ {
+ getHibernateSupport().openSession();
+ }
+
+ public void commit()
+ {
+ assertTrue(getHibernateSupport().commitTransaction());
+ }
+
+
+
+
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/LDAPTestPOJO.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/LDAPTestPOJO.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/LDAPTestPOJO.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,213 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl;
-
-import org.jboss.identity.idm.opends.OpenDSService;
-import org.jboss.portal.test.framework.embedded.DSConfig;
-import org.jboss.unit.api.pojo.annotations.Parameter;
-
-import java.net.URL;
-import java.util.Hashtable;
-
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.directory.DirContext;
-import javax.naming.ldap.InitialLdapContext;
-import javax.naming.ldap.LdapContext;
-
-import org.opends.server.tools.LDAPModify;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class LDAPTestPOJO extends IdentityTestPOJO
-{
-
- private String EMBEDDED_OPEN_DS_DIRECTORY_NAME = "EmbeddedOpenDS";
-
- protected DSConfig directoryConfig;
-
- private String directories = "datasources/directories.xml";
-
- //By default use embedded OpenDS
- private String directoryName = EMBEDDED_OPEN_DS_DIRECTORY_NAME;
-
- public static Hashtable<String,String> env = new
Hashtable<String,String>();
-
- OpenDSService openDSService = new OpenDSService(null);
-
- @Override
- public void start() throws Exception
- {
-
- overrideFromProperties();
-
- directoryConfig = DSConfig.obtainConfig(directories, directoryName);
-
- identityConfig = directoryConfig.getConfigFile();
-
- super.start();
-
- env.put(Context.INITIAL_CONTEXT_FACTORY, directoryConfig.getContextFactory());
- //Use description to store URL to be able to prefix with "ldaps://"
- env.put(Context.PROVIDER_URL, directoryConfig.getDescription());
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, directoryConfig.getAdminDN());
- env.put(Context.SECURITY_CREDENTIALS, directoryConfig.getAdminPassword());
-
- if (directoryName.equals(EMBEDDED_OPEN_DS_DIRECTORY_NAME))
- {
- openDSService.start();
- }
- }
-
- @Override
- public void stop() throws Exception
- {
- cleanUp(new InitialLdapContext(env, null));
-
- super.stop();
-
- if (directoryName.equals(EMBEDDED_OPEN_DS_DIRECTORY_NAME))
- {
- openDSService.stop();
- }
-
- }
-
- public void overrideFromProperties() throws Exception
- {
- super.overrideFromProperties();
-
- String dirName = System.getProperties().getProperty("directoryName");
-
- if (dirName != null && !dirName.startsWith("$"))
- {
- setDirectoryName(dirName);
- }
-
- String trustStorePath =
System.getProperties().getProperty("trustStorePath");
-
- if (trustStorePath != null && !trustStorePath.startsWith("$"))
- {
- System.setProperty("javax.net.ssl.trustStore", trustStorePath);
- }
-
- String trustStorePassword =
System.getProperties().getProperty("trustStorePassword");
-
- if (trustStorePassword != null &&
!trustStorePassword.startsWith("$"))
- {
- System.setProperty("javax.net.ssl.trustStorePassword",
trustStorePassword);
- }
-
- }
-
- @Parameter
- public void setDirectoryName(String directoryName)
- {
- this.directoryName = directoryName;
- }
-
- public String getDirectoryName()
- {
- return directoryName;
- }
-
-// public void populate() throws Exception
-// {
-// populateLDIF("ldap/initial-opends.ldif");
-// }
-
- public void populateClean() throws Exception
- {
- populateLDIF(directoryConfig.getPopulateLdif());
- }
-
- public void populateLDIF(String ldif) throws Exception
- {
-
- URL ldifURL = Thread.currentThread().getContextClassLoader().getResource(ldif);
-
- System.out.println("LDIF: " + ldifURL.toURI().getPath());
-
- String[] cmd = new String[] {"-h", directoryConfig.getHost(),
- "-p", directoryConfig.getPort(),
- "-D", directoryConfig.getAdminDN(),
- "-w", directoryConfig.getAdminPassword(),
- "-a", "-f", ldifURL.toURI().getPath()};
-
- //Not sure why... but it actually does make a difference...
- if (directoryName.equals(EMBEDDED_OPEN_DS_DIRECTORY_NAME))
- {
- System.out.println("Populate success: " + (LDAPModify.mainModify(cmd,
false, System.out, System.err) == 0));
- }
- else
- {
- System.out.println("Populate success: " + (LDAPModify.mainModify(cmd)
== 0));
- }
- }
-
- protected void cleanUp(DirContext ldapCtx) throws Exception
- {
- try
- {
- String dn = directoryConfig.getCleanUpDN();
-
- System.out.println("Removing: " + dn);
-
- removeContext(ldapCtx, dn);
- }
- catch (Exception e)
- {
- //
- }
- }
-
- //subsequent remove of javax.naming.Context
- protected void removeContext(Context mainCtx, String name) throws Exception
- {
- Context deleteCtx = (Context)mainCtx.lookup(name);
- NamingEnumeration subDirs = mainCtx.listBindings(name);
-
- while (subDirs.hasMoreElements())
- {
- Binding binding = (Binding)subDirs.nextElement();
- String subName = binding.getName();
-
- removeContext(deleteCtx, subName);
- }
-
- mainCtx.unbind(name);
- }
-
-
- public LdapContext getLdapContext() throws Exception
- {
- return new InitialLdapContext(env, null);
- }
-
-
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/LDAPTestPOJO.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/LDAPTestPOJO.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/LDAPTestPOJO.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/LDAPTestPOJO.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,213 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl;
+
+import org.picketlink.idm.opends.OpenDSService;
+import org.jboss.portal.test.framework.embedded.DSConfig;
+import org.jboss.unit.api.pojo.annotations.Parameter;
+
+import java.net.URL;
+import java.util.Hashtable;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.opends.server.tools.LDAPModify;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class LDAPTestPOJO extends IdentityTestPOJO
+{
+
+ private String EMBEDDED_OPEN_DS_DIRECTORY_NAME = "EmbeddedOpenDS";
+
+ protected DSConfig directoryConfig;
+
+ private String directories = "datasources/directories.xml";
+
+ //By default use embedded OpenDS
+ private String directoryName = EMBEDDED_OPEN_DS_DIRECTORY_NAME;
+
+ public static Hashtable<String,String> env = new
Hashtable<String,String>();
+
+ OpenDSService openDSService = new OpenDSService(null);
+
+ @Override
+ public void start() throws Exception
+ {
+
+ overrideFromProperties();
+
+ directoryConfig = DSConfig.obtainConfig(directories, directoryName);
+
+ identityConfig = directoryConfig.getConfigFile();
+
+ super.start();
+
+ env.put(Context.INITIAL_CONTEXT_FACTORY, directoryConfig.getContextFactory());
+ //Use description to store URL to be able to prefix with "ldaps://"
+ env.put(Context.PROVIDER_URL, directoryConfig.getDescription());
+ env.put(Context.SECURITY_AUTHENTICATION, "simple");
+ env.put(Context.SECURITY_PRINCIPAL, directoryConfig.getAdminDN());
+ env.put(Context.SECURITY_CREDENTIALS, directoryConfig.getAdminPassword());
+
+ if (directoryName.equals(EMBEDDED_OPEN_DS_DIRECTORY_NAME))
+ {
+ openDSService.start();
+ }
+ }
+
+ @Override
+ public void stop() throws Exception
+ {
+ cleanUp(new InitialLdapContext(env, null));
+
+ super.stop();
+
+ if (directoryName.equals(EMBEDDED_OPEN_DS_DIRECTORY_NAME))
+ {
+ openDSService.stop();
+ }
+
+ }
+
+ public void overrideFromProperties() throws Exception
+ {
+ super.overrideFromProperties();
+
+ String dirName = System.getProperties().getProperty("directoryName");
+
+ if (dirName != null && !dirName.startsWith("$"))
+ {
+ setDirectoryName(dirName);
+ }
+
+ String trustStorePath =
System.getProperties().getProperty("trustStorePath");
+
+ if (trustStorePath != null && !trustStorePath.startsWith("$"))
+ {
+ System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+ }
+
+ String trustStorePassword =
System.getProperties().getProperty("trustStorePassword");
+
+ if (trustStorePassword != null &&
!trustStorePassword.startsWith("$"))
+ {
+ System.setProperty("javax.net.ssl.trustStorePassword",
trustStorePassword);
+ }
+
+ }
+
+ @Parameter
+ public void setDirectoryName(String directoryName)
+ {
+ this.directoryName = directoryName;
+ }
+
+ public String getDirectoryName()
+ {
+ return directoryName;
+ }
+
+// public void populate() throws Exception
+// {
+// populateLDIF("ldap/initial-opends.ldif");
+// }
+
+ public void populateClean() throws Exception
+ {
+ populateLDIF(directoryConfig.getPopulateLdif());
+ }
+
+ public void populateLDIF(String ldif) throws Exception
+ {
+
+ URL ldifURL = Thread.currentThread().getContextClassLoader().getResource(ldif);
+
+ System.out.println("LDIF: " + ldifURL.toURI().getPath());
+
+ String[] cmd = new String[] {"-h", directoryConfig.getHost(),
+ "-p", directoryConfig.getPort(),
+ "-D", directoryConfig.getAdminDN(),
+ "-w", directoryConfig.getAdminPassword(),
+ "-a", "-f", ldifURL.toURI().getPath()};
+
+ //Not sure why... but it actually does make a difference...
+ if (directoryName.equals(EMBEDDED_OPEN_DS_DIRECTORY_NAME))
+ {
+ System.out.println("Populate success: " + (LDAPModify.mainModify(cmd,
false, System.out, System.err) == 0));
+ }
+ else
+ {
+ System.out.println("Populate success: " + (LDAPModify.mainModify(cmd)
== 0));
+ }
+ }
+
+ protected void cleanUp(DirContext ldapCtx) throws Exception
+ {
+ try
+ {
+ String dn = directoryConfig.getCleanUpDN();
+
+ System.out.println("Removing: " + dn);
+
+ removeContext(ldapCtx, dn);
+ }
+ catch (Exception e)
+ {
+ //
+ }
+ }
+
+ //subsequent remove of javax.naming.Context
+ protected void removeContext(Context mainCtx, String name) throws Exception
+ {
+ Context deleteCtx = (Context)mainCtx.lookup(name);
+ NamingEnumeration subDirs = mainCtx.listBindings(name);
+
+ while (subDirs.hasMoreElements())
+ {
+ Binding binding = (Binding)subDirs.nextElement();
+ String subName = binding.getName();
+
+ removeContext(deleteCtx, subName);
+ }
+
+ mainCtx.unbind(name);
+ }
+
+
+ public LdapContext getLdapContext() throws Exception
+ {
+ return new InitialLdapContext(env, null);
+ }
+
+
+
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APILDAPTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/APILDAPTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APILDAPTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,129 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.impl.LDAPTestPOJO;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class APILDAPTestCase extends LDAPTestPOJO implements APITestContext
-{
-
- PersistenceManagerTest persistenceManagerTest;
-
- RelationshipManagerTest relationshipManagerTest;
-
- RoleManagerTest roleManagerTest;
-
- UserQueryTest userQueryTest;
-
- GroupQueryTest groupQueryTest;
-
- RoleQueryTest roleQueryTest;
-
- IdentitySessionFactory identitySessionFactory;
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
- persistenceManagerTest = new PersistenceManagerTest(this);
- relationshipManagerTest = new RelationshipManagerTest(this);
- roleManagerTest = new RoleManagerTest(this);
-
- userQueryTest = new UserQueryTest(this);
- groupQueryTest = new GroupQueryTest(this);
- roleQueryTest = new RoleQueryTest(this);
-
- setRealmName("realm://RedHat/DB_LDAP");
-
- populateClean();
-
-
- identitySessionFactory = new IdentityConfigurationImpl().
- configure(getIdentityConfig()).buildIdentitySessionFactory();
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- public IdentitySessionFactory getIdentitySessionFactory()
- {
- return identitySessionFactory;
- }
-
- @Test
- public void testPersistenceManager() throws Exception
- {
- persistenceManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testRelationshipManager() throws Exception
- {
- relationshipManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testRelationshipManagerCascade() throws Exception
- {
- relationshipManagerTest.testCascade(getRealmName());
- }
-
- @Test
- public void testRelationshipManagerMergedRoleAssociations() throws Exception
- {
- relationshipManagerTest.testMergedRoleAssociations(getRealmName());
- }
-
- @Test
- public void testRoleManager() throws Exception
- {
- roleManagerTest.testMethods(getRealmName());
- }
-
- public void testUserQuery() throws Exception
- {
- userQueryTest.testQuery(getRealmName());
- }
-
- public void testGroupQuery() throws Exception
- {
- groupQueryTest.testQuery(getRealmName());
- }
-
- public void testRoleQuery() throws Exception
- {
- roleQueryTest.testQuery(getRealmName());
- }
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APILDAPTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/APILDAPTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APILDAPTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APILDAPTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,129 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.impl.LDAPTestPOJO;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class APILDAPTestCase extends LDAPTestPOJO implements APITestContext
+{
+
+ PersistenceManagerTest persistenceManagerTest;
+
+ RelationshipManagerTest relationshipManagerTest;
+
+ RoleManagerTest roleManagerTest;
+
+ UserQueryTest userQueryTest;
+
+ GroupQueryTest groupQueryTest;
+
+ RoleQueryTest roleQueryTest;
+
+ IdentitySessionFactory identitySessionFactory;
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+ persistenceManagerTest = new PersistenceManagerTest(this);
+ relationshipManagerTest = new RelationshipManagerTest(this);
+ roleManagerTest = new RoleManagerTest(this);
+
+ userQueryTest = new UserQueryTest(this);
+ groupQueryTest = new GroupQueryTest(this);
+ roleQueryTest = new RoleQueryTest(this);
+
+ setRealmName("realm://RedHat/DB_LDAP");
+
+ populateClean();
+
+
+ identitySessionFactory = new IdentityConfigurationImpl().
+ configure(getIdentityConfig()).buildIdentitySessionFactory();
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ public IdentitySessionFactory getIdentitySessionFactory()
+ {
+ return identitySessionFactory;
+ }
+
+ @Test
+ public void testPersistenceManager() throws Exception
+ {
+ persistenceManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManager() throws Exception
+ {
+ relationshipManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManagerCascade() throws Exception
+ {
+ relationshipManagerTest.testCascade(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManagerMergedRoleAssociations() throws Exception
+ {
+ relationshipManagerTest.testMergedRoleAssociations(getRealmName());
+ }
+
+ @Test
+ public void testRoleManager() throws Exception
+ {
+ roleManagerTest.testMethods(getRealmName());
+ }
+
+ public void testUserQuery() throws Exception
+ {
+ userQueryTest.testQuery(getRealmName());
+ }
+
+ public void testGroupQuery() throws Exception
+ {
+ groupQueryTest.testQuery(getRealmName());
+ }
+
+ public void testRoleQuery() throws Exception
+ {
+ roleQueryTest.testQuery(getRealmName());
+ }
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/APITestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,131 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.impl.IdentityTestPOJO;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class APITestCase extends IdentityTestPOJO implements APITestContext
-{
-
- PersistenceManagerTest persistenceManagerTest;
-
- RelationshipManagerTest relationshipManagerTest;
-
- RoleManagerTest roleManagerTest;
-
- UserQueryTest userQueryTest;
-
- GroupQueryTest groupQueryTest;
-
- RoleQueryTest roleQueryTest;
-
- IdentitySessionFactory identitySessionFactory;
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
- persistenceManagerTest = new PersistenceManagerTest(this);
- relationshipManagerTest = new RelationshipManagerTest(this);
- roleManagerTest = new RoleManagerTest(this);
-
- userQueryTest = new UserQueryTest(this);
- groupQueryTest = new GroupQueryTest(this);
- roleQueryTest = new RoleQueryTest(this);
-
- setRealmName("realm://RedHat/DB");
-
-
- identitySessionFactory = new IdentityConfigurationImpl().
- configure(getIdentityConfig()).buildIdentitySessionFactory();
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- public IdentitySessionFactory getIdentitySessionFactory()
- {
- return identitySessionFactory;
- }
-
- @Test
- public void testPersistenceManager() throws Exception
- {
- persistenceManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testRelationshipManager() throws Exception
- {
- relationshipManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testRelationshipManagerCascade() throws Exception
- {
- relationshipManagerTest.testCascade(getRealmName());
- }
-
- @Test
- public void testRelationshipManagerMergedRoleAssociations() throws Exception
- {
- relationshipManagerTest.testMergedRoleAssociations(getRealmName());
- }
-
- @Test
- public void testRoleManager() throws Exception
- {
- roleManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testUserQuery() throws Exception
- {
- userQueryTest.testQuery(getRealmName());
- }
-
- @Test
- public void testGroupQuery() throws Exception
- {
- groupQueryTest.testQuery(getRealmName());
- }
-
- @Test
- public void testRoleQuery() throws Exception
- {
- roleQueryTest.testQuery(getRealmName());
- }
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/APITestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,131 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.impl.IdentityTestPOJO;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class APITestCase extends IdentityTestPOJO implements APITestContext
+{
+
+ PersistenceManagerTest persistenceManagerTest;
+
+ RelationshipManagerTest relationshipManagerTest;
+
+ RoleManagerTest roleManagerTest;
+
+ UserQueryTest userQueryTest;
+
+ GroupQueryTest groupQueryTest;
+
+ RoleQueryTest roleQueryTest;
+
+ IdentitySessionFactory identitySessionFactory;
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+ persistenceManagerTest = new PersistenceManagerTest(this);
+ relationshipManagerTest = new RelationshipManagerTest(this);
+ roleManagerTest = new RoleManagerTest(this);
+
+ userQueryTest = new UserQueryTest(this);
+ groupQueryTest = new GroupQueryTest(this);
+ roleQueryTest = new RoleQueryTest(this);
+
+ setRealmName("realm://RedHat/DB");
+
+
+ identitySessionFactory = new IdentityConfigurationImpl().
+ configure(getIdentityConfig()).buildIdentitySessionFactory();
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ public IdentitySessionFactory getIdentitySessionFactory()
+ {
+ return identitySessionFactory;
+ }
+
+ @Test
+ public void testPersistenceManager() throws Exception
+ {
+ persistenceManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManager() throws Exception
+ {
+ relationshipManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManagerCascade() throws Exception
+ {
+ relationshipManagerTest.testCascade(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManagerMergedRoleAssociations() throws Exception
+ {
+ relationshipManagerTest.testMergedRoleAssociations(getRealmName());
+ }
+
+ @Test
+ public void testRoleManager() throws Exception
+ {
+ roleManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testUserQuery() throws Exception
+ {
+ userQueryTest.testQuery(getRealmName());
+ }
+
+ @Test
+ public void testGroupQuery() throws Exception
+ {
+ groupQueryTest.testQuery(getRealmName());
+ }
+
+ @Test
+ public void testRoleQuery() throws Exception
+ {
+ roleQueryTest.testQuery(getRealmName());
+ }
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestContext.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/APITestContext.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestContext.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,41 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public interface APITestContext
-{
-
-
- IdentitySessionFactory getIdentitySessionFactory();
-
- void begin();
-
- void commit();
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestContext.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/APITestContext.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestContext.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/APITestContext.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,41 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySessionFactory;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface APITestContext
+{
+
+
+ IdentitySessionFactory getIdentitySessionFactory();
+
+ void begin();
+
+ void commit();
+
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupQueryTest.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/GroupQueryTest.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupQueryTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,128 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.User;
-import org.jboss.identity.idm.api.Group;
-import org.jboss.identity.idm.api.RoleType;
-import org.jboss.identity.idm.api.Role;
-import org.jboss.identity.idm.api.query.GroupQueryBuilder;
-import junit.framework.Assert;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class GroupQueryTest extends Assert
-{
- private APITestContext ctx;
-
- private String ORGANIZATION = "ORGANIZATION";
- private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
- private String DEPARTMENT = "DEPARTMENT";
-
- public GroupQueryTest(APITestContext testContext)
- {
- this.ctx = testContext;
- }
-
- public void testQuery(String realmName) throws Exception
- {
- ctx.begin();
-
- IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
-
- // Create stuff
-
- User user1 = ids.getPersistenceManager().createUser("user1");
- User user2 = ids.getPersistenceManager().createUser("user2");
- User user3 = ids.getPersistenceManager().createUser("user3");
- User user4 = ids.getPersistenceManager().createUser("user4");
-
- Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
- Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
- Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
- Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
- Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
-
- ids.getRelationshipManager().associateUser(group1, user1);
- ids.getRelationshipManager().associateUser(group1, user2);
- ids.getRelationshipManager().associateUser(group2, user3);
- ids.getRelationshipManager().associateGroups(group2, group3);
-
- RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
- RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
- RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
- RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
-
- Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
- Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
- Role role3 = ids.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
-
- // Assertions
-
- GroupQueryBuilder qb = ids.createGroupQueryBuilder();
-
- qb.addAssociatedUser(user1);
-
- assertEquals(1, ids.execute(qb.createQuery()).size());
- assertEquals(group1, ids.uniqueResult(qb.createQuery()));
-
- //
- qb.reset();
-
- qb.addAssociatedUser(user1);
- qb.addAssociatedUser(user2);
-
- assertEquals(1, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addAssociatedUser(user1);
- qb.addRelatedUser(user2);
-
- assertEquals(1, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addAssociatedUser(user1);
- qb.addRelatedUser(user4);
-
- assertEquals(0, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addAssociatedUser(user3);
- qb.addAssociatedGroup(group3, false);
-
- assertEquals(1, ids.execute(qb.createQuery()).size());
- assertEquals(group2, ids.uniqueResult(qb.createQuery()));
-
-
- ctx.commit();
- }
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupQueryTest.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/GroupQueryTest.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupQueryTest.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupQueryTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,128 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.RoleType;
+import org.picketlink.idm.api.Role;
+import org.picketlink.idm.api.query.GroupQueryBuilder;
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class GroupQueryTest extends Assert
+{
+ private APITestContext ctx;
+
+ private String ORGANIZATION = "ORGANIZATION";
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ private String DEPARTMENT = "DEPARTMENT";
+
+ public GroupQueryTest(APITestContext testContext)
+ {
+ this.ctx = testContext;
+ }
+
+ public void testQuery(String realmName) throws Exception
+ {
+ ctx.begin();
+
+ IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
+
+ // Create stuff
+
+ User user1 = ids.getPersistenceManager().createUser("user1");
+ User user2 = ids.getPersistenceManager().createUser("user2");
+ User user3 = ids.getPersistenceManager().createUser("user3");
+ User user4 = ids.getPersistenceManager().createUser("user4");
+
+ Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+ ids.getRelationshipManager().associateUser(group1, user1);
+ ids.getRelationshipManager().associateUser(group1, user2);
+ ids.getRelationshipManager().associateUser(group2, user3);
+ ids.getRelationshipManager().associateGroups(group2, group3);
+
+ RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
+ RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
+ RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
+ RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
+
+ Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
+ Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
+ Role role3 = ids.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
+
+ // Assertions
+
+ GroupQueryBuilder qb = ids.createGroupQueryBuilder();
+
+ qb.addAssociatedUser(user1);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(group1, ids.uniqueResult(qb.createQuery()));
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user1);
+ qb.addAssociatedUser(user2);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user1);
+ qb.addRelatedUser(user2);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user1);
+ qb.addRelatedUser(user4);
+
+ assertEquals(0, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user3);
+ qb.addAssociatedGroup(group3, false);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(group2, ids.uniqueResult(qb.createQuery()));
+
+
+ ctx.commit();
+ }
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupTypeEnum.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/GroupTypeEnum.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupTypeEnum.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,48 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-
-package org.jboss.identity.idm.impl.api;
-
-
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public enum GroupTypeEnum
-{
- ADMINISTRATION,
- ORGANIZATION,
- DIVISION,
- DEPARTMENT,
- PROJECT,
- SECURITY,
- COMMUNITY,
- OFFICE,
- CUSTOM;
-
- public String getName()
- {
- return this.name();
- }
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupTypeEnum.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/GroupTypeEnum.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupTypeEnum.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/GroupTypeEnum.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,48 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+
+package org.picketlink.idm.impl.api;
+
+
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public enum GroupTypeEnum
+{
+ ADMINISTRATION,
+ ORGANIZATION,
+ DIVISION,
+ DEPARTMENT,
+ PROJECT,
+ SECURITY,
+ COMMUNITY,
+ OFFICE,
+ CUSTOM;
+
+ public String getName()
+ {
+ return this.name();
+ }
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/MinimalFlexibleConfigTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/MinimalFlexibleConfigTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/MinimalFlexibleConfigTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,150 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.impl.IdentityTestPOJO;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Test;
-import org.jboss.unit.api.pojo.annotations.Parameter;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class MinimalFlexibleConfigTestCase extends IdentityTestPOJO implements
APITestContext
-{
- private OrganizationTest orgTest;
-
- private PersistenceManagerTest persistenceManagerTest;
-
- private RelationshipManagerTest relationshipManagerTest;
-
- private RoleManagerTest roleManagerTest;
-
- private UserQueryTest userQueryTest;
-
- private GroupQueryTest groupQueryTest;
-
- private RoleQueryTest roleQueryTest;
-
- private IdentitySessionFactory identitySessionFactory;
-
- @Create
- public void setUp() throws Exception
- {
- setIdentityConfig("minimal-flexible-identity-config.xml");
- setRealmName("realm://FlexibleRealm");
-
- super.start();
-
- orgTest = new OrganizationTest(this);
-
- persistenceManagerTest = new PersistenceManagerTest(this);
- relationshipManagerTest = new RelationshipManagerTest(this);
- roleManagerTest = new RoleManagerTest(this);
-
- userQueryTest = new UserQueryTest(this);
- groupQueryTest = new GroupQueryTest(this);
- roleQueryTest = new RoleQueryTest(this);
-
- identitySessionFactory = new IdentityConfigurationImpl().
- configure(getIdentityConfig()).buildIdentitySessionFactory();
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- public IdentitySessionFactory getIdentitySessionFactory()
- {
- return identitySessionFactory;
- }
-
- @Test
- public void testOrganization() throws Exception
- {
-
- orgTest.testRedHatOrganization(getRealmName());
- }
-
- @Test
- public void testSamplePortal() throws Exception
- {
-
- orgTest.testSamplePortal(getRealmName());
- }
-
- @Test
- public void testPersistenceManager() throws Exception
- {
- persistenceManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testRelationshipManager() throws Exception
- {
- relationshipManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testRelationshipManagerCascade() throws Exception
- {
- relationshipManagerTest.testCascade(getRealmName());
- }
-
- @Test
- public void testRelationshipManagerMergedRoleAssociations() throws Exception
- {
- relationshipManagerTest.testMergedRoleAssociations(getRealmName());
- }
-
- @Test
- public void testRoleManager() throws Exception
- {
- roleManagerTest.testMethods(getRealmName());
- }
-
- @Test
- public void testUserQuery() throws Exception
- {
- userQueryTest.testQuery(getRealmName());
- }
-
- @Test
- public void testGroupQuery() throws Exception
- {
- groupQueryTest.testQuery(getRealmName());
- }
-
- @Test
- public void testRoleQuery() throws Exception
- {
- roleQueryTest.testQuery(getRealmName());
- }
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/MinimalFlexibleConfigTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/MinimalFlexibleConfigTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/MinimalFlexibleConfigTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/MinimalFlexibleConfigTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,150 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.impl.IdentityTestPOJO;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.jboss.unit.api.pojo.annotations.Parameter;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class MinimalFlexibleConfigTestCase extends IdentityTestPOJO implements
APITestContext
+{
+ private OrganizationTest orgTest;
+
+ private PersistenceManagerTest persistenceManagerTest;
+
+ private RelationshipManagerTest relationshipManagerTest;
+
+ private RoleManagerTest roleManagerTest;
+
+ private UserQueryTest userQueryTest;
+
+ private GroupQueryTest groupQueryTest;
+
+ private RoleQueryTest roleQueryTest;
+
+ private IdentitySessionFactory identitySessionFactory;
+
+ @Create
+ public void setUp() throws Exception
+ {
+ setIdentityConfig("minimal-flexible-identity-config.xml");
+ setRealmName("realm://FlexibleRealm");
+
+ super.start();
+
+ orgTest = new OrganizationTest(this);
+
+ persistenceManagerTest = new PersistenceManagerTest(this);
+ relationshipManagerTest = new RelationshipManagerTest(this);
+ roleManagerTest = new RoleManagerTest(this);
+
+ userQueryTest = new UserQueryTest(this);
+ groupQueryTest = new GroupQueryTest(this);
+ roleQueryTest = new RoleQueryTest(this);
+
+ identitySessionFactory = new IdentityConfigurationImpl().
+ configure(getIdentityConfig()).buildIdentitySessionFactory();
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ public IdentitySessionFactory getIdentitySessionFactory()
+ {
+ return identitySessionFactory;
+ }
+
+ @Test
+ public void testOrganization() throws Exception
+ {
+
+ orgTest.testRedHatOrganization(getRealmName());
+ }
+
+ @Test
+ public void testSamplePortal() throws Exception
+ {
+
+ orgTest.testSamplePortal(getRealmName());
+ }
+
+ @Test
+ public void testPersistenceManager() throws Exception
+ {
+ persistenceManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManager() throws Exception
+ {
+ relationshipManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManagerCascade() throws Exception
+ {
+ relationshipManagerTest.testCascade(getRealmName());
+ }
+
+ @Test
+ public void testRelationshipManagerMergedRoleAssociations() throws Exception
+ {
+ relationshipManagerTest.testMergedRoleAssociations(getRealmName());
+ }
+
+ @Test
+ public void testRoleManager() throws Exception
+ {
+ roleManagerTest.testMethods(getRealmName());
+ }
+
+ @Test
+ public void testUserQuery() throws Exception
+ {
+ userQueryTest.testQuery(getRealmName());
+ }
+
+ @Test
+ public void testGroupQuery() throws Exception
+ {
+ groupQueryTest.testQuery(getRealmName());
+ }
+
+ @Test
+ public void testRoleQuery() throws Exception
+ {
+ roleQueryTest.testQuery(getRealmName());
+ }
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/ModelTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/ModelTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/ModelTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,49 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import junit.framework.TestCase;
-import org.jboss.identity.idm.impl.api.model.GroupKey;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class ModelTestCase extends TestCase
-{
-
- public void testGroupId() throws Exception
- {
-
- GroupKey key = new GroupKey(GroupKey.PREFIX + GroupKey.SEPARATOR +
"groupTypeName" + GroupKey.SEPARATOR + "groupName");
- assertEquals("groupName", key.getName());
- assertEquals("groupTypeName", key.getType());
-
- key = new GroupKey("groupName", "groupTypeName");
- assertEquals("groupName", key.getName());
- assertEquals("groupTypeName", key.getType());
-
- }
-
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/ModelTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/ModelTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/ModelTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/ModelTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,49 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import junit.framework.TestCase;
+import org.picketlink.idm.impl.api.model.GroupKey;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class ModelTestCase extends TestCase
+{
+
+ public void testGroupId() throws Exception
+ {
+
+ GroupKey key = new GroupKey(GroupKey.PREFIX + GroupKey.SEPARATOR +
"groupTypeName" + GroupKey.SEPARATOR + "groupName");
+ assertEquals("groupName", key.getName());
+ assertEquals("groupTypeName", key.getType());
+
+ key = new GroupKey("groupName", "groupTypeName");
+ assertEquals("groupName", key.getName());
+ assertEquals("groupTypeName", key.getType());
+
+ }
+
+
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationLDAPTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/OrganizationLDAPTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationLDAPTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,108 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.impl.LDAPTestPOJO;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Parameter;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class OrganizationLDAPTestCase extends LDAPTestPOJO implements APITestContext
-{
- private OrganizationTest orgTest;
-
- private IdentitySessionFactory identitySessionFactory;
-
- private String samplePortalRealmName =
"realm://portal/SamplePortal/DB_LDAP";
-
- private String sampleOrganizationRealmName = "realm://RedHat/DB_LDAP";
-
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
-
- orgTest = new OrganizationTest(this);
-
- populateClean();
-
- identitySessionFactory = new IdentityConfigurationImpl().
- configure(getIdentityConfig()).buildIdentitySessionFactory();
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- public IdentitySessionFactory getIdentitySessionFactory()
- {
- return identitySessionFactory;
- }
-
- @Test
- public void testOrganization() throws Exception
- {
-
- orgTest.testRedHatOrganization(getSampleOrganizationRealmName());
- }
-
- @Test
- public void testSamplePortal() throws Exception
- {
-
- orgTest.testSamplePortal(getSamplePortalRealmName());
-
- }
-
- public String getSamplePortalRealmName()
- {
- return samplePortalRealmName;
- }
-
- @Parameter
- public void setSamplePortalRealmName(String samplePortalRealmName)
- {
- this.samplePortalRealmName = samplePortalRealmName;
- }
-
- public String getSampleOrganizationRealmName()
- {
- return sampleOrganizationRealmName;
- }
-
- @Parameter
- public void setSampleOrganizationRealmName(String sampleOrganizationRealmName)
- {
- this.sampleOrganizationRealmName = sampleOrganizationRealmName;
- }
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationLDAPTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/OrganizationLDAPTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationLDAPTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationLDAPTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,108 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.impl.LDAPTestPOJO;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Parameter;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class OrganizationLDAPTestCase extends LDAPTestPOJO implements APITestContext
+{
+ private OrganizationTest orgTest;
+
+ private IdentitySessionFactory identitySessionFactory;
+
+ private String samplePortalRealmName =
"realm://portal/SamplePortal/DB_LDAP";
+
+ private String sampleOrganizationRealmName = "realm://RedHat/DB_LDAP";
+
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+
+ orgTest = new OrganizationTest(this);
+
+ populateClean();
+
+ identitySessionFactory = new IdentityConfigurationImpl().
+ configure(getIdentityConfig()).buildIdentitySessionFactory();
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ public IdentitySessionFactory getIdentitySessionFactory()
+ {
+ return identitySessionFactory;
+ }
+
+ @Test
+ public void testOrganization() throws Exception
+ {
+
+ orgTest.testRedHatOrganization(getSampleOrganizationRealmName());
+ }
+
+ @Test
+ public void testSamplePortal() throws Exception
+ {
+
+ orgTest.testSamplePortal(getSamplePortalRealmName());
+
+ }
+
+ public String getSamplePortalRealmName()
+ {
+ return samplePortalRealmName;
+ }
+
+ @Parameter
+ public void setSamplePortalRealmName(String samplePortalRealmName)
+ {
+ this.samplePortalRealmName = samplePortalRealmName;
+ }
+
+ public String getSampleOrganizationRealmName()
+ {
+ return sampleOrganizationRealmName;
+ }
+
+ @Parameter
+ public void setSampleOrganizationRealmName(String sampleOrganizationRealmName)
+ {
+ this.sampleOrganizationRealmName = sampleOrganizationRealmName;
+ }
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTest.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/OrganizationTest.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,653 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.Group;
-import org.jboss.identity.idm.api.User;
-import org.jboss.identity.idm.api.RoleType;
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.api.Attribute;
-import org.jboss.identity.idm.api.AttributeDescription;
-import org.jboss.identity.idm.api.Credential;
-import org.jboss.identity.idm.common.p3p.P3PConstants;
-import org.jboss.identity.idm.common.exception.IdentityException;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Random;
-import java.util.Arrays;
-
-import junit.framework.Assert;
-
-/**
- * Abstract test mapping real life structures using the API
- *
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class OrganizationTest extends Assert
-{
- APITestContext ctx;
-
- public OrganizationTest(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public void setCtx(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public APITestContext getCtx()
- {
- return ctx;
- }
-
- public void testRedHatOrganization(String realmName) throws Exception
- {
- // GroupType
-
- String ORGANIZATION = "ORGANIZATION";
- String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
- String DIVISION = "DIVISION";
- String DEPARTMENT = "DEPARTMENT";
- String PROJECT = "PROJECT";
- String PEOPLE = "PEOPLE";
-
- IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
-
- IdentitySession session = factory.createIdentitySession(realmName);
-
- //ctx.begin();
-
- ctx.begin();
-
- // Organization structure
-
- Group rhOrg = session.getPersistenceManager().createGroup("RedHat",
ORGANIZATION);
-
- Group jbossDivision =
session.getPersistenceManager().createGroup("JBoss", DIVISION);
- Group rhelDivision = session.getPersistenceManager().createGroup("RHEL",
DIVISION);
-
- session.getRelationshipManager().associateGroups(rhOrg, jbossDivision);
- session.getRelationshipManager().associateGroups(rhOrg, rhelDivision);
-
- Group itDepartment = session.getPersistenceManager().createGroup("IT",
DEPARTMENT);
- Group hrDepartment = session.getPersistenceManager().createGroup("HR",
DEPARTMENT);
-
- session.getRelationshipManager().associateGroups(jbossDivision, itDepartment);
- session.getRelationshipManager().associateGroups(jbossDivision, hrDepartment);
-
- Group rndDepartment = session.getPersistenceManager().createGroup("RnD",
DEPARTMENT);
-
- session.getRelationshipManager().associateGroups(itDepartment, rndDepartment);
-
- Group projectsOU =
session.getPersistenceManager().createGroup("Projects", ORGANIZATION_UNIT);
- Group commonFrameworksOU = session.getPersistenceManager().createGroup("Common
Frameworks", ORGANIZATION_UNIT);
-
- session.getRelationshipManager().associateGroups(rndDepartment, projectsOU);
-
- // Projects
-
- Group portalProject =
session.getPersistenceManager().createGroup("Portal", PROJECT);
- Group soaProject = session.getPersistenceManager().createGroup("SOA",
PROJECT);
- Group jbpmProject = session.getPersistenceManager().createGroup("jBPM",
PROJECT);
- Group seamProject = session.getPersistenceManager().createGroup("Seam",
PROJECT);
- Group asProject = session.getPersistenceManager().createGroup("AS",
PROJECT);
- Group securityProject =
session.getPersistenceManager().createGroup("Security", PROJECT);
-
- session.getRelationshipManager().associateGroups(projectsOU, portalProject);
- session.getRelationshipManager().associateGroups(projectsOU, soaProject);
- session.getRelationshipManager().associateGroups(projectsOU, jbpmProject);
- session.getRelationshipManager().associateGroups(projectsOU, asProject);
- session.getRelationshipManager().associateGroups(projectsOU, seamProject);
-
- // Check...
- assertTrue(session.getRelationshipManager().isAssociated(projectsOU,
portalProject));
- assertTrue(session.getRelationshipManager().isAssociated(projectsOU, soaProject));
- assertTrue(session.getRelationshipManager().isAssociated(projectsOU,
jbpmProject));
- assertTrue(session.getRelationshipManager().isAssociated(projectsOU, asProject));
- assertTrue(session.getRelationshipManager().isAssociated(projectsOU,
seamProject));
-
- // Portal is part of common frameworks
- session.getRelationshipManager().associateGroups(commonFrameworksOU,
portalProject);
-
- // People
-
- Group employeesGroup =
session.getPersistenceManager().createGroup("Employees", PEOPLE);
-
- // Management
-
- User theuteUser = session.getPersistenceManager().createUser("theute");
- User mlittleUser =
session.getPersistenceManager().createUser("mlittle");
- User bgeorgesUser =
session.getPersistenceManager().createUser("bgeorges");
- User asaldhanaUser =
session.getPersistenceManager().createUser("asaldhana");
- User janderseUser =
session.getPersistenceManager().createUser("janderse");
-
- // Portal Team
-
- User bdawidowUser =
session.getPersistenceManager().createUser("bdawidow");
- User claprunUser =
session.getPersistenceManager().createUser("claprun");
- User whalesUser = session.getPersistenceManager().createUser("whales");
- User sshahUser = session.getPersistenceManager().createUser("sshah");
- User mwringeUser =
session.getPersistenceManager().createUser("mwringe");
-
- // Store as employees
-
- session.getRelationshipManager().associateUser(employeesGroup, theuteUser);
- session.getRelationshipManager().associateUser(employeesGroup, mlittleUser);
- session.getRelationshipManager().associateUser(employeesGroup, asaldhanaUser);
- session.getRelationshipManager().associateUser(employeesGroup, bdawidowUser);
- session.getRelationshipManager().associateUser(employeesGroup, claprunUser);
- session.getRelationshipManager().associateUser(employeesGroup, whalesUser);
- session.getRelationshipManager().associateUser(employeesGroup, sshahUser);
- session.getRelationshipManager().associateUser(employeesGroup, mwringeUser);
-
- // Portal team for management purposes
-
- Group portalTeamGroup = session.getPersistenceManager().createGroup("Portal
Team", PEOPLE);
- session.getRelationshipManager().associateUser(portalTeamGroup, bdawidowUser);
- session.getRelationshipManager().associateUser(portalTeamGroup, claprunUser);
- session.getRelationshipManager().associateUser(portalTeamGroup, whalesUser);
- session.getRelationshipManager().associateUser(portalTeamGroup, sshahUser);
- session.getRelationshipManager().associateUser(portalTeamGroup, mwringeUser);
-
- // Portal team is under common frameworks
-
- session.getRelationshipManager().associateGroups(commonFrameworksOU,
portalTeamGroup);
-
- // Role Types
-
- RoleType developerRT =
session.getRoleManager().createRoleType("Developer");
- RoleType managerRT = session.getRoleManager().createRoleType("Manager");
- RoleType leadDeveloperRT = session.getRoleManager().createRoleType("Lead
Developer");
- RoleType productManagerRT = session.getRoleManager().createRoleType("Product
Manager");
-
- // Assign roles
-
- // Common frameworks manager
-
- session.getRoleManager().createRole(managerRT, bgeorgesUser, commonFrameworksOU);
-
- // Portal developers
-
- session.getRoleManager().createRole(developerRT, theuteUser, portalProject);
- session.getRoleManager().createRole(developerRT, bdawidowUser, portalProject);
- session.getRoleManager().createRole(developerRT, claprunUser, portalProject);
- session.getRoleManager().createRole(developerRT, whalesUser, portalProject);
- session.getRoleManager().createRole(developerRT, sshahUser, portalProject);
- session.getRoleManager().createRole(developerRT, mwringeUser, portalProject);
-
- // Portal management
- session.getRoleManager().createRole(leadDeveloperRT, theuteUser, portalProject);
- session.getRoleManager().createRole(managerRT, theuteUser, portalTeamGroup);
- session.getRoleManager().createRole(productManagerRT, janderseUser,
portalProject);
-
- // SOA
-
- session.getRoleManager().createRole(developerRT, mlittleUser, portalProject);
- session.getRoleManager().createRole(productManagerRT, mlittleUser, portalProject);
-
- // AS & Security
-
- session.getRoleManager().createRole(developerRT, asaldhanaUser, asProject);
- session.getRoleManager().createRole(developerRT, asaldhanaUser, securityProject);
- session.getRoleManager().createRole(leadDeveloperRT, asaldhanaUser,
securityProject);
-
-
- // Check what RoleTypes has user theute
- Collection<RoleType> roleTypes =
session.getRoleManager().findUserRoleTypes(theuteUser);
- assertEquals(3, roleTypes.size());
- assertTrue(roleTypes.contains(developerRT));
- assertTrue(roleTypes.contains(leadDeveloperRT));
- assertTrue(roleTypes.contains(managerRT));
- assertFalse(roleTypes.contains(productManagerRT));
-
- assertTrue(session.getRoleManager().hasRole(theuteUser, portalProject,
developerRT));
- assertTrue(session.getRoleManager().hasRole(theuteUser, portalProject,
leadDeveloperRT));
- assertTrue(session.getRoleManager().hasRole(theuteUser, portalTeamGroup,
managerRT));
-
- // Check where anil is Lead Developer and where Developer
-
- roleTypes = session.getRoleManager().findUserRoleTypes(asaldhanaUser);
- assertEquals(2, roleTypes.size());
- assertTrue(roleTypes.contains(developerRT));
- assertTrue(roleTypes.contains(leadDeveloperRT));
-
- roleTypes = session.getRoleManager().findRoleTypes(asaldhanaUser,
securityProject);
- assertEquals(2, roleTypes.size());
- assertTrue(roleTypes.contains(leadDeveloperRT));
-
- roleTypes = session.getRoleManager().findRoleTypes(asaldhanaUser, asProject);
- assertEquals(1, roleTypes.size());
- assertTrue(roleTypes.contains(developerRT));
-
- // and simpler...
- assertTrue(session.getRoleManager().hasRole(asaldhanaUser, asProject,
developerRT));
-
- // Assert relationships
-
- Collection<User> identities =
session.getRelationshipManager().findAssociatedUsers(portalTeamGroup, false);
- assertEquals(5, identities.size());
- assertTrue(identities.contains(claprunUser));
- assertTrue(identities.contains(mwringeUser));
- assertTrue(identities.contains(sshahUser));
- assertTrue(identities.contains(whalesUser));
- assertTrue(identities.contains(bdawidowUser));
-
- Collection<Group> groups =
session.getRelationshipManager().findAssociatedGroups(rndDepartment, PROJECT, true,
false);
- assertEquals(0, groups.size());
-
- // Check to which group Anil belongs
- groups = session.getRelationshipManager().findAssociatedGroups(asaldhanaUser,
PEOPLE);
- assertEquals(1, groups.size());
- assertTrue(groups.contains(employeesGroup));
-
- // Now check sshah
- groups = session.getRelationshipManager().findAssociatedGroups(sshahUser, PEOPLE);
- assertEquals(2, groups.size());
- assertTrue(groups.contains(employeesGroup));
- assertTrue(groups.contains(portalTeamGroup));
-
-
-
-
- // User attributes
- Attribute[] userInfo = new Attribute[]
- {
- new SimpleAttribute(P3PConstants.INFO_USER_NAME_GIVEN, new
String[]{"Boleslaw"}),
- new SimpleAttribute(P3PConstants.INFO_USER_NAME_FAMILY, new
String[]{"Dawidowicz"}),
- //new SimpleAttribute("picture", new byte[][]{picture}),
- new SimpleAttribute("email", new
String[]{"bd(a)example.com"})
- };
-
- session.getAttributesManager().addAttributes(bdawidowUser, userInfo);
-
- Map<String, Attribute> attributes =
session.getAttributesManager().getAttributes(bdawidowUser);
- assertEquals(3, attributes.keySet().size());
- assertEquals("Dawidowicz",
(attributes.get(P3PConstants.INFO_USER_NAME_FAMILY)).getValue());
-
-
- // Generate random binary data for binary attribute
- Random random = new Random();
-
- // Check that binary attribute picture is mapped
- AttributeDescription attributeDescription =
session.getAttributesManager().getAttributeDescription(bdawidowUser,
"picture");
-
- if (attributeDescription != null &&
attributeDescription.getType().equals("binary"))
- {
-
- // 900 kilobytes
- byte[] picture = new byte[921600];
- random.nextBytes(picture);
-
- userInfo = new Attribute[]
- {
- new SimpleAttribute("picture", new byte[][]{picture}),
- };
-
-
- session.getAttributesManager().addAttributes(bdawidowUser, userInfo);
-
- attributes = session.getAttributesManager().getAttributes(bdawidowUser);
- assertEquals(4, attributes.keySet().size());
- assertEquals("Dawidowicz",
(attributes.get(P3PConstants.INFO_USER_NAME_FAMILY)).getValue());
- assertTrue(Arrays.equals((byte[])attributes.get("picture").getValue(),
picture));
- }
-
-
- // Find user by email
-
assertNull(session.getAttributesManager().findUserByUniqueAttribute("email",
"toto"));
- User user =
session.getAttributesManager().findUserByUniqueAttribute("email",
"bd(a)example.com");
- assertEquals(bdawidowUser, user);
-
-
- // If email is configured as unique it should not be possible to set same value for
different user
-
- attributeDescription =
session.getAttributesManager().getAttributeDescription(bdawidowUser, "email");
-
- if (attributeDescription != null && attributeDescription.isUnique())
- {
-
-
- // check if same unique email can be used for other user
- try
- {
- userInfo = new Attribute[]
- {
- new SimpleAttribute("email", new
String[]{"bd(a)example.com"})
- };
-
- session.getAttributesManager().addAttributes(theuteUser, userInfo);
- fail();
- }
- catch (IdentityException e)
- {
- // expected
- }
- }
-
-
-
- // Credential
- User anotherOne = bdawidowUser;
//session.getPersistenceManager().createUser("blah1");
-
- if
(session.getAttributesManager().isCredentialTypeSupported(PasswordCredential.TYPE))
- {
-
- // There is a known issue that on some LDAP servers (MSAD at least) old password
can
- // still be used for some time together with the new one. Because of this
testsuite cannot
- // assert previously set password values
-
- // #1
- session.getAttributesManager().updatePassword(anotherOne,
"Password2000");
- assertTrue(session.getAttributesManager().validatePassword(anotherOne,
"Password2000"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2001"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2002"));
-
- // #1
- session.getAttributesManager().updatePassword(anotherOne,
"Password2002");
- assertTrue(session.getAttributesManager().validatePassword(anotherOne,
"Password2002"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2001"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"wirdPasswordValue"));
-// assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2000"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2003"));
-
-
- // #1
- session.getAttributesManager().updatePassword(anotherOne,
"Password2003");
- assertTrue(session.getAttributesManager().validatePassword(anotherOne,
"Password2003"));
-// assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2000"));
-// assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2002"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2005"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2006"));
- assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2007"));
-
-
- // #2
- Credential password = new PasswordCredential("SuperPassword2345");
- session.getAttributesManager().updateCredential(anotherOne, password);
- assertTrue(session.getAttributesManager().validateCredentials(anotherOne, new
Credential[]{password}));
-
- // #3
- }
-
- if
(session.getAttributesManager().isCredentialTypeSupported(BinaryCredential.TYPE))
- {
- // 500 kilobytes
- byte[] cert = new byte[512000];
- random.nextBytes(cert);
- Credential binaryCredential = new BinaryCredential(cert);
- session.getAttributesManager().updateCredential(anotherOne, binaryCredential);
- assertTrue(session.getAttributesManager().validateCredentials(anotherOne, new
Credential[]{binaryCredential}));
- }
-
-
- ctx.commit();
-
- }
-
- public void testSamplePortal(String realmName) throws Exception
- {
- String SYSTEM = "SYSTEM";
- String ADMINISTRATION = "ADMINISTRATION";
- String COMMUNITY = "COMMUNITY";
- String ORGANIZATION = "ORGANIZATION";
- String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
- String OFFICE = "OFFICE";
- String DIVISION = "DIVISION";
- String DEPARTMENT = "DEPARTMENT";
- String SECURITY = "SECURITY";
- String PEOPLE = "PEOPLE";
-
- IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
-
- IdentitySession session = factory.createIdentitySession(realmName);
-
- ctx.begin();
-
-
-
- // Create all role types
- RoleType adminRT = session.getRoleManager().createRoleType("Admin");
- RoleType accountAdminRT = session.getRoleManager().createRoleType("Account
Admin");
- RoleType managerRT = session.getRoleManager().createRoleType("Manager");
- RoleType officeManagerRT = session.getRoleManager().createRoleType("Office
Manager");
- RoleType contributorRT =
session.getRoleManager().createRoleType("Contributor");
- RoleType communityOwnerRT = session.getRoleManager().createRoleType("Community
Owner");
- RoleType communityMemberRT =
session.getRoleManager().createRoleType("Community Member");
- RoleType communityForumModeratorRT =
session.getRoleManager().createRoleType("Community Forum Moderator");
- RoleType communityCMSAdminRT =
session.getRoleManager().createRoleType("Community CMS Admin");
-
-
- // Create system root groups - groups containing all communities, global security
groups and organization
-
- Group communityRootGroup =
session.getPersistenceManager().createGroup("COMMUNITY_ROOT", SYSTEM);
- Group securityRootGroup =
session.getPersistenceManager().createGroup("SECURITY_ROOT", SYSTEM);
- Group organizationRootGroup =
session.getPersistenceManager().createGroup("ORGANIZATION_ROOT",SYSTEM);
- Group usersROOTGroup =
session.getPersistenceManager().createGroup("USERS_ROOT",SYSTEM);
-
- ctx.commit();
-
- ctx.begin();
-
- // Communities
-
- Group portalLoversCommunity =
session.getPersistenceManager().createGroup("Portal Lovers", COMMUNITY);
- Group baseJumpingCommunity = session.getPersistenceManager().createGroup("BASE
Jumping", COMMUNITY);
- Group geeksCommunity =
session.getPersistenceManager().createGroup("Geeks", COMMUNITY);
-
- session.getRelationshipManager().associateGroups(communityRootGroup,
portalLoversCommunity);
- session.getRelationshipManager().associateGroups(communityRootGroup,
baseJumpingCommunity);
- session.getRelationshipManager().associateGroups(communityRootGroup,
geeksCommunity);
-
- // Security groups - act like global portal roles
-
- Group portalAdminGroup = session.getPersistenceManager().createGroup("Poral
Admin", SECURITY);
- Group cmsAdminGroup = session.getPersistenceManager().createGroup("CMS
Admin", SECURITY);
- Group userAdminGroup = session.getPersistenceManager().createGroup("User
Admin", SECURITY);
- Group cmsEditorGroup = session.getPersistenceManager().createGroup("CMS
Editor", SECURITY);
-
- session.getRelationshipManager().associateGroups(securityRootGroup,
portalAdminGroup);
- session.getRelationshipManager().associateGroups(securityRootGroup,
cmsAdminGroup);
- session.getRelationshipManager().associateGroups(securityRootGroup,
userAdminGroup);
- session.getRelationshipManager().associateGroups(securityRootGroup,
cmsEditorGroup);
-
- // Organization structure
-
- Group acmeOrg = session.getPersistenceManager().createGroup("ACME",
ORGANIZATION);
-
- session.getRelationshipManager().associateGroups(organizationRootGroup, acmeOrg);
-
- Group departmentsOU =
session.getPersistenceManager().createGroup("Departments", ORGANIZATION_UNIT);
- Group officesOU = session.getPersistenceManager().createGroup("Offices",
ORGANIZATION_UNIT);
- Group employeesOU =
session.getPersistenceManager().createGroup("Employees", ORGANIZATION_UNIT);
-
- session.getRelationshipManager().associateGroups(acmeOrg, departmentsOU);
- session.getRelationshipManager().associateGroups(acmeOrg, officesOU);
- session.getRelationshipManager().associateGroups(acmeOrg, employeesOU);
-
- // Departments
-
- Group hrDepart = session.getPersistenceManager().createGroup("HR",
DEPARTMENT);
- Group financeDepart =
session.getPersistenceManager().createGroup("Finance", DEPARTMENT);
- Group rndDepart = session.getPersistenceManager().createGroup("R&D",
DEPARTMENT);
-
- session.getRelationshipManager().associateGroups(departmentsOU, hrDepart);
- session.getRelationshipManager().associateGroups(departmentsOU, financeDepart);
- session.getRelationshipManager().associateGroups(departmentsOU, rndDepart);
-
- // Offices
-
- Group parisOffice =session.getPersistenceManager().createGroup("Paris",
OFFICE);
- Group londonOffice =session.getPersistenceManager().createGroup("London",
OFFICE);
- Group nyOffice =session.getPersistenceManager().createGroup("New York",
OFFICE);
-
- session.getRelationshipManager().associateGroups(officesOU, parisOffice);
- session.getRelationshipManager().associateGroups(officesOU, londonOffice);
- session.getRelationshipManager().associateGroups(officesOU, nyOffice);
-
- // People
-
- User anneUser = session.getPersistenceManager().createUser("anne");
- User marieUser = session.getPersistenceManager().createUser("marie");
- User eveUser = session.getPersistenceManager().createUser("eve");
- User angelinaUser =
session.getPersistenceManager().createUser("angelina");
- User joannaUser = session.getPersistenceManager().createUser("joanna");
- User merilUser = session.getPersistenceManager().createUser("meril");
- User johnUser = session.getPersistenceManager().createUser("john");
- User stanUser = session.getPersistenceManager().createUser("stan");
- User chrisUser = session.getPersistenceManager().createUser("chris");
- User billUser = session.getPersistenceManager().createUser("bill");
- User jackUser = session.getPersistenceManager().createUser("jack");
-
- ctx.commit();
-
- ctx.begin();
-
- // All users are under people root
-
- session.getRelationshipManager().associateUser(usersROOTGroup, anneUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, marieUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, eveUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, angelinaUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, joannaUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, merilUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, johnUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, stanUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, chrisUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, billUser);
- session.getRelationshipManager().associateUser(usersROOTGroup, jackUser);
-
- ctx.commit();
-
- ctx.begin();
-
- //
-
-
- // Anna is...
-
- // Anna Smith...
-
-
- session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_GIVEN, "Anne");
- session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_FAMILY, "Smith");
- session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_JOB_TITLE, "Senior Software Developer");
- session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "anne.smith(a)acme.com");
- session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER, "777 777 777 7
77");
-
- // Anna works in Paris office and participates in BASE jumping community as a forum
moderator and CMS admin
-
- session.getRelationshipManager().associateUser(parisOffice, anneUser);
-
- // Anne could be just associated with BASE jumping community group using
RelationshipManager but insted Role mechanism
- // is used to have more fine grained control of access rights inside of a
community
-
-
- session.save();
-
- ctx.commit();
-
- ctx.begin();
-
- session.getRoleManager().createRole(communityMemberRT, anneUser,
baseJumpingCommunity);
- session.getRoleManager().createRole(communityForumModeratorRT, anneUser,
baseJumpingCommunity);
- session.getRoleManager().createRole(communityCMSAdminRT, anneUser,
baseJumpingCommunity);
-
- // Anne belongs to CMS portal admins security group
-
- session.getRelationshipManager().associateUser(cmsAdminGroup, anneUser);
-
- // Ann is also an owner of geeks community
-
- session.getRoleManager().createRole(communityOwnerRT, anneUser, geeksCommunity);
-
-
- //
-
-
- // Angelina ...
-
- session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_NAME_GIVEN, "Angelina");
- session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_NAME_FAMILY, "Blond");
- session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_JOB_TITLE, "Very important looking job title");
- session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "angelina1979(a)acme.com");
- session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER, "888 88 88 8888");
-
- // She works in London and is office manager there - se both RelationshipManager
and RoleManager used against
- // the same pair of identity objects
-
- session.getRelationshipManager().associateUser(londonOffice, angelinaUser);
-
- session.getRoleManager().createRole(officeManagerRT, angelinaUser, londonOffice);
-
- // Angelina is member of geeks community and manages cms content there
-
- session.getRoleManager().createRole(communityMemberRT, angelinaUser,
geeksCommunity);
- session.getRoleManager().createRole(communityCMSAdminRT, angelinaUser,
geeksCommunity);
-
- // As office manager she also edits portal cms content
-
- session.getRelationshipManager().associateUser(cmsEditorGroup, angelinaUser);
-
-
- //
-
-
- // Some assertions
-
- // How many users do we have in whole acme org and how many people in paris and
london offices
- assertEquals(11,
session.getRelationshipManager().findAssociatedUsers(usersROOTGroup, false).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedUsers(parisOffice,
false).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedUsers(londonOffice,
false).size());
-
-
- // Is anne geeks community owner?
- assertTrue(session.getRoleManager().hasRole(anneUser, geeksCommunity,
communityOwnerRT));
-
- // Does she belong to cms admins
- assertTrue(session.getRelationshipManager().isAssociated(cmsAdminGroup,
anneUser));
-
- // Check all groups that anna belongs to
- Collection<Group> groups =
session.getRelationshipManager().findAssociatedGroups(anneUser);
- assertEquals(3, groups.size());
- assertTrue(groups.contains(usersROOTGroup));
- assertTrue(groups.contains(parisOffice));
- assertTrue(groups.contains(cmsAdminGroup));
-
-
-
- ctx.commit();
-
- }
-
-
-
-
-
-
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTest.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/OrganizationTest.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTest.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,653 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.api.RoleType;
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.api.Attribute;
+import org.picketlink.idm.api.AttributeDescription;
+import org.picketlink.idm.api.Credential;
+import org.picketlink.idm.common.p3p.P3PConstants;
+import org.picketlink.idm.common.exception.IdentityException;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Random;
+import java.util.Arrays;
+
+import junit.framework.Assert;
+
+/**
+ * Abstract test mapping real life structures using the API
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class OrganizationTest extends Assert
+{
+ APITestContext ctx;
+
+ public OrganizationTest(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public void setCtx(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public APITestContext getCtx()
+ {
+ return ctx;
+ }
+
+ public void testRedHatOrganization(String realmName) throws Exception
+ {
+ // GroupType
+
+ String ORGANIZATION = "ORGANIZATION";
+ String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ String DIVISION = "DIVISION";
+ String DEPARTMENT = "DEPARTMENT";
+ String PROJECT = "PROJECT";
+ String PEOPLE = "PEOPLE";
+
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session = factory.createIdentitySession(realmName);
+
+ //ctx.begin();
+
+ ctx.begin();
+
+ // Organization structure
+
+ Group rhOrg = session.getPersistenceManager().createGroup("RedHat",
ORGANIZATION);
+
+ Group jbossDivision =
session.getPersistenceManager().createGroup("JBoss", DIVISION);
+ Group rhelDivision = session.getPersistenceManager().createGroup("RHEL",
DIVISION);
+
+ session.getRelationshipManager().associateGroups(rhOrg, jbossDivision);
+ session.getRelationshipManager().associateGroups(rhOrg, rhelDivision);
+
+ Group itDepartment = session.getPersistenceManager().createGroup("IT",
DEPARTMENT);
+ Group hrDepartment = session.getPersistenceManager().createGroup("HR",
DEPARTMENT);
+
+ session.getRelationshipManager().associateGroups(jbossDivision, itDepartment);
+ session.getRelationshipManager().associateGroups(jbossDivision, hrDepartment);
+
+ Group rndDepartment = session.getPersistenceManager().createGroup("RnD",
DEPARTMENT);
+
+ session.getRelationshipManager().associateGroups(itDepartment, rndDepartment);
+
+ Group projectsOU =
session.getPersistenceManager().createGroup("Projects", ORGANIZATION_UNIT);
+ Group commonFrameworksOU = session.getPersistenceManager().createGroup("Common
Frameworks", ORGANIZATION_UNIT);
+
+ session.getRelationshipManager().associateGroups(rndDepartment, projectsOU);
+
+ // Projects
+
+ Group portalProject =
session.getPersistenceManager().createGroup("Portal", PROJECT);
+ Group soaProject = session.getPersistenceManager().createGroup("SOA",
PROJECT);
+ Group jbpmProject = session.getPersistenceManager().createGroup("jBPM",
PROJECT);
+ Group seamProject = session.getPersistenceManager().createGroup("Seam",
PROJECT);
+ Group asProject = session.getPersistenceManager().createGroup("AS",
PROJECT);
+ Group securityProject =
session.getPersistenceManager().createGroup("Security", PROJECT);
+
+ session.getRelationshipManager().associateGroups(projectsOU, portalProject);
+ session.getRelationshipManager().associateGroups(projectsOU, soaProject);
+ session.getRelationshipManager().associateGroups(projectsOU, jbpmProject);
+ session.getRelationshipManager().associateGroups(projectsOU, asProject);
+ session.getRelationshipManager().associateGroups(projectsOU, seamProject);
+
+ // Check...
+ assertTrue(session.getRelationshipManager().isAssociated(projectsOU,
portalProject));
+ assertTrue(session.getRelationshipManager().isAssociated(projectsOU, soaProject));
+ assertTrue(session.getRelationshipManager().isAssociated(projectsOU,
jbpmProject));
+ assertTrue(session.getRelationshipManager().isAssociated(projectsOU, asProject));
+ assertTrue(session.getRelationshipManager().isAssociated(projectsOU,
seamProject));
+
+ // Portal is part of common frameworks
+ session.getRelationshipManager().associateGroups(commonFrameworksOU,
portalProject);
+
+ // People
+
+ Group employeesGroup =
session.getPersistenceManager().createGroup("Employees", PEOPLE);
+
+ // Management
+
+ User theuteUser = session.getPersistenceManager().createUser("theute");
+ User mlittleUser =
session.getPersistenceManager().createUser("mlittle");
+ User bgeorgesUser =
session.getPersistenceManager().createUser("bgeorges");
+ User asaldhanaUser =
session.getPersistenceManager().createUser("asaldhana");
+ User janderseUser =
session.getPersistenceManager().createUser("janderse");
+
+ // Portal Team
+
+ User bdawidowUser =
session.getPersistenceManager().createUser("bdawidow");
+ User claprunUser =
session.getPersistenceManager().createUser("claprun");
+ User whalesUser = session.getPersistenceManager().createUser("whales");
+ User sshahUser = session.getPersistenceManager().createUser("sshah");
+ User mwringeUser =
session.getPersistenceManager().createUser("mwringe");
+
+ // Store as employees
+
+ session.getRelationshipManager().associateUser(employeesGroup, theuteUser);
+ session.getRelationshipManager().associateUser(employeesGroup, mlittleUser);
+ session.getRelationshipManager().associateUser(employeesGroup, asaldhanaUser);
+ session.getRelationshipManager().associateUser(employeesGroup, bdawidowUser);
+ session.getRelationshipManager().associateUser(employeesGroup, claprunUser);
+ session.getRelationshipManager().associateUser(employeesGroup, whalesUser);
+ session.getRelationshipManager().associateUser(employeesGroup, sshahUser);
+ session.getRelationshipManager().associateUser(employeesGroup, mwringeUser);
+
+ // Portal team for management purposes
+
+ Group portalTeamGroup = session.getPersistenceManager().createGroup("Portal
Team", PEOPLE);
+ session.getRelationshipManager().associateUser(portalTeamGroup, bdawidowUser);
+ session.getRelationshipManager().associateUser(portalTeamGroup, claprunUser);
+ session.getRelationshipManager().associateUser(portalTeamGroup, whalesUser);
+ session.getRelationshipManager().associateUser(portalTeamGroup, sshahUser);
+ session.getRelationshipManager().associateUser(portalTeamGroup, mwringeUser);
+
+ // Portal team is under common frameworks
+
+ session.getRelationshipManager().associateGroups(commonFrameworksOU,
portalTeamGroup);
+
+ // Role Types
+
+ RoleType developerRT =
session.getRoleManager().createRoleType("Developer");
+ RoleType managerRT = session.getRoleManager().createRoleType("Manager");
+ RoleType leadDeveloperRT = session.getRoleManager().createRoleType("Lead
Developer");
+ RoleType productManagerRT = session.getRoleManager().createRoleType("Product
Manager");
+
+ // Assign roles
+
+ // Common frameworks manager
+
+ session.getRoleManager().createRole(managerRT, bgeorgesUser, commonFrameworksOU);
+
+ // Portal developers
+
+ session.getRoleManager().createRole(developerRT, theuteUser, portalProject);
+ session.getRoleManager().createRole(developerRT, bdawidowUser, portalProject);
+ session.getRoleManager().createRole(developerRT, claprunUser, portalProject);
+ session.getRoleManager().createRole(developerRT, whalesUser, portalProject);
+ session.getRoleManager().createRole(developerRT, sshahUser, portalProject);
+ session.getRoleManager().createRole(developerRT, mwringeUser, portalProject);
+
+ // Portal management
+ session.getRoleManager().createRole(leadDeveloperRT, theuteUser, portalProject);
+ session.getRoleManager().createRole(managerRT, theuteUser, portalTeamGroup);
+ session.getRoleManager().createRole(productManagerRT, janderseUser,
portalProject);
+
+ // SOA
+
+ session.getRoleManager().createRole(developerRT, mlittleUser, portalProject);
+ session.getRoleManager().createRole(productManagerRT, mlittleUser, portalProject);
+
+ // AS & Security
+
+ session.getRoleManager().createRole(developerRT, asaldhanaUser, asProject);
+ session.getRoleManager().createRole(developerRT, asaldhanaUser, securityProject);
+ session.getRoleManager().createRole(leadDeveloperRT, asaldhanaUser,
securityProject);
+
+
+ // Check what RoleTypes has user theute
+ Collection<RoleType> roleTypes =
session.getRoleManager().findUserRoleTypes(theuteUser);
+ assertEquals(3, roleTypes.size());
+ assertTrue(roleTypes.contains(developerRT));
+ assertTrue(roleTypes.contains(leadDeveloperRT));
+ assertTrue(roleTypes.contains(managerRT));
+ assertFalse(roleTypes.contains(productManagerRT));
+
+ assertTrue(session.getRoleManager().hasRole(theuteUser, portalProject,
developerRT));
+ assertTrue(session.getRoleManager().hasRole(theuteUser, portalProject,
leadDeveloperRT));
+ assertTrue(session.getRoleManager().hasRole(theuteUser, portalTeamGroup,
managerRT));
+
+ // Check where anil is Lead Developer and where Developer
+
+ roleTypes = session.getRoleManager().findUserRoleTypes(asaldhanaUser);
+ assertEquals(2, roleTypes.size());
+ assertTrue(roleTypes.contains(developerRT));
+ assertTrue(roleTypes.contains(leadDeveloperRT));
+
+ roleTypes = session.getRoleManager().findRoleTypes(asaldhanaUser,
securityProject);
+ assertEquals(2, roleTypes.size());
+ assertTrue(roleTypes.contains(leadDeveloperRT));
+
+ roleTypes = session.getRoleManager().findRoleTypes(asaldhanaUser, asProject);
+ assertEquals(1, roleTypes.size());
+ assertTrue(roleTypes.contains(developerRT));
+
+ // and simpler...
+ assertTrue(session.getRoleManager().hasRole(asaldhanaUser, asProject,
developerRT));
+
+ // Assert relationships
+
+ Collection<User> identities =
session.getRelationshipManager().findAssociatedUsers(portalTeamGroup, false);
+ assertEquals(5, identities.size());
+ assertTrue(identities.contains(claprunUser));
+ assertTrue(identities.contains(mwringeUser));
+ assertTrue(identities.contains(sshahUser));
+ assertTrue(identities.contains(whalesUser));
+ assertTrue(identities.contains(bdawidowUser));
+
+ Collection<Group> groups =
session.getRelationshipManager().findAssociatedGroups(rndDepartment, PROJECT, true,
false);
+ assertEquals(0, groups.size());
+
+ // Check to which group Anil belongs
+ groups = session.getRelationshipManager().findAssociatedGroups(asaldhanaUser,
PEOPLE);
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(employeesGroup));
+
+ // Now check sshah
+ groups = session.getRelationshipManager().findAssociatedGroups(sshahUser, PEOPLE);
+ assertEquals(2, groups.size());
+ assertTrue(groups.contains(employeesGroup));
+ assertTrue(groups.contains(portalTeamGroup));
+
+
+
+
+ // User attributes
+ Attribute[] userInfo = new Attribute[]
+ {
+ new SimpleAttribute(P3PConstants.INFO_USER_NAME_GIVEN, new
String[]{"Boleslaw"}),
+ new SimpleAttribute(P3PConstants.INFO_USER_NAME_FAMILY, new
String[]{"Dawidowicz"}),
+ //new SimpleAttribute("picture", new byte[][]{picture}),
+ new SimpleAttribute("email", new
String[]{"bd(a)example.com"})
+ };
+
+ session.getAttributesManager().addAttributes(bdawidowUser, userInfo);
+
+ Map<String, Attribute> attributes =
session.getAttributesManager().getAttributes(bdawidowUser);
+ assertEquals(3, attributes.keySet().size());
+ assertEquals("Dawidowicz",
(attributes.get(P3PConstants.INFO_USER_NAME_FAMILY)).getValue());
+
+
+ // Generate random binary data for binary attribute
+ Random random = new Random();
+
+ // Check that binary attribute picture is mapped
+ AttributeDescription attributeDescription =
session.getAttributesManager().getAttributeDescription(bdawidowUser,
"picture");
+
+ if (attributeDescription != null &&
attributeDescription.getType().equals("binary"))
+ {
+
+ // 900 kilobytes
+ byte[] picture = new byte[921600];
+ random.nextBytes(picture);
+
+ userInfo = new Attribute[]
+ {
+ new SimpleAttribute("picture", new byte[][]{picture}),
+ };
+
+
+ session.getAttributesManager().addAttributes(bdawidowUser, userInfo);
+
+ attributes = session.getAttributesManager().getAttributes(bdawidowUser);
+ assertEquals(4, attributes.keySet().size());
+ assertEquals("Dawidowicz",
(attributes.get(P3PConstants.INFO_USER_NAME_FAMILY)).getValue());
+ assertTrue(Arrays.equals((byte[])attributes.get("picture").getValue(),
picture));
+ }
+
+
+ // Find user by email
+
assertNull(session.getAttributesManager().findUserByUniqueAttribute("email",
"toto"));
+ User user =
session.getAttributesManager().findUserByUniqueAttribute("email",
"bd(a)example.com");
+ assertEquals(bdawidowUser, user);
+
+
+ // If email is configured as unique it should not be possible to set same value for
different user
+
+ attributeDescription =
session.getAttributesManager().getAttributeDescription(bdawidowUser, "email");
+
+ if (attributeDescription != null && attributeDescription.isUnique())
+ {
+
+
+ // check if same unique email can be used for other user
+ try
+ {
+ userInfo = new Attribute[]
+ {
+ new SimpleAttribute("email", new
String[]{"bd(a)example.com"})
+ };
+
+ session.getAttributesManager().addAttributes(theuteUser, userInfo);
+ fail();
+ }
+ catch (IdentityException e)
+ {
+ // expected
+ }
+ }
+
+
+
+ // Credential
+ User anotherOne = bdawidowUser;
//session.getPersistenceManager().createUser("blah1");
+
+ if
(session.getAttributesManager().isCredentialTypeSupported(PasswordCredential.TYPE))
+ {
+
+ // There is a known issue that on some LDAP servers (MSAD at least) old password
can
+ // still be used for some time together with the new one. Because of this
testsuite cannot
+ // assert previously set password values
+
+ // #1
+ session.getAttributesManager().updatePassword(anotherOne,
"Password2000");
+ assertTrue(session.getAttributesManager().validatePassword(anotherOne,
"Password2000"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2001"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2002"));
+
+ // #1
+ session.getAttributesManager().updatePassword(anotherOne,
"Password2002");
+ assertTrue(session.getAttributesManager().validatePassword(anotherOne,
"Password2002"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2001"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"wirdPasswordValue"));
+// assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2000"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2003"));
+
+
+ // #1
+ session.getAttributesManager().updatePassword(anotherOne,
"Password2003");
+ assertTrue(session.getAttributesManager().validatePassword(anotherOne,
"Password2003"));
+// assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2000"));
+// assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2002"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2005"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2006"));
+ assertFalse(session.getAttributesManager().validatePassword(anotherOne,
"Password2007"));
+
+
+ // #2
+ Credential password = new PasswordCredential("SuperPassword2345");
+ session.getAttributesManager().updateCredential(anotherOne, password);
+ assertTrue(session.getAttributesManager().validateCredentials(anotherOne, new
Credential[]{password}));
+
+ // #3
+ }
+
+ if
(session.getAttributesManager().isCredentialTypeSupported(BinaryCredential.TYPE))
+ {
+ // 500 kilobytes
+ byte[] cert = new byte[512000];
+ random.nextBytes(cert);
+ Credential binaryCredential = new BinaryCredential(cert);
+ session.getAttributesManager().updateCredential(anotherOne, binaryCredential);
+ assertTrue(session.getAttributesManager().validateCredentials(anotherOne, new
Credential[]{binaryCredential}));
+ }
+
+
+ ctx.commit();
+
+ }
+
+ public void testSamplePortal(String realmName) throws Exception
+ {
+ String SYSTEM = "SYSTEM";
+ String ADMINISTRATION = "ADMINISTRATION";
+ String COMMUNITY = "COMMUNITY";
+ String ORGANIZATION = "ORGANIZATION";
+ String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ String OFFICE = "OFFICE";
+ String DIVISION = "DIVISION";
+ String DEPARTMENT = "DEPARTMENT";
+ String SECURITY = "SECURITY";
+ String PEOPLE = "PEOPLE";
+
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session = factory.createIdentitySession(realmName);
+
+ ctx.begin();
+
+
+
+ // Create all role types
+ RoleType adminRT = session.getRoleManager().createRoleType("Admin");
+ RoleType accountAdminRT = session.getRoleManager().createRoleType("Account
Admin");
+ RoleType managerRT = session.getRoleManager().createRoleType("Manager");
+ RoleType officeManagerRT = session.getRoleManager().createRoleType("Office
Manager");
+ RoleType contributorRT =
session.getRoleManager().createRoleType("Contributor");
+ RoleType communityOwnerRT = session.getRoleManager().createRoleType("Community
Owner");
+ RoleType communityMemberRT =
session.getRoleManager().createRoleType("Community Member");
+ RoleType communityForumModeratorRT =
session.getRoleManager().createRoleType("Community Forum Moderator");
+ RoleType communityCMSAdminRT =
session.getRoleManager().createRoleType("Community CMS Admin");
+
+
+ // Create system root groups - groups containing all communities, global security
groups and organization
+
+ Group communityRootGroup =
session.getPersistenceManager().createGroup("COMMUNITY_ROOT", SYSTEM);
+ Group securityRootGroup =
session.getPersistenceManager().createGroup("SECURITY_ROOT", SYSTEM);
+ Group organizationRootGroup =
session.getPersistenceManager().createGroup("ORGANIZATION_ROOT",SYSTEM);
+ Group usersROOTGroup =
session.getPersistenceManager().createGroup("USERS_ROOT",SYSTEM);
+
+ ctx.commit();
+
+ ctx.begin();
+
+ // Communities
+
+ Group portalLoversCommunity =
session.getPersistenceManager().createGroup("Portal Lovers", COMMUNITY);
+ Group baseJumpingCommunity = session.getPersistenceManager().createGroup("BASE
Jumping", COMMUNITY);
+ Group geeksCommunity =
session.getPersistenceManager().createGroup("Geeks", COMMUNITY);
+
+ session.getRelationshipManager().associateGroups(communityRootGroup,
portalLoversCommunity);
+ session.getRelationshipManager().associateGroups(communityRootGroup,
baseJumpingCommunity);
+ session.getRelationshipManager().associateGroups(communityRootGroup,
geeksCommunity);
+
+ // Security groups - act like global portal roles
+
+ Group portalAdminGroup = session.getPersistenceManager().createGroup("Poral
Admin", SECURITY);
+ Group cmsAdminGroup = session.getPersistenceManager().createGroup("CMS
Admin", SECURITY);
+ Group userAdminGroup = session.getPersistenceManager().createGroup("User
Admin", SECURITY);
+ Group cmsEditorGroup = session.getPersistenceManager().createGroup("CMS
Editor", SECURITY);
+
+ session.getRelationshipManager().associateGroups(securityRootGroup,
portalAdminGroup);
+ session.getRelationshipManager().associateGroups(securityRootGroup,
cmsAdminGroup);
+ session.getRelationshipManager().associateGroups(securityRootGroup,
userAdminGroup);
+ session.getRelationshipManager().associateGroups(securityRootGroup,
cmsEditorGroup);
+
+ // Organization structure
+
+ Group acmeOrg = session.getPersistenceManager().createGroup("ACME",
ORGANIZATION);
+
+ session.getRelationshipManager().associateGroups(organizationRootGroup, acmeOrg);
+
+ Group departmentsOU =
session.getPersistenceManager().createGroup("Departments", ORGANIZATION_UNIT);
+ Group officesOU = session.getPersistenceManager().createGroup("Offices",
ORGANIZATION_UNIT);
+ Group employeesOU =
session.getPersistenceManager().createGroup("Employees", ORGANIZATION_UNIT);
+
+ session.getRelationshipManager().associateGroups(acmeOrg, departmentsOU);
+ session.getRelationshipManager().associateGroups(acmeOrg, officesOU);
+ session.getRelationshipManager().associateGroups(acmeOrg, employeesOU);
+
+ // Departments
+
+ Group hrDepart = session.getPersistenceManager().createGroup("HR",
DEPARTMENT);
+ Group financeDepart =
session.getPersistenceManager().createGroup("Finance", DEPARTMENT);
+ Group rndDepart = session.getPersistenceManager().createGroup("R&D",
DEPARTMENT);
+
+ session.getRelationshipManager().associateGroups(departmentsOU, hrDepart);
+ session.getRelationshipManager().associateGroups(departmentsOU, financeDepart);
+ session.getRelationshipManager().associateGroups(departmentsOU, rndDepart);
+
+ // Offices
+
+ Group parisOffice =session.getPersistenceManager().createGroup("Paris",
OFFICE);
+ Group londonOffice =session.getPersistenceManager().createGroup("London",
OFFICE);
+ Group nyOffice =session.getPersistenceManager().createGroup("New York",
OFFICE);
+
+ session.getRelationshipManager().associateGroups(officesOU, parisOffice);
+ session.getRelationshipManager().associateGroups(officesOU, londonOffice);
+ session.getRelationshipManager().associateGroups(officesOU, nyOffice);
+
+ // People
+
+ User anneUser = session.getPersistenceManager().createUser("anne");
+ User marieUser = session.getPersistenceManager().createUser("marie");
+ User eveUser = session.getPersistenceManager().createUser("eve");
+ User angelinaUser =
session.getPersistenceManager().createUser("angelina");
+ User joannaUser = session.getPersistenceManager().createUser("joanna");
+ User merilUser = session.getPersistenceManager().createUser("meril");
+ User johnUser = session.getPersistenceManager().createUser("john");
+ User stanUser = session.getPersistenceManager().createUser("stan");
+ User chrisUser = session.getPersistenceManager().createUser("chris");
+ User billUser = session.getPersistenceManager().createUser("bill");
+ User jackUser = session.getPersistenceManager().createUser("jack");
+
+ ctx.commit();
+
+ ctx.begin();
+
+ // All users are under people root
+
+ session.getRelationshipManager().associateUser(usersROOTGroup, anneUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, marieUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, eveUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, angelinaUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, joannaUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, merilUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, johnUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, stanUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, chrisUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, billUser);
+ session.getRelationshipManager().associateUser(usersROOTGroup, jackUser);
+
+ ctx.commit();
+
+ ctx.begin();
+
+ //
+
+
+ // Anna is...
+
+ // Anna Smith...
+
+
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_GIVEN, "Anne");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_FAMILY, "Smith");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_JOB_TITLE, "Senior Software Developer");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "anne.smith(a)acme.com");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER, "777 777 777 7
77");
+
+ // Anna works in Paris office and participates in BASE jumping community as a forum
moderator and CMS admin
+
+ session.getRelationshipManager().associateUser(parisOffice, anneUser);
+
+ // Anne could be just associated with BASE jumping community group using
RelationshipManager but insted Role mechanism
+ // is used to have more fine grained control of access rights inside of a
community
+
+
+ session.save();
+
+ ctx.commit();
+
+ ctx.begin();
+
+ session.getRoleManager().createRole(communityMemberRT, anneUser,
baseJumpingCommunity);
+ session.getRoleManager().createRole(communityForumModeratorRT, anneUser,
baseJumpingCommunity);
+ session.getRoleManager().createRole(communityCMSAdminRT, anneUser,
baseJumpingCommunity);
+
+ // Anne belongs to CMS portal admins security group
+
+ session.getRelationshipManager().associateUser(cmsAdminGroup, anneUser);
+
+ // Ann is also an owner of geeks community
+
+ session.getRoleManager().createRole(communityOwnerRT, anneUser, geeksCommunity);
+
+
+ //
+
+
+ // Angelina ...
+
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_NAME_GIVEN, "Angelina");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_NAME_FAMILY, "Blond");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_JOB_TITLE, "Very important looking job title");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "angelina1979(a)acme.com");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER, "888 88 88 8888");
+
+ // She works in London and is office manager there - se both RelationshipManager
and RoleManager used against
+ // the same pair of identity objects
+
+ session.getRelationshipManager().associateUser(londonOffice, angelinaUser);
+
+ session.getRoleManager().createRole(officeManagerRT, angelinaUser, londonOffice);
+
+ // Angelina is member of geeks community and manages cms content there
+
+ session.getRoleManager().createRole(communityMemberRT, angelinaUser,
geeksCommunity);
+ session.getRoleManager().createRole(communityCMSAdminRT, angelinaUser,
geeksCommunity);
+
+ // As office manager she also edits portal cms content
+
+ session.getRelationshipManager().associateUser(cmsEditorGroup, angelinaUser);
+
+
+ //
+
+
+ // Some assertions
+
+ // How many users do we have in whole acme org and how many people in paris and
london offices
+ assertEquals(11,
session.getRelationshipManager().findAssociatedUsers(usersROOTGroup, false).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedUsers(parisOffice,
false).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedUsers(londonOffice,
false).size());
+
+
+ // Is anne geeks community owner?
+ assertTrue(session.getRoleManager().hasRole(anneUser, geeksCommunity,
communityOwnerRT));
+
+ // Does she belong to cms admins
+ assertTrue(session.getRelationshipManager().isAssociated(cmsAdminGroup,
anneUser));
+
+ // Check all groups that anna belongs to
+ Collection<Group> groups =
session.getRelationshipManager().findAssociatedGroups(anneUser);
+ assertEquals(3, groups.size());
+ assertTrue(groups.contains(usersROOTGroup));
+ assertTrue(groups.contains(parisOffice));
+ assertTrue(groups.contains(cmsAdminGroup));
+
+
+
+ ctx.commit();
+
+ }
+
+
+
+
+
+
+
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/OrganizationTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,106 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.impl.IdentityTestPOJO;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Test;
-import org.jboss.unit.api.pojo.annotations.Parameter;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class OrganizationTestCase extends IdentityTestPOJO implements APITestContext
-{
- private OrganizationTest orgTest;
-
- private IdentitySessionFactory identitySessionFactory;
-
- private String samplePortalRealmName = "realm://portal/SamplePortal/DB";
-
- private String sampleOrganizationRealmName = "realm://RedHat/DB";
-
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
-
- orgTest = new OrganizationTest(this);
-
- identitySessionFactory = new IdentityConfigurationImpl().
- configure(getIdentityConfig()).buildIdentitySessionFactory();
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- public IdentitySessionFactory getIdentitySessionFactory()
- {
- return identitySessionFactory;
- }
-
- @Test
- public void testOrganization() throws Exception
- {
-
- orgTest.testRedHatOrganization(getSampleOrganizationRealmName());
- }
-
- @Test
- public void testSamplePortal() throws Exception
- {
-
- orgTest.testSamplePortal(getSamplePortalRealmName());
-
- }
-
- public String getSamplePortalRealmName()
- {
- return samplePortalRealmName;
- }
-
- @Parameter
- public void setSamplePortalRealmName(String samplePortalRealmName)
- {
- this.samplePortalRealmName = samplePortalRealmName;
- }
-
- public String getSampleOrganizationRealmName()
- {
- return sampleOrganizationRealmName;
- }
-
- @Parameter
- public void setSampleOrganizationRealmName(String sampleOrganizationRealmName)
- {
- this.sampleOrganizationRealmName = sampleOrganizationRealmName;
- }
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/OrganizationTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/OrganizationTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,106 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.impl.IdentityTestPOJO;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.jboss.unit.api.pojo.annotations.Parameter;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class OrganizationTestCase extends IdentityTestPOJO implements APITestContext
+{
+ private OrganizationTest orgTest;
+
+ private IdentitySessionFactory identitySessionFactory;
+
+ private String samplePortalRealmName = "realm://portal/SamplePortal/DB";
+
+ private String sampleOrganizationRealmName = "realm://RedHat/DB";
+
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+
+ orgTest = new OrganizationTest(this);
+
+ identitySessionFactory = new IdentityConfigurationImpl().
+ configure(getIdentityConfig()).buildIdentitySessionFactory();
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ public IdentitySessionFactory getIdentitySessionFactory()
+ {
+ return identitySessionFactory;
+ }
+
+ @Test
+ public void testOrganization() throws Exception
+ {
+
+ orgTest.testRedHatOrganization(getSampleOrganizationRealmName());
+ }
+
+ @Test
+ public void testSamplePortal() throws Exception
+ {
+
+ orgTest.testSamplePortal(getSamplePortalRealmName());
+
+ }
+
+ public String getSamplePortalRealmName()
+ {
+ return samplePortalRealmName;
+ }
+
+ @Parameter
+ public void setSamplePortalRealmName(String samplePortalRealmName)
+ {
+ this.samplePortalRealmName = samplePortalRealmName;
+ }
+
+ public String getSampleOrganizationRealmName()
+ {
+ return sampleOrganizationRealmName;
+ }
+
+ @Parameter
+ public void setSampleOrganizationRealmName(String sampleOrganizationRealmName)
+ {
+ this.sampleOrganizationRealmName = sampleOrganizationRealmName;
+ }
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/PersistenceManagerTest.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/PersistenceManagerTest.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/PersistenceManagerTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,184 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.Group;
-import org.jboss.identity.idm.api.User;
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.api.IdentitySearchCriteria;
-
-import junit.framework.Assert;
-
-/**
- *
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class PersistenceManagerTest extends Assert
-{
- //TODO:
- //TODO: - force in removeGroup (NYI)
- //TODO: - exception handling
- //TODO: - search criteria
- //TODO: - features description
-
- APITestContext ctx;
-
- private String ORGANIZATION = "ORGANIZATION";
- private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
- private String DIVISION = "DIVISION";
- private String DEPARTMENT = "DEPARTMENT";
- private String PROJECT = "PROJECT";
- private String PEOPLE = "PEOPLE";
-
- public PersistenceManagerTest(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public void setCtx(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public APITestContext getCtx()
- {
- return ctx;
- }
-
- public void testMethods(String realmName) throws Exception
- {
- IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
-
- IdentitySession session = factory.createIdentitySession(realmName);
-
-
-
- ctx.begin();
-
- // Bad names
-
- try
- {
- session.getPersistenceManager().createUser("lol/olo");
- fail();
- }
- catch (IllegalArgumentException e)
- {
- // expected
- }
-
- try
- {
- session.getPersistenceManager().createGroup("/toto", ORGANIZATION);
- fail();
- }
- catch (IllegalArgumentException e)
- {
- // expected
- }
-
-
- // Create / Remove
-
- // Group
- Group group1 = session.getPersistenceManager().createGroup("groupName1",
ORGANIZATION);
-
- assertNotNull(group1);
- assertEquals(group1.getGroupType(), ORGANIZATION);
- assertEquals(group1.getName(), "groupName1");
-
- String group1Id =
session.getPersistenceManager().createGroupKey("groupName1", ORGANIZATION);
-
- assertEquals(group1Id, group1.getKey());
-
- group1 = session.getPersistenceManager().findGroupByKey(group1Id);
-
- assertNotNull(group1);
- assertEquals(group1.getGroupType(), ORGANIZATION);
- assertEquals(group1.getName(), "groupName1");
-
- session.getPersistenceManager().createGroup("groupName2", ORGANIZATION);
- session.getPersistenceManager().createGroup("groupName3", PROJECT);
-
- assertEquals(2, session.getPersistenceManager().getGroupTypeCount(ORGANIZATION));
- assertEquals(1, session.getPersistenceManager().getGroupTypeCount(PROJECT));
- assertEquals(0, session.getPersistenceManager().getGroupTypeCount(DEPARTMENT));
-
- assertEquals(2, session.getPersistenceManager().findGroup(ORGANIZATION).size());
- assertEquals(1, session.getPersistenceManager().findGroup(PROJECT).size());
- assertEquals(0, session.getPersistenceManager().findGroup(DEPARTMENT).size());
-
- session.getPersistenceManager().removeGroup(group1, false);
- String id = session.getPersistenceManager().createGroupKey("groupName2",
ORGANIZATION);
- session.getPersistenceManager().removeGroup(id, false);
- id = session.getPersistenceManager().createGroupKey("groupName3",
PROJECT);
- session.getPersistenceManager().removeGroup(id, false);
-
- assertEquals(0, session.getPersistenceManager().findGroup(ORGANIZATION,
(IdentitySearchCriteria)null).size());
- assertEquals(0, session.getPersistenceManager().findGroup(PROJECT).size());
- assertEquals(0, session.getPersistenceManager().findGroup(DEPARTMENT).size());
-
- assertEquals(0, session.getPersistenceManager().getGroupTypeCount(ORGANIZATION));
- assertEquals(0, session.getPersistenceManager().getGroupTypeCount(PROJECT));
- assertEquals(0, session.getPersistenceManager().getGroupTypeCount(DEPARTMENT));
-
-
- //User
-
- User u1 = session.getPersistenceManager().createUser("olo");
-
- assertNotNull(u1);
- assertEquals(u1.getKey(), "olo");
-
- session.getPersistenceManager().createUser("anna");
-
- assertEquals(2, session.getPersistenceManager().getUserCount());
-
- assertNotNull(session.getPersistenceManager().findUser("olo"));
- assertNotNull(session.getPersistenceManager().findUser("anna"));
-
- //TODO: this should throw some meaningfull exception or simply return null
- //assertNull(session.getPersistenceManager().findUser("olaf"));
-
- assertEquals(2,
session.getPersistenceManager().findUser((IdentitySearchCriteria)null).size());
-
- session.getPersistenceManager().removeUser(u1, false);
-
- assertEquals(1, session.getPersistenceManager().getUserCount());
-
- session.getPersistenceManager().removeUser("anna", false);
-
- assertEquals(0, session.getPersistenceManager().getUserCount());
-
- assertEquals(0,
session.getPersistenceManager().findUser((IdentitySearchCriteria)null).size());
-
-
- ctx.commit();
-
- }
-
-
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/PersistenceManagerTest.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/PersistenceManagerTest.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/PersistenceManagerTest.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/PersistenceManagerTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,184 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.api.IdentitySearchCriteria;
+
+import junit.framework.Assert;
+
+/**
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class PersistenceManagerTest extends Assert
+{
+ //TODO:
+ //TODO: - force in removeGroup (NYI)
+ //TODO: - exception handling
+ //TODO: - search criteria
+ //TODO: - features description
+
+ APITestContext ctx;
+
+ private String ORGANIZATION = "ORGANIZATION";
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ private String DIVISION = "DIVISION";
+ private String DEPARTMENT = "DEPARTMENT";
+ private String PROJECT = "PROJECT";
+ private String PEOPLE = "PEOPLE";
+
+ public PersistenceManagerTest(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public void setCtx(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public APITestContext getCtx()
+ {
+ return ctx;
+ }
+
+ public void testMethods(String realmName) throws Exception
+ {
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session = factory.createIdentitySession(realmName);
+
+
+
+ ctx.begin();
+
+ // Bad names
+
+ try
+ {
+ session.getPersistenceManager().createUser("lol/olo");
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+
+ try
+ {
+ session.getPersistenceManager().createGroup("/toto", ORGANIZATION);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+
+
+ // Create / Remove
+
+ // Group
+ Group group1 = session.getPersistenceManager().createGroup("groupName1",
ORGANIZATION);
+
+ assertNotNull(group1);
+ assertEquals(group1.getGroupType(), ORGANIZATION);
+ assertEquals(group1.getName(), "groupName1");
+
+ String group1Id =
session.getPersistenceManager().createGroupKey("groupName1", ORGANIZATION);
+
+ assertEquals(group1Id, group1.getKey());
+
+ group1 = session.getPersistenceManager().findGroupByKey(group1Id);
+
+ assertNotNull(group1);
+ assertEquals(group1.getGroupType(), ORGANIZATION);
+ assertEquals(group1.getName(), "groupName1");
+
+ session.getPersistenceManager().createGroup("groupName2", ORGANIZATION);
+ session.getPersistenceManager().createGroup("groupName3", PROJECT);
+
+ assertEquals(2, session.getPersistenceManager().getGroupTypeCount(ORGANIZATION));
+ assertEquals(1, session.getPersistenceManager().getGroupTypeCount(PROJECT));
+ assertEquals(0, session.getPersistenceManager().getGroupTypeCount(DEPARTMENT));
+
+ assertEquals(2, session.getPersistenceManager().findGroup(ORGANIZATION).size());
+ assertEquals(1, session.getPersistenceManager().findGroup(PROJECT).size());
+ assertEquals(0, session.getPersistenceManager().findGroup(DEPARTMENT).size());
+
+ session.getPersistenceManager().removeGroup(group1, false);
+ String id = session.getPersistenceManager().createGroupKey("groupName2",
ORGANIZATION);
+ session.getPersistenceManager().removeGroup(id, false);
+ id = session.getPersistenceManager().createGroupKey("groupName3",
PROJECT);
+ session.getPersistenceManager().removeGroup(id, false);
+
+ assertEquals(0, session.getPersistenceManager().findGroup(ORGANIZATION,
(IdentitySearchCriteria)null).size());
+ assertEquals(0, session.getPersistenceManager().findGroup(PROJECT).size());
+ assertEquals(0, session.getPersistenceManager().findGroup(DEPARTMENT).size());
+
+ assertEquals(0, session.getPersistenceManager().getGroupTypeCount(ORGANIZATION));
+ assertEquals(0, session.getPersistenceManager().getGroupTypeCount(PROJECT));
+ assertEquals(0, session.getPersistenceManager().getGroupTypeCount(DEPARTMENT));
+
+
+ //User
+
+ User u1 = session.getPersistenceManager().createUser("olo");
+
+ assertNotNull(u1);
+ assertEquals(u1.getKey(), "olo");
+
+ session.getPersistenceManager().createUser("anna");
+
+ assertEquals(2, session.getPersistenceManager().getUserCount());
+
+ assertNotNull(session.getPersistenceManager().findUser("olo"));
+ assertNotNull(session.getPersistenceManager().findUser("anna"));
+
+ //TODO: this should throw some meaningfull exception or simply return null
+ //assertNull(session.getPersistenceManager().findUser("olaf"));
+
+ assertEquals(2,
session.getPersistenceManager().findUser((IdentitySearchCriteria)null).size());
+
+ session.getPersistenceManager().removeUser(u1, false);
+
+ assertEquals(1, session.getPersistenceManager().getUserCount());
+
+ session.getPersistenceManager().removeUser("anna", false);
+
+ assertEquals(0, session.getPersistenceManager().getUserCount());
+
+ assertEquals(0,
session.getPersistenceManager().findUser((IdentitySearchCriteria)null).size());
+
+
+ ctx.commit();
+
+ }
+
+
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RelationshipManagerTest.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/RelationshipManagerTest.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RelationshipManagerTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,455 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.Group;
-import org.jboss.identity.idm.api.User;
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.api.IdentitySearchCriteria;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import junit.framework.Assert;
-
-/**
- *
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class RelationshipManagerTest extends Assert
-{
- //TODO:
- //TODO: - inheritence in find methods
- //TODO: - creating forbidden associations
- //TODO: - exception handling
- //TODO: - search criteria
- //TODO: - features description
-
- APITestContext ctx;
-
- private String ORGANIZATION = "ORGANIZATION";
- private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
- private String DIVISION = "DIVISION";
- private String DEPARTMENT = "DEPARTMENT";
- private String PROJECT = "PROJECT";
- private String PEOPLE = "PEOPLE";
-
- public RelationshipManagerTest(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public void setCtx(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public APITestContext getCtx()
- {
- return ctx;
- }
-
- public void testMethods(String realmName) throws Exception
- {
- IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
-
- IdentitySession session = factory.createIdentitySession(realmName);
-
- ctx.begin();
-
- // Create stuff
- User user1 = session.getPersistenceManager().createUser("user1");
- User user2 = session.getPersistenceManager().createUser("user2");
- User user3 = session.getPersistenceManager().createUser("user3");
- User user4 = session.getPersistenceManager().createUser("user4");
-
- Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
- Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
- Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
- Group group4 = session.getPersistenceManager().createGroup("group4",
DEPARTMENT);
- Group group5 = session.getPersistenceManager().createGroup("group5",
DEPARTMENT);
-
-
- // Associate groups
-
- session.getRelationshipManager().associateGroups(group1, group2);
- session.getRelationshipManager().associateGroups(group1, group3);
-
- // Assert
-
- // isAssociated
-
- assertTrue(session.getRelationshipManager().isAssociated(group1, group2));
- assertTrue(session.getRelationshipManager().isAssociated(group1, group3));
- assertFalse(session.getRelationshipManager().isAssociated(group1, group4));
- assertFalse(session.getRelationshipManager().isAssociated(group2, group1));
- assertFalse(session.getRelationshipManager().isAssociated(group2, group3));
-
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2), Arrays.asList(group2, group3)));
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group2,
group3), Arrays.asList(group1)));
-
- assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
group2.getKey()));
- assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
group3.getKey()));
- assertFalse(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
group4.getKey()));
- assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
group1.getKey()));
- assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
group3.getKey()));
-
- assertTrue(session.getRelationshipManager().
- isAssociatedByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(group2.getKey(), group3.getKey())));
- assertFalse(session.getRelationshipManager().
- isAssociatedByKeys(Arrays.asList(group1.getKey(), group2.getKey()),
Arrays.asList(group2.getKey(), group3.getKey())));
- assertFalse(session.getRelationshipManager().
- isAssociatedByKeys(Arrays.asList(group2.getKey(), group3.getKey()),
Arrays.asList(group1.getKey())));
-
-
- // Associate groups - other methods
-
- // First disassociate and assert
- session.getRelationshipManager().disassociateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
-
- assertFalse(session.getRelationshipManager().isAssociated(group1, group2));
- assertFalse(session.getRelationshipManager().isAssociated(group1, group3));
-
- // reassociate #1
- session.getRelationshipManager().associateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
-
-
session.getRelationshipManager().disassociateGroupsByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(group2.getKey(), group3.getKey()));
-
- // reassociate #2
-
session.getRelationshipManager().associateGroupsByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(group2.getKey(), group3.getKey()));
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
-
- session.getRelationshipManager().disassociateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
-
- // reassociate #3
- session.getRelationshipManager().associateGroupsByKeys(group1.getKey(),
group2.getKey());
- session.getRelationshipManager().associateGroupsByKeys(group1.getKey(),
group3.getKey());
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
-
- session.getRelationshipManager().disassociateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
-
-
- // Associate Group and Users
-
- session.getRelationshipManager().associateUser(group1, user1);
- session.getRelationshipManager().associateUser(group1, user2);
-
- // isAssociated
-
- assertTrue(session.getRelationshipManager().isAssociated(group1, user1));
- assertTrue(session.getRelationshipManager().isAssociated(group1, user2));
- assertFalse(session.getRelationshipManager().isAssociated(group1, user3));
- assertFalse(session.getRelationshipManager().isAssociated(group2, user1));
- assertFalse(session.getRelationshipManager().isAssociated(group2, user3));
-
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2), Arrays.asList(user1, user2)));
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group2),
Arrays.asList(user3)));
-
- assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
user1.getKey()));
- assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
user2.getKey()));
- assertFalse(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
user3.getKey()));
- assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
user1.getKey()));
- assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
user3.getKey()));
-
- assertTrue(session.getRelationshipManager().
- isAssociatedByKeys(Arrays.asList(group1.getKey()), Arrays.asList(user1.getKey(),
user2.getKey())));
- assertFalse(session.getRelationshipManager().
- isAssociatedByKeys(Arrays.asList(group1.getKey(), group2.getKey()),
Arrays.asList(user1.getKey(), user2.getKey())));
- assertFalse(session.getRelationshipManager().
- isAssociatedByKeys(Arrays.asList(group2.getKey(), group3.getKey()),
Arrays.asList(user1.getKey())));
-
-
- // Associate groups / users - other methods
-
- // First disassociate and assert
- session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
-
- assertFalse(session.getRelationshipManager().isAssociated(group1, user1));
- assertFalse(session.getRelationshipManager().isAssociated(group1, user2));
-
- // reassociate #1
- session.getRelationshipManager().associateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
-
- session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
-
- // reassociate #2
-
session.getRelationshipManager().associateUsersByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(user1.getKey(), user2.getKey()));
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
-
-
session.getRelationshipManager().disassociateUsersByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(user1.getKey(), user2.getKey()));
-
- // reassociate #3
- session.getRelationshipManager().associateUserByKeys(group1.getKey(),
user1.getKey());
- session.getRelationshipManager().associateUserByKeys(group1.getKey(),
user2.getKey());
-
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
-
- session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
-
- // reassociate #4
- session.getRelationshipManager().associateUserByKeys(group1.getKey(),
user1.getKey());
- session.getRelationshipManager().associateUserByKeys(group2.getKey(),
user1.getKey());
- session.getRelationshipManager().associateUserByKeys(group3.getKey(),
user1.getKey());
-
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2, group3), Arrays.asList(user1)));
-
- session.getRelationshipManager().disassociateGroups(user1);
-
- assertFalse(session.getRelationshipManager().isAssociated(group1, user1));
- assertFalse(session.getRelationshipManager().isAssociated(group2, user1));
- assertFalse(session.getRelationshipManager().isAssociated(group3, user1));
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2, group3), Arrays.asList(user1)));
-
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user1).size());
-
-
-
- ctx.commit();
-
- ctx.begin();
-
-
- // Find methods - prepopulate
-
- session.getRelationshipManager().associateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2, user3));
- session.getRelationshipManager().associateUsers(Arrays.asList(group3),
Arrays.asList(user2, user3));
- session.getRelationshipManager().associateGroups(Arrays.asList(group2),
Arrays.asList(group3, group4, group5));
-
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2, user3)));
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group2),
Arrays.asList(group3, group4, group5)));
- assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group3),
Arrays.asList(user2, user3)));
-
- ctx.commit();
- ctx.begin();
-
- // Find users
- //TODO: check if collections contain correct objects (not only size)
-
- assertEquals(3, session.getRelationshipManager().findAssociatedUsers(group1,
false).size());
- assertEquals(0, session.getRelationshipManager().findAssociatedUsers(group2,
false).size());
-
- assertEquals(3, session.getRelationshipManager().findAssociatedUsers(group1, false,
null).size());
- assertEquals(0, session.getRelationshipManager().findAssociatedUsers(group2, false,
null).size());
-
- assertEquals(3,
session.getRelationshipManager().findAssociatedUsers(group1.getKey(), false,
null).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedUsers(group2.getKey(), false,
null).size());
-
- // Find groups
-
- // #1
- assertEquals(3, session.getRelationshipManager().findAssociatedGroups(group2, null,
true, false).size());
- assertEquals(2, session.getRelationshipManager().findAssociatedGroups(group2,
DEPARTMENT, true, false).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(group2,
ORGANIZATION_UNIT, true, false).size());
- assertEquals(0, session.getRelationshipManager().findAssociatedGroups(group2,
ORGANIZATION, true, false).size());
-
- // #1
- assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), DEPARTMENT, true,
false, null).size());
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), ORGANIZATION_UNIT,
true, false, null).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), ORGANIZATION, true,
false, null).size());
-
- // #3
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(group3,
ORGANIZATION_UNIT, false, false).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(group4,
ORGANIZATION_UNIT, false, false).size());
- assertEquals(0, session.getRelationshipManager().findAssociatedGroups(group2,
ORGANIZATION, false, false).size());
- assertEquals(3, session.getRelationshipManager().findAssociatedGroups(group2, null,
true, false).size());
-
- // #4
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(group3.getKey(), ORGANIZATION_UNIT,
false, false, null).size());
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(group4.getKey(), ORGANIZATION_UNIT,
false, false, null).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), ORGANIZATION,
false, false, null).size());
-
- // #5
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user1).size());
- assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user2).size());
- assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user3).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4).size());
-
- // #6
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user1.getKey(), null).size());
- assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user2.getKey(), null).size());
- assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user3.getKey(), null).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4.getKey(), null).size());
-
- // #7
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user1,
ORGANIZATION).size());
- assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user1,
ORGANIZATION_UNIT).size());
- assertEquals(2, session.getRelationshipManager().findAssociatedGroups(user2,
(String)null).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user2,
ORGANIZATION).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user2,
ORGANIZATION_UNIT).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user3,
ORGANIZATION).size());
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user3,
ORGANIZATION_UNIT).size());
- assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user4,
ORGANIZATION).size());
- assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user4,
ORGANIZATION_UNIT).size());
-
- // #7
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user1.getKey(), ORGANIZATION,
null).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user1.getKey(), ORGANIZATION_UNIT,
null).size());
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user2.getKey(), ORGANIZATION,
null).size());
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user2.getKey(), ORGANIZATION_UNIT,
null).size());
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user3.getKey(), ORGANIZATION,
null).size());
- assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user3.getKey(), ORGANIZATION_UNIT,
null).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4.getKey(), ORGANIZATION,
null).size());
- assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4.getKey(), ORGANIZATION_UNIT,
null).size());
-
- // Cleanup and check
- session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2, user3));
- session.getRelationshipManager().disassociateUsers(Arrays.asList(group3),
Arrays.asList(user2, user3));
- session.getRelationshipManager().disassociateGroups(Arrays.asList(group2),
Arrays.asList(group3, group4));
-
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2, user3)));
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group2),
Arrays.asList(group3, group4, group5)));
- assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group3),
Arrays.asList(user2, user3)));
-
- ctx.commit();
-
- }
-
- public void testCascade(String realmName) throws Exception
- {
-
- IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
-
- IdentitySession session = factory.createIdentitySession(realmName);
-
- ctx.begin();
-
- // Create stuff
- User user1 = session.getPersistenceManager().createUser("user1");
- User user2 = session.getPersistenceManager().createUser("user2");
- User user3 = session.getPersistenceManager().createUser("user3");
- User user4 = session.getPersistenceManager().createUser("user4");
- User user5 = session.getPersistenceManager().createUser("user5");
- User user6 = session.getPersistenceManager().createUser("user6");
- User user7 = session.getPersistenceManager().createUser("user7");
-
- Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
- Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION);
- Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION);
- Group group4 = session.getPersistenceManager().createGroup("group4",
ORGANIZATION);
- Group group5 = session.getPersistenceManager().createGroup("group5",
ORGANIZATION);
-
-
- // Create looped associations
- session.getRelationshipManager().associateGroups(group1, group2);
- session.getRelationshipManager().associateGroups(group1, group3);
- session.getRelationshipManager().associateGroups(group2, group4);
- session.getRelationshipManager().associateGroups(group2, group5);
- session.getRelationshipManager().associateGroups(group3, group1);
-
- // Assign users
- session.getRelationshipManager().associateUser(group1, user1);
- session.getRelationshipManager().associateUser(group2, user2);
- session.getRelationshipManager().associateUser(group3, user3);
- session.getRelationshipManager().associateUser(group5, user4);
- session.getRelationshipManager().associateUser(group5, user5);
-
-
- // Make sure that algorithm doesn't go in a loop
- Collection<Group> results = session.getRelationshipManager().
- findAssociatedGroups(group1, ORGANIZATION, true, true);
-
- assertEquals(4, results.size());
- assertFalse(results.contains(group1));
- assertTrue(results.contains(group2));
- assertTrue(results.contains(group3));
- assertTrue(results.contains(group4));
- assertTrue(results.contains(group5));
-
-
- // And get all users associated in a tree
- Collection<User> results2 = session.getRelationshipManager().
- findAssociatedUsers(group1, true);
-
- assertEquals(5, results2.size());
- assertFalse(results2.contains(user6));
- assertFalse(results2.contains(user7));
- assertTrue(results2.contains(user1));
- assertTrue(results2.contains(user2));
- assertTrue(results2.contains(user3));
- assertTrue(results2.contains(user4));
- assertTrue(results2.contains(user5));
-
- }
-
- public void testMergedRoleAssociations(String realmName) throws Exception
- {
- IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
-
- IdentitySession session = factory.createIdentitySession(realmName);
-
- ctx.begin();
-
- // Create stuff
- User user1 = session.getPersistenceManager().createUser("user1");
- User user2 = session.getPersistenceManager().createUser("user2");
- User user3 = session.getPersistenceManager().createUser("user3");
- User user4 = session.getPersistenceManager().createUser("user4");
-
- Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
- Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
- Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
- Group group4 = session.getPersistenceManager().createGroup("group4",
DEPARTMENT);
- Group group5 = session.getPersistenceManager().createGroup("group5",
DEPARTMENT);
-
- // Associate
-
- session.getRelationshipManager().associateGroups(group1, group2);
- session.getRelationshipManager().associateGroups(group1, group3);
- session.getRelationshipManager().associateUser(group1, user1);
- session.getRelationshipManager().associateUser(group1, user2);
-
- session.getRoleManager().createRoleType("rt1");
- session.getRoleManager().createRoleType("rt2");
-
- session.getRoleManager().createRole("rt1", user1.getKey(),
group1.getKey());
- session.getRoleManager().createRole("rt1", user3.getKey(),
group1.getKey());
- session.getRoleManager().createRole("rt1", user4.getKey(),
group1.getKey());
- session.getRoleManager().createRole("rt2", user3.getKey(),
group1.getKey());
-
- session.getRoleManager().createRole("rt1", user3.getKey(),
group2.getKey());
- session.getRoleManager().createRole("rt2", user2.getKey(),
group3.getKey());
-
- // Assert
-
- assertEquals(2, session.getRelationshipManager().findAssociatedUsers(group1, false,
null).size());
- assertEquals(4, session.getRelationshipManager().findRelatedUsers(group1,
null).size());
-
- assertEquals(0, session.getRelationshipManager().findAssociatedUsers(group2, false,
null).size());
- assertEquals(1, session.getRelationshipManager().findRelatedUsers(group2,
null).size());
-
- assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user3,
(IdentitySearchCriteria)null).size());
- assertEquals(2, session.getRelationshipManager().findRelatedGroups(user3, null,
null).size());
-
- assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user2,
(IdentitySearchCriteria)null).size());
- assertEquals(2, session.getRelationshipManager().findRelatedGroups(user2, null,
null).size());
-
- ctx.commit();
-
- }
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RelationshipManagerTest.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/RelationshipManagerTest.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RelationshipManagerTest.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RelationshipManagerTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,455 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.api.IdentitySearchCriteria;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+/**
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RelationshipManagerTest extends Assert
+{
+ //TODO:
+ //TODO: - inheritence in find methods
+ //TODO: - creating forbidden associations
+ //TODO: - exception handling
+ //TODO: - search criteria
+ //TODO: - features description
+
+ APITestContext ctx;
+
+ private String ORGANIZATION = "ORGANIZATION";
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ private String DIVISION = "DIVISION";
+ private String DEPARTMENT = "DEPARTMENT";
+ private String PROJECT = "PROJECT";
+ private String PEOPLE = "PEOPLE";
+
+ public RelationshipManagerTest(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public void setCtx(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public APITestContext getCtx()
+ {
+ return ctx;
+ }
+
+ public void testMethods(String realmName) throws Exception
+ {
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session = factory.createIdentitySession(realmName);
+
+ ctx.begin();
+
+ // Create stuff
+ User user1 = session.getPersistenceManager().createUser("user1");
+ User user2 = session.getPersistenceManager().createUser("user2");
+ User user3 = session.getPersistenceManager().createUser("user3");
+ User user4 = session.getPersistenceManager().createUser("user4");
+
+ Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = session.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = session.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+
+ // Associate groups
+
+ session.getRelationshipManager().associateGroups(group1, group2);
+ session.getRelationshipManager().associateGroups(group1, group3);
+
+ // Assert
+
+ // isAssociated
+
+ assertTrue(session.getRelationshipManager().isAssociated(group1, group2));
+ assertTrue(session.getRelationshipManager().isAssociated(group1, group3));
+ assertFalse(session.getRelationshipManager().isAssociated(group1, group4));
+ assertFalse(session.getRelationshipManager().isAssociated(group2, group1));
+ assertFalse(session.getRelationshipManager().isAssociated(group2, group3));
+
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2), Arrays.asList(group2, group3)));
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group2,
group3), Arrays.asList(group1)));
+
+ assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
group2.getKey()));
+ assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
group3.getKey()));
+ assertFalse(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
group4.getKey()));
+ assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
group1.getKey()));
+ assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
group3.getKey()));
+
+ assertTrue(session.getRelationshipManager().
+ isAssociatedByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(group2.getKey(), group3.getKey())));
+ assertFalse(session.getRelationshipManager().
+ isAssociatedByKeys(Arrays.asList(group1.getKey(), group2.getKey()),
Arrays.asList(group2.getKey(), group3.getKey())));
+ assertFalse(session.getRelationshipManager().
+ isAssociatedByKeys(Arrays.asList(group2.getKey(), group3.getKey()),
Arrays.asList(group1.getKey())));
+
+
+ // Associate groups - other methods
+
+ // First disassociate and assert
+ session.getRelationshipManager().disassociateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
+
+ assertFalse(session.getRelationshipManager().isAssociated(group1, group2));
+ assertFalse(session.getRelationshipManager().isAssociated(group1, group3));
+
+ // reassociate #1
+ session.getRelationshipManager().associateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
+
+
session.getRelationshipManager().disassociateGroupsByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(group2.getKey(), group3.getKey()));
+
+ // reassociate #2
+
session.getRelationshipManager().associateGroupsByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(group2.getKey(), group3.getKey()));
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
+
+ session.getRelationshipManager().disassociateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
+
+ // reassociate #3
+ session.getRelationshipManager().associateGroupsByKeys(group1.getKey(),
group2.getKey());
+ session.getRelationshipManager().associateGroupsByKeys(group1.getKey(),
group3.getKey());
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(group2, group3)));
+
+ session.getRelationshipManager().disassociateGroups(Arrays.asList(group1),
Arrays.asList(group2, group3));
+
+
+ // Associate Group and Users
+
+ session.getRelationshipManager().associateUser(group1, user1);
+ session.getRelationshipManager().associateUser(group1, user2);
+
+ // isAssociated
+
+ assertTrue(session.getRelationshipManager().isAssociated(group1, user1));
+ assertTrue(session.getRelationshipManager().isAssociated(group1, user2));
+ assertFalse(session.getRelationshipManager().isAssociated(group1, user3));
+ assertFalse(session.getRelationshipManager().isAssociated(group2, user1));
+ assertFalse(session.getRelationshipManager().isAssociated(group2, user3));
+
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2), Arrays.asList(user1, user2)));
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group2),
Arrays.asList(user3)));
+
+ assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
user1.getKey()));
+ assertTrue(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
user2.getKey()));
+ assertFalse(session.getRelationshipManager().isAssociatedByKeys(group1.getKey(),
user3.getKey()));
+ assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
user1.getKey()));
+ assertFalse(session.getRelationshipManager().isAssociatedByKeys(group2.getKey(),
user3.getKey()));
+
+ assertTrue(session.getRelationshipManager().
+ isAssociatedByKeys(Arrays.asList(group1.getKey()), Arrays.asList(user1.getKey(),
user2.getKey())));
+ assertFalse(session.getRelationshipManager().
+ isAssociatedByKeys(Arrays.asList(group1.getKey(), group2.getKey()),
Arrays.asList(user1.getKey(), user2.getKey())));
+ assertFalse(session.getRelationshipManager().
+ isAssociatedByKeys(Arrays.asList(group2.getKey(), group3.getKey()),
Arrays.asList(user1.getKey())));
+
+
+ // Associate groups / users - other methods
+
+ // First disassociate and assert
+ session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
+
+ assertFalse(session.getRelationshipManager().isAssociated(group1, user1));
+ assertFalse(session.getRelationshipManager().isAssociated(group1, user2));
+
+ // reassociate #1
+ session.getRelationshipManager().associateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
+
+ session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
+
+ // reassociate #2
+
session.getRelationshipManager().associateUsersByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(user1.getKey(), user2.getKey()));
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
+
+
session.getRelationshipManager().disassociateUsersByKeys(Arrays.asList(group1.getKey()),
Arrays.asList(user1.getKey(), user2.getKey()));
+
+ // reassociate #3
+ session.getRelationshipManager().associateUserByKeys(group1.getKey(),
user1.getKey());
+ session.getRelationshipManager().associateUserByKeys(group1.getKey(),
user2.getKey());
+
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2)));
+
+ session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2));
+
+ // reassociate #4
+ session.getRelationshipManager().associateUserByKeys(group1.getKey(),
user1.getKey());
+ session.getRelationshipManager().associateUserByKeys(group2.getKey(),
user1.getKey());
+ session.getRelationshipManager().associateUserByKeys(group3.getKey(),
user1.getKey());
+
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2, group3), Arrays.asList(user1)));
+
+ session.getRelationshipManager().disassociateGroups(user1);
+
+ assertFalse(session.getRelationshipManager().isAssociated(group1, user1));
+ assertFalse(session.getRelationshipManager().isAssociated(group2, user1));
+ assertFalse(session.getRelationshipManager().isAssociated(group3, user1));
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1,
group2, group3), Arrays.asList(user1)));
+
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user1).size());
+
+
+
+ ctx.commit();
+
+ ctx.begin();
+
+
+ // Find methods - prepopulate
+
+ session.getRelationshipManager().associateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2, user3));
+ session.getRelationshipManager().associateUsers(Arrays.asList(group3),
Arrays.asList(user2, user3));
+ session.getRelationshipManager().associateGroups(Arrays.asList(group2),
Arrays.asList(group3, group4, group5));
+
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2, user3)));
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group2),
Arrays.asList(group3, group4, group5)));
+ assertTrue(session.getRelationshipManager().isAssociated(Arrays.asList(group3),
Arrays.asList(user2, user3)));
+
+ ctx.commit();
+ ctx.begin();
+
+ // Find users
+ //TODO: check if collections contain correct objects (not only size)
+
+ assertEquals(3, session.getRelationshipManager().findAssociatedUsers(group1,
false).size());
+ assertEquals(0, session.getRelationshipManager().findAssociatedUsers(group2,
false).size());
+
+ assertEquals(3, session.getRelationshipManager().findAssociatedUsers(group1, false,
null).size());
+ assertEquals(0, session.getRelationshipManager().findAssociatedUsers(group2, false,
null).size());
+
+ assertEquals(3,
session.getRelationshipManager().findAssociatedUsers(group1.getKey(), false,
null).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedUsers(group2.getKey(), false,
null).size());
+
+ // Find groups
+
+ // #1
+ assertEquals(3, session.getRelationshipManager().findAssociatedGroups(group2, null,
true, false).size());
+ assertEquals(2, session.getRelationshipManager().findAssociatedGroups(group2,
DEPARTMENT, true, false).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(group2,
ORGANIZATION_UNIT, true, false).size());
+ assertEquals(0, session.getRelationshipManager().findAssociatedGroups(group2,
ORGANIZATION, true, false).size());
+
+ // #1
+ assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), DEPARTMENT, true,
false, null).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), ORGANIZATION_UNIT,
true, false, null).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), ORGANIZATION, true,
false, null).size());
+
+ // #3
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(group3,
ORGANIZATION_UNIT, false, false).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(group4,
ORGANIZATION_UNIT, false, false).size());
+ assertEquals(0, session.getRelationshipManager().findAssociatedGroups(group2,
ORGANIZATION, false, false).size());
+ assertEquals(3, session.getRelationshipManager().findAssociatedGroups(group2, null,
true, false).size());
+
+ // #4
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(group3.getKey(), ORGANIZATION_UNIT,
false, false, null).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(group4.getKey(), ORGANIZATION_UNIT,
false, false, null).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(group2.getKey(), ORGANIZATION,
false, false, null).size());
+
+ // #5
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user1).size());
+ assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user2).size());
+ assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user3).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4).size());
+
+ // #6
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user1.getKey(), null).size());
+ assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user2.getKey(), null).size());
+ assertEquals(2,
session.getRelationshipManager().findAssociatedGroups(user3.getKey(), null).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4.getKey(), null).size());
+
+ // #7
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user1,
ORGANIZATION).size());
+ assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user1,
ORGANIZATION_UNIT).size());
+ assertEquals(2, session.getRelationshipManager().findAssociatedGroups(user2,
(String)null).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user2,
ORGANIZATION).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user2,
ORGANIZATION_UNIT).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user3,
ORGANIZATION).size());
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user3,
ORGANIZATION_UNIT).size());
+ assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user4,
ORGANIZATION).size());
+ assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user4,
ORGANIZATION_UNIT).size());
+
+ // #7
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user1.getKey(), ORGANIZATION,
null).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user1.getKey(), ORGANIZATION_UNIT,
null).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user2.getKey(), ORGANIZATION,
null).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user2.getKey(), ORGANIZATION_UNIT,
null).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user3.getKey(), ORGANIZATION,
null).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedGroups(user3.getKey(), ORGANIZATION_UNIT,
null).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4.getKey(), ORGANIZATION,
null).size());
+ assertEquals(0,
session.getRelationshipManager().findAssociatedGroups(user4.getKey(), ORGANIZATION_UNIT,
null).size());
+
+ // Cleanup and check
+ session.getRelationshipManager().disassociateUsers(Arrays.asList(group1),
Arrays.asList(user1, user2, user3));
+ session.getRelationshipManager().disassociateUsers(Arrays.asList(group3),
Arrays.asList(user2, user3));
+ session.getRelationshipManager().disassociateGroups(Arrays.asList(group2),
Arrays.asList(group3, group4));
+
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group1),
Arrays.asList(user1, user2, user3)));
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group2),
Arrays.asList(group3, group4, group5)));
+ assertFalse(session.getRelationshipManager().isAssociated(Arrays.asList(group3),
Arrays.asList(user2, user3)));
+
+ ctx.commit();
+
+ }
+
+ public void testCascade(String realmName) throws Exception
+ {
+
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session = factory.createIdentitySession(realmName);
+
+ ctx.begin();
+
+ // Create stuff
+ User user1 = session.getPersistenceManager().createUser("user1");
+ User user2 = session.getPersistenceManager().createUser("user2");
+ User user3 = session.getPersistenceManager().createUser("user3");
+ User user4 = session.getPersistenceManager().createUser("user4");
+ User user5 = session.getPersistenceManager().createUser("user5");
+ User user6 = session.getPersistenceManager().createUser("user6");
+ User user7 = session.getPersistenceManager().createUser("user7");
+
+ Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION);
+ Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION);
+ Group group4 = session.getPersistenceManager().createGroup("group4",
ORGANIZATION);
+ Group group5 = session.getPersistenceManager().createGroup("group5",
ORGANIZATION);
+
+
+ // Create looped associations
+ session.getRelationshipManager().associateGroups(group1, group2);
+ session.getRelationshipManager().associateGroups(group1, group3);
+ session.getRelationshipManager().associateGroups(group2, group4);
+ session.getRelationshipManager().associateGroups(group2, group5);
+ session.getRelationshipManager().associateGroups(group3, group1);
+
+ // Assign users
+ session.getRelationshipManager().associateUser(group1, user1);
+ session.getRelationshipManager().associateUser(group2, user2);
+ session.getRelationshipManager().associateUser(group3, user3);
+ session.getRelationshipManager().associateUser(group5, user4);
+ session.getRelationshipManager().associateUser(group5, user5);
+
+
+ // Make sure that algorithm doesn't go in a loop
+ Collection<Group> results = session.getRelationshipManager().
+ findAssociatedGroups(group1, ORGANIZATION, true, true);
+
+ assertEquals(4, results.size());
+ assertFalse(results.contains(group1));
+ assertTrue(results.contains(group2));
+ assertTrue(results.contains(group3));
+ assertTrue(results.contains(group4));
+ assertTrue(results.contains(group5));
+
+
+ // And get all users associated in a tree
+ Collection<User> results2 = session.getRelationshipManager().
+ findAssociatedUsers(group1, true);
+
+ assertEquals(5, results2.size());
+ assertFalse(results2.contains(user6));
+ assertFalse(results2.contains(user7));
+ assertTrue(results2.contains(user1));
+ assertTrue(results2.contains(user2));
+ assertTrue(results2.contains(user3));
+ assertTrue(results2.contains(user4));
+ assertTrue(results2.contains(user5));
+
+ }
+
+ public void testMergedRoleAssociations(String realmName) throws Exception
+ {
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session = factory.createIdentitySession(realmName);
+
+ ctx.begin();
+
+ // Create stuff
+ User user1 = session.getPersistenceManager().createUser("user1");
+ User user2 = session.getPersistenceManager().createUser("user2");
+ User user3 = session.getPersistenceManager().createUser("user3");
+ User user4 = session.getPersistenceManager().createUser("user4");
+
+ Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = session.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = session.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+ // Associate
+
+ session.getRelationshipManager().associateGroups(group1, group2);
+ session.getRelationshipManager().associateGroups(group1, group3);
+ session.getRelationshipManager().associateUser(group1, user1);
+ session.getRelationshipManager().associateUser(group1, user2);
+
+ session.getRoleManager().createRoleType("rt1");
+ session.getRoleManager().createRoleType("rt2");
+
+ session.getRoleManager().createRole("rt1", user1.getKey(),
group1.getKey());
+ session.getRoleManager().createRole("rt1", user3.getKey(),
group1.getKey());
+ session.getRoleManager().createRole("rt1", user4.getKey(),
group1.getKey());
+ session.getRoleManager().createRole("rt2", user3.getKey(),
group1.getKey());
+
+ session.getRoleManager().createRole("rt1", user3.getKey(),
group2.getKey());
+ session.getRoleManager().createRole("rt2", user2.getKey(),
group3.getKey());
+
+ // Assert
+
+ assertEquals(2, session.getRelationshipManager().findAssociatedUsers(group1, false,
null).size());
+ assertEquals(4, session.getRelationshipManager().findRelatedUsers(group1,
null).size());
+
+ assertEquals(0, session.getRelationshipManager().findAssociatedUsers(group2, false,
null).size());
+ assertEquals(1, session.getRelationshipManager().findRelatedUsers(group2,
null).size());
+
+ assertEquals(0, session.getRelationshipManager().findAssociatedGroups(user3,
(IdentitySearchCriteria)null).size());
+ assertEquals(2, session.getRelationshipManager().findRelatedGroups(user3, null,
null).size());
+
+ assertEquals(1, session.getRelationshipManager().findAssociatedGroups(user2,
(IdentitySearchCriteria)null).size());
+ assertEquals(2, session.getRelationshipManager().findRelatedGroups(user2, null,
null).size());
+
+ ctx.commit();
+
+ }
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleManagerTest.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/RoleManagerTest.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleManagerTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,285 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.Group;
-import org.jboss.identity.idm.api.User;
-import org.jboss.identity.idm.api.RoleType;
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.api.Role;
-
-import junit.framework.Assert;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- *
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class RoleManagerTest extends Assert
-{
- //TODO:
- //TODO: - exception handling
- //TODO: - search criteria
- //TODO: - features description
-
- APITestContext ctx;
-
- private String ORGANIZATION = "ORGANIZATION";
- private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
- private String DIVISION = "DIVISION";
- private String DEPARTMENT = "DEPARTMENT";
- private String PROJECT = "PROJECT";
- private String PEOPLE = "PEOPLE";
-
- public RoleManagerTest(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public void setCtx(APITestContext ctx)
- {
- this.ctx = ctx;
- }
-
- public APITestContext getCtx()
- {
- return ctx;
- }
-
- public void testMethods(String realmName) throws Exception
- {
- IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
-
- IdentitySession session = factory.createIdentitySession(realmName);
-
- ctx.begin();
-
-
-
- // RoleTypes - pure
- assertEquals(0, session.getRoleManager().findRoleTypes(null).size());
-
- // Create / remove
- RoleType rt1 = session.getRoleManager().createRoleType("rt1");
- RoleType rt2 = session.getRoleManager().createRoleType("rt2");
- RoleType rt3 = session.getRoleManager().createRoleType("rt3");
- RoleType rt4 = session.getRoleManager().createRoleType("rt4");
-
- assertEquals(4, session.getRoleManager().findRoleTypes(null).size());
-
- session.getRoleManager().removeRoleType(rt1);
- session.getRoleManager().removeRoleType(rt2);
-
- assertEquals(2, session.getRoleManager().findRoleTypes(null).size());
-
- session.getRoleManager().removeRoleType("rt3");
- session.getRoleManager().removeRoleType("rt4");
-
- assertEquals(0, session.getRoleManager().findRoleTypes(null).size());
-
- // Create all entities for tests
-
- User user1 = session.getPersistenceManager().createUser("user1");
- User user2 = session.getPersistenceManager().createUser("user2");
- User user3 = session.getPersistenceManager().createUser("user3");
- User user4 = session.getPersistenceManager().createUser("user4");
-
- Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
- Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
- Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
- Group group4 = session.getPersistenceManager().createGroup("group4",
DEPARTMENT);
- Group group5 = session.getPersistenceManager().createGroup("group5",
DEPARTMENT);
-
- rt1 = session.getRoleManager().createRoleType("rt1");
- rt2 = session.getRoleManager().createRoleType("rt2");
- rt3 = session.getRoleManager().createRoleType("rt3");
- rt4 = session.getRoleManager().createRoleType("rt4");
-
- assertEquals(4, session.getRoleManager().findRoleTypes(null).size());
-
-
-
-
- // Create/remove and find roles
-
- Role role1 = session.getRoleManager().createRole(rt1, user1, group1);
- Role role2 = session.getRoleManager().createRole(rt1, user1, group2);
- Role role3 = session.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
-
-
-
-
- //
-
- assertEquals(2, session.getRoleManager().findRoles(user1, rt1).size());
- assertEquals(1, session.getRoleManager().findRoles(user1, rt2).size());
- assertEquals(1, session.getRoleManager().findRoles(group1, rt1).size());
- assertEquals(1, session.getRoleManager().findRoles(group1, rt2).size());
-
- //
-
- assertEquals(2, session.getRoleManager().findGroupRoleTypes(group1).size());
- assertEquals(1, session.getRoleManager().findGroupRoleTypes(group2.getKey(),
null).size());
-
- //
-
- assertEquals(2, session.getRoleManager().findRoles(user1, rt1).size());
- assertEquals(1, session.getRoleManager().findRoles(user1.getKey(),
"rt2").size());
- assertEquals(1, session.getRoleManager().findRoles(group1.getKey(),
"rt1").size());
- assertEquals(1, session.getRoleManager().findRoles(group1, rt1).size());
-
- //
-
- assertEquals(2, session.getRoleManager().findGroupsWithRelatedRole(user1,
null).size());
- assertEquals(1, session.getRoleManager().findGroupsWithRelatedRole(user1.getKey(),
ORGANIZATION, null).size());
-
- //
-
- assertEquals(2, session.getRoleManager().findRoleTypes(user1, group1).size());
- assertEquals(1, session.getRoleManager().findRoleTypes(user1.getKey(),
group2.getKey(), null).size());
-
- //
-
- assertEquals(2, session.getRoleManager().findUserRoleTypes(user1).size());
- assertEquals(0, session.getRoleManager().findUserRoleTypes(user2.getKey(),
null).size());
-
- //
- assertTrue(session.getRoleManager().hasRole(user1, group1, rt1));
- assertTrue(session.getRoleManager().hasRole(user1, group1, rt2));
- assertTrue(session.getRoleManager().hasRole("user1", group2.getKey(),
"rt1"));
- assertFalse(session.getRoleManager().hasRole("user2", group2.getKey(),
"rt1"));
- assertFalse(session.getRoleManager().hasRole(user1, group1, rt3));
- assertFalse(session.getRoleManager().hasRole(user1, group4, rt3));
-
- // Role properties
-
- assertEquals(0, session.getRoleManager().getProperties(role1).keySet().size());
- assertEquals(0, session.getRoleManager().getProperties(rt1).keySet().size());
- assertEquals(0,
session.getRoleManager().getProperties(rt1.getName()).keySet().size());
-
- session.getRoleManager().setProperty(role1, "roleProp1",
"val1");
- session.getRoleManager().setProperty(role1, "roleProp1",
"val2");
- session.getRoleManager().setProperty(role1, "roleProp2",
"val1");
- session.getRoleManager().setProperty(rt1, "rtProp1", "val1");
- session.getRoleManager().setProperty(rt1.getName(), "rtProp1",
"val2");
- session.getRoleManager().setProperty(rt1, "rtProp2", "val1");
- session.getRoleManager().setProperty(rt1, "rtProp3", "val1");
-
- assertEquals(2, session.getRoleManager().getProperties(role1).keySet().size());
- assertEquals(3, session.getRoleManager().getProperties(rt1).keySet().size());
- assertEquals(3,
session.getRoleManager().getProperties(rt1.getName()).keySet().size());
-
- assertEquals("val2",
session.getRoleManager().getProperties(role1).get("roleProp1"));
- assertEquals("val1",
session.getRoleManager().getProperties(role1).get("roleProp2"));
- assertEquals("val2",
session.getRoleManager().getProperties(rt1).get("rtProp1"));
- assertEquals("val1",
session.getRoleManager().getProperties(rt1).get("rtProp2"));
- assertEquals("val1",
session.getRoleManager().getProperties(rt1).get("rtProp3"));
-
-
- Map<String, String> props = new HashMap<String, String>();
- props.put("prop5", "val1");
-
- session.getRoleManager().setProperties(role2, props);
-
- assertEquals(1, session.getRoleManager().getProperties(role2).keySet().size());
-
- assertEquals("val1",
session.getRoleManager().getProperties(role2).get("prop5"));
-
-
- props.put("prop6", "val3");
- session.getRoleManager().setProperties(rt2, props);
- session.getRoleManager().setProperties(rt3.getName(), props);
-
- assertEquals(2, session.getRoleManager().getProperties(rt2).keySet().size());
-
- assertEquals("val3",
session.getRoleManager().getProperties(rt2).get("prop6"));
- assertEquals("val3",
session.getRoleManager().getProperties(rt3).get("prop6"));
-
-
- session.getRoleManager().removeProperty(role2, "prop5");
- assertEquals(0, session.getRoleManager().getProperties(role2).keySet().size());
-
- session.getRoleManager().removeProperty(rt2, "prop6");
- assertEquals(1, session.getRoleManager().getProperties(rt2).keySet().size());
- session.getRoleManager().removeProperty(rt2, "prop5");
- assertEquals(0, session.getRoleManager().getProperties(rt2).keySet().size());
-
-
- // Remove roles
-
- session.getRoleManager().removeRole(rt1, user1, group1);
- session.getRoleManager().removeRole(role2);
- session.getRoleManager().removeRole("rt2", user1.getKey(),
group1.getKey());
-
- assertFalse(session.getRoleManager().hasRole(user1, group1, rt1));
- assertFalse(session.getRoleManager().hasRole(user1, group1, rt2));
- assertFalse(session.getRoleManager().hasRole("user1", group2.getKey(),
"rt1"));
-
- //
-
- assertEquals(0, session.getRoleManager().findRoles(user1, rt1).size());
- assertEquals(0, session.getRoleManager().findRoles(user1, rt2).size());
- assertEquals(0, session.getRoleManager().findRoles(group1, rt1).size());
- assertEquals(0, session.getRoleManager().findRoles(group1, rt2).size());
-
- //
-
- assertEquals(0, session.getRoleManager().findGroupRoleTypes(group1).size());
- assertEquals(0, session.getRoleManager().findGroupRoleTypes(group2.getKey(),
null).size());
-
- //
-
- assertEquals(0, session.getRoleManager().findRoles(user1, rt1).size());
- assertEquals(0, session.getRoleManager().findRoles(user1.getKey(),
"rt2").size());
- assertEquals(0, session.getRoleManager().findRoles(group1.getKey(),
"rt1").size());
- assertEquals(0, session.getRoleManager().findRoles(group1, rt1).size());
-
- //
-
- assertEquals(0, session.getRoleManager().findGroupsWithRelatedRole(user1,
null).size());
- assertEquals(0, session.getRoleManager().findGroupsWithRelatedRole(user1.getKey(),
ORGANIZATION, null).size());
-
- //
-
- assertEquals(0, session.getRoleManager().findRoleTypes(user1, group1).size());
- assertEquals(0, session.getRoleManager().findRoleTypes(user1.getKey(),
group2.getKey(), null).size());
-
- //
-
- assertEquals(0, session.getRoleManager().findUserRoleTypes(user1).size());
- assertEquals(0, session.getRoleManager().findUserRoleTypes(user2.getKey(),
null).size());
-
-
-
-
- ctx.commit();
-
- }
-
-
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleManagerTest.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/RoleManagerTest.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleManagerTest.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleManagerTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,285 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.api.RoleType;
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.api.Role;
+
+import junit.framework.Assert;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RoleManagerTest extends Assert
+{
+ //TODO:
+ //TODO: - exception handling
+ //TODO: - search criteria
+ //TODO: - features description
+
+ APITestContext ctx;
+
+ private String ORGANIZATION = "ORGANIZATION";
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ private String DIVISION = "DIVISION";
+ private String DEPARTMENT = "DEPARTMENT";
+ private String PROJECT = "PROJECT";
+ private String PEOPLE = "PEOPLE";
+
+ public RoleManagerTest(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public void setCtx(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public APITestContext getCtx()
+ {
+ return ctx;
+ }
+
+ public void testMethods(String realmName) throws Exception
+ {
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session = factory.createIdentitySession(realmName);
+
+ ctx.begin();
+
+
+
+ // RoleTypes - pure
+ assertEquals(0, session.getRoleManager().findRoleTypes(null).size());
+
+ // Create / remove
+ RoleType rt1 = session.getRoleManager().createRoleType("rt1");
+ RoleType rt2 = session.getRoleManager().createRoleType("rt2");
+ RoleType rt3 = session.getRoleManager().createRoleType("rt3");
+ RoleType rt4 = session.getRoleManager().createRoleType("rt4");
+
+ assertEquals(4, session.getRoleManager().findRoleTypes(null).size());
+
+ session.getRoleManager().removeRoleType(rt1);
+ session.getRoleManager().removeRoleType(rt2);
+
+ assertEquals(2, session.getRoleManager().findRoleTypes(null).size());
+
+ session.getRoleManager().removeRoleType("rt3");
+ session.getRoleManager().removeRoleType("rt4");
+
+ assertEquals(0, session.getRoleManager().findRoleTypes(null).size());
+
+ // Create all entities for tests
+
+ User user1 = session.getPersistenceManager().createUser("user1");
+ User user2 = session.getPersistenceManager().createUser("user2");
+ User user3 = session.getPersistenceManager().createUser("user3");
+ User user4 = session.getPersistenceManager().createUser("user4");
+
+ Group group1 = session.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = session.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = session.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = session.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = session.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+ rt1 = session.getRoleManager().createRoleType("rt1");
+ rt2 = session.getRoleManager().createRoleType("rt2");
+ rt3 = session.getRoleManager().createRoleType("rt3");
+ rt4 = session.getRoleManager().createRoleType("rt4");
+
+ assertEquals(4, session.getRoleManager().findRoleTypes(null).size());
+
+
+
+
+ // Create/remove and find roles
+
+ Role role1 = session.getRoleManager().createRole(rt1, user1, group1);
+ Role role2 = session.getRoleManager().createRole(rt1, user1, group2);
+ Role role3 = session.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
+
+
+
+
+ //
+
+ assertEquals(2, session.getRoleManager().findRoles(user1, rt1).size());
+ assertEquals(1, session.getRoleManager().findRoles(user1, rt2).size());
+ assertEquals(1, session.getRoleManager().findRoles(group1, rt1).size());
+ assertEquals(1, session.getRoleManager().findRoles(group1, rt2).size());
+
+ //
+
+ assertEquals(2, session.getRoleManager().findGroupRoleTypes(group1).size());
+ assertEquals(1, session.getRoleManager().findGroupRoleTypes(group2.getKey(),
null).size());
+
+ //
+
+ assertEquals(2, session.getRoleManager().findRoles(user1, rt1).size());
+ assertEquals(1, session.getRoleManager().findRoles(user1.getKey(),
"rt2").size());
+ assertEquals(1, session.getRoleManager().findRoles(group1.getKey(),
"rt1").size());
+ assertEquals(1, session.getRoleManager().findRoles(group1, rt1).size());
+
+ //
+
+ assertEquals(2, session.getRoleManager().findGroupsWithRelatedRole(user1,
null).size());
+ assertEquals(1, session.getRoleManager().findGroupsWithRelatedRole(user1.getKey(),
ORGANIZATION, null).size());
+
+ //
+
+ assertEquals(2, session.getRoleManager().findRoleTypes(user1, group1).size());
+ assertEquals(1, session.getRoleManager().findRoleTypes(user1.getKey(),
group2.getKey(), null).size());
+
+ //
+
+ assertEquals(2, session.getRoleManager().findUserRoleTypes(user1).size());
+ assertEquals(0, session.getRoleManager().findUserRoleTypes(user2.getKey(),
null).size());
+
+ //
+ assertTrue(session.getRoleManager().hasRole(user1, group1, rt1));
+ assertTrue(session.getRoleManager().hasRole(user1, group1, rt2));
+ assertTrue(session.getRoleManager().hasRole("user1", group2.getKey(),
"rt1"));
+ assertFalse(session.getRoleManager().hasRole("user2", group2.getKey(),
"rt1"));
+ assertFalse(session.getRoleManager().hasRole(user1, group1, rt3));
+ assertFalse(session.getRoleManager().hasRole(user1, group4, rt3));
+
+ // Role properties
+
+ assertEquals(0, session.getRoleManager().getProperties(role1).keySet().size());
+ assertEquals(0, session.getRoleManager().getProperties(rt1).keySet().size());
+ assertEquals(0,
session.getRoleManager().getProperties(rt1.getName()).keySet().size());
+
+ session.getRoleManager().setProperty(role1, "roleProp1",
"val1");
+ session.getRoleManager().setProperty(role1, "roleProp1",
"val2");
+ session.getRoleManager().setProperty(role1, "roleProp2",
"val1");
+ session.getRoleManager().setProperty(rt1, "rtProp1", "val1");
+ session.getRoleManager().setProperty(rt1.getName(), "rtProp1",
"val2");
+ session.getRoleManager().setProperty(rt1, "rtProp2", "val1");
+ session.getRoleManager().setProperty(rt1, "rtProp3", "val1");
+
+ assertEquals(2, session.getRoleManager().getProperties(role1).keySet().size());
+ assertEquals(3, session.getRoleManager().getProperties(rt1).keySet().size());
+ assertEquals(3,
session.getRoleManager().getProperties(rt1.getName()).keySet().size());
+
+ assertEquals("val2",
session.getRoleManager().getProperties(role1).get("roleProp1"));
+ assertEquals("val1",
session.getRoleManager().getProperties(role1).get("roleProp2"));
+ assertEquals("val2",
session.getRoleManager().getProperties(rt1).get("rtProp1"));
+ assertEquals("val1",
session.getRoleManager().getProperties(rt1).get("rtProp2"));
+ assertEquals("val1",
session.getRoleManager().getProperties(rt1).get("rtProp3"));
+
+
+ Map<String, String> props = new HashMap<String, String>();
+ props.put("prop5", "val1");
+
+ session.getRoleManager().setProperties(role2, props);
+
+ assertEquals(1, session.getRoleManager().getProperties(role2).keySet().size());
+
+ assertEquals("val1",
session.getRoleManager().getProperties(role2).get("prop5"));
+
+
+ props.put("prop6", "val3");
+ session.getRoleManager().setProperties(rt2, props);
+ session.getRoleManager().setProperties(rt3.getName(), props);
+
+ assertEquals(2, session.getRoleManager().getProperties(rt2).keySet().size());
+
+ assertEquals("val3",
session.getRoleManager().getProperties(rt2).get("prop6"));
+ assertEquals("val3",
session.getRoleManager().getProperties(rt3).get("prop6"));
+
+
+ session.getRoleManager().removeProperty(role2, "prop5");
+ assertEquals(0, session.getRoleManager().getProperties(role2).keySet().size());
+
+ session.getRoleManager().removeProperty(rt2, "prop6");
+ assertEquals(1, session.getRoleManager().getProperties(rt2).keySet().size());
+ session.getRoleManager().removeProperty(rt2, "prop5");
+ assertEquals(0, session.getRoleManager().getProperties(rt2).keySet().size());
+
+
+ // Remove roles
+
+ session.getRoleManager().removeRole(rt1, user1, group1);
+ session.getRoleManager().removeRole(role2);
+ session.getRoleManager().removeRole("rt2", user1.getKey(),
group1.getKey());
+
+ assertFalse(session.getRoleManager().hasRole(user1, group1, rt1));
+ assertFalse(session.getRoleManager().hasRole(user1, group1, rt2));
+ assertFalse(session.getRoleManager().hasRole("user1", group2.getKey(),
"rt1"));
+
+ //
+
+ assertEquals(0, session.getRoleManager().findRoles(user1, rt1).size());
+ assertEquals(0, session.getRoleManager().findRoles(user1, rt2).size());
+ assertEquals(0, session.getRoleManager().findRoles(group1, rt1).size());
+ assertEquals(0, session.getRoleManager().findRoles(group1, rt2).size());
+
+ //
+
+ assertEquals(0, session.getRoleManager().findGroupRoleTypes(group1).size());
+ assertEquals(0, session.getRoleManager().findGroupRoleTypes(group2.getKey(),
null).size());
+
+ //
+
+ assertEquals(0, session.getRoleManager().findRoles(user1, rt1).size());
+ assertEquals(0, session.getRoleManager().findRoles(user1.getKey(),
"rt2").size());
+ assertEquals(0, session.getRoleManager().findRoles(group1.getKey(),
"rt1").size());
+ assertEquals(0, session.getRoleManager().findRoles(group1, rt1).size());
+
+ //
+
+ assertEquals(0, session.getRoleManager().findGroupsWithRelatedRole(user1,
null).size());
+ assertEquals(0, session.getRoleManager().findGroupsWithRelatedRole(user1.getKey(),
ORGANIZATION, null).size());
+
+ //
+
+ assertEquals(0, session.getRoleManager().findRoleTypes(user1, group1).size());
+ assertEquals(0, session.getRoleManager().findRoleTypes(user1.getKey(),
group2.getKey(), null).size());
+
+ //
+
+ assertEquals(0, session.getRoleManager().findUserRoleTypes(user1).size());
+ assertEquals(0, session.getRoleManager().findUserRoleTypes(user2.getKey(),
null).size());
+
+
+
+
+ ctx.commit();
+
+ }
+
+
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleQueryTest.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/RoleQueryTest.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleQueryTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,116 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.User;
-import org.jboss.identity.idm.api.Group;
-import org.jboss.identity.idm.api.RoleType;
-import org.jboss.identity.idm.api.Role;
-import org.jboss.identity.idm.api.query.RoleQueryBuilder;
-import org.jboss.identity.idm.api.query.RoleQuery;
-import junit.framework.Assert;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class RoleQueryTest extends Assert
-{
- private APITestContext ctx;
-
- private String ORGANIZATION = "ORGANIZATION";
- private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
- private String DEPARTMENT = "DEPARTMENT";
-
- public RoleQueryTest(APITestContext testContext)
- {
- this.ctx = testContext;
- }
-
- public void testQuery(String realmName) throws Exception
- {
- ctx.begin();
-
- IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
-
- // Create some stuff...
-
- User user1 = ids.getPersistenceManager().createUser("user1");
- User user2 = ids.getPersistenceManager().createUser("user2");
- User user3 = ids.getPersistenceManager().createUser("user3");
- User user4 = ids.getPersistenceManager().createUser("user4");
-
- Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
- Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
- Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
- Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
- Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
-
- RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
- RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
- RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
- RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
-
- Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
- Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
- Role role3 = ids.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
-
- // Test Query
-
- //
- RoleQueryBuilder rqb = ids.createRoleQueryBuilder();
-
- rqb.setUser("user1");
-
- RoleQuery rq = rqb.createQuery();
-
- assertEquals(3, ids.execute(rq).size());
-
- //
- rqb.setGroup(group1);
- rq = rqb.createQuery();
-
- assertEquals(2, ids.execute(rq).size());
-
- //
- rqb.setRoleType(rt2);
- rq = rqb.createQuery();
-
- assertEquals(1, ids.execute(rq).size());
-
-
- //
- rqb.reset();
-
- rqb.setGroup(group2);
- rqb.setRoleType(rt1);
-
- rq = rqb.createQuery();
-
- assertEquals(1, ids.execute(rq).size());
- assertEquals(role2, ids.uniqueResult(rq));
-
- ctx.commit();
- }
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleQueryTest.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/RoleQueryTest.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleQueryTest.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/RoleQueryTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,116 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.RoleType;
+import org.picketlink.idm.api.Role;
+import org.picketlink.idm.api.query.RoleQueryBuilder;
+import org.picketlink.idm.api.query.RoleQuery;
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RoleQueryTest extends Assert
+{
+ private APITestContext ctx;
+
+ private String ORGANIZATION = "ORGANIZATION";
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ private String DEPARTMENT = "DEPARTMENT";
+
+ public RoleQueryTest(APITestContext testContext)
+ {
+ this.ctx = testContext;
+ }
+
+ public void testQuery(String realmName) throws Exception
+ {
+ ctx.begin();
+
+ IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
+
+ // Create some stuff...
+
+ User user1 = ids.getPersistenceManager().createUser("user1");
+ User user2 = ids.getPersistenceManager().createUser("user2");
+ User user3 = ids.getPersistenceManager().createUser("user3");
+ User user4 = ids.getPersistenceManager().createUser("user4");
+
+ Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+ RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
+ RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
+ RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
+ RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
+
+ Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
+ Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
+ Role role3 = ids.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
+
+ // Test Query
+
+ //
+ RoleQueryBuilder rqb = ids.createRoleQueryBuilder();
+
+ rqb.setUser("user1");
+
+ RoleQuery rq = rqb.createQuery();
+
+ assertEquals(3, ids.execute(rq).size());
+
+ //
+ rqb.setGroup(group1);
+ rq = rqb.createQuery();
+
+ assertEquals(2, ids.execute(rq).size());
+
+ //
+ rqb.setRoleType(rt2);
+ rq = rqb.createQuery();
+
+ assertEquals(1, ids.execute(rq).size());
+
+
+ //
+ rqb.reset();
+
+ rqb.setGroup(group2);
+ rqb.setRoleType(rt1);
+
+ rq = rqb.createQuery();
+
+ assertEquals(1, ids.execute(rq).size());
+ assertEquals(role2, ids.uniqueResult(rq));
+
+ ctx.commit();
+ }
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/SimpleTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/SimpleTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/SimpleTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,140 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.impl.IdentityTestPOJO;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-import java.util.logging.Logger;
-
-/**
- * Some iteration to help find possible n+1 selects in logs.
- *
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class SimpleTestCase extends IdentityTestPOJO implements APITestContext
-{
- private static Logger log = Logger.getLogger(SimpleTestCase.class.getName());
-
-
- IdentitySessionFactory identitySessionFactory;
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
-
- setRealmName("realm://RedHat/DB");
-
-
- identitySessionFactory = new IdentityConfigurationImpl().
- configure(getIdentityConfig()).buildIdentitySessionFactory();
-
- log.fine("Statistics after IdentitySessionFactory creation:");
- hibernateSupport.getSessionFactory().getStatistics().logSummary();
-
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- public IdentitySessionFactory getIdentitySessionFactory()
- {
- return identitySessionFactory;
- }
-
- @Test
- public void testPersistenceManager() throws Exception
- {
- IdentitySession session =
identitySessionFactory.createIdentitySession(getRealmName());
-
-
- String ORGANIZATION = "ORGANIZATION";
-
-
-
- for (int i = 0; i < 50; i++)
- {
- log.fine("\n\n\n### Create Group: " + i + "\n");
-
- begin();
- session.getPersistenceManager().createGroup("test" + i,
ORGANIZATION);
- commit();
-
- }
-
- for (int i = 0; i < 50; i++)
- {
- log.fine("\n\n\n### Create User: " + i + "\n");
-
- begin();
- session.getPersistenceManager().createUser("test" + i);
- commit();
-
- }
-
- String groupKey = session.getPersistenceManager().createGroupKey("test0",
ORGANIZATION);
-
- for (int i = 0; i < 50; i++)
- {
- log.fine("\n\n\n### Associate User[" + i + "] to a Group" +
"\n");
-
- begin();
- session.getRelationshipManager().associateUserByKeys(groupKey, "test"
+ i);
- commit();
-
- }
-
- begin();
-
- groupKey = session.getPersistenceManager().createGroup("master",
ORGANIZATION).getKey();
-
- commit();
-
- for (int i = 0; i < 50; i++)
- {
- log.fine("\n\n\n### Associate Group[" + i + "] of type DEPARTMENT
to a Group" + groupKey + "\n");
-
-
-
- begin();
- String groupKey2 =
session.getPersistenceManager().createGroupKey("test" + i, ORGANIZATION);
- session.getRelationshipManager().associateGroupsByKeys(groupKey, groupKey2);
- commit();
-
- }
-
-
-
- }
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/SimpleTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/SimpleTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/SimpleTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/SimpleTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,140 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySessionFactory;
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.impl.IdentityTestPOJO;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+import java.util.logging.Logger;
+
+/**
+ * Some iteration to help find possible n+1 selects in logs.
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleTestCase extends IdentityTestPOJO implements APITestContext
+{
+ private static Logger log = Logger.getLogger(SimpleTestCase.class.getName());
+
+
+ IdentitySessionFactory identitySessionFactory;
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+
+ setRealmName("realm://RedHat/DB");
+
+
+ identitySessionFactory = new IdentityConfigurationImpl().
+ configure(getIdentityConfig()).buildIdentitySessionFactory();
+
+ log.fine("Statistics after IdentitySessionFactory creation:");
+ hibernateSupport.getSessionFactory().getStatistics().logSummary();
+
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ public IdentitySessionFactory getIdentitySessionFactory()
+ {
+ return identitySessionFactory;
+ }
+
+ @Test
+ public void testPersistenceManager() throws Exception
+ {
+ IdentitySession session =
identitySessionFactory.createIdentitySession(getRealmName());
+
+
+ String ORGANIZATION = "ORGANIZATION";
+
+
+
+ for (int i = 0; i < 50; i++)
+ {
+ log.fine("\n\n\n### Create Group: " + i + "\n");
+
+ begin();
+ session.getPersistenceManager().createGroup("test" + i,
ORGANIZATION);
+ commit();
+
+ }
+
+ for (int i = 0; i < 50; i++)
+ {
+ log.fine("\n\n\n### Create User: " + i + "\n");
+
+ begin();
+ session.getPersistenceManager().createUser("test" + i);
+ commit();
+
+ }
+
+ String groupKey = session.getPersistenceManager().createGroupKey("test0",
ORGANIZATION);
+
+ for (int i = 0; i < 50; i++)
+ {
+ log.fine("\n\n\n### Associate User[" + i + "] to a Group" +
"\n");
+
+ begin();
+ session.getRelationshipManager().associateUserByKeys(groupKey, "test"
+ i);
+ commit();
+
+ }
+
+ begin();
+
+ groupKey = session.getPersistenceManager().createGroup("master",
ORGANIZATION).getKey();
+
+ commit();
+
+ for (int i = 0; i < 50; i++)
+ {
+ log.fine("\n\n\n### Associate Group[" + i + "] of type DEPARTMENT
to a Group" + groupKey + "\n");
+
+
+
+ begin();
+ String groupKey2 =
session.getPersistenceManager().createGroupKey("test" + i, ORGANIZATION);
+ session.getRelationshipManager().associateGroupsByKeys(groupKey, groupKey2);
+ commit();
+
+ }
+
+
+
+ }
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/UserQueryTest.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/UserQueryTest.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/UserQueryTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,218 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.api;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.User;
-import org.jboss.identity.idm.api.Group;
-import org.jboss.identity.idm.api.RoleType;
-import org.jboss.identity.idm.api.Role;
-import org.jboss.identity.idm.api.SortOrder;
-import org.jboss.identity.idm.api.query.UserQuery;
-import org.jboss.identity.idm.api.query.UserQueryBuilder;
-import junit.framework.Assert;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class UserQueryTest extends Assert
-{
- private APITestContext ctx;
-
- private String ORGANIZATION = "ORGANIZATION";
-
- private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
-
- private String DEPARTMENT = "DEPARTMENT";
-
- public UserQueryTest(APITestContext testContext)
- {
- this.ctx = testContext;
- }
-
- public void testQuery(String realmName) throws Exception
- {
- ctx.begin();
-
- IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
-
- // Create stuff
-
- User user1 = ids.getPersistenceManager().createUser("user1");
- User user2 = ids.getPersistenceManager().createUser("user2");
- User user3 = ids.getPersistenceManager().createUser("user3");
- User user4 = ids.getPersistenceManager().createUser("user4");
- User testUser1 = ids.getPersistenceManager().createUser("testUser1");
- User testUser2 = ids.getPersistenceManager().createUser("testUser2");
- User testUser3 = ids.getPersistenceManager().createUser("testUser3");
- User testUser4 = ids.getPersistenceManager().createUser("testUser4");
-
- Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
- Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
- Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
- Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
- Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
-
- ids.getRelationshipManager().associateUser(group1, user1);
- ids.getRelationshipManager().associateUser(group1, user2);
-
- RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
- RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
- RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
- RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
-
- Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
- Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
- Role role3 = ids.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
-
- // Asserts
-
- //
- UserQueryBuilder qb = ids.createUserQueryBuilder();
-
- qb.withUserId("user1");
- UserQuery q = qb.createQuery();
-
- assertEquals(1, ids.execute(q).size());
- assertEquals(1, ids.list(q).size());
- assertEquals("user1", ids.uniqueResult(q).getKey());
-
- //
- qb.reset();
-
- qb.addAssociatedGroup(group2);
-
- assertEquals(0, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addAssociatedGroup(group1);
-
- assertEquals(2, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addAssociatedGroup(group1);
- qb.withUserId(user1.getKey());
-
- assertEquals(1, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addAssociatedGroup(group2);
- qb.withUserId(user1.getKey());
-
- assertEquals(0, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addAssociatedGroup(group1);
- qb.addGroupConnectedWithRole(group2);
-
- assertEquals(1, ids.execute(qb.createQuery()).size());
- assertEquals(user1, ids.uniqueResult(qb.createQuery()));
-
- //
- qb.reset();
-
- qb.addRelatedGroup(group1);
-
- assertEquals(2, ids.execute(qb.createQuery()).size());
-
- //
- qb.reset();
-
- qb.addRelatedGroup(group2);
- qb.addAssociatedGroup(group1);
-
- assertEquals(1, ids.execute(qb.createQuery()).size());
- assertEquals(user1, ids.uniqueResult(qb.createQuery()));
-
- //
- qb.reset();
-
- assertEquals(8, ids.execute(qb.createQuery()).size());
-
-
- // Criteria
-
- // All users
- qb.reset();
-
- assertEquals(8, ids.execute(qb.createQuery()).size());
-
- // All users sorted
- qb.reset();
- qb.sort(SortOrder.ASCENDING);
-
- List<User> results = ids.list(qb.createQuery());
-
- assertEquals(testUser1, results.get(0));
- assertEquals(user4, results.get(7));
-
- // All users sorted desc
- qb.reset();
- qb.sort(SortOrder.DESCENDING);
-
- results = ids.list(qb.createQuery());
-
- assertEquals(testUser1, results.get(7));
- assertEquals(user4, results.get(0));
-
- //
- qb.reset();
- qb.sort(SortOrder.DESCENDING);
- qb.idFilter("test*");
-
- results = ids.list(qb.createQuery());
-
- assertEquals(4, results.size());
- assertEquals(testUser1, results.get(3));
- assertEquals(testUser4, results.get(0));
-
- //
- qb.reset();
- qb.sort(SortOrder.ASCENDING);
- qb.idFilter("user*");
- qb.page(1, 2);
- results = ids.list(qb.createQuery());
-
- assertEquals(2, results.size());
- assertEquals(user2, results.get(0));
- assertEquals(user3, results.get(1));
-
-
-
- ctx.commit();
- }
-
-
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/UserQueryTest.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/api/UserQueryTest.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/UserQueryTest.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/api/UserQueryTest.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,218 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.api;
+
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.RoleType;
+import org.picketlink.idm.api.Role;
+import org.picketlink.idm.api.SortOrder;
+import org.picketlink.idm.api.query.UserQuery;
+import org.picketlink.idm.api.query.UserQueryBuilder;
+import junit.framework.Assert;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class UserQueryTest extends Assert
+{
+ private APITestContext ctx;
+
+ private String ORGANIZATION = "ORGANIZATION";
+
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+
+ private String DEPARTMENT = "DEPARTMENT";
+
+ public UserQueryTest(APITestContext testContext)
+ {
+ this.ctx = testContext;
+ }
+
+ public void testQuery(String realmName) throws Exception
+ {
+ ctx.begin();
+
+ IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
+
+ // Create stuff
+
+ User user1 = ids.getPersistenceManager().createUser("user1");
+ User user2 = ids.getPersistenceManager().createUser("user2");
+ User user3 = ids.getPersistenceManager().createUser("user3");
+ User user4 = ids.getPersistenceManager().createUser("user4");
+ User testUser1 = ids.getPersistenceManager().createUser("testUser1");
+ User testUser2 = ids.getPersistenceManager().createUser("testUser2");
+ User testUser3 = ids.getPersistenceManager().createUser("testUser3");
+ User testUser4 = ids.getPersistenceManager().createUser("testUser4");
+
+ Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+ ids.getRelationshipManager().associateUser(group1, user1);
+ ids.getRelationshipManager().associateUser(group1, user2);
+
+ RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
+ RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
+ RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
+ RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
+
+ Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
+ Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
+ Role role3 = ids.getRoleManager().createRole("rt2", user1.getKey(),
group1.getKey());
+
+ // Asserts
+
+ //
+ UserQueryBuilder qb = ids.createUserQueryBuilder();
+
+ qb.withUserId("user1");
+ UserQuery q = qb.createQuery();
+
+ assertEquals(1, ids.execute(q).size());
+ assertEquals(1, ids.list(q).size());
+ assertEquals("user1", ids.uniqueResult(q).getKey());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group2);
+
+ assertEquals(0, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group1);
+
+ assertEquals(2, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group1);
+ qb.withUserId(user1.getKey());
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group2);
+ qb.withUserId(user1.getKey());
+
+ assertEquals(0, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group1);
+ qb.addGroupConnectedWithRole(group2);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(user1, ids.uniqueResult(qb.createQuery()));
+
+ //
+ qb.reset();
+
+ qb.addRelatedGroup(group1);
+
+ assertEquals(2, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addRelatedGroup(group2);
+ qb.addAssociatedGroup(group1);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(user1, ids.uniqueResult(qb.createQuery()));
+
+ //
+ qb.reset();
+
+ assertEquals(8, ids.execute(qb.createQuery()).size());
+
+
+ // Criteria
+
+ // All users
+ qb.reset();
+
+ assertEquals(8, ids.execute(qb.createQuery()).size());
+
+ // All users sorted
+ qb.reset();
+ qb.sort(SortOrder.ASCENDING);
+
+ List<User> results = ids.list(qb.createQuery());
+
+ assertEquals(testUser1, results.get(0));
+ assertEquals(user4, results.get(7));
+
+ // All users sorted desc
+ qb.reset();
+ qb.sort(SortOrder.DESCENDING);
+
+ results = ids.list(qb.createQuery());
+
+ assertEquals(testUser1, results.get(7));
+ assertEquals(user4, results.get(0));
+
+ //
+ qb.reset();
+ qb.sort(SortOrder.DESCENDING);
+ qb.idFilter("test*");
+
+ results = ids.list(qb.createQuery());
+
+ assertEquals(4, results.size());
+ assertEquals(testUser1, results.get(3));
+ assertEquals(testUser4, results.get(0));
+
+ //
+ qb.reset();
+ qb.sort(SortOrder.ASCENDING);
+ qb.idFilter("user*");
+ qb.page(1, 2);
+ results = ids.list(qb.createQuery());
+
+ assertEquals(2, results.size());
+ assertEquals(user2, results.get(0));
+ assertEquals(user3, results.get(1));
+
+
+
+ ctx.commit();
+ }
+
+
+
+}
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/EvilBinaryTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/EvilBinaryTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/EvilBinaryTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,175 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.store.hibernate;
-
-import org.jboss.identity.idm.impl.model.hibernate.*;
-import org.jboss.identity.idm.impl.IdentityTestPOJO;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Test;
-import org.hibernate.Session;
-import org.hibernate.criterion.Projections;
-
-import java.util.*;
-
-
-/**
- * Simple test to show binary/blob issues in database
- *
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class EvilBinaryTestCase extends IdentityTestPOJO
-{
- public EvilBinaryTestCase()
- {
- }
-
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- @Test
- public void testBinary() throws Exception
- {
- begin();
-
- Session session = getSessionFactory().getCurrentSession();
-
-
- HibernateRealm realm = new HibernateRealm("default");
- session.persist(realm);
-
- HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
- session.persist(userType);
- HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
- session.persist(user1);
-
- Set<String> values1 = new HashSet<String>();
- values1.add("Val1");
- values1.add("Val2");
- values1.add("Val3");
-
- HibernateIdentityObjectAttribute attr = new HibernateIdentityObjectAttribute(user1,
"simple1", HibernateIdentityObjectAttribute.TYPE_TEXT);
- attr.setTextValues(values1);
- user1.getAttributes().add(attr);
-
-
- commit();
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
- user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
-
- Random random = new Random();
-
- // Small
- byte[] picture = new byte[512000];
- random.nextBytes(picture);
-
- attr = new HibernateIdentityObjectAttribute(user1, "simple2",
HibernateIdentityObjectAttribute.TYPE_BINARY);
- attr.setBinaryValue(new HibernateIdentityObjectAttributeBinaryValue(picture));
- user1.addAttribute(attr);
-
- values1 = new HashSet<String>();
- values1.add("Val1");
-
- attr = new HibernateIdentityObjectAttribute(user1, "simple3",
HibernateIdentityObjectAttribute.TYPE_TEXT);
- attr.setTextValues(values1);
- user1.getAttributes().add(attr);
-
- values1 = new HashSet<String>();
- values1.add("Val8");
- values1.add("Val15");
-
- attr = new HibernateIdentityObjectAttribute(user1, "simple4",
HibernateIdentityObjectAttribute.TYPE_TEXT);
- attr.setTextValues(values1);
- user1.getAttributes().add(attr);
-
- commit();
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
- user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
-
- // 900 kilobytes
- picture = new byte[921600];
-// picture = new byte[2];
- random.nextBytes(picture);
-
-
- attr = new HibernateIdentityObjectAttribute(user1, "simple5",
HibernateIdentityObjectAttribute.TYPE_BINARY);
- attr.setBinaryValue(new HibernateIdentityObjectAttributeBinaryValue(picture));
- user1.getAttributes().add(attr);
-
- commit();
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
- user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
-
- assertEquals(5, user1.getAttributes().size());
-
- int binaryCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttributeBinaryValue.class).
- setProjection(Projections.rowCount()).uniqueResult()).intValue();
-
- assertEquals(2,binaryCount);
-
- int attrCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttribute.class).
- setProjection(Projections.rowCount()).uniqueResult()).intValue();
-
- assertEquals(5,attrCount);
-
- session.delete(user1);
-
- attrCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttribute.class).
- setProjection(Projections.rowCount()).uniqueResult()).intValue();
-
- assertEquals(0,attrCount);
-
- binaryCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttributeBinaryValue.class).
- setProjection(Projections.rowCount()).uniqueResult()).intValue();
-
- assertEquals(0,binaryCount);
-
-
- commit();
-
- }
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/EvilBinaryTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/EvilBinaryTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/EvilBinaryTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/EvilBinaryTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,175 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.store.hibernate;
+
+import org.picketlink.idm.impl.model.hibernate.*;
+import org.picketlink.idm.impl.IdentityTestPOJO;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.hibernate.Session;
+import org.hibernate.criterion.Projections;
+
+import java.util.*;
+
+
+/**
+ * Simple test to show binary/blob issues in database
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class EvilBinaryTestCase extends IdentityTestPOJO
+{
+ public EvilBinaryTestCase()
+ {
+ }
+
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ @Test
+ public void testBinary() throws Exception
+ {
+ begin();
+
+ Session session = getSessionFactory().getCurrentSession();
+
+
+ HibernateRealm realm = new HibernateRealm("default");
+ session.persist(realm);
+
+ HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
+ session.persist(userType);
+ HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
+ session.persist(user1);
+
+ Set<String> values1 = new HashSet<String>();
+ values1.add("Val1");
+ values1.add("Val2");
+ values1.add("Val3");
+
+ HibernateIdentityObjectAttribute attr = new HibernateIdentityObjectAttribute(user1,
"simple1", HibernateIdentityObjectAttribute.TYPE_TEXT);
+ attr.setTextValues(values1);
+ user1.getAttributes().add(attr);
+
+
+ commit();
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+ user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
+
+ Random random = new Random();
+
+ // Small
+ byte[] picture = new byte[512000];
+ random.nextBytes(picture);
+
+ attr = new HibernateIdentityObjectAttribute(user1, "simple2",
HibernateIdentityObjectAttribute.TYPE_BINARY);
+ attr.setBinaryValue(new HibernateIdentityObjectAttributeBinaryValue(picture));
+ user1.addAttribute(attr);
+
+ values1 = new HashSet<String>();
+ values1.add("Val1");
+
+ attr = new HibernateIdentityObjectAttribute(user1, "simple3",
HibernateIdentityObjectAttribute.TYPE_TEXT);
+ attr.setTextValues(values1);
+ user1.getAttributes().add(attr);
+
+ values1 = new HashSet<String>();
+ values1.add("Val8");
+ values1.add("Val15");
+
+ attr = new HibernateIdentityObjectAttribute(user1, "simple4",
HibernateIdentityObjectAttribute.TYPE_TEXT);
+ attr.setTextValues(values1);
+ user1.getAttributes().add(attr);
+
+ commit();
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+ user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
+
+ // 900 kilobytes
+ picture = new byte[921600];
+// picture = new byte[2];
+ random.nextBytes(picture);
+
+
+ attr = new HibernateIdentityObjectAttribute(user1, "simple5",
HibernateIdentityObjectAttribute.TYPE_BINARY);
+ attr.setBinaryValue(new HibernateIdentityObjectAttributeBinaryValue(picture));
+ user1.getAttributes().add(attr);
+
+ commit();
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+ user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
+
+ assertEquals(5, user1.getAttributes().size());
+
+ int binaryCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttributeBinaryValue.class).
+ setProjection(Projections.rowCount()).uniqueResult()).intValue();
+
+ assertEquals(2,binaryCount);
+
+ int attrCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttribute.class).
+ setProjection(Projections.rowCount()).uniqueResult()).intValue();
+
+ assertEquals(5,attrCount);
+
+ session.delete(user1);
+
+ attrCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttribute.class).
+ setProjection(Projections.rowCount()).uniqueResult()).intValue();
+
+ assertEquals(0,attrCount);
+
+ binaryCount =
((Integer)session.createCriteria(HibernateIdentityObjectAttributeBinaryValue.class).
+ setProjection(Projections.rowCount()).uniqueResult()).intValue();
+
+ assertEquals(0,binaryCount);
+
+
+ commit();
+
+ }
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,376 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.store.hibernate;
-
-import org.jboss.identity.idm.spi.model.IdentityObject;
-import org.jboss.identity.idm.spi.model.IdentityObjectAttribute;
-import org.jboss.identity.idm.spi.store.IdentityStoreInvocationContext;
-import org.jboss.identity.idm.spi.store.IdentityStore;
-import org.jboss.identity.idm.spi.store.IdentityStoreSession;
-import
org.jboss.identity.idm.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
-import org.jboss.identity.idm.spi.configuration.metadata.IdentityConfigurationMetaData;
-import org.jboss.identity.idm.spi.configuration.IdentityStoreConfigurationContext;
-import org.jboss.identity.idm.spi.configuration.IdentityConfigurationContextRegistry;
-import org.jboss.identity.idm.impl.store.hibernate.HibernateIdentityStoreImpl;
-import org.jboss.identity.idm.impl.store.IdentityTypeEnum;
-import org.jboss.identity.idm.impl.store.CommonIdentityStoreTest;
-import org.jboss.identity.idm.impl.store.IdentityStoreTestContext;
-import org.jboss.identity.idm.impl.configuration.jaxb2.JAXB2IdentityConfiguration;
-import org.jboss.identity.idm.impl.configuration.IdentityStoreConfigurationContextImpl;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.identity.idm.impl.api.SimpleAttribute;
-import org.jboss.identity.idm.impl.IdentityTestPOJO;
-import org.jboss.identity.idm.common.exception.IdentityException;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Test;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-
-import java.util.Map;
-import java.util.Random;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class HibernateIdentityStoreTestCase extends IdentityTestPOJO implements
IdentityStoreTestContext
-{
-
- protected HibernateIdentityStoreImpl store;
-
- protected IdentityStoreInvocationContext ctx;
-
- protected CommonIdentityStoreTest commonTest;
-
- public HibernateIdentityStoreTestCase()
- {
-
- }
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
-
- setIdentityConfig("store-test-config.xml");
-
- commonTest = new CommonIdentityStoreTest(this);
-
- IdentityConfigurationMetaData configurationMD = JAXB2IdentityConfiguration
- .createConfigurationMetaData(getIdentityConfig());
-
- IdentityConfigurationContextRegistry identityConfiguration =
(IdentityConfigurationContextRegistry)
- new IdentityConfigurationImpl().configure(configurationMD);
-
- IdentityStoreConfigurationMetaData storeMD = null;
-
- for (IdentityStoreConfigurationMetaData metaData :
configurationMD.getIdentityStores())
- {
- if (metaData.getId().equals("HibernateTestStore"))
- {
- storeMD = metaData;
- break;
- }
- }
-
- IdentityStoreConfigurationContext context =
- new IdentityStoreConfigurationContextImpl(configurationMD,
identityConfiguration, storeMD);
-
- store = new HibernateIdentityStoreImpl("HibernateTestStore")
- {
-
- @Override
- protected Session getHibernateSession(IdentityStoreInvocationContext ctx)
- {
- return getHibernateSupport().getSessionFactory().getCurrentSession();
- }
-
- @Override
- protected SessionFactory
bootstrapHibernateSessionFactory(IdentityStoreConfigurationContext configurationContext)
throws IdentityException
- {
- return getHibernateSupport().getSessionFactory();
- }
-
- };
-
- store.bootstrap(context);
-
-
- ctx = new IdentityStoreInvocationContext()
- {
- public IdentityStoreSession getIdentityStoreSession()
- {
- return null;
- }
-
- public String getRealmId()
- {
- return "testRealm";
- }
-
- public String getSessionId()
- {
- return "";
- }
- };
-
-
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.stop();
- }
-
- public void begin()
- {
- getHibernateSupport().openSession();
- }
-
- public void commit()
- {
- assertTrue(getHibernateSupport().commitTransaction());
- }
-
- public void flush() throws Exception
- {
-
- getHibernateSupport().getSessionFactory().getCurrentSession().flush();
- }
-
- public IdentityStore getStore()
- {
- return store;
- }
-
- public IdentityStoreInvocationContext getCtx()
- {
- return ctx;
- }
-
- // Tests
-
- @Test
- public void testStorePersistence() throws Exception
- {
-
- commonTest.testStorePersistence();
-
- }
-
- @Test
- public void testFindMethods() throws Exception
- {
-
- commonTest.testFindMethods();
-
- }
-
- public void testBinaryAttributes() throws Exception
- {
- begin();
-
- IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
- IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
-
- flush();
-
- IdentityObjectAttribute[] attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key1", new String[]{"val1",
"val2", "val3"}),
- new SimpleAttribute("key2", new String[]{"val1",
"val2", "val3", "val4"})
- };
-
- store.addAttributes(ctx, user1, attrs);
-
- Random random = new Random();
-
- // 900 kilobytes
- byte[] picture1 = new byte[921600];
- random.nextBytes(picture1);
- byte[] picture2 = new byte[921600];
- random.nextBytes(picture2);
-
- attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key1", new byte[][]{picture1}),
- };
-
- store.addAttributes(ctx, user1, attrs);
-
- attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key2", new byte[][]{picture1, picture2}),
- };
-
- store.addAttributes(ctx, user1, attrs);
-
- attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key1", new byte[][]{picture2}),
- };
-
- store.updateAttributes(ctx, user1, attrs);
-
- store.removeAttributes(ctx, user1, new String[]{"key1",
"key2"});
-
- assertNull(store.findIdentityObjectByUniqueAttribute(ctx, IdentityTypeEnum.USER,
new SimpleAttribute("key1", new String[]{"toto"})));
-
-
- commit();
- }
-
- @Test
- public void testAttributes() throws Exception
- {
-
- begin();
-
- IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
- IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
-
- flush();
-
- IdentityObjectAttribute[] attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key1", new String[]{"val1",
"val2", "val3"}),
- new SimpleAttribute("key2", new String[]{"val1",
"val2", "val3", "val4"})
- };
-
- store.addAttributes(ctx, user1, attrs);
-
- flush();
-
- Map<String, IdentityObjectAttribute> persistedAttrs =
store.getAttributes(ctx, user1);
-
- assertEquals(2, persistedAttrs.keySet().size());
-
- assertTrue(persistedAttrs.containsKey("key1"));
- assertEquals(3, persistedAttrs.get("key1").getSize());
-
- assertTrue(persistedAttrs.containsKey("key2"));
- assertEquals(4, persistedAttrs.get("key2").getSize());
-
- flush();
-
- attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key3", new String[]{"val1"})
- };
-
-
- store.addAttributes(ctx, user1, attrs);
-
- flush();
-
- persistedAttrs = store.getAttributes(ctx, user1);
-
- assertEquals(3, persistedAttrs.keySet().size());
-
- assertTrue(persistedAttrs.containsKey("key1"));
- assertEquals(3, persistedAttrs.get("key1").getSize());
-
- assertTrue(persistedAttrs.containsKey("key2"));
- assertEquals(4, persistedAttrs.get("key2").getSize());
-
- assertTrue(persistedAttrs.containsKey("key3"));
- assertEquals(1, persistedAttrs.get("key3").getSize());
-
- flush();
-
- attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key3", new String[]{"val2"})
- };
-
- store.addAttributes(ctx, user1, attrs);
-
- flush();
-
- persistedAttrs = store.getAttributes(ctx, user1);
-
- assertEquals(3, persistedAttrs.keySet().size());
-
- assertTrue(persistedAttrs.containsKey("key3"));
- assertEquals(2, persistedAttrs.get("key3").getSize());
-
- flush();
-
- store.updateAttributes(ctx, user1, attrs);
-
- flush();
-
- persistedAttrs = store.getAttributes(ctx, user1);
-
- assertEquals(3, persistedAttrs.keySet().size());
-
- assertTrue(persistedAttrs.containsKey("key3"));
- assertEquals(1, persistedAttrs.get("key3").getSize());
-
- flush();
-
- attrs = new IdentityObjectAttribute[]{
- new SimpleAttribute("key4", new String[]{"val2"})
- };
-
- store.updateAttributes(ctx, user1, attrs);
-
- flush();
-
- persistedAttrs = store.getAttributes(ctx, user1);
-
- assertEquals(4, persistedAttrs.keySet().size());
- assertEquals("val2",
persistedAttrs.get("key4").getValue().toString());
-
-
- store.removeAttributes(ctx, user1, new String[] {"key3"});
-
- flush();
-
- persistedAttrs = store.getAttributes(ctx, user1);
-
- assertEquals(3, persistedAttrs.keySet().size());
-
-
- commit();
-
- }
-
- @Test
- public void testRelationships() throws Exception
- {
- commonTest.testRelationships();
- }
-
- @Test
- public void testPasswordCredentials() throws Exception
- {
- commonTest.testPasswordCredential();
- }
-
- public void testBinaryCredentials() throws Exception
- {
- commonTest.testBinaryCredential();
- }
-
- @Test
- public void testCriteria() throws Exception
- {
- commonTest.testCriteria();
- }
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,376 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.store.hibernate;
+
+import org.picketlink.idm.spi.model.IdentityObject;
+import org.picketlink.idm.spi.model.IdentityObjectAttribute;
+import org.picketlink.idm.spi.store.IdentityStoreInvocationContext;
+import org.picketlink.idm.spi.store.IdentityStore;
+import org.picketlink.idm.spi.store.IdentityStoreSession;
+import org.picketlink.idm.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
+import org.picketlink.idm.spi.configuration.metadata.IdentityConfigurationMetaData;
+import org.picketlink.idm.spi.configuration.IdentityStoreConfigurationContext;
+import org.picketlink.idm.spi.configuration.IdentityConfigurationContextRegistry;
+import org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl;
+import org.picketlink.idm.impl.store.IdentityTypeEnum;
+import org.picketlink.idm.impl.store.CommonIdentityStoreTest;
+import org.picketlink.idm.impl.store.IdentityStoreTestContext;
+import org.picketlink.idm.impl.configuration.jaxb2.JAXB2IdentityConfiguration;
+import org.picketlink.idm.impl.configuration.IdentityStoreConfigurationContextImpl;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.picketlink.idm.impl.api.SimpleAttribute;
+import org.picketlink.idm.impl.IdentityTestPOJO;
+import org.picketlink.idm.common.exception.IdentityException;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class HibernateIdentityStoreTestCase extends IdentityTestPOJO implements
IdentityStoreTestContext
+{
+
+ protected HibernateIdentityStoreImpl store;
+
+ protected IdentityStoreInvocationContext ctx;
+
+ protected CommonIdentityStoreTest commonTest;
+
+ public HibernateIdentityStoreTestCase()
+ {
+
+ }
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+
+ setIdentityConfig("store-test-config.xml");
+
+ commonTest = new CommonIdentityStoreTest(this);
+
+ IdentityConfigurationMetaData configurationMD = JAXB2IdentityConfiguration
+ .createConfigurationMetaData(getIdentityConfig());
+
+ IdentityConfigurationContextRegistry identityConfiguration =
(IdentityConfigurationContextRegistry)
+ new IdentityConfigurationImpl().configure(configurationMD);
+
+ IdentityStoreConfigurationMetaData storeMD = null;
+
+ for (IdentityStoreConfigurationMetaData metaData :
configurationMD.getIdentityStores())
+ {
+ if (metaData.getId().equals("HibernateTestStore"))
+ {
+ storeMD = metaData;
+ break;
+ }
+ }
+
+ IdentityStoreConfigurationContext context =
+ new IdentityStoreConfigurationContextImpl(configurationMD,
identityConfiguration, storeMD);
+
+ store = new HibernateIdentityStoreImpl("HibernateTestStore")
+ {
+
+ @Override
+ protected Session getHibernateSession(IdentityStoreInvocationContext ctx)
+ {
+ return getHibernateSupport().getSessionFactory().getCurrentSession();
+ }
+
+ @Override
+ protected SessionFactory
bootstrapHibernateSessionFactory(IdentityStoreConfigurationContext configurationContext)
throws IdentityException
+ {
+ return getHibernateSupport().getSessionFactory();
+ }
+
+ };
+
+ store.bootstrap(context);
+
+
+ ctx = new IdentityStoreInvocationContext()
+ {
+ public IdentityStoreSession getIdentityStoreSession()
+ {
+ return null;
+ }
+
+ public String getRealmId()
+ {
+ return "testRealm";
+ }
+
+ public String getSessionId()
+ {
+ return "";
+ }
+ };
+
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ public void begin()
+ {
+ getHibernateSupport().openSession();
+ }
+
+ public void commit()
+ {
+ assertTrue(getHibernateSupport().commitTransaction());
+ }
+
+ public void flush() throws Exception
+ {
+
+ getHibernateSupport().getSessionFactory().getCurrentSession().flush();
+ }
+
+ public IdentityStore getStore()
+ {
+ return store;
+ }
+
+ public IdentityStoreInvocationContext getCtx()
+ {
+ return ctx;
+ }
+
+ // Tests
+
+ @Test
+ public void testStorePersistence() throws Exception
+ {
+
+ commonTest.testStorePersistence();
+
+ }
+
+ @Test
+ public void testFindMethods() throws Exception
+ {
+
+ commonTest.testFindMethods();
+
+ }
+
+ public void testBinaryAttributes() throws Exception
+ {
+ begin();
+
+ IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
+
+ flush();
+
+ IdentityObjectAttribute[] attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key1", new String[]{"val1",
"val2", "val3"}),
+ new SimpleAttribute("key2", new String[]{"val1",
"val2", "val3", "val4"})
+ };
+
+ store.addAttributes(ctx, user1, attrs);
+
+ Random random = new Random();
+
+ // 900 kilobytes
+ byte[] picture1 = new byte[921600];
+ random.nextBytes(picture1);
+ byte[] picture2 = new byte[921600];
+ random.nextBytes(picture2);
+
+ attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key1", new byte[][]{picture1}),
+ };
+
+ store.addAttributes(ctx, user1, attrs);
+
+ attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key2", new byte[][]{picture1, picture2}),
+ };
+
+ store.addAttributes(ctx, user1, attrs);
+
+ attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key1", new byte[][]{picture2}),
+ };
+
+ store.updateAttributes(ctx, user1, attrs);
+
+ store.removeAttributes(ctx, user1, new String[]{"key1",
"key2"});
+
+ assertNull(store.findIdentityObjectByUniqueAttribute(ctx, IdentityTypeEnum.USER,
new SimpleAttribute("key1", new String[]{"toto"})));
+
+
+ commit();
+ }
+
+ @Test
+ public void testAttributes() throws Exception
+ {
+
+ begin();
+
+ IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
+
+ flush();
+
+ IdentityObjectAttribute[] attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key1", new String[]{"val1",
"val2", "val3"}),
+ new SimpleAttribute("key2", new String[]{"val1",
"val2", "val3", "val4"})
+ };
+
+ store.addAttributes(ctx, user1, attrs);
+
+ flush();
+
+ Map<String, IdentityObjectAttribute> persistedAttrs =
store.getAttributes(ctx, user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key1"));
+ assertEquals(3, persistedAttrs.get("key1").getSize());
+
+ assertTrue(persistedAttrs.containsKey("key2"));
+ assertEquals(4, persistedAttrs.get("key2").getSize());
+
+ flush();
+
+ attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key3", new String[]{"val1"})
+ };
+
+
+ store.addAttributes(ctx, user1, attrs);
+
+ flush();
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key1"));
+ assertEquals(3, persistedAttrs.get("key1").getSize());
+
+ assertTrue(persistedAttrs.containsKey("key2"));
+ assertEquals(4, persistedAttrs.get("key2").getSize());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(1, persistedAttrs.get("key3").getSize());
+
+ flush();
+
+ attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key3", new String[]{"val2"})
+ };
+
+ store.addAttributes(ctx, user1, attrs);
+
+ flush();
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(2, persistedAttrs.get("key3").getSize());
+
+ flush();
+
+ store.updateAttributes(ctx, user1, attrs);
+
+ flush();
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(1, persistedAttrs.get("key3").getSize());
+
+ flush();
+
+ attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key4", new String[]{"val2"})
+ };
+
+ store.updateAttributes(ctx, user1, attrs);
+
+ flush();
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(4, persistedAttrs.keySet().size());
+ assertEquals("val2",
persistedAttrs.get("key4").getValue().toString());
+
+
+ store.removeAttributes(ctx, user1, new String[] {"key3"});
+
+ flush();
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+
+ commit();
+
+ }
+
+ @Test
+ public void testRelationships() throws Exception
+ {
+ commonTest.testRelationships();
+ }
+
+ @Test
+ public void testPasswordCredentials() throws Exception
+ {
+ commonTest.testPasswordCredential();
+ }
+
+ public void testBinaryCredentials() throws Exception
+ {
+ commonTest.testBinaryCredential();
+ }
+
+ @Test
+ public void testCriteria() throws Exception
+ {
+ commonTest.testCriteria();
+ }
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateModelTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateModelTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateModelTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,344 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.store.hibernate;
-
-import org.jboss.identity.idm.impl.model.hibernate.*;
-import org.jboss.identity.idm.impl.IdentityTestPOJO;
-import org.jboss.identity.idm.impl.api.PasswordCredential;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Test;
-import org.hibernate.Session;
-import org.hibernate.Query;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.HashSet;
-
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class HibernateModelTestCase extends IdentityTestPOJO
-{
- public HibernateModelTestCase()
- {
- }
-
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
- @Test
- public void testPersistence() {
-
-
- begin();
- Session session = getSessionFactory().getCurrentSession();
-
-
- HibernateRealm defaultRealm = new HibernateRealm("default");
- session.persist(defaultRealm);
-
- Map<String, String> props = new HashMap<String, String>();
- props.put("test", "testValue");
- defaultRealm.setProperties(props);
-
- defaultRealm = (HibernateRealm)session.get(HibernateRealm.class,
defaultRealm.getId());
-
- assertEquals(defaultRealm.getProperties().keySet().size(), 1);
-
- //
-
- HibernateIdentityObjectType iot = new HibernateIdentityObjectType();
- iot.setName("User");
-
- session.persist(iot);
- assertTrue(session.contains(iot));
-
-
- HibernateIdentityObject io = new HibernateIdentityObject();
- io.setName("John Kowalski");
- io.setRealm(defaultRealm);
- io.setIdentityType(iot);
-
- session.persist(io);
- assertTrue(session.contains(io));
-
- session.delete(io);
- assertFalse(session.contains(io));
-
- //
-
-
-
- //
-
- HibernateIdentityObjectRelationshipType iort = new
HibernateIdentityObjectRelationshipType();
- iort.setName("Member");
-
- session.persist(iort);
- assertTrue(session.contains(iort));
-
- assertTrue(session.contains(iort));
-
- session.delete(iort);
- assertFalse(session.contains(iort));
-
- commit();
-
-
- }
-
- @Test
- public void testRelationships()
- {
- begin();
-
-
- Session session = getSessionFactory().getCurrentSession();
-
-
- HibernateRealm realm = new HibernateRealm("default");
- session.persist(realm);
-
- HibernateIdentityObjectType groupType = new
HibernateIdentityObjectType("Group");
- session.persist(groupType);
- HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
- session.persist(userType);
-
- HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
- session.persist(user1);
- HibernateIdentityObject user2 = new HibernateIdentityObject("user2",
userType, realm);
- session.persist(user2);
- HibernateIdentityObject user3 = new HibernateIdentityObject("user3",
userType, realm);
- session.persist(user3);
-
- HibernateIdentityObject group1 = new HibernateIdentityObject("group1",
groupType, realm);
- session.persist(group1);
- HibernateIdentityObject group2 = new HibernateIdentityObject("group2",
groupType, realm);
- session.persist(group2);
- HibernateIdentityObject group3 = new HibernateIdentityObject("group3",
groupType, realm);
- session.persist(group3);
-
- HibernateIdentityObjectRelationshipType memberType = new
HibernateIdentityObjectRelationshipType("member");
- session.persist(memberType);
-
- HibernateIdentityObjectRelationship relationship = new
HibernateIdentityObjectRelationship(memberType, group1, user1);
- session.persist(relationship);
- relationship = new HibernateIdentityObjectRelationship(memberType, group1, user2);
- session.persist(relationship);
- relationship = new HibernateIdentityObjectRelationship(memberType, group2, user3);
- session.persist(relationship);
- relationship = new HibernateIdentityObjectRelationship(memberType, group2,
group1);
- session.persist(relationship);
-
- commit();
-
- //
-
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
- Query ioQuery = session.createQuery("select o from HibernateIdentityObject o
where o.name like :name");
-
- group1 = (HibernateIdentityObject)ioQuery.setParameter("name",
"group1").uniqueResult();
- assertEquals(2, group1.getFromRelationships().size());
- assertEquals(1, group1.getToRelationships().size());
- group2 = (HibernateIdentityObject)ioQuery.setParameter("name",
"group2").uniqueResult();
- assertEquals(2, group2.getFromRelationships().size());
- assertEquals(0, group2.getToRelationships().size());
-
- user3 = (HibernateIdentityObject)ioQuery.setParameter("name",
"user3").uniqueResult();
- assertEquals(1, user3.getToRelationships().size());
- assertEquals(0, user3.getFromRelationships().size());
- assertEquals("group2",
user3.getToRelationships().iterator().next().getFromIdentityObject().getName());
- commit();
-
- }
-
- @Test
- public void testNameTypeConstraint() throws Exception
- {
-
- begin();
- Session session = getSessionFactory().getCurrentSession();
-
-
-
- HibernateRealm realm = new HibernateRealm("default");
- session.persist(realm);
-
- HibernateIdentityObjectType groupType = new
HibernateIdentityObjectType("Group");
- session.persist(groupType);
- HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
- session.persist(userType);
-
- HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
- session.persist(user1);
- HibernateIdentityObject user2 = new HibernateIdentityObject("user2",
userType, realm);
- session.persist(user2);
-
- commit();
-
-
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
- try
- {
-
- HibernateIdentityObject user3 = new HibernateIdentityObject("user2",
userType, realm);
- session.persist(user3);
-
- assertFalse(getHibernateSupport().commitTransaction());
-
- }
- catch (Exception e)
- {
- // may be expected
- getHibernateSupport().rollbackTransaction();
- }
-
-
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
-
- HibernateIdentityObject user4 = new HibernateIdentityObject("group1",
userType, realm);
- session.persist(user4);
-
-
- HibernateIdentityObject group1 = new HibernateIdentityObject("group1",
groupType, realm);
- session.persist(group1);
- HibernateIdentityObject group2 = new HibernateIdentityObject("group2",
groupType, realm);
- session.persist(group2);
-
- //session.flush();
-
- try
- {
-
- HibernateIdentityObject group3 = new HibernateIdentityObject("group2",
groupType, realm);
- session.persist(group3);
-
- // Should fail
- assertFalse(getHibernateSupport().commitTransaction());
- }
- catch (Exception e)
- {
- //expected
- getHibernateSupport().rollbackTransaction();
- }
-
-
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
- HibernateIdentityObject group4 = new HibernateIdentityObject("user1",
groupType, realm);
- session.persist(group4);
-
- session.flush();
-
- commit();
-
-
-
-
-
- }
-
- @Test
- public void testAttributes() throws Exception
- {
- begin();
-
- Session session = getSessionFactory().getCurrentSession();
-
-
-
-
- HibernateRealm realm = new HibernateRealm("default");
- session.persist(realm);
-
- HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
- session.persist(userType);
- HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
- session.persist(user1);
-
- Set<String> values1 = new HashSet<String>();
- values1.add("Val1");
- values1.add("Val2");
- values1.add("Val3");
-
- HibernateIdentityObjectAttribute attr = new HibernateIdentityObjectAttribute(user1,
"simple1", HibernateIdentityObjectAttribute.TYPE_TEXT);
- attr.setTextValues(values1);
- user1.getAttributes().add(attr);
- attr = new HibernateIdentityObjectAttribute(user1, "simple2",
HibernateIdentityObjectAttribute.TYPE_TEXT);
- attr.setTextValues(values1);
- user1.getAttributes().add(attr);
-
-
-
-
-
-
-
- commit();
-
-
-
- begin();
-
- session = getSessionFactory().getCurrentSession();
-
- user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
- assertEquals(2, user1.getAttributes().size() );
-// assertNotNull(user1.getProfileAttributes().get("simple1"));
-// assertEquals(3, user1.getProfileAttributes().get("simple1").length);
-
-
- commit();
-
- }
-
-}
\ No newline at end of file
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateModelTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateModelTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateModelTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/HibernateModelTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,344 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.store.hibernate;
+
+import org.picketlink.idm.impl.model.hibernate.*;
+import org.picketlink.idm.impl.IdentityTestPOJO;
+import org.picketlink.idm.impl.api.PasswordCredential;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class HibernateModelTestCase extends IdentityTestPOJO
+{
+ public HibernateModelTestCase()
+ {
+ }
+
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+ @Test
+ public void testPersistence() {
+
+
+ begin();
+ Session session = getSessionFactory().getCurrentSession();
+
+
+ HibernateRealm defaultRealm = new HibernateRealm("default");
+ session.persist(defaultRealm);
+
+ Map<String, String> props = new HashMap<String, String>();
+ props.put("test", "testValue");
+ defaultRealm.setProperties(props);
+
+ defaultRealm = (HibernateRealm)session.get(HibernateRealm.class,
defaultRealm.getId());
+
+ assertEquals(defaultRealm.getProperties().keySet().size(), 1);
+
+ //
+
+ HibernateIdentityObjectType iot = new HibernateIdentityObjectType();
+ iot.setName("User");
+
+ session.persist(iot);
+ assertTrue(session.contains(iot));
+
+
+ HibernateIdentityObject io = new HibernateIdentityObject();
+ io.setName("John Kowalski");
+ io.setRealm(defaultRealm);
+ io.setIdentityType(iot);
+
+ session.persist(io);
+ assertTrue(session.contains(io));
+
+ session.delete(io);
+ assertFalse(session.contains(io));
+
+ //
+
+
+
+ //
+
+ HibernateIdentityObjectRelationshipType iort = new
HibernateIdentityObjectRelationshipType();
+ iort.setName("Member");
+
+ session.persist(iort);
+ assertTrue(session.contains(iort));
+
+ assertTrue(session.contains(iort));
+
+ session.delete(iort);
+ assertFalse(session.contains(iort));
+
+ commit();
+
+
+ }
+
+ @Test
+ public void testRelationships()
+ {
+ begin();
+
+
+ Session session = getSessionFactory().getCurrentSession();
+
+
+ HibernateRealm realm = new HibernateRealm("default");
+ session.persist(realm);
+
+ HibernateIdentityObjectType groupType = new
HibernateIdentityObjectType("Group");
+ session.persist(groupType);
+ HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
+ session.persist(userType);
+
+ HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
+ session.persist(user1);
+ HibernateIdentityObject user2 = new HibernateIdentityObject("user2",
userType, realm);
+ session.persist(user2);
+ HibernateIdentityObject user3 = new HibernateIdentityObject("user3",
userType, realm);
+ session.persist(user3);
+
+ HibernateIdentityObject group1 = new HibernateIdentityObject("group1",
groupType, realm);
+ session.persist(group1);
+ HibernateIdentityObject group2 = new HibernateIdentityObject("group2",
groupType, realm);
+ session.persist(group2);
+ HibernateIdentityObject group3 = new HibernateIdentityObject("group3",
groupType, realm);
+ session.persist(group3);
+
+ HibernateIdentityObjectRelationshipType memberType = new
HibernateIdentityObjectRelationshipType("member");
+ session.persist(memberType);
+
+ HibernateIdentityObjectRelationship relationship = new
HibernateIdentityObjectRelationship(memberType, group1, user1);
+ session.persist(relationship);
+ relationship = new HibernateIdentityObjectRelationship(memberType, group1, user2);
+ session.persist(relationship);
+ relationship = new HibernateIdentityObjectRelationship(memberType, group2, user3);
+ session.persist(relationship);
+ relationship = new HibernateIdentityObjectRelationship(memberType, group2,
group1);
+ session.persist(relationship);
+
+ commit();
+
+ //
+
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+ Query ioQuery = session.createQuery("select o from HibernateIdentityObject o
where o.name like :name");
+
+ group1 = (HibernateIdentityObject)ioQuery.setParameter("name",
"group1").uniqueResult();
+ assertEquals(2, group1.getFromRelationships().size());
+ assertEquals(1, group1.getToRelationships().size());
+ group2 = (HibernateIdentityObject)ioQuery.setParameter("name",
"group2").uniqueResult();
+ assertEquals(2, group2.getFromRelationships().size());
+ assertEquals(0, group2.getToRelationships().size());
+
+ user3 = (HibernateIdentityObject)ioQuery.setParameter("name",
"user3").uniqueResult();
+ assertEquals(1, user3.getToRelationships().size());
+ assertEquals(0, user3.getFromRelationships().size());
+ assertEquals("group2",
user3.getToRelationships().iterator().next().getFromIdentityObject().getName());
+ commit();
+
+ }
+
+ @Test
+ public void testNameTypeConstraint() throws Exception
+ {
+
+ begin();
+ Session session = getSessionFactory().getCurrentSession();
+
+
+
+ HibernateRealm realm = new HibernateRealm("default");
+ session.persist(realm);
+
+ HibernateIdentityObjectType groupType = new
HibernateIdentityObjectType("Group");
+ session.persist(groupType);
+ HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
+ session.persist(userType);
+
+ HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
+ session.persist(user1);
+ HibernateIdentityObject user2 = new HibernateIdentityObject("user2",
userType, realm);
+ session.persist(user2);
+
+ commit();
+
+
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+ try
+ {
+
+ HibernateIdentityObject user3 = new HibernateIdentityObject("user2",
userType, realm);
+ session.persist(user3);
+
+ assertFalse(getHibernateSupport().commitTransaction());
+
+ }
+ catch (Exception e)
+ {
+ // may be expected
+ getHibernateSupport().rollbackTransaction();
+ }
+
+
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+
+ HibernateIdentityObject user4 = new HibernateIdentityObject("group1",
userType, realm);
+ session.persist(user4);
+
+
+ HibernateIdentityObject group1 = new HibernateIdentityObject("group1",
groupType, realm);
+ session.persist(group1);
+ HibernateIdentityObject group2 = new HibernateIdentityObject("group2",
groupType, realm);
+ session.persist(group2);
+
+ //session.flush();
+
+ try
+ {
+
+ HibernateIdentityObject group3 = new HibernateIdentityObject("group2",
groupType, realm);
+ session.persist(group3);
+
+ // Should fail
+ assertFalse(getHibernateSupport().commitTransaction());
+ }
+ catch (Exception e)
+ {
+ //expected
+ getHibernateSupport().rollbackTransaction();
+ }
+
+
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+ HibernateIdentityObject group4 = new HibernateIdentityObject("user1",
groupType, realm);
+ session.persist(group4);
+
+ session.flush();
+
+ commit();
+
+
+
+
+
+ }
+
+ @Test
+ public void testAttributes() throws Exception
+ {
+ begin();
+
+ Session session = getSessionFactory().getCurrentSession();
+
+
+
+
+ HibernateRealm realm = new HibernateRealm("default");
+ session.persist(realm);
+
+ HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
+ session.persist(userType);
+ HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType, realm);
+ session.persist(user1);
+
+ Set<String> values1 = new HashSet<String>();
+ values1.add("Val1");
+ values1.add("Val2");
+ values1.add("Val3");
+
+ HibernateIdentityObjectAttribute attr = new HibernateIdentityObjectAttribute(user1,
"simple1", HibernateIdentityObjectAttribute.TYPE_TEXT);
+ attr.setTextValues(values1);
+ user1.getAttributes().add(attr);
+ attr = new HibernateIdentityObjectAttribute(user1, "simple2",
HibernateIdentityObjectAttribute.TYPE_TEXT);
+ attr.setTextValues(values1);
+ user1.getAttributes().add(attr);
+
+
+
+
+
+
+
+ commit();
+
+
+
+ begin();
+
+ session = getSessionFactory().getCurrentSession();
+
+ user1 = (HibernateIdentityObject)session.get(HibernateIdentityObject.class, new
Long(user1.getId()));
+ assertEquals(2, user1.getAttributes().size() );
+// assertNotNull(user1.getProfileAttributes().get("simple1"));
+// assertEquals(3, user1.getProfileAttributes().get("simple1").length);
+
+
+ commit();
+
+ }
+
+}
\ No newline at end of file
Deleted:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java 2009-11-18
13:42:38 UTC (rev 1005)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -1,376 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.jboss.identity.idm.impl.store.ldap;
-
-import org.jboss.identity.idm.impl.LDAPTestPOJO;
-import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
-import org.jboss.identity.idm.impl.configuration.IdentityStoreConfigurationContextImpl;
-import org.jboss.identity.idm.impl.configuration.jaxb2.JAXB2IdentityConfiguration;
-import org.jboss.identity.idm.impl.store.CommonIdentityStoreTest;
-import org.jboss.identity.idm.impl.store.IdentityStoreTestContext;
-import org.jboss.identity.idm.spi.configuration.IdentityConfigurationContextRegistry;
-import org.jboss.identity.idm.spi.configuration.IdentityStoreConfigurationContext;
-import org.jboss.identity.idm.spi.configuration.metadata.IdentityConfigurationMetaData;
-import
org.jboss.identity.idm.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
-import org.jboss.identity.idm.spi.store.IdentityStore;
-import org.jboss.identity.idm.spi.store.IdentityStoreInvocationContext;
-import org.jboss.identity.idm.spi.store.IdentityStoreSession;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
-import javax.naming.ldap.LdapContext;
-
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class LDAPIdentityStoreTestCase extends LDAPTestPOJO implements
IdentityStoreTestContext
-{
-
- CommonIdentityStoreTest commonTest;
-
- IdentityStoreInvocationContext ctx;
-
- IdentityStore store;
-
- public LDAPIdentityStoreTestCase()
- {
-
- }
-
- @Create
- public void setUp() throws Exception
- {
- super.start();
-
-// setIdentityConfig("store-test-config.xml");
-
- commonTest = new CommonIdentityStoreTest(this);
-
- IdentityConfigurationMetaData configurationMD = JAXB2IdentityConfiguration
- .createConfigurationMetaData(getIdentityConfig());
-
- IdentityConfigurationContextRegistry registry =
(IdentityConfigurationContextRegistry) new IdentityConfigurationImpl().
- configure(configurationMD);
-
- IdentityStoreConfigurationMetaData storeMD = null;
-
- for (IdentityStoreConfigurationMetaData metaData :
configurationMD.getIdentityStores())
- {
- if (metaData.getId().equals("LDAP Identity Store"))
- {
- storeMD = metaData;
- break;
- }
- }
-
- IdentityStoreConfigurationContext context = new
IdentityStoreConfigurationContextImpl(configurationMD, registry, storeMD);
-
-
-
- //populate();
-
- store = new LDAPIdentityStoreImpl("LDAP Identity Store");
-
- store.bootstrap(context);
-
- final IdentityStoreSession storeSession = store.createIdentityStoreSession();
-
- ctx = new IdentityStoreInvocationContext()
- {
- public IdentityStoreSession getIdentityStoreSession()
- {
- return storeSession;
- }
-
- public String getRealmId()
- {
- return "testRealm";
- }
-
- public String getSessionId()
- {
- return "";
- }
- };
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- super.stop();
- }
-
-
- public void flush() throws Exception
- {
- //nothing
- }
-
- public IdentityStore getStore()
- {
- return store;
- }
-
- public IdentityStoreInvocationContext getCtx()
- {
- return ctx;
- }
-
-
- // Tests
-
-// Just test if OpenDS is running and was populated...
- @Test
- public void testSimple() throws Exception
- {
- populateClean();
-
- Hashtable<String,String> env = new Hashtable<String,String>();
- env.put(Context.INITIAL_CONTEXT_FACTORY, directoryConfig.getContextFactory());
- env.put(Context.PROVIDER_URL, directoryConfig.getDescription());
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, directoryConfig.getAdminDN());
- env.put(Context.SECURITY_CREDENTIALS, directoryConfig.getAdminPassword());
-
- LdapContext ldapCtx = null;
- try
- {
- ldapCtx = new InitialLdapContext(env, null);
-
-// Do something ...
- System.out.println("Attributes: " +
ldapCtx.getAttributes(directoryConfig.getCleanUpDN()));
-
- }
- catch (NamingException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- if (ldapCtx != null)
- {
- ldapCtx.close();
- }
- }
- catch (NamingException e)
- {
- e.printStackTrace();
- }
- }
- }
-
-// @Test
-// public void testIdentityObjectCount() throws Exception
-// {
-// populate();
-//
-// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-// assertEquals(5, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.ROLE));
-// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-// }
-//
-// @Test
-// public void testFindCreateRemove() throws Exception
-// {
-// populate();
-//
-// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-//
-// IdentityObject io = store.findIdentityObject(ctx, "admin",
IdentityTypeEnum.USER);
-// assertEquals("admin", io.getName());
-// assertEquals("uid=admin,ou=People,o=test,dc=portal,dc=example,dc=com",
io.getKey().toString());
-//
-// //
-//
-// store.removeIdentityObject(ctx, io);
-//
-// assertEquals(6, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-//
-// store.createIdentityObject(ctx, "newUserA", IdentityTypeEnum.USER);
-//
-// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-//
-// //
-//
-// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-//
-// store.createIdentityObject(ctx, "newGroupA", IdentityTypeEnum.GROUP);
-//
-// assertEquals(3, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-//
-// //
-//
-// io = store.findIdentityObject(ctx,
"cn=newGroupA,ou=Groups,o=test,dc=portal,dc=example,dc=com");
-// assertEquals("newGroupA", io.getName());
-//
-// }
-
-// @Test
-// public void testAttributes() throws Exception{
-//
-// populate();
-//
-// IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
-// IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
-//
-// //
-//
-// IdentityObjectAttribute[] attrs = new IdentityObjectAttribute[]{
-// new SimpleAttribute("phone", new String[]{"val1"}),
-// new SimpleAttribute("description", new String[]{"val1",
"val2", "val3", "val4"}),
-//
-// };
-//
-// store.addAttributes(ctx, user1, attrs);
-//
-// //
-//
-// Map<String, IdentityObjectAttribute> persistedAttrs =
store.getAttributes(ctx, user1);
-//
-// assertEquals(2, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("phone"));
-// assertEquals(1, persistedAttrs.get("phone").getSize());
-//
-// assertTrue(persistedAttrs.containsKey("description"));
-// assertEquals(4, persistedAttrs.get("description").getSize());
-//
-// //
-//
-// attrs = new IdentityObjectAttribute[]{
-// new SimpleAttribute("carLicense", new String[]{"val1"})
-// };
-//
-// store.addAttributes(ctx, user1, attrs);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(3, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("phone"));
-// assertEquals(1, persistedAttrs.get("phone").getSize());
-//
-// assertTrue(persistedAttrs.containsKey("description"));
-// assertEquals(4, persistedAttrs.get("description").getSize());
-//
-// assertTrue(persistedAttrs.containsKey("carLicense"));
-// assertEquals(1, persistedAttrs.get("carLicense").getSize());
-//
-// attrs = new IdentityObjectAttribute[]{
-// new SimpleAttribute("carLicense", new String[]{"val2"})
-// };
-//
-// store.addAttributes(ctx, user1, attrs);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(3, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("carLicense"));
-// assertEquals(2, persistedAttrs.get("carLicense").getSize());
-//
-// //
-//
-// store.updateAttributes(ctx, user1, attrs);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(3, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("carLicense"));
-// assertEquals(1, persistedAttrs.get("carLicense").getSize());
-//
-// //
-//
-// String[] names = new String[]{"carLicense"};
-// store.removeAttributes(ctx, user1, names);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(2, persistedAttrs.keySet().size());
-//
-// }
-
- @Test
- public void testRelationships() throws Exception
- {
- populateClean();
-
- commonTest.testRelationships();
-
- }
-
- @Test
- public void testStorePersistence() throws Exception
- {
- populateClean();
-
- commonTest.testStorePersistence();
-
- }
-
- @Test
- public void testFindMethods() throws Exception
- {
- populateClean();
-
- commonTest.testFindMethods();
-
- }
-
- @Test
- public void testCriteria() throws Exception
- {
- populateClean();
-
- commonTest.testCriteria();
- }
-
-
- @Test
- public void testCredentials() throws Exception
- {
- populateClean();
-
- commonTest.testPasswordCredential();
- }
-
-}
Copied:
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java
(from rev 1007,
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java)
===================================================================
---
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java
(rev 0)
+++
migration/idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java 2009-11-18
15:27:05 UTC (rev 1013)
@@ -0,0 +1,376 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.store.ldap;
+
+import org.picketlink.idm.impl.LDAPTestPOJO;
+import org.picketlink.idm.impl.configuration.IdentityConfigurationImpl;
+import org.picketlink.idm.impl.configuration.IdentityStoreConfigurationContextImpl;
+import org.picketlink.idm.impl.configuration.jaxb2.JAXB2IdentityConfiguration;
+import org.picketlink.idm.impl.store.CommonIdentityStoreTest;
+import org.picketlink.idm.impl.store.IdentityStoreTestContext;
+import org.picketlink.idm.spi.configuration.IdentityConfigurationContextRegistry;
+import org.picketlink.idm.spi.configuration.IdentityStoreConfigurationContext;
+import org.picketlink.idm.spi.configuration.metadata.IdentityConfigurationMetaData;
+import org.picketlink.idm.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
+import org.picketlink.idm.spi.store.IdentityStore;
+import org.picketlink.idm.spi.store.IdentityStoreInvocationContext;
+import org.picketlink.idm.spi.store.IdentityStoreSession;
+import org.jboss.unit.api.pojo.annotations.Create;
+import org.jboss.unit.api.pojo.annotations.Destroy;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class LDAPIdentityStoreTestCase extends LDAPTestPOJO implements
IdentityStoreTestContext
+{
+
+ CommonIdentityStoreTest commonTest;
+
+ IdentityStoreInvocationContext ctx;
+
+ IdentityStore store;
+
+ public LDAPIdentityStoreTestCase()
+ {
+
+ }
+
+ @Create
+ public void setUp() throws Exception
+ {
+ super.start();
+
+// setIdentityConfig("store-test-config.xml");
+
+ commonTest = new CommonIdentityStoreTest(this);
+
+ IdentityConfigurationMetaData configurationMD = JAXB2IdentityConfiguration
+ .createConfigurationMetaData(getIdentityConfig());
+
+ IdentityConfigurationContextRegistry registry =
(IdentityConfigurationContextRegistry) new IdentityConfigurationImpl().
+ configure(configurationMD);
+
+ IdentityStoreConfigurationMetaData storeMD = null;
+
+ for (IdentityStoreConfigurationMetaData metaData :
configurationMD.getIdentityStores())
+ {
+ if (metaData.getId().equals("LDAP Identity Store"))
+ {
+ storeMD = metaData;
+ break;
+ }
+ }
+
+ IdentityStoreConfigurationContext context = new
IdentityStoreConfigurationContextImpl(configurationMD, registry, storeMD);
+
+
+
+ //populate();
+
+ store = new LDAPIdentityStoreImpl("LDAP Identity Store");
+
+ store.bootstrap(context);
+
+ final IdentityStoreSession storeSession = store.createIdentityStoreSession();
+
+ ctx = new IdentityStoreInvocationContext()
+ {
+ public IdentityStoreSession getIdentityStoreSession()
+ {
+ return storeSession;
+ }
+
+ public String getRealmId()
+ {
+ return "testRealm";
+ }
+
+ public String getSessionId()
+ {
+ return "";
+ }
+ };
+ }
+
+ @Destroy
+ public void tearDown() throws Exception
+ {
+ super.stop();
+ }
+
+
+ public void flush() throws Exception
+ {
+ //nothing
+ }
+
+ public IdentityStore getStore()
+ {
+ return store;
+ }
+
+ public IdentityStoreInvocationContext getCtx()
+ {
+ return ctx;
+ }
+
+
+ // Tests
+
+// Just test if OpenDS is running and was populated...
+ @Test
+ public void testSimple() throws Exception
+ {
+ populateClean();
+
+ Hashtable<String,String> env = new Hashtable<String,String>();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, directoryConfig.getContextFactory());
+ env.put(Context.PROVIDER_URL, directoryConfig.getDescription());
+ env.put(Context.SECURITY_AUTHENTICATION, "simple");
+ env.put(Context.SECURITY_PRINCIPAL, directoryConfig.getAdminDN());
+ env.put(Context.SECURITY_CREDENTIALS, directoryConfig.getAdminPassword());
+
+ LdapContext ldapCtx = null;
+ try
+ {
+ ldapCtx = new InitialLdapContext(env, null);
+
+// Do something ...
+ System.out.println("Attributes: " +
ldapCtx.getAttributes(directoryConfig.getCleanUpDN()));
+
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (ldapCtx != null)
+ {
+ ldapCtx.close();
+ }
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+// @Test
+// public void testIdentityObjectCount() throws Exception
+// {
+// populate();
+//
+// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+// assertEquals(5, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.ROLE));
+// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+// }
+//
+// @Test
+// public void testFindCreateRemove() throws Exception
+// {
+// populate();
+//
+// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+//
+// IdentityObject io = store.findIdentityObject(ctx, "admin",
IdentityTypeEnum.USER);
+// assertEquals("admin", io.getName());
+// assertEquals("uid=admin,ou=People,o=test,dc=portal,dc=example,dc=com",
io.getKey().toString());
+//
+// //
+//
+// store.removeIdentityObject(ctx, io);
+//
+// assertEquals(6, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+//
+// store.createIdentityObject(ctx, "newUserA", IdentityTypeEnum.USER);
+//
+// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+//
+// //
+//
+// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+//
+// store.createIdentityObject(ctx, "newGroupA", IdentityTypeEnum.GROUP);
+//
+// assertEquals(3, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+//
+// //
+//
+// io = store.findIdentityObject(ctx,
"cn=newGroupA,ou=Groups,o=test,dc=portal,dc=example,dc=com");
+// assertEquals("newGroupA", io.getName());
+//
+// }
+
+// @Test
+// public void testAttributes() throws Exception{
+//
+// populate();
+//
+// IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
+// IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
+//
+// //
+//
+// IdentityObjectAttribute[] attrs = new IdentityObjectAttribute[]{
+// new SimpleAttribute("phone", new String[]{"val1"}),
+// new SimpleAttribute("description", new String[]{"val1",
"val2", "val3", "val4"}),
+//
+// };
+//
+// store.addAttributes(ctx, user1, attrs);
+//
+// //
+//
+// Map<String, IdentityObjectAttribute> persistedAttrs =
store.getAttributes(ctx, user1);
+//
+// assertEquals(2, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("phone"));
+// assertEquals(1, persistedAttrs.get("phone").getSize());
+//
+// assertTrue(persistedAttrs.containsKey("description"));
+// assertEquals(4, persistedAttrs.get("description").getSize());
+//
+// //
+//
+// attrs = new IdentityObjectAttribute[]{
+// new SimpleAttribute("carLicense", new String[]{"val1"})
+// };
+//
+// store.addAttributes(ctx, user1, attrs);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(3, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("phone"));
+// assertEquals(1, persistedAttrs.get("phone").getSize());
+//
+// assertTrue(persistedAttrs.containsKey("description"));
+// assertEquals(4, persistedAttrs.get("description").getSize());
+//
+// assertTrue(persistedAttrs.containsKey("carLicense"));
+// assertEquals(1, persistedAttrs.get("carLicense").getSize());
+//
+// attrs = new IdentityObjectAttribute[]{
+// new SimpleAttribute("carLicense", new String[]{"val2"})
+// };
+//
+// store.addAttributes(ctx, user1, attrs);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(3, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("carLicense"));
+// assertEquals(2, persistedAttrs.get("carLicense").getSize());
+//
+// //
+//
+// store.updateAttributes(ctx, user1, attrs);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(3, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("carLicense"));
+// assertEquals(1, persistedAttrs.get("carLicense").getSize());
+//
+// //
+//
+// String[] names = new String[]{"carLicense"};
+// store.removeAttributes(ctx, user1, names);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(2, persistedAttrs.keySet().size());
+//
+// }
+
+ @Test
+ public void testRelationships() throws Exception
+ {
+ populateClean();
+
+ commonTest.testRelationships();
+
+ }
+
+ @Test
+ public void testStorePersistence() throws Exception
+ {
+ populateClean();
+
+ commonTest.testStorePersistence();
+
+ }
+
+ @Test
+ public void testFindMethods() throws Exception
+ {
+ populateClean();
+
+ commonTest.testFindMethods();
+
+ }
+
+ @Test
+ public void testCriteria() throws Exception
+ {
+ populateClean();
+
+ commonTest.testCriteria();
+ }
+
+
+ @Test
+ public void testCredentials() throws Exception
+ {
+ populateClean();
+
+ commonTest.testPasswordCredential();
+ }
+
+}