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 a95faed commit 3b91774
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,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 @@ -176,20 +176,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 @@ -198,12 +188,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 @@ -37,7 +37,7 @@ public class SharedContext {
private String accessToken;
private HttpResponse response;
private String responseBody;
private int grpcErrorCode;
private int grpcStatusCode;
private String publisherAccessToken;
private String devportalAccessToken;
private String adminportalAccessToken;
Expand Down Expand Up @@ -77,11 +77,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 3b91774

Please sign in to comment.