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")
|
@GetMapping("/proven_status")
|
||||||
public @ResponseBody
|
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);
|
LOG.info("Received request to query for theorems whose proven status is {}", provenStatus);
|
||||||
if (provenStatus == null) {
|
if (provenStatus == null) {
|
||||||
LOG.error("ERROR: status was null");
|
LOG.error("ERROR: status was null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
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();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final List<Theorem> listOfTheorems = theoremRepository.findByProvenStatus(provenStatus);
|
final List<Theorem> listOfTheorems = theoremRepository.findByProvenStatus(isProven);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
@@ -95,11 +97,11 @@ public class TheoremController {
|
|||||||
LOG.info("Returning list of all theorems with size {}", listOfTheorems.size());
|
LOG.info("Returning list of all theorems with size {}", listOfTheorems.size());
|
||||||
|
|
||||||
if (listOfTheorems.isEmpty()) {
|
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);
|
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);
|
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-2
@@ -135,7 +135,7 @@ public class TheoremControllerTest {
|
|||||||
|
|
||||||
when(theoremRepository.findByProvenStatus(anyBoolean())).thenReturn(listOfTheorems);
|
when(theoremRepository.findByProvenStatus(anyBoolean())).thenReturn(listOfTheorems);
|
||||||
|
|
||||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus(true);
|
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("true");
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
@@ -155,11 +155,20 @@ public class TheoremControllerTest {
|
|||||||
verifyZeroInteractions(theoremRepository);
|
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
|
@Test
|
||||||
public void testGetAllTheoremsByProvenStatus_noTheoremsFound() {
|
public void testGetAllTheoremsByProvenStatus_noTheoremsFound() {
|
||||||
when(theoremRepository.findByProvenStatus(anyBoolean())).thenReturn(Collections.emptyList());
|
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);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
|
|||||||
Reference in New Issue
Block a user