Compare commits
123 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de5a69d619 | ||
| 296cf62be6 | |||
| f5dbdac990 | |||
| c9a2a978fc | |||
| d0cde837e9 | |||
| 07cdef3d44 | |||
| ab360abcf8 | |||
| 4622c49cee | |||
| f8a1d8bf89 | |||
| ba4c7502db | |||
| 1e15082fcc | |||
| 6b7cf5cd91 | |||
| 413a78f729 | |||
| 80f55c4879 | |||
|
|
ae15ec8073 | ||
| 8c79d9975e | |||
| 749a20c0fd | |||
|
|
b15ef858b0 | ||
|
|
5479130178 | ||
|
|
f0cb7633c6 | ||
|
|
9f5d9e24f5 | ||
| 7b2d5c45a6 | |||
| a84e6c6ab7 | |||
| 9700eb55ab | |||
| 7548ca64d0 | |||
| 6197beb309 | |||
| 6009720d80 | |||
| c90f5b6e09 | |||
| a13ab97154 | |||
| a85bf67d08 | |||
| 1de1f7a5fc | |||
| 2c03c75938 | |||
| 52a21e72f3 | |||
|
|
4b866017a1 | ||
|
|
bd7455c679 | ||
|
|
150933b22b | ||
|
|
0afe995950 | ||
|
|
401383f5da | ||
|
|
b5f1590142 | ||
|
|
c45c0a6108 | ||
|
|
139dc943c3 | ||
| 4d0658a268 | |||
| d560f5831f | |||
| 7af41d4235 | |||
| 4bd1936a7a | |||
| bc92dc60d4 | |||
|
|
fe0912fc24 | ||
| 3483a2dd2c | |||
| d19cb5a989 | |||
| 47dd67623e | |||
| 64dd8397cc | |||
| fd760293ef | |||
| 816d85196b | |||
|
|
2dda30753e | ||
| f4c7b55b62 | |||
| f617ee7bd9 | |||
| c826185bba | |||
| 22e401062a | |||
| e9661fdf78 | |||
| 6d7979c179 | |||
| 11aa1f1cf7 | |||
| d6b18c2279 | |||
| 2c3977e595 | |||
|
|
484180f717 | ||
|
|
22cd0a74d3 | ||
| 103d09bb0e | |||
|
|
2f5aef8092 | ||
|
|
357e9b23cc | ||
|
|
6f5bbab5ac | ||
|
|
27e56039f4 | ||
|
|
0167ac1a11 | ||
|
|
0b6e18b795 | ||
|
|
f2498f4bda | ||
|
|
953f8d807c | ||
|
|
b154648fdf | ||
|
|
fae060e039 | ||
| 0e661bbf79 | |||
| a0753903b2 | |||
|
|
dbce550625 | ||
|
|
6a8f239995 | ||
| 3762c10359 | |||
|
|
e4594dc900 | ||
|
|
cbaea65b56 | ||
|
|
e47f2556f6 | ||
| 4999227e1b | |||
| ca8dc5c5df | |||
| 9d7673ebf2 | |||
| f6de79a3d4 | |||
|
|
4b76f2eb69 | ||
| d8422f67d7 | |||
| 4130e7bef3 | |||
| 96c90a3c49 | |||
|
|
a1d5a82570 | ||
| 30988fa94a | |||
| 0734f6ff10 | |||
| 030e66f516 | |||
| 9ad185b033 | |||
| 68fb41c067 | |||
| 327724faf1 | |||
| 9020b0fdbb | |||
| a3ab3f10bf | |||
| b77a750c30 | |||
| 8c9f2bbd9c | |||
|
|
92aebf0283 | ||
| bb28de709a | |||
| 9e4131f693 | |||
| d0f8e0bafa | |||
| dbba747283 | |||
| 09cbc8c64a | |||
| f2c05fb68f | |||
| 207db50b15 | |||
| 21ef4f27c8 | |||
| 1d44395e7b | |||
| d8e81b1abb | |||
| da673068bb | |||
| abefb397e3 | |||
| dffe0187df | |||
| a4dde1b216 | |||
| cc302f17c3 | |||
| 015c80215c | |||
| 2200a6a2d3 | |||
|
|
b142de57d5 | ||
| 04e662ecd6 |
+15
-8
@@ -13,13 +13,12 @@ addons:
|
|||||||
- mysql-client
|
- mysql-client
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- chmod +x pandamonium-theorem-prover/gradlew
|
- chmod +x gradlew
|
||||||
- cd pandamonium-theorem-prover
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- mysql_upgrade --force -uroot
|
- mysql_upgrade --force -uroot
|
||||||
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS pandamonium;'
|
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS pandamonium;'
|
||||||
- mysql -u root -e "CREATE USER 'panda'@'localhost';"
|
- mysql -u root -e "CREATE USER 'panda'@'localhost' IDENTIFIED BY 'secret';"
|
||||||
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* to 'panda'@'localhost';"
|
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* to 'panda'@'localhost';"
|
||||||
- mysql -u root pandamonium < persistence/scripts/mysql/local_development.sql
|
- mysql -u root pandamonium < persistence/scripts/mysql/local_development.sql
|
||||||
|
|
||||||
@@ -31,11 +30,19 @@ stages:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- stage: Load Database
|
- stage: "Load Database"
|
||||||
script: ./gradlew loaddb
|
script: ./gradlew loaddb
|
||||||
- stage: Build
|
- stage: "Build"
|
||||||
script: ./gradlew build
|
script: ./gradlew build
|
||||||
- stage: Unit Tests
|
- stage: "Unit Tests"
|
||||||
script: ./gradlew test
|
script: ./gradlew test
|
||||||
- stage: Integration Tests
|
- stage: "Integration Tests"
|
||||||
script: ./gradlew integrationTest
|
script:
|
||||||
|
- |
|
||||||
|
./gradlew :persistence:startPersistenceApi &
|
||||||
|
APP_PID=$!
|
||||||
|
- |
|
||||||
|
./gradlew integrationTest
|
||||||
|
- kill $APP_PID
|
||||||
|
- stage: "Sonar Analysis"
|
||||||
|
script: ./gradlew sonar
|
||||||
|
|||||||
@@ -1,2 +1,54 @@
|
|||||||
# Pandamonium Theorem Prover
|
# Pandamonium Theorem Prover
|
||||||
This is the main repository for the Technical Software Project
|
This project contains several different modules for different parts of the system.
|
||||||
|
|
||||||
|
* [persistence](persistence/README.md)
|
||||||
|
* [web-server](src/README.md)
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
1. Clone the project. `git clone git@github.com:atusa17/tsp.git`
|
||||||
|
2. Open the `pandamonium-theorem-prover` folder with IntelliJ. Use auto-import for a Gradle project.
|
||||||
|
3. Individual Components have their own README. Continue there.
|
||||||
|
|
||||||
|
## Running the Tests
|
||||||
|
|
||||||
|
This project is unit tested with JUnit and Mockito. You can run the unit tests with IntelliJ or Gradle. To run them with IntelliJ, browse to any `*Test.java` file and use IntelliJ's built-in test runner to run or debug the test. To run all the unit tests with Gradle:
|
||||||
|
|
||||||
|
* On a Linux or Macintosh machine:
|
||||||
|
|
||||||
|
```$ ./gradlew test```
|
||||||
|
|
||||||
|
* On a Windows machine:
|
||||||
|
|
||||||
|
```$ gradlew.bat test```
|
||||||
|
|
||||||
|
You can also test modules individually:
|
||||||
|
|
||||||
|
* On a Linux or Macintosh machine:
|
||||||
|
|
||||||
|
```$ ./gradlew persistence:test```
|
||||||
|
|
||||||
|
* On a Windows machine:
|
||||||
|
|
||||||
|
```$ gradlew.bat persistence:test```
|
||||||
|
|
||||||
|
## Integration Tests
|
||||||
|
|
||||||
|
To run the integration tests with IntelliJ, browse to any `*Test.java` file residing in any module name `integrationTest` and use IntelliJ's built-in test runner to run or debug the test. To run all the integration tests with Gradle:
|
||||||
|
|
||||||
|
* On a Linux or Macintosh machine:
|
||||||
|
|
||||||
|
```$ ./gradlew integrationTest```
|
||||||
|
|
||||||
|
* On a Windows machine
|
||||||
|
|
||||||
|
```$ gradlew.bat integrationTest```
|
||||||
|
|
||||||
|
## Built with
|
||||||
|
|
||||||
|
* [Spring Boot](https://projects.spring.io/spring-boot/) - Web framework
|
||||||
|
* [Spring Web Flow](https://projects.spring.io/spring-webflow/) - MVC framework
|
||||||
|
* [Gradle](https://gradle.org/) - Dependency management
|
||||||
|
* [JUnit](http://junit.org/junit4/) - Unit tests
|
||||||
|
* [Mockito](http://site.mockito.org/) - Mock objects library
|
||||||
|
* [Lombok](https://projectlombok.org/) - Boilerplate Code Generator
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
theme: jekyll-theme-midnight
|
|
||||||
@@ -37,6 +37,14 @@ sonarqube {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
sonarqube {
|
||||||
|
properties {
|
||||||
|
property "sonar.host.url", "https://sonarcloud.io"
|
||||||
|
property "sonar.projectKey", "atusa17_ptp"
|
||||||
|
property "sonar.organization", "atusa17-github"
|
||||||
|
property "sonar.login", "9dcc611cd79f175459248b053b25450e36e38463"
|
||||||
|
}
|
||||||
|
}
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'jacoco'
|
apply plugin: 'jacoco'
|
||||||
apply plugin: 'org.unbroken-dome.test-sets'
|
apply plugin: 'org.unbroken-dome.test-sets'
|
||||||
@@ -45,6 +53,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
apply plugin: 'java'
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
@@ -56,11 +65,11 @@ subprojects {
|
|||||||
compile "joda-time:joda-time:2.2"
|
compile "joda-time:joda-time:2.2"
|
||||||
compile('org.springframework:spring-context:5.0.9.RELEASE')
|
compile('org.springframework:spring-context:5.0.9.RELEASE')
|
||||||
|
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.4'
|
||||||
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.4'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@@ -94,11 +103,14 @@ dependencies {
|
|||||||
compile 'org.codehaus.groovy:groovy-all:2.3.11'
|
compile 'org.codehaus.groovy:groovy-all:2.3.11'
|
||||||
compile 'org.apache.commons:commons-lang3:3.5'
|
compile 'org.apache.commons:commons-lang3:3.5'
|
||||||
// The production code uses the SLF4J logging API at compile time
|
// The production code uses the SLF4J logging API at compile time
|
||||||
compile 'org.slf4j:slf4j-api:1.7.21'
|
compile 'org.slf4j:slf4j-api:1.7.22'
|
||||||
compile "joda-time:joda-time:2.2"
|
compile "joda-time:joda-time:2.2"
|
||||||
compile("org.springframework.boot:spring-boot-starter-web")
|
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
|
||||||
|
compile('org.springframework.boot:spring-boot-starter-web','org.apache.tomcat.embed:tomcat-embed-jasper'
|
||||||
|
,'javax.servlet:jstl')
|
||||||
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
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 group: 'junit', name: 'junit', version: '4.12'
|
||||||
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||||
@@ -108,6 +120,12 @@ dependencies {
|
|||||||
apt 'org.projectlombok:lombok:1.18.4'
|
apt 'org.projectlombok:lombok:1.18.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project(':persistence') {
|
||||||
|
dependencies {
|
||||||
|
compile project(':utilities')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
if (System.properties['test.profile'] != 'integrationTest') {
|
if (System.properties['test.profile'] != 'integrationTest') {
|
||||||
exclude '**/*integrationTest*'
|
exclude '**/*integrationTest*'
|
||||||
@@ -121,14 +139,7 @@ testSets {
|
|||||||
integrationTest
|
integrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
compileTestKotlin {
|
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapper {
|
wrapper {
|
||||||
gradleVersion = '4.10.2'
|
gradleVersion = '5.2.1'
|
||||||
distributionType = Wrapper.DistributionType.ALL
|
distributionType = Wrapper.DistributionType.ALL
|
||||||
}
|
}
|
||||||
Vendored
@@ -0,0 +1,6 @@
|
|||||||
|
#Sun Feb 03 13:43:34 MST 2019
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
spring.mvc.view.prefix:/WEB-INF/jsp/
|
||||||
|
spring.mvc.view.suffix:.jsp
|
||||||
|
server.port=8090
|
||||||
Generated
-7
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module version="4">
|
|
||||||
<component name="sonarModuleSettings">
|
|
||||||
<option name="localAnalysisScripName" value="<PROJECT>" />
|
|
||||||
<option name="serverName" value="<PROJECT>" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
Generated
-7
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module version="4">
|
|
||||||
<component name="sonarModuleSettings">
|
|
||||||
<option name="localAnalysisScripName" value="<PROJECT>" />
|
|
||||||
<option name="serverName" value="<PROJECT>" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
# tsp-main
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
description = 'Provides database access and connectivity'
|
|
||||||
group 'edu.msudenver.tsp'
|
|
||||||
version '1.0'
|
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
|
||||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
|
||||||
|
|
||||||
compile 'com.mchange:c3p0:0.9.5.2'
|
|
||||||
compile 'mysql:mysql-connector-java:5.1.35'
|
|
||||||
compile 'org.hibernate:hibernate-validator:5.3.4.Final'
|
|
||||||
compile 'javax.validation:validation-api:1.1.0.Final'
|
|
||||||
compile('com.googlecode.log4jdbc:log4jdbc:1.2') {
|
|
||||||
exclude(group: 'org.slf4j')
|
|
||||||
}
|
|
||||||
|
|
||||||
testCompile 'javax.el:javax.el-api:3.0.0'
|
|
||||||
}
|
|
||||||
|
|
||||||
task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local database.') {
|
|
||||||
workingDir "./scripts/mysql"
|
|
||||||
commandLine './loaddb.sh'
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
public class PersistenceConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
class BaseDao {
|
|
||||||
|
|
||||||
// <T> T findById(final int id) {
|
|
||||||
// //TODO insert DB calls for finding objects by their ID's
|
|
||||||
// }
|
|
||||||
|
|
||||||
// <T> List<T> queryForList(final String query) {
|
|
||||||
// //TODO insert DB calls for querying for lists based on the specified query
|
|
||||||
// }
|
|
||||||
|
|
||||||
// <T> T save(final T t) {
|
|
||||||
// //TODO insert DB calls here for insert and update
|
|
||||||
// }
|
|
||||||
|
|
||||||
<T> void delete(final T t) {
|
|
||||||
//TODO insert DB calls here to delete
|
|
||||||
}
|
|
||||||
|
|
||||||
// private <T> T insert(final T object) {
|
|
||||||
// // TODO insert DB calls to insert records
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private <T> T update(final T object) {
|
|
||||||
// //TODO insert DB calls to update records
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class DefinitionDao extends BaseDao {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class NotationDao extends BaseDao {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class ProofDao extends BaseDao {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class TheoremDao extends BaseDao {
|
|
||||||
}
|
|
||||||
-9
@@ -1,9 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
class BaseDto {
|
|
||||||
private String id;
|
|
||||||
private int version;
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
public class DefinitionDto extends BaseDto {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
public class NotationDto extends BaseDto {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
public class ProofDto extends BaseDto {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
public class TheoremDto extends BaseDto {
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.DefinitionDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class DefinitionManager {
|
|
||||||
final private DefinitionDao definitionDao;
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
public class ManagerConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.NotationDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class NotationManager {
|
|
||||||
final private NotationDao notationDao;
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.ProofDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ProofManager {
|
|
||||||
final private ProofDao proofDao;
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.TheoremDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class TheoremManager {
|
|
||||||
final private TheoremDao theoremDao;
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.services.parser;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
//@PropertySource("classpath:development.properties")
|
|
||||||
public class ParserConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
package edu.msudenver.tsp.services.parser;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.manager.DefinitionManager;
|
|
||||||
import edu.msudenver.tsp.persistence.manager.NotationManager;
|
|
||||||
import edu.msudenver.tsp.persistence.manager.ProofManager;
|
|
||||||
import edu.msudenver.tsp.persistence.manager.TheoremManager;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
class ParserService {
|
|
||||||
private final DefinitionManager definitionManager;
|
|
||||||
private final TheoremManager theoremManager;
|
|
||||||
private final NotationManager notationManager;
|
|
||||||
private final ProofManager proofManager;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ParserService(final DefinitionManager definitionManager, final TheoremManager theoremManager,
|
|
||||||
final NotationManager notationManager, final ProofManager proofManager) {
|
|
||||||
this.definitionManager = definitionManager;
|
|
||||||
this.theoremManager = theoremManager;
|
|
||||||
this.notationManager = notationManager;
|
|
||||||
this.proofManager = proofManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-16
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
package edu.msudenver.tsp.services.scoring;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
class TheoremScoringService {
|
|
||||||
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
package edu.msudenver.tsp.services.parser;
|
|
||||||
|
|
||||||
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 ParserServiceTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertEquals(3,3);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SpringBootApplication
|
|
||||||
public class Application {
|
|
||||||
|
|
||||||
public static void main(final String[] args) {
|
|
||||||
SpringApplication.run(Application.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CommandLineRunner commandLineRunner(final ApplicationContext ctx) {
|
|
||||||
return args -> {
|
|
||||||
|
|
||||||
LOG.info("Beans provided by Spring Boot:");
|
|
||||||
|
|
||||||
final String[] beanNames = ctx.getBeanDefinitionNames();
|
|
||||||
Arrays.sort(beanNames);
|
|
||||||
for (final String beanName : beanNames) {
|
|
||||||
LOG.info(beanName);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class HelloController {
|
|
||||||
|
|
||||||
@RequestMapping("/")
|
|
||||||
public String index() {
|
|
||||||
return "Welcome to Project Pandamonium!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
public class ProofsDriver {
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
//@PropertySource("classpath:development.properties")
|
|
||||||
public class WebsiteConfig {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class HelloControllerTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertEquals(3, 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
public class ProofsDriverTest {
|
|
||||||
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website.integrationTest;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class HelloControllerIntegrationTest {
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertEquals(3,3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
group 'edu.msudenver.tsp'
|
|
||||||
version '1.0'
|
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
|
||||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
## PTP Persistence API
|
||||||
|
|
||||||
|
The PTP Persistence API is the web API for accessing the theorems database.
|
||||||
|
|
||||||
|
<http://localhost:8090/>
|
||||||
|
|
||||||
|
## Running from IntelliJ
|
||||||
|
|
||||||
|
* Create a new run configuration in IntelliJ.
|
||||||
|
|
||||||
|
```
|
||||||
|
Name: "PTP Persistence API Tomcat"
|
||||||
|
Application Server: Tomcat (8.5.12)
|
||||||
|
HTTP Port: 8090
|
||||||
|
JMX Port: 1090
|
||||||
|
Deployment tabe: Deploy persistence-api.war (exploded)
|
||||||
|
```
|
||||||
|
## Running the Tests
|
||||||
|
|
||||||
|
This project is unit tested with JUnit and Mockito. You can run the unit tests with IntelliJ or Gradle. To run them with IntelliJ, browse to any `*Test.java` file and use IntelliJ's built-in test runner to run or debug the test. To run all the unit tests with Gradle:
|
||||||
|
|
||||||
|
* On a Linux or Macintosh machine:
|
||||||
|
|
||||||
|
```$ ./gradlew test```
|
||||||
|
|
||||||
|
* On a Windows machine:
|
||||||
|
|
||||||
|
```$ gradlew.bat test```
|
||||||
|
|
||||||
|
You can also test modules individually:
|
||||||
|
|
||||||
|
* On a Linux or Macintosh machine:
|
||||||
|
|
||||||
|
```$ ./gradlew persistence:test```
|
||||||
|
|
||||||
|
* On a Windows machine:
|
||||||
|
|
||||||
|
```$ gradlew.bat persistence:test```
|
||||||
|
|
||||||
|
## Integration Tests
|
||||||
|
|
||||||
|
To run the integration tests with IntelliJ, browse to any `*Test.java` file residing in any module name `integrationTest` and use IntelliJ's built-in test runner to run or debug the test. To run all the integration tests with Gradle:
|
||||||
|
|
||||||
|
* On a Linux or Macintosh machine:
|
||||||
|
|
||||||
|
```$ ./gradlew integrationTest```
|
||||||
|
|
||||||
|
* On a Windows machine
|
||||||
|
|
||||||
|
```$ gradlew.bat integrationTest```
|
||||||
|
|
||||||
|
## Built with
|
||||||
|
|
||||||
|
* [Spring Boot](https://projects.spring.io/spring-boot/) - Web framework
|
||||||
|
* [Spring Web Flow](https://projects.spring.io/spring-webflow/) - MVC framework
|
||||||
|
* [Spring Data](https://spring.io/projects/spring-data/) - Persistence framework
|
||||||
|
* [Gradle](https://gradle.org/) - Dependency management
|
||||||
|
* [JUnit](http://junit.org/junit4/) - Unit tests
|
||||||
|
* [Mockito](http://site.mockito.org/) - Mock objects library
|
||||||
|
* [Lombok](https://projectlombok.org/) - Boilerplate Code Generator
|
||||||
|
* [Hibernate ORM](http://hibernate.org/orm/) - Object/Relational Mapping
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import org.gradle.internal.os.OperatingSystem
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
description = 'Provides database access and connectivity'
|
||||||
|
group 'edu.msudenver.tsp'
|
||||||
|
version '1.0'
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
sonarqube {
|
||||||
|
properties {
|
||||||
|
property "sonar.projectName", 'Pandamonium Persistence Tier'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.5.RELEASE'
|
||||||
|
compile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '9.0.16'
|
||||||
|
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.5.RELEASE'
|
||||||
|
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
|
||||||
|
compile group: 'org.springframework', name: 'spring-aspects', version: '5.1.5.RELEASE'
|
||||||
|
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.1.Final'
|
||||||
|
compile group: 'com.vladmihalcea', name: 'hibernate-types-52', version: '2.4.1'
|
||||||
|
|
||||||
|
compile fileTree(dir: 'lib', include: '**/*.jar')
|
||||||
|
|
||||||
|
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
|
||||||
|
compile('com.googlecode.log4jdbc:log4jdbc:1.2') {
|
||||||
|
exclude(group: 'org.slf4j')
|
||||||
|
}
|
||||||
|
|
||||||
|
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.2.RELEASE'
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
testCompile 'javax.el:javax.el-api:3.0.0'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local database.') {
|
||||||
|
if (OperatingSystem.current().isLinux() || OperatingSystem.current().isMacOsX()) {
|
||||||
|
workingDir "./scripts/mysql"
|
||||||
|
commandLine './loaddb.sh'
|
||||||
|
} else {
|
||||||
|
workingDir "./scripts/mysql"
|
||||||
|
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'
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
set mysql_pwd = secret
|
||||||
|
FOR /R %%s IN (*.sql) do (
|
||||||
|
echo **** %%s ****
|
||||||
|
mysql -u panda -psecret < %%s
|
||||||
|
)
|
||||||
+1
-2
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
export MYSQL_PWD=secret
|
|
||||||
|
|
||||||
for sqlScript in $( find . -name "*.sql" -print | sort);
|
for sqlScript in $( find . -name "*.sql" -print | sort);
|
||||||
do
|
do
|
||||||
echo "**** $sqlScript ****"
|
echo "**** $sqlScript ****"
|
||||||
mysql --batch --quick --raw --line-numbers --force --user=panda < $sqlScript
|
mysql -u panda -psecret < $sqlScript
|
||||||
done
|
done
|
||||||
+25
@@ -23,3 +23,28 @@ definition json not null,
|
|||||||
notation json,
|
notation json,
|
||||||
version int default 1
|
version int default 1
|
||||||
);
|
);
|
||||||
|
create table theorems (
|
||||||
|
id int not null auto_increment primary key unique,
|
||||||
|
name varchar(512) 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)
|
||||||
|
);
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Account;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
|
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.Optional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = PersistenceTestConfig.class)
|
||||||
|
public class AccountsIntegrationTest {
|
||||||
|
@Autowired private AccountsRepository accountsRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRUDFunctionality() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
final Account savedAccount = accountsRepository.save(account);
|
||||||
|
|
||||||
|
assertNotNull(savedAccount);
|
||||||
|
assertEquals(Integer.valueOf(0), savedAccount.getVersion());
|
||||||
|
|
||||||
|
final int id = savedAccount.getId();
|
||||||
|
|
||||||
|
assertEquals("Test username", savedAccount.getUsername());
|
||||||
|
assertEquals("test password", savedAccount.getPassword());
|
||||||
|
assertTrue(savedAccount.getAdministratorStatus());
|
||||||
|
|
||||||
|
savedAccount.setPassword("Test Update");
|
||||||
|
|
||||||
|
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(account);
|
||||||
|
final Optional<Account> deletedAccount = accountsRepository.findById(id);
|
||||||
|
assertFalse(deletedAccount.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Account createAccount() {
|
||||||
|
final Account account = new Account();
|
||||||
|
account.setUsername("Test username");
|
||||||
|
account.setPassword("test password");
|
||||||
|
account.setAdministratorStatus(true);
|
||||||
|
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
|
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.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = PersistenceTestConfig.class)
|
||||||
|
public class DefinitionsIntegrationTest {
|
||||||
|
@Autowired private DefinitionRepository definitionRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRUDFunctionality() {
|
||||||
|
final Definition definition = createDefinition();
|
||||||
|
final Definition savedDefinition = definitionRepository.save(definition);
|
||||||
|
|
||||||
|
assertNotNull(savedDefinition);
|
||||||
|
assertEquals(Integer.valueOf(0), savedDefinition.getVersion());
|
||||||
|
|
||||||
|
final int id = savedDefinition.getId();
|
||||||
|
|
||||||
|
assertEquals("Test Name", savedDefinition.getName());
|
||||||
|
assertNotNull(savedDefinition.getDefinition());
|
||||||
|
assertNotNull(savedDefinition.getNotation());
|
||||||
|
|
||||||
|
final List<String> definitionsList = savedDefinition.getDefinition();
|
||||||
|
final List<String> notationList = savedDefinition.getNotation();
|
||||||
|
|
||||||
|
assertEquals(2, definitionsList.size());
|
||||||
|
assertEquals(1, notationList.size());
|
||||||
|
assertEquals("Test definition 1", definitionsList.get(0));
|
||||||
|
assertEquals("Test definition 2", definitionsList.get(1));
|
||||||
|
assertEquals("\\testLaTeX", notationList.get(0));
|
||||||
|
|
||||||
|
savedDefinition.setName("Test Update");
|
||||||
|
|
||||||
|
final Definition updatedDefinition = definitionRepository.save(savedDefinition);
|
||||||
|
|
||||||
|
assertEquals("Test Update", updatedDefinition.getName());
|
||||||
|
assertNotNull(updatedDefinition.getDefinition());
|
||||||
|
assertNotNull(updatedDefinition.getNotation());
|
||||||
|
|
||||||
|
final List<String> updatedDefinitionsList = updatedDefinition.getDefinition();
|
||||||
|
final List<String> updatedNotationsList = updatedDefinition.getNotation();
|
||||||
|
|
||||||
|
assertEquals(2, updatedDefinitionsList.size());
|
||||||
|
assertEquals(1, updatedNotationsList.size());
|
||||||
|
assertEquals("Test definition 1", updatedDefinitionsList.get(0));
|
||||||
|
assertEquals("Test definition 2", updatedDefinitionsList.get(1));
|
||||||
|
assertEquals("\\testLaTeX", updatedNotationsList.get(0));
|
||||||
|
assertEquals(id, updatedDefinition.getId());
|
||||||
|
|
||||||
|
definitionRepository.delete(updatedDefinition);
|
||||||
|
final Optional<Definition> deletedDefinition = definitionRepository.findById(id);
|
||||||
|
assertFalse(deletedDefinition.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Definition createDefinition() {
|
||||||
|
final List<String> definitionList = new ArrayList<>();
|
||||||
|
definitionList.add("Test definition 1");
|
||||||
|
definitionList.add("Test definition 2");
|
||||||
|
|
||||||
|
final List<String> notationList = new ArrayList<>();
|
||||||
|
notationList.add("\\testLaTeX");
|
||||||
|
|
||||||
|
final Definition definition = new Definition();
|
||||||
|
definition.setName("Test Name");
|
||||||
|
definition.setDefinition(definitionList);
|
||||||
|
definition.setNotation(notationList);
|
||||||
|
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
|
}
|
||||||
+93
@@ -0,0 +1,93 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||||
|
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||||
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableJpaRepositories
|
||||||
|
@EnableJpaAuditing
|
||||||
|
@EntityScan(basePackages = "edu.msudenver.tsp.persistence")
|
||||||
|
public class PersistenceTestConfig {
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
|
final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter());
|
||||||
|
entityManagerFactoryBean.setDataSource(getDataSource());
|
||||||
|
entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
|
||||||
|
entityManagerFactoryBean.setPackagesToScan("edu.msudenver.tsp.persistence");
|
||||||
|
entityManagerFactoryBean.setJpaProperties(additionalProperties());
|
||||||
|
|
||||||
|
return entityManagerFactoryBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JpaTransactionManager jpaTransactionManager() {
|
||||||
|
final JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
|
||||||
|
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
|
||||||
|
return jpaTransactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HibernateJpaVendorAdapter vendorAdapter() {
|
||||||
|
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||||
|
vendorAdapter.setShowSql(true);
|
||||||
|
return vendorAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "dataSource")
|
||||||
|
public DataSource getDataSource(){
|
||||||
|
return DataSourceBuilder
|
||||||
|
.create()
|
||||||
|
.username("panda")
|
||||||
|
.password("secret")
|
||||||
|
.url("jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false&serverTimezone=UTC")
|
||||||
|
.driverClassName("com.mysql.cj.jdbc.Driver")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "sessionFactory")
|
||||||
|
public SessionFactory getSessionFactory(final DataSource dataSource) {
|
||||||
|
final LocalSessionFactoryBuilder sessionFactoryBuilder = new LocalSessionFactoryBuilder(dataSource);
|
||||||
|
sessionFactoryBuilder.scanPackages("edu.msudenver.tsp.persistence.dto");
|
||||||
|
return sessionFactoryBuilder.buildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
public HibernateTransactionManager getTransactionManager(final SessionFactory sessionFactory) {
|
||||||
|
return new HibernateTransactionManager(sessionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
|
||||||
|
final DataSourceInitializer initializer = new DataSourceInitializer();
|
||||||
|
initializer.setDataSource(dataSource);
|
||||||
|
return initializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties additionalProperties() {
|
||||||
|
final Properties properties = new Properties();
|
||||||
|
properties.setProperty("hibernate.hbm2ddl.auto", "update");
|
||||||
|
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect");
|
||||||
|
properties.setProperty("spring.jpa.show-sql", "true");
|
||||||
|
properties.setProperty("spring.datasource.tomcat.max-active", "1");
|
||||||
|
properties.setProperty("hibernate.id.new_generator_mappings","false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
||||||
+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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
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;
|
||||||
|
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.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = PersistenceTestConfig.class)
|
||||||
|
public class TheoremsIntegrationTest {
|
||||||
|
@Autowired private TheoremRepository theoremRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRUDFunctionality() {
|
||||||
|
final Theorem theorem = createTheorem();
|
||||||
|
final Theorem savedTheorem = theoremRepository.save(theorem);
|
||||||
|
|
||||||
|
assertNotNull(savedTheorem);
|
||||||
|
assertEquals(Integer.valueOf(0), savedTheorem.getVersion());
|
||||||
|
|
||||||
|
final int id = savedTheorem.getId();
|
||||||
|
|
||||||
|
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());
|
||||||
|
assertEquals("test theorem 1", savedTheorem.getReferencedTheorems().get(0));
|
||||||
|
assertEquals("test theorem 2", savedTheorem.getReferencedTheorems().get(1));
|
||||||
|
assertEquals("test definition 1", savedTheorem.getReferencedDefinitions().get(0));
|
||||||
|
assertEquals("test definition 2", savedTheorem.getReferencedDefinitions().get(1));
|
||||||
|
|
||||||
|
savedTheorem.setBranch("Test Update");
|
||||||
|
|
||||||
|
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());
|
||||||
|
assertEquals("test theorem 1", updatedTheorem.getReferencedTheorems().get(0));
|
||||||
|
assertEquals("test theorem 2", updatedTheorem.getReferencedTheorems().get(1));
|
||||||
|
assertEquals("test definition 1", updatedTheorem.getReferencedDefinitions().get(0));
|
||||||
|
assertEquals("test definition 2", updatedTheorem.getReferencedDefinitions().get(1));
|
||||||
|
assertEquals(updatedTheorem.getId(), id);
|
||||||
|
|
||||||
|
theoremRepository.delete(theorem);
|
||||||
|
final Optional<Theorem> deletedTheorem = theoremRepository.findById(id);
|
||||||
|
assertFalse(deletedTheorem.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Theorem createTheorem() {
|
||||||
|
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 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 theorem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||||
|
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||||
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableJpaRepositories
|
||||||
|
@EnableJpaAuditing
|
||||||
|
@EntityScan
|
||||||
|
public class PersistenceApi {
|
||||||
|
|
||||||
|
@Value("${spring.datasource.username}") private String username;
|
||||||
|
@Value("${spring.datasource.password}") private String password;
|
||||||
|
@Value("${spring.jpa.hibernate.ddl-auto}") private String hibernateTablePolicy;
|
||||||
|
@Value("${spring.datasource.url}") private String databaseUrl;
|
||||||
|
@Value("${spring.jpa.properties.hibernate.dialect}") private String hibernateDialect;
|
||||||
|
@Value("${spring.jpa.show-sql}") private String showSql;
|
||||||
|
@Value("${spring.datasource.driver-class-name}") private String driverClassName;
|
||||||
|
@Value("${spring.datasource.tomcat.max-active}") private String tomcatPoolMaxActive;
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
SpringApplication.run(PersistenceApi.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
|
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
em.setJpaVendorAdapter(vendorAdapter());
|
||||||
|
em.setDataSource(getDataSource());
|
||||||
|
em.setPersistenceProviderClass(HibernatePersistenceProvider.class);
|
||||||
|
em.setPackagesToScan("edu.msudenver.tsp.persistence");
|
||||||
|
em.setJpaProperties(additionalProperties());
|
||||||
|
|
||||||
|
return em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JpaTransactionManager jpaTransactionManager() {
|
||||||
|
final JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
|
||||||
|
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
|
||||||
|
return jpaTransactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HibernateJpaVendorAdapter vendorAdapter() {
|
||||||
|
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||||
|
vendorAdapter.setShowSql(true);
|
||||||
|
return vendorAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "dataSource")
|
||||||
|
public DataSource getDataSource(){
|
||||||
|
return DataSourceBuilder
|
||||||
|
.create()
|
||||||
|
.username(username)
|
||||||
|
.password(password)
|
||||||
|
.url(databaseUrl)
|
||||||
|
.driverClassName(driverClassName)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "sessionFactory")
|
||||||
|
public SessionFactory getSessionFactory(final DataSource dataSource) {
|
||||||
|
final LocalSessionFactoryBuilder sessionFactoryBuilder = new LocalSessionFactoryBuilder(dataSource);
|
||||||
|
sessionFactoryBuilder.scanPackages("edu.msudenver.tsp.persistence.dto");
|
||||||
|
return sessionFactoryBuilder.buildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
public HibernateTransactionManager getTransactionManager(final SessionFactory sessionFactory) {
|
||||||
|
return new HibernateTransactionManager(sessionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
|
||||||
|
final DataSourceInitializer initializer = new DataSourceInitializer();
|
||||||
|
initializer.setDataSource(dataSource);
|
||||||
|
return initializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties additionalProperties() {
|
||||||
|
final Properties properties = new Properties();
|
||||||
|
properties.setProperty("hibernate.hbm2ddl.auto", "update");
|
||||||
|
properties.setProperty("hibernate.dialect", hibernateDialect);
|
||||||
|
properties.setProperty("spring.jpa.show-sql", showSql);
|
||||||
|
properties.setProperty("spring.datasource.tomcat.max-active", tomcatPoolMaxActive);
|
||||||
|
properties.setProperty("hibernate.id.new_generator_mappings","false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+227
@@ -0,0 +1,227 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Account;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.groups.Default;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequestMapping("/accounts")
|
||||||
|
public class AccountController {
|
||||||
|
private final AccountsRepository accountsRepository;
|
||||||
|
|
||||||
|
@GetMapping({"","/"})
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<Iterable<Account>> getListOfAccounts() {
|
||||||
|
LOG.info("Received request to list all accounts");
|
||||||
|
|
||||||
|
LOG.debug("Querying for list of accounts");
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final List<Account> listOfAccounts = (List<Account>) accountsRepository.findAll();
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
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")
|
||||||
|
public @ResponseBody
|
||||||
|
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);
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<Account> account = accountsRepository.findById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
return account.map(accountDto -> {
|
||||||
|
LOG.info("Returning account with id {}", id);
|
||||||
|
return new ResponseEntity<>(accountDto, HttpStatus.OK);
|
||||||
|
}).orElseGet(
|
||||||
|
() -> {
|
||||||
|
LOG.warn("No account was found with id {}", id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/username")
|
||||||
|
public @ResponseBody
|
||||||
|
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);
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<Account> account = accountsRepository.findByUsername(username);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
return account.map(accountDto -> {
|
||||||
|
LOG.info("Returning account with username {}", username);
|
||||||
|
return new ResponseEntity<>(accountDto, HttpStatus.OK);
|
||||||
|
}).orElseGet(
|
||||||
|
() -> {
|
||||||
|
LOG.warn("No account was found with username {}", username);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account == null) {
|
||||||
|
LOG.error("Passed account is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Checking for any existing users with username {}", account.getUsername());
|
||||||
|
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
LOG.debug("Querying for existing accounts");
|
||||||
|
|
||||||
|
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 {}", account.getUsername());
|
||||||
|
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Saving new account");
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Account savedAccount = accountsRepository.save(account);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
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<Account> updateAccount(
|
||||||
|
@PathVariable("id") final Integer id,
|
||||||
|
@RequestBody final Account account, final BindingResult bindingResult) {
|
||||||
|
|
||||||
|
LOG.info("Received request to update an account");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Account ID must be specified");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Checking for existence of account with id {}", id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<Account> existingAccount = accountsRepository.findById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
if (!existingAccount.isPresent()) {
|
||||||
|
LOG.error("No account associated with id {}", id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Account updatedAccount = accountsRepository.save(existingAccount.get());
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
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);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Specified Id is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Deleting account with id {}", id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
accountsRepository.deleteById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
+181
@@ -0,0 +1,181 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.groups.Default;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequestMapping(path = "/definitions")
|
||||||
|
public class DefinitionController {
|
||||||
|
private final DefinitionRepository definitionRepository;
|
||||||
|
|
||||||
|
@GetMapping({"","/"})
|
||||||
|
public @ResponseBody
|
||||||
|
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<Definition> listOfDefinitions = definitionRepository.findAll();
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
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<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);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<Definition> definition = definitionRepository.findById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
return definition.map(definitionDto -> {
|
||||||
|
LOG.info("Returning definition with id {}", id);
|
||||||
|
return new ResponseEntity<>(definitionDto, HttpStatus.OK);
|
||||||
|
}).orElseGet(
|
||||||
|
() -> {
|
||||||
|
LOG.warn("No definition was found with id {}",id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definition == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Saving new definition");
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Definition savedDefinition = definitionRepository.save(definition);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
LOG.info("Returning the newly created definition with id {}", savedDefinition.getId());
|
||||||
|
return new ResponseEntity<>(savedDefinition, HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/{id}")
|
||||||
|
public @ResponseBody ResponseEntity<Definition> updateDefinition(
|
||||||
|
@PathVariable("id") final Integer id,
|
||||||
|
@RequestBody final Definition definition, final BindingResult bindingResult) {
|
||||||
|
|
||||||
|
LOG.info("Received request to update an account");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definition == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Definition ID must be specified");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Checking for existence of definition with id {}", id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<Definition> existingDefinition = definitionRepository.findById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
if (!existingDefinition.isPresent()) {
|
||||||
|
LOG.error("No definition associated with id {}", id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Definition updatedDefinition = definitionRepository.save(existingDefinition.get());
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
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);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Specified id is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Deleting definition with id {}", id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
definitionRepository.deleteById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
+251
@@ -0,0 +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 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.*;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+283
@@ -0,0 +1,283 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Theorem;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
||||||
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.groups.Default;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequestMapping(path = "/theorems")
|
||||||
|
public class TheoremController {
|
||||||
|
private final TheoremRepository theoremRepository;
|
||||||
|
|
||||||
|
@GetMapping({"","/"})
|
||||||
|
public @ResponseBody
|
||||||
|
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<Theorem> listOfTheorems = theoremRepository.findAll();
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
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")
|
||||||
|
public @ResponseBody
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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<Theorem> listOfTheorems = theoremRepository.findByBranch(branch);
|
||||||
|
|
||||||
|
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 for branch {}", branch);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Returning list of theorems with branch {}", branch);
|
||||||
|
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/proven_status")
|
||||||
|
public @ResponseBody
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Boolean isProven = Boolean.parseBoolean(provenStatus);
|
||||||
|
|
||||||
|
LOG.debug("Querying for theorems with proven status {}", isProven);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final List<Theorem> listOfTheorems = theoremRepository.findByProvenStatus(isProven);
|
||||||
|
|
||||||
|
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 for proven status {}", isProven);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Returning list of theorems with proven status {}", isProven);
|
||||||
|
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/name")
|
||||||
|
public @ResponseBody
|
||||||
|
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);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<Theorem> theorem = theoremRepository.findById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
return theorem.map(theoremDto -> {
|
||||||
|
LOG.info("Returning theorem with id {}", id);
|
||||||
|
return new ResponseEntity<>(theoremDto, HttpStatus.OK);
|
||||||
|
}).orElseGet(
|
||||||
|
() -> {
|
||||||
|
LOG.warn("No theorem was found with id {}", id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theorem == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Saving new theorem");
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Theorem savedTheorem = theoremRepository.save(theorem);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
LOG.info("Returning the newly created theorem with id {}", savedTheorem.getId());
|
||||||
|
return new ResponseEntity<>(savedTheorem, HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/{id}")
|
||||||
|
public @ResponseBody ResponseEntity<Theorem> updateTheorem(
|
||||||
|
@PathVariable("id") final Integer id,
|
||||||
|
@RequestBody final Theorem theorem, final BindingResult bindingResult) {
|
||||||
|
|
||||||
|
LOG.info("Received request to update a theorem");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theorem == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Theorem ID must be specified");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Checking for existence of theorem with id {}", id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<Theorem> existingTheorem = theoremRepository.findById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
if (!existingTheorem.isPresent()) {
|
||||||
|
LOG.error("No theorem associated with id {}", id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Theorem updatedTheorem = theoremRepository.save(existingTheorem.get());
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
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);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Specified id is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Deleting theorem with id {}", id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
theoremRepository.deleteById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Entity(name = "accounts")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
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;
|
||||||
|
@Temporal(TemporalType.DATE) @Column(name = "last_login") private Date lastLogin;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7095627971593953734L;
|
||||||
|
|
||||||
|
@JsonProperty("administrator_status")
|
||||||
|
public boolean getAdministratorStatus() {
|
||||||
|
return administratorStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("administrator_status")
|
||||||
|
public void setAdministratorStatus(final boolean administratorStatus) {
|
||||||
|
this.administratorStatus = administratorStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("last_login")
|
||||||
|
public Date getLastLogin() {
|
||||||
|
return lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("last_login")
|
||||||
|
public void setLastLogin(final Date lastLogin) {
|
||||||
|
this.lastLogin = lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Insert {}
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
public void prePersist() {
|
||||||
|
lastLogin = new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
import com.vladmihalcea.hibernate.type.array.IntArrayType;
|
||||||
|
import com.vladmihalcea.hibernate.type.array.StringArrayType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonNodeBinaryType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonNodeStringType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonStringType;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.TypeDef;
|
||||||
|
import org.hibernate.annotations.TypeDefs;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
|
@MappedSuperclass
|
||||||
|
@TypeDefs({
|
||||||
|
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
|
||||||
|
@TypeDef(name = "int-array", typeClass = IntArrayType.class),
|
||||||
|
@TypeDef(name = "json", typeClass = JsonStringType.class),
|
||||||
|
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class),
|
||||||
|
@TypeDef(name = "jsonb-node", typeClass = JsonNodeBinaryType.class),
|
||||||
|
@TypeDef(name = "json-node", typeClass = JsonNodeStringType.class),
|
||||||
|
})
|
||||||
|
public class BaseDto implements Serializable {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id;
|
||||||
|
@Version
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1686252381978213945L;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
@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 {}
|
||||||
|
}
|
||||||
@@ -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 {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
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.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EntityListeners;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity(name = "theorems")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
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(groups = Insert.class) @Column(name = "proven_status") private boolean provenStatus;
|
||||||
|
|
||||||
|
@JsonProperty("theorem_type")
|
||||||
|
public TheoremType getTheoremType() {
|
||||||
|
return theoremType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("theorem_type")
|
||||||
|
public void setTheoremType(final TheoremType theoremType) {
|
||||||
|
this.theoremType = theoremType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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("proven_status")
|
||||||
|
public boolean getProvenStatus() {
|
||||||
|
return provenStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("proven_status")
|
||||||
|
public void setProvenStatus(final boolean provenStatus) {
|
||||||
|
this.provenStatus = provenStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1545568391140364425L;
|
||||||
|
|
||||||
|
public interface Insert {}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
public enum TheoremType {
|
||||||
|
THEOREM, PROPOSITION, LEMMA, COROLLARY
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
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<Account, Integer> {
|
||||||
|
Optional<Account> findByUsername(String username);
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
|
||||||
|
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<Definition, Integer> {
|
||||||
|
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ProofRepository extends JpaRepository<Proof, Integer> {
|
||||||
|
|
||||||
|
List<Proof> findByBranch(String branch);
|
||||||
|
|
||||||
|
List<Proof> findByTheoremName(String name);
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
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<Theorem, Integer> {
|
||||||
|
|
||||||
|
List<Theorem> findByBranch(String branch);
|
||||||
|
|
||||||
|
List<Theorem> findByProvenStatus(Boolean provenStatus);
|
||||||
|
|
||||||
|
List<Theorem> findByName(String name);
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
spring.jpa.hibernate.ddl-auto = none
|
||||||
|
spring.jpa.database=mysql
|
||||||
|
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false&serverTimezone=UTC
|
||||||
|
spring.datasource.username=panda
|
||||||
|
spring.datasource.password=secret
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
|
||||||
|
spring.jpa.show-sql = true
|
||||||
|
spring.datasource.tomcat.test-while-idle=true
|
||||||
|
spring.datasource.tomcat.validation-query=SELECT 1
|
||||||
|
logging.level.org.springframework.web=DEBUG
|
||||||
|
spring.datasource.tomcat.max-active=5
|
||||||
|
server.port=8090
|
||||||
+276
@@ -0,0 +1,276 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Account;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
|
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.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
@WebMvcTest(controllers = AccountController.class)
|
||||||
|
public class AccountControllerTest {
|
||||||
|
@Mock
|
||||||
|
private AccountsRepository accountsRepository;
|
||||||
|
@InjectMocks
|
||||||
|
private AccountController accountController;
|
||||||
|
@Mock private BindingResult bindingResult;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllAccounts() {
|
||||||
|
final Account accountDto = createAccount();
|
||||||
|
final List<Account> accountList = new ArrayList<>();
|
||||||
|
accountList.add(accountDto);
|
||||||
|
accountList.add(accountDto);
|
||||||
|
|
||||||
|
when(accountsRepository.findAll()).thenReturn(accountList);
|
||||||
|
|
||||||
|
final ResponseEntity<Iterable<Account>> responseEntity = accountController.getListOfAccounts();
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
|
responseEntity.getBody().forEach(account -> assertEquals(accountDto, account));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountById() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.ofNullable(account));
|
||||||
|
|
||||||
|
final ResponseEntity<Account> responseEntity = accountController.getAccountById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertEquals(account, responseEntity.getBody());
|
||||||
|
verify(accountsRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountById_nullId() {
|
||||||
|
final ResponseEntity responseEntity = accountController.getAccountById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountById_noAccountFound() {
|
||||||
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = accountController.getAccountById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
verify(accountsRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountByUsername() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.ofNullable(account));
|
||||||
|
|
||||||
|
final ResponseEntity<Account> responseEntity = accountController.getAccountByUsername("Test username");
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertEquals(account, responseEntity.getBody());
|
||||||
|
verify(accountsRepository).findByUsername(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountById_nullUsername() {
|
||||||
|
final ResponseEntity responseEntity = accountController.getAccountByUsername(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountByUsername_noAccountFound() {
|
||||||
|
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = accountController.getAccountByUsername("Test username");
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
verify(accountsRepository).findByUsername(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertAccount() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
when(accountsRepository.save(any(Account.class))).thenReturn(account);
|
||||||
|
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity<Account> responseEntity = accountController.insertAccount(account, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
|
assertEquals(account, responseEntity.getBody());
|
||||||
|
verify(accountsRepository).save(any(Account.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertAccount_usernameAlreadyExists() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.of(account));
|
||||||
|
|
||||||
|
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(Account.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertAccount_accountsDtoIsNull() {
|
||||||
|
final ResponseEntity responseEntity = accountController.insertAccount(null, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertAccount_bindingResultHasErrors() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = accountController.insertAccount(account, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount() {
|
||||||
|
final Account existingAccount = createAccount();
|
||||||
|
existingAccount.setId(1);
|
||||||
|
existingAccount.setVersion(1);
|
||||||
|
final Account accountUpdate = new Account();
|
||||||
|
accountUpdate.setUsername("Test Update");
|
||||||
|
final Account updatedAccount = existingAccount;
|
||||||
|
updatedAccount.setUsername("Test Update");
|
||||||
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.of(existingAccount));
|
||||||
|
when(accountsRepository.save(any(Account.class))).thenReturn(updatedAccount);
|
||||||
|
|
||||||
|
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(Account.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_bindingResultHasErrors() {
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_accountsDtoIsNull() {
|
||||||
|
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, null, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_idIsNull() {
|
||||||
|
final ResponseEntity<Account> responseEntity = accountController.updateAccount(null, createAccount(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_accountDoesNotExist() {
|
||||||
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
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(Account.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccountById() {
|
||||||
|
doNothing().when(accountsRepository).deleteById(anyInt());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = accountController.deleteAccountById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
|
||||||
|
verify(accountsRepository).deleteById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccountById_idIsNull() {
|
||||||
|
final ResponseEntity responseEntity = accountController.deleteAccountById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(accountsRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Account createAccount() {
|
||||||
|
final Account account = new Account();
|
||||||
|
account.setUsername("Test username");
|
||||||
|
account.setPassword("test password");
|
||||||
|
account.setAdministratorStatus(true);
|
||||||
|
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
}
|
||||||
+227
@@ -0,0 +1,227 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
|
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.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
@WebMvcTest(controllers = DefinitionController.class)
|
||||||
|
public class DefinitionControllerTest {
|
||||||
|
@Mock private DefinitionRepository definitionRepository;
|
||||||
|
@InjectMocks private DefinitionController definitionController;
|
||||||
|
@Mock private BindingResult bindingResult;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllDefinitions() {
|
||||||
|
final Definition definitionDto = createDefinition();
|
||||||
|
final List<Definition> definitionList = new ArrayList<>();
|
||||||
|
definitionList.add(definitionDto);
|
||||||
|
definitionList.add(definitionDto);
|
||||||
|
|
||||||
|
when(definitionRepository.findAll()).thenReturn(definitionList);
|
||||||
|
|
||||||
|
final ResponseEntity<Iterable<Definition>> responseEntity = definitionController.getAllDefinitions();
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
|
responseEntity.getBody().forEach(definition -> assertEquals(definitionDto, definition));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDefinitionsById() {
|
||||||
|
final Definition definition = createDefinition();
|
||||||
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.ofNullable(definition));
|
||||||
|
|
||||||
|
final ResponseEntity<Definition> responseEntity = definitionController.getDefinitionById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertEquals(definition, responseEntity.getBody());
|
||||||
|
verify(definitionRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDefinitionById_nullId() {
|
||||||
|
final ResponseEntity responseEntity = definitionController.getDefinitionById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDefinitionById_noDefinitionFound() {
|
||||||
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = definitionController.getDefinitionById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
verify(definitionRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertDefinition() {
|
||||||
|
final Definition definition = createDefinition();
|
||||||
|
when(definitionRepository.save(any(Definition.class))).thenReturn(definition);
|
||||||
|
|
||||||
|
final ResponseEntity<Definition> responseEntity = definitionController.insertDefinition(definition, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
|
assertEquals(definition, responseEntity.getBody());
|
||||||
|
verify(definitionRepository).save(any(Definition.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertDefinition_definitionDtoIsNull() {
|
||||||
|
final ResponseEntity responseEntity = definitionController.insertDefinition(null, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertDefinition_bindingResultHasErrors() {
|
||||||
|
final Definition definition = createDefinition();
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = definitionController.insertDefinition(definition, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition() {
|
||||||
|
final Definition existingDefinition = createDefinition();
|
||||||
|
existingDefinition.setId(1);
|
||||||
|
existingDefinition.setVersion(1);
|
||||||
|
final Definition definitionUpdate = new Definition();
|
||||||
|
definitionUpdate.setName("Test Update");
|
||||||
|
final Definition updatedDefinition = existingDefinition;
|
||||||
|
updatedDefinition.setName("Test Update");
|
||||||
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.of(existingDefinition));
|
||||||
|
when(definitionRepository.save(any(Definition.class))).thenReturn(updatedDefinition);
|
||||||
|
|
||||||
|
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(Definition.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_bindingResultErrors() {
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_definitionDtoIsNull() {
|
||||||
|
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, null, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_idIsNull() {
|
||||||
|
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(null, createDefinition(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_definitionDoesntExist() {
|
||||||
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
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(Definition.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinitionById() {
|
||||||
|
doNothing().when(definitionRepository).deleteById(anyInt());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = definitionController.deleteDefinitionById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
|
||||||
|
verify(definitionRepository).deleteById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinitionById_nullId() {
|
||||||
|
final ResponseEntity responseEntity = definitionController.deleteDefinitionById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Definition createDefinition() {
|
||||||
|
final List<String> definitionList = new ArrayList<>();
|
||||||
|
definitionList.add("Test definition 1");
|
||||||
|
|
||||||
|
final List<String> notationList = new ArrayList<>();
|
||||||
|
notationList.add("\\testLaTeX");
|
||||||
|
|
||||||
|
final Definition definition = new Definition();
|
||||||
|
definition.setName("Test Name");
|
||||||
|
definition.setDefinition(definitionList);
|
||||||
|
definition.setNotation(notationList);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+364
@@ -0,0 +1,364 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
@WebMvcTest(controllers = TheoremController.class)
|
||||||
|
public class TheoremControllerTest {
|
||||||
|
@Mock private TheoremRepository theoremRepository;
|
||||||
|
@InjectMocks private TheoremController theoremController;
|
||||||
|
@Mock private BindingResult bindingResult;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheorems() {
|
||||||
|
final Theorem theoremDto = createTheorem();
|
||||||
|
final List<Theorem> listOfTheorems = new ArrayList<>();
|
||||||
|
listOfTheorems.add(theoremDto);
|
||||||
|
listOfTheorems.add(theoremDto);
|
||||||
|
|
||||||
|
when(theoremRepository.findAll()).thenReturn(listOfTheorems);
|
||||||
|
|
||||||
|
final ResponseEntity<Iterable<Theorem>> responseEntity = theoremController.getAllTheorems();
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
|
responseEntity.getBody().forEach(theorem -> assertEquals(theoremDto, theorem));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTheoremById() {
|
||||||
|
final Theorem theorem = createTheorem();
|
||||||
|
when(theoremRepository.findById(anyInt())).thenReturn(Optional.ofNullable(theorem));
|
||||||
|
|
||||||
|
final ResponseEntity<Theorem> responseEntity = theoremController.getTheoremById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertEquals(theorem, responseEntity.getBody());
|
||||||
|
verify(theoremRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTheoremById_nullId() {
|
||||||
|
final ResponseEntity responseEntity = theoremController.getTheoremById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTheoremById_noTheoremFound() {
|
||||||
|
when(theoremRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = theoremController.getTheoremById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
verify(theoremRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByBranch() {
|
||||||
|
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<Theorem>> responseEntity = theoremController.getAllTheoremsByBranch("test-branch");
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
|
responseEntity.getBody().forEach(theorem -> assertEquals(theoremDto, theorem));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByBranch_nullBranch() {
|
||||||
|
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByBranch(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByBranch_noTheoremsFound() {
|
||||||
|
when(theoremRepository.findByBranch(anyString())).thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByBranch("test_nonexistent_branch");
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByProvenStatus() {
|
||||||
|
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<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("true");
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
|
responseEntity.getBody().forEach(theorem -> assertEquals(theoremDto, theorem));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByProvenStatus_nullProvenStatus() {
|
||||||
|
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByProvenStatus_invalidProvenStatus() {
|
||||||
|
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("test");
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByProvenStatus_noTheoremsFound() {
|
||||||
|
when(theoremRepository.findByProvenStatus(anyBoolean())).thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("false");
|
||||||
|
|
||||||
|
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());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertTheorem() {
|
||||||
|
final Theorem theorem = createTheorem();
|
||||||
|
when(theoremRepository.save(any(Theorem.class))).thenReturn(theorem);
|
||||||
|
|
||||||
|
final ResponseEntity<Theorem> responseEntity = theoremController.insertTheorem(theorem, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
|
assertEquals(theorem, responseEntity.getBody());
|
||||||
|
verify(theoremRepository).save(any(Theorem.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertTheorem_theoremDtoIsNull() {
|
||||||
|
final ResponseEntity responseEntity = theoremController.insertTheorem(null, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertTheorem_bindingResultHasErrors() {
|
||||||
|
final Theorem theorem = createTheorem();
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = theoremController.insertTheorem(theorem, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTheorem() {
|
||||||
|
final Theorem existingTheorem = createTheorem();
|
||||||
|
existingTheorem.setId(1);
|
||||||
|
existingTheorem.setVersion(1);
|
||||||
|
final Theorem theoremUpdate = new Theorem();
|
||||||
|
theoremUpdate.setName("Test Update");
|
||||||
|
final Theorem updatedTheorem = existingTheorem;
|
||||||
|
updatedTheorem.setName("Test Update");
|
||||||
|
when(theoremRepository.findById(anyInt())).thenReturn(Optional.of(existingTheorem));
|
||||||
|
when(theoremRepository.save(any(Theorem.class))).thenReturn(updatedTheorem);
|
||||||
|
|
||||||
|
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(Theorem.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTheorem_bindingResultHasErrors() {
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(1, createTheorem(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTheorem_theoremDtoIsNull() {
|
||||||
|
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(1, null, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTheorem_idIsNull() {
|
||||||
|
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(null, createTheorem(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTheorem_theoremDoesNotExist() {
|
||||||
|
when(theoremRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
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(Theorem.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTheoremById() {
|
||||||
|
doNothing().when(theoremRepository).deleteById(anyInt());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = theoremController.deleteTheoremById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
|
||||||
|
verify(theoremRepository).deleteById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTheoremById_idIsNull() {
|
||||||
|
final ResponseEntity responseEntity = theoremController.deleteTheoremById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(theoremRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Theorem createTheorem() {
|
||||||
|
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 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 theorem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'edu.msudenver.tsp'
|
||||||
|
version '1.0'
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
sonarqube {
|
||||||
|
properties {
|
||||||
|
property "sonar.projectName", 'Theorem Prover Services'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(':persistence')
|
||||||
|
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.11'
|
||||||
|
compile group: 'org.apache.httpcomponents', name: 'fluent-hc', version: '4.5.7'
|
||||||
|
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'
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import edu.msudenver.tsp.services.factory.RequestFactory;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class RestService {
|
||||||
|
private static final Gson GSON = new Gson();
|
||||||
|
private final RequestFactory requestFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RestService(final RequestFactory requestFactory) {
|
||||||
|
this.requestFactory = requestFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean delete(final String uri, final Integer connectionTimeout, final Integer socketTimeout, final HttpStatus httpStatus) {
|
||||||
|
LOG.info("Sending DELETE {}", uri);
|
||||||
|
final Optional<HttpResponse> response = send(requestFactory.delete(uri), null, connectionTimeout, socketTimeout);
|
||||||
|
|
||||||
|
return response.isPresent() && response.get().getStatusLine().getStatusCode() == httpStatus.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
<T> Optional<T> get(final String uri, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout, final String auth) {
|
||||||
|
LOG.info("Sending GET {}", uri);
|
||||||
|
return send(requestFactory.get(uri), auth, connectionTimeout, socketTimeout, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
<T> Optional<T> post(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout) {
|
||||||
|
LOG.info("Sending POST {} with body: {}", uri, requestJson);
|
||||||
|
return send(requestFactory.post(uri, requestJson), null, connectionTimeout, socketTimeout, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<HttpResponse> post(final String uri, final String requestJson, final Integer connectionTimeout, final Integer socketTimeout) {
|
||||||
|
LOG.info("Sending POST {} with body: {}", uri, requestJson);
|
||||||
|
return send(requestFactory.post(uri, requestJson), null, connectionTimeout, socketTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
<T> Optional<T> put(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout, final String auth) {
|
||||||
|
LOG.info("Sending PUT {} with body: {}", uri, requestJson);
|
||||||
|
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);
|
||||||
|
if (optionalHttpResponse.isPresent()) {
|
||||||
|
final HttpResponse httpResponse = optionalHttpResponse.get();
|
||||||
|
LOG.info("Received {} response", httpResponse.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
final String jsonResponse = httpResponse.getEntity() == null ? null : EntityUtils.toString(httpResponse.getEntity());
|
||||||
|
if (StringUtils.isNotBlank(jsonResponse)) {
|
||||||
|
final T responses = GSON.fromJson(jsonResponse, type.getType());
|
||||||
|
if (responses instanceof List) {
|
||||||
|
LOG.info("Found {} responses.", ((List) responses).size());
|
||||||
|
if (((List) responses).isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.ofNullable(responses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Could not send request", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<HttpResponse> send(final Request request, final String auth, final Integer connectionTimeout, final Integer socketTimeout) {
|
||||||
|
if (StringUtils.isNotBlank(auth)) {
|
||||||
|
request.addHeader("Authorization", "Basic " + auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Optional.ofNullable(request.connectTimeout(connectionTimeout)
|
||||||
|
.socketTimeout(socketTimeout)
|
||||||
|
.execute()
|
||||||
|
.returnResponse());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Could not send request", e);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
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.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
private final RestService restService;
|
||||||
|
@Value("${persistence.api.connection.timeout.milliseconds}") private int connectionTimeoutMilliseconds;
|
||||||
|
@Value("${persistence.api.socket.timeout.milliseconds}") private int socketTimeoutMilliseconds;
|
||||||
|
@Value("${persistence.api.base.url}") private String persistenceApiBaseUrl;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UserService(final RestService restService) {
|
||||||
|
this.restService = restService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Account> createNewAccount(final Account account) {
|
||||||
|
if (account == null) {
|
||||||
|
LOG.error("Given null account, returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||||
|
final Optional<Account> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "/accounts/",
|
||||||
|
new GsonBuilder().create().toJson(account),
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.info("Unable to create new account {}", account.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package edu.msudenver.tsp.services.dto;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
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 = edu.msudenver.tsp.persistence.dto.Account.Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
||||||
|
@NotBlank(groups = edu.msudenver.tsp.persistence.dto.Account.Insert.class, message = "A password must be specified") @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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package edu.msudenver.tsp.services.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BaseDto implements Serializable {
|
||||||
|
private int id;
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5343705942114910963L;
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package edu.msudenver.tsp.services.factory;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RequestFactory {
|
||||||
|
public Request delete(final String uri) {
|
||||||
|
return Request.Delete(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Request get(final String uri) {
|
||||||
|
return Request.Get(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Request post(final String uri, final String requestJson) {
|
||||||
|
return StringUtils.isNotBlank(requestJson) ? Request.Post(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Post(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
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.Put(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Patch(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package edu.msudenver.tsp.services.parser;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
public class Node
|
||||||
|
{
|
||||||
|
@Getter private final String statement;
|
||||||
|
@Getter @Setter private Node left;
|
||||||
|
@Getter @Setter private Node right;
|
||||||
|
@Getter @Setter private Node center;
|
||||||
|
@Getter private final Node parent;
|
||||||
|
@Getter private final int depth;
|
||||||
|
|
||||||
|
public Node(final String statement, final Node parent)
|
||||||
|
{
|
||||||
|
this.statement = statement + "\n";
|
||||||
|
left = null;
|
||||||
|
right = null;
|
||||||
|
center = null;
|
||||||
|
this.parent = parent;
|
||||||
|
if(parent != null)
|
||||||
|
{
|
||||||
|
depth = parent.depth + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
depth = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
String returnVal = this.depth + ": " + this.statement;
|
||||||
|
|
||||||
|
if(this.left != null) returnVal += "... " + this.left.toString();
|
||||||
|
if(this.center != null) returnVal += "... " + this.center.toString();
|
||||||
|
if(this.right != null) returnVal += "... " + this.right.toString();
|
||||||
|
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package edu.msudenver.tsp.services.parser;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
class ParserService {
|
||||||
|
|
||||||
|
public boolean parseUserInput(final String userInput)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
final Node tree = parseRawInput(userInput);
|
||||||
|
retrieveStatements(tree);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch(final Exception e) {
|
||||||
|
LOG.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node parseRawInput(String input)
|
||||||
|
{
|
||||||
|
input = input.toLowerCase();
|
||||||
|
|
||||||
|
final Node root = new Node(input, null);
|
||||||
|
|
||||||
|
if(input.equals(""))
|
||||||
|
{
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
recurse(root);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recurse(final Node current)
|
||||||
|
{
|
||||||
|
int startIndex;
|
||||||
|
int endIndex;
|
||||||
|
final String statement;
|
||||||
|
|
||||||
|
if (current != null) {
|
||||||
|
statement = current.getStatement();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String nextStatement;
|
||||||
|
|
||||||
|
if(statement.contains("let"))
|
||||||
|
{
|
||||||
|
current.setLeft(new Node("let", current));
|
||||||
|
|
||||||
|
startIndex = statement.indexOf("let")+"let".length();
|
||||||
|
|
||||||
|
if(statement.contains("if")){
|
||||||
|
endIndex = statement.indexOf("if");
|
||||||
|
} else if(statement.contains("then")){
|
||||||
|
endIndex = statement.indexOf("then");
|
||||||
|
} else {
|
||||||
|
endIndex = statement.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
nextStatement = statement.substring(startIndex, endIndex);
|
||||||
|
|
||||||
|
current.getLeft().setCenter(new Node(nextStatement, current.getLeft()));
|
||||||
|
recurse(current.getLeft().getCenter());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(statement.contains("if"))
|
||||||
|
{
|
||||||
|
current.setCenter(new Node("if", current));
|
||||||
|
|
||||||
|
startIndex = statement.indexOf("if")+"if".length();
|
||||||
|
endIndex = (statement.contains("then") ? statement.indexOf("then") : statement.length());
|
||||||
|
nextStatement = statement.substring(startIndex, endIndex);
|
||||||
|
|
||||||
|
current.getCenter().setCenter(new Node(nextStatement, current.getCenter()));
|
||||||
|
recurse(current.getCenter().getCenter());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(current.getStatement().contains("then"))
|
||||||
|
{
|
||||||
|
current.setRight(new Node("then", current));
|
||||||
|
|
||||||
|
startIndex = statement.indexOf("then")+"then".length();
|
||||||
|
nextStatement = statement.substring(startIndex);
|
||||||
|
|
||||||
|
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||||
|
recurse(current.getRight().getCenter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> retrieveStatements(final Node parsedTree)
|
||||||
|
{
|
||||||
|
return populateStatementList(parsedTree, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> populateStatementList(final Node node, final ArrayList<String> statementList)
|
||||||
|
{
|
||||||
|
if(node == null)
|
||||||
|
{
|
||||||
|
return statementList;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String statement = node.getStatement().trim();
|
||||||
|
if(!(statement.contains("let") || statement.contains("if") || statement.contains("then")))
|
||||||
|
{
|
||||||
|
statementList.add(statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
populateStatementList(node.getLeft(), statementList);
|
||||||
|
populateStatementList(node.getCenter(), statementList);
|
||||||
|
populateStatementList(node.getRight(), statementList);
|
||||||
|
|
||||||
|
return statementList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
persistence.api.connection.timeout.milliseconds = 5000
|
||||||
|
persistence.api.socket.timeout.milliseconds = 10000
|
||||||
|
persistence.api.base.url = http://localhost:8090/
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package edu.msudenver.tsp.services.parser;
|
||||||
|
|
||||||
|
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.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class ParserServiceTest {
|
||||||
|
|
||||||
|
@Mock private ParserService mockParserService;
|
||||||
|
|
||||||
|
@InjectMocks private ParserService parserService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyStringEqualsEmptyString() {
|
||||||
|
final String expected = "0: \n";
|
||||||
|
final String actual = parserService.parseRawInput("").toString();
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUselessStringEqualsUselessString() {
|
||||||
|
final String expected = "0: cat\n";
|
||||||
|
final String actual = parserService.parseRawInput("cat").toString();
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSingleIfReturnsIfPlusEmptyString() {
|
||||||
|
final String expected = "0: if\n... 1: if\n... 2: \n\n";
|
||||||
|
final String actual = parserService.parseRawInput("if").toString();
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseCaseIfXIsEvenThenXSquaredIsEven() {
|
||||||
|
final String expected = "0: if x is even then x^2 is even\n" +
|
||||||
|
"... 1: if\n" +
|
||||||
|
"... 2: x is even \n" +
|
||||||
|
"... 1: then\n" +
|
||||||
|
"... 2: x^2 is even\n\n";
|
||||||
|
|
||||||
|
final String actual = parserService.parseRawInput("if x is even then x^2 is even").toString();
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLetXBeEvenThenXSquaredIsEven() {
|
||||||
|
final String expected = "0: let x be even. then x^2 is even.\n" +
|
||||||
|
"... 1: let\n" +
|
||||||
|
"... 2: x be even. \n" +
|
||||||
|
"... 1: then\n" +
|
||||||
|
"... 2: x^2 is even.\n\n";
|
||||||
|
|
||||||
|
final String actual = parserService.parseRawInput("Let x be even. Then x^2 is even.").toString();
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLetIfThen() {
|
||||||
|
final String expected = "0: let a. if b, then c.\n" +
|
||||||
|
"... 1: let\n" +
|
||||||
|
"... 2: a. \n" +
|
||||||
|
"... 1: if\n" +
|
||||||
|
"... 2: b, \n" +
|
||||||
|
"... 1: then\n" +
|
||||||
|
"... 2: c.\n\n";
|
||||||
|
|
||||||
|
final String actual = parserService.parseRawInput("Let a. If b, then c.").toString();
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLetStatementWithoutAnyIfOrThenStatements() {
|
||||||
|
final String expected = "0: let a be equal to b.\n" +
|
||||||
|
"... 1: let\n" +
|
||||||
|
"... 2: a be equal to b.\n\n";
|
||||||
|
|
||||||
|
final String actual = parserService.parseRawInput("Let a be equal to b.").toString();
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyStringReturnsEmptyList() {
|
||||||
|
final List<String> expectedList = new ArrayList<>();
|
||||||
|
expectedList.add("");
|
||||||
|
|
||||||
|
when(mockParserService.parseRawInput(anyString())).thenReturn(new Node("", null));
|
||||||
|
final List<String> actualList = parserService.retrieveStatements(mockParserService.parseRawInput(""));
|
||||||
|
|
||||||
|
assertEquals(expectedList, actualList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseCaseReturnsXIsEven() {
|
||||||
|
final List<String> expectedList = new ArrayList<>();
|
||||||
|
expectedList.add("x is even");
|
||||||
|
expectedList.add("x^2 is even");
|
||||||
|
|
||||||
|
final Node testNode = new Node("if x is even then x^2 is even", null);
|
||||||
|
testNode.setCenter(new Node("if", testNode));
|
||||||
|
testNode.getCenter().setCenter(new Node(" x is even ", testNode.getCenter()));
|
||||||
|
testNode.setRight(new Node("then", testNode));
|
||||||
|
testNode.getRight().setCenter(new Node(" x^2 is even", testNode.getRight()));
|
||||||
|
|
||||||
|
when(mockParserService.parseRawInput(anyString())).thenReturn(testNode);
|
||||||
|
final List<String> actualList = parserService.retrieveStatements(mockParserService.parseRawInput("baseCase"));
|
||||||
|
|
||||||
|
assertEquals(expectedList, actualList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDriveParseUserInput() {
|
||||||
|
final Node testNode = new Node("", null);
|
||||||
|
when(mockParserService.parseRawInput(anyString())).thenReturn(testNode);
|
||||||
|
when(mockParserService.retrieveStatements(testNode)).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
|
final boolean successfulTestDrive = parserService.parseUserInput("");
|
||||||
|
|
||||||
|
assertTrue(successfulTestDrive);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user