Skip to content

Commit aa5ed6f

Browse files
committed
Converting Servlet into tests
1 parent dccceb5 commit aa5ed6f

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.asyncclient;
7+
8+
import java.net.URL;
9+
import java.util.concurrent.ExecutionException;
10+
import java.util.concurrent.Future;
11+
import javax.ws.rs.client.Client;
12+
import javax.ws.rs.client.ClientBuilder;
13+
import javax.ws.rs.client.InvocationCallback;
14+
import javax.ws.rs.client.WebTarget;
15+
import javax.ws.rs.core.Response;
16+
import org.jboss.arquillian.test.api.ArquillianResource;
17+
import org.junit.BeforeClass;
18+
import org.junit.Test;
19+
import static org.junit.Assert.*;
20+
21+
/**
22+
* @author Arun Gupta
23+
*/
24+
public class MyResourceTest {
25+
26+
// @ArquillianResource URL baseURL;
27+
28+
private static WebTarget target;
29+
30+
@BeforeClass
31+
public static void setUpClass() {
32+
Client client = ClientBuilder.newClient();
33+
target = client.target("http://localhost:8080/async-client/webresources/fruits");
34+
}
35+
36+
/**
37+
* Test of getList method, of class MyResource.
38+
*/
39+
@Test
40+
public void testPollingResponse() throws InterruptedException, ExecutionException {
41+
Future<Response> r1 = target.request().async().get();
42+
String response = r1.get().readEntity(String.class);
43+
assertEquals("apple", response);
44+
}
45+
46+
/**
47+
* Test of getList method, of class MyResource.
48+
*/
49+
@Test
50+
public void testPollingString() throws InterruptedException, ExecutionException {
51+
Future<String> r1 = target.request().async().get(String.class);
52+
String response = r1.get();
53+
assertEquals("apple", response);
54+
}
55+
56+
/**
57+
* Test of getList method, of class MyResource.
58+
*/
59+
@Test
60+
public void testInvocationCallback() throws InterruptedException, ExecutionException {
61+
target.request().async().get(new InvocationCallback<String>() {
62+
63+
@Override
64+
public void completed(String r) {
65+
assertEquals("apple", r);
66+
}
67+
68+
@Override
69+
public void failed(Throwable t) {
70+
fail(t.getMessage());
71+
}
72+
73+
});
74+
}
75+
76+
}

0 commit comments

Comments
 (0)