-
Notifications
You must be signed in to change notification settings - Fork 0
/
JaxbTest.java
106 lines (95 loc) · 3.42 KB
/
JaxbTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package io.openliberty.oat.jaxb;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jboss.eap.additional.testsuite.annotations.EAT;
import org.jboss.eap.additional.testsuite.annotations.ATFeature;
@EAT({"modules/testcases/OpenLiberty/jaxrs/src/main/java"})
@RunWith(Arquillian.class)
@RunAsClient
public class JaxbTest {
private final static String WARNAME = "arquillian-managed.war";
@Deployment(testable = false)
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class,WARNAME);
war.addClasses(JaxbTest.class, Model.class, Resource.class, TestApplication.class);
return war;
}
@ArquillianResource
private URL urlresouce;
private String httpCall(String urlPattern) throws Exception {
final URL url = new URL(urlresouce + urlPattern);
Callable<String> task = new Callable<String>() {
@Override
public String call() throws Exception {
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
int responseCode = conn.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
final InputStream err = conn.getErrorStream();
try {
throw new Exception("Error in response ...");
}
finally {
err.close();
}
}
final InputStream in = conn.getInputStream();
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
int b;
while((b = in.read()) != -1) {
out.write(b);
}
return out.toString();
}
finally {
in.close();
}
}
};
final ExecutorService executor = Executors.newSingleThreadExecutor();
final Future<String> result = executor.submit(task);
try {
return result.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
// should not happen
throw e;
} finally {
executor.shutdownNow();
try {
executor.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// ignore
}
}
}
@Test
@ATFeature(feature={"jaxrs,jaxb,jsonp,cdi,localConnector,servlet"},minVersion={"2.1,2.2,1.1,2.0,1.0,4.0"},maxVersion={"null,null,null,null,null,null"})
public void testJaxRs() throws Exception {
String result = httpCall("rest/resource");
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><model><name>Niki</name></model>", result);
}
@Test
public void defaultTest() {
}
}