[portal-commits] JBoss Portal SVN: r8937 - branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Wed Nov 14 21:08:23 EST 2007


Author: chris.laprun at jboss.com
Date: 2007-11-14 21:08:23 -0500 (Wed, 14 Nov 2007)
New Revision: 8937

Modified:
   branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
Log:
- Undeploy in finally block to avoid side effects if something goes wrong in a test and the portlet is not properly undeployed.

Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java	2007-11-15 01:42:49 UTC (rev 8936)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java	2007-11-15 02:08:23 UTC (rev 8937)
@@ -129,42 +129,47 @@
       String archiveName = "test-renderparam-portlet.war";
       deploy(archiveName);
 
-      GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
-      MarkupResponse res = markupService.getMarkup(gm);
+      try
+      {
+         GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+         MarkupResponse res = markupService.getMarkup(gm);
 
-      String markupString = res.getMarkupContext().getMarkupString();
+         String markupString = res.getMarkupContext().getMarkupString();
 
-      String julienLink = extractLink(markupString, 0);
-      WSRPPortletURL julienURL = WSRPPortletURL.create(julienLink);
+         String julienLink = extractLink(markupString, 0);
+         WSRPPortletURL julienURL = WSRPPortletURL.create(julienLink);
 
-      ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Anonymous!");
-      ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 0");
+         ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Anonymous!");
+         ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 0");
 
-      ExtendedAssert.assertTrue(julienURL instanceof WSRPRenderURL);
-      WSRPRenderURL julienRender = (WSRPRenderURL)julienURL;
+         ExtendedAssert.assertTrue(julienURL instanceof WSRPRenderURL);
+         WSRPRenderURL julienRender = (WSRPRenderURL)julienURL;
 
-      // We're now trying to get a hello for Julien ;)
-      gm.getMarkupParams().setNavigationalState(julienRender.getNavigationalState().getStringValue());
-      res = markupService.getMarkup(gm);
-      markupString = res.getMarkupContext().getMarkupString();
-      ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Julien!");
+         // We're now trying to get a hello for Julien ;)
+         gm.getMarkupParams().setNavigationalState(julienRender.getNavigationalState().getStringValue());
+         res = markupService.getMarkup(gm);
+         markupString = res.getMarkupContext().getMarkupString();
+         ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Julien!");
 
-      // julien.length() * 2 to bypass second link
-      WSRPPortletURL incrementURL = WSRPPortletURL.create(extractLink(markupString, julienLink.length() * 2));
-      ExtendedAssert.assertTrue(incrementURL instanceof WSRPActionURL);
-      WSRPActionURL incrementAction = (WSRPActionURL)incrementURL;
+         // julien.length() * 2 to bypass second link
+         WSRPPortletURL incrementURL = WSRPPortletURL.create(extractLink(markupString, julienLink.length() * 2));
+         ExtendedAssert.assertTrue(incrementURL instanceof WSRPActionURL);
+         WSRPActionURL incrementAction = (WSRPActionURL)incrementURL;
 
-      // let's see now if we can increment the counter
-      PerformBlockingInteraction performBlockingInteraction =
-         WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
-      InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
-      interactionParams.setInteractionState(incrementAction.getInteractionState().getStringValue());
-      markupService.performBlockingInteraction(performBlockingInteraction);
-      res = markupService.getMarkup(gm);
-      markupString = res.getMarkupContext().getMarkupString();
-      ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 1");
-
-      undeploy(archiveName);
+         // let's see now if we can increment the counter
+         PerformBlockingInteraction performBlockingInteraction =
+            WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+         InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
+         interactionParams.setInteractionState(incrementAction.getInteractionState().getStringValue());
+         markupService.performBlockingInteraction(performBlockingInteraction);
+         res = markupService.getMarkup(gm);
+         markupString = res.getMarkupContext().getMarkupString();
+         ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 1");
+      }
+      finally
+      {
+         undeploy(archiveName);
+      }
    }
 
    private String extractLink(String markupString, int fromIndex)
@@ -182,16 +187,19 @@
       String sessionPortletArchive = "test-session-portlet.war";
       deploy(sessionPortletArchive);
 
-      GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
 
-      MarkupResponse response = markupService.getMarkup(getMarkup);
+      try
+      {
+         GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
 
-      checkMarkupResponseWithSession(response, 0);
+         MarkupResponse response = markupService.getMarkup(getMarkup);
 
-      response = markupService.getMarkup(getMarkup);
-      checkMarkupResponseWithSession(response, 1);
+         checkMarkupResponseWithSession(response, 0);
 
-      // fix-me: try to reuse the old session id: what should happen?
+         response = markupService.getMarkup(getMarkup);
+         checkMarkupResponseWithSession(response, 1);
+
+         // fix-me: try to reuse the old session id: what should happen?
 //      runtimeContext.setSessionID(sessionID);
 //      getMarkup.setRuntimeContext(runtimeContext);
 //      try
@@ -202,9 +210,12 @@
 //      catch (InvalidSessionFault expected)
 //      {
 //      }
-
-      // reset state
-      undeploy(sessionPortletArchive);
+      }
+      finally
+      {
+         // reset state
+         undeploy(sessionPortletArchive);
+      }
    }
 
    public void testPerformBlockingInteractionNoRedirect() throws Exception
@@ -298,12 +309,17 @@
       String dispatcherPortletArchive = "test-dispatcher-portlet.war";
       deploy(dispatcherPortletArchive);
 
-      GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+      try
+      {
+         GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
 
-      MarkupResponse response = markupService.getMarkup(getMarkup);
-      checkMarkupResponse(response, "test");
-
-      undeploy(dispatcherPortletArchive);
+         MarkupResponse response = markupService.getMarkup(getMarkup);
+         checkMarkupResponse(response, "test");
+      }
+      finally
+      {
+         undeploy(dispatcherPortletArchive);
+      }
    }
 
    public void testGetMarkupWithNoContent() throws Exception
@@ -312,12 +328,17 @@
       String basicPortletArchive = "test-basic-portlet.war";
       deploy(basicPortletArchive);
 
-      GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+      try
+      {
+         GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
 
-      MarkupResponse response = markupService.getMarkup(getMarkup);
-      checkMarkupResponse(response, "");
-
-      undeploy(basicPortletArchive);
+         MarkupResponse response = markupService.getMarkup(getMarkup);
+         checkMarkupResponse(response, "");
+      }
+      finally
+      {
+         undeploy(basicPortletArchive);
+      }
    }
 
    public void testGetMarkupWithNonStandardLocales() throws Exception
@@ -339,9 +360,11 @@
       catch (Exception expected)
       {
       }
-      // checkMarkupResponse(response, "GetLocalesPortlet"); // should we return try to generate markup regardless?
-
-      undeploy(getLocalesPortletArchive);
+      finally
+      {
+         // checkMarkupResponse(response, "GetLocalesPortlet"); // should we return try to generate markup regardless?
+         undeploy(getLocalesPortletArchive);
+      }
    }
 
    public void testGetMarkupWithEncodedURLs() throws Exception
@@ -350,13 +373,18 @@
       String encodeURLPortletArchive = "test-encodeurl-portlet.war";
       deploy(encodeURLPortletArchive);
 
-      GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+      try
+      {
+         GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
 
-      MarkupResponse response = markupService.getMarkup(getMarkup);
-      checkMarkupResponse(response, "wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite\n" +
-         "wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite");
-
-      undeploy(encodeURLPortletArchive);
+         MarkupResponse response = markupService.getMarkup(getMarkup);
+         checkMarkupResponse(response, "wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite\n" +
+            "wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite");
+      }
+      finally
+      {
+         undeploy(encodeURLPortletArchive);
+      }
    }
 
    public void testGetMarkupWithUserContext() throws Exception
@@ -365,13 +393,18 @@
       String userContextPortletArchive = "test-usercontext-portlet.war";
       deploy(userContextPortletArchive);
 
-      GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
-      getMarkup.setUserContext(WSRPTypeFactory.createUserContext("johndoe"));
+      try
+      {
+         GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+         getMarkup.setUserContext(WSRPTypeFactory.createUserContext("johndoe"));
 
-      MarkupResponse response = markupService.getMarkup(getMarkup);
-      checkMarkupResponse(response, "user: johndoe");
-
-      undeploy(userContextPortletArchive);
+         MarkupResponse response = markupService.getMarkup(getMarkup);
+         checkMarkupResponse(response, "user: johndoe");
+      }
+      finally
+      {
+         undeploy(userContextPortletArchive);
+      }
    }
 
    public void testGetMarkupMultiValuedFormParams() throws Exception
@@ -380,31 +413,36 @@
       String multiValuedPortletArchive = "test-multivalued-portlet.war";
       deploy(multiValuedPortletArchive);
 
-      PerformBlockingInteraction action =
-         WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
-      action.getInteractionParams().setFormParameters(new NamedString[]{new NamedString("multi", "value1")});
-      BlockingInteractionResponse actionResponse = markupService.performBlockingInteraction(action);
-      GetMarkup markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
-      markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
-      MarkupResponse response = markupService.getMarkup(markupRequest);
-      checkMarkupResponse(response, "multi: value1");
+      try
+      {
+         PerformBlockingInteraction action =
+            WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+         action.getInteractionParams().setFormParameters(new NamedString[]{new NamedString("multi", "value1")});
+         BlockingInteractionResponse actionResponse = markupService.performBlockingInteraction(action);
+         GetMarkup markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+         markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
+         MarkupResponse response = markupService.getMarkup(markupRequest);
+         checkMarkupResponse(response, "multi: value1");
 
-      action.getInteractionParams().setFormParameters(new NamedString[]{
-         new NamedString("multi", "value1"), new NamedString("multi", "value2")});
-      actionResponse = markupService.performBlockingInteraction(action);
-      markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
-      markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
-      response = markupService.getMarkup(markupRequest);
-      checkMarkupResponse(response, "multi: value1, value2");
+         action.getInteractionParams().setFormParameters(new NamedString[]{
+            new NamedString("multi", "value1"), new NamedString("multi", "value2")});
+         actionResponse = markupService.performBlockingInteraction(action);
+         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 = createMarkupRequestForCurrentlyDeployedPortlet();
-      markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
-      response = markupService.getMarkup(markupRequest);
-      checkMarkupResponse(response, "multi: ");
-
-      undeploy(multiValuedPortletArchive);
+         action.getInteractionParams().setFormParameters(new NamedString[]{});
+         actionResponse = markupService.performBlockingInteraction(action);
+         markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+         markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
+         response = markupService.getMarkup(markupRequest);
+         checkMarkupResponse(response, "multi: ");
+      }
+      finally
+      {
+         undeploy(multiValuedPortletArchive);
+      }
    }
 
    public void testImplicitCloning() throws Exception
@@ -413,36 +451,41 @@
       String archiveName = "test-implicitcloning-portlet.war";
       deploy(archiveName);
 
-      // check the initial value
-      GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
-      MarkupResponse res = markupService.getMarkup(gm);
-      String markupString = res.getMarkupContext().getMarkupString();
-      ExtendedAssert.assertEquals("initial", markupString);
+      try
+      {
+         // check the initial value
+         GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+         MarkupResponse res = markupService.getMarkup(gm);
+         String markupString = res.getMarkupContext().getMarkupString();
+         ExtendedAssert.assertEquals("initial", markupString);
 
-      // modify the preference value
-      PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
-      pbi.getInteractionParams().setPortletStateChange(StateChange.cloneBeforeWrite); // request cloning if needed
-      String value = "new value";
-      pbi.getInteractionParams().setFormParameters(new NamedString[]{new NamedString("value", value)});
-      BlockingInteractionResponse response = markupService.performBlockingInteraction(pbi);
-      ExtendedAssert.assertNotNull(response);
+         // modify the preference value
+         PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+         pbi.getInteractionParams().setPortletStateChange(StateChange.cloneBeforeWrite); // request cloning if needed
+         String value = "new value";
+         pbi.getInteractionParams().setFormParameters(new NamedString[]{new NamedString("value", value)});
+         BlockingInteractionResponse response = markupService.performBlockingInteraction(pbi);
+         ExtendedAssert.assertNotNull(response);
 
-      // check that we got a new portlet context
-      PortletContext pc = response.getUpdateResponse().getPortletContext();
-      ExtendedAssert.assertNotNull(pc);
+         // check that we got a new portlet context
+         PortletContext pc = response.getUpdateResponse().getPortletContext();
+         ExtendedAssert.assertNotNull(pc);
 
-      // get the markup again and check that we still get the initial value with the initial portlet context
-      res = markupService.getMarkup(gm);
-      markupString = res.getMarkupContext().getMarkupString();
-      ExtendedAssert.assertEquals("initial", markupString);
+         // get the markup again and check that we still get the initial value with the initial portlet context
+         res = markupService.getMarkup(gm);
+         markupString = res.getMarkupContext().getMarkupString();
+         ExtendedAssert.assertEquals("initial", markupString);
 
-      // retrieving the markup with the new portlet context should return the new value
-      gm.setPortletContext(pc);
-      res = markupService.getMarkup(gm);
-      markupString = res.getMarkupContext().getMarkupString();
-      ExtendedAssert.assertEquals(value, markupString);
-
-      undeploy(archiveName);
+         // retrieving the markup with the new portlet context should return the new value
+         gm.setPortletContext(pc);
+         res = markupService.getMarkup(gm);
+         markupString = res.getMarkupContext().getMarkupString();
+         ExtendedAssert.assertEquals(value, markupString);
+      }
+      finally
+      {
+         undeploy(archiveName);
+      }
    }
 
    public void testGetMarkupWithResource() throws Exception
@@ -451,14 +494,19 @@
       String archive = "test-resource-portlet.war";
       deploy(archive);
 
-      GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
-      MarkupResponse res = markupService.getMarkup(gm);
-      String markupString = res.getMarkupContext().getMarkupString();
-      ExtendedAssert.assertEquals("<img src='wsrp_rewrite?wsrp-urlType=resource&amp;" +
-         "wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&amp;" +
-         "wsrp-requiresRewrite=true/wsrp_rewrite'/>", markupString);
-
-      undeploy(archive);
+      try
+      {
+         GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+         MarkupResponse res = markupService.getMarkup(gm);
+         String markupString = res.getMarkupContext().getMarkupString();
+         ExtendedAssert.assertEquals("<img src='wsrp_rewrite?wsrp-urlType=resource&amp;" +
+            "wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&amp;" +
+            "wsrp-requiresRewrite=true/wsrp_rewrite'/>", markupString);
+      }
+      finally
+      {
+         undeploy(archive);
+      }
    }
 
    public void testApplicationScopeVariableHandling() throws Exception
@@ -467,32 +515,37 @@
       String archive = "test-applicationscope-portlet.war";
       deploy(archive);
 
-      // get handles: current archive contains 2 portlets, one to set the application scoped variable, another one to read it
-      List<String> handles = getHandlesForCurrentlyDeployedArchive();
-      String handle = handles.get(0);
-      String setHandle, getHandle;
-      if (handle.contains("Set"))
+      try
       {
-         setHandle = handle;
-         getHandle = handles.get(1);
+         // get handles: current archive contains 2 portlets, one to set the application scoped variable, another one to read it
+         List<String> handles = getHandlesForCurrentlyDeployedArchive();
+         String handle = handles.get(0);
+         String setHandle, getHandle;
+         if (handle.contains("Set"))
+         {
+            setHandle = handle;
+            getHandle = handles.get(1);
+         }
+         else
+         {
+            getHandle = handle;
+            setHandle = handles.get(1);
+         }
+
+         // set appVar to value in the application scope by the first portlet
+         PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(setHandle);
+         pbi.getInteractionParams().setFormParameters(new NamedString[]{new NamedString("appVar", "value")});
+         markupService.performBlockingInteraction(pbi);
+
+         // the second portlet reads the appVar value and outputs it
+         GetMarkup gm = createMarkupRequest(getHandle);
+         MarkupResponse res = markupService.getMarkup(gm);
+         checkMarkupResponse(res, "appVar=value");
       }
-      else
+      finally
       {
-         getHandle = handle;
-         setHandle = handles.get(1);
+         undeploy(archive);
       }
-
-      // set appVar to value in the application scope by the first portlet
-      PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(setHandle);
-      pbi.getInteractionParams().setFormParameters(new NamedString[]{new NamedString("appVar", "value")});
-      markupService.performBlockingInteraction(pbi);
-
-      // the second portlet reads the appVar value and outputs it
-      GetMarkup gm = createMarkupRequest(getHandle);
-      MarkupResponse res = markupService.getMarkup(gm);
-      checkMarkupResponse(res, "appVar=value");
-
-      undeploy(archive);
    }
 
    private String checkPBIAndGetNavigationalState(String symbol) throws Exception




More information about the portal-commits mailing list