commit c5e176f17ca54151ab5df67e66d46a7371fb2266 Author: Greg Gauthier Date: Wed Jul 12 14:14:52 2023 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..accd629 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..004a2c1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + + com.gmgauthier + utilites + 1.0-SNAPSHOT + + + 11 + 11 + UTF-8 + + + + + + io.rest-assured + rest-assured + 5.3.1 + test + + + + + org.glassfish.jersey.core + jersey-client + 3.1.2 + + + + + org.glassfish.jersey.ext + jersey-proxy-client + 3.1.2 + test + + + + + com.fasterxml.jackson.core + jackson-core + 2.15.2 + + + + + com.fasterxml.jackson.core + jackson-databind + 2.15.2 + + + + + com.fasterxml.jackson.core + jackson-annotations + 2.15.2 + + + + + com.konghq + unirest-java + 3.14.5 + + + + + com.konghq + unirest-objectmapper-jackson + 4.0.1 + + + + + com.google.code.gson + gson + 2.10.1 + + + + + io.cucumber + cucumber-java + 7.13.0 + + + + + + \ No newline at end of file diff --git a/src/main/java/com/gmgauthier/JsonUtils.java b/src/main/java/com/gmgauthier/JsonUtils.java new file mode 100644 index 0000000..fa090bd --- /dev/null +++ b/src/main/java/com/gmgauthier/JsonUtils.java @@ -0,0 +1,44 @@ +package com.gmgauthier; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import io.cucumber.datatable.DataTable; +import kong.unirest.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class JsonUtils { + public JSONObject getJsonFromGson(JsonObject jsonObject) { + return new JSONObject().getJSONObject(jsonObject.toString()); + } + + public JSONObject getJsonFromDataTable(DataTable dataTable) { + List> tableDetails = + dataTable.transpose().asMaps(String.class, String.class); + String bodyString = new Gson().toJson(tableDetails.get(0)); //root element + return new JSONObject(bodyString); + } + + public JsonObject getFixtureDataFrom(String filename) throws IOException { + String json = getJsonAsString(filename); + return new Gson().fromJson(json, JsonObject.class); + } + + public String getJsonAsString(String filename) throws IOException { + BufferedReader reader = null; + InputStream inputStream = + getClass().getResourceAsStream("/relative/path/%s.json"); + if (inputStream != null) { + reader = new BufferedReader(new InputStreamReader(inputStream)); + } else { + throw new IOException("%s.json not found, or has no content."); + } + return reader.lines().collect(Collectors.joining(System.lineSeparator())); + } +} \ No newline at end of file