-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from bcgov/feature/GRAD2-2973
GRAD2-2973 - District Cache on Trax API needs to also import District Details
- Loading branch information
Showing
12 changed files
with
270 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/CodeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package ca.bc.gov.educ.api.trax.controller.v2; | ||
|
||
import ca.bc.gov.educ.api.trax.service.institute.CodeService; | ||
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; | ||
import ca.bc.gov.educ.api.trax.util.GradValidation; | ||
import ca.bc.gov.educ.api.trax.util.PermissionsConstants; | ||
import ca.bc.gov.educ.api.trax.util.ResponseHelper; | ||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RestController("codeControllerV2") | ||
@CrossOrigin | ||
@OpenAPIDefinition(info = @Info(title = "API for TRAX Code Tables Data.", | ||
description = "This API is for Reading TRAX Code Tables data.", version = "1"), | ||
security = {@SecurityRequirement(name = "OAUTH2", | ||
scopes = {"READ_GRAD_COUNTRY_CODE_DATA", | ||
"READ_GRAD_PROVINCE_CODE_DATA", | ||
})}) | ||
public class CodeController { | ||
|
||
CodeService codeService; | ||
GradValidation validation; | ||
ResponseHelper response; | ||
|
||
@Autowired | ||
public CodeController(CodeService codeService, GradValidation validation, ResponseHelper response) { | ||
this.codeService = codeService; | ||
this.validation = validation; | ||
this.response = response; | ||
} | ||
|
||
@PutMapping(EducGradTraxApiConstants.GRAD_TRAX_CODE_URL_MAPPING_V2 + EducGradTraxApiConstants.PUT_SCHOOL_CATEGORY_CODES_MAPPING) | ||
@PreAuthorize(PermissionsConstants.UPDATE_GRAD_TRAX_CACHE) | ||
@Operation(summary = "Reload School Category Codes in the cache", description = "Reload School Category Codes in the cache", tags = {"Cache"}) | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), | ||
@ApiResponse(responseCode = "422", description = "UNPROCESSABLE CONTENT")}) | ||
public ResponseEntity<String> reloadSchoolCategoryCodesIntoCache() { | ||
log.debug("reloadSchoolCategoryCodesIntoCache : "); | ||
try { | ||
codeService.initializeSchoolCategoryCodeCache(true); | ||
} catch (Exception e) { | ||
return ResponseEntity.unprocessableEntity().body("Error loading School Category Codes into cache"); | ||
} | ||
return ResponseEntity.ok("School Category Codes loaded into cache!"); | ||
} | ||
|
||
@PutMapping(EducGradTraxApiConstants.GRAD_TRAX_CODE_URL_MAPPING_V2 + EducGradTraxApiConstants.PUT_SCHOOL_FUNDING_GROUP_CODES_MAPPING) | ||
@PreAuthorize(PermissionsConstants.UPDATE_GRAD_TRAX_CACHE) | ||
@Operation(summary = "Reload School Funding Group Codes in the cache", description = "Reload School Funding Group Codes in the cache", tags = {"Cache"}) | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), | ||
@ApiResponse(responseCode = "422", description = "UNPROCESSABLE CONTENT")}) | ||
public ResponseEntity<String> reloadSchoolFundingGroupCodesIntoCache() { | ||
log.debug("reloadSchoolFundingGroupCodesIntoCache : "); | ||
try { | ||
codeService.initializeSchoolFundingGroupCodeCache(true); | ||
} catch (Exception e) { | ||
return ResponseEntity.unprocessableEntity().body("Error loading School Funding Group Codes into cache"); | ||
} | ||
return ResponseEntity.ok("School Funding Group Codes loaded into cache!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
api/src/test/java/ca/bc/gov/educ/api/trax/controller/v2/CodeControllerV2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ca.bc.gov.educ.api.trax.controller.v2; | ||
|
||
import ca.bc.gov.educ.api.trax.service.institute.CodeService; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CodeControllerV2Test { | ||
|
||
@Mock | ||
private CodeService codeService; | ||
|
||
@InjectMocks | ||
private CodeController codeController; | ||
|
||
@Test | ||
void testReloadSchoolCategoryCodesIntoCache_shouldReturnOK() { | ||
doNothing().when(codeService).initializeSchoolCategoryCodeCache(true); | ||
codeController.reloadSchoolCategoryCodesIntoCache(); | ||
Mockito.verify(codeService).initializeSchoolCategoryCodeCache(true); | ||
} | ||
|
||
@Test | ||
void testReloadSchoolCategoryCodesIntoCache_shouldThrowException() { | ||
doThrow(new RuntimeException()).when(codeService).initializeSchoolCategoryCodeCache(true); | ||
codeController.reloadSchoolCategoryCodesIntoCache(); | ||
assertThrows(RuntimeException.class, () -> codeService.initializeSchoolCategoryCodeCache(true)); | ||
} | ||
|
||
@Test | ||
void testReloadSchoolFundingGroupCodesIntoCache_shouldReturnOK() { | ||
doNothing().when(codeService).initializeSchoolFundingGroupCodeCache(true); | ||
codeController.reloadSchoolFundingGroupCodesIntoCache(); | ||
Mockito.verify(codeService).initializeSchoolFundingGroupCodeCache(true); | ||
} | ||
|
||
@Test | ||
void testReloadSchoolFundingGroupCodesIntoCache_shouldThrowException() { | ||
doThrow(new RuntimeException()).when(codeService).initializeSchoolFundingGroupCodeCache(true); | ||
codeController.reloadSchoolFundingGroupCodesIntoCache(); | ||
assertThrows(RuntimeException.class, () -> codeService.initializeSchoolFundingGroupCodeCache(true)); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
api/src/test/java/ca/bc/gov/educ/api/trax/controller/v2/DistrictControllerV2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ca.bc.gov.educ.api.trax.controller.v2; | ||
|
||
import ca.bc.gov.educ.api.trax.service.institute.DistrictService; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DistrictControllerV2Test { | ||
|
||
@Mock | ||
private DistrictService districtService; | ||
|
||
@InjectMocks | ||
private DistrictController districtController; | ||
|
||
@Test | ||
void testReloadSchoolCategoryCodesIntoCache_shouldReturnOK() { | ||
doNothing().when(districtService).initializeDistrictCache(true); | ||
districtController.reloadDistrictsIntoCache(); | ||
Mockito.verify(districtService).initializeDistrictCache(true); | ||
} | ||
|
||
@Test | ||
void testReloadSchoolCategoryCodesIntoCache_shouldThrowException() { | ||
doThrow(new RuntimeException()).when(districtService).initializeDistrictCache(true); | ||
districtController.reloadDistrictsIntoCache(); | ||
assertThrows(RuntimeException.class, () -> districtService.initializeDistrictCache(true)); | ||
} | ||
|
||
} |
Oops, something went wrong.