Author: chris.laprun(a)jboss.com
Date: 2006-12-04 18:06:50 -0500 (Mon, 04 Dec 2006)
New Revision: 5759
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java
Log:
- Cleaned-up NeedPortletHandleTest and adapted inheriting tests.
- Need to figure out what can be tested in ReleaseSessionTestCase since not much can be
based on our implementation.
Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java 2006-12-04
23:03:50 UTC (rev 5758)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java 2006-12-04
23:06:50 UTC (rev 5759)
@@ -29,7 +29,6 @@
import org.jboss.portal.wsrp.WSRPPortletURL;
import org.jboss.portal.wsrp.WSRPRenderURL;
import org.jboss.portal.wsrp.WSRPTypeFactory;
-import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
import org.jboss.portal.wsrp.core.CacheControl;
import org.jboss.portal.wsrp.core.GetMarkup;
@@ -42,7 +41,6 @@
import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
import org.jboss.portal.wsrp.core.UnsupportedModeFault;
import org.jboss.portal.wsrp.core.UpdateResponse;
-import org.jboss.portal.wsrp.handler.RequestHeaderClientHandler;
import java.rmi.RemoteException;
@@ -108,7 +106,7 @@
String archiveName = "test-renderparam-portlet.war";
deploy(archiveName);
- GetMarkup gm = createMarkupRequest(archiveName);
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
MarkupResponse res = markupService.getMarkup(gm);
String markupString = res.getMarkupContext().getMarkupString();
@@ -135,7 +133,7 @@
// let's see now if we can increment the counter
PerformBlockingInteraction performBlockingInteraction =
-
WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForPortletDeployedIn(archiveName));
+
WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
InteractionParams interactionParams =
performBlockingInteraction.getInteractionParams();
interactionParams.setInteractionState(incrementAction.getInteractionState().getStringValue());
markupService.performBlockingInteraction(performBlockingInteraction);
@@ -161,7 +159,7 @@
String sessionPortletArchive = "test-session-portlet.war";
deploy(sessionPortletArchive);
- GetMarkup getMarkup = createMarkupRequest(sessionPortletArchive);
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
MarkupResponse response = markupService.getMarkup(getMarkup);
@@ -240,7 +238,7 @@
String sessionPortletArchive = "test-session-portlet.war";
deploy(sessionPortletArchive);
- response = markupService.getMarkup(createMarkupRequest(sessionPortletArchive));
+ response =
markupService.getMarkup(createMarkupRequestForCurrentlyDeployedPortlet());
cacheControl = response.getMarkupContext().getCacheControl();
ExtendedAssert.assertNull(cacheControl);
@@ -299,7 +297,7 @@
String dispatcherPortletArchive = "test-dispatcher-portlet.war";
deploy(dispatcherPortletArchive);
- GetMarkup getMarkup = createMarkupRequest(dispatcherPortletArchive);
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
MarkupResponse response = markupService.getMarkup(getMarkup);
checkMarkupResponse(response, "test");
@@ -313,7 +311,7 @@
String basicPortletArchive = "test-basic-portlet.war";
deploy(basicPortletArchive);
- GetMarkup getMarkup = createMarkupRequest(basicPortletArchive);
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
MarkupResponse response = markupService.getMarkup(getMarkup);
checkMarkupResponse(response, "");
@@ -327,7 +325,7 @@
String getLocalesPortletArchive = "test-getlocales-portlet.war";
deploy(getLocalesPortletArchive);
- GetMarkup getMarkup = createMarkupRequest(getLocalesPortletArchive);
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
getMarkup.getMarkupParams().setLocales(new String[]{"en_US"});
MarkupResponse response = null;
@@ -352,7 +350,7 @@
String encodeURLPortletArchive = "test-encodeurl-portlet.war";
deploy(encodeURLPortletArchive);
- GetMarkup getMarkup = createMarkupRequest(encodeURLPortletArchive);
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
MarkupResponse response = markupService.getMarkup(getMarkup);
checkMarkupResponse(response,
"wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite\n"
+
@@ -367,7 +365,7 @@
String userContextPortletArchive = "test-usercontext-portlet.war";
deploy(userContextPortletArchive);
- GetMarkup getMarkup = createMarkupRequest(userContextPortletArchive);
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
getMarkup.setUserContext(WSRPTypeFactory.createUserContext("johndoe"));
MarkupResponse response = markupService.getMarkup(getMarkup);
@@ -386,7 +384,7 @@
WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
action.getInteractionParams().setFormParameters(new NamedString[]{new
NamedString("multi", "value1")});
BlockingInteractionResponse actionResponse =
markupService.performBlockingInteraction(action);
- GetMarkup markupRequest = createMarkupRequest(multiValuedPortletArchive);
+ GetMarkup markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
MarkupResponse response = markupService.getMarkup(markupRequest);
checkMarkupResponse(response, "multi: value1");
@@ -394,14 +392,14 @@
action.getInteractionParams().setFormParameters(new NamedString[]{
new NamedString("multi", "value1"), new
NamedString("multi", "value2")});
actionResponse = markupService.performBlockingInteraction(action);
- markupRequest = createMarkupRequest(multiValuedPortletArchive);
+ markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
response = markupService.getMarkup(markupRequest);
checkMarkupResponse(response, "multi: value1, value2");
action.getInteractionParams().setFormParameters(new NamedString[]{});
actionResponse = markupService.performBlockingInteraction(action);
- markupRequest = createMarkupRequest(multiValuedPortletArchive);
+ markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
response = markupService.getMarkup(markupRequest);
checkMarkupResponse(response, "multi: ");
@@ -449,9 +447,7 @@
"&wsrp-navigationalState=JBPNS_/wsrp_rewrite\">render</a></div>",
markupContext.getMarkupString());
// checking session
- ProducerSessionInformation sessionInfo =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
- ExtendedAssert.assertNotNull(sessionInfo);
-
ExtendedAssert.assertTrue(sessionInfo.getUserCookie().lastIndexOf("JSESSIONID")
!= -1);
+ checkSessionForCurrentlyDeployedPortlet(response);
}
private MarkupContext checkMarkupResponse(MarkupResponse response, String
markupString)
@@ -469,22 +465,8 @@
return markupContext;
}
- /**
- * Creates a valid Markup request.
- *
- * @param archiveName
- * @return a basic, valid GetMarkup object representing the markup request
- */
- private GetMarkup createMarkupRequest(String archiveName) throws Exception
+ protected String getMostUsedPortletWARFileName()
{
- GetMarkup getMarkup =
WSRPTypeFactory.createDefaultMarkupRequest(getHandleForPortletDeployedIn(archiveName));
- getMarkup.getMarkupParams().setMarkupCharacterSets(new
String[]{WSRPConstants.DEFAULT_CHARACTER_SET});
-
- return getMarkup;
+ return DEFAULT_MARKUP_PORTLET_WAR;
}
-
- private GetMarkup createMarkupRequest() throws Exception
- {
- return createMarkupRequest(null);
- }
}
\ No newline at end of file
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java 2006-12-04
23:03:50 UTC (rev 5758)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java 2006-12-04
23:06:50 UTC (rev 5759)
@@ -23,16 +23,21 @@
package org.jboss.portal.test.wsrp.v1.producer;
+import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
+import org.jboss.portal.wsrp.core.GetMarkup;
import org.jboss.portal.wsrp.core.GetServiceDescription;
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.MarkupResponse;
import org.jboss.portal.wsrp.core.OperationFailedFault;
import org.jboss.portal.wsrp.core.PortletDescription;
import org.jboss.portal.wsrp.core.ServiceDescription;
+import org.jboss.portal.wsrp.handler.RequestHeaderClientHandler;
import java.rmi.RemoteException;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -42,44 +47,33 @@
*/
public abstract class NeedPortletHandleTest extends V1ProducerBaseTest
{
- private String portletWARFileName;
- private Map warFileName2handle = new HashMap();
+ private String mostUsedPortletWARFileName;
private String currentlyDeployedArchiveName;
+ private Map war2Handle = new HashMap(7);
+
public NeedPortletHandleTest(String portletWARFileName)
throws Exception
{
this("NeedPortletHandleTest", portletWARFileName);
- this.portletWARFileName = portletWARFileName;
+ this.mostUsedPortletWARFileName = portletWARFileName;
}
protected NeedPortletHandleTest(String name, String portletWARFileName)
throws Exception
{
super(name);
- this.portletWARFileName = portletWARFileName;
+ this.mostUsedPortletWARFileName = portletWARFileName;
}
- protected String getHandleForPortletDeployedIn(String archiveName)
- throws org.jboss.portal.wsrp.core.OperationFailedFault,
org.jboss.portal.wsrp.core.InvalidRegistrationFault, java.rmi.RemoteException
- {
-// printMappings("getHandleForPortletDeployedIn");
- if (archiveName == null)
- {
- archiveName = portletWARFileName;
- }
-
- return (String)warFileName2handle.get(archiveName);
- }
-
protected String getDefaultHandle() throws RemoteException, InvalidRegistrationFault,
OperationFailedFault
{
- return getHandleForPortletDeployedIn(null);
+ return (String)war2Handle.get(mostUsedPortletWARFileName);
}
protected String getHandleForCurrentlyDeployedArchive() throws RemoteException,
InvalidRegistrationFault, OperationFailedFault
{
- return getHandleForPortletDeployedIn(currentlyDeployedArchiveName);
+ return (String)war2Handle.get(currentlyDeployedArchiveName);
}
/**
@@ -93,32 +87,25 @@
{
super.deploy(archiveName);
currentlyDeployedArchiveName = archiveName;
- GetServiceDescription getServiceDescription =
WSRPTypeFactory.createGetServiceDescription();
- ServiceDescription serviceDescription =
serviceDescriptionService.getServiceDescription(getServiceDescription);
- PortletDescription[] offered = serviceDescription.getOfferedPortlets();
- for (int i = 0; i < offered.length; i++)
+
+ if (!war2Handle.containsKey(archiveName))
{
- PortletDescription portletDescription = offered[i];
- String handle = portletDescription.getPortletHandle();
- if (!warFileName2handle.containsKey(archiveName))
+ GetServiceDescription getServiceDescription =
WSRPTypeFactory.createGetServiceDescription();
+ ServiceDescription serviceDescription =
serviceDescriptionService.getServiceDescription(getServiceDescription);
+ PortletDescription[] offered = serviceDescription.getOfferedPortlets();
+ for (int i = 0; i < offered.length; i++)
{
- warFileName2handle.put(archiveName, handle);
+ PortletDescription portletDescription = offered[i];
+ String handle = portletDescription.getPortletHandle();
+ String warName = handle.substring(1, handle.indexOf('.')) +
".war";
+ if (warName.equals(archiveName))
+ {
+ war2Handle.put(warName, handle);
+ }
}
}
-// printMappings("deploy");
}
- private void printMappings(String when)
- {
- System.out.println("when = " + when);
- for (Iterator iterator = warFileName2handle.entrySet().iterator();
iterator.hasNext();)
- {
- Map.Entry entry = (Map.Entry)iterator.next();
- System.out.println("archive = " + entry.getKey() + " | handle =
" + entry.getValue());
- }
- System.out.println("----");
- }
-
protected void undeploy(String archiveName) throws Exception
{
try
@@ -132,23 +119,63 @@
return;
}
- if (warFileName2handle.containsKey(archiveName))
+ currentlyDeployedArchiveName = null;
+
+ // only remove the mapping if we're not undeploying the most used portlet
(optimization, as it avoids parsing the SD)
+ if (!mostUsedPortletWARFileName.equals(archiveName))
{
- warFileName2handle.remove(archiveName);
+ war2Handle.remove(archiveName);
}
- currentlyDeployedArchiveName = null;
-// printMappings("undeploy");
}
public void setUp() throws Exception
{
super.setUp();
- deploy(portletWARFileName);
+ this.mostUsedPortletWARFileName = getMostUsedPortletWARFileName();
+ deploy(mostUsedPortletWARFileName);
}
+ /**
+ * Sub-classes need to implement this method to return the local WAR file name of the
portlet being deployed most of
+ * the time in the context of the test case. This is required since we cannot rely on
the name to be properly set at
+ * all time via the constructor.
+ *
+ * @return
+ */
+ protected abstract String getMostUsedPortletWARFileName();
+
public void tearDown() throws Exception
{
- undeploy(portletWARFileName);
+ undeploy(mostUsedPortletWARFileName);
super.tearDown();
}
+
+ /**
+ * Creates a valid Markup request.
+ *
+ * @return a basic, valid GetMarkup object representing the markup request
+ */
+ protected GetMarkup createMarkupRequestForCurrentlyDeployedPortlet() throws Exception
+ {
+ GetMarkup getMarkup =
WSRPTypeFactory.createDefaultMarkupRequest(getHandleForCurrentlyDeployedArchive());
+ getMarkup.getMarkupParams().setMarkupCharacterSets(new
String[]{WSRPConstants.DEFAULT_CHARACTER_SET});
+
+ return getMarkup;
+ }
+
+ protected GetMarkup createMarkupRequest() throws Exception
+ {
+ return createMarkupRequestForCurrentlyDeployedPortlet();
+ }
+
+ protected void checkSessionForCurrentlyDeployedPortlet(MarkupResponse response)
+ throws RemoteException, InvalidRegistrationFault, OperationFailedFault
+ {
+ // We don't send any portlet session information, just user cookies... The
producer takes care of the details
+ // What this means, though is that we don't have access to individual portlet
session ids... so we can only
+ // check that we get a cookie... Not very test-friendly...
+ ProducerSessionInformation sessionInfo =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ ExtendedAssert.assertNotNull(sessionInfo);
+
ExtendedAssert.assertTrue(sessionInfo.getUserCookie().lastIndexOf("JSESSIONID")
!= -1);
+ }
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java 2006-12-04
23:03:50 UTC (rev 5758)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java 2006-12-04
23:06:50 UTC (rev 5759)
@@ -41,10 +41,12 @@
*/
public class PortletManagementTestCase extends NeedPortletHandleTest
{
+ private static final String TEST_BASIC_PORTLET_WAR =
"test-basic-portlet.war";
+
public PortletManagementTestCase()
throws Exception
{
- super("PortletManagementTestCase", "test-basic-portlet.war");
+ super("PortletManagementTestCase", TEST_BASIC_PORTLET_WAR);
}
public void testClonePortlet()
@@ -109,6 +111,11 @@
// todo: implement
}
+ protected String getMostUsedPortletWARFileName()
+ {
+ return TEST_BASIC_PORTLET_WAR;
+ }
+
private static class PropertyDecorator implements Decorator
{
private Property prop;
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java 2006-12-04
23:03:50 UTC (rev 5758)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java 2006-12-04
23:06:50 UTC (rev 5759)
@@ -27,13 +27,17 @@
import org.jboss.portal.common.junit.ExtendedAssert;
import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
+import org.jboss.portal.wsrp.core.GetMarkup;
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.MarkupResponse;
import org.jboss.portal.wsrp.core.MissingParametersFault;
import org.jboss.portal.wsrp.core.OperationFailedFault;
import org.jboss.portal.wsrp.core.RegistrationContext;
import org.jboss.portal.wsrp.core.ReleaseSessions;
import org.jboss.portal.wsrp.handler.RequestHeaderClientHandler;
+import java.rmi.RemoteException;
+
/**
* Tests the behavior of the ReleaseSession method.
*
@@ -47,10 +51,22 @@
Logger log = Logger.getLogger(ReleaseSessionTestCase.class);
+ public void tearDown() throws Exception
+ {
+ producer.getProducerRegistrationRequirements().clearRegistrationProperties();
+ producer.getRegistrationManager().clear();
+ super.tearDown();
+ }
+
+
+ protected String getMostUsedPortletWARFileName()
+ {
+ return DEFAULT_SESSION_PORTLET_WAR;
+ }
+
public ReleaseSessionTestCase() throws Exception
{
super("SessionWar", DEFAULT_SESSION_PORTLET_WAR);
- //super("SessionWar");
log.debug("Instantiating ReleaseSessionTestCase");
}
@@ -62,15 +78,19 @@
Class exceptionClass = InvalidRegistrationFault.class;
String message = "A null RegistrationContext when a registration is required
should produce an InvalidRegistrationFault";
- releaseSessionsWithRegistration(regContext, getSessionIDs(), exceptionClass,
message);
+ releaseSessionsWithRegistration(regContext, null, exceptionClass, message);
}
public void testNullRegistrationContext() throws Exception
{
RegistrationContext regContext = null;
+ GetMarkup getMarkup = createMarkupRequest();
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+ checkSessionForCurrentlyDeployedPortlet(response);
+
// Since no registration is required, a null RegistrationContext should be
acceptable
- releaseSessions(regContext, getSessionIDs(), null, null);
+ releaseSessions(regContext, null, null, null);
}
public void testNullSessionIDWithRegistration() throws Exception
@@ -231,10 +251,11 @@
//*************************************************************************************************
- private String[] getSessionIDs()
+ private String[] getSessionIDs() throws RemoteException, InvalidRegistrationFault,
OperationFailedFault
{
ProducerSessionInformation sessionInfo =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
- String sessionID =
(sessionInfo.getUserCookie()).substring("JSESSIONID=".length());
+ // session ids are portlet session, not portal session so we cannot rely on the
JSESSIONID cookie
+ String sessionID = sessionInfo.getSessionIdForPortlet(getDefaultHandle());
return new String[]
{sessionID};
}