On 5/25/10 3:24 PM, Bruno Cardoso wrote:
> Hi Pavel,
>
> This is what I did:
>
> Created a scenario class normally:
>
> *public class* TestScenario *extends *Scenario {
>
> public TestScenario() {
> super(new TestStep());
> }
> }
>
>
> Then I created my Step:
>
> *public class* TestStep *extends *Steps {
> private BaseJerseyTest jerseyTest;
>
> public TestStep() {
> jerseyTest = new BaseJerseyTest();
> }
>
> @Given("something")
> public void givenSomething() {
> System.out.println("give something");
> }
>
> @When("something")
> public void whenSomething() {
> System.out.println("when something");
> }
>
> @Then("something")
> public void thenSomething() {
> System.out.println("then something");
>
> WebResource webResource = jerseyTest.resource();
> Client client = webResource.path("/clients/1") //
> .type(MediaType.APPLICATION_XML) //
> .get(Client.class);
>
> Assert.assertNotNull("Should have returned a client
> name!", client.getName());
> Assert.assertEquals("Should have matched the client name",
> "Bruno Cardoso", client.getName());
> }
> }
>
>
> In my step I create an instance of JerseyTest
>
> public class BaseJerseyTest extends JerseyTest {
>
> public BaseJerseyTest() {
> super(new
> WebAppDescriptor.Builder("com.sun.jersey.samples.springannotations.resources.jerseymanaged")
> //
> .contextPath(CONTEXT_PATH) //
> .contextParam("contextConfigLocation",
> "classpath:/spring/domain-bootstrap-context.xml") //
> .servletClass(SpringServlet.class) //
> .contextListenerClass(ContextLoaderListener.class) //
> .build());
> }
> }
>
>
> This should work, using an external container for this test works fine:
>
> -Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory
> -Djersey.test.port=8080 -Djersey.test.host=localhost
>
> But, if i try using grizzly doesn't work:
> -Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory
Do you have some error message/stacktrace?
And.. I noticed you don't call setUp and tearDown methods; you should do
something like:
public TestStep() {
jerseyTest = new BaseJerseyTest();
jerseyTest.setUp();
}
Finding correct place for tearDown call might be little challenge, but
I'd suspect that JBehave has something similar like JUnits @After.
Pavel
>
> Any idea why this happens?
>
> If I create a test JUnit class extending BaseJersey, both tests work
> fine, external and grizzly but with JBehave, I'm having problems
> getting grizzly to work.
>
> Thanks
>
> On Tue, May 25, 2010 at 1:33 PM, Pavel Bucek <Pavel.Bucek_at_sun.com
> <mailto:Pavel.Bucek_at_sun.com>> wrote:
>
> Hello Bruno,
>
> I guess you probably can subclass JerseyTest in your
> org.jbehave.scenario.Scenario descendant, call manually
> JerseyTest.setUp() method in init phase, perform your tests and
> call JerseyTest.tearDown().
>
> It would not be as clear as simple Jersey or JBehave test but it
> should work.
>
> Regards,
> Pavel
>
>
> On 5/25/10 12:30 PM, Bruno Cardoso wrote:
>
> Hi
>
> Is it possible to integrate both frameworks? Is it possible to
> create a Jersey Testcase without extending JerseyTest ?
> because JBehave already forces you to extend
> org.jbehave.scenario.Scenario.
>
> Thanks
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> <mailto:users-unsubscribe_at_jersey.dev.java.net>
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> <mailto:users-help_at_jersey.dev.java.net>
>
>