[seam-commits] Seam SVN: r13010 - in branches/community/Seam_2_2: examples/restbay/src/org/jboss/seam/example/restbay/test and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Jun 3 08:18:06 EDT 2010
Author: jharting
Date: 2010-06-03 08:18:05 -0400 (Thu, 03 Jun 2010)
New Revision: 13010
Added:
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/ContextDataResource.java
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/ContextDataTest.java
Modified:
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
branches/community/Seam_2_2/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java
Log:
JBSEAM-4642
Added: branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/ContextDataResource.java
===================================================================
--- branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/ContextDataResource.java (rev 0)
+++ branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/ContextDataResource.java 2010-06-03 12:18:05 UTC (rev 13010)
@@ -0,0 +1,35 @@
+package org.jboss.seam.example.restbay.resteasy;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.ext.Providers;
+
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+
+ at Path("/contextData")
+ at Produces("text/plain")
+public class ContextDataResource
+{
+ @GET
+ @Path("/providers")
+ public boolean providersAvailable()
+ {
+ return ResteasyProviderFactory.getContextData(Providers.class) != null;
+ }
+
+ @GET
+ @Path("/registry")
+ public boolean registryAvailable()
+ {
+ return ResteasyProviderFactory.getContextData(Providers.class) != null;
+ }
+
+ @GET
+ @Path("/dispatcher")
+ public boolean dispatcherAvailable()
+ {
+ return ResteasyProviderFactory.getContextData(Providers.class) != null;
+ }
+
+}
Added: branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/ContextDataTest.java
===================================================================
--- branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/ContextDataTest.java (rev 0)
+++ branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/ContextDataTest.java 2010-06-03 12:18:05 UTC (rev 13010)
@@ -0,0 +1,50 @@
+package org.jboss.seam.example.restbay.test;
+
+import static org.testng.Assert.assertEquals;
+
+import org.jboss.seam.mock.EnhancedMockHttpServletRequest;
+import org.jboss.seam.mock.EnhancedMockHttpServletResponse;
+import org.jboss.seam.mock.ResourceRequestEnvironment;
+import org.jboss.seam.mock.SeamTest;
+import org.jboss.seam.mock.ResourceRequestEnvironment.Method;
+import org.jboss.seam.mock.ResourceRequestEnvironment.ResourceRequest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Jozef Hartinger
+ */
+public class ContextDataTest extends SeamTest
+{
+ @DataProvider(name = "contextDataTypes")
+ public Object[][] getContextDataTypePaths()
+ {
+ return new String[][]{ { "/providers" }, { "/registry" }, { "/dispatcher" } };
+ }
+
+ @Test(dataProvider = "contextDataTypes")
+ public void testContextData(String pathSegment) throws Exception
+ {
+ final String path = "/restv1/contextData" + pathSegment;
+
+ new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, path)
+ {
+
+ @Override
+ protected void prepareRequest(EnhancedMockHttpServletRequest request)
+ {
+ super.prepareRequest(request);
+ request.addHeader("Accept", "text/plain");
+ }
+
+ @Override
+ protected void onResponse(EnhancedMockHttpServletResponse response)
+ {
+ assertEquals(response.getStatus(), 200, "Unexpected response code.");
+ assertEquals(response.getContentAsString(), "true", "Unexpected response.");
+ }
+
+ }.run();
+ }
+}
Modified: branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
===================================================================
--- branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml 2010-06-03 10:02:18 UTC (rev 13009)
+++ branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml 2010-06-03 12:18:05 UTC (rev 13010)
@@ -37,6 +37,12 @@
<class name="org.jboss.seam.example.restbay.test.SubresourceTest"/>
</classes>
</test>
+
+ <test name="RestBay Context Data">
+ <classes>
+ <class name="org.jboss.seam.example.restbay.test.ContextDataTest"/>
+ </classes>
+ </test>
<test name="RestBay DBUnit Integration">
Modified: branches/community/Seam_2_2/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java
===================================================================
--- branches/community/Seam_2_2/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java 2010-06-03 10:02:18 UTC (rev 13009)
+++ branches/community/Seam_2_2/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java 2010-06-03 12:18:05 UTC (rev 13010)
@@ -26,7 +26,9 @@
import org.jboss.resteasy.core.ThreadLocalResteasyProviderFactory;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory;
+import org.jboss.resteasy.spi.Registry;
import org.jboss.resteasy.spi.ResourceFactory;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.StringConverter;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
@@ -53,8 +55,11 @@
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import javax.ws.rs.ext.Providers;
+
/**
* Detects (through scanning and configuration) JAX-RS resources and providers, then
* registers them with RESTEasy.
@@ -108,6 +113,13 @@
// TODO: How does that actually work? It's never used because the dispatcher is created with the original one
SeamResteasyProviderFactory.setInstance(new ThreadLocalResteasyProviderFactory(providerFactory));
+ // Put Providers, Registry and Dispatcher into RESTEasy context.
+ dispatcher.getDefaultContextObjects().put(Providers.class, providerFactory);
+ dispatcher.getDefaultContextObjects().put(Registry.class, dispatcher.getRegistry());
+ dispatcher.getDefaultContextObjects().put(Dispatcher.class, dispatcher);
+ Map contextDataMap = SeamResteasyProviderFactory.getContextDataMap();
+ contextDataMap.putAll(dispatcher.getDefaultContextObjects());
+
// Seam can scan the classes for us, we just have to list them in META-INF/seam-deployment.properties
DeploymentStrategy deployment = (DeploymentStrategy) Component.getInstance("deploymentStrategy");
AnnotationDeploymentHandler handler =
More information about the seam-commits
mailing list