From 64292fcda33dd18602befc17c8772c9e07b36dd8 Mon Sep 17 00:00:00 2001 From: lnash94 Date: Thu, 7 Nov 2024 15:22:51 +0530 Subject: [PATCH] Add negative tests --- .../BallerinaToOpenAPICLINegativeTests.java | 21 +++++++++++ .../Ballerina.toml | 4 +++ .../result.yaml | 33 +++++++++++++++++ .../service_file.bal | 35 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/Ballerina.toml create mode 100644 openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/result.yaml create mode 100644 openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/service_file.bal diff --git a/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPICLINegativeTests.java b/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPICLINegativeTests.java index 02b918cf9..15b957b03 100644 --- a/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPICLINegativeTests.java +++ b/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPICLINegativeTests.java @@ -99,6 +99,27 @@ public void testForExamplesHasCompilerErrorse() throws IOException, InterruptedE assertOnErrorStream(process, out); } + @Test(description = "Generate with openapi serviceConfig annotation to service contract type " + + "and service declaration") + public void openapiServiceConfigForServiceContractTypeWithServiceDeclaration() throws IOException, + InterruptedException { + String balFilePath = "project_openapi_info_with_service_contract_type_and_declaration/service_file.bal"; + List 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); + //Thread for wait out put generate + Thread.sleep(5000); + // compare generated file has not included constraint annotation for scenario record field. + Assert.assertTrue(Files.exists(TEST_RESOURCE.resolve("service_contract_openapi.yaml"))); + Assert.assertTrue(Files.exists(TEST_RESOURCE.resolve("v1_openapi.yaml"))); + process.waitFor(); + } + @AfterClass public void cleanUp() throws IOException { TestUtil.cleanDistribution(); diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/Ballerina.toml b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/Ballerina.toml new file mode 100644 index 000000000..e1316d57d --- /dev/null +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org= "ballerina" +name= "openapi_service_contract" +version= "2.0.0" diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/result.yaml b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/result.yaml new file mode 100644 index 000000000..641cc4efd --- /dev/null +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/result.yaml @@ -0,0 +1,33 @@ +openapi: 3.0.1 +info: + title: Pet Store + description: API system description + termsOfService: http://mock-api-doc + contact: + name: sumudu + url: http://mock-api-contact + email: sumudu@abc.com + license: + name: ABC + url: http://abc.com + version: 1.0.0 +servers: + - url: "http://{server}:{port}/v1" + variables: + server: + default: localhost + port: + default: "8080" +paths: + /users: + get: + operationId: getUsers + responses: + "200": + description: Ok + content: + application/json: + schema: + type: array + items: + type: string diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/service_file.bal b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/service_file.bal new file mode 100644 index 000000000..8120d40d3 --- /dev/null +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info_with_service_contract_type_and_declaration/service_file.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// 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. + +import ballerina/http; +import ballerina/openapi; + +@openapi:ServiceInfo { + version: "1.0.0", + title: "Pet store", + description: "API system description", + email: "sumudu@abc.com", + contactName: "sumudu", + contactURL: "http://mock-api-contact", + termsOfService: "http://mock-api-doc", + licenseName: "ABC", + licenseURL: "http://abc.com" +} +@http:ServiceConfig {basePath: "/v1"} +type OASServiceType service object { + *http:ServiceContract; + resource function get users() returns string[]; +};