org.jboss.seam.mock
public class ResourceRequestEnvironment extends Object
This class is supposed to be used within a SeamTest, in fact, you need to pass an instance of SeamTest into its constructor. This prepares the environment for the resource request processing. You can either share an instance of the environment between all your test methods (prepare it in @BeforeClass) or you can create a new instance for each ResourceRequest:
import org.jboss.seam.mock.ResourceRequestEnvironment; import org.jboss.seam.mock.EnhancedMockHttpServletRequest; import org.jboss.seam.mock.EnhancedMockHttpServletResponse; import static org.jboss.seam.mock.ResourceRequestEnvironment.ResourceRequest; import static org.jboss.seam.mock.ResourceRequestEnvironment.Method; public class MyTest extends SeamTest { ResourceRequestEnvironment sharedEnvironment; @BeforeClass public void prepareSharedEnvironment() throws Exception { sharedEnvironment = new ResourceRequestEnvironment(this) { @Override public MapgetDefaultHeaders() { return new HashMap () {{ put("Accept", "text/plain"); }}; } }; } @Test public void test() throws Exception { //Not shared: new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, "/my/relative/uri) new ResourceRequest(sharedEnvironment, Method.GET, "/my/relative/uri) { @Override protected void prepareRequest(EnhancedMockHttpServletRequest request) { request.addQueryParameter("foo", "123"); request.addHeader("Accept-Language", "en_US, de"); } @Override protected void onResponse(EnhancedMockHttpServletResponse response) { assert response.getStatus() == 200; assert response.getContentAsString().equals("foobar"); } }.run(); } }
Note that in a SeamTest the (mock) HTTP session is always shared between all requests in a particular test method. Each test method however executes with a new (mock) HTTP session. Design your tests accordingly, this is not configurable.
IMPORTANT: A ResourceRequest has to be executed in a @Test method or in a @BeforeMethod callback. You can not execute it in any other callback, such * as @BeforeClass.
Modifier and Type | Class and Description |
---|---|
static class |
ResourceRequestEnvironment.Method |
static class |
ResourceRequestEnvironment.ResourceRequest |
Modifier and Type | Field and Description |
---|---|
protected SeamResourceServlet |
resourceServlet |
protected AbstractSeamTest |
seamTest |
Constructor and Description |
---|
ResourceRequestEnvironment(AbstractSeamTest seamTest) |
protected final AbstractSeamTest seamTest
protected final SeamResourceServlet resourceServlet
public ResourceRequestEnvironment(AbstractSeamTest seamTest)
Copyright © 2015 Seam Framework. All Rights Reserved.