views:

39

answers:

2

This is my pom.xml (part of it):

[...]
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-server</artifactId>
  <version>${jersey.version}</version>
</dependency>
<dependency>
  <groupId>com.sun.jersey.jersey-test-framework</groupId>
  <artifactId>jersey-test-framework-embedded-glassfish</artifactId>
  <version>${jersey.version}</version>
  <scope>test</scope>
</dependency>
[...]

This is the test:

public class FooTest extends JerseyTest {
  public FooTest() throws Exception {
    super("com.XXX");
  }
  @Before
  public void setUp() throws Exception {
  }
  @Test
  public void shouldWork() throws Exception {
  }
}

This is what I'm getting in the log:

com.sun.jersey.test.framework.spi.container.TestContainerException: org.glassfish.embed.EmbeddedException: You must start the server before calling this API method: EmbeddedDeployer.EmbeddedDeployer Constructor.
at com.sun.jersey.test.framework.spi.container.embedded.glassfish.EmbeddedGlassFishTestContainerFactory$EmbeddedGlassFishTestContainer.stop(EmbeddedGlassFishTestContainerFactory.java:154)
at com.sun.jersey.test.framework.JerseyTest.tearDown(JerseyTest.java:312)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]

When I remove setUp() method from the class everything works fine. What's wrong here?

+1  A: 

You are unintentionally overriding its setUp() method. Try changing its name to something else, why not say it, before().

The original setUp() method invokes test container by calling TestContainer.start(). In your case it couldn't do that, because you overrided the method and never made any call to super.setUp(). Therefore, its complaining that, You must start the server.... so and so.

Adeel Ansari
@Vincenzo: I said unintentionally, because one would expect `@Override` over it if its intentional. ;D
Adeel Ansari
@Adeel Yes, thank you very much, now I see the problem. And it's already fixed :) I up-voted your answer.
Vincenzo
Thanks for that. I really appreciate.
Adeel Ansari
+1  A: 

Try super.setUp(); in setup.

When you remove it it will call its inherited version of super. which is fine.

But as you add your own setUp you have overridden the super's version .

org.life.java