Project Created

This commit is contained in:
dDogge 2024-03-26 20:38:55 +01:00
commit ead83c4c5c
38 changed files with 885 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
/.settings
/.gradle
/build/
/target/
*.class

10
README.md Normal file
View file

@ -0,0 +1,10 @@
# README
How to run:
$ gradlew run
or:
$ gradlew shadowJar
$ java -jar build/libs/krusty-1.0-all.jar

39
build.gradle Normal file
View file

@ -0,0 +1,39 @@
plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '4.0.3'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile group: 'com.sparkjava', name: 'spark-core', version: '2.9.1'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.19'
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.30.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.2'
testCompile group: 'junit', name: 'junit', version: '4.13'
testCompile group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.0'
testCompile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
}
group = 'com.krusty'
version = '1.0'
description = 'Krusty'
sourceCompatibility = '11'
targetCompatibility = '11'
application {
mainClassName = "krusty.ServerMain"
}
jar {
manifest {
attributes 'Implementation-Title': 'KrustyServer',
'Implementation-Version': version,
'Main-Class': 'krusty.Main'
}
}

BIN
gradle/.DS_Store vendored Normal file

Binary file not shown.

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,6 @@
#Mon Feb 17 13:38:19 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

172
gradlew vendored Executable file
View file

@ -0,0 +1,172 @@
#!/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='"-Xmx64m"'
# 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" "$@"

84
gradlew.bat vendored Normal file
View file

@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

5
settings.gradle Normal file
View file

@ -0,0 +1,5 @@
/*
* This file was generated by the Gradle 'init' task.
*/
rootProject.name = 'krusty'

BIN
src/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/main/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/main/java/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,55 @@
package krusty;
import spark.Request;
import spark.Response;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
import static krusty.Jsonizer.toJson;
public class Database {
/**
* Modify it to fit your environment and then use this string when connecting to your database!
*/
private static final String jdbcString = "jdbc:mysql://localhost/krusty";
// For use with MySQL or PostgreSQL
private static final String jdbcUsername = "<CHANGE ME>";
private static final String jdbcPassword = "<CHANGE ME>";
public void connect() {
// Connect to database here
}
// TODO: Implement and change output in all methods below!
public String getCustomers(Request req, Response res) {
return "{}";
}
public String getRawMaterials(Request req, Response res) {
return "{}";
}
public String getCookies(Request req, Response res) {
return "{\"cookies\":[]}";
}
public String getRecipes(Request req, Response res) {
return "{}";
}
public String getPallets(Request req, Response res) {
return "{\"pallets\":[]}";
}
public String reset(Request req, Response res) {
return "{}";
}
public String createPallet(Request req, Response res) {
return "{}";
}
}

View file

@ -0,0 +1,78 @@
package krusty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOError;
import java.io.IOException;
import java.io.StringWriter;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
/**
* Auxiliary class for automatically translating a ResultSet to JSON
*/
public class Jsonizer {
private static final ObjectMapper mapper = new ObjectMapper();
static {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mapper.setDateFormat(df);
}
/**
* Convert any POJO or plain Java data to JSON supported by Jackson
*
* @param name name of returned data
* @return {name: jackson serialized json representation}
*/
public static String anythingToJson(Object data, String name) {
try {
Map<String, Object> entries = new HashMap<>();
entries.put(name, data);
return mapper.writeValueAsString(entries);
} catch (JsonProcessingException e) {
throw new IOError(e);
}
}
/**
* Convert JDBC Result to JSON
*
* @param rs open and unused ResultSet
* @param name name of the resultset
* @return JSON object with one entry: {name: result of ResultSet}
* @throws SQLException
*/
public static String toJson(ResultSet rs, String name) throws SQLException {
try {
ResultSetMetaData meta = rs.getMetaData();
StringWriter sw = new StringWriter();
JsonGenerator writer = mapper.getFactory().createGenerator(sw);
writer.writeStartObject();
writer.writeFieldName(name);
writer.writeStartArray();
while (rs.next()) {
writer.writeStartObject();
for (int i = 1; i <= meta.getColumnCount(); i++) {
writer.writeFieldName(meta.getColumnLabel(i));
writer.writeObject(rs.getObject(i));
}
writer.writeEndObject();
}
writer.writeEndArray();
writer.writeEndObject();
writer.flush();
return sw.toString();
} catch (IOException e) {
throw new IOError(e);
}
}
}

View file

@ -0,0 +1,83 @@
package krusty;
import java.io.IOError;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import static spark.Spark.*;
public class ServerMain {
public static int PORT = 8888;
public static String API_ENTRYPOINT = "/api/v1";
private Database db;
public void startServer() {
staticFiles.location("/public");
db = new Database();
db.connect();
port(PORT);
enableCORS();
initIndex();
initRoutes();
}
private void initIndex() {
try {
byte[] indexData = getClass().getResource("/public/index.html").openStream().readAllBytes();
final String index = new String(indexData, StandardCharsets.UTF_8);
get("/", (req, res) -> index);
} catch (IOException e) {
throw new IOError(e);
}
}
private void initRoutes() {
get(API_ENTRYPOINT + "/customers", (req, res) -> db.getCustomers(req, res));
get(API_ENTRYPOINT + "/raw-materials", (req, res) -> db.getRawMaterials(req, res));
get(API_ENTRYPOINT + "/cookies", (req, res) -> db.getCookies(req, res));
get(API_ENTRYPOINT + "/recipes", (req, res) -> db.getRecipes(req, res));
get(API_ENTRYPOINT + "/pallets", (req, res) -> db.getPallets(req, res));
post(API_ENTRYPOINT + "/reset", (req, res) -> db.reset(req, res));
post(API_ENTRYPOINT + "/pallets", (req, res) -> db.createPallet(req, res));
}
public void stopServer() {
stop();
}
/**
* Setup CORS, see:
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
* - http://sparkjava.com/tutorials/cors
*/
private void enableCORS() {
options("/*", (request, response) -> {
String accessControlRequestHeaders = request.headers("Access-Control-Request-Headers");
if (accessControlRequestHeaders != null) {
response.header("Access-Control-Allow-Headers", accessControlRequestHeaders);
}
String accessControlRequestMethod = request.headers("Access-Control-Request-Method");
if (accessControlRequestMethod != null) {
response.header("Access-Control-Allow-Methods", accessControlRequestMethod);
}
return "OK";
});
before((request, response) -> {
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Headers", "Content-Type, Accept");
response.type("application/json");
});
}
public static void main(String[] args) throws InterruptedException {
new ServerMain().startServer();
}
}

BIN
src/main/resources/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/main/resources/public/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"><title>Krusty</title><link href="/static/css/main.59f83d58.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],i=r[1],a=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var i=t[l];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this.webpackJsonpfrontend=this.webpackJsonpfrontend||[],i=l.push.bind(l);l.push=r,l=l.slice();for(var a=0;a<l.length;a++)r(l[a]);var p=i;t()}([])</script><script src="/static/js/2.0a7bcc05.chunk.js"></script><script src="/static/js/main.4ee489f9.chunk.js"></script></body></html>

View file

@ -0,0 +1,2 @@
div.App{width:800px;margin:0 auto}@media screen and (max-width:800px){div.App{width:100%}}body{margin:10px;padding:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}code{font-family:source-code-pro,Menlo,Monaco,Consolas,"Courier New",monospace}
/*# sourceMappingURL=main.59f83d58.chunk.css.map */

View file

@ -0,0 +1 @@
{"version":3,"sources":["index.css"],"names":[],"mappings":"AAAA,QACC,WAAY,CACZ,aACD,CAEA,oCACE,QACE,UACF,CACF,CAEA,KACE,WAAY,CACZ,SAAU,CACV,mJAEY,CACZ,kCAAmC,CACnC,iCACF,CAEA,KACE,yEAEF","file":"main.59f83d58.chunk.css","sourcesContent":["div.App {\n\twidth: 800px;\n\tmargin: 0 auto;\n}\n\n@media screen and (max-width: 800px) {\n div.App {\n width: 100%;\n }\n}\n\nbody {\n margin: 10px;\n padding: 0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n monospace;\n}\n"]}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,49 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/**
* A better abstraction over CSS.
*
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present
* @website https://github.com/cssinjs/jss
* @license MIT
*/
/** @license React v0.18.0
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v16.12.0
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v16.12.0
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v16.12.0
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,2 @@
!function(e){function r(r){for(var n,f,l=r[0],i=r[1],a=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var i=t[l];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this.webpackJsonpfrontend=this.webpackJsonpfrontend||[],i=l.push.bind(l);l.push=r,l=l.slice();for(var a=0;a<l.length;a++)r(l[a]);var p=i;t()}([]);
//# sourceMappingURL=runtime-main.1c2d59f4.js.map

File diff suppressed because one or more lines are too long

BIN
src/test/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/test/java/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,195 @@
package krusty;
import static org.junit.Assert.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.json.JSONException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.skyscreamer.jsonassert.JSONAssert;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class KrustyTests {
public static final String BASE_URL = "http://localhost:" + ServerMain.PORT + ServerMain.API_ENTRYPOINT + "/";
/**
*
* Test cases
*
* Note that they are ordered in alphabetical order,
* this because one test case creates pallets that other use.
*
*/
@Test
public void test01Customers() throws JSONException {
String expected = readFile("ExpectedCustomers.json");
String actual = getURL("customers");
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void test02Cookies() throws JSONException {
String expected = readFile("ExpectedCookies.json");
String actual = getURL("cookies");
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void test03RawMaterials() throws JSONException {
String expected = readFile("ExpectedRawMaterialsStart.json");
String actual = getURL("raw-materials");
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void test04CreatePallets() throws JSONException {
createPallet("Nut ring");
createPallet("Nut ring");
createPallet("Tango");
createPallet("Amneris");
createPallet("Amneris");
createPallet("Amneris");
createPallet("Berliner");
String expected = readFile("ExpectedRawMaterialsAfterCreatingPallets.json");
String actual = getURL("raw-materials");
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void test05Pallets() throws JSONException {
String expected = readFile("ExpectedPallets.json");
String actual = getURL("pallets");
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void test06PalletsByCookie() throws JSONException, UnirestException {
String expected = readFile("ExpectedPalletsByCookie.json");
String actual = Unirest.get(BASE_URL + "pallets")
.queryString("cookie", "Nut ring")
.asString().getBody();
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void test07PalletsByCookieAndDate() throws JSONException, UnirestException {
String expected = readFile("ExpectedPalletsByCookie.json");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String today = formatter.format(new Date());
String actual = Unirest.get(BASE_URL + "pallets")
.queryString("cookie", "Nut ring")
.queryString("from", today)
.asString().getBody();
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void test08PalletsByCookieAndDate2() throws JSONException, UnirestException {
String expected = readFile("ExpectedPalletsEmpty.json");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, 1);
String nextYear = formatter.format(calendar.getTime());
String actual = Unirest.get(BASE_URL + "pallets")
.queryString("cookie", "Nut ring")
.queryString("from", nextYear)
.asString().getBody();
JSONAssert.assertEquals(expected, actual, false);
}
/**
*
* Auxiliary methods
*
*/
protected String readFile(String file) {
try {
String path = "src/test/resources/" + file;
return new String(Files.readAllBytes(Paths.get(path)));
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
return "";
}
protected String getURL(String url) {
try {
HttpResponse<String> res = Unirest.get(BASE_URL + url).asString();
return res.getBody();
} catch (UnirestException e) {
fail("Connection failed.\n" + e.getMessage());
}
return "";
}
protected String createPallet(String cookie) {
try {
HttpResponse<String> res = Unirest.post(BASE_URL + "pallets")
.queryString("cookie", cookie)
.asString();
return res.getBody();
} catch (UnirestException e) {
fail("Connection failed.\n" + e.getMessage());
}
return "";
}
/**
*
* Automatically start REST server if it is not running and reset database.
*
*/
private static ServerMain server;
@BeforeClass
public static void startServer() throws InterruptedException {
try {
// Check if rest server is running
Unirest.get(BASE_URL).asString();
} catch (UnirestException e) {
// Start REST server and sleep a bit before start running test cases
server = new ServerMain();
server.startServer();
Thread.sleep(250);
}
// Reset database
try {
Unirest.post(BASE_URL + "reset").asString();
} catch (UnirestException e2) {
fail(e2.getMessage());
}
}
@AfterClass
public static void stopServer() {
if (server != null) {
server.stopServer();
}
}
}

View file

@ -0,0 +1,10 @@
{
"cookies": [
{"name": "Amneris"},
{"name": "Berliner"},
{"name": "Nut cookie"},
{"name": "Nut ring"},
{"name": "Tango"},
{"name": "Almond delight"}
]
}

View file

@ -0,0 +1,12 @@
{
"customers": [
{"name": "Bjudkakor AB", "address": "Ystad"},
{"name": "Finkakor AB", "address": "Helsingborg"},
{"name": "Gästkakor AB", "address": "Hässleholm"},
{"name": "Kaffebröd AB", "address": "Landskrona"},
{"name": "Kalaskakor AB", "address": "Trelleborg"},
{"name": "Partykakor AB", "address": "Kristianstad"},
{"name": "Skånekakor AB", "address": "Perstorp"},
{"name": "Småbröd AB", "address": "Malmö"}
]
}

View file

@ -0,0 +1,11 @@
{
"pallets": [
{"cookie": "Amneris", "blocked": "no"},
{"cookie": "Amneris", "blocked": "no"},
{"cookie": "Amneris", "blocked": "no"},
{"cookie": "Berliner", "blocked": "no"},
{"cookie": "Nut ring", "blocked": "no"},
{"cookie": "Nut ring", "blocked": "no"},
{"cookie": "Tango", "blocked": "no"}
]
}

View file

@ -0,0 +1,6 @@
{
"pallets": [
{"cookie": "Nut ring", "blocked": "no"},
{"cookie": "Nut ring", "blocked": "no"}
]
}

View file

@ -0,0 +1,4 @@
{
"pallets": [
]
}

View file

@ -0,0 +1,23 @@
{
"raw-materials": [
{"name": "Bread crumbs", "amount": 500000, "unit": "g"},
{"name": "Butter", "amount": 386600, "unit": "g"},
{"name": "Chocolate", "amount": 497300, "unit": "g"},
{"name": "Chopped almonds", "amount": 500000, "unit": "g"},
{"name": "Cinnamon", "amount": 500000, "unit": "g"},
{"name": "Egg whites", "amount": 500000, "unit": "ml"},
{"name": "Eggs", "amount": 456800, "unit": "g"},
{"name": "Fine-ground nuts", "amount": 500000, "unit": "g"},
{"name": "Flour", "amount": 416300, "unit": "g"},
{"name": "Ground, roasted nuts", "amount": 500000, "unit": "g"},
{"name": "Icing sugar", "amount": 474080, "unit": "g"},
{"name": "Marzipan", "amount": 378500, "unit": "g"},
{"name": "Potato starch", "amount": 495950, "unit": "g"},
{"name": "Roasted, chopped nuts", "amount": 475700, "unit": "g"},
{"name": "Sodium bicarbonate", "amount": 499784, "unit": "g"},
{"name": "Sugar", "amount": 486500, "unit": "g"},
{"name": "Vanilla", "amount": 499892, "unit": "g"},
{"name": "Vanilla sugar", "amount": 499730, "unit": "g"},
{"name": "Wheat flour", "amount": 495950, "unit": "g"}
]
}

View file

@ -0,0 +1,23 @@
{
"raw-materials": [
{"name": "Bread crumbs", "amount": 500000, "unit": "g"},
{"name": "Butter", "amount": 500000, "unit": "g"},
{"name": "Chocolate", "amount": 500000, "unit": "g"},
{"name": "Chopped almonds", "amount": 500000, "unit": "g"},
{"name": "Cinnamon", "amount": 500000, "unit": "g"},
{"name": "Egg whites", "amount": 500000, "unit": "ml"},
{"name": "Eggs", "amount": 500000, "unit": "g"},
{"name": "Fine-ground nuts", "amount": 500000, "unit": "g"},
{"name": "Flour", "amount": 500000, "unit": "g"},
{"name": "Ground, roasted nuts", "amount": 500000, "unit": "g"},
{"name": "Icing sugar", "amount": 500000, "unit": "g"},
{"name": "Marzipan", "amount": 500000, "unit": "g"},
{"name": "Potato starch", "amount": 500000, "unit": "g"},
{"name": "Roasted, chopped nuts", "amount": 500000, "unit": "g"},
{"name": "Sodium bicarbonate", "amount": 500000, "unit": "g"},
{"name": "Sugar", "amount": 500000, "unit": "g"},
{"name": "Vanilla", "amount": 500000, "unit": "g"},
{"name": "Vanilla sugar", "amount": 500000, "unit": "g"},
{"name": "Wheat flour", "amount": 500000, "unit": "g"}
]
}