From ffd7a91f4ca0df4541066d6f7427434d66f2db14 Mon Sep 17 00:00:00 2001 From: soletsdev Date: Thu, 8 Feb 2024 14:57:53 -0800 Subject: [PATCH] adding additional testing for coverage --- .../gov/educ/penreg/api/rest/RestUtils.java | 2 +- .../educ/penreg/api/rest/RestUtilsTest.java | 35 +++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java index d0219d4f..39e216e3 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java @@ -118,7 +118,7 @@ public void setGradeCodesMap() { try { writeLock.lock(); this.gradeCodesMap.clear(); - final List gradeCodes = this.webClient.get().uri(this.props.getStudentApiURL(), uri -> uri.path("/grade-codes").build()).header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).retrieve().bodyToFlux(GradeCode.class).collectList().block(); + final List gradeCodes = this.webClient.get().uri(this.props.getStudentApiURL() + "/grade-codes").header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).retrieve().bodyToFlux(GradeCode.class).collectList().block(); this.gradeCodesMap.put(GRADE_CODES, gradeCodes); } catch (Exception ex) { diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java index d0502dc1..9e0b17bc 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java @@ -3,14 +3,13 @@ import ca.bc.gov.educ.penreg.api.constants.EventType; import ca.bc.gov.educ.penreg.api.messaging.MessagePublisher; import ca.bc.gov.educ.penreg.api.properties.ApplicationProperties; -import ca.bc.gov.educ.penreg.api.struct.Event; -import ca.bc.gov.educ.penreg.api.struct.School; -import ca.bc.gov.educ.penreg.api.struct.Student; -import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudentValidationIssueTypeCode; +import ca.bc.gov.educ.penreg.api.struct.*; +import ca.bc.gov.educ.penreg.api.struct.v1.*; import ca.bc.gov.educ.penreg.api.support.NatsMessageImpl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.nats.client.Message; +import java.util.*; import lombok.val; import org.junit.Before; import org.junit.Test; @@ -24,7 +23,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -68,6 +66,7 @@ public class RestUtilsTest { @Before public void setUp() throws Exception { when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(this.applicationProperties.getInstituteApiUrl() + "/school")).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.header(any(), any())).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); @@ -80,12 +79,17 @@ public void setUp() throws Exception { .thenReturn(Flux.just(createValidationIssueTypeCodeArray("GENDER_ERR", "Gender error"))); this.restUtils.populatePenRequestBatchStudentValidationIssueTypeCodeMap(); + when(this.requestHeadersUriMock.uri(this.applicationProperties.getPenServicesApiURL() + "/grade-codes")).thenReturn(this.requestHeadersMock); + when(this.responseMock.bodyToFlux(GradeCode.class)) + .thenReturn(Flux.just(createGradeCodeArray())); + this.restUtils.setGradeCodesMap(); + openMocks(this); } private School[] createSchoolArray() { School[] schools = new School[1]; - schools[0] = School.builder().mincode("10200001").schoolNumber("00001").build(); + schools[0] = School.builder().mincode("10200001").schoolNumber("00001").schoolId("22b358d728-259b-4d55-98ac-c41dafe66ded").build(); return schools; } @@ -95,6 +99,11 @@ private PenRequestBatchStudentValidationIssueTypeCode[] createValidationIssueTyp return codes; } + private GradeCode[] createGradeCodeArray() { + GradeCode[] codes = new GradeCode[1]; + codes[0] = GradeCode.builder().gradeCode("A").label("A").description("hello").build(); + return codes; + } @Test public void testGetStudentByStudentID_givenAPICallSuccess_shouldReturnData() { final String studentID = UUID.randomUUID().toString(); @@ -200,6 +209,20 @@ public void testGetSchoolByMincodeWhenEmpty_givenAPICallSuccess_shouldReturnData assertThat(result.get().getMincode()).isEqualTo("10200001"); } + @Test + public void testGetStudentRegistrationContactList_givenAPICallSuccess_shouldReturnEmptyList() { + val result = this.restUtils.getStudentRegistrationContactList("Invalid Mincode"); + assertThat(result).isEmpty(); + } + + @Test + public void testGetGradeCode_shouldReturnData() { + + val result = this.restUtils.getGradeCodes(); + assertThat(result).hasSize(1); + assertThat(result.get(0).getGradeCode()).isEqualTo("A"); + } + private WebClient.RequestBodySpec returnMockBodySpec() { return this.requestBodyMock; }