Author: julien(a)jboss.com
Date: 2007-08-30 15:41:05 -0400 (Thu, 30 Aug 2007)
New Revision: 8113
Added:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestDriverServer.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoMethodCommand.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeMethodResponse.java
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestCase.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestContext.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestConversation.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoGetCommand.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoPostCommand.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeGetResponse.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokePostResponse.java
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/server/NodeId.java
Log:
- added HTTPTestDriverServer which extends RemoteTestDriverServer to provide initial
configuration of the HTTPTestContext
- added initialPath on the HTTPTestContext class
- improved support of URIs on http command/response classes
- added DoMethodCommand and InvokeMethodResponse to factor common state on DoGetCommand,
DoPostCommand, InvokeGetCommand and InvokePostCommand
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestCase.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestCase.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestCase.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -31,6 +31,9 @@
import org.jboss.portal.test.framework.driver.remote.TestContext;
import org.jboss.portal.test.framework.driver.remote.RemoteTestCase;
+import java.net.URI;
+import java.net.URISyntaxException;
+
/**
* Defines an http test case working from the server side point of view.
*
@@ -41,14 +44,29 @@
{
/** The test path. */
- protected final String path;
+ protected final URI uri;
- public HTTPTestCase(String testCaseId, String path)
+ public HTTPTestCase(String testCaseId, String uri)
{
super(testCaseId);
//
- this.path = path;
+ if (uri == null)
+ {
+ throw new IllegalArgumentException("No null URI accepted");
+ }
+
+ //
+ try
+ {
+ this.uri = new URI(uri);
+ }
+ catch (URISyntaxException e)
+ {
+ IllegalArgumentException iae = new IllegalArgumentException("Wrong URI
syntax");
+ iae.initCause(e);
+ throw iae;
+ }
}
/**
@@ -59,7 +77,7 @@
{
if (cmd instanceof StartTestCommand)
{
- return new InvokeGetResponse(path);
+ return new InvokeGetResponse(uri);
}
else
{
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestContext.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestContext.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestContext.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -96,6 +96,9 @@
ctx.setResponse(currentResponse);
}
+ /** . */
+ String initialPath;
+
public HTTPTestContext(TestContext that)
{
super(that);
@@ -105,4 +108,9 @@
{
super(requestCount, archivePath, parametrization);
}
+
+ public String getInitialPath()
+ {
+ return initialPath;
+ }
}
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestConversation.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestConversation.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestConversation.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -29,7 +29,6 @@
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HeaderElement;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.GetMethod;
@@ -42,10 +41,12 @@
import org.jboss.portal.test.framework.driver.http.command.DoGetCommand;
import org.jboss.portal.test.framework.driver.http.command.DoPostCommand;
import org.jboss.portal.test.framework.driver.http.command.SendResponseCommand;
+import org.jboss.portal.test.framework.driver.http.command.DoMethodCommand;
import org.jboss.portal.test.framework.driver.http.response.HTTPDriverResponseContext;
import org.jboss.portal.test.framework.driver.http.response.HTTPDriverResponse;
import org.jboss.portal.test.framework.driver.http.response.InvokeGetResponse;
import org.jboss.portal.test.framework.driver.http.response.InvokePostResponse;
+import org.jboss.portal.test.framework.driver.http.response.InvokeMethodResponse;
import org.jboss.portal.test.framework.driver.remote.TestConversation;
import org.jboss.portal.test.framework.driver.remote.TestContext;
import org.jboss.portal.test.framework.driver.remote.RemoteTestDriver;
@@ -64,6 +65,10 @@
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.MalformedURLException;
import junit.framework.AssertionFailedError;
@@ -126,77 +131,83 @@
protected RemoteDriverResponseContext invoke(RemoteDriverCommandContext
commandContext) throws Exception
{
DriverCommand command = commandContext.getCommand();
- if (command instanceof DoPostCommand)
+ if (command instanceof DoMethodCommand)
{
- DoPostCommand doPostCmd = (DoPostCommand)command;
- PostMethod post = null;
- try
+ DoMethodCommand method = (DoMethodCommand)command;
+ URI uri = method.getURI();
+ URL url = getURL(uri);
+ if (command instanceof DoPostCommand)
{
- post = new PostMethod(doPostCmd.getURL());
- post.setFollowRedirects(false);
- HttpRequest.Body body = doPostCmd.getBody();
- if (doPostCmd.getContentType() != null)
+ DoPostCommand doPostCmd = (DoPostCommand)command;
+ PostMethod post = null;
+ try
{
- post.addRequestHeader("Content-Type",
doPostCmd.getContentType());
- }
- if (body instanceof HttpRequest.Raw)
- {
- HttpRequest.Raw rb = (HttpRequest.Raw)body;
- ByteArrayRequestEntity entity = new
ByteArrayRequestEntity(rb.getBytes());
- post.setRequestEntity(entity);
- }
- else if (body instanceof HttpRequest.Form)
- {
- HttpRequest.Form fb = (HttpRequest.Form)body;
- Collection tmp = new ArrayList();
- for (Iterator i = fb.getParameterNames().iterator(); i.hasNext();)
+ post = new PostMethod(url.toString());
+ post.setFollowRedirects(false);
+ HttpRequest.Body body = doPostCmd.getBody();
+ if (doPostCmd.getContentType() != null)
{
- String name = (String)i.next();
- String[] values = fb.getParameterValues(name);
- for (int j = 0; j < values.length; j++)
+ post.addRequestHeader("Content-Type",
doPostCmd.getContentType());
+ }
+ if (body instanceof HttpRequest.Raw)
+ {
+ HttpRequest.Raw rb = (HttpRequest.Raw)body;
+ ByteArrayRequestEntity entity = new
ByteArrayRequestEntity(rb.getBytes());
+ post.setRequestEntity(entity);
+ }
+ else if (body instanceof HttpRequest.Form)
+ {
+ HttpRequest.Form fb = (HttpRequest.Form)body;
+ Collection tmp = new ArrayList();
+ for (Iterator i = fb.getParameterNames().iterator(); i.hasNext();)
{
- String value = values[j];
- NameValuePair nvp = new NameValuePair(name, value);
- tmp.add(nvp);
+ String name = (String)i.next();
+ String[] values = fb.getParameterValues(name);
+ for (int j = 0; j < values.length; j++)
+ {
+ String value = values[j];
+ NameValuePair nvp = new NameValuePair(name, value);
+ tmp.add(nvp);
+ }
}
+ NameValuePair[] nvps = (NameValuePair[])tmp.toArray(new
NameValuePair[tmp.size()]);
+ post.setRequestBody(nvps);
}
- NameValuePair[] nvps = (NameValuePair[])tmp.toArray(new
NameValuePair[tmp.size()]);
- post.setRequestBody(nvps);
+ executeHTTPMethod(post);
+ return decodeHTTPResponse(post);
}
- executeHTTPMethod(post);
- return decodeHTTPResponse(post);
- }
- finally
- {
- if (post != null)
+ finally
{
- post.releaseConnection();
+ if (post != null)
+ {
+ post.releaseConnection();
+ }
}
}
- }
- else if (command instanceof DoGetCommand)
- {
- DoGetCommand doGetCmd = (DoGetCommand)command;
- GetMethod get = null;
- try
+ else
{
- get = new GetMethod(doGetCmd.getURL());
- HttpHeaders headers = doGetCmd.getHeaders();
- for (Iterator i = headers.headers();i.hasNext();)
+ DoGetCommand doGetCmd = (DoGetCommand)command;
+ GetMethod get = null;
+ try
{
- HttpHeader header = (HttpHeader)i.next();
- Header _header = new Header(header.getName(), header.getValue());
- get.addRequestHeader(_header);
+ get = new GetMethod(url.toString());
+ HttpHeaders headers = doGetCmd.getHeaders();
+ for (Iterator i = headers.headers();i.hasNext();)
+ {
+ HttpHeader header = (HttpHeader)i.next();
+ Header _header = new Header(header.getName(), header.getValue());
+ get.addRequestHeader(_header);
+ }
+ get.setFollowRedirects(false);
+ executeHTTPMethod(get);
+ return decodeHTTPResponse(get);
}
- get.setFollowRedirects(false);
- executeHTTPMethod(get);
- return decodeHTTPResponse(get);
- }
- finally
- {
- if (get != null)
+ finally
{
- get.releaseConnection();
+ if (get != null)
+ {
+ get.releaseConnection();
+ }
}
}
}
@@ -222,24 +233,39 @@
}
}
+ private URL getURL(URI uri) throws URISyntaxException, MalformedURLException
+ {
+ if (!uri.isAbsolute())
+ {
+ int port = driver.getPort(node);
+ uri = new URI("http://localhost:" + port).resolve(uri);
+ }
+ return uri.toURL();
+ }
+
/**
* Create an http command from an http response.
* @param responseContext
*/
protected HTTPDriverCommand createHTTPCommand(HTTPDriverResponseContext
responseContext) throws Exception
{
+
DriverResponse resp = responseContext.getResponse();
- if (resp instanceof InvokeGetResponse)
+ if (resp instanceof InvokeMethodResponse)
{
- InvokeGetResponse igr = (InvokeGetResponse)resp;
- return new DoGetCommand(igr.getURL(), igr.getHeaders());
+ if (resp instanceof InvokeGetResponse)
+ {
+ InvokeGetResponse igr = (InvokeGetResponse)resp;
+ URI uri = igr.getURI();
+ return new DoGetCommand(igr.getURI(), igr.getHeaders());
+ }
+ else
+ {
+ InvokePostResponse ipr = (InvokePostResponse)resp;
+ HttpRequest.Body dpcb = ipr.getBody();
+ return new DoPostCommand(ipr.getURI(), ipr.getContentType(), dpcb);
+ }
}
- else if (resp instanceof InvokePostResponse)
- {
- InvokePostResponse ipr = (InvokePostResponse)resp;
- HttpRequest.Body dpcb = ipr.getBody();
- return new DoPostCommand(ipr.getURL(), ipr.getContentType(), dpcb);
- }
else
{
HttpMethod method = responseContext.getHttpMethod();
@@ -307,7 +333,7 @@
{
String redirectLocation = locationHeader.getValue();
log.info("# Received '302' code --> " +
redirectLocation);
- DoGetCommand cmd = new DoGetCommand(redirectLocation);
+ DoGetCommand cmd = new DoGetCommand(new URI(redirectLocation));
// For now we don't add any contextual payload as
// 302 is some kind of implicit redirect response
@@ -332,41 +358,26 @@
private int executeHTTPMethod(HttpMethod method) throws Exception
{
int port = method.getURI().getPort();
- if (port != -1)
- {
- node = driver.getNode(port);
- if (node == null)
- {
- throw new IllegalArgumentException("Wrong port " +
method.getURI().getPort());
- }
- }
- else
- {
- port = driver.getPort(node);
- }
- //
- String host = method.getURI().getHost();
- if (host == null)
+ // Update to the next node
+ node = driver.getNode(port);
+ if (node == null)
{
- host = "localhost";
+ throw new IllegalArgumentException("Wrong port " +
method.getURI().getPort() + " in URI " + method.getURI());
}
- //
- HostConfiguration cfg = new HostConfiguration();
- cfg.setHost(host, port);
-
- //
+ // Push context to the node
pushContext();
//
- log.info("# Invoking test case over http " + cfg + " " +
method.getURI());
- int status = client.executeMethod(cfg, method);
+ log.info("# Invoking test case over http " + method.getURI());
+ int status = client.executeMethod(method);
// Force to read the response body before we close the connection
// otherwise the content will be lost
method.getResponseBody();
+
return status;
}
Added:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestDriverServer.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestDriverServer.java
(rev 0)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/HTTPTestDriverServer.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.portal.test.framework.driver.remote.RemoteTestDriverServer;
+import org.jboss.portal.test.framework.driver.remote.TestContext;
+
+/**
+ * Extends the remote test driver server to add the notion of initial path that can be
used by
+ * the tested system.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class HTTPTestDriverServer extends RemoteTestDriverServer
+{
+
+ /** . */
+ private String initialPath = "/test";
+
+ public String getInitialPath()
+ {
+ return initialPath;
+ }
+
+ public void setInitialPath(String initialPath)
+ {
+ this.initialPath = initialPath;
+ }
+
+ public void pushContext(String testId, TestContext testContext)
+ {
+ if (testContext instanceof HTTPTestContext)
+ {
+ HTTPTestContext httpTestContext = (HTTPTestContext)testContext;
+ httpTestContext.initialPath = initialPath;
+ }
+
+ //
+ super.pushContext(testId, testContext);
+ }
+}
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoGetCommand.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoGetCommand.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoGetCommand.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -24,47 +24,24 @@
import org.jboss.portal.common.http.HttpHeaders;
+import java.net.URI;
+
/**
* Perform a get.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5448 $
*/
-public class DoGetCommand extends HTTPDriverCommand
+public class DoGetCommand extends DoMethodCommand
{
- /** . */
- private String url;
-
- /** . */
- private HttpHeaders headers;
-
- public DoGetCommand(String url)
+ public DoGetCommand(URI uri, HttpHeaders headers)
{
- this(url, new HttpHeaders());
+ super(uri, headers);
}
- public DoGetCommand(String url, HttpHeaders headers)
+ public DoGetCommand(URI uri)
{
- if (url == null)
- {
- throw new IllegalArgumentException();
- }
- if (headers == null)
- {
- throw new IllegalArgumentException();
- }
- this.url = url;
- this.headers = headers;
+ super(uri);
}
-
- public String getURL()
- {
- return url;
- }
-
- public HttpHeaders getHeaders()
- {
- return headers;
- }
}
Added:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoMethodCommand.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoMethodCommand.java
(rev 0)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoMethodCommand.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * 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 org.jboss.portal.common.http.HttpHeaders;
+
+import java.net.URI;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DoMethodCommand extends HTTPDriverCommand
+{
+
+ /** . */
+ private URI uri;
+
+ /** . */
+ private HttpHeaders headers;
+
+ public DoMethodCommand(URI uri, HttpHeaders headers)
+ {
+ this.uri = uri;
+ this.headers = headers;
+ }
+
+ public DoMethodCommand(URI uri)
+ {
+ this(uri, new HttpHeaders());
+ }
+
+ public URI getURI()
+ {
+ return uri;
+ }
+
+ public HttpHeaders getHeaders()
+ {
+ return headers;
+ }
+}
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoPostCommand.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoPostCommand.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/command/DoPostCommand.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -24,39 +24,36 @@
import org.jboss.portal.common.http.HttpRequest;
+import java.net.URI;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5448 $
*/
-public class DoPostCommand extends HTTPDriverCommand
+public class DoPostCommand extends DoMethodCommand
{
- private String url;
-
+ /** . */
private String contentType;
+ /** . */
private HttpRequest.Body body;
- public DoPostCommand(String url, String contentType, HttpRequest.Body body)
+ public DoPostCommand(URI uri, String contentType, HttpRequest.Body body)
{
- if (url == null)
- {
- throw new IllegalArgumentException();
- }
+ super(uri);
+
+ //
if (body == null)
{
throw new IllegalArgumentException();
}
- this.url = url;
+
+ //
this.contentType = contentType;
this.body = body;
}
- public String getURL()
- {
- return url;
- }
-
public String getContentType()
{
return contentType;
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeGetResponse.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeGetResponse.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeGetResponse.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -25,54 +25,32 @@
import org.jboss.portal.common.http.HttpHeaders;
import org.jboss.portal.common.http.HttpHeader;
+import java.net.URI;
+import java.net.URISyntaxException;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @author <a href="mailto:boleslaw.dawidowicz@jboss.com">Boleslaw
Dawidowicz</a>
* @version $Revision: 5448 $
*/
-public class InvokeGetResponse extends HTTPDriverResponse
+public class InvokeGetResponse extends InvokeMethodResponse
{
/** The serialVersionUID */
private static final long serialVersionUID = 5968471624915140976L;
- /** . */
- private String url;
-
- /** . */
- private HttpHeaders headers;
-
public InvokeGetResponse(String url)
{
- if (url == null)
- {
- throw new IllegalArgumentException("Cannot invoke against a null
URL");
- }
- this.url = url;
- this.headers = new HttpHeaders();
+ super(url);
}
- public String getURL()
+ public InvokeGetResponse(URI uri)
{
- return url;
+ super(uri);
}
- public HttpHeader addHeader(String headerName)
- {
- if (headerName == null)
- {
- throw new IllegalArgumentException("No null header name accepted");
- }
- return headers.addHeader(headerName);
- }
-
- public HttpHeaders getHeaders()
- {
- return headers;
- }
-
public String toString()
{
- return "InvokeGet[url=" + url + "]";
+ return "InvokeGet[uri=" + getURI() + "]";
}
}
Added:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeMethodResponse.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeMethodResponse.java
(rev 0)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokeMethodResponse.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -0,0 +1,103 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.portal.common.http.HttpHeaders;
+import org.jboss.portal.common.http.HttpHeader;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class InvokeMethodResponse extends HTTPDriverResponse
+{
+
+ /** . */
+ private URI uri;
+
+ /** . */
+ private HttpHeaders headers;
+
+ public InvokeMethodResponse(String uri) throws IllegalArgumentException
+ {
+ if (uri == null)
+ {
+ throw new IllegalArgumentException("Cannot invoke against a null
URL");
+ }
+
+ //
+ URI tmp;
+ try
+ {
+ tmp = new URI(uri);
+ }
+ catch (URISyntaxException e)
+ {
+ IllegalArgumentException iae = new IllegalArgumentException("Wrong URI
syntax");
+ iae.initCause(e);
+ throw iae;
+ }
+
+ //
+ if (tmp.isOpaque())
+ {
+ throw new IllegalArgumentException("No opaque URI accepted");
+ }
+
+ //
+ this.uri = tmp;
+ this.headers = new HttpHeaders();
+ }
+
+ public InvokeMethodResponse(URI uri) throws IllegalArgumentException
+ {
+ if (uri == null)
+ {
+ throw new IllegalArgumentException("Cannot invoke against a null
URL");
+ }
+ this.uri = uri;
+ this.headers = new HttpHeaders();
+ }
+
+ public URI getURI()
+ {
+ return uri;
+ }
+
+ public HttpHeader addHeader(String headerName)
+ {
+ if (headerName == null)
+ {
+ throw new IllegalArgumentException("No null header name accepted");
+ }
+ return headers.addHeader(headerName);
+ }
+
+ public HttpHeaders getHeaders()
+ {
+ return headers;
+ }
+}
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokePostResponse.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokePostResponse.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/driver/http/response/InvokePostResponse.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -24,13 +24,16 @@
import org.jboss.portal.common.http.HttpRequest;
+import java.net.URISyntaxException;
+import java.net.URI;
+
/**
* The portlet wants to invoke a post.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5448 $
*/
-public class InvokePostResponse extends HTTPDriverResponse
+public class InvokePostResponse extends InvokeMethodResponse
{
/** The serialVersionUID */
@@ -42,23 +45,20 @@
/** . */
public static final String MULTIPART_FORM_DATA = "multipart/form-data";
- /** The post url. */
- private String url;
-
/** The content type. */
private String contentType;
/** The post body. */
private HttpRequest.Body body;
- public String getURL()
+ public InvokePostResponse(String uri)
{
- return url;
+ super(uri);
}
- public void setURL(String url)
+ public InvokePostResponse(URI uri)
{
- this.url = url;
+ super(uri);
}
public HttpRequest.Body getBody()
@@ -83,6 +83,6 @@
public String toString()
{
- return "InvokePost[url=" + url + "]";
+ return "InvokePost[uri=" + getURI() + "]";
}
}
Modified:
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/server/NodeId.java
===================================================================
---
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/server/NodeId.java 2007-08-30
18:31:08 UTC (rev 8112)
+++
modules/test/trunk/test/src/main/org/jboss/portal/test/framework/server/NodeId.java 2007-08-30
19:41:05 UTC (rev 8113)
@@ -85,11 +85,37 @@
*/
public static NodeId locate() throws IllegalStateException
{
- String serverName = System.getProperty("jboss.server.name");
- if (serverName == null)
+ // Legacy jboss server name
+ String nodeName = System.getProperty("jboss.server.name");
+
+ // Otherwise use a system property specified in the command line
+ if (nodeName != null)
{
- throw new IllegalStateException("Not in a node context");
+ nodeName = System.getProperty("test.node.name");
}
- return new NodeId(serverName);
+
+ // If nothing is specified we assume it is the default one
+ if (nodeName == null)
+ {
+ nodeName = "default";
+ }
+
+ //
+ if ("default".equals(nodeName))
+ {
+ return DEFAULT;
+ }
+ else if ("ports-01".equals(nodeName))
+ {
+ return PORTS_01;
+ }
+ else if ("ports-02".equals(nodeName))
+ {
+ return PORTS_02;
+ }
+ else
+ {
+ throw new IllegalStateException("Cannot determine node id " +
nodeName);
+ }
}
}