Skip to content

Commit bbb6fe9

Browse files
committed
Removing web pages and converting to unit tests
1 parent f88ef7b commit bbb6fe9

3 files changed

Lines changed: 55 additions & 201 deletions

File tree

jaxrs/mapping-exceptions/src/main/java/org/javaee7/jaxrs/mapping/exceptions/TestServlet.java

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

jaxrs/mapping-exceptions/src/main/webapp/index.jsp

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.mapping.exceptions;
8+
9+
import javax.ws.rs.ClientErrorException;
10+
import javax.ws.rs.client.Client;
11+
import javax.ws.rs.client.ClientBuilder;
12+
import javax.ws.rs.client.WebTarget;
13+
import org.junit.Before;
14+
import org.junit.Test;
15+
import static org.junit.Assert.*;
16+
17+
/**
18+
*
19+
* @author argupta
20+
*/
21+
public class MyResourceTest {
22+
WebTarget target;
23+
24+
@Before
25+
public void setUp() {
26+
Client client = ClientBuilder.newClient();
27+
target = client
28+
.target("http://localhost:8080/mapping-exceptions/webresources/order");
29+
}
30+
31+
/**
32+
* Test of getOrder method, of class MyResource.
33+
*/
34+
@Test
35+
public void testOddOrder() {
36+
String response = target.path("1").request().get(String.class);
37+
assertEquals("1", response);
38+
}
39+
40+
/**
41+
* Test of getOrder method, of class MyResource.
42+
*/
43+
@Test
44+
public void testEvenOrder() {
45+
try {
46+
System.out.print(target.path("2").request().get(String.class));
47+
} catch (ClientErrorException e) {
48+
assertEquals(412, e.getResponse().getStatus());
49+
} catch (Exception e) {
50+
fail(e.getMessage());
51+
}
52+
53+
}
54+
55+
}

0 commit comments

Comments
 (0)