Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e2873e

Browse files
committed
Started work on a simple test case - still throwing "java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder" and needs further investigation
1 parent 439841a commit 7e2873e

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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.endpoint;
8+
9+
import java.io.File;
10+
import java.util.logging.Logger;
11+
import javax.ws.rs.client.Client;
12+
import javax.ws.rs.client.ClientBuilder;
13+
import javax.ws.rs.client.Entity;
14+
import javax.ws.rs.client.WebTarget;
15+
import org.jboss.arquillian.container.test.api.Deployment;
16+
import org.jboss.arquillian.container.test.api.TargetsContainer;
17+
import org.jboss.arquillian.junit.Arquillian;
18+
import org.jboss.shrinkwrap.api.ShrinkWrap;
19+
import org.jboss.shrinkwrap.api.spec.WebArchive;
20+
import org.junit.Test;
21+
import static org.junit.Assert.*;
22+
import org.junit.BeforeClass;
23+
import org.junit.runner.RunWith;
24+
25+
/**
26+
* @author Arun Gupta
27+
*/
28+
//@RunWith(Arquillian.class)
29+
public class MyResourceTest {
30+
31+
private static WebTarget target;
32+
33+
/**
34+
* Arquillian specific method for creating a file which can be deployed
35+
* while executing the test.
36+
*
37+
* @return a war file
38+
*/
39+
// @Deployment
40+
// @TargetsContainer("wildfly-arquillian")
41+
public static WebArchive createDeployment() {
42+
WebArchive war = ShrinkWrap.create(WebArchive.class).
43+
addClass(MyApplication.class).
44+
addClass(Database.class).
45+
addClass(MyResource.class);
46+
System.out.println(war.toString(true));
47+
48+
return war;
49+
}
50+
51+
@BeforeClass
52+
public static void setupClass() {
53+
Client client = ClientBuilder.newClient();
54+
target = client.target("http://localhost:8080/jaxrs-endpoint/webresources/fruit");
55+
}
56+
57+
/**
58+
* Test of POST method, of class MyResource.
59+
*/
60+
@Test
61+
public void testPost() {
62+
System.out.println("POST");
63+
target.request().post(Entity.text("apple"));
64+
String r = target.request().get(String.class);
65+
assertEquals("[apple]", r);
66+
}
67+
68+
/**
69+
* Test of PUT method, of class MyResource.
70+
*/
71+
@Test
72+
public void testPut() {
73+
System.out.println("PUT");
74+
target.request().put(Entity.text("banana"));
75+
String r = target.request().get(String.class);
76+
assertEquals("[apple, banana]", r);
77+
}
78+
79+
/**
80+
* Test of GET method, of class MyResource.
81+
*/
82+
@Test
83+
public void testGetAll() {
84+
System.out.println("GET");
85+
String r = target.request().get(String.class);
86+
assertEquals("[apple, banana]", r);
87+
}
88+
89+
/**
90+
* Test of GET method, of class MyResource.
91+
*/
92+
@Test
93+
public void testGetOne() {
94+
System.out.println("GET");
95+
String r = target.path("apple").request().get(String.class);
96+
assertEquals("[apple]", r);
97+
}
98+
99+
/**
100+
* Test of GET method, of class MyResource.
101+
*/
102+
@Test
103+
public void testDelete() {
104+
System.out.println("DELETE");
105+
target.path("banana").request().delete();
106+
String r = target.request().get(String.class);
107+
assertEquals("[apple]", r);
108+
}
109+
110+
}

0 commit comments

Comments
 (0)