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 6321d4ee7..cba1b1530 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 @@ -53,6 +53,7 @@ import org.wso2.apk.integration.utils.Utils; 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; import java.io.IOException; import java.io.InputStream; @@ -97,8 +98,12 @@ public void systemIsReady() { @Then("the student response body should contain name: {string} age: {int}") public void theStudentResponseBodyShouldContainNameAndAge(String arg0, int arg1) { - int age = sharedContext.getStudentResponse().getAge(); - String name = sharedContext.getStudentResponse().getName(); + StudentResponse studentResponse = sharedContext.getStudentResponse(); + if (studentResponse == null) { + Assert.fail("Student response is null."); + } + int age = studentResponse.getAge(); + String name = studentResponse.getName(); Assert.assertEquals(name, arg0); Assert.assertEquals(age, arg1); } @@ -165,6 +170,8 @@ public void GetStudent(String arg0, int arg1) throws StatusRuntimeException { } catch (StatusRuntimeException e) { if (e.getStatus().getCode()== Status.Code.PERMISSION_DENIED){ sharedContext.setGrpcErrorCode(403); + } else { + logger.error(e.getMessage()); } } } @@ -177,6 +184,8 @@ public void GetStudentDefaultVersion(String arg0, int arg1) throws StatusRuntime } catch (StatusRuntimeException e) { if (e.getStatus().getCode()== Status.Code.PERMISSION_DENIED){ sharedContext.setGrpcErrorCode(403); + } else { + logger.error(e.getMessage()); } } } diff --git a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleGRPCStudentClient.java b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleGRPCStudentClient.java index d8fcc7e7c..c7f04210b 100644 --- a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleGRPCStudentClient.java +++ b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleGRPCStudentClient.java @@ -43,7 +43,14 @@ public StudentResponse GetStudent(Map headers) throws StatusRunt .intercept(interceptor) .build(); StudentServiceGrpc.StudentServiceBlockingStub blockingStub = StudentServiceGrpc.newBlockingStub(managedChannel); - return blockingStub.getStudent(StudentRequest.newBuilder().setId(1).build()); + if (blockingStub == null) { + throw new RuntimeException("Failed to create blocking stub"); + } + StudentResponse response = blockingStub.getStudent(StudentRequest.newBuilder().setId(1).build()); + if (response == null) { + throw new RuntimeException("Failed to get student"); + } + return response; }catch (SSLException e) { throw new RuntimeException("Failed to create SSL context", e); } finally { @@ -74,7 +81,14 @@ public StudentResponse GetStudentDefaultVersion(Map headers) thr .intercept(interceptor) .build(); StudentServiceDefaultVersionGrpc.StudentServiceBlockingStub blockingStub = StudentServiceDefaultVersionGrpc.newBlockingStub(managedChannel); - return blockingStub.getStudent(StudentRequest.newBuilder().setId(1).build()); + if (blockingStub == null) { + throw new RuntimeException("Failed to create blocking stub"); + } + StudentResponse response = blockingStub.getStudent(StudentRequest.newBuilder().setId(1).build()); + if (response == null) { + throw new RuntimeException("Failed to get student"); + } + return response; }catch (SSLException e) { throw new RuntimeException("Failed to create SSL context", e); } finally {