Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Feb 22, 2025
1 parent a4e0c13 commit 1c8a22f
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion integration/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

import app.sdkgen.client.Credentials.Anonymous;
import app.sdkgen.client.Exception.ClientException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.message.BasicNameValuePair;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Main {
public static void main(String[] args) throws ClientException {
public static void main(String[] args) throws ClientException, JsonProcessingException {
Anonymous credentials = new Anonymous();
Client client = new Client("http://127.0.0.1:1080", credentials);

assertGetHello(client);
assertGetEntries(client);
assertInsert(client);
assertThrowException(client);
assertBinary(client);
assertForm(client);
assertJson(client);
assertText(client);
assertXml(client);
}

private static void assertGetHello(Client client) throws ClientException {
Expand Down Expand Up @@ -77,4 +90,60 @@ private static void assertThrowException(Client client) throws ClientException
}
}
}

private static void assertBinary(Client client) throws ClientException
{
byte[] payload = {0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72};

var response = client.test().binary(payload);

if (!Arrays.equals(payload, response)) {
throw new RuntimeException("Test assertBinary failed");
}
}

private static void assertForm(Client client) throws ClientException
{
List<NameValuePair> payload = List.of(new BasicNameValuePair("foo", "bar"));

var response = client.test().form(payload);

if (!response.get(0).getName().equals("foo") || !response.get(0).getValue().equals("bar")) {
throw new RuntimeException("Test assertForm failed");
}
}

private static void assertJson(Client client) throws ClientException, JsonProcessingException {
HashMap<String, String> payload = new HashMap<>();
payload.put("foo", "bar");

var response = client.test().json(payload);

var objectMapper = new ObjectMapper();
if (!objectMapper.writeValueAsString(payload).equals(objectMapper.writeValueAsString(response))) {
throw new RuntimeException("Test assertJson failed");
}
}

private static void assertText(Client client) throws ClientException
{
String payload = "foobar";

var response = client.test().text(payload);

if (!payload.equals(response)) {
throw new RuntimeException("Test assertText failed");
}
}

private static void assertXml(Client client) throws ClientException
{
String payload = "<foo>bar</foo>";

var response = client.test().xml(payload);

if (!payload.equals(response)) {
throw new RuntimeException("Test assertXml failed");
}
}
}

0 comments on commit 1c8a22f

Please sign in to comment.