PAN-52 Fixed issue with the Theorems API
This commit is contained in:
@@ -38,6 +38,7 @@ CREATE TABLE proofs
|
|||||||
(
|
(
|
||||||
id INT NOT NULL AUTO_INCREMENT,
|
id INT NOT NULL AUTO_INCREMENT,
|
||||||
theorem_name VARCHAR(512) NOT NULL,
|
theorem_name VARCHAR(512) NOT NULL,
|
||||||
|
proof VARCHAR(4096) NOT NULL,
|
||||||
branch VARCHAR(512) NOT NULL,
|
branch VARCHAR(512) NOT NULL,
|
||||||
theorem INT NOT NULL,
|
theorem INT NOT NULL,
|
||||||
FOREIGN KEY fk_theorem (theorem) REFERENCES theorems (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
FOREIGN KEY fk_theorem (theorem) REFERENCES theorems (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
|||||||
+3
@@ -33,6 +33,7 @@ public class ProofsIntegrationTest {
|
|||||||
|
|
||||||
assertEquals("Test proof", savedProof.getTheoremName());
|
assertEquals("Test proof", savedProof.getTheoremName());
|
||||||
assertEquals("Test branch", savedProof.getBranch());
|
assertEquals("Test branch", savedProof.getBranch());
|
||||||
|
assertEquals("test", savedProof.getProof());
|
||||||
assertNotNull(savedProof.getDateCreated());
|
assertNotNull(savedProof.getDateCreated());
|
||||||
assertNotNull(savedProof.getLastUpdated());
|
assertNotNull(savedProof.getLastUpdated());
|
||||||
assertEquals(2, savedProof.getReferencedTheorems().size());
|
assertEquals(2, savedProof.getReferencedTheorems().size());
|
||||||
@@ -50,6 +51,7 @@ public class ProofsIntegrationTest {
|
|||||||
assertEquals(Integer.valueOf(0), updatedProof.getVersion());
|
assertEquals(Integer.valueOf(0), updatedProof.getVersion());
|
||||||
assertEquals("Test proof", updatedProof.getTheoremName());
|
assertEquals("Test proof", updatedProof.getTheoremName());
|
||||||
assertEquals("Test Update", updatedProof.getBranch());
|
assertEquals("Test Update", updatedProof.getBranch());
|
||||||
|
assertEquals("test", updatedProof.getProof());
|
||||||
assertNotNull(updatedProof.getLastUpdated());
|
assertNotNull(updatedProof.getLastUpdated());
|
||||||
assertNotNull(updatedProof.getDateCreated());
|
assertNotNull(updatedProof.getDateCreated());
|
||||||
assertNotEquals(updatedProof.getDateCreated().toInstant(), updatedProof.getLastUpdated().toInstant());
|
assertNotEquals(updatedProof.getDateCreated().toInstant(), updatedProof.getLastUpdated().toInstant());
|
||||||
@@ -77,6 +79,7 @@ public class ProofsIntegrationTest {
|
|||||||
|
|
||||||
final Proof proof = new Proof();
|
final Proof proof = new Proof();
|
||||||
proof.setTheoremName("Test proof");
|
proof.setTheoremName("Test proof");
|
||||||
|
proof.setProof("test");
|
||||||
proof.setBranch("Test branch");
|
proof.setBranch("Test branch");
|
||||||
proof.setDateCreated(new Date());
|
proof.setDateCreated(new Date());
|
||||||
proof.setReferencedTheorems(referencedTheoremsList);
|
proof.setReferencedTheorems(referencedTheoremsList);
|
||||||
|
|||||||
+3
@@ -32,6 +32,7 @@ public class TheoremsIntegrationTest {
|
|||||||
|
|
||||||
assertEquals("Test theorem", savedTheorem.getName());
|
assertEquals("Test theorem", savedTheorem.getName());
|
||||||
assertEquals("Test branch", savedTheorem.getBranch());
|
assertEquals("Test branch", savedTheorem.getBranch());
|
||||||
|
assertEquals("test", savedTheorem.getTheorem());
|
||||||
assertTrue(savedTheorem.getProvenStatus());
|
assertTrue(savedTheorem.getProvenStatus());
|
||||||
assertEquals(2, savedTheorem.getReferencedTheorems().size());
|
assertEquals(2, savedTheorem.getReferencedTheorems().size());
|
||||||
assertEquals(2, savedTheorem.getReferencedDefinitions().size());
|
assertEquals(2, savedTheorem.getReferencedDefinitions().size());
|
||||||
@@ -48,6 +49,7 @@ public class TheoremsIntegrationTest {
|
|||||||
assertEquals(Integer.valueOf(0), updatedTheorem.getVersion());
|
assertEquals(Integer.valueOf(0), updatedTheorem.getVersion());
|
||||||
assertEquals("Test theorem", updatedTheorem.getName());
|
assertEquals("Test theorem", updatedTheorem.getName());
|
||||||
assertEquals("Test Update", updatedTheorem.getBranch());
|
assertEquals("Test Update", updatedTheorem.getBranch());
|
||||||
|
assertEquals("test", updatedTheorem.getTheorem());
|
||||||
assertTrue(updatedTheorem.getProvenStatus());
|
assertTrue(updatedTheorem.getProvenStatus());
|
||||||
assertEquals(2, updatedTheorem.getReferencedTheorems().size());
|
assertEquals(2, updatedTheorem.getReferencedTheorems().size());
|
||||||
assertEquals(2, updatedTheorem.getReferencedDefinitions().size());
|
assertEquals(2, updatedTheorem.getReferencedDefinitions().size());
|
||||||
@@ -73,6 +75,7 @@ public class TheoremsIntegrationTest {
|
|||||||
|
|
||||||
final Theorem theorem = new Theorem();
|
final Theorem theorem = new Theorem();
|
||||||
theorem.setName("Test theorem");
|
theorem.setName("Test theorem");
|
||||||
|
theorem.setTheorem("test");
|
||||||
theorem.setBranch("Test branch");
|
theorem.setBranch("Test branch");
|
||||||
theorem.setProvenStatus(true);
|
theorem.setProvenStatus(true);
|
||||||
theorem.setTheoremType(TheoremType.THEOREM);
|
theorem.setTheoremType(TheoremType.THEOREM);
|
||||||
|
|||||||
+12
-2
@@ -75,13 +75,18 @@ public class ProofController {
|
|||||||
|
|
||||||
@GetMapping("/branch")
|
@GetMapping("/branch")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<List<Proof>> getAllProofsByBranch(@RequestParam("branch") final String branch) {
|
ResponseEntity<List<Proof>> getAllProofsByBranch(@RequestParam("branch") String branch) {
|
||||||
LOG.info("Received request to query for proofs related to the {} branch of mathematics", branch);
|
LOG.info("Received request to query for proofs related to the {} branch of mathematics", branch);
|
||||||
if (branch == null) {
|
if (branch == null) {
|
||||||
LOG.error("ERROR: branch was null");
|
LOG.error("ERROR: branch was null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (branch.contains("_") || branch.contains("-")) {
|
||||||
|
branch = branch.replace("_"," ");
|
||||||
|
branch = branch.replace("-", " ");
|
||||||
|
}
|
||||||
|
|
||||||
LOG.debug("Querying for proofs with branch {}", branch);
|
LOG.debug("Querying for proofs with branch {}", branch);
|
||||||
|
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
@@ -105,13 +110,18 @@ public class ProofController {
|
|||||||
|
|
||||||
@GetMapping("/theorem_name")
|
@GetMapping("/theorem_name")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<List<Proof>> getAllProofsByTheoremName(@RequestParam("theorem_name") final String theoremName) {
|
ResponseEntity<List<Proof>> getAllProofsByTheoremName(@RequestParam("theorem_name") String theoremName) {
|
||||||
LOG.info("Received request to query for proofs of the theorem {}", theoremName);
|
LOG.info("Received request to query for proofs of the theorem {}", theoremName);
|
||||||
if (theoremName == null) {
|
if (theoremName == null) {
|
||||||
LOG.error("ERROR: theorem name was null");
|
LOG.error("ERROR: theorem name was null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (theoremName.contains("_") || theoremName.contains("-")) {
|
||||||
|
theoremName = theoremName.replace("_"," ");
|
||||||
|
theoremName = theoremName.replace("-", " ");
|
||||||
|
}
|
||||||
|
|
||||||
LOG.debug("Querying for proofs of the theorem {}", theoremName);
|
LOG.debug("Querying for proofs of the theorem {}", theoremName);
|
||||||
|
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -22,6 +23,9 @@ public class Proof extends BaseDto implements Serializable {
|
|||||||
@Size(min = 1, max = 512, message = "The name must be at least 1 character and at most 512 characters")
|
@Size(min = 1, max = 512, message = "The name must be at least 1 character and at most 512 characters")
|
||||||
@Column(name = "theorem_name")
|
@Column(name = "theorem_name")
|
||||||
private String theoremName;
|
private String theoremName;
|
||||||
|
@NotNull(groups = Insert.class)
|
||||||
|
@Size(min = 1, max = 4096, message = "The proof must be at least 1 character and at most 4096 characters")
|
||||||
|
private String proof;
|
||||||
@NotBlank(groups = Insert.class)
|
@NotBlank(groups = Insert.class)
|
||||||
@Size(min = 1, max = 512, message = "The branch must be at least 1 character and at most 512 characters")
|
@Size(min = 1, max = 512, message = "The branch must be at least 1 character and at most 512 characters")
|
||||||
private String branch;
|
private String branch;
|
||||||
|
|||||||
+6
-5
@@ -53,7 +53,7 @@ public class ProofControllerTest {
|
|||||||
|
|
||||||
when(proofRepository.findByBranch(anyString())).thenReturn(listOfProofs);
|
when(proofRepository.findByBranch(anyString())).thenReturn(listOfProofs);
|
||||||
|
|
||||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByBranch("test");
|
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByBranch("Test_branch");
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
@@ -77,7 +77,7 @@ public class ProofControllerTest {
|
|||||||
public void testGetAllProofsByBranch_noProofsFound() {
|
public void testGetAllProofsByBranch_noProofsFound() {
|
||||||
when(proofRepository.findByBranch(anyString())).thenReturn(Collections.emptyList());
|
when(proofRepository.findByBranch(anyString())).thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByBranch("test nonexistent branch");
|
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByBranch("test-nonexistent-branch");
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
@@ -93,7 +93,7 @@ public class ProofControllerTest {
|
|||||||
|
|
||||||
when(proofRepository.findByTheoremName(anyString())).thenReturn(listOfProofs);
|
when(proofRepository.findByTheoremName(anyString())).thenReturn(listOfProofs);
|
||||||
|
|
||||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName("test");
|
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName("Test_proof");
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
@@ -104,7 +104,7 @@ public class ProofControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllProfsByTheoremName_nullTheoremName() {
|
public void testGetAllProofsByTheoremName_nullTheoremName() {
|
||||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName(null);
|
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName(null);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
@@ -117,7 +117,7 @@ public class ProofControllerTest {
|
|||||||
public void testGetAllProofsByTheoremName_noProofsFound() {
|
public void testGetAllProofsByTheoremName_noProofsFound() {
|
||||||
when(proofRepository.findByTheoremName(anyString())).thenReturn(Collections.emptyList());
|
when(proofRepository.findByTheoremName(anyString())).thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName("test nonexistent branch");
|
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName("test-nonexistent-proof");
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
@@ -299,6 +299,7 @@ public class ProofControllerTest {
|
|||||||
final Proof proof = new Proof();
|
final Proof proof = new Proof();
|
||||||
proof.setTheoremName("Test proof");
|
proof.setTheoremName("Test proof");
|
||||||
proof.setBranch("Test branch");
|
proof.setBranch("Test branch");
|
||||||
|
proof.setProof("test proof");
|
||||||
proof.setDateCreated(new Date());
|
proof.setDateCreated(new Date());
|
||||||
proof.setReferencedTheorems(referencedTheoremsList);
|
proof.setReferencedTheorems(referencedTheoremsList);
|
||||||
proof.setReferencedDefinitions(referencedDefinitionsList);
|
proof.setReferencedDefinitions(referencedDefinitionsList);
|
||||||
|
|||||||
Reference in New Issue
Block a user