Skip to content

Commit 7acd1f1

Browse files
committed
Removing web pages/Servlet and converting to unit tests
1 parent b538a28 commit 7acd1f1

3 files changed

Lines changed: 62 additions & 197 deletions

File tree

jaxrs/server-negotiation/src/main/java/org/javaee7/jaxrs/server/negotiation/TestServlet.java

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

jaxrs/server-negotiation/src/main/webapp/index.jsp

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.server.negotiation;
8+
9+
import java.io.IOException;
10+
import javax.ws.rs.client.Client;
11+
import javax.ws.rs.client.ClientBuilder;
12+
import javax.ws.rs.client.WebTarget;
13+
import org.custommonkey.xmlunit.XMLAssert;
14+
import org.json.JSONException;
15+
import org.junit.After;
16+
import org.junit.AfterClass;
17+
import org.junit.Before;
18+
import org.junit.BeforeClass;
19+
import org.junit.Test;
20+
import static org.junit.Assert.*;
21+
import org.skyscreamer.jsonassert.JSONAssert;
22+
import org.skyscreamer.jsonassert.JSONCompareMode;
23+
import org.xml.sax.SAXException;
24+
25+
/**
26+
* @author Arun Gupta
27+
*/
28+
public class MyResourceTest {
29+
30+
WebTarget target;
31+
32+
@Before
33+
public void setUp() {
34+
Client client = ClientBuilder.newClient();
35+
target = client
36+
.target("http://localhost:8080/server-negotiation/webresources/persons");
37+
}
38+
39+
@Test
40+
public void testJson() throws JSONException {
41+
String response = target.request().accept("application/*").get(String.class);
42+
JSONAssert.assertEquals("[{\"name\":\"Penny\",\"age\":1},{\"name\":\"Leonard\",\"age\":2},{\"name\":\"Sheldon\",\"age\":3}]",
43+
response,
44+
JSONCompareMode.STRICT);
45+
}
46+
47+
@Test
48+
public void testJson2() throws JSONException {
49+
String response = target.request().get(String.class);
50+
JSONAssert.assertEquals("[{\"name\":\"Penny\",\"age\":1},{\"name\":\"Leonard\",\"age\":2},{\"name\":\"Sheldon\",\"age\":3}]",
51+
response,
52+
JSONCompareMode.STRICT);
53+
}
54+
55+
@Test
56+
public void testXml() throws JSONException, SAXException, IOException {
57+
String response = target.request().accept("application/xml").get(String.class);
58+
XMLAssert.assertXMLEqual("<collection><person><age>1</age><name>Penny</name></person><person><age>2</age><name>Leonard</name></person><person><age>3</age><name>Sheldon</name></person></collection>",
59+
response);
60+
}
61+
62+
}

0 commit comments

Comments
 (0)