Author: julien(a)jboss.com
Date: 2007-02-12 12:54:14 -0500 (Mon, 12 Feb 2007)
New Revision: 6223
Modified:
trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java
Log:
more registration / state integration test
Modified: trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java 2007-02-12
17:52:07 UTC (rev 6222)
+++ trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java 2007-02-12
17:54:14 UTC (rev 6223)
@@ -29,14 +29,12 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
-import org.hibernate.Session;
import org.jboss.portal.Mode;
import org.jboss.portal.common.junit.TransactionAssert;
import org.jboss.portal.common.test.TestParametrization;
import org.jboss.portal.common.test.junit.JUnitAdapter;
import org.jboss.portal.common.test.junit.POJOJUnitTest;
import org.jboss.portal.common.value.StringValue;
-import org.jboss.portal.core.impl.portlet.state.PersistentConsumer;
import org.jboss.portal.core.impl.portlet.state.PersistentRegistration;
import
org.jboss.portal.core.impl.portlet.state.PersistentPortletStatePersistenceManager;
import org.jboss.portal.core.impl.portlet.state.ProducerPortletInvoker;
@@ -64,7 +62,6 @@
import org.jboss.portal.portlet.test.ValueMapAssert;
import org.jboss.portal.portlet.test.support.PortletInvokerSupport;
import org.jboss.portal.portlet.test.support.PortletSupport;
-import org.jboss.portal.registration.RegistrationStatus;
import org.jboss.portal.registration.RegistrationLocal;
import org.jboss.portal.registration.ConsumerGroup;
import org.jboss.portal.registration.Consumer;
@@ -421,7 +418,7 @@
{
try
{
- beginTX();
+ beginRegistrationScopedTX();
consumer.createClone(null);
fail("Was expecting an IllegalArgumentException");
}
@@ -433,7 +430,7 @@
public void testDestroyNonExistingPortletWithinTx() throws Exception
{
- beginTX();
+ beginRegistrationScopedTX();
List failures =
consumer.destroyClones(Collections.singletonList(PortletContext.createPortletContext("_1")));
assertEquals(Collections.singletonList(new DestroyCloneFailure("_1")),
failures);
commitTX();
@@ -443,7 +440,7 @@
{
try
{
- beginTX();
+ beginRegistrationScopedTX();
consumer.destroyClones(null);
fail("Was expecting an IllegalArgumentException");
}
@@ -473,44 +470,44 @@
{
// Clone a POP 2 times
beginTX();
- PortletContext cloneId1 =
consumer.createClone(PortletContext.createPortletContext("SimplePortlet"));
- PortletContext cloneId2 =
consumer.createClone(PortletContext.createPortletContext("SimplePortlet"));
+ PortletContext clone1 =
consumer.createClone(PortletContext.createPortletContext("SimplePortlet"));
+ PortletContext clone2 =
consumer.createClone(PortletContext.createPortletContext("SimplePortlet"));
commitTX();
// Clone the modified CCP 2 times
beginTX();
- PortletContext cloneCloneId1 = consumer.createClone(cloneId1);
- PortletContext cloneCloneId2 = consumer.createClone(cloneId1);
+ PortletContext cloneOfClone1 = consumer.createClone(clone1);
+ PortletContext cloneOfClone2 = consumer.createClone(clone1);
commitTX();
// Destroy the clone 2
beginTX();
- List failures = consumer.destroyClones(Collections.singletonList(cloneId2));
+ List failures = consumer.destroyClones(Collections.singletonList(clone2));
assertEquals(Collections.EMPTY_LIST, failures);
commitTX();
// Destroy the clone of the clone 2
beginTX();
- failures = consumer.destroyClones(Collections.singletonList(cloneCloneId2));
+ failures = consumer.destroyClones(Collections.singletonList(cloneOfClone2));
assertEquals(Collections.EMPTY_LIST, failures);
commitTX();
// Destroy the clone 1
beginTX();
- failures = consumer.destroyClones(Collections.singletonList(cloneId1));
+ failures = consumer.destroyClones(Collections.singletonList(clone1));
assertEquals(Collections.EMPTY_LIST, failures);
commitTX();
// Destroy the clone of the clone 1
beginTX();
- failures = consumer.destroyClones(Collections.singletonList(cloneCloneId1));
+ failures = consumer.destroyClones(Collections.singletonList(cloneOfClone1));
assertEquals(Collections.EMPTY_LIST, failures);
commitTX();
}
public void testInvokeCloneBeforeWritePOPWithinTx() throws Exception
{
- beginTX();
+ beginRegistrationScopedTX();
PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
action.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE,
PortletContext.createPortletContext("CloningPortlet"));
action.setUserContext(new UserContextImpl("julien"));
@@ -521,24 +518,32 @@
// Check state
beginTX();
- PortletContext cloneId = instanceContext.getClonedContext();
- assertNotNull(cloneId);
- PortletStateContext state =
persistenceManager.loadState(cloneId.getId().substring(1));
- assertNotNull(state);
- assertEquals(cloneId.getId().substring(1), state.getId());
- assertEquals("CloningPortlet", state.getState().getPortletId());
+ PortletContext clone = instanceContext.getClonedContext();
+ assertNotNull(clone);
+ PersistentPortletState cloneState =
(PersistentPortletState)persistenceManager.loadState(clone.getId().substring(1));
+ assertNotNull(cloneState);
+ assertEquals(clone.getId().substring(1), cloneState.getId());
+ assertEquals("CloningPortlet", cloneState.getState().getPortletId());
SimplePropertyMap expectedValue = new SimplePropertyMap();
expectedValue.setProperty("abc", new StringValue("def"));
expectedValue.setProperty("_abc", new StringValue("_def"));
- ValueMapAssert.assertEquals(expectedValue, state.getState().getProperties());
+ ValueMapAssert.assertEquals(expectedValue, cloneState.getState().getProperties());
+ if (useRegistration)
+ {
+ PersistentRegistration registration = cloneState.getRelatedRegistration();
+ assertNotNull(registration);
+ assertEquals(registrationId, registration.getId());
+ }
commitTX();
}
public void testInvokeReadWritePOPWithinTx() throws Exception
{
- beginTX();
+ beginRegistrationScopedTX();
PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
- action.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE,
+ action.setAttribute(
+ PortletInvocation.REQUEST_SCOPE,
+ PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE,
PortletContext.createPortletContext("CloneFailedCloningPortlet"));
action.setUserContext(new UserContextImpl("julien"));
InstanceContextImpl instanceContext = new InstanceContextImpl("whatever",
AccessMode.READ_WRITE);
@@ -549,12 +554,13 @@
// Check state
beginTX();
assertNull(instanceContext.getClonedContext());
+ assertNull(instanceContext.getModifiedContext());
commitTX();
}
public void testInvokeReadOnlyPOPWithinTx() throws Exception
{
- beginTX();
+ beginRegistrationScopedTX();
PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
action.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE,
PortletContext.createPortletContext("CloneFailedCloningPortlet"));
@@ -567,6 +573,7 @@
// Check state
beginTX();
assertNull(instanceContext.getClonedContext());
+ assertNull(instanceContext.getModifiedContext());
commitTX();
}
@@ -585,7 +592,7 @@
commitTX();
//
- beginTX();
+ beginRegistrationScopedTX();
PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
action.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, cloningPortletId);
action.setUserContext(new UserContextImpl("julien"));
@@ -596,16 +603,22 @@
// Check state
beginTX();
- PortletContext cloneId = instanceContext.getClonedContext();
- assertNotNull(cloneId);
- PortletStateContext state =
persistenceManager.loadState(cloneId.getId().substring(1));
- assertNotNull(state);
- assertEquals(cloneId.getId().substring(1), state.getId());
- assertEquals("CloningPortlet", state.getState().getPortletId());
+ PortletContext clone = instanceContext.getClonedContext();
+ assertNotNull(clone);
+ PersistentPortletState cloneState =
(PersistentPortletState)persistenceManager.loadState(clone.getId().substring(1));
+ assertNotNull(cloneState);
+ assertEquals(clone.getId().substring(1), cloneState.getId());
+ assertEquals("CloningPortlet", cloneState.getState().getPortletId());
SimplePropertyMap expectedValue = new SimplePropertyMap();
expectedValue.setProperty("abc", new StringValue("deff"));
expectedValue.setProperty("_abc", new StringValue("_def"));
- ValueMapAssert.assertEquals(expectedValue, state.getState().getProperties());
+ ValueMapAssert.assertEquals(expectedValue, cloneState.getState().getProperties());
+ if (useRegistration)
+ {
+ PersistentRegistration registration = cloneState.getRelatedRegistration();
+ assertNotNull(registration);
+ assertEquals(registrationId, registration.getId());
+ }
commitTX();
}
@@ -616,7 +629,7 @@
commitTX();
//
- beginTX();
+ beginRegistrationScopedTX();
PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
action.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, cloningPortletId);
action.setUserContext(new UserContextImpl("julien"));
@@ -646,7 +659,7 @@
commitTX();
//
- beginTX();
+ beginRegistrationScopedTX();
PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
action.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, cloneFailedCloningPortletId);
action.setUserContext(new UserContextImpl("julien"));
@@ -663,7 +676,7 @@
public void testInvokeCloneBeforeWritePOPWithinTxThrowsException() throws Exception
{
- beginTX();
+ beginRegistrationScopedTX();
PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
action.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE,
PortletContext.createPortletContext("CloningPortletThrowingRuntimeException"));