Skip to content

Commit ab647ab

Browse files
committed
Arquillian enabling the test and removing redundant files
1 parent ce532ec commit ab647ab

3 files changed

Lines changed: 97 additions & 214 deletions

File tree

jaxrs/singleton-annotation/src/main/java/org/javaee7/jaxrs/singleton/annotation/TestServlet.java

Lines changed: 0 additions & 159 deletions
This file was deleted.

jaxrs/singleton-annotation/src/main/webapp/index.jsp

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package org.javaee7.jaxrs.singleton.annotation;
8+
9+
import java.net.MalformedURLException;
10+
import java.net.URL;
11+
import java.util.StringTokenizer;
12+
import javax.ws.rs.client.Client;
13+
import javax.ws.rs.client.ClientBuilder;
14+
import javax.ws.rs.client.Entity;
15+
import javax.ws.rs.client.WebTarget;
16+
import org.jboss.arquillian.container.test.api.Deployment;
17+
import org.jboss.arquillian.junit.Arquillian;
18+
import org.jboss.arquillian.test.api.ArquillianResource;
19+
import org.jboss.shrinkwrap.api.ShrinkWrap;
20+
import org.jboss.shrinkwrap.api.spec.WebArchive;
21+
import org.junit.After;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
import static org.junit.Assert.*;
25+
import org.junit.FixMethodOrder;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.MethodSorters;
28+
29+
/**
30+
* @author Arun Gupta
31+
*/
32+
@RunWith(Arquillian.class)
33+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
34+
public class MyResourceTest {
35+
36+
WebTarget target;
37+
38+
@ArquillianResource
39+
private URL base;
40+
41+
Client client;
42+
43+
@Before
44+
public void setUp() throws MalformedURLException {
45+
client = ClientBuilder.newClient();
46+
target = client.target(new URL(base, "webresources/myresource").toExternalForm());
47+
}
48+
49+
@After
50+
public void tear() {
51+
client.close();
52+
}
53+
54+
@Deployment(testable = false)
55+
public static WebArchive createDeployment() {
56+
return ShrinkWrap.create(WebArchive.class)
57+
.addClasses(
58+
MyApplication.class, MyResource.class);
59+
}
60+
61+
@Test
62+
public void test1Post() {
63+
target.request().post(Entity.text("pineapple"));
64+
target.request().post(Entity.text("mango"));
65+
target.request().post(Entity.text("kiwi"));
66+
target.request().post(Entity.text("passion fruit"));
67+
68+
String list = target.request().get(String.class);
69+
StringTokenizer tokens = new StringTokenizer(list, ",");
70+
assertEquals(4, tokens.countTokens());
71+
}
72+
73+
@Test
74+
public void test2Get() {
75+
String response = target.path("2").request().get(String.class);
76+
assertEquals("kiwi", response);
77+
}
78+
79+
@Test
80+
public void test3Delete() {
81+
target.path("kiwi").request().delete();
82+
83+
String list = target.request().get(String.class);
84+
StringTokenizer tokens = new StringTokenizer(list, ",");
85+
assertEquals(3, tokens.countTokens());
86+
}
87+
88+
@Test
89+
public void test4Put() {
90+
target.request().put(Entity.text("apple"));
91+
92+
String list = target.request().get(String.class);
93+
StringTokenizer tokens = new StringTokenizer(list, ",");
94+
assertEquals(4, tokens.countTokens());
95+
}
96+
97+
}

0 commit comments

Comments
 (0)