I have a maven multi-module project defined with these modules:
MyClient - a custom client that uses jersey client.
TestServer - a Jersey server to use for integration tests.
IntegrationTests - test MyClient using TestServer.
In TestServer, I use JerseyTest to exercise the test server and it
works great.
In IntegrationTests, I wish to use JerseyTest to run the TestServer and
test MyClient. This does not work for me. Here's part of my test code.
I'm just seeing if I can hit the server at this point:
public class RestClientTest extends JerseyTest {
WebResource webResource;
public RestClientTest() throws Exception {
super("com.zzz.rest", "com.zzz.model");
webResource = resource();
}
@Test
public void serverTest() {
GenericType<Collection<User>> genericTypeUsers = new
GenericType<Collection<User>>() {};
webResource.path("weblogs").get(genericTypeUsers);
}
This identical code works in the TestServer project, but not in the
IntegrationTest project. I get the exception below. Is what I am trying
to do even possible? If so, how do I get it to work?
com.sun.jersey.api.client.ClientHandlerException:
java.net.ConnectException: Connection refused
at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(U
RLConnectionClientHandler.java:131)
at com.sun.jersey.api.client.Client.handle(Client.java:616)
at
com.sun.jersey.api.client.WebResource.handle(WebResource.java:570)
at
com.sun.jersey.api.client.WebResource.get(WebResource.java:186)
at
com.overstock.rest.client.RestClientTest.serverTest(RestClientTest.java
:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
va:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
rImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMe
thod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCalla
ble.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMeth
od.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMetho
d.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.ja
va:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java
:31)
at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4Class
Runner.java:79)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunne
r.java:71)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunne
r.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4Te
stReference.java:49)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.j
ava:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteT
estRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteT
estRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRu
nner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestR
unner.java:197)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at
sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLCon
nection.java:970)
at
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnect
ion.java:911)
at
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.j
ava:836)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConne
ction.java:1172)
at
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(
URLConnectionClientHandler.java:218)
at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(U
RLConnectionClientHandler.java:129)
... 29 more