1919 */
2020package org .eclipse .microprofile .starter ;
2121
22+ import com .fasterxml .jackson .databind .ObjectMapper ;
23+ import jakarta .ws .rs .client .Client ;
24+ import jakarta .ws .rs .client .ClientBuilder ;
25+ import jakarta .ws .rs .client .WebTarget ;
26+ import jakarta .ws .rs .core .Response ;
27+ import java .io .File ;
28+ import java .io .IOException ;
29+ import java .net .URISyntaxException ;
30+ import java .net .URL ;
31+ import java .util .logging .Logger ;
32+ import org .jboss .arquillian .container .test .api .Deployment ;
2233import org .jboss .arquillian .container .test .api .RunAsClient ;
2334import org .jboss .arquillian .junit .Arquillian ;
35+ import org .jboss .arquillian .test .api .ArquillianResource ;
36+ import org .jboss .shrinkwrap .api .ShrinkWrap ;
37+ import org .jboss .shrinkwrap .api .spec .WebArchive ;
38+ import org .jboss .shrinkwrap .resolver .api .maven .Maven ;
39+ import org .junit .Assert ;
2440import org .junit .Before ;
2541import org .junit .Test ;
2642import org .junit .runner .RunWith ;
2743
28- import jakarta .ws .rs .client .Client ;
29- import jakarta .ws .rs .client .ClientBuilder ;
30- import jakarta .ws .rs .client .WebTarget ;
31- import java .io .File ;
32- import java .io .FileNotFoundException ;
33- import java .nio .charset .StandardCharsets ;
34- import java .util .Scanner ;
35-
36- import static org .junit .Assert .assertTrue ;
37-
3844/**
3945 * MicroProfile Starter runtimes API smoke tests.
40- *
46+ * <p>
4147 * Some rudimentary tests to make sure we ain't breaking the API.
4248 *
4349 * @author Michal Karm Babacek <[email protected] > 4450 */
4551@ RunWith (Arquillian .class )
46- public class APITest {
52+ public class APITest {
53+
54+ public static final String URI = "api" ;
55+
56+ private static final String WARNAME = "mp-starter-test.war" ;
57+ private Client client = ClientBuilder .newClient ();
58+
59+ private static final Logger logger = Logger .getLogger (APITest .class .getName ());
60+
61+ @ Deployment (testable = true )
62+ public static WebArchive createDeployment () {
63+ WebArchive archive = ShrinkWrap .create (WebArchive .class , WARNAME )
64+ .addPackages (true , "org.eclipse.microprofile.starter" )
65+ .addAsLibraries (Maven .resolver ().resolve ("org.thymeleaf:thymeleaf:3.0.10.RELEASE" ,
66+ "org.apache.maven:maven-model:3.9.6" , "org.apache.maven:maven-builder-support:3.9.6" ,
67+ "org.apache.maven:maven-artifact:3.9.6" , "org.apache.maven:maven-model-builder:3.9.6" ,
68+ "com.google.guava:guava:11.0.2" , "com.fasterxml.jackson.core:jackson-core:2.10.5" ,
69+ "com.fasterxml.jackson.core:jackson-annotations:2.10.5" , "com.fasterxml.jackson.core:jackson-databind:2.10.5" ,
70+ "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.10.5" ,
71+ "org.apache.commons:commons-compress:1.20" )
72+ .withTransitivity ().asFile ());
73+ return archive ;
74+ }
4775
48- public static final String API_URL = "http://127.0.0.1:9090/api" ;
49- final Client client = ClientBuilder . newBuilder (). build () ;
76+ @ ArquillianResource
77+ private URL baseURL ;
5078
5179 private WebTarget target ;
5280 private File v7Matrix ;
@@ -61,8 +89,8 @@ public class APITest {
6189 private File v3MatrixServers ;
6290
6391 @ Before
64- public void before () {
65- target = client .target (API_URL );
92+ public void before () throws URISyntaxException {
93+ target = client .target (baseURL . toURI () + URI );
6694 v7Matrix = new File (getClass ().getClassLoader ().getResource ("json_examples/v7/supportMatrix.json.segments" ).getFile ());
6795 v7MatrixServers = new File (getClass ().getClassLoader ().getResource ("json_examples/v7/supportMatrix_servers.json.segments" ).getFile ());
6896 v6Matrix = new File (getClass ().getClassLoader ().getResource ("json_examples/v6/supportMatrix.json.segments" ).getFile ());
@@ -75,20 +103,16 @@ public void before() {
75103 v3MatrixServers = new File (getClass ().getClassLoader ().getResource ("json_examples/v3/supportMatrix_servers.json.segments" ).getFile ());
76104 }
77105
78- public void test (File segments , String uri ) throws FileNotFoundException {
79- String response = client .target (API_URL + uri ).request ().get (String .class );
80- try (Scanner scanner = new Scanner (segments , StandardCharsets .UTF_8 .toString ())) {
81- scanner .useDelimiter ("\n " );
82- while (scanner .hasNext ()) {
83- String l = scanner .nextLine ();
84- assertTrue ("Response of " + uri + " \n " + response + "\n should have contained the string: " + l , response .contains (l ));
85- }
86- }
106+ public void test (File segments , String uri ) throws IOException , URISyntaxException {
107+ String response = client .target (baseURL .toString () + URI + uri ).request ().get (String .class );
108+ ObjectMapper objectMapper = new ObjectMapper ();
109+ String expectedJson = objectMapper .writeValueAsString (objectMapper .readTree (segments ));
110+ Assert .assertEquals ("Not Equal failure" , expectedJson , response );
87111 }
88112
89113 @ Test
90114 @ RunAsClient
91- public void supportMatrix () throws FileNotFoundException {
115+ public void supportMatrix () throws IOException , URISyntaxException {
92116 test (v7Matrix , "/7/supportMatrix" );
93117 test (v7MatrixServers , "/7/supportMatrix/servers" );
94118 test (v6Matrix , "/6/supportMatrix" );
0 commit comments