Skip to content

Commit ae09dc7

Browse files
committed
Adding tests
1 parent bd675b2 commit ae09dc7

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.client.negotiation;
8+
9+
import javax.ws.rs.client.Client;
10+
import javax.ws.rs.client.ClientBuilder;
11+
import javax.ws.rs.client.WebTarget;
12+
import org.junit.After;
13+
import org.junit.AfterClass;
14+
import org.junit.Before;
15+
import org.junit.BeforeClass;
16+
import org.junit.Test;
17+
import static org.junit.Assert.*;
18+
19+
/**
20+
* @author Arun Gupta
21+
*/
22+
public class MyResourceTest {
23+
24+
private static WebTarget target;
25+
26+
@BeforeClass
27+
public static void setUpClass() {
28+
Client client = ClientBuilder.newClient();
29+
target = client
30+
.target("http://localhost:8080/client-negotiation/webresources/persons");
31+
}
32+
33+
@Test
34+
public void testXML() {
35+
String xml = target.request("application/xml").get(String.class);
36+
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><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>", xml);
37+
}
38+
39+
@Test
40+
public void testJSON() {
41+
String json = target.request("application/json").get(String.class);
42+
assertEquals("[{\"age\":1,\"name\":\"Penny\"},{\"age\":2,\"name\":\"Leonard\"},{\"age\":3,\"name\":\"Sheldon\"}]", json);
43+
}
44+
45+
}

0 commit comments

Comments
 (0)