|
3 | 3 | import com.github.clagomess.modplsql.dto.ConfigDto;
|
4 | 4 | import com.github.clagomess.modplsql.jdbc.Database;
|
5 | 5 | import lombok.extern.slf4j.Slf4j;
|
| 6 | +import org.apache.commons.lang.RandomStringUtils; |
6 | 7 | import org.hamcrest.CoreMatchers;
|
7 | 8 | import org.hamcrest.MatcherAssert;
|
8 | 9 | import org.junit.jupiter.api.Assertions;
|
9 | 10 | import org.junit.jupiter.api.BeforeAll;
|
10 | 11 | import org.junit.jupiter.api.Test;
|
11 | 12 |
|
12 | 13 | import javax.ws.rs.client.ClientBuilder;
|
| 14 | +import javax.ws.rs.client.Entity; |
| 15 | +import javax.ws.rs.core.Form; |
| 16 | +import javax.ws.rs.core.MediaType; |
| 17 | +import javax.ws.rs.core.Response; |
13 | 18 | import java.sql.SQLException;
|
14 | 19 |
|
15 | 20 | @Slf4j
|
@@ -52,4 +57,89 @@ public void index() {
|
52 | 57 | log.info("{}", response);
|
53 | 58 | MatcherAssert.assertThat(response, CoreMatchers.containsString("Hello World"));
|
54 | 59 | }
|
| 60 | + |
| 61 | + @Test |
| 62 | + public void httpGetParam(){ |
| 63 | + String p1 = RandomStringUtils.randomAlphanumeric(10); |
| 64 | + String p2 = RandomStringUtils.randomAlphanumeric(10); |
| 65 | + |
| 66 | + String response = ClientBuilder.newClient() |
| 67 | + .target(endpoint + String.format("/!MODPLSQL.HTTP_PARAM?p1=%s&p2=%s", p1, p2)) |
| 68 | + .request() |
| 69 | + .get(String.class); |
| 70 | + |
| 71 | + log.info("{}", response); |
| 72 | + MatcherAssert.assertThat(response, CoreMatchers.containsString(String.format("P1 => %s", p1))); |
| 73 | + MatcherAssert.assertThat(response, CoreMatchers.containsString(String.format("P2 => %s", p2))); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void httpPostParam(){ |
| 78 | + String p1 = RandomStringUtils.randomAlphanumeric(10); |
| 79 | + String p2 = RandomStringUtils.randomAlphanumeric(10); |
| 80 | + |
| 81 | + Form form = new Form(); |
| 82 | + form.param("p1", p1); |
| 83 | + form.param("p2", p2); |
| 84 | + |
| 85 | + Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE); |
| 86 | + |
| 87 | + String response = ClientBuilder.newClient() |
| 88 | + .target(endpoint + String.format("/!MODPLSQL.HTTP_PARAM?p1=%s&p2=%s", p1, p2)) |
| 89 | + .request() |
| 90 | + .post(entity, String.class); |
| 91 | + |
| 92 | + log.info("{}", response); |
| 93 | + MatcherAssert.assertThat(response, CoreMatchers.containsString(String.format("P1 => %s", p1))); |
| 94 | + MatcherAssert.assertThat(response, CoreMatchers.containsString(String.format("P2 => %s", p2))); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void setCookie(){ |
| 99 | + String cookie = RandomStringUtils.randomAlphanumeric(10); |
| 100 | + |
| 101 | + String response = ClientBuilder.newClient() |
| 102 | + .target(endpoint + "/!MODPLSQL.SET_COOKIE") |
| 103 | + .request() |
| 104 | + .cookie("MODPLSQL_SESSION", cookie) |
| 105 | + .get(String.class); |
| 106 | + |
| 107 | + log.info("{}", response); |
| 108 | + MatcherAssert.assertThat(response, CoreMatchers.containsString(String.format("COOKIE => %s", cookie))); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void getCookie(){ |
| 113 | + Response response = ClientBuilder.newClient() |
| 114 | + .target(endpoint + "/!MODPLSQL.GET_COOKIE") |
| 115 | + .request() |
| 116 | + .get(); |
| 117 | + |
| 118 | + log.info("{}", response); |
| 119 | + Assertions.assertTrue(response.getCookies().size() > 0); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void httpNoParam(){ |
| 124 | + String response = ClientBuilder.newClient() |
| 125 | + .target(endpoint + "/!MODPLSQL.HTTP_NO_PARAM") |
| 126 | + .request() |
| 127 | + .get(String.class); |
| 128 | + |
| 129 | + log.info("{}", response); |
| 130 | + MatcherAssert.assertThat(response, CoreMatchers.containsString("HTTP_NO_PARAM => OK")); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void httpNamedParam(){ |
| 135 | + String p_vl1 = RandomStringUtils.randomAlphanumeric(10); |
| 136 | + |
| 137 | + String response = ClientBuilder.newClient() |
| 138 | + .target(endpoint + "/!MODPLSQL.HTTP_NAMED_PARAM?P_VL1=" + p_vl1) |
| 139 | + .request() |
| 140 | + .get(String.class); |
| 141 | + |
| 142 | + log.info("{}", response); |
| 143 | + MatcherAssert.assertThat(response, CoreMatchers.containsString("P_VL1 => " + p_vl1)); |
| 144 | + } |
55 | 145 | }
|
0 commit comments