From b43369023e8cdc2a2a9b166ba838f14b7df1b101 Mon Sep 17 00:00:00 2001 From: DinethH Date: Thu, 9 May 2024 10:09:42 +0530 Subject: [PATCH] changed gRPC status code --- .../wso2/apk/integration/api/BaseSteps.java | 30 ++++++------------- .../apk/integration/api/SharedContext.java | 11 ++++--- .../src/test/resources/tests/api/GRPC.feature | 22 ++++---------- .../test/resources/tests/api/GRPCMTLS.feature | 5 ++-- 4 files changed, 22 insertions(+), 46 deletions(-) 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 7663f9deee..faf39122f5 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 @@ -137,9 +137,9 @@ public void theResponseStatusCodeShouldBe(int expectedStatusCode) throws IOExcep Assert.assertEquals(actualStatusCode, expectedStatusCode); } - @Then("the grpc error response status code should be {int}") - public void theGrpcErrorResponseStatusCodeShouldBe(int expectedStatusCode) throws IOException { - int actualStatusCode = sharedContext.getGrpcErrorCode(); + @Then("the gRPC response status code should be {int}") + public void theGrpcResponseStatusCodeShouldBe(int expectedStatusCode) throws IOException { + int actualStatusCode = sharedContext.getGrpcStatusCode(); Assert.assertEquals(actualStatusCode, expectedStatusCode); } @@ -171,20 +171,10 @@ public void GetStudent(String arg0, int arg1) throws StatusRuntimeException { try { SimpleGRPCStudentClient grpcStudentClient = new SimpleGRPCStudentClient(arg0, arg1); sharedContext.setStudentResponse(grpcStudentClient.GetStudent(sharedContext.getHeaders())); + sharedContext.setGrpcStatusCode(0); } catch (StatusRuntimeException e) { - if (e.getStatus().getCode()== Status.Code.PERMISSION_DENIED){ - sharedContext.setGrpcErrorCode(403); - } else if (e.getStatus().getCode()== Status.Code.UNIMPLEMENTED){ - sharedContext.setGrpcErrorCode(501); - } else if (e.getStatus().getCode()== Status.Code.UNAVAILABLE){ - sharedContext.setGrpcErrorCode(503); - } else if (e.getStatus().getCode()== Status.Code.NOT_FOUND){ - sharedContext.setGrpcErrorCode(404); - } else if (e.getStatus().getCode()== Status.Code.UNAUTHENTICATED){ - sharedContext.setGrpcErrorCode(401); - } else { - logger.error(e.getMessage() + "code: " + e.getStatus().getCode()); - } + sharedContext.setGrpcStatusCode(e.getStatus().getCode().value()); + logger.error(e.getMessage() + " Status code: " + e.getStatus().getCode().value()) ; } } @@ -193,12 +183,10 @@ public void GetStudentDefaultVersion(String arg0, int arg1) throws StatusRuntime try { SimpleGRPCStudentClient grpcStudentClient = new SimpleGRPCStudentClient(arg0, arg1); sharedContext.setStudentResponse(grpcStudentClient.GetStudentDefaultVersion(sharedContext.getHeaders())); + sharedContext.setGrpcStatusCode(0); } catch (StatusRuntimeException e) { - if (e.getStatus().getCode()== Status.Code.PERMISSION_DENIED){ - sharedContext.setGrpcErrorCode(403); - } else { - logger.error(e.getMessage()); - } + sharedContext.setGrpcStatusCode(e.getStatus().getCode().value()); + logger.error(e.getMessage() + " Status code: " + e.getStatus().getCode().value()) ; } } diff --git a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java index 2b7c88bb0b..66bc9bfbc5 100644 --- a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java +++ b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java @@ -18,7 +18,6 @@ package org.wso2.apk.integration.api; import org.apache.http.HttpResponse; -import org.wso2.apk.integration.utils.clients.SimpleGRPCStudentClient; import org.wso2.apk.integration.utils.clients.SimpleHTTPClient; import org.wso2.apk.integration.utils.clients.studentGrpcClient.StudentResponse; @@ -36,7 +35,7 @@ public class SharedContext { private String accessToken; private HttpResponse response; private String responseBody; - private int grpcErrorCode; + private int grpcStatusCode; private HashMap valueStore = new HashMap<>(); private HashMap headers = new HashMap<>(); @@ -56,11 +55,11 @@ public void setAccessToken(String accessToken) { this.accessToken = accessToken; } - public int getGrpcErrorCode() { - return grpcErrorCode; + public int getGrpcStatusCode() { + return grpcStatusCode; } - public void setGrpcErrorCode(int grpcErrorCode) { - this.grpcErrorCode = grpcErrorCode; + public void setGrpcStatusCode(int grpcStatusCode) { + this.grpcStatusCode = grpcStatusCode; } public HttpResponse getResponse() { 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 8ebc10e4dc..873ad7c48e 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/GRPC.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/GRPC.feature @@ -15,9 +15,7 @@ Feature: Generating APK conf for gRPC API Then I set headers | Authorization | bearer ${accessToken} | And I make grpc request GetStudent to "default.gw.wso2.com" with port 9095 - And I eventually receive 200 response code, not accepting - | 429 | - | 500 | + And the gRPC response status code should be 0 And the student response body should contain name: "Dineth" age: 10 Scenario: Undeploy API @@ -57,9 +55,7 @@ Feature: Generating APK conf for gRPC API And make the API deployment request Then the response status code should be 200 And I make grpc request GetStudent to "default.gw.wso2.com" with port 9095 - And I eventually receive 200 response code, not accepting - | 429 | - | 500 | + And the gRPC response status code should be 0 And the student response body should contain name: "Dineth" age: 10 Scenario: Undeploy API @@ -78,15 +74,13 @@ Feature: Generating APK conf for gRPC API Then I set headers | Authorization | bearer ${accessToken} | And I make grpc request GetStudent to "default.gw.wso2.com" with port 9095 - And the grpc error response status code should be 403 + And the gRPC response status code should be 7 Given I have a valid subscription with scopes | wso2 | Then I set headers | Authorization | bearer ${accessToken} | And I make grpc request GetStudent to "default.gw.wso2.com" with port 9095 - And I eventually receive 200 response code, not accepting - | 429 | - | 500 | + And the gRPC response status code should be 0 And the student response body should contain name: "Dineth" age: 10 Scenario: Undeploy API @@ -105,17 +99,13 @@ Feature: Generating APK conf for gRPC API Then I set headers | Authorization | bearer ${accessToken} | And I make grpc request GetStudent to "default.gw.wso2.com" with port 9095 - And I eventually receive 200 response code, not accepting - | 429 | - | 500 | + And the gRPC response status code should be 0 And the student response body should contain name: "Dineth" age: 10 Given I have a valid subscription Then I set headers | Authorization | bearer ${accessToken} | And I make grpc request GetStudent default version to "default.gw.wso2.com" with port 9095 - And I eventually receive 200 response code, not accepting - | 429 | - | 500 | + And the gRPC response status code should be 0 And the student response body should contain name: "Dineth" age: 10 Scenario: Undeploy API diff --git a/test/cucumber-tests/src/test/resources/tests/api/GRPCMTLS.feature b/test/cucumber-tests/src/test/resources/tests/api/GRPCMTLS.feature index 05548f7ca8..87fa0fac0f 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/GRPCMTLS.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/GRPCMTLS.feature @@ -9,8 +9,7 @@ Feature: Test mTLS between client and gateway with client certificate sent in he Then I set headers | X-WSO2-CLIENT-CERTIFICATE | ${clientCertificate} | And I make grpc request GetStudent to "default.gw.wso2.com" with port 9095 - And I eventually receive 200 response code, not accepting - | 401 | + And the gRPC response status code should be 0 And the student response body should contain name: "Dineth" age: 10 Scenario: Undeploy API @@ -30,7 +29,7 @@ Feature: Test mTLS between client and gateway with client certificate sent in he | X-WSO2-CLIENT-CERTIFICATE | ${clientCertificate} | | Authorization | bearer {accessToken} | And I make grpc request GetStudent to "default.gw.wso2.com" with port 9095 - And the grpc error response status code should be 401 + And the gRPC response status code should be 16 Scenario: Undeploy API Given The system is ready