|
2 | 2 |
|
3 | 3 | import app.sdkgen.client.Credentials.Anonymous;
|
4 | 4 | import app.sdkgen.client.Exception.ClientException;
|
| 5 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 7 | +import org.apache.hc.core5.http.NameValuePair; |
| 8 | +import org.apache.hc.core5.http.message.BasicNameValuePair; |
| 9 | + |
| 10 | +import java.util.Arrays; |
| 11 | +import java.util.HashMap; |
| 12 | +import java.util.List; |
5 | 13 |
|
6 | 14 | public class Main {
|
7 |
| - public static void main(String[] args) throws ClientException { |
| 15 | + public static void main(String[] args) throws ClientException, JsonProcessingException { |
8 | 16 | Anonymous credentials = new Anonymous();
|
9 | 17 | Client client = new Client("http://127.0.0.1:1080", credentials);
|
10 | 18 |
|
11 | 19 | assertGetHello(client);
|
12 | 20 | assertGetEntries(client);
|
13 | 21 | assertInsert(client);
|
14 | 22 | assertThrowException(client);
|
| 23 | + assertBinary(client); |
| 24 | + assertForm(client); |
| 25 | + assertJson(client); |
| 26 | + assertText(client); |
| 27 | + assertXml(client); |
15 | 28 | }
|
16 | 29 |
|
17 | 30 | private static void assertGetHello(Client client) throws ClientException {
|
@@ -77,4 +90,60 @@ private static void assertThrowException(Client client) throws ClientException
|
77 | 90 | }
|
78 | 91 | }
|
79 | 92 | }
|
| 93 | + |
| 94 | + private static void assertBinary(Client client) throws ClientException |
| 95 | + { |
| 96 | + byte[] payload = {0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72}; |
| 97 | + |
| 98 | + var response = client.test().binary(payload); |
| 99 | + |
| 100 | + if (!Arrays.equals(payload, response)) { |
| 101 | + throw new RuntimeException("Test assertBinary failed"); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + private static void assertForm(Client client) throws ClientException |
| 106 | + { |
| 107 | + List<NameValuePair> payload = List.of(new BasicNameValuePair("foo", "bar")); |
| 108 | + |
| 109 | + var response = client.test().form(payload); |
| 110 | + |
| 111 | + if (!response.get(0).getName().equals("foo") || !response.get(0).getValue().equals("bar")) { |
| 112 | + throw new RuntimeException("Test assertForm failed"); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + private static void assertJson(Client client) throws ClientException, JsonProcessingException { |
| 117 | + HashMap<String, String> payload = new HashMap<>(); |
| 118 | + payload.put("foo", "bar"); |
| 119 | + |
| 120 | + var response = client.test().json(payload); |
| 121 | + |
| 122 | + var objectMapper = new ObjectMapper(); |
| 123 | + if (!objectMapper.writeValueAsString(payload).equals(objectMapper.writeValueAsString(response))) { |
| 124 | + throw new RuntimeException("Test assertJson failed"); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + private static void assertText(Client client) throws ClientException |
| 129 | + { |
| 130 | + String payload = "foobar"; |
| 131 | + |
| 132 | + var response = client.test().text(payload); |
| 133 | + |
| 134 | + if (!payload.equals(response)) { |
| 135 | + throw new RuntimeException("Test assertText failed"); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + private static void assertXml(Client client) throws ClientException |
| 140 | + { |
| 141 | + String payload = "<foo>bar</foo>"; |
| 142 | + |
| 143 | + var response = client.test().xml(payload); |
| 144 | + |
| 145 | + if (!payload.equals(response)) { |
| 146 | + throw new RuntimeException("Test assertXml failed"); |
| 147 | + } |
| 148 | + } |
80 | 149 | }
|
0 commit comments