-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4898 from DimuthuMadushan/add-gql-tool-test
Add Integration Tests for GraphQL Tool
- Loading branch information
Showing
15 changed files
with
665 additions
and
14 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
ballerina-test/src/test/java/org/ballerinalang/distribution/test/GraphqlToolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.ballerinalang.distribution.test; | ||
|
||
import org.ballerinalang.distribution.utils.TestUtils; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import static org.ballerinalang.distribution.utils.TestUtils.*; | ||
|
||
public class GraphqlToolTest { | ||
|
||
@BeforeClass | ||
public void setupDistributions() throws IOException { | ||
TestUtils.cleanDistribution(); | ||
TestUtils.prepareDistribution(DISTRIBUTIONS_DIR.resolve(DISTRIBUTION_FILE_NAME + ".zip")); | ||
} | ||
|
||
@Test(description = "Check GraphQL client generation") | ||
public void testGraphqlClientGenerationUsingEndpoint() throws IOException, InterruptedException { | ||
Path testResource = Paths.get("/graphql/client-gen/project_1"); | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add("-i"); | ||
buildArgs.add("graphql_endpoint.config.yaml"); | ||
boolean successful = TestUtils.executeGraphql(DISTRIBUTION_FILE_NAME, TestUtils.getResource(testResource), | ||
buildArgs); | ||
Assert.assertTrue(successful); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("client.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("types.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("config_types.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("utils.bal"))); | ||
TestUtils.deleteGeneratedFiles("client.bal", GRAPHQL_CMD); | ||
} | ||
|
||
@Test(description = "Check GraphQL client generation") | ||
public void testGraphqlClientGenerationUsingSchemaFile() throws IOException, InterruptedException { | ||
Path testResource = Paths.get("/graphql/client-gen/project_2"); | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add("-i"); | ||
buildArgs.add("graphql_schema.config.yaml"); | ||
boolean successful = TestUtils.executeGraphql(DISTRIBUTION_FILE_NAME, TestUtils.getResource(testResource), | ||
buildArgs); | ||
Assert.assertTrue(successful); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("client.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("types.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("config_types.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("utils.bal"))); | ||
TestUtils.deleteGeneratedFiles("client.bal", GRAPHQL_CMD); | ||
} | ||
|
||
@Test(description = "Check GraphQL schema generation") | ||
public void testGraphqlSchemaGeneration() throws IOException, InterruptedException { | ||
Path testResource = Paths.get("/graphql/schema-gen"); | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add("-i"); | ||
buildArgs.add("service.bal"); | ||
boolean successful = TestUtils.executeGraphql(DISTRIBUTION_FILE_NAME, TestUtils.getResource(testResource), | ||
buildArgs); | ||
Assert.assertTrue(successful); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("schema_graphql.graphql"))); | ||
TestUtils.deleteGeneratedFiles("schema_graphql.graphql", GRAPHQL_CMD); | ||
} | ||
|
||
@Test(description = "Check GraphQL schema generation") | ||
public void testGraphqlSchemaGenerationWithServicePathFlag() throws IOException, InterruptedException { | ||
Path testResource = Paths.get("/graphql/schema-gen/project_1"); | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add("-i"); | ||
buildArgs.add("main.bal"); | ||
buildArgs.add("-s"); | ||
buildArgs.add("/gql"); | ||
boolean successful = TestUtils.executeGraphql(DISTRIBUTION_FILE_NAME, TestUtils.getResource(testResource), | ||
buildArgs); | ||
Assert.assertTrue(successful); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("schema_gql.graphql"))); | ||
TestUtils.deleteGeneratedFiles("schema_gql.graphql", GRAPHQL_CMD); | ||
} | ||
|
||
@Test(description = "Check GraphQL service generation") | ||
public void testGraphqlServiceGeneration() throws IOException, InterruptedException { | ||
Path testResource = Paths.get("/graphql/service-gen"); | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add("-i"); | ||
buildArgs.add("schema_starwars.graphql"); | ||
boolean successful = TestUtils.executeGraphql(DISTRIBUTION_FILE_NAME, TestUtils.getResource(testResource), | ||
buildArgs); | ||
Assert.assertTrue(successful); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("service.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("types.bal"))); | ||
TestUtils.deleteGeneratedFiles("service.bal", GRAPHQL_CMD); | ||
} | ||
|
||
@Test(description = "Check GraphQL service generation") | ||
public void testGraphqlServiceGenerationWithRecordFlag() throws IOException, InterruptedException { | ||
Path testResource = Paths.get("/graphql/service-gen"); | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add("-i"); | ||
buildArgs.add("schema_book.graphql"); | ||
buildArgs.add("-r"); | ||
boolean successful = TestUtils.executeGraphql(DISTRIBUTION_FILE_NAME, TestUtils.getResource(testResource), | ||
buildArgs); | ||
Assert.assertTrue(successful); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("service.bal"))); | ||
Assert.assertTrue(Files.exists(TestUtils.getResource(testResource).resolve("types.bal"))); | ||
TestUtils.deleteGeneratedFiles("service.bal", GRAPHQL_CMD); | ||
} | ||
|
||
@AfterClass | ||
public void cleanUp() throws IOException { | ||
TestUtils.cleanDistribution(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
ballerina-test/src/test/resources/graphql/client-gen/project_1/graphql_endpoint.config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## The GraphQL schema. E.g., https://countries.trevorblades.com or ./schemas/country.graphql | ||
schema: https://countries.trevorblades.com | ||
## The GraphQL documents that have queries/mutations | ||
documents: | ||
- ./query_country.graphql |
5 changes: 5 additions & 0 deletions
5
ballerina-test/src/test/resources/graphql/client-gen/project_1/query_country.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
query countryByCode($code: ID!) { | ||
country(code: $code) { | ||
name | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
ballerina-test/src/test/resources/graphql/client-gen/project_2/graphql_schema.config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## The GraphQL schema. E.g., https://countries.trevorblades.com or ./schemas/country.graphql | ||
schema: ./schema_country.graphql | ||
## The GraphQL documents that have queries/mutations | ||
documents: | ||
- ./queries/query_country.graphql |
5 changes: 5 additions & 0 deletions
5
ballerina-test/src/test/resources/graphql/client-gen/project_2/queries/query_country.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
query countryByCode($code: ID!) { | ||
country(code: $code) { | ||
name | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
ballerina-test/src/test/resources/graphql/client-gen/project_2/schema_country.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
schema { | ||
query: Query | ||
} | ||
|
||
"Directs the executor to include this field or fragment only when the `if` argument is true" | ||
directive @include( | ||
"Included when true." | ||
if: Boolean! | ||
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
|
||
"Directs the executor to skip this field or fragment when the `if`'argument is true." | ||
directive @skip( | ||
"Skipped when true." | ||
if: Boolean! | ||
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
|
||
directive @cacheControl(maxAge: Int, scope: CacheControlScope) on OBJECT | FIELD_DEFINITION | INTERFACE | ||
|
||
"Marks the field, argument, input field or enum value as deprecated" | ||
directive @deprecated( | ||
"The reason for the deprecation" | ||
reason: String = "No longer supported" | ||
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION | ||
|
||
"Exposes a URL that specifies the behaviour of this scalar." | ||
directive @specifiedBy( | ||
"The URL that specifies the behaviour of this scalar." | ||
url: String! | ||
) on SCALAR | ||
|
||
type Continent { | ||
code: ID! | ||
countries: [Country!]! | ||
name: String! | ||
} | ||
|
||
type Country { | ||
capital: String | ||
code: ID! | ||
continent: Continent! | ||
currency: String | ||
emoji: String! | ||
emojiU: String! | ||
languages: [Language!]! | ||
name: String! | ||
native: String! | ||
phone: String! | ||
states: [State!]! | ||
} | ||
|
||
type Language { | ||
code: ID! | ||
name: String | ||
native: String | ||
rtl: Boolean! | ||
} | ||
|
||
type Query { | ||
continent(code: ID!): Continent | ||
continents(filter: ContinentFilterInput): [Continent!]! | ||
countries(filter: CountryFilterInput): [Country!]! | ||
country(code: ID!): Country | ||
language(code: ID!): Language | ||
languages(filter: LanguageFilterInput): [Language!]! | ||
} | ||
|
||
type State { | ||
code: String | ||
country: Country! | ||
name: String! | ||
} | ||
|
||
enum CacheControlScope { | ||
PRIVATE | ||
PUBLIC | ||
} | ||
|
||
"The `Upload` scalar type represents a file upload." | ||
scalar Upload | ||
|
||
input ContinentFilterInput { | ||
code: StringQueryOperatorInput | ||
} | ||
|
||
input CountryFilterInput { | ||
code: StringQueryOperatorInput | ||
continent: StringQueryOperatorInput | ||
currency: StringQueryOperatorInput | ||
} | ||
|
||
input LanguageFilterInput { | ||
code: StringQueryOperatorInput | ||
} | ||
|
||
input StringQueryOperatorInput { | ||
eq: String | ||
in: [String!] | ||
ne: String | ||
nin: [String!] | ||
regex: String | ||
} |
4 changes: 4 additions & 0 deletions
4
ballerina-test/src/test/resources/graphql/schema-gen/project_1/Ballerina.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
org = "ballerina_sdl_file_generator_test" | ||
name = "project_1" | ||
version = "0.1.0" |
Oops, something went wrong.