[jboss-cvs] jboss-portal/portlet/src/main/org/jboss/portal/test/portlet/state ...
Julien Viet
julien at jboss.com
Sun Jul 30 08:36:24 EDT 2006
User: julien
Date: 06/07/30 08:36:24
Added: portlet/src/main/org/jboss/portal/test/portlet/state
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:24; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/test/portlet/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.portlet.state;
import junit.framework.TestCase;
import org.jboss.portal.portlet.state.producer.StatefulPortletInvoker;
import org.jboss.portal.portlet.state.producer.State;
import org.jboss.portal.portlet.state.producer.NoSuchStateException;
import org.jboss.portal.portlet.NoSuchPortletException;
import org.jboss.portal.portlet.InvalidPortletIdException;
import org.jboss.portal.portlet.test.ValueMapAssert;
import org.jboss.portal.portlet.test.support.PortletInvokerSupport;
import org.jboss.portal.portlet.test.support.state.StateStoreSupport;
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;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class StatefulPortletInvokerTestCase extends TestCase
{
private StatefulPortletInvoker invoker;
private PortletInvokerSupport nextInvoker;
private StateStoreSupport stateStore;
protected void setUp() throws Exception
{
invoker = new StatefulPortletInvoker();
nextInvoker = new PortletInvokerSupport();
stateStore = new StateStoreSupport();
//
invoker.setPortletInvoker(nextInvoker);
invoker.setStateStore(stateStore);
}
protected void tearDown() throws Exception
{
invoker = null;
nextInvoker = null;
stateStore = null;
}
public void testCloneWithNullId() throws Exception
{
try
{
invoker.createClone(null);
fail("was expecting an IllegalArgumentException");
}
catch (IllegalArgumentException expected)
{
}
}
public void testCloneNonExistingPOP() throws Exception
{
String popId = invoker.wrapPOPId("NonExistingPortletId");
try
{
invoker.createClone(popId);
fail("was expecting an NoSuchPortletException");
}
catch (NoSuchPortletException expected)
{
}
}
public void testCloneNonExistingCCP() throws Exception
{
String ccpId = invoker.wrapCCPId("1");
try
{
invoker.createClone(ccpId);
fail("was expecting an NoSuchPortletException");
}
catch (NoSuchPortletException expected)
{
}
}
public void testCloneInvalidCCP() throws Exception
{
String ccpId = invoker.wrapCCPId("InvalidPortletId");
try
{
invoker.createClone(ccpId);
fail("was expecting an InvalidPortletIdException");
}
catch (InvalidPortletIdException expected)
{
}
}
public void testCloneInvalidPOP() throws Exception
{
nextInvoker.addInvalidPortlet("InvalidPortletId");
String popId = invoker.wrapPOPId("InvalidPortletId");
try
{
invoker.createClone(popId);
fail("was expecting an InvalidPortletIdException");
}
catch (InvalidPortletIdException expected)
{
}
}
public void testClonePortlet() throws Exception
{
nextInvoker.addPortlet(new PortletSupport("PortletId")
{
{
info.getPreferencesSupport().addPreference("abc", new StringValue("def"));
}
});
String popCloneId = invoker.createClone(invoker.wrapPOPId("PortletId"));
// Check state
assertNotNull(popCloneId);
String popCloneStateId = invoker.unwrapCCPId(popCloneId);
State popCloneState = stateStore.loadState(popCloneStateId);
assertNotNull(popCloneState);
assertEquals("PortletId", popCloneState.getPortletId());
ValueMap expected = new SimpleValueMap();
expected.setValue("abc", new StringValue("def"));
ValueMapAssert.assertEquals(expected, popCloneState.getProperties());
// Update state
ValueMap next = new SimpleValueMap();
next.setValue("ghi", new StringValue("jkl"));
stateStore.updateState(popCloneStateId, next);
// Clone a CCP
String ccpCloneId = invoker.createClone(popCloneId);
// Check state
assertNotNull(ccpCloneId);
String ccpCloneStateId = invoker.unwrapCCPId(ccpCloneId);
State ccpCloneState = stateStore.loadState(ccpCloneStateId);
assertNotNull(popCloneState);
assertEquals("PortletId", popCloneState.getPortletId());
expected = new SimpleValueMap();
expected.setValue("ghi", new StringValue("jkl"));
ValueMapAssert.assertEquals(expected, ccpCloneState.getProperties());
}
public void testGetWithNullId() throws Exception
{
try
{
invoker.getPortlet(null);
fail("was expecting an IllegalArgumentException");
}
catch (IllegalArgumentException expected)
{
}
}
public void testGetNonExistingPOP() throws Exception
{
String popId = invoker.wrapPOPId("NonExistingPortletId");
assertNull(invoker.getPortlet(popId));
}
public void testGetNonExistingCCP() throws Exception
{
String ccpId = invoker.wrapCCPId("1");
assertNull(invoker.getPortlet(ccpId));
}
public void testGetInvalidPOP() throws Exception
{
nextInvoker.addInvalidPortlet("InvalidPortletId");
String popId = invoker.wrapPOPId("InvalidPortletId");
try
{
assertNull(invoker.getPortlet(popId));
fail("was expecting an InvalidPortletIdException");
}
catch (InvalidPortletIdException expected)
{
}
}
public void testGetInvalidCCP() throws Exception
{
String ccpId = invoker.wrapCCPId("InvalidPortletId");
try
{
assertNull(invoker.getPortlet(ccpId));
fail("was expecting an InvalidPortletIdException");
}
catch (InvalidPortletIdException expected)
{
}
}
public void testDestroyWithNullId() throws Exception
{
try
{
invoker.destroyClone(null);
fail("was expecting an IllegalArgumentException");
}
catch (IllegalArgumentException expected)
{
}
}
public void testDestroyPOP() throws Exception
{
nextInvoker.addPortlet(new PortletSupport("PortletId"));
String popId = invoker.wrapPOPId("PortletId");
try
{
invoker.destroyClone(popId);
fail("was expecting an IllegalArgumentException");
}
catch (InvalidPortletIdException expected)
{
}
}
public void testDestroyCCP() throws Exception
{
nextInvoker.addPortlet(new PortletSupport("PortletId"));
String stateId = stateStore.createState("PortletId", new SimpleValueMap());
String cloneId = invoker.wrapCCPId(stateId);
invoker.destroyClone(cloneId);
try
{
stateStore.loadState(stateId);
fail("Was expecting NoSuchStateException");
}
catch (NoSuchStateException e)
{
}
}
public void testDestroyInvalidCCP() throws Exception
{
String ccpId = invoker.wrapCCPId("PortletId");
try
{
invoker.destroyClone(ccpId);
fail("was expecting a InvalidPortletIdException");
}
catch (InvalidPortletIdException expected)
{
}
}
public void testDestroyNonExistingCCP() throws Exception
{
String ccpId = invoker.wrapCCPId("1");
try
{
invoker.destroyClone(ccpId);
fail("was expecting a NoSuchPortletException");
}
catch (NoSuchPortletException expected)
{
}
}
public void testGetPropertiesWithNullPortlet() throws Exception
{
try
{
invoker.getProperties(null);
fail("was expecting an IllegalArgumentException");
}
catch (IllegalArgumentException e)
{
}
}
public void testGetNonExistingPOPProperties() throws Exception
{
String popId = invoker.wrapPOPId("NonExistingPortletId");
try
{
invoker.getProperties(popId);
fail("was expecting a NoSuchPortletException");
}
catch (NoSuchPortletException e)
{
}
}
public void testGetInvalidPOPProperties() throws Exception
{
nextInvoker.addInvalidPortlet("InvalidPortletId");
String popId = invoker.wrapPOPId("InvalidPortletId");
try
{
invoker.getProperties(popId);
fail("was expecting an InvalidPortletIdException");
}
catch (InvalidPortletIdException e)
{
}
}
public void testGetNonExistingCCPProperties() throws Exception
{
String ccpId = invoker.wrapCCPId("1");
try
{
invoker.getProperties(ccpId);
fail("was expecting a NoSuchPortletException");
}
catch (NoSuchPortletException e)
{
}
}
public void testGetInvalidCCPProperties() throws Exception
{
String ccpId = invoker.wrapCCPId("InvalidPortletId");
try
{
invoker.getProperties(ccpId);
fail("was expecting a nInvalidPortletIdException");
}
catch (InvalidPortletIdException e)
{
}
}
public void testGetPOPProperties() throws Exception
{
nextInvoker.addPortlet(new PortletSupport("PortletId")
{
{
info.getPreferencesSupport().addPreference("abc", new StringValue("def"));
info.getPreferencesSupport().addPreference("ghi", new StringValue("jkl"), Boolean.TRUE);
}
});
String popId = invoker.wrapPOPId("PortletId");
ValueMap props = invoker.getProperties(popId);
ValueMap expectedProps = new SimpleValueMap();
expectedProps.setValue("abc", new StringValue("def"));
expectedProps.setValue("ghi", new StringValue("jkl"));
ValueMapAssert.assertEquals(expectedProps, props);
}
public void testGetCCPProperties() throws Exception
{
nextInvoker.addPortlet(new PortletSupport("PortletId")
{
{
info.getPreferencesSupport().addPreference("abc", new StringValue("def"));
info.getPreferencesSupport().addPreference("ghi", new StringValue("jkl"));
info.getPreferencesSupport().addPreference("mno", new StringValue("pqr"), Boolean.TRUE);
info.getPreferencesSupport().addPreference("stu", new StringValue("vwx"), Boolean.TRUE);
}
});
ValueMap ccpProps = new SimpleValueMap();
ccpProps.setValue("abc", new StringValue("_def"));
ccpProps.setValue("mno", new StringValue("_pqr"));
String stateId = stateStore.createState("PortletId", ccpProps);
String ccpId = invoker.wrapCCPId(stateId);
ValueMap props = invoker.getProperties(ccpId);
ValueMap expectedProps = new SimpleValueMap();
expectedProps.setValue("abc", new StringValue("_def"));
expectedProps.setValue("ghi", new StringValue("jkl"));
expectedProps.setValue("mno", new StringValue("pqr"));
expectedProps.setValue("stu", new StringValue("vwx"));
ValueMapAssert.assertEquals(expectedProps, props);
}
public void testSetPropertiesWithNullId() throws Exception
{
try
{
invoker.setProperties(null, new SimpleValueMap());
fail("Was expecting an IllegalArgumentException");
}
catch (IllegalArgumentException expected)
{
}
}
public void testSetPropertiesWithNullProperties() throws Exception
{
String ccpId = invoker.wrapCCPId("1");
try
{
invoker.setProperties(ccpId, null);
fail("Was expecting an IllegalArgumentException");
}
catch (IllegalArgumentException expected)
{
}
}
public void testSetPOPProperties() throws Exception
{
nextInvoker.addPortlet(new PortletSupport("PortletId"));
String popId = invoker.wrapPOPId("PortletId");
try
{
invoker.setProperties(popId, new SimpleValueMap());
fail("Was expecting an InvalidPortletIdException");
}
catch (InvalidPortletIdException expected)
{
}
}
public void testSetNonExistingCCPProperties() throws Exception
{
String ccpId = invoker.wrapCCPId("1");
try
{
invoker.setProperties(ccpId, new SimpleValueMap());
fail("Was expecting a NoSuchPortletException");
}
catch (NoSuchPortletException expected)
{
}
}
public void testSetCCPProperties() throws Exception
{
String stateId = stateStore.createState("PortletId", new SimpleValueMap());
nextInvoker.addPortlet(new PortletSupport("PortletId")
{
{
info.getPreferencesSupport().addPreference("abc", new StringValue("def"));
info.getPreferencesSupport().addPreference("ghi", new StringValue("jkl"));
info.getPreferencesSupport().addPreference("mno", new StringValue("pqr"), Boolean.TRUE);
info.getPreferencesSupport().addPreference("stu", new StringValue("vwx"), Boolean.TRUE);
}
});
String ccpId = invoker.wrapCCPId(stateId);
SimpleValueMap newProperties = new SimpleValueMap();
newProperties.setValue("abc", new StringValue("def"));
newProperties.setValue("ghi", new StringValue("_jkl"));
newProperties.setValue("mno", new StringValue("pqr"));
newProperties.setValue("stu", new StringValue("_vwx"));
invoker.setProperties(ccpId, newProperties);
State state = stateStore.loadState(stateId);
ValueMap props = state.getProperties();
ValueMap expectedProps = new SimpleValueMap();
expectedProps.setValue("abc", new StringValue("def"));
expectedProps.setValue("ghi", new StringValue("_jkl"));
ValueMapAssert.assertEquals(expectedProps, props);
}
public void testInvokeReadOnly() throws Exception
{
}
}
More information about the jboss-cvs-commits
mailing list