-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error message for openapi spec generations when bal service has c…
…ompilation issue
- Loading branch information
Showing
16 changed files
with
308 additions
and
16 deletions.
There are no files selected for viewing
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
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
76 changes: 76 additions & 0 deletions
76
...tion-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPICLINegativeTests.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,76 @@ | ||
/* | ||
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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 io.ballerina.openapi.cmd; | ||
|
||
import io.ballerina.openapi.OpenAPITest; | ||
import io.ballerina.openapi.TestUtil; | ||
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 io.ballerina.openapi.TestUtil.DISTRIBUTIONS_DIR; | ||
import static io.ballerina.openapi.TestUtil.RESOURCES_PATH; | ||
import static io.ballerina.openapi.TestUtil.assertOnErrorStream; | ||
|
||
/** | ||
* This {@code BallerinaToOpenAPITests} contains all the ballerina to openapi command negative. | ||
*/ | ||
public class BallerinaToOpenAPICLINegativeTests extends OpenAPITest { | ||
public static final String DISTRIBUTION_FILE_NAME = DISTRIBUTIONS_DIR.toString(); | ||
public static final Path TEST_RESOURCE = Paths.get(RESOURCES_PATH.toString() + "/ballerina_sources"); | ||
|
||
@BeforeClass | ||
public void setupDistributions() throws IOException { | ||
TestUtil.cleanDistribution(); | ||
} | ||
|
||
@Test(description = "Test for given bal service file contains compilation issues") | ||
public void constraintWithUnsupportedStringPattern() throws IOException, InterruptedException { | ||
String balFilePath = "bal_service_has_compilation_issue/service.bal"; | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add(0, "openapi"); | ||
buildArgs.add("-i"); | ||
buildArgs.add(balFilePath); | ||
buildArgs.add("-o"); | ||
buildArgs.add(tmpDir.toString()); | ||
|
||
Process process = getProcess(buildArgs, TEST_RESOURCE); | ||
|
||
String out = "OpenAPI contract generation failed due to Ballerina code has compilation errors. :\n" + | ||
"ERROR [main.bal:(11:1,11:2)] invalid token '}'"; | ||
//Thread for wait out put generate | ||
Thread.sleep(5000); | ||
// compare generated file has not included constraint annotation for scenario record field. | ||
Assert.assertFalse(Files.exists(TEST_RESOURCE.resolve("payload_openapi.yaml"))); | ||
process.waitFor(); | ||
assertOnErrorStream(process, out); | ||
} | ||
|
||
@AfterClass | ||
public void cleanUp() throws IOException { | ||
TestUtil.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
66 changes: 66 additions & 0 deletions
66
...tests/src/test/java/io/ballerina/openapi/extension/build/BuildExtensionNegativeTests.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,66 @@ | ||
/* | ||
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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 io.ballerina.openapi.extension.build; | ||
|
||
import io.ballerina.openapi.OpenAPITest; | ||
import io.ballerina.openapi.TestUtil; | ||
import org.testng.Assert; | ||
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 io.ballerina.openapi.TestUtil.DISTRIBUTIONS_DIR; | ||
import static io.ballerina.openapi.TestUtil.RESOURCE; | ||
import static io.ballerina.openapi.TestUtil.RESOURCES_PATH; | ||
import static io.ballerina.openapi.TestUtil.assertOnErrorStream; | ||
|
||
/** | ||
* These negative tests are related to the `--export-openapi` flag for `bal build` command. | ||
*/ | ||
public class BuildExtensionNegativeTests extends OpenAPITest { | ||
public static final String DISTRIBUTION_FILE_NAME = DISTRIBUTIONS_DIR.toString(); | ||
public static final Path TEST_RESOURCE = Paths.get(RESOURCES_PATH.toString() + "/build"); | ||
|
||
@BeforeClass | ||
public void setupDistributions() throws IOException { | ||
TestUtil.cleanDistribution(); | ||
} | ||
|
||
@Test(description = "Ballerina package has compilation error") | ||
public void packageHasCompilationErrors() throws IOException, InterruptedException { | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add("build"); | ||
buildArgs.add("--export-openapi"); | ||
Process process = getProcess(buildArgs, TEST_RESOURCE); | ||
|
||
String out = "OpenAPI contract generation failed due to Ballerina code has compilation errors. :\n" + | ||
"ERROR [main.bal:(11:1,11:2)] invalid token '}'"; | ||
//Thread for wait out put generate | ||
Thread.sleep(5000); | ||
// compare generated file has not included constraint annotation for scenario record field. | ||
Assert.assertFalse(Files.exists(RESOURCE.resolve("\"build/project_9/target/openapi/"))); | ||
process.waitFor(); | ||
assertOnErrorStream(process, out); | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
...n-tests/src/test/resources/ballerina_sources/bal_service_has_compilation_issue/.gitignore
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 @@ | ||
target |
8 changes: 8 additions & 0 deletions
8
...sts/src/test/resources/ballerina_sources/bal_service_has_compilation_issue/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,8 @@ | ||
[package] | ||
org = "openapi_gen_test" | ||
name = "compilation_issue" | ||
version = "0.1.0" | ||
|
||
[build-options] | ||
observabilityIncluded = true | ||
|
23 changes: 23 additions & 0 deletions
23
...-tests/src/test/resources/ballerina_sources/bal_service_has_compilation_issue/result.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,23 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: Mock Yaml | ||
version: 2.0.0 | ||
servers: | ||
- url: "{server}:{port}/" | ||
variables: | ||
server: | ||
default: http://localhost | ||
port: | ||
default: "9090" | ||
paths: | ||
/greeting: | ||
get: | ||
operationId: getGreeting | ||
responses: | ||
"200": | ||
description: Ok | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
components: {} |
10 changes: 10 additions & 0 deletions
10
...-tests/src/test/resources/ballerina_sources/bal_service_has_compilation_issue/service.bal
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,10 @@ | ||
import ballerina/http; | ||
|
||
service /payload on new http:Listener(0) { | ||
resource function get hello() { | ||
} | ||
|
||
resource function post path(@http:Payload string name) { | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
openapi-integration-tests/src/test/resources/build/pakage_with_compilation_issue/.gitignore
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 @@ | ||
target |
8 changes: 8 additions & 0 deletions
8
...i-integration-tests/src/test/resources/build/pakage_with_compilation_issue/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,8 @@ | ||
[package] | ||
org = "openapi_extension_test" | ||
name = "compilation_issue" | ||
version = "0.1.0" | ||
|
||
[build-options] | ||
observabilityIncluded = true | ||
|
Oops, something went wrong.