77package org .javaee7 .jaxrs .server .negotiation ;
88
99import java .io .IOException ;
10+ import java .net .MalformedURLException ;
11+ import java .net .URL ;
12+
1013import javax .ws .rs .client .Client ;
1114import javax .ws .rs .client .ClientBuilder ;
1215import javax .ws .rs .client .WebTarget ;
16+
1317import org .custommonkey .xmlunit .XMLAssert ;
18+ import org .jboss .arquillian .container .test .api .Deployment ;
19+ import org .jboss .arquillian .junit .Arquillian ;
20+ import org .jboss .arquillian .test .api .ArquillianResource ;
21+ import org .jboss .shrinkwrap .api .ShrinkWrap ;
22+ import org .jboss .shrinkwrap .api .spec .WebArchive ;
1423import org .json .JSONException ;
15- import org .junit .After ;
16- import org .junit .AfterClass ;
1724import org .junit .Before ;
18- import org .junit .BeforeClass ;
1925import org .junit .Test ;
20- import static org .junit .Assert .* ;
26+ import org .junit .runner . RunWith ;
2127import org .skyscreamer .jsonassert .JSONAssert ;
2228import org .skyscreamer .jsonassert .JSONCompareMode ;
2329import org .xml .sax .SAXException ;
2430
2531/**
2632 * @author Arun Gupta
2733 */
34+ @ RunWith (Arquillian .class )
2835public class MyResourceTest {
2936
30- WebTarget target ;
31-
37+ @ Deployment (testable = false )
38+ public static WebArchive createDeployment () {
39+ return ShrinkWrap .create (WebArchive .class )
40+ .addClasses (MyApplication .class , MyResource .class , People .class , Person .class );
41+ }
42+
43+ @ ArquillianResource
44+ private URL base ;
45+
46+ private WebTarget target ;
47+
3248 @ Before
33- public void setUp () {
49+ public void setUp () throws MalformedURLException {
3450 Client client = ClientBuilder .newClient ();
35- target = client
36- .target ("http://localhost:8080/server-negotiation/webresources/persons" );
51+ target = client .target (new URL (base , "webresources/persons" ).toExternalForm ());
3752 }
3853
3954 @ Test
@@ -55,7 +70,7 @@ public void testJson2() throws JSONException {
5570 @ Test
5671 public void testXml () throws JSONException , SAXException , IOException {
5772 String response = target .request ().accept ("application/xml" ).get (String .class );
58- XMLAssert .assertXMLEqual ("<collection ><person><age>1</age><name>Penny</name></person><person><age>2</age><name>Leonard</name></person><person><age>3</age><name>Sheldon</name></person></collection >" ,
73+ XMLAssert .assertXMLEqual ("<people ><person><age>1</age><name>Penny</name></person><person><age>2</age><name>Leonard</name></person><person><age>3</age><name>Sheldon</name></person></people >" ,
5974 response );
6075 }
6176
0 commit comments