Skip to content

Commit ec41bff

Browse files
committed
Adding tests
1 parent 96ed03a commit ec41bff

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
package org.javaee7.jaxrs.beanvalidation;
7+
8+
import javax.ws.rs.BadRequestException;
9+
import javax.ws.rs.client.Client;
10+
import javax.ws.rs.client.ClientBuilder;
11+
import javax.ws.rs.client.Entity;
12+
import javax.ws.rs.client.WebTarget;
13+
import org.junit.After;
14+
import org.junit.AfterClass;
15+
import org.junit.Before;
16+
import org.junit.BeforeClass;
17+
import org.junit.Test;
18+
import static org.junit.Assert.*;
19+
20+
/**
21+
* @author Arun Gupta
22+
*/
23+
public class MyResourceTest {
24+
25+
private static WebTarget target;
26+
27+
public MyResourceTest() {
28+
}
29+
30+
@BeforeClass
31+
public static void setUpClass() {
32+
Client client = ClientBuilder.newClient();
33+
target = client.target("http://localhost:8080/beanvalidation/webresources/endpoint");
34+
}
35+
36+
@Test
37+
public void testInvalidRequest() {
38+
try {
39+
target.request().post(Entity.text("fo"), String.class);
40+
fail("Request must fail with payload < 3");
41+
} catch (BadRequestException e) {
42+
assertNotNull(e);
43+
}
44+
}
45+
46+
@Test
47+
public void testValidRequest() {
48+
String r = target.request().post(Entity.text("foo"), String.class);
49+
assertEquals("foo", "foo");
50+
}
51+
52+
}

0 commit comments

Comments
 (0)