[webbeans-commits] Webbeans SVN: r3515 - in tck/trunk/impl/src/main: resources/org/jboss/jsr299/tck/tests/context/conversation/client and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Sun Aug 16 05:54:46 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-08-16 05:54:45 -0400 (Sun, 16 Aug 2009)
New Revision: 3515

Removed:
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ConversationState.java
Modified:
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/AbstractConversationTest.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ClientConversationContextTest.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/Cloud.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/InvalidatingSessionDestroysConversationTest.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ManualCidPropagationTest.java
   tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/cloud.jsf
   tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/rain.jsf
Log:
Fix tests

Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/AbstractConversationTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/AbstractConversationTest.java	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/AbstractConversationTest.java	2009-08-16 09:54:45 UTC (rev 3515)
@@ -1,15 +1,12 @@
 package org.jboss.jsr299.tck.tests.context.conversation.client;
 
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
 import org.jboss.jsr299.tck.AbstractJSR299Test;
 
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 
@@ -22,53 +19,21 @@
    
    public static final String LONG_RUNNING_HEADER_NAME = "org.jboss.jsr299.tck.longRunning";
    
-   private static final long TIMEOUT = 200;
-   
-   protected boolean isCloudDestroyed(HttpClient client) throws Exception
+   protected boolean isCloudDestroyed(WebClient client) throws Exception
    {
-      HttpMethod method = new GetMethod(getConversationStatusPath("cloudDestroyed"));
-      try
-      {
-         client.executeMethod(method);
-         if (method.getStatusCode() == 200)
-         {
-            return true;
-         }
-         else
-         {
-            return false;
-         }
-      }
-      finally
-      {
-         method.releaseConnection();
-      }
+      client.setThrowExceptionOnFailingStatusCode(false);
+      Page page = client.getPage(getConversationStatusPath("cloudDestroyed"));
+      return page.getWebResponse().getStatusCode() == 200;
    }
    
-   protected void resetCloud(HttpClient client) throws Exception
+   protected void resetCloud(WebClient client) throws Exception
    {
-      HttpMethod method = new GetMethod(getConversationStatusPath("resetCloud"));
-      try
-      {
-         client.executeMethod(method);
-      }
-      finally
-      {
-         method.releaseConnection();
-      }
+      client.getPage(getConversationStatusPath("resetCloud"));
    }
    
-   protected void invalidateSession(HttpClient client) throws Exception
+   protected void invalidateSession(WebClient client) throws Exception
    {
-      HttpMethod method = new GetMethod(getConversationStatusPath("invalidateSession"));
-      try
-      {
-         client.executeMethod(method);
-      }
-      finally
-      {
-         method.releaseConnection();
-      }
+      client.getPage(getConversationStatusPath("invalidateSession"));
    }
    
    protected String getConversationStatusPath(String method)
@@ -76,64 +41,14 @@
       return super.getContextPath() + "conversation-status?method=" + method;
    }
    
-   protected URL getConversationStatusURL(String method) throws MalformedURLException
-   {
-      return new URL(getConversationStatusPath(method));
-   }
-   
-   protected ConversationState request(HttpClient client, String viewId) throws Exception
-   {
-      HttpMethod method = new GetMethod(getPath(viewId));
-      try
-      {
-         client.executeMethod(method);
-         assert method.getStatusCode() == 200;
-         return new ConversationState(method.getResponseHeader(CID_HEADER_NAME).getValue(), Boolean.valueOf(method.getResponseHeader(LONG_RUNNING_HEADER_NAME).getValue()));
-      }
-      finally
-      {
-         method.releaseConnection();
-      }
-   }
-   
-   protected ConversationState request(HttpClient client, String viewId, ConversationState c) throws Exception
-   {
-      return request(client, viewId + "?" + CID_REQUEST_PARAMETER_NAME + "=" + c.getId());
-   }
-   
-   protected String getBodyAsString(HttpClient client, String viewId) throws Exception
-   {
-      HttpMethod method = new GetMethod(getPath(viewId));
-      try
-      {
-         client.executeMethod(method);
-         assert method.getStatusCode() == 200;
-         return method.getResponseBodyAsString();
-      }
-      finally
-      {
-         method.releaseConnection();
-      }
-   }
-   
    protected String getPath(String viewId)
    {
       return getContextPath() + viewId;
    }
    
-   protected boolean isActiveBeforeApplyRequestValues(HttpClient client, String viewId) throws Exception
+   protected String getPath(String viewId, String cid)
    {
-      HttpMethod method = new GetMethod(getPath(viewId));
-      try
-      {
-         client.executeMethod(method);
-         assert method.getStatusCode() == 200;
-         return Boolean.valueOf(method.getResponseHeader(ConversationTestPhaseListener.ACTIVE_BEFORE_APPLY_REQUEST_VALUES_HEADER_NAME).getValue());
-      }
-      finally
-      {
-         method.releaseConnection();
-      }
+      return getContextPath() + viewId + "?" + CID_REQUEST_PARAMETER_NAME + "=" + cid;
    }
    
    protected <T> Set<T> getElements(HtmlElement rootElement, Class<T> elementClass)
@@ -167,17 +82,17 @@
      return null;
    }
    
-   protected String getCid(HtmlPage page)
+   protected String getCid(Page page)
    {
       return page.getWebResponse().getResponseHeaderValue(AbstractConversationTest.CID_HEADER_NAME);
    }
    
-   protected Boolean hasRained(HtmlPage page)
+   protected Boolean hasRained(Page page)
    {
       return Boolean.valueOf(page.getWebResponse().getResponseHeaderValue(Cloud.RAINED_HEADER_NAME));
    }
    
-   protected Boolean isLongRunning(HtmlPage page)
+   protected Boolean isLongRunning(Page page)
    {
       return Boolean.valueOf(page.getWebResponse().getResponseHeaderValue(LONG_RUNNING_HEADER_NAME));
    }

Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ClientConversationContextTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ClientConversationContextTest.java	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ClientConversationContextTest.java	2009-08-16 09:54:45 UTC (rev 3515)
@@ -1,6 +1,5 @@
 package org.jboss.jsr299.tck.tests.context.conversation.client;
 
-import org.apache.commons.httpclient.HttpClient;
 import org.jboss.test.audit.annotations.SpecAssertion;
 import org.jboss.test.audit.annotations.SpecAssertions;
 import org.jboss.test.audit.annotations.SpecVersion;
@@ -12,8 +11,10 @@
 import org.jboss.testharness.impl.packaging.war.WarArtifactDescriptor;
 import org.testng.annotations.Test;
 
+import com.gargoylesoftware.htmlunit.Page;
 import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSpan;
 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
 
 /**
@@ -64,10 +65,10 @@
    // TODO this test doesn't verify that the conversation context itself is destroyed
    public void testTransientConversationInstancesDestroyedAtRequestEnd() throws Exception
    {
-      HttpClient client = new HttpClient();
+      WebClient client = new WebClient();
       resetCloud(client);
-      ConversationState c = request(client, "/cloud.jsf");
-      assert c.isTransient();
+      HtmlPage page = client.getPage(getPath("/cloud.jsf"));
+      assert !isLongRunning(page);
       assert isCloudDestroyed(client);
    }
    
@@ -75,60 +76,96 @@
    @SpecAssertion(section = "6.7.4", id = "k")
    public void testLongRunningConversationInstancesNotDestroyedAtRequestEnd() throws Exception
    {
-      HttpClient client = new HttpClient();
+      WebClient client = new WebClient();
+      
+      
+      
+      HtmlPage storm = client.getPage(getPath("/storm.jsf"));
+      HtmlSubmitInput beginConversationButton = getFirstMatchingElement(storm, HtmlSubmitInput.class, "beginConversationButton");
+      storm = beginConversationButton.click();
+      
       resetCloud(client);
-      ConversationState c = request(client, "/clouds.jsf");
+      
+      client.getPage(getPath("/cloud.jsf", getCid(storm)));
       assert !isCloudDestroyed(client);
    }
    
-   @Test(groups = { "contexts" , "broken"})
+   @Test(groups = { "contexts" })
    @SpecAssertion(section = "6.7.4", id = "p")
    public void testConversationsDontCrossSessionBoundary1() throws Exception
    {
       WebClient webClient = new WebClient();
+      
+      // Load the page
       HtmlPage rain = webClient.getPage(getPath("/rain.jsf"));
+      
+      // begin a conversation
       HtmlSubmitInput beginConversationButton = getFirstMatchingElement(rain, HtmlSubmitInput.class, "beginConversationButton");
       rain = beginConversationButton.click();
+      String cid = getCid(rain);
       
+      // Cause rain
       HtmlSubmitInput rainButton = getFirstMatchingElement(rain, HtmlSubmitInput.class, "rain");
-      
       rain = rainButton.click();
       
+      // Re-request the page, inside the conversation and check it has rained
+      rain = webClient.getPage(getPath("/rain.jsf", cid));
       assert hasRained(rain);
       
-      webClient.getPage(getConversationStatusPath("invalidateSession"));
+      // Invalidate the session, invalidate the conversation-scoped cloud
+      invalidateSession(webClient);
       
+      // Re-request the page, check it hasn't rained
+      rain = webClient.getPage(getPath("/rain.jsf", cid));
       assert !hasRained(rain);
    }
    
-   @Test(groups = { "contexts" , "broken"})
+   @Test(groups = { "contexts" })
    @SpecAssertion(section = "6.7.4", id = "p")
    public void testConversationsDontCrossSessionBoundary2() throws Exception
    {
-      // TODO Test assumes conversation.getId() is available when not in a lrc
-      HttpClient client1 = new HttpClient();
-      HttpClient client2 = new HttpClient();
-      ConversationState c1 = request(client1, "/rain.jsf");
-      //assert hasRained(client1, "/cloud.jsf", c1.getId());
-      //assert !hasRained(client2, "/cloud.jsf", c1.getId());
+      WebClient webClient = new WebClient();
+      
+      // Load the page
+      HtmlPage rain = webClient.getPage(getPath("/rain.jsf"));
+      
+      // begin a conversation
+      HtmlSubmitInput beginConversationButton = getFirstMatchingElement(rain, HtmlSubmitInput.class, "beginConversationButton");
+      rain = beginConversationButton.click();
+      String cid = getCid(rain);
+      
+      // Cause rain
+      HtmlSubmitInput rainButton = getFirstMatchingElement(rain, HtmlSubmitInput.class, "rain");
+      rain = rainButton.click();
+      
+      // Re-request the page, inside the conversation and check it has rained
+      rain = webClient.getPage(getPath("/rain.jsf", cid));
+      assert hasRained(rain);
+      
+      // Create a new web client and load the page
+      webClient = new WebClient();
+      rain = webClient.getPage(getPath("/rain.jsf", cid));
+      assert !hasRained(rain);
    }
    
    @Test(groups = { "contexts" })
    @SpecAssertion(section = "6.7.4", id = "a")
    public void testConversationActiveDuringNonFacesRequest() throws Exception
    {
-      HttpClient client = new HttpClient();
-      assert getBodyAsString(client, "/cloud.jsf").contains(Cloud.NAME);
+      WebClient client = new WebClient();
+      HtmlPage page = client.getPage(getPath("/cloud.jsf"));
+      HtmlSpan span = getFirstMatchingElement(page, HtmlSpan.class, "cloudName");
+      assert span.getTextContent().equals(Cloud.NAME);
    }
    
    @Test(groups = { "contexts" })
    @SpecAssertion(section = "6.7.4", id = "tb")
    public void testConversationPropagationToNonExistentConversationLeadsToTransientConversation() throws Exception
    {
-      HttpClient client = new HttpClient();
-      ConversationState c1 = request(client, "/cloud.jsf", new ConversationState("org.jboss.jsr299", false));
-      assert c1.isTransient();
-      assert !c1.getId().equals("org.jboss.jsr299");
+      WebClient client = new WebClient();
+      Page page = client.getPage(getPath("/cloud.jsf", "org.jboss.jsr299"));
+      assert !isLongRunning(page);
+      assert !getCid(page).equals("org.jboss.jsr299");
    }
 
 }
\ No newline at end of file

Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/Cloud.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/Cloud.java	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/Cloud.java	2009-08-16 09:54:45 UTC (rev 3515)
@@ -13,7 +13,7 @@
 	 */
 	private static final long serialVersionUID = 5765109971012677278L;
 
-public static final String NAME = Cloud.class.getName() + ".Pete";
+	public static final String NAME = Cloud.class.getName() + ".Pete";
    
    public static final String RAINED_HEADER_NAME = Cloud.class.getName() + ".rained";
    

Deleted: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ConversationState.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ConversationState.java	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ConversationState.java	2009-08-16 09:54:45 UTC (rev 3515)
@@ -1,33 +0,0 @@
-package org.jboss.jsr299.tck.tests.context.conversation.client;
-
-/**
- * A simple bean to hold the state of the conversation that
- * was returned in the headers of the request.
- */
-public class ConversationState
-{
-   private String id;
-   
-   private boolean longRunning;
-   
-   public ConversationState(String id, boolean longRunning)
-   {
-      this.id = id;
-      this.longRunning = longRunning;
-   }
-   
-   public String getId()
-   {
-      return id;
-   }
-   
-   public boolean isLongRunning()
-   {
-      return longRunning;
-   }
-   
-   public boolean isTransient()
-   {
-      return !longRunning;
-   }
-}

Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/InvalidatingSessionDestroysConversationTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/InvalidatingSessionDestroysConversationTest.java	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/InvalidatingSessionDestroysConversationTest.java	2009-08-16 09:54:45 UTC (rev 3515)
@@ -1,6 +1,5 @@
 package org.jboss.jsr299.tck.tests.context.conversation.client;
 
-import org.apache.commons.httpclient.HttpClient;
 import org.jboss.test.audit.annotations.SpecAssertion;
 import org.jboss.test.audit.annotations.SpecVersion;
 import org.jboss.testharness.impl.packaging.Artifact;
@@ -11,6 +10,8 @@
 import org.jboss.testharness.impl.packaging.war.WarArtifactDescriptor;
 import org.testng.annotations.Test;
 
+import com.gargoylesoftware.htmlunit.WebClient;
+
 /**
  * @author Nicklas Karlsson
  */
@@ -27,18 +28,17 @@
 public class InvalidatingSessionDestroysConversationTest extends AbstractConversationTest
 {
    
-   @Test(groups = { "contexts", "broken" })
+   @Test(groups = { "contexts" })
    @SpecAssertion(section = "6.7.4", id = "qa")
    // TODO this test doesn't precisely probe the boundaries of the service() method
    public void testInvalidatingSessionDestroysConversation() throws Exception
    {
-      // TODO Test assumes conversation.getId() is available when not in a lrc
-      HttpClient client = new HttpClient();
-      resetCloud(client);
-      request(client, "/clouds.jsf");
-      assert !isCloudDestroyed(client);
-      invalidateSession(client);
-      assert isCloudDestroyed(client);
+      WebClient webClient = new WebClient();
+      resetCloud(webClient);
+      webClient.getPage(getPath("/clouds.jsf"));
+      assert !isCloudDestroyed(webClient);
+      invalidateSession(webClient);
+      assert isCloudDestroyed(webClient);
    }
 
 }
\ No newline at end of file

Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ManualCidPropagationTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ManualCidPropagationTest.java	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/conversation/client/ManualCidPropagationTest.java	2009-08-16 09:54:45 UTC (rev 3515)
@@ -1,7 +1,5 @@
 package org.jboss.jsr299.tck.tests.context.conversation.client;
 
-import java.net.URL;
-
 import org.jboss.test.audit.annotations.SpecAssertion;
 import org.jboss.test.audit.annotations.SpecVersion;
 import org.jboss.testharness.impl.packaging.Artifact;
@@ -13,7 +11,6 @@
 import org.testng.annotations.Test;
 
 import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.WebRequestSettings;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
 
@@ -36,7 +33,7 @@
 public class ManualCidPropagationTest extends AbstractConversationTest
 {
    
-   @Test(groups = { "contexts", "broken" })
+   @Test(groups = { "contexts" })
    @SpecAssertion(section = "6.7.4", id = "n")
    public void testManualCidPropagation() throws Exception
    {
@@ -47,11 +44,8 @@
       
       String c1 = getCid(storm);
       
-      WebRequestSettings settings = new WebRequestSettings(new URL(getPath("/cloud.jsf")));
-      settings.addAdditionalHeader(CID_REQUEST_PARAMETER_NAME, c1);
+      HtmlPage cloud = webClient.getPage(getPath("/cloud.jsf", c1));
       
-      HtmlPage cloud = webClient.getPage(settings);
-      
       String c2 = getCid(cloud);
       
       assert isLongRunning(cloud);

Modified: tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/cloud.jsf
===================================================================
--- tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/cloud.jsf	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/cloud.jsf	2009-08-16 09:54:45 UTC (rev 3515)
@@ -14,7 +14,7 @@
   </head>
   <body>
    <f:view>
-      <h:outputText value="#{cloud.name}" />
+      <h:outputText value="#{cloud.name}" id="cloudName" />
    </f:view>
   </body>
   </html>

Modified: tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/rain.jsf
===================================================================
--- tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/rain.jsf	2009-08-16 09:52:30 UTC (rev 3514)
+++ tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/conversation/client/rain.jsf	2009-08-16 09:54:45 UTC (rev 3515)
@@ -14,8 +14,10 @@
   </head>
   <body>
    <f:view>
+     <h:form>
       <h:commandButton action="#{storm.beginConversation}" value="Thunder" id="beginConversationButton"/>
-      <h:commandButton action="#{cloud.rain}" value="Rain" id="rain"/> 
+      <h:commandButton action="#{cloud.rain}" value="Rain" id="rain"/>
+     </h:form> 
    </f:view>
   </body>
   </html>




More information about the weld-commits mailing list