[jboss-cvs] jboss-portal/core/src/main/org/jboss/portal/test/core/state ...

Julien Viet julien at jboss.com
Sun Jul 30 08:36:22 EDT 2006


  User: julien  
  Date: 06/07/30 08:36:22

  Added:       core/src/main/org/jboss/portal/test/core/state  
                        SimpleInstanceContext.java
                        StatefulPortletInvokerTestCase.java
  Log:
  JBPORTAL-973 : Portlet instance container integration testing
  JBPORTAL-972 : Portlet stateful invoker testing
  
  Revision  Changes    Path
  1.1      date: 2006/07/30 12:36:22;  author: julien;  state: Exp;jboss-portal/core/src/main/org/jboss/portal/test/core/state/SimpleInstanceContext.java
  
  Index: SimpleInstanceContext.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., 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.core.state;
  
  import org.jboss.portal.portlet.support.spi.InstanceContextSupport;
  import org.jboss.portal.portlet.state.AccessMode;
  
  /**
   * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
   * @version $Revision: 1.1 $
   */
  public class SimpleInstanceContext extends InstanceContextSupport
  {
  
     private final String id;
     private final AccessMode accessMode;
     private String cloneId;
  
     public SimpleInstanceContext(String id, AccessMode accessMode)
     {
        this.id = id;
        this.accessMode = accessMode;
     }
  
     public String getId()
     {
        return id;
     }
  
     public void portletCloned(String cloneId)
     {
        this.cloneId = cloneId;
     }
  
     public AccessMode getAccessMode()
     {
        return accessMode;
     }
  
     public String getCloneId()
     {
        return cloneId;
     }
  }
  
  
  
  1.1      date: 2006/07/30 12:36:22;  author: julien;  state: Exp;jboss-portal/core/src/main/org/jboss/portal/test/core/state/StatefulPortletInvokerTestCase.java
  
  Index: StatefulPortletInvokerTestCase.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., 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.core.state;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  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 org.jboss.portal.test.framework.embedded.DataSourceSupport;
  import org.jboss.portal.test.framework.embedded.HibernateSupport;
  import org.jboss.portal.test.framework.junit.DatabaseTestSuite;
  import org.jboss.portal.test.framework.junit.TransactionAssert;
  import org.jboss.portal.test.framework.TestRuntimeContext;
  import org.jboss.portal.test.core.model.instance.SimpleActionContext;
  import org.jboss.portal.test.core.model.instance.SimpleUserContext;
  import org.jboss.portal.portlet.test.ValueMapAssert;
  import org.jboss.portal.core.impl.portlet.state.PersistentStateStore;
  import org.jboss.portal.core.impl.portlet.state.StatefulPortletInvoker;
  import org.jboss.portal.portlet.NoSuchPortletException;
  import org.jboss.portal.portlet.Portlet;
  import org.jboss.portal.portlet.Mode;
  import org.jboss.portal.portlet.invocation.PortletInvocation;
  import org.jboss.portal.portlet.invocation.ActionInvocation;
  import org.jboss.portal.portlet.state.producer.State;
  import org.jboss.portal.portlet.state.AbstractPropertyContext;
  import org.jboss.portal.portlet.state.PropertyChange;
  import org.jboss.portal.portlet.state.AccessMode;
  import org.jboss.portal.portlet.test.support.info.PreferencesInfoSupport;
  import org.jboss.portal.portlet.test.support.PortletInvokerSupport;
  import org.jboss.portal.portlet.test.support.PortletSupport;
  import org.jboss.portal.common.value.StringValue;
  import org.jboss.portal.common.value.ValueMap;
  import org.jboss.portal.common.value.SimpleValueMap;
  
  import java.net.URL;
  
  /**
   * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
   * @version $Revision: 1.1 $
   */
  public class StatefulPortletInvokerTestCase extends TestCase
  {
  
     static
     {
        Appender appender = new ConsoleAppender(new SimpleLayout());
        Logger.getRoot().addAppender(appender);
        Logger.getRoot().setLevel(Level.DEBUG);
        Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
     }
  
     public static TestSuite suite() throws Exception
     {
        URL configsURL = Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
        DataSourceSupport.Config[] configs = DataSourceSupport.Config.fromXML(configsURL);
        DatabaseTestSuite suite = new DatabaseTestSuite(configs);
        suite.addTestCase(StatefulPortletInvokerTestCase.class);
        return suite;
     }
  
     /** . */
     private TestRuntimeContext runtimeContext;
  
     /** . */
     private DataSourceSupport.Config dsCfg;
  
     /** . */
     private HibernateSupport hibernateSupport;
  
     /** . */
     private PersistentStateStore stateStore;
  
     /** . */
     private StatefulPortletInvoker statefulPortletInvoker;
  
     /** . */
     private PortletInvokerSupport nextPortletInvoker;
  
     public StatefulPortletInvokerTestCase(DataSourceSupport.Config config)
     {
        this.dsCfg = config;
     }
  
     public HibernateSupport getHibernateSupport()
     {
        return hibernateSupport;
     }
  
     public void setHibernateSupport(HibernateSupport hibernateSupport)
     {
        this.hibernateSupport = hibernateSupport;
     }
  
     public PersistentStateStore getStateStore()
     {
        return stateStore;
     }
  
     public void setStateStore(PersistentStateStore stateStore)
     {
        this.stateStore = stateStore;
     }
  
     public StatefulPortletInvoker getStatefulPortletInvoker()
     {
        return statefulPortletInvoker;
     }
  
     public void setStatefulPortletInvoker(StatefulPortletInvoker statefulPortletInvoker)
     {
        this.statefulPortletInvoker = statefulPortletInvoker;
     }
  
     public PortletInvokerSupport getNextPortletInvoker()
     {
        return nextPortletInvoker;
     }
  
     public void setNextPortletInvoker(PortletInvokerSupport nextPortletInvoker)
     {
        this.nextPortletInvoker = nextPortletInvoker;
     }
  
     protected void setUp() throws Exception
     {
        runtimeContext = new TestRuntimeContext("org/jboss/portal/test/core/state/jboss-beans.xml");
        runtimeContext.addBean("TestBean", this);
        runtimeContext.addBean("DataSourceConfig", dsCfg);
        runtimeContext.start();
  
        nextPortletInvoker.addPortlet(new PortletSupport("SimplePortlet")
        {
           {
              PreferencesInfoSupport prefs = info.getPreferencesSupport();
              prefs.addPreference("abc", new StringValue("def"));
           }
           public void invoke(PortletInvocation invocation)
           {
              AbstractPropertyContext props = (AbstractPropertyContext)invocation.getAttribute(PortletInvocation.PREFERENCES_ATTRIBUTE);
              props.update(new PropertyChange[]{new PropertyChange(PropertyChange.PREF_SET, "_abc", new StringValue("_def"))});
           }
        });
  
        nextPortletInvoker.addPortlet(new PortletSupport("CloningPortlet")
        {
           {
              PreferencesInfoSupport prefs = info.getPreferencesSupport();
              prefs.addPreference("abc", new StringValue("def"));
           }
           public void invoke(PortletInvocation invocation)
           {
              AbstractPropertyContext props = (AbstractPropertyContext)invocation.getAttribute(PortletInvocation.PREFERENCES_ATTRIBUTE);
              props.update(new PropertyChange[]{new PropertyChange(PropertyChange.PREF_SET, "_abc", new StringValue("_def"))});
           }
        });
  
        nextPortletInvoker.addPortlet(new PortletSupport("CloneFailedCloningPortlet")
        {
           {
              PreferencesInfoSupport prefs = info.getPreferencesSupport();
              prefs.addPreference("abc", new StringValue("def"));
           }
           public void invoke(PortletInvocation invocation)
           {
              try
              {
                 AbstractPropertyContext props = (AbstractPropertyContext)invocation.getAttribute(PortletInvocation.PREFERENCES_ATTRIBUTE);
                 props.update(new PropertyChange[]{new PropertyChange(PropertyChange.PREF_SET, "_abc", new StringValue("_def"))});
                 fail("Was expecting an IllegalStateException");
              }
              catch (IllegalStateException expected)
              {
              }
           }
        });
  
        nextPortletInvoker.addPortlet(new PortletSupport("CloningPortletThrowingRuntimeException")
        {
           {
              PreferencesInfoSupport prefs = info.getPreferencesSupport();
              prefs.addPreference("abc", new StringValue("def"));
           }
           public void invoke(PortletInvocation invocation)
           {
              AbstractPropertyContext props = (AbstractPropertyContext)invocation.getAttribute(PortletInvocation.PREFERENCES_ATTRIBUTE);
              props.update(new PropertyChange[]{new PropertyChange(PropertyChange.PREF_SET, "_abc", new StringValue("_def"))});
              throw new RuntimeException("custom_message");
           }
        });
     }
  
     protected void tearDown() throws Exception
     {
        // Cleanup any pending transaction
        TransactionAssert.endTransaction();
  
        runtimeContext.stop();
     }
  
     public void testCloneNonExistingPortletWithinTx() throws Exception
     {
        try
        {
           TransactionAssert.beginTransaction();
           statefulPortletInvoker.createClone("UnknownPortlet");
           fail("Was expecting no such portlet exception");
        }
        catch (NoSuchPortletException e)
        {
           TransactionAssert.rollbackTransaction(true);
        }
  
        // todo check state
  
  //      try
  //      {
  //         TransactionAssert.beginTransaction();
  //         statefulPortletInvoker.createClone("_1");
  //         fail("Was expecting no such portlet exception");
  //      }
  //      catch (NoSuchPortletException e)
  //      {
  //         TransactionAssert.rollbackTransaction(true);
  //      }
  
        // todo check state
     }
  
     public void testCloneNullPortletWithinTx() throws Exception
     {
        try
        {
           TransactionAssert.beginTransaction();
           statefulPortletInvoker.createClone(null);
           fail("Was expecting an IllegalArgumentException");
        }
        catch (IllegalArgumentException expected)
        {
           TransactionAssert.rollbackTransaction(true);
        }
     }
  
     public void testCloneExistingPortletWithinTx() throws Exception
     {
        // Clone a POP
        TransactionAssert.beginTransaction();
        String cloneId = statefulPortletInvoker.createClone("SimplePortlet");
        TransactionAssert.commitTransaction();
  
        // Check the clone state
        TransactionAssert.beginTransaction();
        assertTrue(cloneId.startsWith("_"));
        State cloneState = stateStore.loadState(cloneId.substring(1));
        assertNotNull(cloneState);
        assertEquals(cloneId, "_" + cloneState.getId());
        assertEquals("SimplePortlet", cloneState.getPortletId());
        ValueMap cloneValues = cloneState.getProperties();
        assertNotNull(cloneValues);
        assertNotNull(cloneValues.getKeys());
        assertEquals(1, cloneValues.getKeys().size());
        assertEquals(new StringValue("def"), cloneValues.getValue("abc"));
        TransactionAssert.commitTransaction();
  
        // Update CCP state directly
        TransactionAssert.beginTransaction();
        ValueMap newCloneValues = new SimpleValueMap(cloneValues);
        newCloneValues.setValue("abc", new StringValue("fed"));
        stateStore.updateState(cloneId.substring(1), newCloneValues);
        TransactionAssert.commitTransaction();
  
        // Clone the modified CCP
        TransactionAssert.beginTransaction();
        String cloneCloneId = statefulPortletInvoker.createClone(cloneId);
        TransactionAssert.commitTransaction();
  
        // Check the clone clone state
        TransactionAssert.beginTransaction();
        assertTrue(cloneCloneId.startsWith("_"));
        State cloneCloneState = stateStore.loadState(cloneCloneId.substring(1));
        assertNotNull(cloneCloneState);
        assertEquals(cloneCloneId, "_" + cloneCloneState.getId());
        assertEquals("SimplePortlet", cloneCloneState.getPortletId());
        ValueMap cloneCloneValues = cloneCloneState.getProperties();
        assertNotNull(cloneCloneValues);
        assertNotNull(cloneCloneValues.getKeys());
        assertEquals(1, cloneCloneValues.getKeys().size());
        assertEquals(new StringValue("fed"), cloneCloneValues.getValue("abc"));
        TransactionAssert.commitTransaction();
     }
  
     public void testDestroyNonExistingPortletWithinTx() throws Exception
     {
        try
        {
           TransactionAssert.beginTransaction();
           statefulPortletInvoker.destroyClone("_1");
           fail("Was expecting NoSuchPortletException");
        }
        catch (NoSuchPortletException e)
        {
           TransactionAssert.rollbackTransaction(true);
        }
     }
  
     public void testDestroyNullPortletWithinTx() throws Exception
     {
        try
        {
           TransactionAssert.beginTransaction();
           statefulPortletInvoker.destroyClone(null);
           fail("Was expecting an IllegalArgumentException");
        }
        catch (IllegalArgumentException expected)
        {
           TransactionAssert.rollbackTransaction(true);
        }
     }
  
  /*
     public void testDestroyInvalidPortletWithinTx() throws Exception
     {
        try
        {
           TransactionAssert.beginTransaction();
           statefulPortletInvoker.destroyClone("_invalid");
           fail("Was expecting an InvalidPortletIdException");
        }
        catch (InvalidPortletIdException expected)
        {
           TransactionAssert.rollbackTransaction(true);
        }
     }
  */
  
     public void testDestroyPortletWithinTx() throws Exception
     {
        // Clone a POP 2 times
        TransactionAssert.beginTransaction();
        String cloneId1 = statefulPortletInvoker.createClone("SimplePortlet");
        String cloneId2 = statefulPortletInvoker.createClone("SimplePortlet");
        TransactionAssert.commitTransaction();
  
        // Clone the modified CCP 2 times
        TransactionAssert.beginTransaction();
        String cloneCloneId1 = statefulPortletInvoker.createClone(cloneId1);
        String cloneCloneId2 = statefulPortletInvoker.createClone(cloneId1);
        TransactionAssert.commitTransaction();
  
        // Destroy the clone 2
        TransactionAssert.beginTransaction();
        statefulPortletInvoker.destroyClone(cloneId2);
        TransactionAssert.commitTransaction();
  
        // Destroy the clone of the clone 2
        TransactionAssert.beginTransaction();
        statefulPortletInvoker.destroyClone(cloneCloneId2);
        TransactionAssert.commitTransaction();
  
        // Destroy the clone 1
        TransactionAssert.beginTransaction();
        statefulPortletInvoker.destroyClone(cloneId1);
        TransactionAssert.commitTransaction();
  
        // Destroy the clone of the clone 1
        TransactionAssert.beginTransaction();
        statefulPortletInvoker.destroyClone(cloneCloneId1);
        TransactionAssert.commitTransaction();
     }
  
     public void testInvokeCloneBeforeWritePOPWithinTx() throws Exception
     {
        TransactionAssert.beginTransaction();
        PortletInvocation action = new ActionInvocation(new SimpleActionContext(Mode.VIEW));
        action.setAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE, "CloningPortlet");
        action.setUserContext(new SimpleUserContext("julien"));
        SimpleInstanceContext instanceContext = new SimpleInstanceContext("whatever", AccessMode.CLONE_BEFORE_WRITE);
        action.setInstanceContext(instanceContext);
        statefulPortletInvoker.invoke(action);
        TransactionAssert.commitTransaction();
  
        // Check state
        TransactionAssert.beginTransaction();
        String cloneId = instanceContext.getCloneId();
        assertNotNull(cloneId);
        State state = stateStore.loadState(cloneId.substring(1));
        assertNotNull(state);
        assertEquals(cloneId.substring(1), state.getId());
        assertEquals("CloningPortlet", state.getPortletId());
        SimpleValueMap expectedValue = new SimpleValueMap();
        expectedValue.setValue("abc", new StringValue("def"));
        expectedValue.setValue("_abc", new StringValue("_def"));
        ValueMapAssert.assertEquals(expectedValue, state.getProperties());
        TransactionAssert.commitTransaction();
     }
  
     public void testInvokeReadWritePOPWithinTx() throws Exception
     {
        TransactionAssert.beginTransaction();
        PortletInvocation action = new ActionInvocation(new SimpleActionContext(Mode.VIEW));
        action.setAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE, "CloneFailedCloningPortlet");
        action.setUserContext(new SimpleUserContext("julien"));
        SimpleInstanceContext instanceContext = new SimpleInstanceContext("whatever", AccessMode.READ_WRITE);
        action.setInstanceContext(instanceContext);
        statefulPortletInvoker.invoke(action);
        TransactionAssert.commitTransaction();
  
        // Check state
        TransactionAssert.beginTransaction();
        assertNull(instanceContext.getCloneId());
        TransactionAssert.commitTransaction();
     }
  
     public void testInvokeReadOnlyPOPWithinTx() throws Exception
     {
        TransactionAssert.beginTransaction();
        PortletInvocation action = new ActionInvocation(new SimpleActionContext(Mode.VIEW));
        action.setAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE, "CloneFailedCloningPortlet");
        action.setUserContext(new SimpleUserContext("julien"));
        SimpleInstanceContext instanceContext = new SimpleInstanceContext("whatever", AccessMode.READ_ONLY);
        action.setInstanceContext(instanceContext);
        statefulPortletInvoker.invoke(action);
        TransactionAssert.commitTransaction();
  
        // Check state
        TransactionAssert.beginTransaction();
        assertNull(instanceContext.getCloneId());
        TransactionAssert.commitTransaction();
     }
  
     public void testInvokeCloneBeforeWriteCCPWithinTx() throws Exception
     {
        TransactionAssert.beginTransaction();
        String cloningPortletId = statefulPortletInvoker.createClone("CloningPortlet");
        TransactionAssert.commitTransaction();
  
        // Modify the state of the CCP
        TransactionAssert.beginTransaction();
        State cloningPortletState = stateStore.loadState(cloningPortletId.substring(1));
        SimpleValueMap newCloningPortletStateValue = new SimpleValueMap(cloningPortletState.getProperties());
        newCloningPortletStateValue.setValue("abc", new StringValue("deff"));
        stateStore.updateState(cloningPortletId.substring(1), newCloningPortletStateValue);
        TransactionAssert.commitTransaction();
  
        //
        TransactionAssert.beginTransaction();
        PortletInvocation action = new ActionInvocation(new SimpleActionContext(Mode.VIEW));
        action.setAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE, cloningPortletId);
        action.setUserContext(new SimpleUserContext("julien"));
        SimpleInstanceContext instanceContext = new SimpleInstanceContext("whatever", AccessMode.CLONE_BEFORE_WRITE);
        action.setInstanceContext(instanceContext);
        statefulPortletInvoker.invoke(action);
        TransactionAssert.commitTransaction();
  
        // Check state
        TransactionAssert.beginTransaction();
        String cloneId = instanceContext.getCloneId();
        assertNotNull(cloneId);
        State state = stateStore.loadState(cloneId.substring(1));
        assertNotNull(state);
        assertEquals(cloneId.substring(1), state.getId());
        assertEquals("CloningPortlet", state.getPortletId());
        SimpleValueMap expectedValue = new SimpleValueMap();
        expectedValue.setValue("abc", new StringValue("deff"));
        expectedValue.setValue("_abc", new StringValue("_def"));
        ValueMapAssert.assertEquals(expectedValue, state.getProperties());
        TransactionAssert.commitTransaction();
     }
  
     public void testInvokeReadWriteCCPWithinTx() throws Exception
     {
        TransactionAssert.beginTransaction();
        String cloningPortletId = statefulPortletInvoker.createClone("CloningPortlet");
        TransactionAssert.commitTransaction();
  
        //
        TransactionAssert.beginTransaction();
        PortletInvocation action = new ActionInvocation(new SimpleActionContext(Mode.VIEW));
        action.setAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE, cloningPortletId);
        action.setUserContext(new SimpleUserContext("julien"));
        SimpleInstanceContext instanceContext = new SimpleInstanceContext("whatever", AccessMode.READ_WRITE);
        action.setInstanceContext(instanceContext);
        statefulPortletInvoker.invoke(action);
        TransactionAssert.commitTransaction();
  
        // Check state
        TransactionAssert.beginTransaction();
        assertNull(instanceContext.getCloneId());
        State state = stateStore.loadState(cloningPortletId.substring(1));
        assertNotNull(state);
        assertEquals("CloningPortlet", state.getPortletId());
        assertEquals(cloningPortletId.substring(1), state.getId());
        SimpleValueMap expectedValue = new SimpleValueMap();
        expectedValue.setValue("abc", new StringValue("def"));
        expectedValue.setValue("_abc", new StringValue("_def"));
        ValueMapAssert.assertEquals(expectedValue, state.getProperties());
        TransactionAssert.commitTransaction();
     }
  
     public void testInvokeReadOnlyCCPWithinTx() throws Exception
     {
        TransactionAssert.beginTransaction();
        String cloneFailedCloningPortletId = statefulPortletInvoker.createClone("CloneFailedCloningPortlet");
        TransactionAssert.commitTransaction();
  
        //
        TransactionAssert.beginTransaction();
        PortletInvocation action = new ActionInvocation(new SimpleActionContext(Mode.VIEW));
        action.setAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE, cloneFailedCloningPortletId);
        action.setUserContext(new SimpleUserContext("julien"));
        SimpleInstanceContext instanceContext = new SimpleInstanceContext("whatever", AccessMode.READ_ONLY);
        action.setInstanceContext(instanceContext);
        statefulPortletInvoker.invoke(action);
        TransactionAssert.commitTransaction();
  
        // Check state
        TransactionAssert.beginTransaction();
        assertNull(instanceContext.getCloneId());
        TransactionAssert.commitTransaction();
     }
  
     public void testInvokeCloneBeforeWritePOPWithinTxThrowsException() throws Exception
     {
        TransactionAssert.beginTransaction();
        PortletInvocation action = new ActionInvocation(new SimpleActionContext(Mode.VIEW));
        action.setAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE, "CloningPortletThrowingRuntimeException");
        action.setUserContext(new SimpleUserContext("julien"));
        SimpleInstanceContext instanceContext = new SimpleInstanceContext("whatever", AccessMode.CLONE_BEFORE_WRITE);
        action.setInstanceContext(instanceContext);
        try
        {
           statefulPortletInvoker.invoke(action);
           fail("Was expecting RuntimeException");
        }
        catch (RuntimeException expected)
        {
           assertEquals("custom_message", expected.getMessage());
           TransactionAssert.rollbackTransaction(true);
        }
  
        // Check state
        TransactionAssert.beginTransaction();
        assertNull(instanceContext.getCloneId());
        TransactionAssert.commitTransaction();
     }
  
     public void testGetProperties()
     {
  
     }
  
     public void testSetProperties()
     {
  
     }
  
     /**
      * todo : should check the portlet metadata as well
      */
     public void testGetPortlet() throws Exception
     {
        // Clone a POP
        TransactionAssert.beginTransaction();
        String cloneId = statefulPortletInvoker.createClone("SimplePortlet");
        TransactionAssert.commitTransaction();
  
        //
        TransactionAssert.beginTransaction();
        Portlet portlet = statefulPortletInvoker.getPortlet(cloneId);
        assertEquals("SimplePortlet", portlet.getId());
        TransactionAssert.commitTransaction();
  
        // Clone the modified CCP
        TransactionAssert.beginTransaction();
        String cloneCloneId = statefulPortletInvoker.createClone(cloneId);
        TransactionAssert.commitTransaction();
  
        //
        TransactionAssert.beginTransaction();
        portlet = statefulPortletInvoker.getPortlet(cloneCloneId);
        assertEquals("SimplePortlet", portlet.getId());
        TransactionAssert.commitTransaction();
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list