Author: pete.muir(a)jboss.org
Date: 2009-03-05 19:09:59 -0500 (Thu, 05 Mar 2009)
New Revision: 1777
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/util/Servlet.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/Dog.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/InjectionIntoServletTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/TestServlet.java
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/beans.xml
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/web.xml
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractDeclarativeTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/ArtifactGenerator.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/IntegrationTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/jsr299/TCKArtifactDescriptor.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/NonContextualInjectionTest.java
Log:
Add a test for servlet injection (ri-broken here though)
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractDeclarativeTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractDeclarativeTest.java 2009-03-05
22:36:08 UTC (rev 1776)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractDeclarativeTest.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -225,10 +225,10 @@
{
testResult.setThrowable(deploymentException.getCause());
}
- else if (!isDeployToContainerNeeded() && !skipTest)
+ else if ((!isDeployToContainerNeeded() || artifact.isRunLocally()) &&
!skipTest)
{
callback.runTestMethod(testResult);
- if (!getCurrentConfiguration().isStandalone() && !isInContainer())
+ if (!getCurrentConfiguration().isStandalone() && !isInContainer()
&& !artifact.isRunLocally())
{
log.warn("Running testcase locally " + testResult.getMethod());
}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractTest.java 2009-03-05
22:36:08 UTC (rev 1776)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/AbstractTest.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -86,11 +86,6 @@
{
getCurrentConfiguration().getContexts().destroyContext(context);
}
-
- public AbstractTest()
- {
- super();
- }
protected static Configuration getCurrentConfiguration()
{
@@ -113,4 +108,9 @@
}
}
+ public String getContextPath()
+ {
+ return "http://" + getCurrentConfiguration().getHost() + "/" +
this.getClass().getName() + "/";
+ }
+
}
\ No newline at end of file
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/ArtifactGenerator.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/ArtifactGenerator.java 2009-03-05
22:36:08 UTC (rev 1776)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/ArtifactGenerator.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -31,6 +31,7 @@
private static final Logger log = Logger.getLogger(ArtifactProcessor.class);
private final boolean unit;
+ private final boolean runLocally;
private final boolean addDeclaringPackage;
private final String beansXml;
private final PackagingType packagingType;
@@ -78,10 +79,12 @@
if (declaringClass.isAnnotationPresent(IntegrationTest.class))
{
this.unit = false;
+ this.runLocally =
declaringClass.getAnnotation(IntegrationTest.class).runLocally();
}
else
{
this.unit = true;
+ this.runLocally = false;
}
if (declaringClass.isAnnotationPresent(Resources.class))
@@ -146,8 +149,11 @@
{
final TCKArtifactDescriptor artifact = newArtifact(packagingType,
declaringClass, beansXml, standalone, addDeclaringPackage);
artifact.setUnit(unit);
+ artifact.setRunLocally(runLocally);
artifact.setExpectedDeploymentException(expectedDeploymentException);
artifact.getClasses().addAll(classes);
+ // Annoying hack
+ artifact.getResources().removeAll(resources);
artifact.getResources().addAll(resources);
artifact.getLibraries().addAll(extraLibraries);
return artifact;
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/IntegrationTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/IntegrationTest.java 2009-03-05
22:36:08 UTC (rev 1776)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/IntegrationTest.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -21,4 +21,6 @@
public @interface IntegrationTest
{
+ boolean runLocally() default false;
+
}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/jsr299/TCKArtifactDescriptor.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/jsr299/TCKArtifactDescriptor.java 2009-03-05
22:36:08 UTC (rev 1776)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/packaging/jsr299/TCKArtifactDescriptor.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -40,6 +40,7 @@
private static final Logger log = Logger.getLogger(TCKArtifactDescriptor.class);
private boolean unit;
+ private boolean runLocally;
private Class<? extends Throwable> expectedDeploymentException;
public TCKArtifactDescriptor(Class<?> declaringClass, String
beansXmlSourceFileName)
@@ -113,4 +114,14 @@
this.expectedDeploymentException = expectedDeploymentException;
}
+ public boolean isRunLocally()
+ {
+ return runLocally;
+ }
+
+ public void setRunLocally(boolean runLocally)
+ {
+ this.runLocally = runLocally;
+ }
+
}
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/util/Servlet.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/util/Servlet.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/util/Servlet.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -0,0 +1,85 @@
+package org.jboss.jsr299.tck.impl.util;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class Servlet
+{
+
+ public static abstract class ServletConnection
+ {
+
+ private final long connectTimeout;
+ private final URL url;
+ private HttpURLConnection connection;
+
+ public ServletConnection(long connectTimeout, URL url)
+ {
+ this.connectTimeout = connectTimeout;
+ this.url = url;
+ }
+
+ private void init() throws IOException
+ {
+ long timeoutTime = System.currentTimeMillis() + connectTimeout;
+ boolean interrupted = false;
+ while (timeoutTime > System.currentTimeMillis())
+ {
+ URLConnection connection = url.openConnection();
+ if (!(connection instanceof HttpURLConnection))
+ {
+ throw new IllegalStateException("Not an http connection! " +
connection);
+ }
+ this.connection = (HttpURLConnection) connection;
+ this.connection.setUseCaches(false);
+ this.connection.setDefaultUseCaches(false);
+ connection.connect();
+ if (this.connection.getResponseCode() == HttpURLConnection.HTTP_OK)
+ {
+ return;
+ }
+ try
+ {
+ Thread.sleep(200);
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ }
+ if (interrupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ protected HttpURLConnection getConnection()
+ {
+ return connection;
+ }
+
+ private void cleanup()
+ {
+ this.connection.disconnect();
+ }
+
+ protected abstract void execute() throws Exception;
+
+ public void run() throws Exception
+ {
+ try
+ {
+ init();
+ execute();
+ }
+ finally
+ {
+ cleanup();
+ }
+ }
+
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/impl/util/Servlet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/NonContextualInjectionTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/NonContextualInjectionTest.java 2009-03-05
22:36:08 UTC (rev 1776)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/NonContextualInjectionTest.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -51,11 +51,5 @@
assert false;
}
- @Test(groups = { "stub", "integration" })
- @SpecAssertion(section = "5.12.3", id = "a")
- public void testInjectionIntoServlet()
- {
- assert false;
- }
}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/Dog.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/Dog.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/Dog.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.lookup.nonContextual.servlet;
+
+public class Dog
+{
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/Dog.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/InjectionIntoServletTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/InjectionIntoServletTest.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/InjectionIntoServletTest.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -0,0 +1,42 @@
+package org.jboss.jsr299.tck.tests.lookup.nonContextual.servlet;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+import org.jboss.jsr299.tck.AbstractDeclarativeTest;
+import org.jboss.jsr299.tck.impl.packaging.Artifact;
+import org.jboss.jsr299.tck.impl.packaging.IntegrationTest;
+import org.jboss.jsr299.tck.impl.packaging.Resource;
+import org.jboss.jsr299.tck.impl.packaging.Resources;
+import org.jboss.jsr299.tck.impl.packaging.war.WarArtifactDescriptor;
+import org.jboss.jsr299.tck.impl.util.Servlet;
+import org.testng.annotations.Test;
+
+@Artifact
+@IntegrationTest(runLocally=true)
+@Resources({
+ @Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION,
source="web.xml")
+})
+public class InjectionIntoServletTest extends AbstractDeclarativeTest
+{
+
+ @Test(groups = { "ri-broken", "integration" })
+ @SpecAssertion(section = "5.12.3", id = "a")
+ public void testInjectionIntoServlet() throws Exception
+ {
+ new Servlet.ServletConnection(getCurrentConfiguration().getConnectTimeout(), new
URL(getContextPath()))
+ {
+
+ @Override
+ protected void execute() throws IOException
+ {
+ assert getConnection().getResponseCode() == HttpServletResponse.SC_OK;
+ }
+
+ }.run();
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/InjectionIntoServletTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/TestServlet.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/TestServlet.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/TestServlet.java 2009-03-06
00:09:59 UTC (rev 1777)
@@ -0,0 +1,29 @@
+package org.jboss.jsr299.tck.tests.lookup.nonContextual.servlet;
+
+import java.io.IOException;
+
+import javax.inject.Current;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class TestServlet extends HttpServlet
+{
+
+ @Current Dog dog;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ if (dog == null)
+ {
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ else
+ {
+ resp.setStatus(HttpServletResponse.SC_OK);
+ }
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/TestServlet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/beans.xml
===================================================================
---
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/beans.xml
(rev 0)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/beans.xml 2009-03-06
00:09:59 UTC (rev 1777)
@@ -0,0 +1,7 @@
+<Beans xmlns="urn:java:ee"
+
xmlns:test="urn:java:org.jboss.jsr299.tck.tests.lookup.nonContextual">
+ <Deploy>
+ <Standard />
+ <Production />
+ </Deploy>
+</Beans>
Property changes on:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/beans.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/web.xml
===================================================================
---
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/web.xml
(rev 0)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/web.xml 2009-03-06
00:09:59 UTC (rev 1777)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.5"
+
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <display-name>JSR-299 TCK</display-name>
+
+ <servlet>
+ <servlet-name>JSR-299 Servlet Injection Test</servlet-name>
+
<servlet-class>org.jboss.jsr299.tck.tests.lookup.nonContextual.servlet.TestServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JSR-299 Servlet Injection Test</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
Property changes on:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/lookup/nonContextual/servlet/web.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain