Skip to content

Commit

Permalink
add cucumber test for api definition endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DDH13 committed May 2, 2024
1 parent c2a0997 commit ed46c2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
Expand Down
23 changes: 23 additions & 0 deletions test/cucumber-tests/src/test/resources/tests/api/GRPC.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed46c2c

Please sign in to comment.