You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/03/15 22:17:05 UTC
svn commit: r923444 - in /openwebbeans/trunk/webbeans-porting: pom.xml
src/main/java/org/apache/webbeans/test/tck/ContainersImpl.java
src/main/java/org/apache/webbeans/test/tck/TomcatConnector.java
Author: gerdogdu
Date: Mon Mar 15 21:16:59 2010
New Revision: 923444
URL: http://svn.apache.org/viewvc?rev=923444&view=rev
Log:
WebProfile testing support
Added:
openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/TomcatConnector.java (with props)
Modified:
openwebbeans/trunk/webbeans-porting/pom.xml
openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContainersImpl.java
Modified: openwebbeans/trunk/webbeans-porting/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-porting/pom.xml?rev=923444&r1=923443&r2=923444&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-porting/pom.xml (original)
+++ openwebbeans/trunk/webbeans-porting/pom.xml Mon Mar 15 21:16:59 2010
@@ -65,6 +65,13 @@
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
Modified: openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContainersImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContainersImpl.java?rev=923444&r1=923443&r2=923444&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContainersImpl.java (original)
+++ openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContainersImpl.java Mon Mar 15 21:16:59 2010
@@ -13,68 +13,85 @@
*/
package org.apache.webbeans.test.tck;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.util.HttpURLConnection;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.jboss.testharness.api.DeploymentException;
import org.jboss.testharness.spi.Containers;
-public class ContainersImpl implements Containers
+public class ContainersImpl extends TomcatConnector implements Containers
{
- public static final String TOMCAT_LOCATION = "catalina.home";
-
- private WebBeansLogger logger = WebBeansLogger.getLogger(ContainersImpl.class);
-
- public void cleanup() throws IOException
+ private HttpClient client = null;
+
+ private DeploymentException excepton = null;
+
+ public ContainersImpl() throws IOException
{
-
+ super();
+ client = new HttpClient();
+ client = new HttpClient();
+ client.getParams().setAuthenticationPreemptive(true);
+ Credentials credentials = new UsernamePasswordCredentials("tests", "secret");
+ client.getState().setCredentials(new AuthScope(null, 8080, null), credentials);
}
- public boolean deploy(InputStream archive, String name)
+ /* (non-Javadoc)
+ * @see org.jboss.testharness.integration.tomcat.TomcatConnector#deploy(java.io.InputStream, java.lang.String)
+ */
+ @Override
+ public boolean deploy(InputStream stream, String name) throws IOException
{
- logger.info("Deploying artifact with name : " + name + " to container");
-
- try
+ boolean result = super.deploy(stream, name);
+ if(result)
{
- if (archive.available() > 0)
+ GetMethod method = null;
+ try
{
- File file = new File("target/container/" + name);
- FileOutputStream os = new FileOutputStream(file);
- byte temp[] = new byte[512];
-
- while (archive.read(temp) != -1)
+ method = new GetMethod("http://localhost:8080/manager/list");
+ int r = client.executeMethod(method);
+ if(r == HttpURLConnection.HTTP_OK)
{
- os.write(temp);
+ String string = method.getResponseBodyAsString();
+ int start = string.indexOf(getContextName(name)+":running");
+
+ if(start == -1)
+ {
+ this.excepton = new DeploymentException("Deployment Failure",new WebBeansConfigurationException("Deployment Failure"));
+ return false;
+ }
}
- os.close();
-
+ }finally
+ {
+ method.releaseConnection();
}
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- return false;
- }
-
- public void setup() throws IOException
- {
-
- }
-
- public void undeploy(String name) throws IOException
- {
-
+
+ return result;
}
+ /* (non-Javadoc)
+ * @see org.jboss.testharness.integration.tomcat.TomcatConnector#getDeploymentException()
+ */
+ @Override
public DeploymentException getDeploymentException()
{
- // TODO Auto-generated method stub
- return null;
+ if(this.excepton != null)
+ {
+ return this.excepton;
+ }
+
+ return super.getDeploymentException();
}
+
+
+
}
Added: openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/TomcatConnector.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/TomcatConnector.java?rev=923444&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/TomcatConnector.java (added)
+++ openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/TomcatConnector.java Mon Mar 15 21:16:59 2010
@@ -0,0 +1,146 @@
+package org.apache.webbeans.test.tck;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.jboss.testharness.api.DeploymentException;
+import org.jboss.testharness.spi.Containers;
+import org.jboss.testharness.spi.helpers.AbstractContainerConnector;
+
+public class TomcatConnector extends AbstractContainerConnector implements Containers
+{
+
+ private WebBeansLogger logger = WebBeansLogger.getLogger(TomcatConnector.class);
+
+ private static final String SERVER_HOME_PROPERTY_NAME = "tomcat.home";
+
+ private String binDirectory;
+ private final File tmpdir;
+ private final HttpClient client;
+
+ private DeploymentException deploymentException;
+
+ public TomcatConnector() throws IOException
+ {
+ logger.info("You must add the the tests/secret user to Tomcat, for example, in $CATALINA_BASE/conf/tomcat-users.xml add <user name=\"tests\" password=\"secret\" roles=\"standard,manager\" />");
+ tmpdir = new File(System.getProperty("java.io.tmpdir"), "org.jboss.webbeans.tck.integration.jbossas");
+ tmpdir.mkdir();
+ tmpdir.deleteOnExit();
+ client = new HttpClient();
+ client.getParams().setAuthenticationPreemptive(true);
+ Credentials credentials = new UsernamePasswordCredentials("tests", "secret");
+ client.getState().setCredentials(new AuthScope(null, 8080, null), credentials);
+ }
+
+ @Override
+ protected String getServerHomePropertyName()
+ {
+ return SERVER_HOME_PROPERTY_NAME;
+ }
+
+ @Override
+ protected void shutdownServer() throws IOException
+ {
+ launch(getBinDirectory(), "shutdown", "");
+ }
+
+ @Override
+ protected void startServer() throws IOException
+ {
+ launch(getBinDirectory(), "startup", "");
+ }
+
+ protected String getBinDirectory()
+ {
+ if (binDirectory == null)
+ {
+ binDirectory = new File(getServerDirectory() + "/bin").getPath();
+ }
+ return binDirectory;
+ }
+
+ @Override
+ protected String getLogName()
+ {
+ return "tomcat.log";
+ }
+
+ public boolean deploy(InputStream stream, String name) throws IOException
+ {
+ String deployUrl = getManagerUrl("deploy", "path=/" + getContextName(name), "update=true");
+ PutMethod put = new PutMethod(deployUrl);
+ put.setRequestEntity(new InputStreamRequestEntity(stream));
+ try
+ {
+ int status = client.executeMethod(put);
+ if (status != HttpURLConnection.HTTP_OK)
+ {
+ deploymentException = getDeploymentExceptionTransformer().transform(new DeploymentException(new String(put.getResponseBody())));
+ return false;
+ }
+ return true;
+ }
+ finally
+ {
+ put.releaseConnection();
+ }
+ }
+
+ public DeploymentException getDeploymentException()
+ {
+ return deploymentException;
+ }
+
+ public void undeploy(String name) throws IOException
+ {
+ String deployUrl = getManagerUrl("undeploy", "path=/" + getContextName(name));
+ HttpMethod get = new GetMethod(deployUrl);
+ try
+ {
+ int status = client.executeMethod(get);
+ if (status != HttpURLConnection.HTTP_OK)
+ {
+ throw new IllegalStateException(new String(get.getResponseBody()));
+ }
+ }
+ finally
+ {
+ get.releaseConnection();
+ }
+ }
+
+ protected String getManagerUrl(String command, String... parameters)
+ {
+ String url = getHttpUrl() + "manager/" + command ;
+ for (int i = 0; i < parameters.length; i ++)
+ {
+ String parameter = parameters[i];
+ if (i == 0)
+ {
+ url += "?" + parameter;
+ }
+ else
+ {
+ url += "&" + parameter;
+ }
+ }
+ return url;
+ }
+
+ protected String getContextName(String name)
+ {
+ return name.substring(0, name.length() - 4);
+ }
+
+}
\ No newline at end of file
Propchange: openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/TomcatConnector.java
------------------------------------------------------------------------------
svn:eol-style = native