Skip to content

Commit 45a5009

Browse files
committed
Convert JAX-RS samples to Arquillian: Beanvalidation
Issue: #78
1 parent 218a41e commit 45a5009

File tree

3 files changed

+26
-207
lines changed

3 files changed

+26
-207
lines changed

jaxrs/beanvalidation/src/main/java/org/javaee7/jaxrs/beanvalidation/TestServlet.java

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

jaxrs/beanvalidation/src/main/webapp/index.jsp

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

jaxrs/beanvalidation/src/test/java/org/javaee7/jaxrs/beanvalidation/MyResourceTest.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,48 @@
55
*/
66
package org.javaee7.jaxrs.beanvalidation;
77

8+
import static org.junit.Assert.assertEquals;
9+
import static org.junit.Assert.assertNotNull;
10+
import static org.junit.Assert.fail;
11+
12+
import java.net.MalformedURLException;
13+
import java.net.URL;
14+
815
import javax.ws.rs.BadRequestException;
916
import javax.ws.rs.client.Client;
1017
import javax.ws.rs.client.ClientBuilder;
1118
import javax.ws.rs.client.Entity;
1219
import javax.ws.rs.client.WebTarget;
13-
import org.junit.After;
14-
import org.junit.AfterClass;
20+
21+
import org.jboss.arquillian.container.test.api.Deployment;
22+
import org.jboss.arquillian.junit.Arquillian;
23+
import org.jboss.arquillian.test.api.ArquillianResource;
24+
import org.jboss.shrinkwrap.api.ShrinkWrap;
25+
import org.jboss.shrinkwrap.api.spec.WebArchive;
1526
import org.junit.Before;
16-
import org.junit.BeforeClass;
1727
import org.junit.Test;
18-
import static org.junit.Assert.*;
28+
import org.junit.runner.RunWith;
1929

2030
/**
2131
* @author Arun Gupta
2232
*/
33+
@RunWith(Arquillian.class)
2334
public class MyResourceTest {
2435

36+
@Deployment(testable = false)
37+
public static WebArchive createDeployment() {
38+
return ShrinkWrap.create(WebArchive.class)
39+
.addClasses(MyApplication.class, MyResource.class);
40+
}
2541
private static WebTarget target;
2642

27-
public MyResourceTest() {
28-
}
43+
@ArquillianResource
44+
private URL base;
2945

30-
@BeforeClass
31-
public static void setUpClass() {
46+
@Before
47+
public void setUpClass() throws MalformedURLException {
3248
Client client = ClientBuilder.newClient();
33-
target = client.target("http://localhost:8080/beanvalidation/webresources/endpoint");
49+
target = client.target(new URL(base, "webresources/endpoint").toExternalForm());
3450
}
3551

3652
@Test
@@ -46,7 +62,7 @@ public void testInvalidRequest() {
4662
@Test
4763
public void testValidRequest() {
4864
String r = target.request().post(Entity.text("foo"), String.class);
49-
assertEquals("foo", "foo");
65+
assertEquals("foo", r);
5066
}
5167

5268
}

0 commit comments

Comments
 (0)