[portal-commits] JBoss Portal SVN: r5840 - in trunk/identity/src/main/org/jboss/portal/test/identity: . db

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Wed Dec 13 10:40:21 EST 2006


Author: bdaw
Date: 2006-12-13 10:40:19 -0500 (Wed, 13 Dec 2006)
New Revision: 5840

Added:
   trunk/identity/src/main/org/jboss/portal/test/identity/db/
   trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
   trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java
Log:
refactored identity tests for the new stuff

Added: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java	2006-12-13 15:39:20 UTC (rev 5839)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java	2006-12-13 15:40:19 UTC (rev 5840)
@@ -0,0 +1,261 @@
+/*
+* 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.portal.test.identity.db;
+
+import org.jboss.portal.identity2.IdentityServiceControllerImpl;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity2.ProfileMap;
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.db.HibernateUserImpl;
+import org.jboss.portal.identity2.db.HibernateUserModuleImpl;
+import org.jboss.portal.identity2.db.HibernateRoleModuleImpl;
+import org.jboss.portal.identity2.db.HibernateMembershipModuleImpl;
+import org.jboss.portal.identity2.db.HibernateUserProfileModuleImpl;
+import org.jboss.portal.identity2.config.metadata.ConfigurationParser;
+import org.jboss.portal.identity2.config.info.ProfileInfoSupport;
+import org.jboss.portal.identity2.info.ProfileInfo;
+import org.jboss.portal.test.identity.UserTest;
+import org.jboss.portal.common.p3p.P3PConstants;
+import junit.framework.TestSuite;
+
+import java.util.Date;
+import java.text.SimpleDateFormat;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 5748 $
+ */
+public class DBIdentityTestCase extends DBTestCase
+{
+
+   public static TestSuite suite() throws Exception
+   {
+      System.out.println("###");
+      return createTestSuite(DBIdentityTestCase.class);
+   }
+
+   public void setUp() throws Exception
+   {
+
+      //generate hibernate mappings based on the profile file
+//      ProfileInfo info = new ProfileInfoSupport(ConfigurationParser.parseProfileConfiguration("test/config/profile-config.xml"));
+//      String pattern = "<property name=\"@name@\" column=\"@column@\" type=\"java.lang.String\" update=\"true\" insert=\"true\" unique=\"false\"/>";
+//      HibernateHelper.generateProfileMappings("hibernate/domain-template-single.hbm.xml",
+//                                              "resources/hibernate/domain-identity.hbm.xml",
+//                                              pattern,
+//                                              info,
+//                                              Thread.currentThread().getContextClassLoader());
+
+      
+
+      //initialize microcontainer stuff
+      super.setUp();
+      
+
+      //bootstrap identity modules
+      IdentityServiceControllerImpl controller = new IdentityServiceControllerImpl();
+      controller.setConfigFile("test/config/db-config.xml");
+      controller.setDefaultConfigFile("test/config/standardidentity-config.xml");
+      controller.setRegisterMBeans(false);
+      controller.start();
+      identityContext = controller.getIdentityContext();
+      this.userModule = (HibernateUserModuleImpl)identityContext.getObject(IdentityContext.TYPE_USER_MODULE);
+      this.roleModule = (HibernateRoleModuleImpl)identityContext.getObject(IdentityContext.TYPE_ROLE_MODULE);
+      this.membershipModule = (HibernateMembershipModuleImpl)identityContext.getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
+      this.userProfileModule = (HibernateUserProfileModuleImpl)identityContext.getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
+
+      //
+      utc = new UserTest();
+      utc.setUserModule(userModule);
+      utc.setRoleModule(roleModule);
+      utc.setMembershipModule(membershipModule);
+      utc.setContext(this);
+      utc.populate();
+   }
+
+
+
+
+
+
+   public void testWorking() throws Exception
+   {
+      
+   }
+
+   //
+
+   public void testFindUsersUsingFilter() throws Exception
+   {
+      utc.testFindUsersUsingFilter();
+   }
+
+   public void testFindUser1() throws Exception
+   {
+      utc.testFindUser1();
+   }
+
+   public void testFindUser2() throws Exception
+   {
+      utc.testFindUser2();
+   }
+
+   public void testFindUsers() throws Exception
+   {
+      utc.testFindUsers();
+   }
+
+   public void testCreateUser() throws Exception
+   {
+      utc.testCreateUser();
+   }
+
+   public void testCreateRole() throws Exception
+   {
+      utc.testCreateRole();
+   }
+
+   public void testCountUser() throws Exception
+   {
+      utc.testCountUser();
+   }
+
+   public void testRemoveNonExistingRole() throws Exception
+   {
+      utc.testRemoveNonExistingRole();
+   }
+
+   public void testRemoveRole() throws Exception
+   {
+      utc.testRemoveRole();
+   }
+
+   public void testRemoveUser() throws Exception
+   {
+      utc.testRemoveUser();
+   }
+
+   public void testFindRoles() throws Exception
+   {
+      utc.testFindRoles();
+   }
+
+   public void testFindRoleMembers() throws Exception
+   {
+      utc.testFindRoleMembers();
+   }
+
+   public void testDynamicProperty() throws Exception
+   {
+      begin();
+      User user = userModule.createUser("testname", "testpassword");
+      ProfileMap map = ((HibernateUserImpl)user).getProfileMap();
+      assertNull(map.get("foo"));
+      assertFalse(map.isReadOnly("foo"));
+      map.put("foo", "value");
+      assertEquals("value", map.get("foo"));
+      assertFalse(map.isReadOnly("foo"));
+      commit();
+
+      begin();
+      user = userModule.findUserByUserName("testname");
+      map = ((HibernateUserImpl)user).getProfileMap();
+      assertEquals("value", map.get("foo"));
+      assertFalse(map.isReadOnly("foo"));
+      commit();
+   }
+
+   public void testStaticProperty() throws Exception
+   {
+      begin();
+
+      //
+      User user = userModule.createUser("testname", "testpassword");
+      ProfileMap map = ((HibernateUserImpl)user).getProfileMap();
+      assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
+
+      // Test cannot remove a static property
+      try
+      {
+         map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
+         fail("Should not be capable to remove static property");
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+
+      // Test read only property
+      assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
+      try
+      {
+         map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
+         fail("Should not be capable to modify a read only static property");
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+
+      // Test non nullable and writable property
+      try
+      {
+         map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
+         fail("Should not be capable to nullify a non nullable static property");
+      }
+      catch (NullPointerException expected)
+      {
+      }
+      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+      assertEquals("true", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+      // Test boolean property
+      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
+      assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals("false", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+      assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals("true", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+      userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
+      assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals("false", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+      userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+      assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals("true", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      try
+      {
+         map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
+         fail("Should not be capable to set a bad value to boolean property");
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+
+      // Test date
+      Date date = ((HibernateUserImpl)user).getRegistrationDate();
+      SimpleDateFormat sdf = new SimpleDateFormat();
+      assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
+
+      commit();
+   }
+}

Added: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java	2006-12-13 15:39:20 UTC (rev 5839)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java	2006-12-13 15:40:19 UTC (rev 5840)
@@ -0,0 +1,201 @@
+/*
+* 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.portal.test.identity.db;
+
+import org.jboss.portal.test.framework.embedded.DataSourceSupport;
+import org.jboss.portal.test.framework.embedded.HibernateSupport;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.identity.UserTest;
+import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.jboss.portal.common.test.junit.JUnitAdapter;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity2.db.HibernateUserModuleImpl;
+import org.jboss.portal.identity2.db.HibernateRoleModuleImpl;
+import org.jboss.portal.identity2.db.HibernateMembershipModuleImpl;
+import org.jboss.portal.identity2.db.HibernateUserProfileModuleImpl;
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+import junit.framework.TestSuite;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class DBTestCase extends junit.framework.TestCase implements UserTest.Context
+{
+
+   static
+   {
+      Appender appender = new ConsoleAppender(new SimpleLayout());
+      Logger.getRoot().addAppender(appender);
+      Logger.getRoot().setLevel(Level.DEBUG);
+      Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
+      Logger.getLogger("org.jboss.portal.identity2").setLevel(Level.DEBUG);
+   }
+
+   public static TestSuite createTestSuite(Class clazz) throws Exception
+   {
+      URL configsURL = Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
+      Map parameterMap = new HashMap();
+      parameterMap.put("DataSourceConfig", DataSourceSupport.Config.fromXML2(configsURL));
+      POJOJUnitTest abc = new POJOJUnitTest(clazz);
+      JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
+      TestSuite suite = new TestSuite();
+      suite.addTest(adapter);
+      return suite;
+   }
+
+
+    /**
+    * .
+    */
+   protected DataSourceSupport.Config dataSourceConfigParameter;
+
+   /**
+    * .
+    */
+   protected TestRuntimeContext runtimeContext;
+
+   /**
+    * .
+    */
+   protected HibernateSupport hibernate;
+
+   /**
+    * .
+    */
+   protected IdentityContext identityContext;
+
+   /** . */
+   protected UserTest utc;
+
+   /**
+    * .
+    */
+   protected HibernateUserModuleImpl userModule;
+
+   /**
+    * .
+    */
+   protected HibernateRoleModuleImpl roleModule;
+
+   /**
+    * .
+    */
+   protected HibernateMembershipModuleImpl membershipModule;
+
+   /**
+    * .
+    */
+   protected HibernateUserProfileModuleImpl userProfileModule;
+
+   public DataSourceSupport.Config getDataSourceConfigParameter()
+   {
+      return dataSourceConfigParameter;
+   }
+
+   public void setDataSourceConfigParameter(DataSourceSupport.Config dataSourceConfig)
+   {
+      this.dataSourceConfigParameter = dataSourceConfig;
+   }
+
+   public HibernateSupport getHibernate()
+   {
+      return hibernate;
+   }
+
+   public void setHibernate(HibernateSupport hibernate)
+   {
+      this.hibernate = hibernate;
+   }
+
+
+   public String getName()
+   {
+      return super.getName() + "," + dataSourceConfigParameter.getName();
+   }
+
+
+   protected void setUp() throws Exception
+   {                                                                           
+      hibernate = new HibernateSupport();
+
+
+      runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/db-beans.xml");
+      runtimeContext.addBean("DBTestBean", this);
+      runtimeContext.addBean("HibernateSupport", hibernate);
+      runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
+
+      HibernateSupport.Config config = HibernateSupport.getConfig(dataSourceConfigParameter.getName());
+      //add hibernate properties for dynamic entities
+      //config.getProperties().put("hibernate.default_entity_mode","dynamic-map");
+
+      runtimeContext.addBean("HibernateConfig", config);
+      runtimeContext.start();
+   }
+
+
+
+   public void tearDown() throws Exception
+   {
+      utc.setUserModule(null);
+      utc.setRoleModule(null);
+      utc.setMembershipModule(null);
+      utc.setUserProfileModule(null);
+      utc.setContext(null);
+      utc = null;
+
+      //
+      roleModule.destroy();
+      userModule.destroy();
+      membershipModule.destroy();
+      userProfileModule.destroy();
+      
+      roleModule = null;
+      userModule = null;
+      membershipModule = null;
+      userProfileModule = null;
+
+      //
+      runtimeContext.stop();
+   }
+
+
+   public void begin()
+   {
+      hibernate.openSession();
+   }
+
+   public void commit()
+   {
+      assertTrue(hibernate.commitTransaction());
+   }
+
+
+}




More information about the portal-commits mailing list