Skip to content

Commit 3851b1e

Browse files
committed
Arquillian enabling the test
1 parent b53aaef commit 3851b1e

File tree

1 file changed

+51
-20
lines changed

1 file changed

+51
-20
lines changed
Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,74 @@
11
package org.javaee7.sample;
22

3+
import java.net.MalformedURLException;
4+
import java.net.URI;
5+
import java.net.URL;
6+
import javax.ws.rs.client.Client;
7+
import javax.ws.rs.client.ClientBuilder;
8+
import javax.ws.rs.client.WebTarget;
9+
import org.jboss.arquillian.container.test.api.Deployment;
10+
import org.jboss.arquillian.junit.Arquillian;
11+
import org.jboss.arquillian.test.api.ArquillianResource;
12+
import org.jboss.shrinkwrap.api.ShrinkWrap;
13+
import org.jboss.shrinkwrap.api.spec.WebArchive;
314
import org.junit.Test;
415
import static org.junit.Assert.*;
16+
import org.junit.Before;
17+
import org.junit.runner.RunWith;
518

619
/**
720
* @author arungupta
821
*/
22+
@RunWith(Arquillian.class)
923
public class PersonTest {
10-
11-
public PersonTest() {
24+
25+
private WebTarget target;
26+
27+
@Deployment(testable = false)
28+
public static WebArchive createDeployment() {
29+
return ShrinkWrap.create(WebArchive.class)
30+
.addPackage("org.javaee7.sample");
31+
}
32+
33+
@ArquillianResource
34+
private URL base;
35+
36+
@Before
37+
public void setUp() throws MalformedURLException {
38+
Client client = ClientBuilder.newClient();
39+
target = client.target(URI.create(new URL(base, "resources/persons").toExternalForm()));
1240
}
13-
41+
1442
/**
1543
* Test of get method, of class Person.
1644
*/
17-
@Test
45+
// @Test
1846
public void testGetAll() {
19-
System.out.println("get");
20-
Person instance = new Person();
21-
String expResult = "";
22-
String result = instance.get();
23-
assertEquals(expResult, result);
24-
// TODO review the generated test code and remove the default call to fail.
25-
fail("The test case is a prototype.");
47+
String[] list = target.request().get(String[].class);
48+
assertEquals(8, list.length);
49+
50+
assertEquals("Penny", list[0]);
51+
assertEquals("Leonard", list[1]);
52+
assertEquals("Sheldon", list[2]);
53+
assertEquals("Amy", list[3]);
54+
assertEquals("Howard", list[4]);
55+
assertEquals("Bernadette", list[5]);
56+
assertEquals("Raj", list[6]);
57+
assertEquals("Priya", list[7]);
2658
}
2759

2860
/**
2961
* Test of get method, of class Person.
3062
*/
3163
@Test
3264
public void testGetOne() {
33-
System.out.println("get");
34-
int id = 0;
35-
Person instance = new Person();
36-
String expResult = "";
37-
String result = instance.get(id);
38-
assertEquals(expResult, result);
39-
// TODO review the generated test code and remove the default call to fail.
40-
fail("The test case is a prototype.");
65+
WebTarget target2 = target.path("{id}");
66+
67+
String response = target2.resolveTemplate("id", 0).request().get(String.class);
68+
assertEquals("Penny", response);
69+
70+
response = target2.resolveTemplate("id", 1).request().get(String.class);
71+
assertEquals("Leonard", response);
4172
}
42-
73+
4374
}

0 commit comments

Comments
 (0)