PAN-52 Fixed issue with the Theorems API
This commit is contained in:
+7
-5
@@ -75,19 +75,21 @@ public class TheoremController {
|
||||
|
||||
@GetMapping("/proven_status")
|
||||
public @ResponseBody
|
||||
ResponseEntity<List<Theorem>> getAllTheoremsByProvenStatus(@PathVariable("proven_status") final Boolean provenStatus) {
|
||||
ResponseEntity<List<Theorem>> getAllTheoremsByProvenStatus(@RequestParam("proven_status") final String provenStatus) {
|
||||
LOG.info("Received request to query for theorems whose proven status is {}", provenStatus);
|
||||
if (provenStatus == null) {
|
||||
LOG.error("ERROR: status was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for theorems with proven status {}", provenStatus);
|
||||
final Boolean isProven = Boolean.parseBoolean(provenStatus);
|
||||
|
||||
LOG.debug("Querying for theorems with proven status {}", isProven);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<Theorem> listOfTheorems = theoremRepository.findByProvenStatus(provenStatus);
|
||||
final List<Theorem> listOfTheorems = theoremRepository.findByProvenStatus(isProven);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
@@ -95,11 +97,11 @@ public class TheoremController {
|
||||
LOG.info("Returning list of all theorems with size {}", listOfTheorems.size());
|
||||
|
||||
if (listOfTheorems.isEmpty()) {
|
||||
LOG.warn("No theorems were found for proven status {}", provenStatus);
|
||||
LOG.warn("No theorems were found for proven status {}", isProven);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
LOG.info("Returning list of theorems with proven status {}", provenStatus);
|
||||
LOG.info("Returning list of theorems with proven status {}", isProven);
|
||||
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
+11
-2
@@ -135,7 +135,7 @@ public class TheoremControllerTest {
|
||||
|
||||
when(theoremRepository.findByProvenStatus(anyBoolean())).thenReturn(listOfTheorems);
|
||||
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus(true);
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("true");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
@@ -155,11 +155,20 @@ public class TheoremControllerTest {
|
||||
verifyZeroInteractions(theoremRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByProvenStatus_invalidProvenStatus() {
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("test");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByProvenStatus_noTheoremsFound() {
|
||||
when(theoremRepository.findByProvenStatus(anyBoolean())).thenReturn(Collections.emptyList());
|
||||
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus(false);
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("false");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
|
||||
Reference in New Issue
Block a user