[portal-commits] JBoss Portal SVN: r8878 - branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/instance.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Nov 12 09:49:09 EST 2007


Author: thomas.heute at jboss.com
Date: 2007-11-12 09:49:09 -0500 (Mon, 12 Nov 2007)
New Revision: 8878

Added:
   branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/instance/BackwardCompatibilityInstanceTestCase.java
Log:
Ugly test case for schema update
oups

Added: branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/instance/BackwardCompatibilityInstanceTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/instance/BackwardCompatibilityInstanceTestCase.java	                        (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/instance/BackwardCompatibilityInstanceTestCase.java	2007-11-12 14:49:09 UTC (rev 8878)
@@ -0,0 +1,266 @@
+/******************************************************************************
+ * 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.                   *
+ ******************************************************************************/
+
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.portal.test.core.model.instance;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.hibernate.Query;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.classic.Session;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
+import org.jboss.portal.common.junit.TransactionAssert;
+import org.jboss.portal.common.value.StringValue;
+import org.jboss.portal.core.impl.model.instance.InstanceContainerImpl;
+import org.jboss.portal.core.model.instance.Instance;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.state.AbstractPropertyContext;
+import org.jboss.portal.portlet.state.PropertyChange;
+import org.jboss.portal.portlet.state.PropertyContext;
+import org.jboss.portal.test.framework.AbstractPortalTestCase;
+import org.jboss.portal.test.framework.embedded.HibernateSupport;
+import org.jboss.portal.test.framework.embedded.HibernateSupport.Config;
+import org.jboss.portal.test.framework.mc.TestRuntimeContext;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision: 8786 $
+ * @since Apr 4, 2006
+ */
+public class BackwardCompatibilityInstanceTestCase extends AbstractPortalTestCase
+{
+
+   /** . */
+   private HibernateSupport instanceHibernateSupport260;
+
+   /** . */
+   private HibernateSupport portletHibernateSupport;
+
+   /** . */
+   private InstanceContainerImpl instanceContainer260;
+   
+   /** . */
+   private PortletInvokerSupport portletContainer;
+   
+   /** . */
+   private Config config;
+   
+   /** . */
+   private Collection mappings;
+
+   static
+   {
+      Appender appender = new ConsoleAppender(new SimpleLayout());
+      Logger.getRoot().addAppender(appender);
+      Logger.getRoot().setLevel(Level.ERROR);
+      Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
+   }
+
+   public static TestSuite suite() throws Exception
+   {
+      return AbstractPortalTestCase.suite(BackwardCompatibilityInstanceTestCase.class);
+   }
+
+   protected String getConfigLocationPrefix()
+   {
+      return "org/jboss/portal/test/core/model/instance/";
+   }
+   
+   public HibernateSupport getInstanceHibernateSupport260()
+   {
+      return instanceHibernateSupport260;
+   }
+
+   public void setInstanceHibernateSupport260(HibernateSupport instanceHibernateSupport260)
+   {
+      this.instanceHibernateSupport260 = instanceHibernateSupport260;
+   }
+
+   public HibernateSupport getPortletHibernateSupport()
+   {
+      return portletHibernateSupport;
+   }
+
+   public void setPortletHibernateSupport(HibernateSupport portletHibernateSupport)
+   {
+      this.portletHibernateSupport = portletHibernateSupport;
+   }
+
+   public InstanceContainerImpl getInstanceContainer260()
+   {
+      return instanceContainer260;
+   }
+
+   public void setInstanceContainer260(InstanceContainerImpl instanceContainer260)
+   {
+      this.instanceContainer260 = instanceContainer260;
+   }
+
+   protected void setUp() throws Exception
+   {
+      runtimeContext = new TestRuntimeContext(getConfigLocation());
+      runtimeContext.addBean("TestBean", this);
+      runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
+      runtimeContext.addBean("HibernateConfig", HibernateSupport.getConfig(dataSourceConfigParameter.getName()));
+      configureRuntimeContext(runtimeContext);
+      runtimeContext.start();
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      // clean up any pending transaction
+      TransactionAssert.endTransaction();
+
+      runtimeContext.stop();
+   }
+
+   public void testRead() throws Exception
+   {
+      // Add portlet
+      portletContainer.addInternalPortlet("MyPortlet", new TestPortletSupport());
+
+      // Create new instance
+      TransactionAssert.beginTransaction();
+      instanceContainer260.createDefinition("MyInstance", "MyPortlet").getId();
+      TransactionAssert.commitTransaction();
+      
+      Configuration cfg = new Configuration();
+
+      //
+      for (Iterator i = mappings.iterator(); i.hasNext();)
+      {
+         String mapping = (String)i.next();
+         cfg.addResource(mapping, Thread.currentThread().getContextClassLoader());
+      }
+
+      //
+      Properties props = new Properties();
+      for (Iterator i = config.getProperties().entrySet().iterator();i.hasNext();)
+      {
+         Map.Entry entry = (Map.Entry)i.next();
+         String key = (String)entry.getKey();
+         String value = (String)entry.getValue();
+         cfg.setProperty(key, value);
+      }
+      cfg.addProperties(props);
+      
+      // todo : make this configurable somehow
+      cfg.setProperty("hibernate.connection.datasource", "java:/DefaultDS");
+      
+      SessionFactory sessionFactory = cfg.buildSessionFactory();
+      
+      SchemaUpdate update = new SchemaUpdate(cfg, cfg.buildSettings());
+      update.execute(false, true);
+
+      // Get Hibernate session with 2.6.x schema
+      Session session = sessionFactory.openSession();
+      session.beginTransaction();
+      Query query = session.createQuery("From PersistentInstanceDefinition");
+      Instance instance = (Instance)query.uniqueResult();
+      assertEquals(null, instance.getDisplayName().getDefaultValue());
+   }
+
+   public PortletInvokerSupport getPortletContainer()
+   {
+      return portletContainer;
+   }
+
+   public void setPortletContainer(PortletInvokerSupport portletContainer)
+   {
+      this.portletContainer = portletContainer;
+   }
+
+   private class TestPortletSupport extends PortletSupport
+   {
+
+      private PortletInvocation invocation;
+
+      public TestPortletSupport()
+      {
+         this.info.getMetaSupport().setDisplayName("Foo");
+      }
+
+      public PortletInvocationResponse invoke(PortletInvocation invocation)
+      {
+         this.invocation = invocation;
+         try
+         {
+            return execute();
+         }
+         finally
+         {
+            this.invocation = null;
+         }
+      }
+
+      public PortletInvocationResponse execute()
+      {
+         return null;
+      }
+
+      public void setProperty(String key, String value) throws IllegalStateException
+      {
+         AbstractPropertyContext props = (AbstractPropertyContext)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE, PropertyContext.PREFERENCES_ATTRIBUTE);
+         props.update(new PropertyChange[]{PropertyChange.newUpdate(key, new StringValue(value))});
+      }
+   }
+
+   public Config getConfig()
+   {
+      return config;
+   }
+
+   public void setConfig(Config config)
+   {
+      this.config = config;
+   }
+
+   public Collection getMappings()
+   {
+      return mappings;
+   }
+
+   public void setMappings(Collection mappings)
+   {
+      this.mappings = mappings;
+   }
+
+}




More information about the portal-commits mailing list