[jboss-svn-commits] JBoss Portal SVN: r5629 - in trunk/test/src/main/org/jboss/portal/test/framework/driver/http: . command response

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 13 11:39:15 EST 2006


Author: julien at jboss.com
Date: 2006-11-13 11:39:12 -0500 (Mon, 13 Nov 2006)
New Revision: 5629

Added:
   trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/SubmitResponseCommand.java
   trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/SubmitResponseResponse.java
Modified:
   trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HttpTestDriverClient.java
Log:
improve protocol handling in the http test driver client and remove duplicate code.

Modified: trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HttpTestDriverClient.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HttpTestDriverClient.java	2006-11-13 15:28:52 UTC (rev 5628)
+++ trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HttpTestDriverClient.java	2006-11-13 16:39:12 UTC (rev 5629)
@@ -143,28 +143,13 @@
    {
       try
       {
-         if (cmd instanceof StartTestCommand)
-         {
-            Node node = nodeManager.getNode(initialNodeId);
+         Node node = nodeManager.getNode(initialNodeId);
 
-            // Setup context
-            HttpTestContext ctx = new HttpTestContext(testId, -1, archivePath);
-            getServer().updateContext(testId, ctx);
+         // Create conversation
+         TestConversation conversation = new TestConversation(testId, node);
 
-            //
-            DriverResponse resp = getServer().invoke(testId, cmd);
-            if (resp instanceof HttpResponse)
-            {
-               HttpResponse httpResp = (HttpResponse)resp;
-               HttpConversation conversation = new HttpConversation(testId, node);
-               return conversation.handleHttpResponse(httpResp);
-            }
-            return resp;
-         }
-         else
-         {
-            return new ErrorResponse(new UnsupportedOperationException());
-         }
+         //
+         return conversation.handleCommand(cmd);
       }
       catch (Exception e)
       {
@@ -172,7 +157,10 @@
       }
    }
 
-   private class HttpConversation
+   /**
+    * A test conversation
+    */
+   private class TestConversation
    {
 
       /** The test name. */
@@ -187,7 +175,7 @@
       /** The request count for that session. */
       int requestCount;
 
-      public HttpConversation(String testName, Node node)
+      public TestConversation(String testName, Node node)
       {
          this.testName = testName;
          this.node = node;
@@ -198,13 +186,14 @@
          client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("test", "test"));
       }
 
-      private DriverResponse handleHttpResponse(HttpResponse httpResp) throws Exception
+      private DriverResponse handleCommand(DriverCommand cmd) throws Exception
       {
-         HttpCommand httpCmd = createHttpCommand(httpResp);
-         DriverResponse resp = invokeHttp(httpCmd);
+         DriverResponse resp = invokeHttp(cmd);
          if (resp instanceof HttpResponse)
          {
-            return handleHttpResponse((HttpResponse)resp);
+            HttpResponse httpResp = (HttpResponse)resp;
+            HttpCommand httpCmd = createHttpCommand(httpResp);
+            return handleCommand(httpCmd);
          }
          else
          {
@@ -233,9 +222,8 @@
       /**
        *
        */
-      private DriverResponse invokeHttp(HttpCommand cmd) throws Exception
+      private DriverResponse invokeHttp(DriverCommand cmd) throws Exception
       {
-         HttpMethod hm = null;
          if (cmd instanceof DoPostCommand)
          {
             DoPostCommand doPostCmd = (DoPostCommand)cmd;
@@ -275,7 +263,7 @@
                   post.setRequestBody(nvps);
                }
                executeMethod(post);
-               hm = post;
+               return decodeHttpResponse(post);
             }
             finally
             {
@@ -302,7 +290,7 @@
                }
                get.setFollowRedirects(false);
                executeMethod(get);
-               hm = get;
+               return decodeHttpResponse(get);
             }
             finally
             {
@@ -312,8 +300,22 @@
                }
             }
          }
+         else if (cmd instanceof StartTestCommand)
+         {
+            requestCount = -1;
+            pushContext();
+            DriverResponse response = getServer().invoke(testName, cmd);
+            requestCount = 0;
+            return response;
+         }
+         else
+         {
+            return new ErrorResponse("Unexpected response");
+         }
+      }
 
-         //
+      private DriverResponse decodeHttpResponse(HttpMethod hm) throws Exception
+      {
          HttpTestDriverServer agent = getServer();
          HttpTestContext ctx = agent.retrieveContext(testName);
          DriverResponse response = ctx.getResponse();
@@ -347,7 +349,7 @@
                {
                   String redirectLocation = locationHeader.getValue();
                   log.info("# Received '302' code --> " + redirectLocation);
-                  cmd = new DoGetCommand(redirectLocation);
+                  DoGetCommand cmd = new DoGetCommand(redirectLocation);
                   return invokeHttp(cmd);
                }
                else
@@ -392,11 +394,9 @@
          //
          HostConfiguration cfg = new HostConfiguration();
          cfg.setHost(host, port);
-         HttpTestContext ctx = new HttpTestContext(testName, requestCount, archivePath);
 
-         log.info("# Updating test case context of : " + node + " : " + ctx);
-         HttpTestDriverServer agent = getServer();
-         agent.updateContext(testName, ctx);
+         //
+         pushContext();
 
          //
          log.info("# Invoking test case over http " + cfg + " " + method.getURI());
@@ -404,6 +404,15 @@
          return client.executeMethod(cfg, method);
       }
 
+      private void pushContext()
+      {
+         HttpTestContext ctx = new HttpTestContext(testName, requestCount, archivePath);
+
+         log.info("# Updating test case context of : " + node + " : " + ctx);
+         HttpTestDriverServer agent = getServer();
+         agent.updateContext(testName, ctx);
+      }
+
       private Node getNode(int port)
       {
          NodeId nodeId = null;

Added: trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/SubmitResponseCommand.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/SubmitResponseCommand.java	2006-11-13 15:28:52 UTC (rev 5628)
+++ trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/SubmitResponseCommand.java	2006-11-13 16:39:12 UTC (rev 5629)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.framework.driver.http.command;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class SubmitResponseCommand extends HttpCommand
+{
+
+   private Map headers;
+
+   private byte[] bytes;
+
+}

Added: trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/SubmitResponseResponse.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/SubmitResponseResponse.java	2006-11-13 15:28:52 UTC (rev 5628)
+++ trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/SubmitResponseResponse.java	2006-11-13 16:39:12 UTC (rev 5629)
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.framework.driver.http.response;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class SubmitResponseResponse extends HttpResponse
+{
+}




More information about the jboss-svn-commits mailing list