-
Notifications
You must be signed in to change notification settings - Fork 50
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 #1692 from lnash94/error-message-bto
[master] Fix providing error message for openapi spec generation when bal service has compilation issues
- Loading branch information
Showing
18 changed files
with
347 additions
and
39 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
78 changes: 78 additions & 0 deletions
78
...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,78 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). | ||
* | ||
* 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 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 class contains all the ballerina to OpenAPI command related negative tests. | ||
*/ | ||
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 testForGivenBalServiceHasCompilationIssue() 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 is skipped because of the Ballerina file/package has the " + | ||
" following compilation error(s):\n" + | ||
"ERROR [service.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("cpi_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) 2024, WSO2 LLC. (http://www.wso2.org). | ||
* | ||
* 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 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(); | ||
} | ||
|
||
//TODO: Fix the test case , verified manually | ||
@Test(description = "Ballerina package has compilation error", enabled = false) | ||
public void packageHasCompilationErrors() throws IOException, InterruptedException { | ||
List<String> buildArgs = new LinkedList<>(); | ||
buildArgs.add(0, "build"); | ||
buildArgs.add("--export-openapi"); | ||
Process process = getProcess(buildArgs, TEST_RESOURCE.resolve("package_with_compilation_issue")); | ||
String out = "openapi contract generation is skipped because of the following compilation error(s) in " + | ||
"the ballerina package:\n" + | ||
" ERROR [service.bal:(10:1,10:2)] invalid token '}'"; | ||
// compare generated file has not included constraint annotation for scenario record field. | ||
Assert.assertFalse(Files.exists(RESOURCE.resolve("\"build/package_with_compilation_issue/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: {} |
Oops, something went wrong.