Skip to content

Commit

Permalink
changed gRPC status code
Browse files Browse the repository at this point in the history
  • Loading branch information
DDH13 committed May 9, 2024
1 parent aaa9180 commit b433690
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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()) ;
}
}

Expand All @@ -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()) ;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,7 +35,7 @@ public class SharedContext {
private String accessToken;
private HttpResponse response;
private String responseBody;
private int grpcErrorCode;
private int grpcStatusCode;
private HashMap<String, Object> valueStore = new HashMap<>();
private HashMap<String, String> headers = new HashMap<>();

Expand All @@ -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() {
Expand Down
22 changes: 6 additions & 16 deletions test/cucumber-tests/src/test/resources/tests/api/GRPC.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b433690

Please sign in to comment.