Compare commits
132 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd92307cf8 | ||
| 1e7e46fc66 | |||
| 53ba34db1e | |||
| 7305f444f8 | |||
|
|
34c74da321 | ||
|
|
dd6e98130d | ||
| 93774e7e11 | |||
| c5727c8d1a | |||
| 61c4b3de42 | |||
| 9dd7fb66f5 | |||
| 8127cb1647 | |||
| 12f7d7f359 | |||
| c8600b8bb4 | |||
| 091215f1eb | |||
| 67f77d6c9e | |||
| c75b243df8 | |||
| 609f018f9f | |||
| 7802e25310 | |||
|
|
1bddb2d646 | ||
| 36036b710d | |||
|
|
adbcd786f0 | ||
|
|
b1d4ed9719 | ||
| 765d8283d9 | |||
| 8724d6c2f8 | |||
| 5a44b5b793 | |||
| 6d1db048c8 | |||
| 69726a46a4 | |||
| ae88fd356d | |||
| bc0d631e6c | |||
| 92bea81ae5 | |||
| 978b58fe2c | |||
| 8a582614f9 | |||
| eedc7a3eee | |||
| 0bc56f57e6 | |||
|
|
cc7e6e0ed2 | ||
| e2e2b24f3d | |||
|
|
c715e98e81 | ||
|
|
6791f6c61f | ||
|
|
8f2968bc2b | ||
|
|
98f6b9e2b7 | ||
|
|
3b4753215c | ||
|
|
94440faa4d | ||
|
|
cf5135e5b0 | ||
|
|
7060f2e7e3 | ||
|
|
89f1c55f51 | ||
|
|
de5a69d619 | ||
| 296cf62be6 | |||
| f5dbdac990 | |||
| c9a2a978fc | |||
| d0cde837e9 | |||
| 07cdef3d44 | |||
| ab360abcf8 | |||
| 4622c49cee | |||
| f8a1d8bf89 | |||
| ba4c7502db | |||
| 1e15082fcc | |||
| 6b7cf5cd91 | |||
| 413a78f729 | |||
| 80f55c4879 | |||
|
|
ae15ec8073 | ||
| 8c79d9975e | |||
| 9695f5082a | |||
| f5f959b453 | |||
| f35777b5a6 | |||
| 748781f10f | |||
|
|
083c149a73 | ||
| 749a20c0fd | |||
|
|
b15ef858b0 | ||
|
|
860e5379e6 | ||
|
|
5479130178 | ||
|
|
f0cb7633c6 | ||
|
|
9f5d9e24f5 | ||
| 7b2d5c45a6 | |||
| b48094ba26 | |||
| 3853911b3c | |||
| 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 | |||
|
|
46122cbafd | ||
|
|
ffaf020b80 | ||
|
|
5d429b2c8e | ||
|
|
ced18dcc97 | ||
|
|
238908f4fa | ||
|
|
10b0a09690 | ||
|
|
ba37ffeb57 | ||
|
|
2dda30753e | ||
| f4c7b55b62 | |||
| f617ee7bd9 | |||
| c826185bba | |||
| 22e401062a | |||
| e9661fdf78 | |||
| 6d7979c179 | |||
| 11aa1f1cf7 | |||
| d6b18c2279 | |||
|
|
86c5e8123e | ||
| 2c3977e595 | |||
| 0e661bbf79 | |||
| a0753903b2 | |||
| 3762c10359 | |||
| 4999227e1b | |||
| ca8dc5c5df | |||
| 9d7673ebf2 | |||
| f6de79a3d4 | |||
| d8422f67d7 |
+13
-5
@@ -30,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
|
||||||
|
|||||||
+5
-9
@@ -70,7 +70,6 @@ subprojects {
|
|||||||
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')}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@@ -100,14 +99,18 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
compile group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.3'
|
||||||
compile 'org.codehaus.groovy:groovy-all:2.3.11'
|
compile 'org.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.22'
|
compile 'org.slf4j:slf4j-api:1.7.22'
|
||||||
compile "joda-time:joda-time:2.2"
|
compile "joda-time:joda-time:2.2"
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
|
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 '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')}
|
||||||
@@ -136,13 +139,6 @@ testSets {
|
|||||||
integrationTest
|
integrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
compileTestKotlin {
|
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapper {
|
wrapper {
|
||||||
gradleVersion = '5.2.1'
|
gradleVersion = '5.2.1'
|
||||||
distributionType = Wrapper.DistributionType.ALL
|
distributionType = Wrapper.DistributionType.ALL
|
||||||
|
|||||||
@@ -1,172 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
##
|
|
||||||
## Gradle start up script for UN*X
|
|
||||||
##
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
PRG="$0"
|
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
|
||||||
ls=`ls -ld "$PRG"`
|
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
|
||||||
PRG="$link"
|
|
||||||
else
|
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=`basename "$0"`
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS=""
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD="maximum"
|
|
||||||
|
|
||||||
warn ( ) {
|
|
||||||
echo "$*"
|
|
||||||
}
|
|
||||||
|
|
||||||
die ( ) {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "`uname`" in
|
|
||||||
CYGWIN* )
|
|
||||||
cygwin=true
|
|
||||||
;;
|
|
||||||
Darwin* )
|
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
||||||
else
|
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD="java"
|
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
ulimit -n $MAX_FD
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
|
||||||
if $cygwin ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=$((i+1))
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
(0) set -- ;;
|
|
||||||
(1) set -- "$args0" ;;
|
|
||||||
(2) set -- "$args0" "$args1" ;;
|
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Escape application args
|
|
||||||
save ( ) {
|
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
|
||||||
echo " "
|
|
||||||
}
|
|
||||||
APP_ARGS=$(save "$@")
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
|
||||||
|
|
||||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
|
||||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
|
||||||
cd "$(dirname "$0")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
||||||
BIN
Binary file not shown.
@@ -50,3 +50,11 @@ task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local d
|
|||||||
commandLine=['cmd','/c','loaddb.bat']
|
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'
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ create table accounts (
|
|||||||
id int not null auto_increment primary key unique,
|
id int not null auto_increment primary key unique,
|
||||||
username varchar(50) not null unique,
|
username varchar(50) not null unique,
|
||||||
password varchar(256) not null,
|
password varchar(256) not null,
|
||||||
administrator_status boolean default false,
|
administrator boolean default false,
|
||||||
last_login date,
|
last_login date,
|
||||||
version int default 1
|
version int default 1
|
||||||
);
|
);
|
||||||
insert into accounts (username, password, administrator_status)
|
insert into accounts (username, password, administrator)
|
||||||
values ('admin', 'secret', true),
|
values ('admin', 'secret', true),
|
||||||
('atusa', 'secret', true),
|
('atusa', 'secret', true),
|
||||||
('dantanxiaotian', 'secret', true),
|
('dantanxiaotian', 'secret', true),
|
||||||
@@ -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)
|
||||||
|
);
|
||||||
+14
-14
@@ -1,6 +1,6 @@
|
|||||||
package edu.msudenver.tsp.persistence;
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
import edu.msudenver.tsp.persistence.dto.Account;
|
||||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -19,8 +19,8 @@ public class AccountsIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCRUDFunctionality() {
|
public void testCRUDFunctionality() {
|
||||||
final AccountDto accountDto = createAccount();
|
final Account account = createAccount();
|
||||||
final AccountDto savedAccount = accountsRepository.save(accountDto);
|
final Account savedAccount = accountsRepository.save(account);
|
||||||
|
|
||||||
assertNotNull(savedAccount);
|
assertNotNull(savedAccount);
|
||||||
assertEquals(Integer.valueOf(0), savedAccount.getVersion());
|
assertEquals(Integer.valueOf(0), savedAccount.getVersion());
|
||||||
@@ -29,29 +29,29 @@ public class AccountsIntegrationTest {
|
|||||||
|
|
||||||
assertEquals("Test username", savedAccount.getUsername());
|
assertEquals("Test username", savedAccount.getUsername());
|
||||||
assertEquals("test password", savedAccount.getPassword());
|
assertEquals("test password", savedAccount.getPassword());
|
||||||
assertTrue(savedAccount.isAdministratorStatus());
|
assertTrue(savedAccount.isAdministrator());
|
||||||
|
|
||||||
savedAccount.setPassword("Test Update");
|
savedAccount.setPassword("Test Update");
|
||||||
|
|
||||||
final AccountDto updatedAccount = accountsRepository.save(savedAccount);
|
final Account updatedAccount = accountsRepository.save(savedAccount);
|
||||||
|
|
||||||
assertEquals("Test username", savedAccount.getUsername());
|
assertEquals("Test username", savedAccount.getUsername());
|
||||||
assertEquals("Test Update", savedAccount.getPassword());
|
assertEquals("Test Update", savedAccount.getPassword());
|
||||||
assertTrue(savedAccount.isAdministratorStatus());
|
assertTrue(savedAccount.isAdministrator());
|
||||||
assertEquals(updatedAccount.getId(), id);
|
assertEquals(updatedAccount.getId(), id);
|
||||||
|
|
||||||
accountsRepository.delete(accountDto);
|
accountsRepository.delete(account);
|
||||||
final Optional<AccountDto> deletedAccount = accountsRepository.findById(id);
|
final Optional<Account> deletedAccount = accountsRepository.findById(id);
|
||||||
assertFalse(deletedAccount.isPresent());
|
assertFalse(deletedAccount.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccountDto createAccount() {
|
private Account createAccount() {
|
||||||
final AccountDto accountDto = new AccountDto();
|
final Account account = new Account();
|
||||||
accountDto.setUsername("Test username");
|
account.setUsername("Test username");
|
||||||
accountDto.setPassword("test password");
|
account.setPassword("test password");
|
||||||
accountDto.setAdministratorStatus(true);
|
account.setAdministrator(true);
|
||||||
|
|
||||||
return accountDto;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-22
@@ -1,8 +1,6 @@
|
|||||||
package edu.msudenver.tsp.persistence;
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.Definition;
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
|
||||||
import edu.msudenver.tsp.persistence.dto.Notation;
|
|
||||||
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -23,8 +21,8 @@ public class DefinitionsIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCRUDFunctionality() {
|
public void testCRUDFunctionality() {
|
||||||
final DefinitionDto definitionDto = createDefinition();
|
final Definition definition = createDefinition();
|
||||||
final DefinitionDto savedDefinition = definitionRepository.save(definitionDto);
|
final Definition savedDefinition = definitionRepository.save(definition);
|
||||||
|
|
||||||
assertNotNull(savedDefinition);
|
assertNotNull(savedDefinition);
|
||||||
assertEquals(Integer.valueOf(0), savedDefinition.getVersion());
|
assertEquals(Integer.valueOf(0), savedDefinition.getVersion());
|
||||||
@@ -35,8 +33,8 @@ public class DefinitionsIntegrationTest {
|
|||||||
assertNotNull(savedDefinition.getDefinition());
|
assertNotNull(savedDefinition.getDefinition());
|
||||||
assertNotNull(savedDefinition.getNotation());
|
assertNotNull(savedDefinition.getNotation());
|
||||||
|
|
||||||
final List<String> definitionsList = savedDefinition.getDefinition().getDefinitions();
|
final List<String> definitionsList = savedDefinition.getDefinition();
|
||||||
final List<String> notationList = savedDefinition.getNotation().getNotations();
|
final List<String> notationList = savedDefinition.getNotation();
|
||||||
|
|
||||||
assertEquals(2, definitionsList.size());
|
assertEquals(2, definitionsList.size());
|
||||||
assertEquals(1, notationList.size());
|
assertEquals(1, notationList.size());
|
||||||
@@ -46,14 +44,14 @@ public class DefinitionsIntegrationTest {
|
|||||||
|
|
||||||
savedDefinition.setName("Test Update");
|
savedDefinition.setName("Test Update");
|
||||||
|
|
||||||
final DefinitionDto updatedDefinition = definitionRepository.save(savedDefinition);
|
final Definition updatedDefinition = definitionRepository.save(savedDefinition);
|
||||||
|
|
||||||
assertEquals("Test Update", updatedDefinition.getName());
|
assertEquals("Test Update", updatedDefinition.getName());
|
||||||
assertNotNull(updatedDefinition.getDefinition());
|
assertNotNull(updatedDefinition.getDefinition());
|
||||||
assertNotNull(updatedDefinition.getNotation());
|
assertNotNull(updatedDefinition.getNotation());
|
||||||
|
|
||||||
final List<String> updatedDefinitionsList = updatedDefinition.getDefinition().getDefinitions();
|
final List<String> updatedDefinitionsList = updatedDefinition.getDefinition();
|
||||||
final List<String> updatedNotationsList = updatedDefinition.getNotation().getNotations();
|
final List<String> updatedNotationsList = updatedDefinition.getNotation();
|
||||||
|
|
||||||
assertEquals(2, updatedDefinitionsList.size());
|
assertEquals(2, updatedDefinitionsList.size());
|
||||||
assertEquals(1, updatedNotationsList.size());
|
assertEquals(1, updatedNotationsList.size());
|
||||||
@@ -63,29 +61,23 @@ public class DefinitionsIntegrationTest {
|
|||||||
assertEquals(id, updatedDefinition.getId());
|
assertEquals(id, updatedDefinition.getId());
|
||||||
|
|
||||||
definitionRepository.delete(updatedDefinition);
|
definitionRepository.delete(updatedDefinition);
|
||||||
final Optional<DefinitionDto> deletedDefinition = definitionRepository.findById(id);
|
final Optional<Definition> deletedDefinition = definitionRepository.findById(id);
|
||||||
assertFalse(deletedDefinition.isPresent());
|
assertFalse(deletedDefinition.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefinitionDto createDefinition() {
|
private Definition createDefinition() {
|
||||||
final List<String> definitionList = new ArrayList<>();
|
final List<String> definitionList = new ArrayList<>();
|
||||||
definitionList.add("Test definition 1");
|
definitionList.add("Test definition 1");
|
||||||
definitionList.add("Test definition 2");
|
definitionList.add("Test definition 2");
|
||||||
|
|
||||||
final Definition definition = new Definition();
|
|
||||||
definition.setDefinitions(definitionList);
|
|
||||||
|
|
||||||
final List<String> notationList = new ArrayList<>();
|
final List<String> notationList = new ArrayList<>();
|
||||||
notationList.add("\\testLaTeX");
|
notationList.add("\\testLaTeX");
|
||||||
|
|
||||||
final Notation notation = new Notation();
|
final Definition definition = new Definition();
|
||||||
notation.setNotations(notationList);
|
definition.setName("Test Name");
|
||||||
|
definition.setDefinition(definitionList);
|
||||||
|
definition.setNotation(notationList);
|
||||||
|
|
||||||
final DefinitionDto definitionDto = new DefinitionDto();
|
return definition;
|
||||||
definitionDto.setName("Test Name");
|
|
||||||
definitionDto.setDefinition(definition);
|
|
||||||
definitionDto.setNotation(notation);
|
|
||||||
|
|
||||||
return definitionDto;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ public class PersistenceTestConfig {
|
|||||||
.create()
|
.create()
|
||||||
.username("panda")
|
.username("panda")
|
||||||
.password("secret")
|
.password("secret")
|
||||||
.url("jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false")
|
.url("jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false&serverTimezone=UTC")
|
||||||
.driverClassName("com.mysql.cj.jdbc.Driver")
|
.driverClassName("com.mysql.cj.jdbc.Driver")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,5 +105,6 @@ public class PersistenceApi {
|
|||||||
properties.setProperty("hibernate.id.new_generator_mappings","false");
|
properties.setProperty("hibernate.id.new_generator_mappings","false");
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+95
-44
@@ -1,6 +1,8 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
import edu.msudenver.tsp.persistence.dto.Account;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -14,6 +16,8 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.groups.Default;
|
import javax.validation.groups.Default;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -21,12 +25,13 @@ import java.util.Optional;
|
|||||||
@RestController
|
@RestController
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RequestMapping("/accounts")
|
@RequestMapping("/accounts")
|
||||||
|
@Validated
|
||||||
public class AccountController {
|
public class AccountController {
|
||||||
private final AccountsRepository accountsRepository;
|
private final AccountsRepository accountsRepository;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping({"","/"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<Iterable<AccountDto>> getListOfAccounts() {
|
ResponseEntity<Iterable<Account>> getListOfAccounts() {
|
||||||
LOG.info("Received request to list all accounts");
|
LOG.info("Received request to list all accounts");
|
||||||
|
|
||||||
LOG.debug("Querying for list of accounts");
|
LOG.debug("Querying for list of accounts");
|
||||||
@@ -34,59 +39,104 @@ public class AccountController {
|
|||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final List<AccountDto> listOfAccounts = (List<AccountDto>) accountsRepository.findAll();
|
final List<Account> listOfAccounts = (List<Account>) accountsRepository.findAll();
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Successfully completed query. Query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Successfully completed query. Query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
LOG.info("Returning list of all accounts with size of " + listOfAccounts.size());
|
LOG.info("Returning list of all accounts with size of {}", listOfAccounts.size());
|
||||||
|
|
||||||
return new ResponseEntity<>(listOfAccounts, HttpStatus.OK);
|
return new ResponseEntity<>(listOfAccounts, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/id")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<AccountDto> getAccountById(@PathVariable("id") final Integer id) {
|
ResponseEntity<Account> getAccountById(@RequestParam("id") final Integer id) throws BadRequestException {
|
||||||
LOG.info("Received request to query for account with id " + id);
|
LOG.info("Received request to query for account with id {}", id);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
LOG.error("ERROR: ID was null");
|
LOG.error("ERROR: ID was null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("ERROR: ID cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Querying for account with id " + id);
|
LOG.debug("Querying for account with id {}", id);
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final Optional<AccountDto> account = accountsRepository.findById(id);
|
final Optional<Account> account = accountsRepository.findById(id);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
return account.map(accountDto -> {
|
return account.map(accountDto -> {
|
||||||
LOG.info("Returning account with id " + id);
|
LOG.info("Returning account with id {}", id);
|
||||||
return new ResponseEntity<>(accountDto, HttpStatus.OK);
|
return new ResponseEntity<>(accountDto, HttpStatus.OK);
|
||||||
}).orElseGet(
|
}).orElseGet(
|
||||||
() -> {
|
() -> {
|
||||||
LOG.warn("No account was found with id " + id);
|
LOG.warn("No account was found with id {}", id);
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/")
|
@GetMapping("/username")
|
||||||
@Validated({AccountDto.Insert.class, Default.class})
|
public @ResponseBody
|
||||||
public @ResponseBody ResponseEntity<AccountDto> insertAccount(
|
ResponseEntity<Account> getAccountByUsername(@RequestParam("username") final String username) throws BadRequestException {
|
||||||
@Valid @RequestBody final AccountDto accountDto, final BindingResult bindingResult) {
|
LOG.info("Received request to query for account with username {}", username);
|
||||||
|
if (username == null) {
|
||||||
|
LOG.error("ERROR: username was null");
|
||||||
|
throw new BadRequestException("ERROR: Username cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
throws UnprocessableEntityException, BadRequestException {
|
||||||
|
|
||||||
LOG.info("Received request to insert a new account");
|
LOG.info("Received request to insert a new account");
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
LOG.error("Binding result is unprocessable");
|
LOG.error("Binding result is unprocessable");
|
||||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountDto == null) {
|
if (account == null) {
|
||||||
LOG.error("Passed account is unprocessable");
|
LOG.error("Passed account is unprocessable");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Passed account is unprocessable");
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
LOG.debug("Saving new account");
|
||||||
@@ -94,78 +144,79 @@ public class AccountController {
|
|||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final AccountDto savedAccount = accountsRepository.save(accountDto);
|
final Account savedAccount = accountsRepository.save(account);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
LOG.info("Returning the newly created account");
|
LOG.info("Returning the newly created account");
|
||||||
return new ResponseEntity<>(savedAccount, HttpStatus.CREATED);
|
return new ResponseEntity<>(savedAccount, HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/{id}")
|
@PatchMapping("/{id}")
|
||||||
public @ResponseBody ResponseEntity<AccountDto> updateAccount(
|
public @ResponseBody ResponseEntity<Account> updateAccount(
|
||||||
@PathVariable("id") final Integer id,
|
@PathVariable("id") final Integer id,
|
||||||
@RequestBody final AccountDto accountDto, final BindingResult bindingResult) {
|
@RequestBody final Account account, final BindingResult bindingResult)
|
||||||
|
throws UnprocessableEntityException, BadRequestException {
|
||||||
|
|
||||||
LOG.info("Received request to update an account");
|
LOG.info("Received request to update an account");
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
LOG.error("Binding result is unprocessable");
|
LOG.error("Binding result is unprocessable");
|
||||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountDto == null) {
|
if (account == null) {
|
||||||
LOG.error("Passed entity is null");
|
LOG.error("Passed entity is null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Passed account is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
LOG.error("Account ID must be specified");
|
LOG.error("Account ID must be specified");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Account ID must be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Checking for existence of account with id " + id);
|
LOG.debug("Checking for existence of account with id {}", id);
|
||||||
|
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final Optional<AccountDto> existingAccount = accountsRepository.findById(id);
|
final Optional<Account> existingAccount = accountsRepository.findById(id);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
if (!existingAccount.isPresent()) {
|
if (!existingAccount.isPresent()) {
|
||||||
LOG.error("No account associated with id " + id);
|
LOG.error("No account associated with id {}", id);
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistenceUtilities.copyNonNullProperties(accountDto, existingAccount.get());
|
PersistenceUtilities.copyNonNullProperties(account, existingAccount.get());
|
||||||
existingAccount.get().setVersion(existingAccount.get().getVersion()+ 1);
|
existingAccount.get().setVersion(existingAccount.get().getVersion()+ 1);
|
||||||
|
|
||||||
LOG.info("Updating account with id " + id);
|
LOG.info("Updating account with id {}", id);
|
||||||
LOG.debug("Querying for account with ID " + id);
|
LOG.debug("Querying for account with id {}", id);
|
||||||
|
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final AccountDto updatedAccount = accountsRepository.save(existingAccount.get());
|
final Account updatedAccount = accountsRepository.save(existingAccount.get());
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
return new ResponseEntity<>(updatedAccount, HttpStatus.OK);
|
return new ResponseEntity<>(updatedAccount, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public @ResponseBody ResponseEntity<Void> deleteAccountById(@PathVariable("id") final Integer id) {
|
public @ResponseBody ResponseEntity<Void> deleteAccountById(@PathVariable("id") final Integer id) throws BadRequestException {
|
||||||
LOG.info("Received request to delete account with id " + id);
|
LOG.info("Received request to delete account with id {}", id);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
LOG.error("Specified Id is null");
|
LOG.error("Specified Id is null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Specified ID is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Deleting account with id " + id);
|
LOG.debug("Deleting account with id {}", id);
|
||||||
|
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
@@ -174,7 +225,7 @@ public class AccountController {
|
|||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-49
@@ -1,6 +1,8 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -20,73 +22,76 @@ import java.util.Optional;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RequestMapping(path = "/definitions/")
|
@RequestMapping(path = "/definitions")
|
||||||
|
@Validated
|
||||||
public class DefinitionController {
|
public class DefinitionController {
|
||||||
private final DefinitionRepository definitionRepository;
|
private final DefinitionRepository definitionRepository;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping({"","/"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<Iterable<DefinitionDto>> getAllDefinitions() {
|
ResponseEntity<Iterable<Definition>> getAllDefinitions() {
|
||||||
LOG.info("Received request to list all definitions");
|
LOG.info("Received request to list all definitions");
|
||||||
|
|
||||||
LOG.debug("Querying for list of all definitions");
|
LOG.debug("Querying for list of all definitions");
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final List<DefinitionDto> listOfDefinitions = definitionRepository.findAll();
|
final List<Definition> listOfDefinitions = definitionRepository.findAll();
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Successfully completed query. Query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Successfully completed query. Query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
LOG.info("Returning list of all definition with size " + listOfDefinitions.size());
|
LOG.info("Returning list of all definition with size {}", listOfDefinitions.size());
|
||||||
|
|
||||||
return new ResponseEntity<>(listOfDefinitions, HttpStatus.OK);
|
return new ResponseEntity<>(listOfDefinitions, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<DefinitionDto> getDefinitionById(@PathVariable("id") final Integer id) {
|
ResponseEntity<Definition> getDefinitionById(@PathVariable("id") final Integer id)
|
||||||
LOG.info("Received request to query for definition with id " + id);
|
throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for definition with id {}", id);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
LOG.error("ERROR: ID was null");
|
LOG.error("ERROR: ID cannot be null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("ERROR: ID cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Querying for definition with id " + id);
|
LOG.debug("Querying for definition with id {}", id);
|
||||||
|
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final Optional<DefinitionDto> definition = definitionRepository.findById(id);
|
final Optional<Definition> definition = definitionRepository.findById(id);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
return definition.map(definitionDto -> {
|
return definition.map(definitionDto -> {
|
||||||
LOG.info("Returning definition with id " + id);
|
LOG.info("Returning definition with id {}", id);
|
||||||
return new ResponseEntity<>(definitionDto, HttpStatus.OK);
|
return new ResponseEntity<>(definitionDto, HttpStatus.OK);
|
||||||
}).orElseGet(
|
}).orElseGet(
|
||||||
() -> {
|
() -> {
|
||||||
LOG.warn("No definition was found with id " + id);
|
LOG.warn("No definition was found with id {}",id);
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/")
|
@PostMapping({"","/"})
|
||||||
@Validated({DefinitionDto.Insert.class, Default.class})
|
@Validated({Definition.Insert.class, Default.class})
|
||||||
public @ResponseBody ResponseEntity<DefinitionDto> insertDefinition(
|
public @ResponseBody ResponseEntity<Definition> insertDefinition(
|
||||||
@Valid @RequestBody final DefinitionDto definitionDto,
|
@Valid @RequestBody final Definition definition,
|
||||||
final BindingResult bindingResult) {
|
final BindingResult bindingResult)
|
||||||
|
throws UnprocessableEntityException, BadRequestException {
|
||||||
LOG.info("Received request to insert a new definition");
|
LOG.info("Received request to insert a new definition");
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
LOG.error("Binding result is unprocessable");
|
LOG.error("Binding result is unprocessable");
|
||||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (definitionDto == null) {
|
if (definition == null) {
|
||||||
LOG.error("Passed entity is unprocessable");
|
LOG.error("Passed entity is null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Passed definition is be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Saving new definition");
|
LOG.debug("Saving new definition");
|
||||||
@@ -94,78 +99,78 @@ public class DefinitionController {
|
|||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final DefinitionDto savedDefinition = definitionRepository.save(definitionDto);
|
final Definition savedDefinition = definitionRepository.save(definition);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
LOG.info("Returning the newly created definition with id " + savedDefinition.getId());
|
LOG.info("Returning the newly created definition with id {}", savedDefinition.getId());
|
||||||
return new ResponseEntity<>(savedDefinition, HttpStatus.CREATED);
|
return new ResponseEntity<>(savedDefinition, HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/{id}")
|
@PatchMapping("/{id}")
|
||||||
public @ResponseBody ResponseEntity<DefinitionDto> updateDefinition(
|
public @ResponseBody ResponseEntity<Definition> updateDefinition(
|
||||||
@PathVariable("id") final Integer id,
|
@PathVariable("id") final Integer id,
|
||||||
@RequestBody final DefinitionDto definitionDto, final BindingResult bindingResult) {
|
@RequestBody final Definition definition, final BindingResult bindingResult) throws UnprocessableEntityException, BadRequestException {
|
||||||
|
|
||||||
LOG.info("Received request to update an account");
|
LOG.info("Received request to update an account");
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
LOG.error("Binding result is unprocessable");
|
LOG.error("Binding result is unprocessable");
|
||||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (definitionDto == null) {
|
if (definition == null) {
|
||||||
LOG.error("Passed entity is null");
|
LOG.error("Passed entity is null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Passed definition is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
LOG.error("Definition ID must be specified");
|
LOG.error("Definition ID must be specified");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Definition ID must be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Checking for existence of definition with id " + id);
|
LOG.debug("Checking for existence of definition with id {}", id);
|
||||||
|
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final Optional<DefinitionDto> existingDefinition = definitionRepository.findById(id);
|
final Optional<Definition> existingDefinition = definitionRepository.findById(id);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
if (!existingDefinition.isPresent()) {
|
if (!existingDefinition.isPresent()) {
|
||||||
LOG.error("No definition associated with id " + id);
|
LOG.error("No definition associated with id {}", id);
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistenceUtilities.copyNonNullProperties(definitionDto, existingDefinition.get());
|
PersistenceUtilities.copyNonNullProperties(definition, existingDefinition.get());
|
||||||
existingDefinition.get().setVersion(existingDefinition.get().getVersion()+ 1);
|
existingDefinition.get().setVersion(existingDefinition.get().getVersion()+ 1);
|
||||||
|
|
||||||
LOG.info("Updating definition with id " + id);
|
LOG.info("Updating definition with id {}", id);
|
||||||
LOG.debug("Querying for definition with ID " + id);
|
LOG.debug("Querying for definition with id {}", id);
|
||||||
|
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final DefinitionDto updatedDefinition = definitionRepository.save(existingDefinition.get());
|
final Definition updatedDefinition = definitionRepository.save(existingDefinition.get());
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
return new ResponseEntity<>(updatedDefinition, HttpStatus.OK);
|
return new ResponseEntity<>(updatedDefinition, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public @ResponseBody ResponseEntity<Void> deleteDefinitionById(@PathVariable("id") final Integer id) {
|
public @ResponseBody ResponseEntity<Void> deleteDefinitionById(@PathVariable("id") final Integer id) throws BadRequestException {
|
||||||
LOG.info("Received request to delete definition with id " + id);
|
LOG.info("Received request to delete definition with id {}", id);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
LOG.error("Specified id is null");
|
LOG.error("Specified id is null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
throw new BadRequestException("Specified ID is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Deleting definition with id " + id);
|
LOG.debug("Deleting definition with id {}", id);
|
||||||
|
|
||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
@@ -174,7 +179,7 @@ public class DefinitionController {
|
|||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
LOG.debug("Received response from server: query took {}ms to complete", stopWatch.getTotalTimeMillis());
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||||
|
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||||
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class ExceptionHandlingController {
|
||||||
|
|
||||||
|
@ExceptionHandler(HttpMessageNotReadableException.class)
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
public void handleMessageNotReadableException(final HttpServletRequest request, final HttpMessageNotReadableException e) {
|
||||||
|
LOG.error("Unable to bind post data sent to: {} \nCaught Exception: {}", request.getRequestURI(), e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(ValidationException.class)
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
public String handleMessageInvalidRequest(final HttpServletRequest request, final ValidationException e) {
|
||||||
|
LOG.error("Request did not validate. Experienced the following error: {}", e.getMessage());
|
||||||
|
return "Request did not evaluate. Experienced the following error: " + e.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||||
|
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
|
||||||
|
public void handleHttpRequestMethodNotSupported(final HttpServletRequest request) {
|
||||||
|
LOG.error("Unsupported request method ({}) for URL: {}", request.getMethod(), request.getRequestURI());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
|
||||||
|
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
|
||||||
|
public void handleHttpMediaTypeNotSupportedException(final HttpServletRequest request, final HttpMediaTypeNotSupportedException e) {
|
||||||
|
LOG.error("Unsupported media type ({}) for URL: {}", e.getContentType(), request.getRequestURI());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
public void handleException(final HttpServletRequest request, final Exception e) {
|
||||||
|
LOG.error("Exception caught for URL: {}", request.getRequestURI(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
public List<String> handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) {
|
||||||
|
LOG.error("Request did not evaluate. Experienced the following error: {}", e.getMessage());
|
||||||
|
return e.getBindingResult().getFieldErrors().stream().map(x -> x.getField() + " " + x.getDefaultMessage()).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(BadRequestException.class)
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
public List<String> handleBadRequestException(final BadRequestException e) {
|
||||||
|
return e.getErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(UnprocessableEntityException.class)
|
||||||
|
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||||
|
public List<String> handleUnprocessableEntityException(final UnprocessableEntityException e) {
|
||||||
|
return Collections.singletonList("Request did not evaluate. Experienced the following error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.repository.NotationRepository;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class NotationController {
|
|
||||||
final private NotationRepository notationRepository;
|
|
||||||
}
|
|
||||||
+248
-3
@@ -1,11 +1,256 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
import edu.msudenver.tsp.persistence.repository.ProofRepository;
|
import edu.msudenver.tsp.persistence.repository.ProofRepository;
|
||||||
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.StopWatch;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@Component
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.groups.Default;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@RequestMapping("/proofs")
|
||||||
public class ProofController {
|
public class ProofController {
|
||||||
final private ProofRepository proofRepository;
|
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) throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for proof with id {}", id);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("ERROR: ID was null");
|
||||||
|
throw new BadRequestException("Specified ID is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for proofs related to the {} branch of mathematics", branch);
|
||||||
|
if (branch == null) {
|
||||||
|
LOG.error("ERROR: branch was null");
|
||||||
|
throw new BadRequestException("Specified branch is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for proofs of the theorem {}", theoremName);
|
||||||
|
if (theoremName == null) {
|
||||||
|
LOG.error("ERROR: theorem name was null");
|
||||||
|
throw new BadRequestException("Specified theorem name is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws UnprocessableEntityException, BadRequestException {
|
||||||
|
LOG.info("Received request to insert a new proof");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proof == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
throw new BadRequestException("Passed proof is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
throws UnprocessableEntityException, BadRequestException {
|
||||||
|
|
||||||
|
LOG.info("Received request to update a proof");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proof == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
throw new BadRequestException("Passed proof is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Proof ID must be specified");
|
||||||
|
throw new BadRequestException("Specified ID is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws BadRequestException {
|
||||||
|
LOG.info("Received request to delete proof with id {}", id);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Specified id is null");
|
||||||
|
throw new BadRequestException("Specified ID is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+277
-3
@@ -1,11 +1,285 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Theorem;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
||||||
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.StopWatch;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@Component
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.groups.Default;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@RequestMapping(path = "/theorems")
|
||||||
public class TheoremController {
|
public class TheoremController {
|
||||||
final private TheoremRepository theoremRepository;
|
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) throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for theorems related to the {} branch of mathematics", branch);
|
||||||
|
if (branch == null) {
|
||||||
|
LOG.error("ERROR: branch was null");
|
||||||
|
throw new BadRequestException("Specified branch is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for theorems whose proven status is {}", provenStatus);
|
||||||
|
if (provenStatus == null) {
|
||||||
|
LOG.error("ERROR: status was null");
|
||||||
|
throw new BadRequestException("Specified status is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for theorems whose name is {}", name);
|
||||||
|
if (name == null) {
|
||||||
|
LOG.error("ERROR: name was null");
|
||||||
|
throw new BadRequestException("Specified name is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws BadRequestException {
|
||||||
|
LOG.info("Received request to query for theorem with id {}", id);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("ERROR: ID was null");
|
||||||
|
throw new BadRequestException("Specified ID is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws UnprocessableEntityException, BadRequestException {
|
||||||
|
LOG.info("Received request to insert a new theorem");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theorem == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
throw new BadRequestException("Passed theorem is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws UnprocessableEntityException, BadRequestException {
|
||||||
|
|
||||||
|
LOG.info("Received request to update a theorem");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
throw new UnprocessableEntityException(bindingResult.getAllErrors().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theorem == null) {
|
||||||
|
LOG.error("Passed entity is null");
|
||||||
|
throw new BadRequestException("Passed theorem is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Theorem ID must be specified");
|
||||||
|
throw new BadRequestException("Specified ID is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) throws BadRequestException {
|
||||||
|
LOG.info("Received request to delete theorem with id {}", id);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Specified id is null");
|
||||||
|
throw new BadRequestException("Specified ID is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-8
@@ -5,10 +5,7 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.EntityListeners;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
@@ -19,13 +16,28 @@ import java.util.Date;
|
|||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class AccountDto extends BaseDto implements Serializable {
|
public class Account extends BaseDto implements Serializable {
|
||||||
@NotBlank(groups = Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
@NotBlank(groups = Insert.class, message = "A 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;
|
@NotBlank(groups = Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
||||||
@NotNull @JsonProperty("administrator_status") private boolean administratorStatus;
|
@NotNull private boolean administrator;
|
||||||
@Temporal(TemporalType.DATE) @JsonProperty("last_login") private Date lastLogin;
|
@Temporal(TemporalType.DATE) @Column(name = "last_login") private Date lastLogin;
|
||||||
|
|
||||||
public static final long serialVersionUID = 7095627971593953734L;
|
private static final long serialVersionUID = 7095627971593953734L;
|
||||||
|
|
||||||
|
@JsonProperty("last_login")
|
||||||
|
public Date getLastLogin() {
|
||||||
|
return lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("last_login")
|
||||||
|
public void setLastLogin(final Date lastLogin) {
|
||||||
|
this.lastLogin = lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
public interface Insert {}
|
public interface Insert {}
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
public void prePersist() {
|
||||||
|
lastLogin = new Date();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -36,5 +36,5 @@ public class BaseDto implements Serializable {
|
|||||||
@Version
|
@Version
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
public static final long serialVersionUID = -1686252381978213945L;
|
private static final long serialVersionUID = -1686252381978213945L;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,36 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Data;
|
||||||
import lombok.Setter;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
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.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
@Entity(name = "definitions")
|
||||||
@Setter
|
@Table(name = "definitions")
|
||||||
@ToString
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class Definition implements Serializable {
|
@Data
|
||||||
private List<String> definitions;
|
@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;
|
||||||
|
|
||||||
public static final long serialVersionUID = -2208496232532214840L;
|
@NotNull(groups = Insert.class, message = "At least one (1) definition must be specified")
|
||||||
|
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> definition;
|
||||||
|
|
||||||
|
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> notation;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5314619286352932857L;
|
||||||
|
|
||||||
|
public interface Insert {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.hibernate.annotations.Type;
|
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EntityListeners;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@Entity(name = "definitions")
|
|
||||||
@Table(name = "definitions")
|
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class DefinitionDto extends BaseDto implements Serializable {
|
|
||||||
@NotBlank(groups = Insert.class, message = "A name must be specified")
|
|
||||||
@Size(min = 1, max = 200, message = "Must be between 1 and 200 characters")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotBlank(groups = Insert.class, message = "At least one (1) definition must be specified")
|
|
||||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private Definition definition;
|
|
||||||
|
|
||||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private Notation notation;
|
|
||||||
|
|
||||||
public static final long serialVersionUID = -5314619286352932857L;
|
|
||||||
|
|
||||||
public interface Insert {}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
public class Notation implements Serializable {
|
|
||||||
private List<String> notations;
|
|
||||||
public static final long serialVersionUID = 2301438318932336121L;
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
public class NotationDto extends BaseDto {
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity(name = "proofs")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class Proof extends BaseDto implements Serializable {
|
||||||
|
@NotBlank(groups = Insert.class)
|
||||||
|
@Size(min = 1, max = 512, message = "The name must be at least 1 character and at most 512 characters")
|
||||||
|
@Column(name = "theorem_name")
|
||||||
|
private String theoremName;
|
||||||
|
@NotNull(groups = Insert.class)
|
||||||
|
@Size(min = 1, max = 4096, message = "The proof must be at least 1 character and at most 4096 characters")
|
||||||
|
private String proof;
|
||||||
|
@NotNull(groups = Insert.class)
|
||||||
|
private Integer theorem;
|
||||||
|
@NotBlank(groups = Insert.class)
|
||||||
|
@Size(min = 1, max = 512, message = "The branch must be at least 1 character and at most 512 characters")
|
||||||
|
private String branch;
|
||||||
|
@Type(type = "json") @Column(name = "referenced_definitions", columnDefinition = "jsonb") private List<String> referencedDefinitions;
|
||||||
|
@Type(type = "json") @Column(name = "referenced_theorems", columnDefinition = "jsonb") private List<String> referencedTheorems;
|
||||||
|
@Temporal(TemporalType.DATE) @Column(name = "date_created") private Date dateCreated;
|
||||||
|
@Temporal(TemporalType.DATE) @Column(name = "last_updated") private Date lastUpdated;
|
||||||
|
|
||||||
|
@JsonProperty("theorem_name")
|
||||||
|
public String getTheoremName() {
|
||||||
|
return theoremName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("theorem_name")
|
||||||
|
public void setTheoremName(final String theoremName) {
|
||||||
|
this.theoremName = theoremName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("referenced_definitions")
|
||||||
|
public List<String> getReferencedDefinitions() {
|
||||||
|
return referencedDefinitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("referenced_definitions")
|
||||||
|
public void setReferencedDefinitions(final List<String> referencedDefinitions) {
|
||||||
|
this.referencedDefinitions = referencedDefinitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("referenced_theorems")
|
||||||
|
public List<String> getReferencedTheorems() {
|
||||||
|
return referencedTheorems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("referenced_theorems")
|
||||||
|
public void setReferencedTheorems(final List<String> referencedTheorems) {
|
||||||
|
this.referencedTheorems = referencedTheorems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("date_created")
|
||||||
|
public Date getDateCreated() {
|
||||||
|
return dateCreated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("date_created")
|
||||||
|
public void setDateCreated(final Date dateCreated) {
|
||||||
|
this.dateCreated = dateCreated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("last_updated")
|
||||||
|
public Date getLastUpdated() {
|
||||||
|
return lastUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("last_updated")
|
||||||
|
public void setLastUpdated(final Date lastUpdated) {
|
||||||
|
this.lastUpdated = lastUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
public void prePersist() {
|
||||||
|
lastUpdated = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7731220940349760402L;
|
||||||
|
|
||||||
|
public interface Insert {}
|
||||||
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
public class ProofDto extends BaseDto {
|
|
||||||
}
|
|
||||||
@@ -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 {}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
|
||||||
|
|
||||||
public class TheoremDto extends BaseDto {
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
public enum TheoremType {
|
||||||
|
THEOREM, PROPOSITION, LEMMA, COROLLARY
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.exception;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BadRequestException extends Exception {
|
||||||
|
@Getter private final List<String> errors;
|
||||||
|
|
||||||
|
public BadRequestException(final String message) {
|
||||||
|
super(message);
|
||||||
|
errors = Collections.singletonList(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BadRequestException(final List<String> errorMessages) {
|
||||||
|
super(String.join(" ", errorMessages));
|
||||||
|
errors = errorMessages;
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.exception;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UnprocessableEntityException extends Exception {
|
||||||
|
@Getter
|
||||||
|
private final List<String> errors;
|
||||||
|
|
||||||
|
public UnprocessableEntityException(final String message) {
|
||||||
|
super(message);
|
||||||
|
errors = Collections.singletonList(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnprocessableEntityException(final List<String> errorMessages) {
|
||||||
|
super(String.join(" ", errorMessages));
|
||||||
|
errors = errorMessages;
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-2
@@ -1,9 +1,12 @@
|
|||||||
package edu.msudenver.tsp.persistence.repository;
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
import edu.msudenver.tsp.persistence.dto.Account;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface AccountsRepository extends CrudRepository<AccountDto, Integer> {
|
public interface AccountsRepository extends CrudRepository<Account, Integer> {
|
||||||
|
Optional<Account> findByUsername(String username);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
package edu.msudenver.tsp.persistence.repository;
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface DefinitionRepository extends JpaRepository<DefinitionDto, Integer> {
|
public interface DefinitionRepository extends JpaRepository<Definition, Integer> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.repository;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
|
|
||||||
public interface NotationRepository extends CrudRepository<BaseDto, Long> {
|
|
||||||
}
|
|
||||||
+11
-3
@@ -1,7 +1,15 @@
|
|||||||
package edu.msudenver.tsp.persistence.repository;
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
public interface ProofRepository extends CrudRepository<BaseDto, Long> {
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ProofRepository extends JpaRepository<Proof, Integer> {
|
||||||
|
|
||||||
|
List<Proof> findByBranch(String branch);
|
||||||
|
|
||||||
|
List<Proof> findByTheoremName(String name);
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-3
@@ -1,7 +1,17 @@
|
|||||||
package edu.msudenver.tsp.persistence.repository;
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
import edu.msudenver.tsp.persistence.dto.Theorem;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
public interface TheoremRepository extends CrudRepository<BaseDto, Long> {
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
spring.jpa.hibernate.ddl-auto = none
|
spring.jpa.hibernate.ddl-auto = none
|
||||||
spring.jpa.database=mysql
|
spring.jpa.database=mysql
|
||||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false
|
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false&serverTimezone=UTC
|
||||||
spring.datasource.username=panda
|
spring.datasource.username=panda
|
||||||
spring.datasource.password=secret
|
spring.datasource.password=secret
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|||||||
+111
-94
@@ -1,6 +1,8 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
import edu.msudenver.tsp.persistence.dto.Account;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -25,58 +27,51 @@ import static org.mockito.Mockito.*;
|
|||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
@WebMvcTest(controllers = AccountController.class)
|
@WebMvcTest(controllers = AccountController.class)
|
||||||
public class AccountControllerTest {
|
public class AccountControllerTest {
|
||||||
@Mock
|
@Mock private AccountsRepository accountsRepository;
|
||||||
private AccountsRepository accountsRepository;
|
@InjectMocks private AccountController accountController;
|
||||||
@InjectMocks
|
|
||||||
private AccountController accountController;
|
|
||||||
@Mock private BindingResult bindingResult;
|
@Mock private BindingResult bindingResult;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllAccounts() {
|
public void testGetAllAccounts() {
|
||||||
final AccountDto accountDto = createAccount();
|
final Account accountDto = createAccount();
|
||||||
final List<AccountDto> accountDtoList = new ArrayList<>();
|
final List<Account> accountList = new ArrayList<>();
|
||||||
accountDtoList.add(accountDto);
|
accountList.add(accountDto);
|
||||||
accountDtoList.add(accountDto);
|
accountList.add(accountDto);
|
||||||
|
|
||||||
when(accountsRepository.findAll()).thenReturn(accountDtoList);
|
when(accountsRepository.findAll()).thenReturn(accountList);
|
||||||
|
|
||||||
final ResponseEntity<Iterable<AccountDto>> responseEntity = accountController.getListOfAccounts();
|
final ResponseEntity<Iterable<Account>> responseEntity = accountController.getListOfAccounts();
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
responseEntity.getBody().forEach(account -> assertEquals(account, accountDto));
|
responseEntity.getBody().forEach(account -> assertEquals(accountDto, account));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccountById() {
|
public void testGetAccountById() throws BadRequestException {
|
||||||
final AccountDto accountDto = createAccount();
|
final Account account = createAccount();
|
||||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.ofNullable(accountDto));
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.ofNullable(account));
|
||||||
|
|
||||||
final ResponseEntity<AccountDto> responseEntity = accountController.getAccountById(1);
|
final ResponseEntity<Account> responseEntity = accountController.getAccountById(1);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertEquals(accountDto, responseEntity.getBody());
|
assertEquals(account, responseEntity.getBody());
|
||||||
verify(accountsRepository).findById(anyInt());
|
verify(accountsRepository).findById(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = BadRequestException.class)
|
||||||
public void testGetAccountById_nullId() {
|
public void testGetAccountById_nullId() throws BadRequestException {
|
||||||
final ResponseEntity responseEntity = accountController.getAccountById(null);
|
accountController.getAccountById(null);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertFalse(responseEntity.hasBody());
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
|
||||||
verifyZeroInteractions(accountsRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccountById_noAccountFound() {
|
public void testGetAccountById_noAccountFound() throws BadRequestException {
|
||||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
final ResponseEntity responseEntity = accountController.getAccountById(1);
|
final ResponseEntity responseEntity = accountController.getAccountById(1);
|
||||||
@@ -88,22 +83,69 @@ public class AccountControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInsertAccount() {
|
public void testGetAccountByUsername() throws BadRequestException {
|
||||||
final AccountDto accountDto = createAccount();
|
final Account account = createAccount();
|
||||||
when(accountsRepository.save(any(AccountDto.class))).thenReturn(accountDto);
|
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.ofNullable(account));
|
||||||
|
|
||||||
final ResponseEntity<AccountDto> responseEntity = accountController.insertAccount(accountDto, bindingResult);
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetAccountById_nullUsername() throws BadRequestException {
|
||||||
|
accountController.getAccountByUsername(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountByUsername_noAccountFound() throws BadRequestException {
|
||||||
|
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() throws UnprocessableEntityException, BadRequestException {
|
||||||
|
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);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertEquals(accountDto, responseEntity.getBody());
|
assertEquals(account, responseEntity.getBody());
|
||||||
verify(accountsRepository).save(any(AccountDto.class));
|
verify(accountsRepository).save(any(Account.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInsertAccount_accountsDtoIsNull() {
|
public void testInsertAccount_usernameAlreadyExists() throws UnprocessableEntityException, BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testInsertAccount_accountsDtoIsNull() throws UnprocessableEntityException, BadRequestException {
|
||||||
final ResponseEntity responseEntity = accountController.insertAccount(null, bindingResult);
|
final ResponseEntity responseEntity = accountController.insertAccount(null, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
@@ -112,87 +154,67 @@ public class AccountControllerTest {
|
|||||||
verifyZeroInteractions(accountsRepository);
|
verifyZeroInteractions(accountsRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = UnprocessableEntityException.class)
|
||||||
public void testInsertAccount_bindingResultHasErrors() {
|
public void testInsertAccount_bindingResultHasErrors() throws UnprocessableEntityException, BadRequestException {
|
||||||
final AccountDto definitionDto = createAccount();
|
final Account account = createAccount();
|
||||||
when(bindingResult.hasErrors()).thenReturn(true);
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
final ResponseEntity responseEntity = accountController.insertAccount(definitionDto, bindingResult);
|
accountController.insertAccount(account, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertFalse(responseEntity.hasBody());
|
|
||||||
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
|
||||||
verifyZeroInteractions(accountsRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAccount() {
|
public void testUpdateAccount() throws UnprocessableEntityException, BadRequestException {
|
||||||
final AccountDto existingAccount = createAccount();
|
final Account existingAccount = createAccount();
|
||||||
existingAccount.setId(1);
|
existingAccount.setId(1);
|
||||||
existingAccount.setVersion(1);
|
existingAccount.setVersion(1);
|
||||||
final AccountDto accountUpdate = new AccountDto();
|
final Account accountUpdate = new Account();
|
||||||
accountUpdate.setUsername("Test Update");
|
accountUpdate.setUsername("Test Update");
|
||||||
final AccountDto updatedAccount = existingAccount;
|
final Account updatedAccount = existingAccount;
|
||||||
updatedAccount.setUsername("Test Update");
|
updatedAccount.setUsername("Test Update");
|
||||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.of(existingAccount));
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.of(existingAccount));
|
||||||
when(accountsRepository.save(any(AccountDto.class))).thenReturn(updatedAccount);
|
when(accountsRepository.save(any(Account.class))).thenReturn(updatedAccount);
|
||||||
|
|
||||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, accountUpdate, bindingResult);
|
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, accountUpdate, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertEquals(updatedAccount, responseEntity.getBody());
|
assertEquals(updatedAccount, responseEntity.getBody());
|
||||||
verify(accountsRepository).findById(anyInt());
|
verify(accountsRepository).findById(anyInt());
|
||||||
verify(accountsRepository).save(any(AccountDto.class));
|
verify(accountsRepository).save(any(Account.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = UnprocessableEntityException.class)
|
||||||
public void testUpdateAccount_bindingResultHasErrors() {
|
public void testUpdateAccount_bindingResultHasErrors() throws UnprocessableEntityException, BadRequestException {
|
||||||
when(bindingResult.hasErrors()).thenReturn(true);
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
accountController.updateAccount(1, createAccount(), bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
@Test(expected = BadRequestException.class)
|
||||||
assertFalse(responseEntity.hasBody());
|
public void testUpdateAccount_accountsDtoIsNull() throws UnprocessableEntityException, BadRequestException {
|
||||||
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
accountController.updateAccount(1, null, bindingResult);
|
||||||
verifyZeroInteractions(accountsRepository);
|
}
|
||||||
|
|
||||||
|
@Test(expected = BadRequestException.class)
|
||||||
|
public void testUpdateAccount_idIsNull() throws UnprocessableEntityException, BadRequestException {
|
||||||
|
accountController.updateAccount(null, createAccount(), bindingResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAccount_accountsDtoIsNull() {
|
public void testUpdateAccount_accountDoesNotExist() throws UnprocessableEntityException, BadRequestException {
|
||||||
final ResponseEntity<AccountDto> 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<AccountDto> 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());
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
final ResponseEntity<Account> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
verify(accountsRepository, times(0)).save(any(AccountDto.class));
|
verify(accountsRepository, times(0)).save(any(Account.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteAccountById() {
|
public void testDeleteAccountById() throws BadRequestException {
|
||||||
doNothing().when(accountsRepository).deleteById(anyInt());
|
doNothing().when(accountsRepository).deleteById(anyInt());
|
||||||
|
|
||||||
final ResponseEntity responseEntity = accountController.deleteAccountById(1);
|
final ResponseEntity responseEntity = accountController.deleteAccountById(1);
|
||||||
@@ -203,22 +225,17 @@ public class AccountControllerTest {
|
|||||||
verify(accountsRepository).deleteById(anyInt());
|
verify(accountsRepository).deleteById(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = BadRequestException.class)
|
||||||
public void testDeleteAccountById_idIsNull() {
|
public void testDeleteAccountById_idIsNull() throws BadRequestException {
|
||||||
final ResponseEntity responseEntity = accountController.deleteAccountById(null);
|
accountController.deleteAccountById(null);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertFalse(responseEntity.hasBody());
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
|
||||||
verifyZeroInteractions(accountsRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccountDto createAccount() {
|
private Account createAccount() {
|
||||||
final AccountDto accountDto = new AccountDto();
|
final Account account = new Account();
|
||||||
accountDto.setUsername("Test username");
|
account.setUsername("Test username");
|
||||||
accountDto.setPassword("test password");
|
account.setPassword("test password");
|
||||||
accountDto.setAdministratorStatus(true);
|
account.setAdministrator(true);
|
||||||
|
|
||||||
return accountDto;
|
return account;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+64
-105
@@ -1,8 +1,8 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.Definition;
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
import edu.msudenver.tsp.persistence.dto.Notation;
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -32,50 +32,45 @@ public class DefinitionControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllDefinitions() {
|
public void testGetAllDefinitions() {
|
||||||
final DefinitionDto definitionDto = createDefinition();
|
final Definition definitionDto = createDefinition();
|
||||||
final List<DefinitionDto> definitionDtoList = new ArrayList<>();
|
final List<Definition> definitionList = new ArrayList<>();
|
||||||
definitionDtoList.add(definitionDto);
|
definitionList.add(definitionDto);
|
||||||
definitionDtoList.add(definitionDto);
|
definitionList.add(definitionDto);
|
||||||
|
|
||||||
when(definitionRepository.findAll()).thenReturn(definitionDtoList);
|
when(definitionRepository.findAll()).thenReturn(definitionList);
|
||||||
|
|
||||||
final ResponseEntity<Iterable<DefinitionDto>> responseEntity = definitionController.getAllDefinitions();
|
final ResponseEntity<Iterable<Definition>> responseEntity = definitionController.getAllDefinitions();
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
responseEntity.getBody().forEach(definition -> assertEquals(definition, definitionDto));
|
responseEntity.getBody().forEach(definition -> assertEquals(definitionDto, definition));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDefinitionsById() {
|
public void testGetDefinitionsById() throws BadRequestException {
|
||||||
final DefinitionDto definitionDto = createDefinition();
|
final Definition definition = createDefinition();
|
||||||
when(definitionRepository.findById(anyInt())).thenReturn(Optional.ofNullable(definitionDto));
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.ofNullable(definition));
|
||||||
|
|
||||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.getDefinitionById(1);
|
final ResponseEntity<Definition> responseEntity = definitionController.getDefinitionById(1);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertEquals(definitionDto, responseEntity.getBody());
|
assertEquals(definition, responseEntity.getBody());
|
||||||
verify(definitionRepository).findById(anyInt());
|
verify(definitionRepository).findById(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = BadRequestException.class)
|
||||||
public void testGetDefinitionById_nullId() {
|
public void testGetDefinitionById_nullId() throws BadRequestException {
|
||||||
final ResponseEntity responseEntity = definitionController.getDefinitionById(null);
|
definitionController.getDefinitionById(null);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertFalse(responseEntity.hasBody());
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
|
||||||
verifyZeroInteractions(definitionRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDefinitionById_noDefinitionFound() {
|
public void testGetDefinitionById_noDefinitionFound() throws BadRequestException {
|
||||||
when(definitionRepository.findById(anyInt())).thenReturn(Optional.empty());
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
final ResponseEntity responseEntity = definitionController.getDefinitionById(1);
|
final ResponseEntity responseEntity = definitionController.getDefinitionById(1);
|
||||||
@@ -87,111 +82,86 @@ public class DefinitionControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInsertDefinition() {
|
public void testInsertDefinition() throws BadRequestException, UnprocessableEntityException {
|
||||||
final DefinitionDto definitionDto = createDefinition();
|
final Definition definition = createDefinition();
|
||||||
when(definitionRepository.save(any(DefinitionDto.class))).thenReturn(definitionDto);
|
when(definitionRepository.save(any(Definition.class))).thenReturn(definition);
|
||||||
|
|
||||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.insertDefinition(definitionDto, bindingResult);
|
final ResponseEntity<Definition> responseEntity = definitionController.insertDefinition(definition, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertEquals(definitionDto, responseEntity.getBody());
|
assertEquals(definition, responseEntity.getBody());
|
||||||
verify(definitionRepository).save(any(DefinitionDto.class));
|
verify(definitionRepository).save(any(Definition.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = BadRequestException.class)
|
||||||
public void testInsertDefinition_definitionDtoIsNull() {
|
public void testInsertDefinition_definitionDtoIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
final ResponseEntity responseEntity = definitionController.insertDefinition(null, bindingResult);
|
definitionController.insertDefinition(null, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertFalse(responseEntity.hasBody());
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
|
||||||
verifyZeroInteractions(definitionRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = UnprocessableEntityException.class)
|
||||||
public void testInsertDefinition_bindingResultHasErrors() {
|
public void testInsertDefinition_bindingResultHasErrors() throws BadRequestException, UnprocessableEntityException {
|
||||||
final DefinitionDto definitionDto = createDefinition();
|
final Definition definition = createDefinition();
|
||||||
when(bindingResult.hasErrors()).thenReturn(true);
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
final ResponseEntity responseEntity = definitionController.insertDefinition(definitionDto, bindingResult);
|
definitionController.insertDefinition(definition, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertFalse(responseEntity.hasBody());
|
|
||||||
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
|
||||||
verifyZeroInteractions(definitionRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateDefinition() {
|
public void testUpdateDefinition() throws BadRequestException, UnprocessableEntityException {
|
||||||
final DefinitionDto existingDefinition = createDefinition();
|
final Definition existingDefinition = createDefinition();
|
||||||
existingDefinition.setId(1);
|
existingDefinition.setId(1);
|
||||||
existingDefinition.setVersion(1);
|
existingDefinition.setVersion(1);
|
||||||
final DefinitionDto definitionUpdate = new DefinitionDto();
|
final Definition definitionUpdate = new Definition();
|
||||||
definitionUpdate.setName("Test Update");
|
definitionUpdate.setName("Test Update");
|
||||||
final DefinitionDto updatedDefinition = existingDefinition;
|
final Definition updatedDefinition = existingDefinition;
|
||||||
updatedDefinition.setName("Test Update");
|
updatedDefinition.setName("Test Update");
|
||||||
when(definitionRepository.findById(anyInt())).thenReturn(Optional.of(existingDefinition));
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.of(existingDefinition));
|
||||||
when(definitionRepository.save(any(DefinitionDto.class))).thenReturn(updatedDefinition);
|
when(definitionRepository.save(any(Definition.class))).thenReturn(updatedDefinition);
|
||||||
|
|
||||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(1, definitionUpdate, bindingResult);
|
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, definitionUpdate, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertEquals(updatedDefinition, responseEntity.getBody());
|
assertEquals(updatedDefinition, responseEntity.getBody());
|
||||||
verify(definitionRepository).findById(anyInt());
|
verify(definitionRepository).findById(anyInt());
|
||||||
verify(definitionRepository).save(any(DefinitionDto.class));
|
verify(definitionRepository).save(any(Definition.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = UnprocessableEntityException.class)
|
||||||
public void testUpdateDefinition_bindingResultErrors() {
|
public void testUpdateDefinition_bindingResultErrors() throws BadRequestException, UnprocessableEntityException {
|
||||||
when(bindingResult.hasErrors()).thenReturn(true);
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
@Test(expected = BadRequestException.class)
|
||||||
assertFalse(responseEntity.hasBody());
|
public void testUpdateDefinition_definitionDtoIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
definitionController.updateDefinition(1, null, bindingResult);
|
||||||
verifyZeroInteractions(definitionRepository);
|
}
|
||||||
|
|
||||||
|
@Test(expected = BadRequestException.class)
|
||||||
|
public void testUpdateDefinition_idIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
definitionController.updateDefinition(null, createDefinition(), bindingResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateDefinition_definitionDtoIsNull() {
|
public void testUpdateDefinition_definitionDoesntExist() throws BadRequestException, UnprocessableEntityException {
|
||||||
final ResponseEntity<DefinitionDto> 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<DefinitionDto> 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());
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
final ResponseEntity<DefinitionDto> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
final ResponseEntity<Definition> responseEntity = definitionController.updateDefinition(1, createDefinition(), bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
verify(definitionRepository, times(0)).save(any(DefinitionDto.class));
|
verify(definitionRepository, times(0)).save(any(Definition.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteDefinitionById() {
|
public void testDeleteDefinitionById() throws BadRequestException {
|
||||||
doNothing().when(definitionRepository).deleteById(anyInt());
|
doNothing().when(definitionRepository).deleteById(anyInt());
|
||||||
|
|
||||||
final ResponseEntity responseEntity = definitionController.deleteDefinitionById(1);
|
final ResponseEntity responseEntity = definitionController.deleteDefinitionById(1);
|
||||||
@@ -202,34 +172,23 @@ public class DefinitionControllerTest {
|
|||||||
verify(definitionRepository).deleteById(anyInt());
|
verify(definitionRepository).deleteById(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = BadRequestException.class)
|
||||||
public void testDeleteDefinitionById_nullId() {
|
public void testDeleteDefinitionById_nullId() throws BadRequestException {
|
||||||
final ResponseEntity responseEntity = definitionController.deleteDefinitionById(null);
|
definitionController.deleteDefinitionById(null);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertFalse(responseEntity.hasBody());
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
|
||||||
verifyZeroInteractions(definitionRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefinitionDto createDefinition() {
|
private Definition createDefinition() {
|
||||||
final List<String> definitionList = new ArrayList<>();
|
final List<String> definitionList = new ArrayList<>();
|
||||||
definitionList.add("Test definition 1");
|
definitionList.add("Test definition 1");
|
||||||
|
|
||||||
final Definition definition = new Definition();
|
|
||||||
definition.setDefinitions(definitionList);
|
|
||||||
|
|
||||||
final List<String> notationList = new ArrayList<>();
|
final List<String> notationList = new ArrayList<>();
|
||||||
notationList.add("\\testLaTeX");
|
notationList.add("\\testLaTeX");
|
||||||
|
|
||||||
final Notation notation = new Notation();
|
final Definition definition = new Definition();
|
||||||
notation.setNotations(notationList);
|
definition.setName("Test Name");
|
||||||
|
definition.setDefinition(definitionList);
|
||||||
|
definition.setNotation(notationList);
|
||||||
|
|
||||||
final DefinitionDto definitionDto = new DefinitionDto();
|
return definition;
|
||||||
definitionDto.setName("Test Name");
|
|
||||||
definitionDto.setDefinition(definition);
|
|
||||||
definitionDto.setNotation(notation);
|
|
||||||
|
|
||||||
return definitionDto;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class ExceptionHandlingControllerTest {
|
||||||
|
@Mock
|
||||||
|
ExceptionHandlingController exceptionHandlingController;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleMessageNotReadableException() {
|
||||||
|
exceptionHandlingController.handleMessageNotReadableException(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleMessageInvalidRequestException() {
|
||||||
|
exceptionHandlingController.handleMessageInvalidRequest(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleHttpRequestMethodNotSupportedException() {
|
||||||
|
exceptionHandlingController.handleHttpRequestMethodNotSupported(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleHttpMediaTypeNotSupportedException() {
|
||||||
|
exceptionHandlingController.handleHttpMediaTypeNotSupportedException(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleException() {
|
||||||
|
exceptionHandlingController.handleException(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleMethodArgumentNotValidException() {
|
||||||
|
exceptionHandlingController.handleMethodArgumentNotValidException(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleBadRequestException() {
|
||||||
|
exceptionHandlingController.handleBadRequestException(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleUnprocessableEntityException() {
|
||||||
|
exceptionHandlingController.handleUnprocessableEntityException(any());
|
||||||
|
}
|
||||||
|
}
|
||||||
+267
@@ -0,0 +1,267 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Proof;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
|
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() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetAllProfsByBranch_nullBranch() throws BadRequestException {
|
||||||
|
proofController.getAllProofsByBranch(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllProofsByBranch_noProofsFound() throws BadRequestException {
|
||||||
|
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() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetAllProofsByTheoremName_nullTheoremName() throws BadRequestException {
|
||||||
|
proofController.getAllProofsByTheoremName(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllProofsByTheoremName_noProofsFound() throws BadRequestException {
|
||||||
|
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() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetProofById_nullId() throws BadRequestException {
|
||||||
|
proofController.getProofById(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProofById_noProofFound() throws BadRequestException {
|
||||||
|
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() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testInsertProof_proofDtoIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
proofController.insertProof(null, bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnprocessableEntityException.class)
|
||||||
|
public void testInsertProof_bindingResultHasErrors() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
final Proof proof = createProof();
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
proofController.insertProof(proof, bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateProof() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
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(expected = UnprocessableEntityException.class)
|
||||||
|
public void testUpdateProof_bindingResultHasErrors() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
proofController.updateProof(1, createProof(), bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = BadRequestException.class)
|
||||||
|
public void testUpdateProof_proofDtoIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
proofController.updateProof(1, null, bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = BadRequestException.class)
|
||||||
|
public void testUpdateProof_idIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
proofController.updateProof(null, createProof(), bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateProof_theoremDoesNotExist() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
when(proofRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity<Proof> responseEntity = proofController.updateProof(1, createProof(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
verify(proofRepository, times(0)).save(any(Proof.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteProofById() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testDeleteProofById_idIsNull() throws BadRequestException {
|
||||||
|
proofController.deleteProofById(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+316
@@ -0,0 +1,316 @@
|
|||||||
|
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.exception.BadRequestException;
|
||||||
|
import edu.msudenver.tsp.persistence.exception.UnprocessableEntityException;
|
||||||
|
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() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetTheoremById_nullId() throws BadRequestException {
|
||||||
|
theoremController.getTheoremById(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTheoremById_noTheoremFound() throws BadRequestException {
|
||||||
|
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() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetAllTheoremsByBranch_nullBranch() throws BadRequestException {
|
||||||
|
theoremController.getAllTheoremsByBranch(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByBranch_noTheoremsFound() throws BadRequestException {
|
||||||
|
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() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetAllTheoremsByProvenStatus_nullProvenStatus() throws BadRequestException {
|
||||||
|
theoremController.getAllTheoremsByProvenStatus(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByProvenStatus_invalidProvenStatus() throws BadRequestException {
|
||||||
|
final ResponseEntity<List<Theorem>> responseEntity = theoremController.getAllTheoremsByProvenStatus("test");
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByProvenStatus_noTheoremsFound() throws BadRequestException {
|
||||||
|
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() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testGetAllTheoremsByName_nullName() throws BadRequestException {
|
||||||
|
theoremController.getAllTheoremsByName(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllTheoremsByName_noNameFound() throws BadRequestException {
|
||||||
|
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() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testInsertTheorem_theoremDtoIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
theoremController.insertTheorem(null, bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnprocessableEntityException.class)
|
||||||
|
public void testInsertTheorem_bindingResultHasErrors() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
final Theorem theorem = createTheorem();
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
theoremController.insertTheorem(theorem, bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTheorem() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
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(expected = UnprocessableEntityException.class)
|
||||||
|
public void testUpdateTheorem_bindingResultHasErrors() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
theoremController.updateTheorem(1, createTheorem(), bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = BadRequestException.class)
|
||||||
|
public void testUpdateTheorem_theoremDtoIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
theoremController.updateTheorem(1, null, bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = BadRequestException.class)
|
||||||
|
public void testUpdateTheorem_idIsNull() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
theoremController.updateTheorem(null, createTheorem(), bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTheorem_theoremDoesNotExist() throws BadRequestException, UnprocessableEntityException {
|
||||||
|
when(theoremRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity<Theorem> responseEntity = theoremController.updateTheorem(1, createTheorem(), bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
verify(theoremRepository, times(0)).save(any(Theorem.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTheoremById() throws BadRequestException {
|
||||||
|
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(expected = BadRequestException.class)
|
||||||
|
public void testDeleteTheoremById_idIsNull() throws BadRequestException {
|
||||||
|
theoremController.deleteTheoremById(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-2
@@ -18,7 +18,15 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':persistence')
|
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.11'
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
compile group: 'org.apache.httpcomponents', name: 'fluent-hc', version: '4.5.7'
|
||||||
|
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
|
||||||
|
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: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
|
||||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
compile fileTree(dir: 'lib', include: '**/*.jar')
|
||||||
|
|
||||||
|
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
testCompile group: 'org.springframework', name: 'spring-test', version: '5.1.5.RELEASE'
|
||||||
}
|
}
|
||||||
|
|||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.services.dto.Definition;
|
||||||
|
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.TestPropertySource;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = ServicesTestConfig.class)
|
||||||
|
@TestPropertySource(locations = "classpath:test.properties")
|
||||||
|
public class DefinitionServiceIntegrationTest {
|
||||||
|
@Autowired private DefinitionService definitionService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRUD() {
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
final Optional<Definition> createdDefinition = definitionService.createDefinition(testDefinition);
|
||||||
|
|
||||||
|
assertTrue(createdDefinition.isPresent());
|
||||||
|
assertNotEquals(0, createdDefinition.get().getId());
|
||||||
|
assertThat(createdDefinition.get().getVersion(), is(0));
|
||||||
|
assertThat(createdDefinition.get().getName(), is("Test Name"));
|
||||||
|
assertNotNull(createdDefinition.get().getDefinition());
|
||||||
|
assertThat(createdDefinition.get().getDefinition().size(), is(1));
|
||||||
|
assertThat(createdDefinition.get().getDefinition().get(0), is("Test definition 1"));
|
||||||
|
assertNotNull(createdDefinition.get().getNotation());
|
||||||
|
assertThat(createdDefinition.get().getNotation().size(), is(1));
|
||||||
|
assertThat(createdDefinition.get().getNotation().get(0), is("\\testLaTeX"));
|
||||||
|
|
||||||
|
final Optional<Definition> definitionFoundById = definitionService.findById(createdDefinition.get().getId());
|
||||||
|
|
||||||
|
assertThat(definitionFoundById.get(), is(equalTo(createdDefinition.get())));
|
||||||
|
|
||||||
|
final Definition definitionUpdate = new Definition();
|
||||||
|
definitionUpdate.setId(createdDefinition.get().getId());
|
||||||
|
definitionUpdate.setName("Test Update");
|
||||||
|
|
||||||
|
final Optional<Definition> updatedDefinition = definitionService.updateDefinition(definitionUpdate);
|
||||||
|
|
||||||
|
assertTrue(updatedDefinition.isPresent());
|
||||||
|
assertNotEquals(0, updatedDefinition.get().getId());
|
||||||
|
assertThat(updatedDefinition.get().getVersion(), is(1));
|
||||||
|
assertThat(updatedDefinition.get().getName(), is("Test Update"));
|
||||||
|
assertNotNull(updatedDefinition.get().getDefinition());
|
||||||
|
assertThat(updatedDefinition.get().getDefinition().size(), is(1));
|
||||||
|
assertThat(updatedDefinition.get().getDefinition().get(0), is("Test definition 1"));
|
||||||
|
assertNotNull(updatedDefinition.get().getNotation());
|
||||||
|
assertThat(updatedDefinition.get().getNotation().size(), is(1));
|
||||||
|
assertThat(updatedDefinition.get().getNotation().get(0), is("\\testLaTeX"));
|
||||||
|
|
||||||
|
final boolean deletionWasSuccessful = definitionService.deleteDefinition(updatedDefinition.get());
|
||||||
|
|
||||||
|
assertThat(deletionWasSuccessful, is(true));
|
||||||
|
|
||||||
|
final Optional<Definition> deletedDefinitionFoundById = definitionService.findById(createdDefinition.get().getId());
|
||||||
|
|
||||||
|
assertFalse(deletedDefinitionFoundById.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan
|
||||||
|
public class ServicesTestConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Autowired
|
||||||
|
public UserService userService(final RestService restService) {
|
||||||
|
return new UserService(restService);
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.services.dto.Account;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = ServicesTestConfig.class)
|
||||||
|
@TestPropertySource("classpath:test.properties")
|
||||||
|
public class UserServiceIntegrationTest {
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("userService")
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRUD() {
|
||||||
|
final Account testAccount = createAccount();
|
||||||
|
|
||||||
|
final Optional<Account> testCreatedAccount = userService.createAccount(testAccount);
|
||||||
|
assertTrue(testCreatedAccount.isPresent());
|
||||||
|
final Account returnedAccount = testCreatedAccount.get();
|
||||||
|
assertEquals("test_user", returnedAccount.getUsername());
|
||||||
|
assertEquals("test_password", returnedAccount.getPassword());
|
||||||
|
assertFalse(returnedAccount.isAdministrator());
|
||||||
|
|
||||||
|
final Optional<Account> getAccountById = userService.findAccountById(returnedAccount.getId());
|
||||||
|
assertTrue(getAccountById.isPresent());
|
||||||
|
final Account returnedAccountById = getAccountById.get();
|
||||||
|
assertEquals("test_user", returnedAccountById.getUsername());
|
||||||
|
assertEquals("test_password", returnedAccountById.getPassword());
|
||||||
|
assertFalse(returnedAccountById.isAdministrator());
|
||||||
|
|
||||||
|
final Optional<Account> getAccountByUsername = userService.findAccountByUsername(returnedAccount.getUsername());
|
||||||
|
assertTrue(getAccountByUsername.isPresent());
|
||||||
|
final Account returnedAccountByUsername = getAccountByUsername.get();
|
||||||
|
assertEquals("test_user", returnedAccountByUsername.getUsername());
|
||||||
|
assertEquals("test_password", returnedAccountByUsername.getPassword());
|
||||||
|
assertFalse(returnedAccountById.isAdministrator());
|
||||||
|
|
||||||
|
returnedAccount.setUsername("test_updatedUser");
|
||||||
|
returnedAccount.setPassword("test_updatedPassword");
|
||||||
|
|
||||||
|
final Optional<Account> updatedAccount = userService.updateAccount(returnedAccount);
|
||||||
|
assertTrue(updatedAccount .isPresent());
|
||||||
|
final Account returnedUpdatedAccount = updatedAccount.get();
|
||||||
|
assertEquals("test_updatedUser", returnedUpdatedAccount.getUsername());
|
||||||
|
assertEquals("test_updatedPassword", returnedUpdatedAccount.getPassword());
|
||||||
|
assertFalse(returnedUpdatedAccount.isAdministrator());
|
||||||
|
|
||||||
|
final boolean result = userService.deleteAccount(returnedUpdatedAccount);
|
||||||
|
assertTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Account createAccount() {
|
||||||
|
final Account testAccount = new Account();
|
||||||
|
testAccount.setUsername("test_user");
|
||||||
|
testAccount.setPassword("test_password");
|
||||||
|
testAccount.setAdministrator(false);
|
||||||
|
testAccount.setLastLogin(new Date());
|
||||||
|
|
||||||
|
return testAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
persistence.api.connection.timeout.milliseconds=5000
|
||||||
|
persistence.api.socket.timeout.milliseconds=10000
|
||||||
|
persistence.api.base.url=http://localhost:8090/
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import edu.msudenver.tsp.services.dto.Definition;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class DefinitionService {
|
||||||
|
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 DefinitionService(final RestService restService) {
|
||||||
|
this.restService = restService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<List<Definition>> getAllDefinitions() {
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<List<Definition>> typeToken = new TypeToken<List<Definition>>(){};
|
||||||
|
final Optional<List<Definition>> persistenceApiResponse =
|
||||||
|
restService.get(persistenceApiBaseUrl + "definitions/",
|
||||||
|
typeToken, connectionTimeoutMilliseconds, socketTimeoutMilliseconds, null);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.info("Unable to get list of definitions");
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error getting list of definitions!", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Get all definitions request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Definition> findById(final int id) {
|
||||||
|
if (id == 0) {
|
||||||
|
LOG.error("Null id specified; returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Sending request to find definition by id {}", id);
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Definition> typeToken = new TypeToken<Definition>(){};
|
||||||
|
final Optional<Definition> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "definitions/" + id,
|
||||||
|
typeToken, connectionTimeoutMilliseconds, socketTimeoutMilliseconds, null);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.info("Unable to find definition with id {}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error finding definition by id", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Find by id request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Definition> createDefinition(final Definition definition) {
|
||||||
|
if (definition == null) {
|
||||||
|
LOG.error("Given null definition, returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Sending request to insert definition {}", definition);
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Definition> typeToken = new TypeToken<Definition>() {};
|
||||||
|
final Optional<Definition> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "definitions/",
|
||||||
|
new GsonBuilder().create().toJson(definition),
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Creation successful. Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.info("Unable to create new definition {}", definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error creating new definition", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Create new definition request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Definition> updateDefinition(final Definition definition) {
|
||||||
|
if (definition == null) {
|
||||||
|
LOG.error("Given null definition, returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definition.getId() == 0) {
|
||||||
|
LOG.error("Given invalid id 0, returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Sending request to update definition {}", definition);
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Definition> typeToken = new TypeToken<Definition>(){};
|
||||||
|
final Optional<Definition> persistenceApiResponse = restService.patch(persistenceApiBaseUrl + "definitions/" + definition.getId(),
|
||||||
|
new GsonBuilder().create().toJson(definition),
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Update successful. Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.info("Unable to update definition {}", definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error updating definition", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Update definition request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteDefinition(final Definition definition) {
|
||||||
|
if (definition == null) {
|
||||||
|
LOG.error("Given null definition, returning false");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definition.getId() == 0) {
|
||||||
|
LOG.error("Given invalid id 0, returning false");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Sending request to delete definition {}", definition);
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final boolean deleteIsSuccessful = restService.delete(persistenceApiBaseUrl + "definitions/" + definition.getId(),
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds,
|
||||||
|
HttpStatus.NO_CONTENT);
|
||||||
|
|
||||||
|
if (deleteIsSuccessful) {
|
||||||
|
LOG.info("Deletion successful. Returning true");
|
||||||
|
} else {
|
||||||
|
LOG.info("Unable to delete definition {}", definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deleteIsSuccessful;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error when deleting definition", e);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
LOG.info("Delete definition request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,14 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||||
|
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableAutoConfiguration(exclude = {DevToolsDataSourceAutoConfiguration.class,
|
||||||
|
HibernateJpaAutoConfiguration.class,
|
||||||
|
DataSourceAutoConfiguration.class})
|
||||||
|
public class ServiceConfig {
|
||||||
|
}
|
||||||
@@ -0,0 +1,221 @@
|
|||||||
|
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.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
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<List<Account>> getListOfAccounts() {
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<List<Account>> typeToken = new TypeToken<List<Account>>() {};
|
||||||
|
final Optional<List<Account>> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "accounts/",
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds,
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Unable to get the list of accounts");
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error getting the list of accounts", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Get the list of accounts request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Account> findAccountById(final int id) {
|
||||||
|
|
||||||
|
if (id == 0) {
|
||||||
|
LOG.error("No user ID specified! Returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||||
|
final Optional<Account> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "accounts/id?id=" + id,
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds,
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Unable to find account with id {}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error finding account by id", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Find account by ID request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Account> findAccountByUsername(final String username) {
|
||||||
|
if (username == null) {
|
||||||
|
LOG.error("No username specified! Returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||||
|
final Optional<Account> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "accounts/username?username=" + username,
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds,
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Unable to GET account with username {}", username);
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error finding account by username", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Find account by username request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Account> createAccount(final Account account) {
|
||||||
|
if (account == null) {
|
||||||
|
LOG.error("Given null account, returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||||
|
final Optional<Account> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "accounts/",
|
||||||
|
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create().toJson(account),
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Account> updateAccount(final Account account) {
|
||||||
|
if (account == null) {
|
||||||
|
LOG.error("Specified account is null; returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account.getId() == 0) {
|
||||||
|
LOG.error("No user ID specified! Returning {}");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
final int id = account.getId();
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypeToken<Account> typeToken = new TypeToken<Account>(){};
|
||||||
|
final Optional<Account> persistenceApiResponse = restService.patch(persistenceApiBaseUrl + "accounts/" + id,
|
||||||
|
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create().toJson(account),
|
||||||
|
typeToken,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds);
|
||||||
|
|
||||||
|
if (persistenceApiResponse.isPresent()) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Unable to update user with id {}", account.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Error updating user", e);
|
||||||
|
return Optional.empty();
|
||||||
|
} finally {
|
||||||
|
LOG.info("Update user request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean deleteAccount(final Account account) {
|
||||||
|
if (account == null){
|
||||||
|
LOG.error("Specified account is null; returning {}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account.getId() == 0) {
|
||||||
|
LOG.error("No user ID specified! Returning {}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int id = account.getId();
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
final boolean persistenceApiResponse = restService.delete(persistenceApiBaseUrl + "accounts/" + id,
|
||||||
|
connectionTimeoutMilliseconds,
|
||||||
|
socketTimeoutMilliseconds, HttpStatus.NO_CONTENT);
|
||||||
|
if (persistenceApiResponse) {
|
||||||
|
LOG.info("Returning {}", persistenceApiResponse);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG.error("Unable to delete user {}", account);
|
||||||
|
}
|
||||||
|
|
||||||
|
return persistenceApiResponse;
|
||||||
|
}catch (final Exception e) {
|
||||||
|
LOG.error("Error deleting user", e);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
LOG.info("Delete user request took {}ms", Duration.between(start, Instant.now()).toMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
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.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 {
|
||||||
|
@Size(max = 50) private String username;
|
||||||
|
@Size(max = 256) private String password;
|
||||||
|
@NotNull private boolean administrator;
|
||||||
|
@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,24 @@
|
|||||||
|
package edu.msudenver.tsp.services.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@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")
|
||||||
|
private List<String> definition;
|
||||||
|
private List<String> notation;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3412178112996807691L;
|
||||||
|
|
||||||
|
public interface Insert {}
|
||||||
|
}
|
||||||
@@ -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.Patch(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Patch(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +1,24 @@
|
|||||||
package edu.msudenver.tsp.services.parser;
|
package edu.msudenver.tsp.services.parser;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.controller.DefinitionController;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import edu.msudenver.tsp.persistence.controller.NotationController;
|
|
||||||
import edu.msudenver.tsp.persistence.controller.ProofController;
|
|
||||||
import edu.msudenver.tsp.persistence.controller.TheoremController;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
class ParserService {
|
class ParserService {
|
||||||
private final DefinitionController definitionController;
|
|
||||||
private final TheoremController theoremController;
|
|
||||||
private final NotationController notationController;
|
|
||||||
private final ProofController proofController;
|
|
||||||
private Node root;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ParserService(final DefinitionController definitionController, final TheoremController theoremController,
|
|
||||||
final NotationController notationController, final ProofController proofController) {
|
|
||||||
this.definitionController = definitionController;
|
|
||||||
this.theoremController = theoremController;
|
|
||||||
this.notationController = notationController;
|
|
||||||
this.proofController = proofController;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean parseUserInput(final String userInput)
|
public boolean parseUserInput(final String userInput)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
final Node tree = parseRawInput(userInput);
|
final Node tree = parseRawInput(userInput);
|
||||||
final List<String> statements = retrieveStatements(tree);
|
retrieveStatements(tree);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch(final Exception e) {
|
} catch(final Exception e) {
|
||||||
e.printStackTrace();
|
LOG.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -44,7 +27,7 @@ class ParserService {
|
|||||||
{
|
{
|
||||||
input = input.toLowerCase();
|
input = input.toLowerCase();
|
||||||
|
|
||||||
root = new Node(input, null);
|
final Node root = new Node(input, null);
|
||||||
|
|
||||||
if(input.equals(""))
|
if(input.equals(""))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package edu.msudenver.tsp.services.scoring;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
//@PropertySource("classpath:development.properties")
|
|
||||||
public class ScoringConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public TheoremScoringService theoremScoringService() {
|
|
||||||
return new TheoremScoringService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package edu.msudenver.tsp.services.scoring;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
class TheoremScoringService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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,290 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import edu.msudenver.tsp.services.dto.Definition;
|
||||||
|
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 java.util.Optional;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Matchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class DefinitionServiceTest {
|
||||||
|
@Mock private RestService restService;
|
||||||
|
@InjectMocks private DefinitionService definitionService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllDefinitions() {
|
||||||
|
final List<Definition> definitionList = new ArrayList<>();
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
definitionList.add(testDefinition);
|
||||||
|
definitionList.add(testDefinition);
|
||||||
|
|
||||||
|
when(restService.get(anyString(), any(), anyInt(), anyInt(), anyString()))
|
||||||
|
.thenReturn(Optional.of(definitionList));
|
||||||
|
|
||||||
|
final Optional<List<Definition>> listOfDefinitions = definitionService.getAllDefinitions();
|
||||||
|
|
||||||
|
assertTrue(listOfDefinitions.isPresent());
|
||||||
|
assertThat(listOfDefinitions.get().size(), is(2));
|
||||||
|
listOfDefinitions.get().forEach(definition -> assertThat(definition, equalTo(testDefinition)));
|
||||||
|
verify(restService).get(anyString(), any(), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllDefinitions_RequestReturnsEmptyOptional() {
|
||||||
|
when(restService.get(anyString(), any(), anyInt(), anyInt(), anyString()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<List<Definition>> listOfDefinitions = definitionService.getAllDefinitions();
|
||||||
|
|
||||||
|
assertFalse(listOfDefinitions.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllDefinitions_ExceptionThrownWhenSendingRequest() {
|
||||||
|
when(restService.get(anyString(), any(), anyInt(), anyInt(), anyString()))
|
||||||
|
.thenThrow(new UnsupportedOperationException("Test exception"));
|
||||||
|
|
||||||
|
final Optional<List<Definition>> listOfDefinitions = definitionService.getAllDefinitions();
|
||||||
|
|
||||||
|
assertFalse(listOfDefinitions.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindById() {
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
when(restService.get(anyString(), any(), anyInt(), anyInt(), anyString()))
|
||||||
|
.thenReturn(Optional.of(testDefinition));
|
||||||
|
|
||||||
|
final Optional<Definition> foundDefinition = definitionService.findById(testDefinition.getId());
|
||||||
|
|
||||||
|
assertTrue(foundDefinition.isPresent());
|
||||||
|
assertThat(foundDefinition.get().getId(), is(1));
|
||||||
|
assertThat(foundDefinition.get(), is(equalTo(testDefinition)));
|
||||||
|
verify(restService).get(anyString(), any(), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindById_RequestReturnsEmptyOptional() {
|
||||||
|
when(restService.get(anyString(), any(), anyInt(), anyInt(), anyString()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<Definition> nonExistentDefinition = definitionService.findById(1);
|
||||||
|
|
||||||
|
assertFalse(nonExistentDefinition.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindById_ExceptionThrownWhenSendingRequest() {
|
||||||
|
when(restService.get(anyString(), any(), anyInt(), anyInt(), anyString()))
|
||||||
|
.thenThrow(new UnsupportedOperationException("test exception"));
|
||||||
|
|
||||||
|
final Optional<Definition> exceptionThrowingDefinition = definitionService.findById(1);
|
||||||
|
|
||||||
|
assertFalse(exceptionThrowingDefinition.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindById_IdIsZero() {
|
||||||
|
final Optional<Definition> impossibleDefinition = definitionService.findById(0);
|
||||||
|
|
||||||
|
assertFalse(impossibleDefinition.isPresent());
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDefinition() {
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
final String testDefinitionJson = new GsonBuilder().create().toJson(testDefinition);
|
||||||
|
|
||||||
|
when(restService.post(anyString(), anyString(), any(), anyInt(), anyInt()))
|
||||||
|
.thenReturn(Optional.of(testDefinition));
|
||||||
|
|
||||||
|
final Optional<Definition> createdDefinition = definitionService.createDefinition(testDefinition);
|
||||||
|
|
||||||
|
assertNotNull(createdDefinition);
|
||||||
|
assertTrue(createdDefinition.isPresent());
|
||||||
|
assertEquals(testDefinition, createdDefinition.get());
|
||||||
|
verify(restService).post(anyString(), eq(testDefinitionJson), any(), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDefinition_NullDefinition() {
|
||||||
|
final Optional<Definition> nullDefinition = definitionService.createDefinition(null);
|
||||||
|
|
||||||
|
assertFalse(nullDefinition.isPresent());
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDefinition_UnableToCreateDefinition() {
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
final String testDefinitionJson = new GsonBuilder().create().toJson(testDefinition);
|
||||||
|
|
||||||
|
when(restService.post(anyString(), anyString(), any(), anyInt(), anyInt()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<Definition> createdDefinition = definitionService.createDefinition(testDefinition);
|
||||||
|
|
||||||
|
assertNotNull(createdDefinition);
|
||||||
|
assertFalse(createdDefinition.isPresent());
|
||||||
|
verify(restService).post(anyString(), eq(testDefinitionJson), any(), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDefinition_RestServiceThrowsException() {
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
final String testDefinitionJson = new GsonBuilder().create().toJson(testDefinition);
|
||||||
|
|
||||||
|
when(restService.post(anyString(), anyString(), any(), anyInt(), anyInt()))
|
||||||
|
.thenThrow(new UnsupportedOperationException("test exception"));
|
||||||
|
|
||||||
|
final Optional<Definition> createdDefinition = definitionService.createDefinition(testDefinition);
|
||||||
|
|
||||||
|
assertNotNull(createdDefinition);
|
||||||
|
assertFalse(createdDefinition.isPresent());
|
||||||
|
verify(restService).post(anyString(), eq(testDefinitionJson), any(), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition() {
|
||||||
|
when(restService.patch(anyString(), anyString(), any(), anyInt(), anyInt()))
|
||||||
|
.thenReturn(Optional.of(createDefinition().setName("Test update")));
|
||||||
|
|
||||||
|
final Definition testDefinition = new Definition();
|
||||||
|
testDefinition.setName("Test update");
|
||||||
|
testDefinition.setId(1);
|
||||||
|
|
||||||
|
final Optional<Definition> updatedDefinition = definitionService.updateDefinition(testDefinition);
|
||||||
|
|
||||||
|
assertTrue(updatedDefinition.isPresent());
|
||||||
|
assertThat(updatedDefinition.get().getId(), is(1));
|
||||||
|
assertThat(updatedDefinition.get().getName(), is(equalTo("Test update")));
|
||||||
|
verify(restService).patch(anyString(), anyString(), any(), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_nullDefinition() {
|
||||||
|
final Optional<Definition> testUpdate = definitionService.updateDefinition(null);
|
||||||
|
|
||||||
|
assertFalse(testUpdate.isPresent());
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_IdIsZero() {
|
||||||
|
final Definition impossibleDefinition = createDefinition();
|
||||||
|
impossibleDefinition.setId(0);
|
||||||
|
|
||||||
|
final Optional<Definition> testUpdate = definitionService.updateDefinition(impossibleDefinition);
|
||||||
|
|
||||||
|
assertFalse(testUpdate.isPresent());
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_RequestReturnsEmptyOptional() {
|
||||||
|
when(restService.patch(anyString(), anyString(), any(), anyInt(), anyInt()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<Definition> nonExistentDefinition = definitionService.updateDefinition(createDefinition());
|
||||||
|
|
||||||
|
assertFalse(nonExistentDefinition.isPresent());
|
||||||
|
verify(restService).patch(anyString(), anyString(), any(), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDefinition_ExceptionThrownWhenSendingRequest() {
|
||||||
|
when(restService.patch(anyString(), anyString(), any(), anyInt(), anyInt()))
|
||||||
|
.thenThrow(new UnsupportedOperationException("test exception"));
|
||||||
|
|
||||||
|
final Optional<Definition> exceptionThrowingDefinition = definitionService.updateDefinition(createDefinition());
|
||||||
|
|
||||||
|
assertFalse(exceptionThrowingDefinition.isPresent());
|
||||||
|
verify(restService).patch(anyString(), anyString(), any(), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinition() {
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any()))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
|
final boolean deleteIsSuccessful = definitionService.deleteDefinition(createDefinition());
|
||||||
|
|
||||||
|
assertTrue(deleteIsSuccessful);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinition_NullDefinition() {
|
||||||
|
final boolean deleteIsSuccessful = definitionService.deleteDefinition(null);
|
||||||
|
|
||||||
|
assertFalse(deleteIsSuccessful);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinition_IdIsZero() {
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
testDefinition.setId(0);
|
||||||
|
|
||||||
|
final boolean deleteIsSuccessful = definitionService.deleteDefinition(testDefinition);
|
||||||
|
|
||||||
|
assertFalse(deleteIsSuccessful);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinition_RequestReturnsFalse() {
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any()))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
final boolean deleteIsSuccessful = definitionService.deleteDefinition(createDefinition());
|
||||||
|
|
||||||
|
assertFalse(deleteIsSuccessful);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinition_ExceptionThrownWhenSendingRequest() {
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any()))
|
||||||
|
.thenThrow(new UnsupportedOperationException("test exception"));
|
||||||
|
|
||||||
|
final boolean deleteIsSuccessful = definitionService.deleteDefinition(createDefinition());
|
||||||
|
|
||||||
|
assertFalse(deleteIsSuccessful);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
definition.setId(1);
|
||||||
|
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import edu.msudenver.tsp.services.dto.Account;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class UserServiceTest {
|
||||||
|
@Mock private RestService restService;
|
||||||
|
@InjectMocks private UserService userService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetListOfAccounts() {
|
||||||
|
final List<Account> accountList = new ArrayList<>();
|
||||||
|
accountList.add(createAccount());
|
||||||
|
accountList.add(createAccount());
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(), anyString())).thenReturn(Optional.of(accountList));
|
||||||
|
|
||||||
|
final Optional<List<Account>> response = userService.getListOfAccounts();
|
||||||
|
|
||||||
|
assertTrue(response.isPresent());
|
||||||
|
assertEquals(accountList, response.get());
|
||||||
|
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetListOfAccounts_PersistenceApiResponseIsEmpty() {
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<List<Account>> response = userService.getListOfAccounts();
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetListOfAccounts_RestServiceThrowsException() {
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenThrow(Exception.class);
|
||||||
|
|
||||||
|
final Optional<List<Account>> response = userService.getListOfAccounts();
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountById() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.of(account));
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.findAccountById(1);
|
||||||
|
|
||||||
|
assertTrue(response.isPresent());
|
||||||
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountById_IdEqualsZero() {
|
||||||
|
final Optional<Account> response = userService.findAccountById(0);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountById_PersistenceApiResponseIsEmpty() {
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.findAccountById(1);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountById_RestServiceThrowsException() {
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenThrow(Exception.class);
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.findAccountById(1);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountByUsername() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.of(account));
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.findAccountByUsername(account.getUsername());
|
||||||
|
|
||||||
|
assertTrue(response.isPresent());
|
||||||
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountByUsername_NullUsername() {
|
||||||
|
final Optional<Account> response = userService.findAccountByUsername(null);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountByUsername_PersistenceApiResponseIsEmpty() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.findAccountByUsername(account.getUsername());
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAccountByUsername_RestServiceThrowsException() {
|
||||||
|
when(restService.get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString())).thenThrow(Exception.class);
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.findAccountByUsername("test");
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(), any(TypeToken.class), anyInt(), anyInt(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAccount() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
|
||||||
|
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.of(account));
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.createAccount(account);
|
||||||
|
|
||||||
|
assertTrue(response.isPresent());
|
||||||
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAccount_NullAccount() {
|
||||||
|
final Optional<Account> response = userService.createAccount(null);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verify(restService, times(0)).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAccount_AccountCouldNotBeCreated() {
|
||||||
|
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.createAccount(createAccount());
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAccount_RestServiceThrowsException() {
|
||||||
|
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenThrow(Exception.class);
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.createAccount(createAccount());
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.of(account));
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.updateAccount(account);
|
||||||
|
|
||||||
|
assertTrue(response.isPresent());
|
||||||
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_NullAccount() {
|
||||||
|
final Optional<Account> response = userService.updateAccount(null);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_IdEqualsZero() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(0);
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.updateAccount(account);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_PersistenceApiResponseIsEmpty() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.updateAccount(account);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_RestServiceThrowsException() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenThrow(Exception.class);
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.updateAccount(account);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any())).thenReturn(true);
|
||||||
|
|
||||||
|
final boolean isDeleteSuccessful = userService.deleteAccount(account);
|
||||||
|
|
||||||
|
assertTrue(isDeleteSuccessful);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_NullAccount() {
|
||||||
|
final boolean isDeleteSuccessful = userService.deleteAccount(null);
|
||||||
|
|
||||||
|
assertFalse(isDeleteSuccessful);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_IdEqualsZero() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(0);
|
||||||
|
|
||||||
|
final boolean isDeleteSuccessful = userService.deleteAccount(account);
|
||||||
|
|
||||||
|
assertFalse(isDeleteSuccessful);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_PersistenceApiResponseIsEmpty() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any())).thenReturn(false);
|
||||||
|
|
||||||
|
final boolean isDeleteSuccessful = userService.deleteAccount(account);
|
||||||
|
|
||||||
|
assertFalse(isDeleteSuccessful);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_RestServiceThrowsException() {
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any())).thenThrow(Exception.class);
|
||||||
|
|
||||||
|
final boolean persistenceApiResponse = userService.deleteAccount(account);
|
||||||
|
|
||||||
|
assertFalse(persistenceApiResponse);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Account createAccount() {
|
||||||
|
final Account account = new Account();
|
||||||
|
account.setUsername("Test username");
|
||||||
|
account.setPassword("test password");
|
||||||
|
account.setAdministrator(true);
|
||||||
|
account.setLastLogin(new Date());
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package edu.msudenver.tsp.services.factory;
|
||||||
|
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
public class RequestFactoryTest {
|
||||||
|
private final RequestFactory requestFactory = new RequestFactory();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDelete() {
|
||||||
|
final Request testRequest = requestFactory.delete("testUri");
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGet() {
|
||||||
|
final Request testRequest = requestFactory.get("testUri");
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPost() {
|
||||||
|
final Request testRequest = requestFactory.post("testUri", "testJson");
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPost_blankRequestJson() {
|
||||||
|
final Request testRequest = requestFactory.post("testUri", null);
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPut() {
|
||||||
|
final Request testRequest = requestFactory.put("testUri", "testJson");
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPut_blankRequestJson() {
|
||||||
|
final Request testRequest = requestFactory.put("testUri", null);
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatch() {
|
||||||
|
final Request testRequest = requestFactory.patch("testUri", "testJson");
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatch_blankRequestJson() {
|
||||||
|
final Request testRequest = requestFactory.patch("testUri", null);
|
||||||
|
|
||||||
|
assertNotNull(testRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package edu.msudenver.tsp.services.parser;
|
package edu.msudenver.tsp.services.parser;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.controller.DefinitionController;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -12,18 +12,13 @@ import java.util.List;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ParserServiceTest {
|
public class ParserServiceTest {
|
||||||
|
|
||||||
private final DefinitionController definitionControllerMock = mock(DefinitionController.class);
|
@Mock private ParserService mockParserService;
|
||||||
private final ParserService mockParserService = mock(ParserService.class);
|
@InjectMocks private ParserService parserService;
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
private final ParserService parserService = new ParserService(definitionControllerMock, null,
|
|
||||||
null, null);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyStringEqualsEmptyString() {
|
public void testEmptyStringEqualsEmptyString() {
|
||||||
|
|||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
package edu.msudenver.tsp.services.scoring;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
|
||||||
public class TheoremScoringServiceTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertEquals(3,3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,12 @@
|
|||||||
package edu.msudenver.tsp.website;
|
package edu.msudenver.tsp.website;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
public static void main(final String[] args) {
|
public static void main(final String[] args) {
|
||||||
SpringApplication.run(Application.class, 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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
public class ProofsDriver {
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package edu.msudenver.tsp.website.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.website.forms.TheoremForm;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Controller
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequestMapping("/theorem")
|
||||||
|
public class TheoremEntryController {
|
||||||
|
@GetMapping({"/",""})
|
||||||
|
public ModelAndView enterTheoremPage() {
|
||||||
|
LOG.info("Received request to display the theorem entry page: returning model with name 'Theorem'");
|
||||||
|
return new ModelAndView("Theorem");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping({"/",""})
|
||||||
|
public String saveTheorem(@Validated final TheoremForm theoremForm, final Model model) {
|
||||||
|
model.addAttribute("theoremName", theoremForm.getTheoremName());
|
||||||
|
model.addAttribute("theorem", theoremForm.getTheorem());
|
||||||
|
LOG.info("Saving theorem {}...", theoremForm);
|
||||||
|
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package edu.msudenver.tsp.website.forms;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class TheoremForm {
|
||||||
|
private String theoremName;
|
||||||
|
private String theorem;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
spring.mvc.view.prefix:/WEB-INF/jsp/
|
||||||
|
spring.mvc.view.suffix:.jsp
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<%@ page contentType="text/html; charset=UTF-8"
|
||||||
|
pageEncoding="UTF-8"%>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>Theorem Entry</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form method="post" action="">
|
||||||
|
<label>Theorem Name:
|
||||||
|
<input type="text" name="theoremName"/>
|
||||||
|
</label>
|
||||||
|
<br><label>Theorem:
|
||||||
|
<input type="text" name="theorem"/>
|
||||||
|
</label><br>
|
||||||
|
<input type="submit" value="Save">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<%--
|
||||||
|
Created by IntelliJ IDEA.
|
||||||
|
User: atusa
|
||||||
|
Date: 2/1/19
|
||||||
|
Time: 8:03 PM
|
||||||
|
To change this template use File | Settings | File Templates.
|
||||||
|
--%>
|
||||||
|
|
||||||
|
|
||||||
|
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>Pandamonium™ Theorem Prover</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<h1>Theorem Prover</h1>
|
||||||
|
<h2>Hello! Welcome to Pandamonium™ Theorem Prover!!</h2>
|
||||||
|
|
||||||
|
Click on this <strong><a href="/theorem/">link</a></strong> to visit theorem entering page.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<br><b>Name: </b><%= request.getParameter("theoremName")%>
|
||||||
|
<br><b>Theorem: </b><%= request.getParameter("theorem")%>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<%--
|
|
||||||
Created by IntelliJ IDEA.
|
|
||||||
User: atusa
|
|
||||||
Date: 2/1/19
|
|
||||||
Time: 8:03 PM
|
|
||||||
To change this template use File | Settings | File Templates.
|
|
||||||
--%>
|
|
||||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>$Title$</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
$END$
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
public class ProofsDriverTest {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package edu.msudenver.tsp.website.controller;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class TheoremEntryControllerTest {
|
||||||
|
|
||||||
|
private final TheoremEntryController theoremEntryController = new TheoremEntryController();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnterTheoremPage() {
|
||||||
|
final ModelAndView modelAndView = theoremEntryController.enterTheoremPage();
|
||||||
|
|
||||||
|
assertNotNull(modelAndView);
|
||||||
|
assertEquals("Theorem", modelAndView.getViewName());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user