Skip to content

Commit 1c8a22f

Browse files
committed
add tests
1 parent a4e0c13 commit 1c8a22f

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

integration/java/Main.java

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
22

33
import app.sdkgen.client.Credentials.Anonymous;
44
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;
513

614
public class Main {
7-
public static void main(String[] args) throws ClientException {
15+
public static void main(String[] args) throws ClientException, JsonProcessingException {
816
Anonymous credentials = new Anonymous();
917
Client client = new Client("http://127.0.0.1:1080", credentials);
1018

1119
assertGetHello(client);
1220
assertGetEntries(client);
1321
assertInsert(client);
1422
assertThrowException(client);
23+
assertBinary(client);
24+
assertForm(client);
25+
assertJson(client);
26+
assertText(client);
27+
assertXml(client);
1528
}
1629

1730
private static void assertGetHello(Client client) throws ClientException {
@@ -77,4 +90,60 @@ private static void assertThrowException(Client client) throws ClientException
7790
}
7891
}
7992
}
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+
}
80149
}

0 commit comments

Comments
 (0)