Skip to content

Commit

Permalink
Format Test Response Files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishad-M-I-M committed Jun 8, 2023
2 parents 823e721 + b42dec0 commit 1539d1e
Show file tree
Hide file tree
Showing 10 changed files with 749 additions and 40 deletions.
22 changes: 18 additions & 4 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ task downloadBallerinaDist(type: Download) {
}
}

task getBalHomePath {
dependsOn {
extractBallerinaDist
}
doLast {
if (checkBallerinaVersion.shouldDownload){
getBalHomePath.ext.balHomePath =
"${project.buildDir}/ballerina-${ballerinaLangVersion}-swan-lake/distributions/ballerina-${ballerinaLangVersion}"
} else {
getBalHomePath.ext.balHomePath =
"${System.getProperty("BALLERINA_HOME")}/distributions/ballerina-${ballerinaLangVersion}"
}
}
}

task extractBallerinaDist(type: Copy) {
dependsOn downloadBallerinaDist
onlyIf {
Expand All @@ -138,7 +153,6 @@ task extractBallerinaDist(type: Copy) {
into project.buildDir
doLast {
println "Ballerina distribution extracted successfully."
System.setProperty("BALLERINA_HOME", "${project.buildDir}/${fileName}")
}
}

Expand Down Expand Up @@ -166,13 +180,13 @@ task checkBallerinaVersion(type: Exec) {

test {
dependsOn {
extractBallerinaDist
getBalHomePath
}
doFirst {
println "Ballerina distribution path: ${System.getProperty("BALLERINA_HOME")}/distributions/ballerina-${ballerinaLangVersion}"
println "Ballerina Home Path: ${getBalHomePath.balHomePath}"
systemProperties = [
"target.dir" : project.buildDir,
"ballerina.home": "${System.getProperty("BALLERINA_HOME")}/distributions/ballerina-${ballerinaLangVersion}"
"ballerina.home": getBalHomePath.balHomePath
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ public static String getRequestContent(String filename) throws IOException {
}

public static String getResponseContent(String filename) throws IOException {
return Files.readString(sampleResponseResourceDir.resolve(filename + ".json"));
return replaceWhiteSpacesAndNewLines(Files.readString(sampleResponseResourceDir.resolve(filename + ".json")));
}

public static String getGraphqlQueryResponse(String graphqlUrl, String query) throws IOException {
return getGraphqlResponse(graphqlUrl, ("{\"query\":\"{" + query + "}\"}").getBytes());
return replaceWhiteSpacesAndNewLines(getGraphqlResponse(graphqlUrl,
("{\"query\":\"{" + query + "}\"}").getBytes()));
}

public static String getGraphqlMutationResponse(String grapqlUrl, String query) throws IOException {
return getGraphqlResponse(grapqlUrl, ("{\"query\":\"" + query + "\"}").getBytes());
return replaceWhiteSpacesAndNewLines(getGraphqlResponse(grapqlUrl,
("{\"query\":\"" + query + "\"}").getBytes()));
}

private static String getGraphqlResponse(String grapqlUrl, byte[] body) throws IOException {
Expand Down Expand Up @@ -147,4 +149,8 @@ public static String getCorrespondingFolderName(String schemaFileName) {
char firstChar = schemaFileName.charAt(0);
return Character.toLowerCase(firstChar) + schemaFileName.substring(1);
}

public static String replaceWhiteSpacesAndNewLines(String str) {
return str.replaceAll("\\s+", "").replaceAll("\\n+", "");
}
}
28 changes: 0 additions & 28 deletions native/src/test/java/io/xlibb/gateway/generator/GraphqlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Utility class for Graphql tests.
Expand Down Expand Up @@ -76,30 +74,4 @@ public void clean() {
System.setOut(null);
}

protected String readOutput(boolean status) throws IOException {
String output = this.console.toString();
this.console.close();
this.console = new ByteArrayOutputStream();
this.printStream = new PrintStream(this.console);
if (!status) {
PrintStream out = System.out;
out.println(output);
}
return output;
}

protected String readContent(Path path) throws IOException {
Stream<String> lines = Files.lines(path);
String output = lines.collect(Collectors.joining(System.lineSeparator()));
lines.close();
return output.trim().replaceAll("\\s+", "").replaceAll(System.lineSeparator(), "");
}

protected String readContentWithFormat(Path filePath) throws IOException {
Stream<String> schemaLines = Files.lines(filePath);
String schemaContent = schemaLines.collect(Collectors.joining(System.getProperty("line.separator")));
schemaLines.close();
return schemaContent;
}

}
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
{"data":{"addMission":{"id":15, "designation":"Apollo 17", "crew":[{"id":6, "name":"Eugene Cernan", "missions":[{"id":8, "designation":"Apollo 10"}, {"id":15, "designation":"Apollo 17"}]}, {"id":13, "name":"Ronald Evans", "missions":[{"id":15, "designation":"Apollo 17"}]}, {"id":24, "name":"Harrison Schmitt", "missions":[{"id":15, "designation":"Apollo 17"}]}]}}}
{
"data": {
"addMission": {
"id": 15,
"designation": "Apollo 17",
"crew": [
{
"id": 6,
"name": "Eugene Cernan",
"missions": [
{
"id": 8,
"designation": "Apollo 10"
},
{
"id": 15,
"designation": "Apollo 17"
}
]
},
{
"id": 13,
"name": "Ronald Evans",
"missions": [
{
"id": 15,
"designation": "Apollo 17"
}
]
},
{
"id": 24,
"name": "Harrison Schmitt",
"missions": [
{
"id": 15,
"designation": "Apollo 17"
}
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{"data":{"astronaut":{"id":1, "name":"Buzz Aldrin"}}}
{
"data": {
"astronaut": {
"id": 1,
"name": "Buzz Aldrin"
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
{"data":{"mission":{"id":1, "designation":"Apollo 1", "crew":[{"id":14, "name":"Gus Grissom"}, {"id":30, "name":"Ed White"}, {"id":7, "name":"Roger B. Chaffee"}]}}}
{
"data": {
"mission": {
"id": 1,
"designation": "Apollo 1",
"crew": [
{
"id": 14,
"name": "Gus Grissom"
},
{
"id": 30,
"name": "Ed White"
},
{
"id": 7,
"name": "Roger B. Chaffee"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
org = "graphql_tool_test"
org = "federation_gateway_test"
name = "astronaut_service"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
org = "graphql_tool_test"
org = "federation_gateway_test"
name = "missions_service"
version = "0.1.0"
Loading

0 comments on commit 1539d1e

Please sign in to comment.