55 */
66package org .javaee7 .jaxrs .singelton .application ;
77
8+ import java .net .MalformedURLException ;
9+ import java .net .URL ;
810import java .util .StringTokenizer ;
911import javax .ws .rs .client .Client ;
1012import javax .ws .rs .client .ClientBuilder ;
1113import javax .ws .rs .client .Entity ;
1214import javax .ws .rs .client .WebTarget ;
15+ import org .jboss .arquillian .container .test .api .Deployment ;
16+ import org .jboss .arquillian .junit .Arquillian ;
17+ import org .jboss .arquillian .test .api .ArquillianResource ;
18+ import org .jboss .shrinkwrap .api .ShrinkWrap ;
19+ import org .jboss .shrinkwrap .api .spec .WebArchive ;
20+ import org .junit .After ;
1321import org .junit .Before ;
1422import org .junit .Test ;
1523import static org .junit .Assert .*;
1624import org .junit .FixMethodOrder ;
25+ import org .junit .runner .RunWith ;
1726import org .junit .runners .MethodSorters ;
1827
1928/**
2029 * @author Arun Gupta
2130 */
31+ @ RunWith (Arquillian .class )
2232@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
2333public class MyResourceTest {
2434
2535 WebTarget target ;
26-
36+
37+ @ ArquillianResource
38+ private URL base ;
39+
40+ Client client ;
41+
2742 @ Before
28- public void setUp () {
29- Client client = ClientBuilder .newClient ();
30- target = client .target ("http://localhost:8080/singleton-application/webresources/myresource" );
43+ public void setUp () throws MalformedURLException {
44+ client = ClientBuilder .newClient ();
45+ target = client .target (new URL (base , "webresources/myresource" ).toExternalForm ());
46+ }
47+
48+ @ After
49+ public void tear () {
50+ client .close ();
51+ }
52+
53+ @ Deployment (testable = false )
54+ public static WebArchive createDeployment () {
55+ return ShrinkWrap .create (WebArchive .class )
56+ .addClasses (
57+ MyApplication .class , MyResource .class );
3158 }
3259
3360 @ Test
@@ -36,7 +63,7 @@ public void test1Post() {
3663 target .request ().post (Entity .text ("mango" ));
3764 target .request ().post (Entity .text ("kiwi" ));
3865 target .request ().post (Entity .text ("passion fruit" ));
39-
66+
4067 String list = target .request ().get (String .class );
4168 StringTokenizer tokens = new StringTokenizer (list , "," );
4269 assertEquals (4 , tokens .countTokens ());
@@ -51,7 +78,7 @@ public void test2Get() {
5178 @ Test
5279 public void test3Delete () {
5380 target .path ("kiwi" ).request ().delete ();
54-
81+
5582 String list = target .request ().get (String .class );
5683 StringTokenizer tokens = new StringTokenizer (list , "," );
5784 assertEquals (3 , tokens .countTokens ());
@@ -60,7 +87,7 @@ public void test3Delete() {
6087 @ Test
6188 public void test4Put () {
6289 target .request ().put (Entity .text ("apple" ));
63-
90+
6491 String list = target .request ().get (String .class );
6592 StringTokenizer tokens = new StringTokenizer (list , "," );
6693 assertEquals (4 , tokens .countTokens ());
0 commit comments