|
12 | 12 | package it.io.openliberty.guides.data; |
13 | 13 |
|
14 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 15 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 16 | +import static org.junit.jupiter.api.Assertions.fail; |
| 17 | + |
| 18 | +import java.io.InputStream; |
| 19 | +import java.io.StringReader; |
| 20 | +import java.util.Arrays; |
15 | 21 |
|
16 | 22 | import org.junit.jupiter.api.AfterEach; |
17 | 23 | import org.junit.jupiter.api.BeforeEach; |
18 | 24 | import org.junit.jupiter.api.Test; |
19 | 25 |
|
| 26 | +import jakarta.json.Json; |
| 27 | +import jakarta.json.JsonArray; |
| 28 | +import jakarta.json.JsonObject; |
| 29 | +import jakarta.json.JsonObjectBuilder; |
| 30 | +import jakarta.validation.constraints.AssertTrue; |
20 | 31 | import jakarta.ws.rs.client.Client; |
21 | 32 | import jakarta.ws.rs.client.ClientBuilder; |
| 33 | +import jakarta.ws.rs.core.MediaType; |
22 | 34 | import jakarta.ws.rs.core.Response; |
23 | 35 |
|
24 | | - |
25 | 36 | public class DataGuideIT { |
26 | 37 |
|
27 | 38 | private static final String PORT = System.getProperty("http.port"); |
28 | 39 | private static final String URL = "http://localhost:" + PORT |
29 | | - + "/shipping/packageQuery"; |
| 40 | + + "/shipping/packageQuery"; |
30 | 41 |
|
31 | 42 | private Client client; |
32 | 43 |
|
33 | 44 | @BeforeEach |
34 | 45 | public void beforeEach() { |
35 | | - client = ClientBuilder.newClient(); |
| 46 | + client = ClientBuilder.newClient(); |
36 | 47 | } |
37 | 48 |
|
38 | | - @AfterEach |
| 49 | + @AfterEach |
39 | 50 | public void afterEach() { |
40 | | - client.close(); |
| 51 | + client.close(); |
41 | 52 | } |
42 | 53 |
|
43 | | - |
44 | 54 | @Test |
45 | | - public void testQueries() throws Exception { |
| 55 | + public void testGetQueries() throws Exception { |
46 | 56 | Response response = client.target(URL).request().get(); |
47 | | - assertEquals(200, response.getStatus(), |
48 | | - "Incorrect response code from: " + URL); |
| 57 | + assertEquals(200, response.getStatus(), "Incorrect response code from: " + URL); |
| 58 | + String jsonReponse = response.readEntity(String.class); |
| 59 | + JsonArray json = Json.createReader(new StringReader(jsonReponse)).readArray(); |
| 60 | + // System.out.println(json); |
| 61 | + JsonObject findByLengthGreaterThan = Json.createObjectBuilder() |
| 62 | + .add("name", "findByLengthGreaterThan") |
| 63 | + .add("parameters", Json.createArrayBuilder().add("length").build()) |
| 64 | + .add("types", Json.createArrayBuilder().add("float").build()).build(); |
| 65 | + |
| 66 | + JsonObject findByLengthGreaterThanAndWidthLessThan = Json.createObjectBuilder() |
| 67 | + .add("name", "findByLengthGreaterThanAndWidthLessThan") |
| 68 | + .add("parameters", |
| 69 | + Json.createArrayBuilder().add("length").add("width").build()) |
| 70 | + .add("types", |
| 71 | + Json.createArrayBuilder().add("float").add("float").build()) |
| 72 | + .build(); |
49 | 73 |
|
| 74 | + assertTrue(json.contains(findByLengthGreaterThan), json.toString()); |
| 75 | + assertTrue(json.contains(findByLengthGreaterThanAndWidthLessThan), |
| 76 | + json.toString()); |
50 | 77 | } |
51 | 78 |
|
52 | 79 | } |
0 commit comments