From ed46c2c316adffc8d6e6db9adbbebe76dd9c3780 Mon Sep 17 00:00:00 2001 From: DinethH Date: Thu, 2 May 2024 16:27:45 +0530 Subject: [PATCH] add cucumber test for api definition endpoint --- .../wso2/apk/integration/api/BaseSteps.java | 6 ++++- .../src/test/resources/tests/api/GRPC.feature | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java index d31b2c245..7f4e7826a 100644 --- a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java +++ b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java @@ -112,6 +112,11 @@ public void theStudentResponseBodyShouldContainNameAndAge(String arg0, int arg1) public void theResponseBodyShouldContain(String expectedText) throws IOException { Assert.assertTrue(sharedContext.getResponseBody().contains(expectedText), "Actual response body: " + sharedContext.getResponseBody()); } + @Then("the response body should contain endpoint definition for student.proto") + public void theResponseBodyShouldContainEndpointDefinition() throws IOException { + String expectedText = "{\"apiDefinition\":\"syntax = \\\"proto3\\\";\\n\\noption java_multiple_files = true;\\noption java_package = \\\"org.example\\\";\\npackage dineth.grpc.api.v1.student;\\n\\nservice StudentService {\\n rpc GetStudent(StudentRequest) returns (StudentResponse) {};\\n rpc GetStudentStream(StudentRequest) returns (stream StudentResponse) {};\\n rpc SendStudentStream(stream StudentRequest) returns (StudentResponse) {};\\n rpc SendAndGetStudentStream(stream StudentRequest) returns (stream StudentResponse) {}\\n}\\n\\nmessage StudentRequest {\\n int32 id = 3;\\n}\\n\\nmessage StudentResponse {\\n string name = 1;\\n int32 age = 2;\\n}\\n\"}"; + Assert.assertTrue(sharedContext.getResponseBody().contains(expectedText), "Actual response body: " + sharedContext.getResponseBody()); + } @Then("the response body should not contain {string}") public void theResponseBodyShouldNotContain(String expectedText) throws IOException { Assert.assertFalse(sharedContext.getResponseBody().contains(expectedText), "Actual response body: " + sharedContext.getResponseBody()); @@ -134,7 +139,6 @@ public void theResponseStatusCodeShouldBe(int expectedStatusCode) throws IOExcep @Then("the grpc error response status code should be {int}") public void theGrpcErrorResponseStatusCodeShouldBe(int expectedStatusCode) throws IOException { - int actualStatusCode = sharedContext.getGrpcErrorCode(); Assert.assertEquals(actualStatusCode, expectedStatusCode); } diff --git a/test/cucumber-tests/src/test/resources/tests/api/GRPC.feature b/test/cucumber-tests/src/test/resources/tests/api/GRPC.feature index c6b7ebcd8..8ebc10e4d 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/GRPC.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/GRPC.feature @@ -20,6 +20,29 @@ Feature: Generating APK conf for gRPC API | 500 | And the student response body should contain name: "Dineth" age: 10 + Scenario: Undeploy API + Given The system is ready + And I have a valid subscription + When I undeploy the API whose ID is "grpc-basic-api" + Then the response status code should be 202 + + Scenario: Checking api-definition endpoint to get proto file + Given The system is ready + And I have a valid subscription + When I use the APK Conf file "artifacts/apk-confs/grpc/grpc.apk-conf" + And the definition file "artifacts/definitions/student.proto" + And make the API deployment request + Then the response status code should be 200 + Then I set headers + | Authorization | bearer ${accessToken} | + | Host | default.gw.wso2.com | + And I send "GET" request to "https://default.gw.wso2.com:9095/dineth.grpc.api.v1/api-definition/" with body "" + And I eventually receive 200 response code, not accepting + | 429 | + | 500 | + And the response body should contain endpoint definition for student.proto + + Scenario: Undeploy API Given The system is ready And I have a valid subscription