Skip to content

Commit

Permalink
adding additional testing for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
soletsdev committed Feb 8, 2024
1 parent a6573a5 commit ffd7a91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void setGradeCodesMap() {
try {
writeLock.lock();
this.gradeCodesMap.clear();
final List<GradeCode> 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<GradeCode> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

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

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

0 comments on commit ffd7a91

Please sign in to comment.