|
1 | 1 | package org.javaee7.sample; |
2 | 2 |
|
| 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; |
3 | 14 | import org.junit.Test; |
4 | 15 | import static org.junit.Assert.*; |
| 16 | +import org.junit.Before; |
| 17 | +import org.junit.runner.RunWith; |
5 | 18 |
|
6 | 19 | /** |
7 | 20 | * @author arungupta |
8 | 21 | */ |
| 22 | +@RunWith(Arquillian.class) |
9 | 23 | 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())); |
12 | 40 | } |
13 | | - |
| 41 | + |
14 | 42 | /** |
15 | 43 | * Test of get method, of class Person. |
16 | 44 | */ |
17 | | - @Test |
| 45 | +// @Test |
18 | 46 | 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]); |
26 | 58 | } |
27 | 59 |
|
28 | 60 | /** |
29 | 61 | * Test of get method, of class Person. |
30 | 62 | */ |
31 | 63 | @Test |
32 | 64 | 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); |
41 | 72 | } |
42 | | - |
| 73 | + |
43 | 74 | } |
0 commit comments