4141package org .glassfish .jersey .examples .linking ;
4242
4343import java .util .List ;
44- import javax .ws .rs .core .MediaType ;
4544
45+ import javax .ws .rs .core .MediaType ;
4646import javax .ws .rs .core .Response ;
47- import org .glassfish .jersey .client .ClientResponse ;
4847
4948import org .glassfish .jersey .examples .linking .resources .ItemsResource ;
5049import org .glassfish .jersey .linking .DeclarativeLinkingFeature ;
5352import org .glassfish .jersey .test .TestProperties ;
5453
5554import org .junit .Test ;
55+ import static org .hamcrest .CoreMatchers .containsString ;
56+ import static org .hamcrest .MatcherAssert .assertThat ;
5657import static org .junit .Assert .assertEquals ;
57- import static org .junit .Assert .assertTrue ;
5858
5959/**
6060 * @author Naresh ([email protected] ) @@ -65,7 +65,7 @@ public class LinkWebAppTest extends JerseyTest {
6565 @ Override
6666 protected ResourceConfig configure () {
6767 enable (TestProperties .LOG_TRAFFIC );
68- ResourceConfig rc = new ResourceConfig (ItemsResource .class );
68+ final ResourceConfig rc = new ResourceConfig (ItemsResource .class );
6969 rc .register (DeclarativeLinkingFeature .class );
7070 return rc ;
7171 }
@@ -75,16 +75,21 @@ protected ResourceConfig configure() {
7575 */
7676 @ Test
7777 public void testLinks () throws Exception {
78-
79- Response response = target ().path ("items" ).queryParam ("offset" , 10 ).queryParam ("limit" , "10" ).request ().accept (MediaType .APPLICATION_XML_TYPE ).get (Response .class );
78+ final Response response = target ().path ("items" )
79+ .queryParam ("offset" , 10 )
80+ .queryParam ("limit" , "10" )
81+ .request (MediaType .APPLICATION_XML_TYPE )
82+ .get (Response .class );
83+
8084 final Response .StatusType statusInfo = response .getStatusInfo ();
8185 assertEquals ("Should have succeeded" , 200 , statusInfo .getStatusCode ());
8286
83-
84- String content = response .readEntity (String .class );
85- List <Object > linkHeaders = response .getHeaders ().get ("Link" );
87+ final String content = response .readEntity (String .class );
88+ final List <Object > linkHeaders = response .getHeaders ().get ("Link" );
8689
8790 assertEquals ("Should have two link headers" , 2 , linkHeaders .size ());
88- assertTrue ("Content should contain next link" ,content .contains ("http://localhost:9998/items?offset=20&limit=10" ));
91+ assertThat ("Content should contain next link" ,
92+ content ,
93+ containsString ("http://localhost:" + getPort () + "/items?offset=20&limit=10" ));
8994 }
9095}
0 commit comments