fix conflict
This commit is contained in:
+13
-5
@@ -30,11 +30,19 @@ stages:
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: Load Database
|
||||
- stage: "Load Database"
|
||||
script: ./gradlew loaddb
|
||||
- stage: Build
|
||||
- stage: "Build"
|
||||
script: ./gradlew build
|
||||
- stage: Unit Tests
|
||||
- stage: "Unit Tests"
|
||||
script: ./gradlew test
|
||||
- stage: Integration Tests
|
||||
script: ./gradlew integrationTest
|
||||
- stage: "Integration Tests"
|
||||
script:
|
||||
- |
|
||||
./gradlew :persistence:startPersistenceApi &
|
||||
APP_PID=$!
|
||||
- |
|
||||
./gradlew integrationTest
|
||||
- kill $APP_PID
|
||||
- stage: "Sonar Analysis"
|
||||
script: ./gradlew sonar
|
||||
|
||||
+3
-11
@@ -70,9 +70,6 @@ subprojects {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.2.RELEASE'
|
||||
testCompile 'javax.el:javax.el-api:3.0.0'
|
||||
|
||||
}
|
||||
|
||||
test {
|
||||
@@ -102,7 +99,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||
compile group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.3'
|
||||
compile 'org.codehaus.groovy:groovy-all:2.3.11'
|
||||
compile 'org.apache.commons:commons-lang3:3.5'
|
||||
// The production code uses the SLF4J logging API at compile time
|
||||
@@ -112,6 +109,8 @@ dependencies {
|
||||
compile('org.springframework.boot:spring-boot-starter-web','org.apache.tomcat.embed:tomcat-embed-jasper'
|
||||
,'javax.servlet:jstl')
|
||||
|
||||
testCompile 'javax.el:javax.el-api:3.0.0'
|
||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.3.RELEASE'
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||
@@ -140,13 +139,6 @@ testSets {
|
||||
integrationTest
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
wrapper {
|
||||
gradleVersion = '5.2.1'
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
spring.mvc.view.prefix:/WEB-INF/jsp/
|
||||
spring.mvc.view.suffix:.jsp
|
||||
@@ -50,3 +50,11 @@ task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local d
|
||||
commandLine=['cmd','/c','loaddb.bat']
|
||||
}
|
||||
}
|
||||
|
||||
task startPersistenceApi(type: JavaExec, description: 'Starts the Persistence API') {
|
||||
dependsOn 'loadDb'
|
||||
dependsOn 'build'
|
||||
classpath = files('build/libs/persistence-1.0.jar')
|
||||
classpath += sourceSets.main.runtimeClasspath
|
||||
main = 'edu.msudenver.tsp.persistence.PersistenceApi'
|
||||
}
|
||||
|
||||
@@ -26,10 +26,25 @@ version int default 1
|
||||
create table theorems (
|
||||
id int not null auto_increment primary key unique,
|
||||
name varchar(512) not null,
|
||||
theorem_type enum ('THEOREM', 'PROPOSITION', 'LEMMA', 'COROLLARY') not null,
|
||||
theorem varchar(1024) not null,
|
||||
theorem_type varchar(20) not null,
|
||||
branch varchar(512) not null,
|
||||
referenced_definitions json,
|
||||
referenced_theorems json,
|
||||
proven_status boolean default false,
|
||||
version int default 1
|
||||
)
|
||||
);
|
||||
CREATE TABLE proofs
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
theorem_name VARCHAR(512) NOT NULL,
|
||||
proof VARCHAR(4096) NOT NULL,
|
||||
branch VARCHAR(512) NOT NULL,
|
||||
theorem INT NOT NULL,
|
||||
referenced_definitions JSON,
|
||||
referenced_theorems JSON,
|
||||
date_added DATE,
|
||||
last_updated DATE,
|
||||
version INT DEFAULT 1,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
+12
-12
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Account;
|
||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -19,8 +19,8 @@ public class AccountsIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testCRUDFunctionality() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
final AccountDto savedAccount = accountsRepository.save(accountDto);
|
||||
final Account account = createAccount();
|
||||
final Account savedAccount = accountsRepository.save(account);
|
||||
|
||||
assertNotNull(savedAccount);
|
||||
assertEquals(Integer.valueOf(0), savedAccount.getVersion());
|
||||
@@ -33,25 +33,25 @@ public class AccountsIntegrationTest {
|
||||
|
||||
savedAccount.setPassword("Test Update");
|
||||
|
||||
final AccountDto updatedAccount = accountsRepository.save(savedAccount);
|
||||
final Account updatedAccount = accountsRepository.save(savedAccount);
|
||||
|
||||
assertEquals("Test username", savedAccount.getUsername());
|
||||
assertEquals("Test Update", savedAccount.getPassword());
|
||||
assertTrue(savedAccount.getAdministratorStatus());
|
||||
assertEquals(updatedAccount.getId(), id);
|
||||
|
||||
accountsRepository.delete(accountDto);
|
||||
final Optional<AccountDto> deletedAccount = accountsRepository.findById(id);
|
||||
accountsRepository.delete(account);
|
||||
final Optional<Account> deletedAccount = accountsRepository.findById(id);
|
||||
assertFalse(deletedAccount.isPresent());
|
||||
}
|
||||
|
||||
private AccountDto createAccount() {
|
||||
final AccountDto accountDto = new AccountDto();
|
||||
accountDto.setUsername("Test username");
|
||||
accountDto.setPassword("test password");
|
||||
accountDto.setAdministratorStatus(true);
|
||||
private Account createAccount() {
|
||||
final Account account = new Account();
|
||||
account.setUsername("Test username");
|
||||
account.setPassword("test password");
|
||||
account.setAdministratorStatus(true);
|
||||
|
||||
return accountDto;
|
||||
return account;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-22
@@ -1,8 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Notation;
|
||||
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -23,8 +21,8 @@ public class DefinitionsIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testCRUDFunctionality() {
|
||||
final DefinitionDto definitionDto = createDefinition();
|
||||
final DefinitionDto savedDefinition = definitionRepository.save(definitionDto);
|
||||
final Definition definition = createDefinition();
|
||||
final Definition savedDefinition = definitionRepository.save(definition);
|
||||
|
||||
assertNotNull(savedDefinition);
|
||||
assertEquals(Integer.valueOf(0), savedDefinition.getVersion());
|
||||
@@ -35,8 +33,8 @@ public class DefinitionsIntegrationTest {
|
||||
assertNotNull(savedDefinition.getDefinition());
|
||||
assertNotNull(savedDefinition.getNotation());
|
||||
|
||||
final List<String> definitionsList = savedDefinition.getDefinition().getDefinitions();
|
||||
final List<String> notationList = savedDefinition.getNotation().getNotations();
|
||||
final List<String> definitionsList = savedDefinition.getDefinition();
|
||||
final List<String> notationList = savedDefinition.getNotation();
|
||||
|
||||
assertEquals(2, definitionsList.size());
|
||||
assertEquals(1, notationList.size());
|
||||
@@ -46,14 +44,14 @@ public class DefinitionsIntegrationTest {
|
||||
|
||||
savedDefinition.setName("Test Update");
|
||||
|
||||
final DefinitionDto updatedDefinition = definitionRepository.save(savedDefinition);
|
||||
final Definition updatedDefinition = definitionRepository.save(savedDefinition);
|
||||
|
||||
assertEquals("Test Update", updatedDefinition.getName());
|
||||
assertNotNull(updatedDefinition.getDefinition());
|
||||
assertNotNull(updatedDefinition.getNotation());
|
||||
|
||||
final List<String> updatedDefinitionsList = updatedDefinition.getDefinition().getDefinitions();
|
||||
final List<String> updatedNotationsList = updatedDefinition.getNotation().getNotations();
|
||||
final List<String> updatedDefinitionsList = updatedDefinition.getDefinition();
|
||||
final List<String> updatedNotationsList = updatedDefinition.getNotation();
|
||||
|
||||
assertEquals(2, updatedDefinitionsList.size());
|
||||
assertEquals(1, updatedNotationsList.size());
|
||||
@@ -63,29 +61,23 @@ public class DefinitionsIntegrationTest {
|
||||
assertEquals(id, updatedDefinition.getId());
|
||||
|
||||
definitionRepository.delete(updatedDefinition);
|
||||
final Optional<DefinitionDto> deletedDefinition = definitionRepository.findById(id);
|
||||
final Optional<Definition> deletedDefinition = definitionRepository.findById(id);
|
||||
assertFalse(deletedDefinition.isPresent());
|
||||
}
|
||||
|
||||
private DefinitionDto createDefinition() {
|
||||
private Definition createDefinition() {
|
||||
final List<String> definitionList = new ArrayList<>();
|
||||
definitionList.add("Test definition 1");
|
||||
definitionList.add("Test definition 2");
|
||||
|
||||
final Definition definition = new Definition();
|
||||
definition.setDefinitions(definitionList);
|
||||
|
||||
final List<String> notationList = new ArrayList<>();
|
||||
notationList.add("\\testLaTeX");
|
||||
|
||||
final Notation notation = new Notation();
|
||||
notation.setNotations(notationList);
|
||||
final Definition definition = new Definition();
|
||||
definition.setName("Test Name");
|
||||
definition.setDefinition(definitionList);
|
||||
definition.setNotation(notationList);
|
||||
|
||||
final DefinitionDto definitionDto = new DefinitionDto();
|
||||
definitionDto.setName("Test Name");
|
||||
definitionDto.setDefinition(definition);
|
||||
definitionDto.setNotation(notation);
|
||||
|
||||
return definitionDto;
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package edu.msudenver.tsp.persistence;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||
import edu.msudenver.tsp.persistence.repository.ProofRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = PersistenceTestConfig.class)
|
||||
public class ProofsIntegrationTest {
|
||||
@Autowired
|
||||
private ProofRepository proofRepository;
|
||||
|
||||
@Test
|
||||
public void testCRUDFunctionality() {
|
||||
final Proof proof = createProof();
|
||||
final Proof savedProof = proofRepository.save(proof);
|
||||
|
||||
assertNotNull(savedProof);
|
||||
assertEquals(Integer.valueOf(0), savedProof.getVersion());
|
||||
|
||||
final int id = savedProof.getId();
|
||||
|
||||
assertEquals("Test proof", savedProof.getTheoremName());
|
||||
assertEquals("Test branch", savedProof.getBranch());
|
||||
assertEquals("test", savedProof.getProof());
|
||||
assertEquals(Integer.valueOf(1), savedProof.getTheorem());
|
||||
assertNotNull(savedProof.getDateCreated());
|
||||
assertNotNull(savedProof.getLastUpdated());
|
||||
assertEquals(2, savedProof.getReferencedTheorems().size());
|
||||
assertEquals(2, savedProof.getReferencedDefinitions().size());
|
||||
assertEquals("test theorem 1", savedProof.getReferencedTheorems().get(0));
|
||||
assertEquals("test theorem 2", savedProof.getReferencedTheorems().get(1));
|
||||
assertEquals("test definition 1", savedProof.getReferencedDefinitions().get(0));
|
||||
assertEquals("test definition 2", savedProof.getReferencedDefinitions().get(1));
|
||||
|
||||
savedProof.setBranch("Test Update");
|
||||
|
||||
final Proof updatedProof = proofRepository.save(savedProof);
|
||||
|
||||
assertNotNull(updatedProof);
|
||||
assertEquals(Integer.valueOf(0), updatedProof.getVersion());
|
||||
assertEquals("Test proof", updatedProof.getTheoremName());
|
||||
assertEquals("Test Update", updatedProof.getBranch());
|
||||
assertEquals("test", updatedProof.getProof());
|
||||
assertEquals(Integer.valueOf(1), savedProof.getTheorem());
|
||||
assertNotNull(updatedProof.getLastUpdated());
|
||||
assertNotNull(updatedProof.getDateCreated());
|
||||
assertNotEquals(updatedProof.getDateCreated().toInstant(), updatedProof.getLastUpdated().toInstant());
|
||||
assertEquals(2, updatedProof.getReferencedTheorems().size());
|
||||
assertEquals(2, updatedProof.getReferencedDefinitions().size());
|
||||
assertEquals("test theorem 1", updatedProof.getReferencedTheorems().get(0));
|
||||
assertEquals("test theorem 2", updatedProof.getReferencedTheorems().get(1));
|
||||
assertEquals("test definition 1", updatedProof.getReferencedDefinitions().get(0));
|
||||
assertEquals("test definition 2", updatedProof.getReferencedDefinitions().get(1));
|
||||
assertEquals(updatedProof.getId(), id);
|
||||
|
||||
proofRepository.delete(proof);
|
||||
final Optional<Proof> deletedProof = proofRepository.findById(id);
|
||||
assertFalse(deletedProof.isPresent());
|
||||
}
|
||||
|
||||
private Proof createProof() {
|
||||
final List<String> referencedTheoremsList = new ArrayList<>();
|
||||
referencedTheoremsList.add("test theorem 1");
|
||||
referencedTheoremsList.add("test theorem 2");
|
||||
|
||||
final List<String> referencedDefinitionsList = new ArrayList<>();
|
||||
referencedDefinitionsList.add("test definition 1");
|
||||
referencedDefinitionsList.add("test definition 2");
|
||||
|
||||
final Proof proof = new Proof();
|
||||
proof.setTheoremName("Test proof");
|
||||
proof.setProof("test");
|
||||
proof.setTheorem(1);
|
||||
proof.setBranch("Test branch");
|
||||
proof.setDateCreated(new Date());
|
||||
proof.setReferencedTheorems(referencedTheoremsList);
|
||||
proof.setReferencedDefinitions(referencedDefinitionsList);
|
||||
|
||||
return proof;
|
||||
}
|
||||
}
|
||||
+18
-15
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.TheoremDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Theorem;
|
||||
import edu.msudenver.tsp.persistence.dto.TheoremType;
|
||||
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
||||
import org.junit.Test;
|
||||
@@ -22,8 +22,8 @@ public class TheoremsIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testCRUDFunctionality() {
|
||||
final TheoremDto theoremDto = createTheorem();
|
||||
final TheoremDto savedTheorem = theoremRepository.save(theoremDto);
|
||||
final Theorem theorem = createTheorem();
|
||||
final Theorem savedTheorem = theoremRepository.save(theorem);
|
||||
|
||||
assertNotNull(savedTheorem);
|
||||
assertEquals(Integer.valueOf(0), savedTheorem.getVersion());
|
||||
@@ -32,6 +32,7 @@ public class TheoremsIntegrationTest {
|
||||
|
||||
assertEquals("Test theorem", savedTheorem.getName());
|
||||
assertEquals("Test branch", savedTheorem.getBranch());
|
||||
assertEquals("test", savedTheorem.getTheorem());
|
||||
assertTrue(savedTheorem.getProvenStatus());
|
||||
assertEquals(2, savedTheorem.getReferencedTheorems().size());
|
||||
assertEquals(2, savedTheorem.getReferencedDefinitions().size());
|
||||
@@ -42,12 +43,13 @@ public class TheoremsIntegrationTest {
|
||||
|
||||
savedTheorem.setBranch("Test Update");
|
||||
|
||||
final TheoremDto updatedTheorem = theoremRepository.save(savedTheorem);
|
||||
final Theorem updatedTheorem = theoremRepository.save(savedTheorem);
|
||||
|
||||
assertNotNull(updatedTheorem);
|
||||
assertEquals(Integer.valueOf(0), updatedTheorem.getVersion());
|
||||
assertEquals("Test theorem", updatedTheorem.getName());
|
||||
assertEquals("Test Update", updatedTheorem.getBranch());
|
||||
assertEquals("test", updatedTheorem.getTheorem());
|
||||
assertTrue(updatedTheorem.getProvenStatus());
|
||||
assertEquals(2, updatedTheorem.getReferencedTheorems().size());
|
||||
assertEquals(2, updatedTheorem.getReferencedDefinitions().size());
|
||||
@@ -57,12 +59,12 @@ public class TheoremsIntegrationTest {
|
||||
assertEquals("test definition 2", updatedTheorem.getReferencedDefinitions().get(1));
|
||||
assertEquals(updatedTheorem.getId(), id);
|
||||
|
||||
theoremRepository.delete(theoremDto);
|
||||
final Optional<TheoremDto> deletedTheorem = theoremRepository.findById(id);
|
||||
theoremRepository.delete(theorem);
|
||||
final Optional<Theorem> deletedTheorem = theoremRepository.findById(id);
|
||||
assertFalse(deletedTheorem.isPresent());
|
||||
}
|
||||
|
||||
private TheoremDto createTheorem() {
|
||||
private Theorem createTheorem() {
|
||||
final List<String> referencedTheoremsList = new ArrayList<>();
|
||||
referencedTheoremsList.add("test theorem 1");
|
||||
referencedTheoremsList.add("test theorem 2");
|
||||
@@ -71,14 +73,15 @@ public class TheoremsIntegrationTest {
|
||||
referencedDefinitionsList.add("test definition 1");
|
||||
referencedDefinitionsList.add("test definition 2");
|
||||
|
||||
final TheoremDto theoremDto = new TheoremDto();
|
||||
theoremDto.setName("Test theorem");
|
||||
theoremDto.setBranch("Test branch");
|
||||
theoremDto.setProvenStatus(true);
|
||||
theoremDto.setTheoremType(TheoremType.THEOREM);
|
||||
theoremDto.setReferencedTheorems(referencedTheoremsList);
|
||||
theoremDto.setReferencedDefinitions(referencedDefinitionsList);
|
||||
final Theorem theorem = new Theorem();
|
||||
theorem.setName("Test theorem");
|
||||
theorem.setTheorem("test");
|
||||
theorem.setBranch("Test branch");
|
||||
theorem.setProvenStatus(true);
|
||||
theorem.setTheoremType(TheoremType.THEOREM);
|
||||
theorem.setReferencedTheorems(referencedTheoremsList);
|
||||
theorem.setReferencedDefinitions(referencedDefinitionsList);
|
||||
|
||||
return theoremDto;
|
||||
return theorem;
|
||||
}
|
||||
}
|
||||
|
||||
+47
-47
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Account;
|
||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -26,9 +26,9 @@ import java.util.Optional;
|
||||
public class AccountController {
|
||||
private final AccountsRepository accountsRepository;
|
||||
|
||||
@GetMapping("/")
|
||||
@GetMapping({"","/"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<Iterable<AccountDto>> getListOfAccounts() {
|
||||
ResponseEntity<Iterable<Account>> getListOfAccounts() {
|
||||
LOG.info("Received request to list all accounts");
|
||||
|
||||
LOG.debug("Querying for list of accounts");
|
||||
@@ -36,78 +36,78 @@ public class AccountController {
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<AccountDto> listOfAccounts = (List<AccountDto>) accountsRepository.findAll();
|
||||
final List<Account> listOfAccounts = (List<Account>) accountsRepository.findAll();
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Successfully completed query. Query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.info("Returning list of all accounts with size of " + listOfAccounts.size());
|
||||
LOG.debug("Successfully completed query. Query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all accounts with size of {}", listOfAccounts.size());
|
||||
|
||||
return new ResponseEntity<>(listOfAccounts, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@GetMapping("/id")
|
||||
public @ResponseBody
|
||||
ResponseEntity<AccountDto> getAccountById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to query for account with id " + id);
|
||||
ResponseEntity<Account> getAccountById(@RequestParam("id") final Integer id) {
|
||||
LOG.info("Received request to query for account with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("ERROR: ID was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for account with id " + id);
|
||||
LOG.debug("Querying for account with id {}", id);
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<AccountDto> account = accountsRepository.findById(id);
|
||||
final Optional<Account> account = accountsRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
return account.map(accountDto -> {
|
||||
LOG.info("Returning account with id " + id);
|
||||
LOG.info("Returning account with id {}", id);
|
||||
return new ResponseEntity<>(accountDto, HttpStatus.OK);
|
||||
}).orElseGet(
|
||||
() -> {
|
||||
LOG.warn("No account was found with id " + id);
|
||||
LOG.warn("No account was found with id {}", id);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/{username}")
|
||||
@GetMapping("/username")
|
||||
public @ResponseBody
|
||||
ResponseEntity<AccountDto> getAccountByUsername(@PathVariable("username") final String username) {
|
||||
LOG.info("Received request to query for account with username " + username);
|
||||
ResponseEntity<Account> getAccountByUsername(@RequestParam("username") final String username) {
|
||||
LOG.info("Received request to query for account with username {}", username);
|
||||
if (username == null) {
|
||||
LOG.error("ERROR: username was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for account with username " + username);
|
||||
LOG.debug("Querying for account with username {}", username);
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<AccountDto> account = accountsRepository.findByUsername(username);
|
||||
final Optional<Account> account = accountsRepository.findByUsername(username);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
return account.map(accountDto -> {
|
||||
LOG.info("Returning account with username " + username);
|
||||
LOG.info("Returning account with username {}", username);
|
||||
return new ResponseEntity<>(accountDto, HttpStatus.OK);
|
||||
}).orElseGet(
|
||||
() -> {
|
||||
LOG.warn("No account was found with username " + username);
|
||||
LOG.warn("No account was found with username {}", username);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
@Validated({AccountDto.Insert.class, Default.class})
|
||||
public @ResponseBody ResponseEntity<AccountDto> insertAccount(
|
||||
@Valid @RequestBody final AccountDto accountDto, final BindingResult bindingResult) {
|
||||
@PostMapping({"","/"})
|
||||
@Validated({Account.Insert.class, Default.class})
|
||||
public @ResponseBody ResponseEntity<Account> insertAccount(
|
||||
@Valid @RequestBody final Account account, final BindingResult bindingResult) {
|
||||
|
||||
LOG.info("Received request to insert a new account");
|
||||
if (bindingResult.hasErrors()) {
|
||||
@@ -115,23 +115,23 @@ public class AccountController {
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (accountDto == null) {
|
||||
if (account == null) {
|
||||
LOG.error("Passed account is unprocessable");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.info("Checking for any existing users with username {}", accountDto.getUsername());
|
||||
LOG.info("Checking for any existing users with username {}", account.getUsername());
|
||||
|
||||
final Instant start = Instant.now();
|
||||
|
||||
LOG.debug("Querying for existing accounts");
|
||||
|
||||
final Optional<AccountDto> existingAccount = accountsRepository.findByUsername(accountDto.getUsername());
|
||||
final Optional<Account> existingAccount = accountsRepository.findByUsername(account.getUsername());
|
||||
|
||||
LOG.debug("Received response from the server: query took {} ms", Duration.between(start, Instant.now()).toMillis());
|
||||
|
||||
if (existingAccount.isPresent()) {
|
||||
LOG.warn("An account already exists with username {}", accountDto.getUsername());
|
||||
LOG.warn("An account already exists with username {}", account.getUsername());
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
@@ -140,19 +140,19 @@ public class AccountController {
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final AccountDto savedAccount = accountsRepository.save(accountDto);
|
||||
final Account savedAccount = accountsRepository.save(account);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning the newly created account");
|
||||
return new ResponseEntity<>(savedAccount, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<AccountDto> updateAccount(
|
||||
public @ResponseBody ResponseEntity<Account> updateAccount(
|
||||
@PathVariable("id") final Integer id,
|
||||
@RequestBody final AccountDto accountDto, final BindingResult bindingResult) {
|
||||
@RequestBody final Account account, final BindingResult bindingResult) {
|
||||
|
||||
LOG.info("Received request to update an account");
|
||||
if (bindingResult.hasErrors()) {
|
||||
@@ -160,7 +160,7 @@ public class AccountController {
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (accountDto == null) {
|
||||
if (account == null) {
|
||||
LOG.error("Passed entity is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -170,48 +170,48 @@ public class AccountController {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Checking for existence of account with id " + id);
|
||||
LOG.debug("Checking for existence of account with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<AccountDto> existingAccount = accountsRepository.findById(id);
|
||||
final Optional<Account> existingAccount = accountsRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
if (!existingAccount.isPresent()) {
|
||||
LOG.error("No account associated with id " + id);
|
||||
LOG.error("No account associated with id {}", id);
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
PersistenceUtilities.copyNonNullProperties(accountDto, existingAccount.get());
|
||||
PersistenceUtilities.copyNonNullProperties(account, existingAccount.get());
|
||||
existingAccount.get().setVersion(existingAccount.get().getVersion()+ 1);
|
||||
|
||||
LOG.info("Updating account with id " + id);
|
||||
LOG.debug("Querying for account with ID " + id);
|
||||
LOG.info("Updating account with id {}", id);
|
||||
LOG.debug("Querying for account with id {}", id);
|
||||
|
||||
stopWatch.start();
|
||||
|
||||
final AccountDto updatedAccount = accountsRepository.save(existingAccount.get());
|
||||
final Account updatedAccount = accountsRepository.save(existingAccount.get());
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(updatedAccount, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<Void> deleteAccountById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to delete account with id " + id);
|
||||
LOG.info("Received request to delete account with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("Specified Id is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Deleting account with id " + id);
|
||||
LOG.debug("Deleting account with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
@@ -220,7 +220,7 @@ public class AccountController {
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
+36
-36
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -24,59 +24,59 @@ import java.util.Optional;
|
||||
public class DefinitionController {
|
||||
private final DefinitionRepository definitionRepository;
|
||||
|
||||
@GetMapping("/")
|
||||
@GetMapping({"","/"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<Iterable<DefinitionDto>> getAllDefinitions() {
|
||||
ResponseEntity<Iterable<Definition>> getAllDefinitions() {
|
||||
LOG.info("Received request to list all definitions");
|
||||
|
||||
LOG.debug("Querying for list of all definitions");
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<DefinitionDto> listOfDefinitions = definitionRepository.findAll();
|
||||
final List<Definition> listOfDefinitions = definitionRepository.findAll();
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Successfully completed query. Query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.info("Returning list of all definition with size " + listOfDefinitions.size());
|
||||
LOG.debug("Successfully completed query. Query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all definition with size {}", listOfDefinitions.size());
|
||||
|
||||
return new ResponseEntity<>(listOfDefinitions, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public @ResponseBody
|
||||
ResponseEntity<DefinitionDto> getDefinitionById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to query for definition with id " + id);
|
||||
ResponseEntity<Definition> getDefinitionById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to query for definition with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("ERROR: ID was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for definition with id " + id);
|
||||
LOG.debug("Querying for definition with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<DefinitionDto> definition = definitionRepository.findById(id);
|
||||
final Optional<Definition> definition = definitionRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
return definition.map(definitionDto -> {
|
||||
LOG.info("Returning definition with id " + id);
|
||||
LOG.info("Returning definition with id {}", id);
|
||||
return new ResponseEntity<>(definitionDto, HttpStatus.OK);
|
||||
}).orElseGet(
|
||||
() -> {
|
||||
LOG.warn("No definition was found with id " + id);
|
||||
LOG.warn("No definition was found with id {}",id);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
@Validated({DefinitionDto.Insert.class, Default.class})
|
||||
public @ResponseBody ResponseEntity<DefinitionDto> insertDefinition(
|
||||
@Valid @RequestBody final DefinitionDto definitionDto,
|
||||
@PostMapping({"","/"})
|
||||
@Validated({Definition.Insert.class, Default.class})
|
||||
public @ResponseBody ResponseEntity<Definition> insertDefinition(
|
||||
@Valid @RequestBody final Definition definition,
|
||||
final BindingResult bindingResult) {
|
||||
LOG.info("Received request to insert a new definition");
|
||||
if (bindingResult.hasErrors()) {
|
||||
@@ -84,7 +84,7 @@ public class DefinitionController {
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (definitionDto == null) {
|
||||
if (definition == null) {
|
||||
LOG.error("Passed entity is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -94,19 +94,19 @@ public class DefinitionController {
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final DefinitionDto savedDefinition = definitionRepository.save(definitionDto);
|
||||
final Definition savedDefinition = definitionRepository.save(definition);
|
||||
|
||||
stopWatch.stop();
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
LOG.info("Returning the newly created definition with id " + savedDefinition.getId());
|
||||
LOG.info("Returning the newly created definition with id {}", savedDefinition.getId());
|
||||
return new ResponseEntity<>(savedDefinition, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<DefinitionDto> updateDefinition(
|
||||
public @ResponseBody ResponseEntity<Definition> updateDefinition(
|
||||
@PathVariable("id") final Integer id,
|
||||
@RequestBody final DefinitionDto definitionDto, final BindingResult bindingResult) {
|
||||
@RequestBody final Definition definition, final BindingResult bindingResult) {
|
||||
|
||||
LOG.info("Received request to update an account");
|
||||
if (bindingResult.hasErrors()) {
|
||||
@@ -114,7 +114,7 @@ public class DefinitionController {
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (definitionDto == null) {
|
||||
if (definition == null) {
|
||||
LOG.error("Passed entity is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -124,48 +124,48 @@ public class DefinitionController {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Checking for existence of definition with id " + id);
|
||||
LOG.debug("Checking for existence of definition with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<DefinitionDto> existingDefinition = definitionRepository.findById(id);
|
||||
final Optional<Definition> existingDefinition = definitionRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
if (!existingDefinition.isPresent()) {
|
||||
LOG.error("No definition associated with id " + id);
|
||||
LOG.error("No definition associated with id {}", id);
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
PersistenceUtilities.copyNonNullProperties(definitionDto, existingDefinition.get());
|
||||
PersistenceUtilities.copyNonNullProperties(definition, existingDefinition.get());
|
||||
existingDefinition.get().setVersion(existingDefinition.get().getVersion()+ 1);
|
||||
|
||||
LOG.info("Updating definition with id " + id);
|
||||
LOG.debug("Querying for definition with ID " + id);
|
||||
LOG.info("Updating definition with id {}", id);
|
||||
LOG.debug("Querying for definition with id {}", id);
|
||||
|
||||
stopWatch.start();
|
||||
|
||||
final DefinitionDto updatedDefinition = definitionRepository.save(existingDefinition.get());
|
||||
final Definition updatedDefinition = definitionRepository.save(existingDefinition.get());
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(updatedDefinition, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<Void> deleteDefinitionById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to delete definition with id " + id);
|
||||
LOG.info("Received request to delete definition with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("Specified id is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Deleting definition with id " + id);
|
||||
LOG.debug("Deleting definition with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
@@ -174,7 +174,7 @@ public class DefinitionController {
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.repository.NotationRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class NotationController {
|
||||
private final NotationRepository notationRepository;
|
||||
}
|
||||
+242
-2
@@ -1,11 +1,251 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||
import edu.msudenver.tsp.persistence.repository.ProofRepository;
|
||||
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Component
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/proofs")
|
||||
public class ProofController {
|
||||
private final ProofRepository proofRepository;
|
||||
|
||||
@GetMapping({"","/"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<Iterable<Proof>> getAllProofs() {
|
||||
LOG.info("Received request to list all theorems");
|
||||
|
||||
LOG.debug("Querying for list of all theorems");
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<Proof> listOfProofs = proofRepository.findAll();
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Successfully completed query. Query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all theorems with size {}", listOfProofs.size());
|
||||
|
||||
return new ResponseEntity<>(listOfProofs, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/id")
|
||||
public @ResponseBody
|
||||
ResponseEntity<Proof> getProofById(@RequestParam("id") final Integer id) {
|
||||
LOG.info("Received request to query for proof with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("ERROR: ID was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for proof with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<Proof> proof = proofRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
return proof.map(proofDto -> {
|
||||
LOG.info("Returning proof with id {}", id);
|
||||
return new ResponseEntity<>(proofDto, HttpStatus.OK);
|
||||
}).orElseGet(
|
||||
() -> {
|
||||
LOG.warn("No proof was found with id {}", id);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/branch")
|
||||
public @ResponseBody
|
||||
ResponseEntity<List<Proof>> getAllProofsByBranch(@RequestParam("branch") String branch) {
|
||||
LOG.info("Received request to query for proofs related to the {} branch of mathematics", branch);
|
||||
if (branch == null) {
|
||||
LOG.error("ERROR: branch was null");
|
||||
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);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<Proof> listOfProofs = proofRepository.findByBranch(branch);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all proofs with size {}", listOfProofs.size());
|
||||
|
||||
if (listOfProofs.isEmpty()) {
|
||||
LOG.warn("No proofs were found for branch {}", branch);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
LOG.info("Returning list of proofs with branch {}", branch);
|
||||
return new ResponseEntity<>(listOfProofs, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/theorem_name")
|
||||
public @ResponseBody
|
||||
ResponseEntity<List<Proof>> getAllProofsByTheoremName(@RequestParam("theorem_name") String theoremName) {
|
||||
LOG.info("Received request to query for proofs of the theorem {}", theoremName);
|
||||
if (theoremName == null) {
|
||||
LOG.error("ERROR: theorem name was null");
|
||||
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);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<Proof> listOfProofs = proofRepository.findByTheoremName(theoremName);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all proofs with size {}", listOfProofs.size());
|
||||
|
||||
if (listOfProofs.isEmpty()) {
|
||||
LOG.warn("No proofs were found of the theorem {}", theoremName);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
LOG.info("Returning list of proofs for the theorem {}", theoremName);
|
||||
return new ResponseEntity<>(listOfProofs, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping({"","/"})
|
||||
@Validated({Proof.Insert.class, Default.class})
|
||||
public @ResponseBody ResponseEntity<Proof> insertProof(
|
||||
@Valid @RequestBody final Proof proof,
|
||||
final BindingResult bindingResult) {
|
||||
LOG.info("Received request to insert a new proof");
|
||||
if (bindingResult.hasErrors()) {
|
||||
LOG.error("Binding result is unprocessable");
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (proof == null) {
|
||||
LOG.error("Passed entity is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Saving new proof");
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Proof savedProof = proofRepository.save(proof);
|
||||
|
||||
stopWatch.stop();
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
LOG.info("Returning the newly created proof with id {}", savedProof.getId());
|
||||
return new ResponseEntity<>(savedProof, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<Proof> updateProof(
|
||||
@PathVariable("id") final Integer id,
|
||||
@RequestBody final Proof proof, final BindingResult bindingResult) {
|
||||
|
||||
LOG.info("Received request to update a proof");
|
||||
if (bindingResult.hasErrors()) {
|
||||
LOG.error("Binding result is unprocessable");
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (proof == null) {
|
||||
LOG.error("Passed entity is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (id == null) {
|
||||
LOG.error("Proof ID must be specified");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Checking for existence of proof with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<Proof> existingProof = proofRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
if (!existingProof.isPresent()) {
|
||||
LOG.error("No proof associated with id {}", id);
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
PersistenceUtilities.copyNonNullProperties(proof, existingProof.get());
|
||||
existingProof.get().setVersion(existingProof.get().getVersion()+ 1);
|
||||
|
||||
LOG.info("Updating proof with id {}", id);
|
||||
LOG.debug("Querying for proof with ID {}", id);
|
||||
|
||||
stopWatch.start();
|
||||
|
||||
final Proof updatedProof = proofRepository.save(existingProof.get());
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(updatedProof, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<Void> deleteProofById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to delete proof with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("Specified id is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Deleting proof with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
proofRepository.deleteById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
||||
+98
-53
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.TheoremDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Theorem;
|
||||
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
||||
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -9,9 +9,11 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -22,45 +24,50 @@ import java.util.Optional;
|
||||
public class TheoremController {
|
||||
private final TheoremRepository theoremRepository;
|
||||
|
||||
@GetMapping("/")
|
||||
@GetMapping({"","/"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<Iterable<TheoremDto>> getAllTheorems() {
|
||||
ResponseEntity<Iterable<Theorem>> getAllTheorems() {
|
||||
LOG.info("Received request to list all theorems");
|
||||
|
||||
LOG.debug("Querying for list of all theorems");
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<TheoremDto> listOfTheorems = theoremRepository.findAll();
|
||||
final List<Theorem> listOfTheorems = theoremRepository.findAll();
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Successfully completed query. Query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.info("Returning list of all theorems with size " + listOfTheorems.size());
|
||||
LOG.debug("Successfully completed query. Query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all theorems with size {}", listOfTheorems.size());
|
||||
|
||||
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{branch}")
|
||||
@GetMapping("/branch")
|
||||
public @ResponseBody
|
||||
ResponseEntity<List<TheoremDto>> getAllTheoremsByBranch(@PathVariable("branch") final String branch) {
|
||||
LOG.info("Received request to query for theorems related to the " + branch + " branch of mathematics");
|
||||
ResponseEntity<List<Theorem>> getAllTheoremsByBranch(@RequestParam("branch") String branch) {
|
||||
LOG.info("Received request to query for theorems related to the {} branch of mathematics", branch);
|
||||
if (branch == null) {
|
||||
LOG.error("ERROR: branch was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for theorems with branch " + branch);
|
||||
if (branch.contains("_") || branch.contains("-")) {
|
||||
branch = branch.replace("_", " ");
|
||||
branch = branch.replace("-", " ");
|
||||
}
|
||||
|
||||
LOG.debug("Querying for theorems with branch {}", branch);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<TheoremDto> listOfTheorems = theoremRepository.findByBranch(branch);
|
||||
final List<Theorem> listOfTheorems = theoremRepository.findByBranch(branch);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.info("Returning list of all theorems with size " + listOfTheorems.size());
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all theorems with size {}", listOfTheorems.size());
|
||||
|
||||
if (listOfTheorems.isEmpty()) {
|
||||
LOG.warn("No theorems were found for branch {}", branch);
|
||||
@@ -71,69 +78,107 @@ public class TheoremController {
|
||||
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{proven_status}")
|
||||
@GetMapping("/proven_status")
|
||||
public @ResponseBody
|
||||
ResponseEntity<List<TheoremDto>> getAllTheoremsByProvenStatus(@PathVariable("proven_status") final Boolean provenStatus) {
|
||||
LOG.info("Received request to query for theorems whose proven status is " + 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<TheoremDto> listOfTheorems = theoremRepository.findByProvenStatus(provenStatus);
|
||||
final List<Theorem> listOfTheorems = theoremRepository.findByProvenStatus(isProven);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.info("Returning list of all theorems with size " + listOfTheorems.size());
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
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);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@GetMapping("/name")
|
||||
public @ResponseBody
|
||||
ResponseEntity<TheoremDto> getTheoremById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to query for theorem with id " + id);
|
||||
ResponseEntity<List<Theorem>> getAllTheoremsByName(@RequestParam("name") String name) {
|
||||
LOG.info("Received request to query for theorems whose name is {}", name);
|
||||
if (name == null) {
|
||||
LOG.error("ERROR: name was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (name.contains("_") || name.contains("-")) {
|
||||
name = name.replace("_", " ");
|
||||
name = name.replace("-", " ");
|
||||
}
|
||||
|
||||
LOG.debug("Querying for theorems with name {}", name);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<Theorem> listOfTheorems = theoremRepository.findByName(name);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
LOG.info("Returning list of all theorems with size {}", listOfTheorems.size());
|
||||
|
||||
if (listOfTheorems.isEmpty()) {
|
||||
LOG.warn("No theorems were found with name {}", name);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
LOG.info("Returning list of theorems with name {}", name);
|
||||
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/id")
|
||||
public @ResponseBody
|
||||
ResponseEntity<Theorem> getTheoremById(@RequestParam("id") final Integer id) {
|
||||
LOG.info("Received request to query for theorem with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("ERROR: ID was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for theorem with id " + id);
|
||||
LOG.debug("Querying for theorem with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<TheoremDto> theorem = theoremRepository.findById(id);
|
||||
final Optional<Theorem> theorem = theoremRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
return theorem.map(theoremDto -> {
|
||||
LOG.info("Returning theorem with id " + id);
|
||||
LOG.info("Returning theorem with id {}", id);
|
||||
return new ResponseEntity<>(theoremDto, HttpStatus.OK);
|
||||
}).orElseGet(
|
||||
() -> {
|
||||
LOG.warn("No theorem was found with id " + id);
|
||||
LOG.warn("No theorem was found with id {}", id);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public @ResponseBody ResponseEntity<TheoremDto> insertTheorem(
|
||||
@Valid @RequestBody final TheoremDto theoremDto,
|
||||
@PostMapping({"","/"})
|
||||
@Validated({Theorem.Insert.class, Default.class})
|
||||
public @ResponseBody ResponseEntity<Theorem> insertTheorem(
|
||||
@Valid @RequestBody final Theorem theorem,
|
||||
final BindingResult bindingResult) {
|
||||
LOG.info("Received request to insert a new theorem");
|
||||
if (bindingResult.hasErrors()) {
|
||||
@@ -141,7 +186,7 @@ public class TheoremController {
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (theoremDto == null) {
|
||||
if (theorem == null) {
|
||||
LOG.error("Passed entity is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -151,27 +196,27 @@ public class TheoremController {
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final TheoremDto savedTheorem = theoremRepository.save(theoremDto);
|
||||
final Theorem savedTheorem = theoremRepository.save(theorem);
|
||||
|
||||
stopWatch.stop();
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
LOG.info("Returning the newly created theorem with id " + savedTheorem.getId());
|
||||
LOG.info("Returning the newly created theorem with id {}", savedTheorem.getId());
|
||||
return new ResponseEntity<>(savedTheorem, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<TheoremDto> updateTheorem(
|
||||
public @ResponseBody ResponseEntity<Theorem> updateTheorem(
|
||||
@PathVariable("id") final Integer id,
|
||||
@RequestBody final TheoremDto theoremDto, final BindingResult bindingResult) {
|
||||
@RequestBody final Theorem theorem, final BindingResult bindingResult) {
|
||||
|
||||
LOG.info("Received request to update an account");
|
||||
LOG.info("Received request to update a theorem");
|
||||
if (bindingResult.hasErrors()) {
|
||||
LOG.error("Binding result is unprocessable");
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (theoremDto == null) {
|
||||
if (theorem == null) {
|
||||
LOG.error("Passed entity is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -181,48 +226,48 @@ public class TheoremController {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Checking for existence of theorem with id " + id);
|
||||
LOG.debug("Checking for existence of theorem with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<TheoremDto> existingTheorem = theoremRepository.findById(id);
|
||||
final Optional<Theorem> existingTheorem = theoremRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
if (!existingTheorem.isPresent()) {
|
||||
LOG.error("No theorem associated with id " + id);
|
||||
LOG.error("No theorem associated with id {}", id);
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
PersistenceUtilities.copyNonNullProperties(theoremDto, existingTheorem.get());
|
||||
PersistenceUtilities.copyNonNullProperties(theorem, existingTheorem.get());
|
||||
existingTheorem.get().setVersion(existingTheorem.get().getVersion()+ 1);
|
||||
|
||||
LOG.info("Updating theorem with id " + id);
|
||||
LOG.debug("Querying for theorem with ID " + id);
|
||||
LOG.info("Updating theorem with id {}", id);
|
||||
LOG.debug("Querying for theorem with id {}", id);
|
||||
|
||||
stopWatch.start();
|
||||
|
||||
final TheoremDto updatedTheorem = theoremRepository.save(existingTheorem.get());
|
||||
final Theorem updatedTheorem = theoremRepository.save(existingTheorem.get());
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(updatedTheorem, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public @ResponseBody ResponseEntity<Void> deleteTheoremById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to delete theorem with id " + id);
|
||||
LOG.info("Received request to delete theorem with id {}", id);
|
||||
if (id == null) {
|
||||
LOG.error("Specified id is null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Deleting theorem with id " + id);
|
||||
LOG.debug("Deleting theorem with id {}", id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
@@ -231,7 +276,7 @@ public class TheoremController {
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import java.util.Date;
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AccountDto extends BaseDto implements Serializable {
|
||||
public class Account extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
||||
@NotBlank(groups = Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
||||
@NotNull @Column(name = "administrator_status") private boolean administratorStatus;
|
||||
@@ -1,17 +1,35 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class Definition implements Serializable {
|
||||
private List<String> definitions;
|
||||
@Entity(name = "definitions")
|
||||
@Table(name = "definitions")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Definition extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = Insert.class, message = "A name must be specified")
|
||||
@Size(min = 1, max = 200, message = "Must be between 1 and 200 characters")
|
||||
private String name;
|
||||
|
||||
private static final long serialVersionUID = -2208496232532214840L;
|
||||
@NotBlank(groups = Insert.class, message = "At least one (1) definition must be specified")
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> definition;
|
||||
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> notation;
|
||||
|
||||
private static final long serialVersionUID = -5314619286352932857L;
|
||||
|
||||
public interface Insert {}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity(name = "definitions")
|
||||
@Table(name = "definitions")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DefinitionDto extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = Insert.class, message = "A name must be specified")
|
||||
@Size(min = 1, max = 200, message = "Must be between 1 and 200 characters")
|
||||
private String name;
|
||||
|
||||
@NotBlank(groups = Insert.class, message = "At least one (1) definition must be specified")
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private Definition definition;
|
||||
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private Notation notation;
|
||||
|
||||
private static final long serialVersionUID = -5314619286352932857L;
|
||||
|
||||
public interface Insert {}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class Notation implements Serializable {
|
||||
private List<String> notations;
|
||||
private static final long serialVersionUID = 2301438318932336121L;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
public class NotationDto extends BaseDto {
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Entity(name = "proofs")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Proof extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = Insert.class)
|
||||
@Size(min = 1, max = 512, message = "The name must be at least 1 character and at most 512 characters")
|
||||
@Column(name = "theorem_name")
|
||||
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;
|
||||
@NotNull(groups = Insert.class)
|
||||
private Integer theorem;
|
||||
@NotBlank(groups = Insert.class)
|
||||
@Size(min = 1, max = 512, message = "The branch must be at least 1 character and at most 512 characters")
|
||||
private String branch;
|
||||
@Type(type = "json") @Column(name = "referenced_definitions", columnDefinition = "jsonb") private List<String> referencedDefinitions;
|
||||
@Type(type = "json") @Column(name = "referenced_theorems", columnDefinition = "jsonb") private List<String> referencedTheorems;
|
||||
@Temporal(TemporalType.DATE) @Column(name = "date_created") private Date dateCreated;
|
||||
@Temporal(TemporalType.DATE) @Column(name = "last_updated") private Date lastUpdated;
|
||||
|
||||
@JsonProperty("theorem_name")
|
||||
public String getTheoremName() {
|
||||
return theoremName;
|
||||
}
|
||||
|
||||
@JsonProperty("theorem_name")
|
||||
public void setTheoremName(final String theoremName) {
|
||||
this.theoremName = theoremName;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_definitions")
|
||||
public List<String> getReferencedDefinitions() {
|
||||
return referencedDefinitions;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_definitions")
|
||||
public void setReferencedDefinitions(final List<String> referencedDefinitions) {
|
||||
this.referencedDefinitions = referencedDefinitions;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_theorems")
|
||||
public List<String> getReferencedTheorems() {
|
||||
return referencedTheorems;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_theorems")
|
||||
public void setReferencedTheorems(final List<String> referencedTheorems) {
|
||||
this.referencedTheorems = referencedTheorems;
|
||||
}
|
||||
|
||||
@JsonProperty("date_created")
|
||||
public Date getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
@JsonProperty("date_created")
|
||||
public void setDateCreated(final Date dateCreated) {
|
||||
this.dateCreated = dateCreated;
|
||||
}
|
||||
|
||||
@JsonProperty("last_updated")
|
||||
public Date getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
@JsonProperty("last_updated")
|
||||
public void setLastUpdated(final Date lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
lastUpdated = new Date();
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -7731220940349760402L;
|
||||
|
||||
public interface Insert {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
public class ProofDto extends BaseDto {
|
||||
}
|
||||
+9
-5
@@ -19,13 +19,14 @@ import java.util.List;
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TheoremDto extends BaseDto implements Serializable {
|
||||
@NotBlank @Size(min = 1, max = 512, message = "theorem name must be between 1 and 512 characters") private String name;
|
||||
@NotNull @Column(name = "theorem_type") private TheoremType theoremType;
|
||||
@NotNull(message = "a branch of mathematics that this theorem is associated with must be specified") private String branch;
|
||||
public class Theorem extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = Insert.class) @Size(min = 1, max = 512, message = "theorem name must be between 1 and 512 characters") private String name;
|
||||
@NotNull(groups = Insert.class) @Size(min = 1, max = 1024, message = "theorem must be between 1 and 1024 characters") private String theorem;
|
||||
@NotNull(groups = Insert.class) @Column(name = "theorem_type") private TheoremType theoremType;
|
||||
@NotNull(groups = Insert.class, message = "a branch of mathematics that this theorem is associated with must be specified") private String branch;
|
||||
@Type(type = "json") @Column(name = "referenced_definitions", columnDefinition = "jsonb") private List<String> referencedDefinitions;
|
||||
@Type(type = "json") @Column(name = "referenced_theorems", columnDefinition = "jsonb") private List<String> referencedTheorems;
|
||||
@NotNull @Column(name = "proven_status") private boolean provenStatus;
|
||||
@NotNull(groups = Insert.class) @Column(name = "proven_status") private boolean provenStatus;
|
||||
|
||||
@JsonProperty("theorem_type")
|
||||
public TheoremType getTheoremType() {
|
||||
@@ -68,4 +69,7 @@ public class TheoremDto extends BaseDto implements Serializable {
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1545568391140364425L;
|
||||
|
||||
public interface Insert {}
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Account;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface AccountsRepository extends CrudRepository<AccountDto, Integer> {
|
||||
Optional<AccountDto> findByUsername(String username);
|
||||
public interface AccountsRepository extends CrudRepository<Account, Integer> {
|
||||
Optional<Account> findByUsername(String username);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DefinitionRepository extends JpaRepository<DefinitionDto, Integer> {
|
||||
public interface DefinitionRepository extends JpaRepository<Definition, Integer> {
|
||||
|
||||
}
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface NotationRepository extends CrudRepository<BaseDto, Long> {
|
||||
}
|
||||
+11
-3
@@ -1,7 +1,15 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
public interface ProofRepository extends CrudRepository<BaseDto, Long> {
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProofRepository extends JpaRepository<Proof, Integer> {
|
||||
|
||||
List<Proof> findByBranch(String branch);
|
||||
|
||||
List<Proof> findByTheoremName(String name);
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,15 +1,17 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.TheoremDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Theorem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface TheoremRepository extends JpaRepository<TheoremDto, Integer> {
|
||||
public interface TheoremRepository extends JpaRepository<Theorem, Integer> {
|
||||
|
||||
List<TheoremDto> findByBranch(String branch);
|
||||
List<Theorem> findByBranch(String branch);
|
||||
|
||||
List<TheoremDto> findByProvenStatus(Boolean provenStatus);
|
||||
List<Theorem> findByProvenStatus(Boolean provenStatus);
|
||||
|
||||
List<Theorem> findByName(String name);
|
||||
}
|
||||
|
||||
+43
-43
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Account;
|
||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,14 +33,14 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllAccounts() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
final List<AccountDto> accountDtoList = new ArrayList<>();
|
||||
accountDtoList.add(accountDto);
|
||||
accountDtoList.add(accountDto);
|
||||
final Account accountDto = createAccount();
|
||||
final List<Account> accountList = new ArrayList<>();
|
||||
accountList.add(accountDto);
|
||||
accountList.add(accountDto);
|
||||
|
||||
when(accountsRepository.findAll()).thenReturn(accountDtoList);
|
||||
when(accountsRepository.findAll()).thenReturn(accountList);
|
||||
|
||||
final ResponseEntity<Iterable<AccountDto>> responseEntity = accountController.getListOfAccounts();
|
||||
final ResponseEntity<Iterable<Account>> responseEntity = accountController.getListOfAccounts();
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
@@ -52,16 +52,16 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAccountById() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.ofNullable(accountDto));
|
||||
final Account account = createAccount();
|
||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.ofNullable(account));
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.getAccountById(1);
|
||||
final ResponseEntity<Account> responseEntity = accountController.getAccountById(1);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(accountDto, responseEntity.getBody());
|
||||
assertEquals(account, responseEntity.getBody());
|
||||
verify(accountsRepository).findById(anyInt());
|
||||
}
|
||||
|
||||
@@ -89,16 +89,16 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAccountByUsername() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.ofNullable(accountDto));
|
||||
final Account account = createAccount();
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.ofNullable(account));
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.getAccountByUsername("Test username");
|
||||
final ResponseEntity<Account> responseEntity = accountController.getAccountByUsername("Test username");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(accountDto, responseEntity.getBody());
|
||||
assertEquals(account, responseEntity.getBody());
|
||||
verify(accountsRepository).findByUsername(anyString());
|
||||
}
|
||||
|
||||
@@ -126,32 +126,32 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testInsertAccount() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
when(accountsRepository.save(any(AccountDto.class))).thenReturn(accountDto);
|
||||
final Account account = createAccount();
|
||||
when(accountsRepository.save(any(Account.class))).thenReturn(account);
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.insertAccount(accountDto, bindingResult);
|
||||
final ResponseEntity<Account> responseEntity = accountController.insertAccount(account, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||
assertEquals(accountDto, responseEntity.getBody());
|
||||
verify(accountsRepository).save(any(AccountDto.class));
|
||||
assertEquals(account, responseEntity.getBody());
|
||||
verify(accountsRepository).save(any(Account.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertAccount_usernameAlreadyExists() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.of(accountDto));
|
||||
final Account account = createAccount();
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.of(account));
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.insertAccount(accountDto, bindingResult);
|
||||
final ResponseEntity<Account> responseEntity = accountController.insertAccount(account, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode());
|
||||
verify(accountsRepository).findByUsername(anyString());
|
||||
verify(accountsRepository, times(0)).save(any(AccountDto.class));
|
||||
verify(accountsRepository, times(0)).save(any(Account.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,10 +166,10 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testInsertAccount_bindingResultHasErrors() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
final Account account = createAccount();
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity responseEntity = accountController.insertAccount(accountDto, bindingResult);
|
||||
final ResponseEntity responseEntity = accountController.insertAccount(account, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -179,31 +179,31 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount() {
|
||||
final AccountDto existingAccount = createAccount();
|
||||
final Account existingAccount = createAccount();
|
||||
existingAccount.setId(1);
|
||||
existingAccount.setVersion(1);
|
||||
final AccountDto accountUpdate = new AccountDto();
|
||||
final Account accountUpdate = new Account();
|
||||
accountUpdate.setUsername("Test Update");
|
||||
final AccountDto updatedAccount = existingAccount;
|
||||
final Account updatedAccount = existingAccount;
|
||||
updatedAccount.setUsername("Test Update");
|
||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.of(existingAccount));
|
||||
when(accountsRepository.save(any(AccountDto.class))).thenReturn(updatedAccount);
|
||||
when(accountsRepository.save(any(Account.class))).thenReturn(updatedAccount);
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, accountUpdate, bindingResult);
|
||||
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, accountUpdate, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(updatedAccount, responseEntity.getBody());
|
||||
verify(accountsRepository).findById(anyInt());
|
||||
verify(accountsRepository).save(any(AccountDto.class));
|
||||
verify(accountsRepository).save(any(Account.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount_bindingResultHasErrors() {
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -213,7 +213,7 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount_accountsDtoIsNull() {
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, null, bindingResult);
|
||||
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, null, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -223,7 +223,7 @@ public class AccountControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount_idIsNull() {
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(null, createAccount(), bindingResult);
|
||||
final ResponseEntity<Account> responseEntity = accountController.updateAccount(null, createAccount(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -235,12 +235,12 @@ public class AccountControllerTest {
|
||||
public void testUpdateAccount_accountDoesNotExist() {
|
||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verify(accountsRepository, times(0)).save(any(AccountDto.class));
|
||||
verify(accountsRepository, times(0)).save(any(Account.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -265,12 +265,12 @@ public class AccountControllerTest {
|
||||
verifyZeroInteractions(accountsRepository);
|
||||
}
|
||||
|
||||
private AccountDto createAccount() {
|
||||
final AccountDto accountDto = new AccountDto();
|
||||
accountDto.setUsername("Test username");
|
||||
accountDto.setPassword("test password");
|
||||
accountDto.setAdministratorStatus(true);
|
||||
private Account createAccount() {
|
||||
final Account account = new Account();
|
||||
account.setUsername("Test username");
|
||||
account.setPassword("test password");
|
||||
account.setAdministratorStatus(true);
|
||||
|
||||
return accountDto;
|
||||
return account;
|
||||
}
|
||||
}
|
||||
+34
-42
@@ -1,8 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Notation;
|
||||
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -32,14 +30,14 @@ public class DefinitionControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllDefinitions() {
|
||||
final DefinitionDto definitionDto = createDefinition();
|
||||
final List<DefinitionDto> definitionDtoList = new ArrayList<>();
|
||||
definitionDtoList.add(definitionDto);
|
||||
definitionDtoList.add(definitionDto);
|
||||
final Definition definitionDto = createDefinition();
|
||||
final List<Definition> definitionList = new ArrayList<>();
|
||||
definitionList.add(definitionDto);
|
||||
definitionList.add(definitionDto);
|
||||
|
||||
when(definitionRepository.findAll()).thenReturn(definitionDtoList);
|
||||
when(definitionRepository.findAll()).thenReturn(definitionList);
|
||||
|
||||
final ResponseEntity<Iterable<DefinitionDto>> responseEntity = definitionController.getAllDefinitions();
|
||||
final ResponseEntity<Iterable<Definition>> responseEntity = definitionController.getAllDefinitions();
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
@@ -51,16 +49,16 @@ public class DefinitionControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetDefinitionsById() {
|
||||
final DefinitionDto definitionDto = createDefinition();
|
||||
when(definitionRepository.findById(anyInt())).thenReturn(Optional.ofNullable(definitionDto));
|
||||
final Definition definition = createDefinition();
|
||||
when(definitionRepository.findById(anyInt())).thenReturn(Optional.ofNullable(definition));
|
||||
|
||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.getDefinitionById(1);
|
||||
final ResponseEntity<Definition> responseEntity = definitionController.getDefinitionById(1);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(definitionDto, responseEntity.getBody());
|
||||
assertEquals(definition, responseEntity.getBody());
|
||||
verify(definitionRepository).findById(anyInt());
|
||||
}
|
||||
|
||||
@@ -88,17 +86,17 @@ public class DefinitionControllerTest {
|
||||
|
||||
@Test
|
||||
public void testInsertDefinition() {
|
||||
final DefinitionDto definitionDto = createDefinition();
|
||||
when(definitionRepository.save(any(DefinitionDto.class))).thenReturn(definitionDto);
|
||||
final Definition definition = createDefinition();
|
||||
when(definitionRepository.save(any(Definition.class))).thenReturn(definition);
|
||||
|
||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.insertDefinition(definitionDto, bindingResult);
|
||||
final ResponseEntity<Definition> responseEntity = definitionController.insertDefinition(definition, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||
assertEquals(definitionDto, responseEntity.getBody());
|
||||
verify(definitionRepository).save(any(DefinitionDto.class));
|
||||
assertEquals(definition, responseEntity.getBody());
|
||||
verify(definitionRepository).save(any(Definition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,10 +111,10 @@ public class DefinitionControllerTest {
|
||||
|
||||
@Test
|
||||
public void testInsertDefinition_bindingResultHasErrors() {
|
||||
final DefinitionDto definitionDto = createDefinition();
|
||||
final Definition definition = createDefinition();
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity responseEntity = definitionController.insertDefinition(definitionDto, bindingResult);
|
||||
final ResponseEntity responseEntity = definitionController.insertDefinition(definition, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -126,31 +124,31 @@ public class DefinitionControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateDefinition() {
|
||||
final DefinitionDto existingDefinition = createDefinition();
|
||||
final Definition existingDefinition = createDefinition();
|
||||
existingDefinition.setId(1);
|
||||
existingDefinition.setVersion(1);
|
||||
final DefinitionDto definitionUpdate = new DefinitionDto();
|
||||
final Definition definitionUpdate = new Definition();
|
||||
definitionUpdate.setName("Test Update");
|
||||
final DefinitionDto updatedDefinition = existingDefinition;
|
||||
final Definition updatedDefinition = existingDefinition;
|
||||
updatedDefinition.setName("Test Update");
|
||||
when(definitionRepository.findById(anyInt())).thenReturn(Optional.of(existingDefinition));
|
||||
when(definitionRepository.save(any(DefinitionDto.class))).thenReturn(updatedDefinition);
|
||||
when(definitionRepository.save(any(Definition.class))).thenReturn(updatedDefinition);
|
||||
|
||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(1, definitionUpdate, bindingResult);
|
||||
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, definitionUpdate, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(updatedDefinition, responseEntity.getBody());
|
||||
verify(definitionRepository).findById(anyInt());
|
||||
verify(definitionRepository).save(any(DefinitionDto.class));
|
||||
verify(definitionRepository).save(any(Definition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDefinition_bindingResultErrors() {
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
||||
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -160,7 +158,7 @@ public class DefinitionControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateDefinition_definitionDtoIsNull() {
|
||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(1, null, bindingResult);
|
||||
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, null, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -170,7 +168,7 @@ public class DefinitionControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateDefinition_idIsNull() {
|
||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(null, createDefinition(), bindingResult);
|
||||
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(null, createDefinition(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -182,12 +180,12 @@ public class DefinitionControllerTest {
|
||||
public void testUpdateDefinition_definitionDoesntExist() {
|
||||
when(definitionRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
||||
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verify(definitionRepository, times(0)).save(any(DefinitionDto.class));
|
||||
verify(definitionRepository, times(0)).save(any(Definition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -212,24 +210,18 @@ public class DefinitionControllerTest {
|
||||
verifyZeroInteractions(definitionRepository);
|
||||
}
|
||||
|
||||
private DefinitionDto createDefinition() {
|
||||
private Definition createDefinition() {
|
||||
final List<String> definitionList = new ArrayList<>();
|
||||
definitionList.add("Test definition 1");
|
||||
|
||||
final Definition definition = new Definition();
|
||||
definition.setDefinitions(definitionList);
|
||||
|
||||
final List<String> notationList = new ArrayList<>();
|
||||
notationList.add("\\testLaTeX");
|
||||
|
||||
final Notation notation = new Notation();
|
||||
notation.setNotations(notationList);
|
||||
final Definition definition = new Definition();
|
||||
definition.setName("Test Name");
|
||||
definition.setDefinition(definitionList);
|
||||
definition.setNotation(notationList);
|
||||
|
||||
final DefinitionDto definitionDto = new DefinitionDto();
|
||||
definitionDto.setName("Test Name");
|
||||
definitionDto.setDefinition(definition);
|
||||
definitionDto.setNotation(notation);
|
||||
|
||||
return definitionDto;
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
+310
@@ -0,0 +1,310 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||
import edu.msudenver.tsp.persistence.repository.ProofRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProofControllerTest {
|
||||
@Mock private ProofRepository proofRepository;
|
||||
@InjectMocks private ProofController proofController;
|
||||
@Mock private BindingResult bindingResult;
|
||||
|
||||
@Test
|
||||
public void testGetAllProofs() {
|
||||
final Proof proofDto = createProof();
|
||||
final List<Proof> listOfProofs = new ArrayList<>();
|
||||
listOfProofs.add(proofDto);
|
||||
listOfProofs.add(proofDto);
|
||||
|
||||
when(proofRepository.findAll()).thenReturn(listOfProofs);
|
||||
|
||||
final ResponseEntity<Iterable<Proof>> responseEntity = proofController.getAllProofs();
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
|
||||
responseEntity.getBody().forEach(proof -> assertEquals(proofDto, proof));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllProofsByBranch() {
|
||||
final Proof proofDto = createProof();
|
||||
final List<Proof> listOfProofs = new ArrayList<>();
|
||||
listOfProofs.add(proofDto);
|
||||
listOfProofs.add(proofDto);
|
||||
|
||||
when(proofRepository.findByBranch(anyString())).thenReturn(listOfProofs);
|
||||
|
||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByBranch("Test_branch");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
|
||||
responseEntity.getBody().forEach(proof -> assertEquals(proofDto, proof));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllProfsByBranch_nullBranch() {
|
||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByBranch(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllProofsByBranch_noProofsFound() {
|
||||
when(proofRepository.findByBranch(anyString())).thenReturn(Collections.emptyList());
|
||||
|
||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByBranch("test-nonexistent-branch");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllProofsByTheoremName() {
|
||||
final Proof proofDto = createProof();
|
||||
final List<Proof> listOfProofs = new ArrayList<>();
|
||||
listOfProofs.add(proofDto);
|
||||
listOfProofs.add(proofDto);
|
||||
|
||||
when(proofRepository.findByTheoremName(anyString())).thenReturn(listOfProofs);
|
||||
|
||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName("Test_proof");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
|
||||
responseEntity.getBody().forEach(proof -> assertEquals(proofDto, proof));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllProofsByTheoremName_nullTheoremName() {
|
||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllProofsByTheoremName_noProofsFound() {
|
||||
when(proofRepository.findByTheoremName(anyString())).thenReturn(Collections.emptyList());
|
||||
|
||||
final ResponseEntity<List<Proof>> responseEntity = proofController.getAllProofsByTheoremName("test-nonexistent-proof");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProofById() {
|
||||
final Proof proof = createProof();
|
||||
when(proofRepository.findById(anyInt())).thenReturn(Optional.ofNullable(proof));
|
||||
|
||||
final ResponseEntity<Proof> responseEntity = proofController.getProofById(1);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(proof, responseEntity.getBody());
|
||||
verify(proofRepository).findById(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProofById_nullId() {
|
||||
final ResponseEntity responseEntity = proofController.getProofById(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProofById_noProofFound() {
|
||||
when(proofRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity responseEntity = proofController.getProofById(1);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
verify(proofRepository).findById(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertProof() {
|
||||
final Proof proof = createProof();
|
||||
when(proofRepository.save(any(Proof.class))).thenReturn(proof);
|
||||
|
||||
final ResponseEntity<Proof> responseEntity = proofController.insertProof(proof, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||
assertEquals(proof, responseEntity.getBody());
|
||||
verify(proofRepository).save(any(Proof.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertProof_proofDtoIsNull() {
|
||||
final ResponseEntity responseEntity = proofController.insertProof(null, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertProof_bindingResultHasErrors() {
|
||||
final Proof proof = createProof();
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity responseEntity = proofController.insertProof(proof, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProof() {
|
||||
final Proof existingProof = createProof();
|
||||
existingProof.setId(1);
|
||||
existingProof.setVersion(1);
|
||||
final Proof proofUpdate = new Proof();
|
||||
proofUpdate.setTheoremName("Test Update");
|
||||
final Proof updatedProof = existingProof;
|
||||
updatedProof.setTheoremName("Test Update");
|
||||
when(proofRepository.findById(anyInt())).thenReturn(Optional.of(existingProof));
|
||||
when(proofRepository.save(any(Proof.class))).thenReturn(updatedProof);
|
||||
|
||||
final ResponseEntity<Proof> responseEntity = proofController.updateProof(1, proofUpdate, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(updatedProof, responseEntity.getBody());
|
||||
verify(proofRepository).findById(anyInt());
|
||||
verify(proofRepository).save(any(Proof.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProof_bindingResultHasErrors() {
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity<Proof> responseEntity = proofController.updateProof(1, createProof(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProof_proofDtoIsNull() {
|
||||
final ResponseEntity<Proof> responseEntity = proofController.updateProof(1, null, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProof_idIsNull() {
|
||||
final ResponseEntity<Proof> responseEntity = proofController.updateProof(null, createProof(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProof_theoremDoesNotExist() {
|
||||
when(proofRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity<Proof> responseEntity = proofController.updateProof(1, createProof(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verify(proofRepository, times(0)).save(any(Proof.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProofById() {
|
||||
doNothing().when(proofRepository).deleteById(anyInt());
|
||||
|
||||
final ResponseEntity responseEntity = proofController.deleteProofById(1);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
|
||||
verify(proofRepository).deleteById(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProofById_idIsNull() {
|
||||
final ResponseEntity responseEntity = proofController.deleteProofById(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(proofRepository);
|
||||
}
|
||||
|
||||
private Proof createProof() {
|
||||
final List<String> referencedTheoremsList = new ArrayList<>();
|
||||
referencedTheoremsList.add("test theorem 1");
|
||||
referencedTheoremsList.add("test theorem 2");
|
||||
|
||||
final List<String> referencedDefinitionsList = new ArrayList<>();
|
||||
referencedDefinitionsList.add("test definition 1");
|
||||
referencedDefinitionsList.add("test definition 2");
|
||||
|
||||
final Proof proof = new Proof();
|
||||
proof.setTheoremName("Test proof");
|
||||
proof.setTheorem(1);
|
||||
proof.setBranch("Test branch");
|
||||
proof.setProof("test proof");
|
||||
proof.setDateCreated(new Date());
|
||||
proof.setReferencedTheorems(referencedTheoremsList);
|
||||
proof.setReferencedDefinitions(referencedDefinitionsList);
|
||||
|
||||
return proof;
|
||||
}
|
||||
}
|
||||
+95
-45
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.controller;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dto.TheoremDto;
|
||||
import edu.msudenver.tsp.persistence.dto.Theorem;
|
||||
import edu.msudenver.tsp.persistence.dto.TheoremType;
|
||||
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
||||
import org.junit.Test;
|
||||
@@ -32,14 +32,14 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllTheorems() {
|
||||
final TheoremDto theoremDto = createTheorem();
|
||||
final List<TheoremDto> listOfTheorems = new ArrayList<>();
|
||||
final Theorem theoremDto = createTheorem();
|
||||
final List<Theorem> listOfTheorems = new ArrayList<>();
|
||||
listOfTheorems.add(theoremDto);
|
||||
listOfTheorems.add(theoremDto);
|
||||
|
||||
when(theoremRepository.findAll()).thenReturn(listOfTheorems);
|
||||
|
||||
final ResponseEntity<Iterable<TheoremDto>> responseEntity = theoremController.getAllTheorems();
|
||||
final ResponseEntity<Iterable<Theorem>> responseEntity = theoremController.getAllTheorems();
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
@@ -51,16 +51,16 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetTheoremById() {
|
||||
final TheoremDto theoremDto = createTheorem();
|
||||
when(theoremRepository.findById(anyInt())).thenReturn(Optional.ofNullable(theoremDto));
|
||||
final Theorem theorem = createTheorem();
|
||||
when(theoremRepository.findById(anyInt())).thenReturn(Optional.ofNullable(theorem));
|
||||
|
||||
final ResponseEntity<TheoremDto> responseEntity = theoremController.getTheoremById(1);
|
||||
final ResponseEntity<Theorem> responseEntity = theoremController.getTheoremById(1);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(theoremDto, responseEntity.getBody());
|
||||
assertEquals(theorem, responseEntity.getBody());
|
||||
verify(theoremRepository).findById(anyInt());
|
||||
}
|
||||
|
||||
@@ -88,14 +88,14 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByBranch() {
|
||||
final TheoremDto theoremDto = createTheorem();
|
||||
final List<TheoremDto> listOfTheorems = new ArrayList<>();
|
||||
final Theorem theoremDto = createTheorem();
|
||||
final List<Theorem> listOfTheorems = new ArrayList<>();
|
||||
listOfTheorems.add(theoremDto);
|
||||
listOfTheorems.add(theoremDto);
|
||||
|
||||
when(theoremRepository.findByBranch(anyString())).thenReturn(listOfTheorems);
|
||||
|
||||
final ResponseEntity<List<TheoremDto>> responseEntity = theoremController.getAllTheoremsByBranch("test");
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByBranch("test-branch");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
@@ -107,7 +107,7 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByBranch_nullBranch() {
|
||||
final ResponseEntity<List<TheoremDto>> responseEntity = theoremController.getAllTheoremsByBranch(null);
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByBranch(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -119,7 +119,7 @@ public class TheoremControllerTest {
|
||||
public void testGetAllTheoremsByBranch_noTheoremsFound() {
|
||||
when(theoremRepository.findByBranch(anyString())).thenReturn(Collections.emptyList());
|
||||
|
||||
final ResponseEntity<List<TheoremDto>> responseEntity = theoremController.getAllTheoremsByBranch("test nonexistent branch");
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByBranch("test_nonexistent_branch");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -128,14 +128,14 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByProvenStatus() {
|
||||
final TheoremDto theoremDto = createTheorem();
|
||||
final List<TheoremDto> listOfTheorems = new ArrayList<>();
|
||||
final Theorem theoremDto = createTheorem();
|
||||
final List<Theorem> listOfTheorems = new ArrayList<>();
|
||||
listOfTheorems.add(theoremDto);
|
||||
listOfTheorems.add(theoremDto);
|
||||
|
||||
when(theoremRepository.findByProvenStatus(anyBoolean())).thenReturn(listOfTheorems);
|
||||
|
||||
final ResponseEntity<List<TheoremDto>> responseEntity = theoremController.getAllTheoremsByProvenStatus(true);
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("true");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
@@ -147,7 +147,7 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByProvenStatus_nullProvenStatus() {
|
||||
final ResponseEntity<List<TheoremDto>> responseEntity = theoremController.getAllTheoremsByProvenStatus(null);
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -155,11 +155,60 @@ 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<TheoremDto>> responseEntity = theoremController.getAllTheoremsByProvenStatus(false);
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("false");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByName() {
|
||||
final Theorem theoremDto = createTheorem();
|
||||
final List<Theorem> listOfTheorems = new ArrayList<>();
|
||||
listOfTheorems.add(theoremDto);
|
||||
listOfTheorems.add(theoremDto);
|
||||
|
||||
when(theoremRepository.findByName(anyString())).thenReturn(listOfTheorems);
|
||||
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByName("Test_Theorem");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
|
||||
responseEntity.getBody().forEach(theorem -> assertEquals(theoremDto, theorem));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByName_nullName() {
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByName(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(theoremRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTheoremsByName_noNameFound() {
|
||||
when(theoremRepository.findByName(anyString())).thenReturn(Collections.emptyList());
|
||||
|
||||
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByName("No-name");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -168,17 +217,17 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testInsertTheorem() {
|
||||
final TheoremDto theoremDto = createTheorem();
|
||||
when(theoremRepository.save(any(TheoremDto.class))).thenReturn(theoremDto);
|
||||
final Theorem theorem = createTheorem();
|
||||
when(theoremRepository.save(any(Theorem.class))).thenReturn(theorem);
|
||||
|
||||
final ResponseEntity<TheoremDto> responseEntity = theoremController.insertTheorem(theoremDto, bindingResult);
|
||||
final ResponseEntity<Theorem> responseEntity = theoremController.insertTheorem(theorem, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||
assertEquals(theoremDto, responseEntity.getBody());
|
||||
verify(theoremRepository).save(any(TheoremDto.class));
|
||||
assertEquals(theorem, responseEntity.getBody());
|
||||
verify(theoremRepository).save(any(Theorem.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,10 +242,10 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testInsertTheorem_bindingResultHasErrors() {
|
||||
final TheoremDto theoremDto = createTheorem();
|
||||
final Theorem theorem = createTheorem();
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity responseEntity = theoremController.insertTheorem(theoremDto, bindingResult);
|
||||
final ResponseEntity responseEntity = theoremController.insertTheorem(theorem, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -206,31 +255,31 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateTheorem() {
|
||||
final TheoremDto existingTheorem = createTheorem();
|
||||
final Theorem existingTheorem = createTheorem();
|
||||
existingTheorem.setId(1);
|
||||
existingTheorem.setVersion(1);
|
||||
final TheoremDto theoremUpdate = new TheoremDto();
|
||||
final Theorem theoremUpdate = new Theorem();
|
||||
theoremUpdate.setName("Test Update");
|
||||
final TheoremDto updatedTheorem = existingTheorem;
|
||||
final Theorem updatedTheorem = existingTheorem;
|
||||
updatedTheorem.setName("Test Update");
|
||||
when(theoremRepository.findById(anyInt())).thenReturn(Optional.of(existingTheorem));
|
||||
when(theoremRepository.save(any(TheoremDto.class))).thenReturn(updatedTheorem);
|
||||
when(theoremRepository.save(any(Theorem.class))).thenReturn(updatedTheorem);
|
||||
|
||||
final ResponseEntity<TheoremDto> responseEntity = theoremController.updateTheorem(1, theoremUpdate, bindingResult);
|
||||
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(1, theoremUpdate, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(updatedTheorem, responseEntity.getBody());
|
||||
verify(theoremRepository).findById(anyInt());
|
||||
verify(theoremRepository).save(any(TheoremDto.class));
|
||||
verify(theoremRepository).save(any(Theorem.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTheorem_bindingResultHasErrors() {
|
||||
when(bindingResult.hasErrors()).thenReturn(true);
|
||||
|
||||
final ResponseEntity<TheoremDto> responseEntity = theoremController.updateTheorem(1, createTheorem(), bindingResult);
|
||||
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(1, createTheorem(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -240,7 +289,7 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateTheorem_theoremDtoIsNull() {
|
||||
final ResponseEntity<TheoremDto> responseEntity = theoremController.updateTheorem(1, null, bindingResult);
|
||||
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(1, null, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -250,7 +299,7 @@ public class TheoremControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateTheorem_idIsNull() {
|
||||
final ResponseEntity<TheoremDto> responseEntity = theoremController.updateTheorem(null, createTheorem(), bindingResult);
|
||||
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(null, createTheorem(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
@@ -262,12 +311,12 @@ public class TheoremControllerTest {
|
||||
public void testUpdateTheorem_theoremDoesNotExist() {
|
||||
when(theoremRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity<TheoremDto> responseEntity = theoremController.updateTheorem(1, createTheorem(), bindingResult);
|
||||
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(1, createTheorem(), bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verify(theoremRepository, times(0)).save(any(TheoremDto.class));
|
||||
verify(theoremRepository, times(0)).save(any(Theorem.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -292,7 +341,7 @@ public class TheoremControllerTest {
|
||||
verifyZeroInteractions(theoremRepository);
|
||||
}
|
||||
|
||||
private TheoremDto createTheorem() {
|
||||
private Theorem createTheorem() {
|
||||
final List<String> referencedTheoremsList = new ArrayList<>();
|
||||
referencedTheoremsList.add("test theorem 1");
|
||||
referencedTheoremsList.add("test theorem 2");
|
||||
@@ -301,14 +350,15 @@ public class TheoremControllerTest {
|
||||
referencedDefinitionsList.add("test definition 1");
|
||||
referencedDefinitionsList.add("test definition 2");
|
||||
|
||||
final TheoremDto theoremDto = new TheoremDto();
|
||||
theoremDto.setName("Test theorem");
|
||||
theoremDto.setBranch("Test branch");
|
||||
theoremDto.setProvenStatus(true);
|
||||
theoremDto.setTheoremType(TheoremType.THEOREM);
|
||||
theoremDto.setReferencedTheorems(referencedTheoremsList);
|
||||
theoremDto.setReferencedDefinitions(referencedDefinitionsList);
|
||||
final Theorem theorem = new Theorem();
|
||||
theorem.setName("Test theorem");
|
||||
theorem.setTheorem("test theorem thing here");
|
||||
theorem.setBranch("Test branch");
|
||||
theorem.setProvenStatus(true);
|
||||
theorem.setTheoremType(TheoremType.THEOREM);
|
||||
theorem.setReferencedTheorems(referencedTheoremsList);
|
||||
theorem.setReferencedDefinitions(referencedDefinitionsList);
|
||||
|
||||
return theoremDto;
|
||||
return theorem;
|
||||
}
|
||||
}
|
||||
@@ -24,5 +24,7 @@ dependencies {
|
||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
|
||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
||||
|
||||
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile group: 'org.springframework', name: 'spring-test', version: '5.1.5.RELEASE'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
public class ServicesTestConfig {
|
||||
|
||||
@Bean
|
||||
@Autowired
|
||||
public UserService userService(final RestService restService) {
|
||||
return new UserService(restService);
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import edu.msudenver.tsp.services.dto.Account;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = ServicesTestConfig.class)
|
||||
@TestPropertySource("classpath:test.properties")
|
||||
public class UserServiceIntegrationTest {
|
||||
@Autowired
|
||||
@Qualifier("userService")
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void testUserService(){
|
||||
final Account testAccount = createAccount();
|
||||
|
||||
final Optional<Account> testCreatedAccount = userService.createAccount(testAccount);
|
||||
assertTrue(testCreatedAccount.isPresent());
|
||||
final Account returnedAccount = testCreatedAccount.get();
|
||||
assertEquals("test_user", returnedAccount.getUsername());
|
||||
assertEquals("test_password", returnedAccount.getPassword());
|
||||
assertFalse(returnedAccount.isAdministratorStatus());
|
||||
|
||||
final Optional<Account> getAccountById = userService.findAccountById(returnedAccount.getId());
|
||||
assertTrue(getAccountById.isPresent());
|
||||
final Account returnedAccountById = getAccountById.get();
|
||||
assertEquals("test_user", returnedAccountById.getUsername());
|
||||
assertEquals("test_password", returnedAccountById.getPassword());
|
||||
assertFalse(returnedAccountById.isAdministratorStatus());
|
||||
|
||||
final Optional<Account> getAccountByUsername = userService.findAccountByUsername(returnedAccount.getUsername());
|
||||
assertTrue(getAccountByUsername.isPresent());
|
||||
final Account returnedAccountByUsername = getAccountByUsername.get();
|
||||
assertEquals("test_user", returnedAccountByUsername.getUsername());
|
||||
assertEquals("test_password", returnedAccountByUsername.getPassword());
|
||||
assertFalse(returnedAccountById.isAdministratorStatus());
|
||||
|
||||
returnedAccount.setUsername("test_updatedUser");
|
||||
returnedAccount.setPassword("test_updatedPassword");
|
||||
|
||||
final Optional<Account> updatedAccount = userService.updateAccount(returnedAccount);
|
||||
assertTrue(updatedAccount .isPresent());
|
||||
final Account returnedUpdatedAccount = updatedAccount.get();
|
||||
assertEquals("test_updatedUser", returnedUpdatedAccount.getUsername());
|
||||
assertEquals("test_updatedPassword", returnedUpdatedAccount.getPassword());
|
||||
assertFalse(returnedUpdatedAccount.isAdministratorStatus());
|
||||
|
||||
final boolean result = userService.deleteAccount(returnedUpdatedAccount);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
private Account createAccount() {
|
||||
final Account testAccount = new Account();
|
||||
testAccount.setUsername("test_user");
|
||||
testAccount.setPassword("test_password");
|
||||
testAccount.setAdministratorStatus(false);
|
||||
testAccount.setLastLogin(new Date());
|
||||
|
||||
return testAccount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
persistence.api.connection.timeout.milliseconds=5000
|
||||
persistence.api.socket.timeout.milliseconds=10000
|
||||
persistence.api.base.url=http://localhost:8090/
|
||||
@@ -53,6 +53,11 @@ public class RestService {
|
||||
return send(requestFactory.put(uri, requestJson), auth, connectionTimeout, socketTimeout, type);
|
||||
}
|
||||
|
||||
<T> Optional<T> patch(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout) {
|
||||
LOG.info("Sending PATCH {} with body: {}", uri, requestJson);
|
||||
return send(requestFactory.patch(uri, requestJson), null, connectionTimeout, socketTimeout, type);
|
||||
}
|
||||
|
||||
private <T> Optional<T> send(final Request request, final String auth, final Integer connectionTimeout, final Integer socketTimeout, final TypeToken<T> type) {
|
||||
try {
|
||||
final Optional<HttpResponse> optionalHttpResponse = send(request, auth, connectionTimeout, socketTimeout);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration(exclude = {DevToolsDataSourceAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class,
|
||||
DataSourceAutoConfiguration.class})
|
||||
public class ServiceConfig {
|
||||
}
|
||||
@@ -6,10 +6,12 @@ import edu.msudenver.tsp.services.dto.Account;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@@ -25,7 +27,96 @@ public class UserService {
|
||||
this.restService = restService;
|
||||
}
|
||||
|
||||
public Optional<Account> createNewAccount(final Account account) {
|
||||
public Optional<List<Account>> getListOfAccounts() {
|
||||
final Instant start = Instant.now();
|
||||
|
||||
try {
|
||||
final TypeToken<List<Account>> typeToken = new TypeToken<List<Account>>() {};
|
||||
final Optional<List<Account>> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "accounts/",
|
||||
typeToken,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds,
|
||||
null);
|
||||
|
||||
if (persistenceApiResponse.isPresent()) {
|
||||
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||
} else {
|
||||
LOG.warn("Unable to get the list of accounts");
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Error getting the list of accounts", e);
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
LOG.info("Get the list of accounts request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Account> findAccountById(final int id) {
|
||||
|
||||
if (id == 0) {
|
||||
LOG.error("No user ID specified! Returning {}");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final Instant start = Instant.now();
|
||||
|
||||
try {
|
||||
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||
final Optional<Account> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "accounts/id?id=" + id,
|
||||
typeToken,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds,
|
||||
null);
|
||||
|
||||
if (persistenceApiResponse.isPresent()) {
|
||||
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||
} else {
|
||||
LOG.warn("Unable to find account with id {}", id);
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Error finding account by id", e);
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
LOG.info("Find account by ID request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Account> findAccountByUsername(final String username) {
|
||||
if (username == null) {
|
||||
LOG.error("No username specified! Returning {}");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final Instant start = Instant.now();
|
||||
|
||||
try {
|
||||
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||
final Optional<Account> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "accounts/username?username=" + username,
|
||||
typeToken,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds,
|
||||
null);
|
||||
|
||||
if (persistenceApiResponse.isPresent()) {
|
||||
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||
} else {
|
||||
LOG.warn("Unable to GET account with username {}", username);
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Error finding account by username", e);
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
LOG.info("Find account by username request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Account> createAccount(final Account account) {
|
||||
if (account == null) {
|
||||
LOG.error("Given null account, returning {}");
|
||||
return Optional.empty();
|
||||
@@ -34,8 +125,8 @@ public class UserService {
|
||||
|
||||
try {
|
||||
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||
final Optional<Account> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "/accounts/",
|
||||
new GsonBuilder().create().toJson(account),
|
||||
final Optional<Account> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "accounts/",
|
||||
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create().toJson(account),
|
||||
typeToken,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds);
|
||||
@@ -43,15 +134,88 @@ public class UserService {
|
||||
if (persistenceApiResponse.isPresent()) {
|
||||
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||
} else {
|
||||
LOG.info("Unable to create new account {}", account.toString());
|
||||
LOG.warn("Unable to create new account {}", account.toString());
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Error creating new account {}", e);
|
||||
LOG.error("Error creating new account", e);
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
LOG.info("Create new account request took {} ms", Duration.between(start, Instant.now()).toMillis());
|
||||
LOG.info("Create new account request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Account> updateAccount(final Account account) {
|
||||
if (account == null) {
|
||||
LOG.error("Specified account is null; returning {}");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
if (account.getId() == 0) {
|
||||
LOG.error("No user ID specified! Returning {}");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final int id = account.getId();
|
||||
final Instant start = Instant.now();
|
||||
|
||||
try {
|
||||
final TypeToken<Account> typeToken = new TypeToken<Account>(){};
|
||||
final Optional<Account> persistenceApiResponse = restService.patch(persistenceApiBaseUrl + "accounts/" + id,
|
||||
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create().toJson(account),
|
||||
typeToken,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds);
|
||||
|
||||
if (persistenceApiResponse.isPresent()) {
|
||||
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||
} else {
|
||||
LOG.warn("Unable to update user with id {}", account.getId());
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Error updating user", e);
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
LOG.info("Update user request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean deleteAccount(final Account account) {
|
||||
if (account == null){
|
||||
LOG.error("Specified account is null; returning {}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.getId() == 0) {
|
||||
LOG.error("No user ID specified! Returning {}");
|
||||
return false;
|
||||
}
|
||||
|
||||
final int id = account.getId();
|
||||
final Instant start = Instant.now();
|
||||
|
||||
try {
|
||||
|
||||
final boolean persistenceApiResponse = restService.delete(persistenceApiBaseUrl + "accounts/" + id,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds, HttpStatus.NO_CONTENT);
|
||||
if (persistenceApiResponse) {
|
||||
LOG.info("Returning {}", persistenceApiResponse);
|
||||
}
|
||||
else {
|
||||
LOG.error("Unable to delete user {}", account);
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
}catch (final Exception e) {
|
||||
LOG.error("Error deleting user", e);
|
||||
return false;
|
||||
} finally {
|
||||
LOG.info("Delete user request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package edu.msudenver.tsp.services.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Account extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = AccountDto.Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
||||
@NotBlank(groups = AccountDto.Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
||||
@Size(max = 50) private String username;
|
||||
@Size(max = 256) private String password;
|
||||
@NotNull @SerializedName("administrator_status") private boolean administratorStatus;
|
||||
@Temporal(TemporalType.DATE) @SerializedName("last_login") private Date lastLogin;
|
||||
|
||||
private static final long serialVersionUID = 7095627971593953734L;
|
||||
|
||||
}
|
||||
|
||||
@@ -22,4 +22,8 @@ public class RequestFactory {
|
||||
public Request put(final String uri, final String requestJson) {
|
||||
return StringUtils.isNotBlank(requestJson) ? Request.Put(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Put(uri);
|
||||
}
|
||||
|
||||
public Request patch(final String uri, final String requestJson) {
|
||||
return StringUtils.isNotBlank(requestJson) ? Request.Patch(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Patch(uri);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,24 @@
|
||||
package edu.msudenver.tsp.services.parser;
|
||||
|
||||
import edu.msudenver.tsp.persistence.controller.DefinitionController;
|
||||
import edu.msudenver.tsp.persistence.controller.NotationController;
|
||||
import edu.msudenver.tsp.persistence.controller.ProofController;
|
||||
import edu.msudenver.tsp.persistence.controller.TheoremController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
class ParserService {
|
||||
private final DefinitionController definitionController;
|
||||
private final TheoremController theoremController;
|
||||
private final NotationController notationController;
|
||||
private final ProofController proofController;
|
||||
private Node root;
|
||||
|
||||
@Autowired
|
||||
public ParserService(final DefinitionController definitionController, final TheoremController theoremController,
|
||||
final NotationController notationController, final ProofController proofController) {
|
||||
this.definitionController = definitionController;
|
||||
this.theoremController = theoremController;
|
||||
this.notationController = notationController;
|
||||
this.proofController = proofController;
|
||||
}
|
||||
|
||||
public boolean parseUserInput(final String userInput)
|
||||
{
|
||||
try {
|
||||
final Node tree = parseRawInput(userInput);
|
||||
final List<String> statements = retrieveStatements(tree);
|
||||
retrieveStatements(tree);
|
||||
|
||||
return true;
|
||||
} catch(final Exception e) {
|
||||
e.printStackTrace();
|
||||
LOG.error(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -44,7 +27,7 @@ class ParserService {
|
||||
{
|
||||
input = input.toLowerCase();
|
||||
|
||||
root = new Node(input, null);
|
||||
final Node root = new Node(input, null);
|
||||
|
||||
if(input.equals(""))
|
||||
{
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package edu.msudenver.tsp.services.scoring;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
//@PropertySource("classpath:development.properties")
|
||||
public class ScoringConfig {
|
||||
|
||||
@Bean
|
||||
public TheoremScoringService theoremScoringService() {
|
||||
return new TheoremScoringService();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package edu.msudenver.tsp.services.scoring;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
class TheoremScoringService {
|
||||
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
persistence.api.connection.timeout.milliseconds = 5000
|
||||
persistence.api.socket.timeout.milliseconds = 10000
|
||||
persistence.api.base.url = http://localhost:8090/
|
||||
persistence.api.connection.timeout.milliseconds=5000
|
||||
persistence.api.socket.timeout.milliseconds=10000
|
||||
persistence.api.base.url=http://localhost:8090/
|
||||
@@ -0,0 +1,313 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import edu.msudenver.tsp.services.dto.Account;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UserServiceTest {
|
||||
@Mock private RestService restService;
|
||||
@InjectMocks private UserService userService;
|
||||
|
||||
@Test
|
||||
public void testGetListOfAccounts() {
|
||||
final List<Account> accountList = new ArrayList<>();
|
||||
accountList.add(createAccount());
|
||||
accountList.add(createAccount());
|
||||
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(), anyString())).thenReturn(Optional.of(accountList));
|
||||
|
||||
final Optional<List<Account>> response = userService.getListOfAccounts();
|
||||
|
||||
assertTrue(response.isPresent());
|
||||
assertEquals(accountList, response.get());
|
||||
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetListOfAccounts_PersistenceApiResponseIsEmpty() {
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.empty());
|
||||
|
||||
final Optional<List<Account>> response = userService.getListOfAccounts();
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetListOfAccounts_RestServiceThrowsException() {
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenThrow(Exception.class);
|
||||
|
||||
final Optional<List<Account>> response = userService.getListOfAccounts();
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountById() {
|
||||
final Account account = createAccount();
|
||||
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.of(account));
|
||||
|
||||
final Optional<Account> response = userService.findAccountById(1);
|
||||
|
||||
assertTrue(response.isPresent());
|
||||
assertEquals(account, response.get());
|
||||
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountById_IdEqualsZero() {
|
||||
final Optional<Account> response = userService.findAccountById(0);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
assertEquals(Optional.empty(), response);
|
||||
verifyZeroInteractions(restService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountById_PersistenceApiResponseIsEmpty() {
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.empty());
|
||||
|
||||
final Optional<Account> response = userService.findAccountById(1);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountById_RestServiceThrowsException() {
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenThrow(Exception.class);
|
||||
|
||||
final Optional<Account> response = userService.findAccountById(1);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountByUsername() {
|
||||
final Account account = createAccount();
|
||||
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.of(account));
|
||||
|
||||
final Optional<Account> response = userService.findAccountByUsername(account.getUsername());
|
||||
|
||||
assertTrue(response.isPresent());
|
||||
assertEquals(account, response.get());
|
||||
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountByUsername_NullUsername() {
|
||||
final Optional<Account> response = userService.findAccountByUsername(null);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
assertEquals(Optional.empty(), response);
|
||||
verifyZeroInteractions(restService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountByUsername_PersistenceApiResponseIsEmpty() {
|
||||
final Account account = createAccount();
|
||||
|
||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.empty());
|
||||
|
||||
final Optional<Account> response = userService.findAccountByUsername(account.getUsername());
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAccountByUsername_RestServiceThrowsException() {
|
||||
when(restService.get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString())).thenThrow(Exception.class);
|
||||
|
||||
final Optional<Account> response = userService.findAccountByUsername("test");
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAccount() {
|
||||
final Account account = createAccount();
|
||||
|
||||
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.of(account));
|
||||
|
||||
final Optional<Account> response = userService.createAccount(account);
|
||||
|
||||
assertTrue(response.isPresent());
|
||||
assertEquals(account, response.get());
|
||||
verify(restService).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAccount_NullAccount() {
|
||||
final Optional<Account> response = userService.createAccount(null);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
assertEquals(Optional.empty(), response);
|
||||
verify(restService, times(0)).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAccount_AccountCouldNotBeCreated() {
|
||||
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.empty());
|
||||
|
||||
final Optional<Account> response = userService.createAccount(createAccount());
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAccount_RestServiceThrowsException() {
|
||||
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenThrow(Exception.class);
|
||||
|
||||
final Optional<Account> response = userService.createAccount(createAccount());
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount() {
|
||||
final Account account = createAccount();
|
||||
account.setId(1);
|
||||
|
||||
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.of(account));
|
||||
|
||||
final Optional<Account> response = userService.updateAccount(account);
|
||||
|
||||
assertTrue(response.isPresent());
|
||||
assertEquals(account, response.get());
|
||||
verify(restService).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount_NullAccount() {
|
||||
final Optional<Account> response = userService.updateAccount(null);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verifyZeroInteractions(restService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount_IdEqualsZero() {
|
||||
final Account account = createAccount();
|
||||
account.setId(0);
|
||||
|
||||
final Optional<Account> response = userService.updateAccount(account);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verifyZeroInteractions(restService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount_PersistenceApiResponseIsEmpty() {
|
||||
final Account account = createAccount();
|
||||
account.setId(1);
|
||||
|
||||
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.empty());
|
||||
|
||||
final Optional<Account> response = userService.updateAccount(account);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccount_RestServiceThrowsException() {
|
||||
final Account account = createAccount();
|
||||
account.setId(1);
|
||||
|
||||
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenThrow(Exception.class);
|
||||
|
||||
final Optional<Account> response = userService.updateAccount(account);
|
||||
|
||||
assertFalse(response.isPresent());
|
||||
verify(restService).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAccount() {
|
||||
final Account account = createAccount();
|
||||
account.setId(1);
|
||||
|
||||
when(restService.delete(anyString(), anyInt(), anyInt(), any())).thenReturn(true);
|
||||
|
||||
final boolean isDeleteSuccessful = userService.deleteAccount(account);
|
||||
|
||||
assertTrue(isDeleteSuccessful);
|
||||
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAccount_NullAccount() {
|
||||
final boolean isDeleteSuccessful = userService.deleteAccount(null);
|
||||
|
||||
assertFalse(isDeleteSuccessful);
|
||||
verifyZeroInteractions(restService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAccount_IdEqualsZero() {
|
||||
final Account account = createAccount();
|
||||
account.setId(0);
|
||||
|
||||
final boolean isDeleteSuccessful = userService.deleteAccount(account);
|
||||
|
||||
assertFalse(isDeleteSuccessful);
|
||||
verifyZeroInteractions(restService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAccount_PersistenceApiResponseIsEmpty() {
|
||||
final Account account = createAccount();
|
||||
account.setId(1);
|
||||
|
||||
when(restService.delete(anyString(), anyInt(), anyInt(), any())).thenReturn(false);
|
||||
|
||||
final boolean isDeleteSuccessful = userService.deleteAccount(account);
|
||||
|
||||
assertFalse(isDeleteSuccessful);
|
||||
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAccount_RestServiceThrowsException() {
|
||||
final Account account = createAccount();
|
||||
account.setId(1);
|
||||
|
||||
when(restService.delete(anyString(), anyInt(), anyInt(), any())).thenThrow(Exception.class);
|
||||
|
||||
final boolean persistenceApiResponse = userService.deleteAccount(account);
|
||||
|
||||
assertFalse(persistenceApiResponse);
|
||||
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
|
||||
private Account createAccount() {
|
||||
final Account account = new Account();
|
||||
account.setUsername("Test username");
|
||||
account.setPassword("test password");
|
||||
account.setAdministratorStatus(true);
|
||||
account.setLastLogin(new Date());
|
||||
return account;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package edu.msudenver.tsp.services.factory;
|
||||
|
||||
import org.apache.http.client.fluent.Request;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class RequestFactoryTest {
|
||||
private final RequestFactory requestFactory = new RequestFactory();
|
||||
|
||||
@Test
|
||||
public void testDelete() {
|
||||
final Request testRequest = requestFactory.delete("testUri");
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet() {
|
||||
final Request testRequest = requestFactory.get("testUri");
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost() {
|
||||
final Request testRequest = requestFactory.post("testUri", "testJson");
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_blankRequestJson() {
|
||||
final Request testRequest = requestFactory.post("testUri", null);
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPut() {
|
||||
final Request testRequest = requestFactory.put("testUri", "testJson");
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPut_blankRequestJson() {
|
||||
final Request testRequest = requestFactory.put("testUri", null);
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch() {
|
||||
final Request testRequest = requestFactory.patch("testUri", "testJson");
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_blankRequestJson() {
|
||||
final Request testRequest = requestFactory.patch("testUri", null);
|
||||
|
||||
assertNotNull(testRequest);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package edu.msudenver.tsp.services.parser;
|
||||
|
||||
import edu.msudenver.tsp.persistence.controller.DefinitionController;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -12,18 +12,13 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ParserServiceTest {
|
||||
|
||||
private final DefinitionController definitionControllerMock = mock(DefinitionController.class);
|
||||
private final ParserService mockParserService = mock(ParserService.class);
|
||||
|
||||
@InjectMocks
|
||||
private final ParserService parserService = new ParserService(definitionControllerMock, null,
|
||||
null, null);
|
||||
@Mock private ParserService mockParserService;
|
||||
@InjectMocks private ParserService parserService;
|
||||
|
||||
@Test
|
||||
public void testEmptyStringEqualsEmptyString() {
|
||||
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package edu.msudenver.tsp.services.scoring;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TheoremScoringServiceTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertEquals(3,3);
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,9 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package edu.msudenver.tsp.website.controller;
|
||||
|
||||
import edu.msudenver.tsp.website.controller.forms.Theorem;
|
||||
import edu.msudenver.tsp.website.forms.TheoremForm;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -9,7 +9,6 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Slf4j
|
||||
@@ -18,16 +17,16 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
@RequestMapping("/theorem")
|
||||
public class TheoremEntryController {
|
||||
@GetMapping({"/",""})
|
||||
public ModelAndView enterTheoremPage()
|
||||
{
|
||||
public ModelAndView enterTheoremPage() {
|
||||
LOG.info("Received request to display the theorem entry page: returning model with name 'Theorem'");
|
||||
return new ModelAndView("Theorem");
|
||||
}
|
||||
|
||||
@PostMapping({"/",""})
|
||||
public String saveTheorem(@Validated Theorem theorem, Model model) {
|
||||
|
||||
model.addAttribute("theromName1", theorem.getTheoremName1());
|
||||
model.addAttribute("theromName2", theorem.getTheoremName2());
|
||||
public String saveTheorem(@Validated final TheoremForm theoremForm, final Model model) {
|
||||
model.addAttribute("theoremName", theoremForm.getTheoremName());
|
||||
model.addAttribute("theorem", theoremForm.getTheorem());
|
||||
LOG.info("Saving theorem {}...", theoremForm);
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package edu.msudenver.tsp.website.controller.forms;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Theorem {
|
||||
private String theoremName1 ;
|
||||
private String theoremName2 ;
|
||||
|
||||
// @NotBlank(message = "Theorem name must not be blank") private String theoremName;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package edu.msudenver.tsp.website.forms;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TheoremForm {
|
||||
private String theoremName;
|
||||
private String theorem;
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
<%@ page contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Theorem Page</title>
|
||||
@@ -13,4 +14,20 @@ Enter Theorem Name : <input type="text" name="theoremName1">
|
||||
<input type="submit" value="save">
|
||||
</form>
|
||||
</body>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Theorem Entry</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="">
|
||||
<label>Theorem Name:
|
||||
<input type="text" name="theoremName"/>
|
||||
</label>
|
||||
<br><label>Theorem:
|
||||
<input type="text" name="theorem"/>
|
||||
</label><br>
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: atusa
|
||||
Date: 2/1/19
|
||||
Time: 8:03 PM
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
|
||||
|
||||
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Pandamonium™ Theorem Prover</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<h1>Theorem Prover</h1>
|
||||
<h2>Hello! Welcome to Pandamonium™ Theorem Prover!!</h2>
|
||||
|
||||
Click on this <strong><a href="/theorem/">link</a></strong> to visit theorem entering page.
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
<br><b>Name:</b><%= request.getParameter("theoremName1")%>
|
||||
<br><b>Name:</b><%= request.getParameter("theoremName2")%>
|
||||
<body>
|
||||
<br><b>Name: </b><%= request.getParameter("theoremName")%>
|
||||
<br><b>Theorem: </b><%= request.getParameter("theorem")%>
|
||||
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,16 +0,0 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: atusa
|
||||
Date: 2/1/19
|
||||
Time: 8:03 PM
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>abc</title>
|
||||
</head>
|
||||
<body>
|
||||
$END$
|
||||
</body>
|
||||
</html>
|
||||
+11
-23
@@ -2,44 +2,32 @@ package edu.msudenver.tsp.website.controller;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TheoremEntryControllerTest {
|
||||
|
||||
@InjectMocks
|
||||
private TheoremEntryController theoremEntryController;
|
||||
private final TheoremEntryController theoremEntryController = new TheoremEntryController();
|
||||
|
||||
@Test
|
||||
public void theoremPage(){
|
||||
|
||||
final ModelAndView modelAndView= theoremEntryController.enterTheoremPage();
|
||||
|
||||
assertNotNull(modelAndView);
|
||||
assertEquals("Theorem",modelAndView.getViewName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveTheorem(){
|
||||
|
||||
final ModelAndView modelAndView= theoremEntryController.enterTheoremPage();
|
||||
|
||||
@Test
|
||||
public void testEnterTheoremPage() {
|
||||
final ModelAndView modelAndView = theoremEntryController.enterTheoremPage();
|
||||
|
||||
|
||||
assertNotNull(modelAndView);
|
||||
assertEquals("Theorem",modelAndView.getViewName());
|
||||
assertEquals("Theorem", modelAndView.getViewName());
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user