Skip to content

Commit

Permalink
GRAD2-2929: task is complete.
Browse files Browse the repository at this point in the history
GRAD2-2929: task is complete.
  • Loading branch information
infstar committed Sep 12, 2024
1 parent f1fd12a commit f9a688a
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 325 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Objects;

@Component
public class RESTGenerics {
public class RESTService {

public static final String ERROR_MESSAGE1 = "Service failed to process after max retries.";
public static final String ERROR_MESSAGE2 = "5xx error.";
Expand All @@ -32,7 +32,7 @@ public class RESTGenerics {
private final WebClient batchWebClient;

@Autowired
public RESTGenerics(@Qualifier("batchClient") WebClient batchWebClient, WebClient webClient, final EducGradBatchGraduationApiConstants constants) {
public RESTService(@Qualifier("batchClient") WebClient batchWebClient, WebClient webClient, final EducGradBatchGraduationApiConstants constants) {
this.constants = constants;
this.webClient = webClient;
this.batchWebClient = batchWebClient;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ca.bc.gov.educ.api.batchgraduation.model.PsiCredentialDistribution;
import ca.bc.gov.educ.api.batchgraduation.model.ReportGradStudentData;
import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTGenerics;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTService;
import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants;
import ca.bc.gov.educ.api.batchgraduation.util.JsonTransformer;
import ca.bc.gov.educ.api.batchgraduation.util.ThreadLocalStateUtil;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class GraduationReportService {
WebClient batchWebClient;

@Autowired
RESTGenerics restGenerics;
RESTService restService;

@Autowired
EducGradBatchGraduationApiConstants constants;
Expand Down Expand Up @@ -74,37 +74,37 @@ public List<PsiCredentialDistribution> getPsiStudentsForRun(String transmissionT
}

public List<StudentCredentialDistribution> getStudentsNonGradForYearlyDistribution(String accessToken) {
var response = restGenerics.get(String.format(constants.getStudentDataNonGradEarly()), List.class, accessToken);
var response = restService.get(String.format(constants.getStudentDataNonGradEarly()), List.class, accessToken);
List<ReportGradStudentData> reportGradStudentDataList = jsonTransformer.convertValue(response, new TypeReference<>(){});
return populateStudentCredentialDistributions(reportGradStudentDataList);
}

// Year-end NonGrad distribution
public List<StudentCredentialDistribution> getStudentsNonGradForYearlyDistribution(String mincode, String accessToken) {
var response = restGenerics.get(String.format(constants.getStudentDataNonGradEarlyByMincode(), mincode), List.class, accessToken);
var response = restService.get(String.format(constants.getStudentDataNonGradEarlyByMincode(), mincode), List.class, accessToken);
List<ReportGradStudentData> reportGradStudentDataList = jsonTransformer.convertValue(response, new TypeReference<>(){});
return populateStudentCredentialDistributions(reportGradStudentDataList);
}

// Year-end distribution
public List<StudentCredentialDistribution> getStudentsForYearlyDistribution(String accessToken) {
var response = restGenerics.get(String.format(constants.getStudentReportDataYearly()), List.class, accessToken);
var response = restService.get(String.format(constants.getStudentReportDataYearly()), List.class, accessToken);
List<ReportGradStudentData> reportGradStudentDataList = jsonTransformer.convertValue(response, new TypeReference<>(){});
return populateStudentCredentialDistributions(reportGradStudentDataList);
}

public List<String> getSchoolsNonGradYearly(String accessToken) {
var response = restGenerics.get(constants.getSchoolDataNonGradEarly(), List.class, accessToken);
var response = restService.get(constants.getSchoolDataNonGradEarly(), List.class, accessToken);
return jsonTransformer.convertValue(response, new TypeReference<List<String>>(){});
}

public List<String> getDistrictsNonGradYearly(String accessToken) {
var response = restGenerics.get(constants.getDistrictDataNonGradEarly(), List.class, accessToken);
var response = restService.get(constants.getDistrictDataNonGradEarly(), List.class, accessToken);
return jsonTransformer.convertValue(response, new TypeReference<List<String>>(){});
}

public List<String> getDistrictsYearly(String accessToken) {
var response = restGenerics.get(constants.getDistrictDataYearly(), List.class, accessToken);
var response = restService.get(constants.getDistrictDataYearly(), List.class, accessToken);
return jsonTransformer.convertValue(response, new TypeReference<List<String>>(){});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.time.Duration;

import static ca.bc.gov.educ.api.batchgraduation.rest.RESTGenerics.ERROR_MESSAGE1;
import static ca.bc.gov.educ.api.batchgraduation.rest.RESTGenerics.ERROR_MESSAGE2;
import static ca.bc.gov.educ.api.batchgraduation.rest.RESTService.ERROR_MESSAGE1;
import static ca.bc.gov.educ.api.batchgraduation.rest.RESTService.ERROR_MESSAGE2;

@Component
public class TokenUtils {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ca.bc.gov.educ.api.batchgraduation.entity.BatchGradAlgorithmJobHistoryEntity;
import ca.bc.gov.educ.api.batchgraduation.model.*;
import ca.bc.gov.educ.api.batchgraduation.repository.BatchGradAlgorithmJobHistoryRepository;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTGenerics;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTService;
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils;
import ca.bc.gov.educ.api.batchgraduation.service.GraduationReportService;
import ca.bc.gov.educ.api.batchgraduation.service.ParallelDataFetch;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class DistributionRunCompletionNotificationListenerTest {
RestUtils restUtils;

@MockBean
RESTGenerics restGenerics;
RESTService restService;

@Autowired
EducGradBatchGraduationApiConstants constants;
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut
// when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
// when(this.responseMock.bodyToMono(tListRes)).thenReturn(Mono.just(tList));

when(this.restGenerics.get(constants.getTranscriptDistributionList(), List.class, "accessToken")).thenReturn(tList);
when(this.restService.get(constants.getTranscriptDistributionList(), List.class, "accessToken")).thenReturn(tList);


// when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
Expand All @@ -172,7 +172,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut
// when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
// when(this.responseMock.bodyToMono(tListRes)).thenReturn(Mono.just(tList));

when(this.restGenerics.get(constants.getTranscriptYearlyDistributionList(), List.class, "accessToken")).thenReturn(tList);
when(this.restService.get(constants.getTranscriptYearlyDistributionList(), List.class, "accessToken")).thenReturn(tList);

ReportGradStudentData reportGradStudentData = new ReportGradStudentData();
reportGradStudentData.setGraduationStudentRecordId(scd.getStudentID());
Expand All @@ -187,7 +187,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut
// when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
// when(this.responseMock.bodyToMono(repListRes)).thenReturn(Mono.just(List.of(reportGradStudentData)));

when(this.restGenerics.get(constants.getStudentDataNonGradEarlyByMincode(), List.class, "accessToken")).thenReturn(List.of(reportGradStudentData));
when(this.restService.get(constants.getStudentDataNonGradEarlyByMincode(), List.class, "accessToken")).thenReturn(List.of(reportGradStudentData));

ParameterizedTypeReference<List<StudentCredentialDistribution>> cListRes = new ParameterizedTypeReference<>() {
};
Expand All @@ -198,7 +198,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut
// when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
// when(this.responseMock.bodyToMono(cListRes)).thenReturn(Mono.just(cList));

when(this.restGenerics.get(constants.getCertificateDistributionList(), List.class, "accessToken")).thenReturn(cList);
when(this.restService.get(constants.getCertificateDistributionList(), List.class, "accessToken")).thenReturn(cList);

ResponseObj obj = new ResponseObj();
obj.setAccess_token("asdasd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ca.bc.gov.educ.api.batchgraduation.model.PsiCredentialDistribution;
import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTGenerics;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTService;
import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -34,7 +34,7 @@ public class GraduationReportServiceTest {
GraduationReportService graduationReportService;

@MockBean
RESTGenerics restGenerics;
RESTService restService;

@MockBean
@Qualifier("batchClient")
Expand Down Expand Up @@ -77,7 +77,7 @@ public void testGetTranscriptYearly() {
@Test
public void testGetSchoolsNonGradYearly() {

when(this.restGenerics.get(constants.getSchoolDataNonGradEarly(), List.class, "accessToken")).thenReturn(List.of("1234567"));
when(this.restService.get(constants.getSchoolDataNonGradEarly(), List.class, "accessToken")).thenReturn(List.of("1234567"));

List<String> res = graduationReportService.getSchoolsNonGradYearly("accessToken");
assertThat(res).isNotEmpty();
Expand All @@ -87,7 +87,7 @@ public void testGetSchoolsNonGradYearly() {
@Test
public void testGetDistrictsNonGradYearly() {

when(this.restGenerics.get(constants.getDistrictDataNonGradEarly(), List.class, "accessToken")).thenReturn(List.of("123"));
when(this.restService.get(constants.getDistrictDataNonGradEarly(), List.class, "accessToken")).thenReturn(List.of("123"));

List<String> res = graduationReportService.getDistrictsNonGradYearly("accessToken");
assertThat(res).isNotEmpty();
Expand All @@ -97,7 +97,7 @@ public void testGetDistrictsNonGradYearly() {
@Test
public void testGetDistrictsYearly() {

when(this.restGenerics.get(constants.getDistrictDataYearly(), List.class, "accessToken")).thenReturn(List.of("1234567"));
when(this.restService.get(constants.getDistrictDataYearly(), List.class, "accessToken")).thenReturn(List.of("1234567"));

List<String> res = graduationReportService.getDistrictsYearly("accessToken");
assertThat(res).isNotEmpty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ca.bc.gov.educ.api.batchgraduation.util;

import ca.bc.gov.educ.api.batchgraduation.rest.RESTGenerics;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -12,26 +12,26 @@
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
public class RestGenericsGetTest {
public class RESTServiceGetTest {

@Autowired
private RESTGenerics restGenerics;
private RESTService restService;

//@Test
public void testGet_GivenProperData_Expect200Response(){
String response;
response = this.restGenerics.get("https://httpstat.us/200", String.class, "1234");
response = this.restService.get("https://httpstat.us/200", String.class, "1234");
Assert.assertEquals("200 OK", response);
}

//@Test(expected = ServiceException.class)
public void testGet_Given5xxErrorFromService_ExpectServiceError(){
this.restGenerics.get("https://httpstat.us/503", String.class, "1234");
this.restService.get("https://httpstat.us/503", String.class, "1234");
}

//@Test(expected = ServiceException.class)
public void testGet_Given4xxErrorFromService_ExpectServiceError(){
this.restGenerics.get("https://httpstat.us/403", String.class, "1234");
this.restService.get("https://httpstat.us/403", String.class, "1234");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ca.bc.gov.educ.api.batchgraduation.util;

import ca.bc.gov.educ.api.batchgraduation.exception.ServiceException;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTGenerics;
import ca.bc.gov.educ.api.batchgraduation.rest.RESTService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -28,11 +28,11 @@
@RunWith(SpringRunner.class)
@ExtendWith(MockitoExtension.class)
@ActiveProfiles("test")
public class RestGenericsPostTest {
public class RESTServicePostTest {

@Autowired
@InjectMocks
private RESTGenerics restGenerics;
private RESTService restService;
@Mock
private WebClient.RequestHeadersSpec requestHeadersMock;
@Mock
Expand Down Expand Up @@ -63,7 +63,7 @@ public void testPost_GivenProperData_Expect200Response(){
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.onStatus(any(), any())).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(byte[].class)).thenReturn(Mono.just(TEST_BYTES));
byte[] response = this.restGenerics.post("https://fake.url.com", testBody, byte[].class, "1234");
byte[] response = this.restService.post("https://fake.url.com", testBody, byte[].class, "1234");
Assert.assertArrayEquals(TEST_BYTES, response);
}

Expand All @@ -78,7 +78,7 @@ public void testPost_Given4xxErrorFromService_ExpectServiceError() {
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.onStatus(any(), any())).thenThrow(new ServiceException(getErrorMessage(any(String.class), "5xx error.")));
when(this.responseMock.bodyToMono(byte[].class)).thenReturn(Mono.just(TEST_BYTES));
this.restGenerics.post("https://fake.url.com", testBody, byte[].class, "1234");
this.restService.post("https://fake.url.com", testBody, byte[].class, "1234");
}

private String getErrorMessage(String url, String errorMessage) {
Expand Down
Loading

0 comments on commit f9a688a

Please sign in to comment.