Integration tests with REST Assured and Jetty -


i have rest api running in jetty using eclipse' jetty maven plugin; , use rest-assured integration test. kept failing due connection refused. double checked rest-assured dependencies date, im wondering if jetty running during phase. here code:

dependencies:

<dependency>   <groupid>com.jayway.restassured</groupid>   <artifactid>rest-assured</artifactid>   <version>2.8.0</version>   <scope>test</scope> </dependency> <dependency>   <groupid>org.apache.httpcomponents</groupid>   <artifactid>httpclient</artifactid>   <version>4.5.1</version> </dependency> 

jetty maven plugin:

<plugin>         <groupid>org.eclipse.jetty</groupid>         <artifactid>jetty-maven-plugin</artifactid>         <version>9.2.1.v20140609</version>         <configuration>           <httpconnector>             <port>8103</port>           </httpconnector>           <stopport>8005</stopport>           <stopkey>stop</stopkey>         </configuration>         <executions>           <execution>             <id>start-jetty</id>             <phase>pre-integration-test</phase>             <goals>               <goal>stop</goal>               <goal>run-war</goal>             </goals>             <configuration>               <scanintervalseconds>0</scanintervalseconds>               <daemon>true</daemon>             </configuration>           </execution>           <execution>             <id>stop-jetty</id>             <phase>post-integration-test</phase>             <goals>               <goal>stop</goal>             </goals>           </execution>         </executions>       </plugin>     </plugins> 

it code:

@test     public void testhead() throws exception {         //j-         given()             .port(port)             .head(url)   <-- /status             .then()             .statuscode(200);         //j+     } 

the error message see is:

java.net.connectexception: connection refused      @ java.net.plainsocketimpl.socketconnect(native method)     @ java.net.abstractplainsocketimpl.doconnect(abstractplainsocketimpl.java:339)     @ java.net.abstractplainsocketimpl.connecttoaddress(abstractplainsocketimpl.java:200)     @ java.net.abstractplainsocketimpl.connect(abstractplainsocketimpl.java:182)     @ java.net.sockssocketimpl.connect(sockssocketimpl.java:392)     @ java.net.socket.connect(socket.java:579)     @ org.apache.http.conn.scheme.plainsocketfactory.connectsocket(plainsocketfactory.java:117)     @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:177)     @ org.apache.http.impl.conn.managedclientconnectionimpl.open(managedclientconnectionimpl.java:304)     @ org.apache.http.impl.client.defaultrequestdirector.tryconnect(defaultrequestdirector.java:611)     @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:446)     @ org.apache.http.impl.client.abstracthttpclient.doexecute(abstracthttpclient.java:882)     @ org.apache.http.impl.client.closeablehttpclient.execute(closeablehttpclient.java:82)     @ org.apache.http.impl.client.closeablehttpclient.execute(closeablehttpclient.java:55)     @ org.apache.http.client.httpclient$execute$0.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:133)     @ com.jayway.restassured.internal.requestspecificationimpl$restassuredhttpbuilder.dorequest(requestspecificationimpl.groovy:1952)     @ com.jayway.restassured.internal.http.httpbuilder.dorequest(httpbuilder.java:492)     @ com.jayway.restassured.internal.http.httpbuilder.request(httpbuilder.java:441)     @ com.jayway.restassured.internal.http.httpbuilder$request$2.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:141)     @ com.jayway.restassured.internal.requestspecificationimpl.sendhttprequest(requestspecificationimpl.groovy:1374)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ org.codehaus.groovy.reflection.cachedmethod.invoke(cachedmethod.java:93)     @ groovy.lang.metamethod.domethodinvoke(metamethod.java:325)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1210)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1019)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:810)     @ com.jayway.restassured.internal.requestspecificationimpl.invokemethod(requestspecificationimpl.groovy)     @ org.codehaus.groovy.runtime.callsite.pogointerceptablesite.call(pogointerceptablesite.java:48)     @ org.codehaus.groovy.runtime.callsite.pogointerceptablesite.callcurrent(pogointerceptablesite.java:58)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcallcurrent(callsitearray.java:52)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.callcurrent(abstractcallsite.java:154)     @ com.jayway.restassured.internal.requestspecificationimpl.sendrequest(requestspecificationimpl.groovy:1156)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ org.codehaus.groovy.reflection.cachedmethod.invoke(cachedmethod.java:93)     @ groovy.lang.metamethod.domethodinvoke(metamethod.java:325)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1210)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1019)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:810)     @ com.jayway.restassured.internal.requestspecificationimpl.invokemethod(requestspecificationimpl.groovy)     @ org.codehaus.groovy.runtime.callsite.pogointerceptablesite.call(pogointerceptablesite.java:48)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:149)     @ com.jayway.restassured.internal.filter.sendrequestfilter.filter(sendrequestfilter.groovy:30)     @ com.jayway.restassured.filter.filter$filter$0.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ com.jayway.restassured.filter.filter$filter.call(unknown source)     @ com.jayway.restassured.internal.filter.filtercontextimpl.next(filtercontextimpl.groovy:73)     @ com.jayway.restassured.filter.time.timingfilter.filter(timingfilter.java:56)     @ com.jayway.restassured.filter.filter$filter.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:141)     @ com.jayway.restassured.internal.filter.filtercontextimpl.next(filtercontextimpl.groovy:73)     @ com.jayway.restassured.filter.filtercontext$next.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:133)     @ com.jayway.restassured.internal.requestspecificationimpl.applypathparamsandsendrequest(requestspecificationimpl.groovy:1574)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ org.codehaus.groovy.reflection.cachedmethod.invoke(cachedmethod.java:93)     @ groovy.lang.metamethod.domethodinvoke(metamethod.java:325)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1210)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1019)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:810)     @ com.jayway.restassured.internal.requestspecificationimpl.invokemethod(requestspecificationimpl.groovy)     @ org.codehaus.groovy.runtime.callsite.pogointerceptablesite.call(pogointerceptablesite.java:48)     @ org.codehaus.groovy.runtime.callsite.pogointerceptablesite.callcurrent(pogointerceptablesite.java:58)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcallcurrent(callsitearray.java:52)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.callcurrent(abstractcallsite.java:154)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.callcurrent(abstractcallsite.java:182)     @ com.jayway.restassured.internal.requestspecificationimpl.get(requestspecificationimpl.groovy:159)     @ com.jayway.restassured.internal.requestspecificationimpl.get(requestspecificationimpl.groovy) 

looks me jetty not able start @ all? that's why connect refused? because versions of jetty-maven-plugin , rest-assured not compatible?

this exception occurs when there no service listening on port trying connect to.

please check following:

  1. server down?
  2. server not waiting/configured connection?
  3. wrong port number while trying connect?

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -