Recipe App
Created
April 11, 2020 21:07
-
-
Save vcheruk2/09307f625467a04bb0dbd26a3eba2358 to your computer and use it in GitHub Desktop.
Ingredient Servie Impl / Test Failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
jobs: # a collection of steps | |
build: # runs not using Workflows must have a `build` job as entry point | |
working_directory: ~/circleci-demo-java-spring # directory where steps will run | |
docker: # run the steps with Docker | |
- image: circleci/openjdk:11.0.3-jdk-stretch # ...with this image as the primary container; this is where all `steps` will run | |
steps: # a collection of executable commands | |
- checkout # check out source code to working directory | |
- restore_cache: # restore the saved cache after the first run or if `pom.xml` has changed | |
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/ | |
key: circleci-demo-java-spring-{{ checksum "pom.xml" }} | |
- run: mvn dependency:go-offline # gets the project dependencies | |
- save_cache: # saves the project dependencies | |
paths: | |
- ~/.m2 | |
key: circleci-demo-java-spring-{{ checksum "pom.xml" }} | |
- run: mvn package # run the actual tests | |
- store_test_results: # uploads the test metadata from the `target/surefire-reports` directory so that it can show up in the CircleCI dashboard. | |
# Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/ | |
path: target/surefire-reports | |
- store_artifacts: # store the uberjar as an artifact | |
# Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/ | |
path: target/demo-java-spring-0.0.1-SNAPSHOT.jar | |
# See https://circleci.com/docs/2.0/deployment-integrations/ for deploy examples | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HELP.md | |
target/ | |
!.mvn/wrapper/maven-wrapper.jar | |
!**/src/main/** | |
!**/src/test/** | |
### STS ### | |
.apt_generated | |
.classpath | |
.factorypath | |
.project | |
.settings | |
.springBeans | |
.sts4-cache | |
### IntelliJ IDEA ### | |
.idea | |
*.iws | |
*.iml | |
*.ipr | |
### NetBeans ### | |
/nbproject/private/ | |
/nbbuild/ | |
/dist/ | |
/nbdist/ | |
/.nb-gradle/ | |
build/ | |
### VS Code ### | |
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip | |
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2007-present the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* https://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
import java.net.*; | |
import java.io.*; | |
import java.nio.channels.*; | |
import java.util.Properties; | |
public class MavenWrapperDownloader { | |
private static final String WRAPPER_VERSION = "0.5.6"; | |
/** | |
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | |
*/ | |
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" | |
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; | |
/** | |
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | |
* use instead of the default one. | |
*/ | |
private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | |
".mvn/wrapper/maven-wrapper.properties"; | |
/** | |
* Path where the maven-wrapper.jar will be saved to. | |
*/ | |
private static final String MAVEN_WRAPPER_JAR_PATH = | |
".mvn/wrapper/maven-wrapper.jar"; | |
/** | |
* Name of the property which should be used to override the default download url for the wrapper. | |
*/ | |
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | |
public static void main(String args[]) { | |
System.out.println("- Downloader started"); | |
File baseDirectory = new File(args[0]); | |
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | |
// If the maven-wrapper.properties exists, read it and check if it contains a custom | |
// wrapperUrl parameter. | |
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | |
String url = DEFAULT_DOWNLOAD_URL; | |
if (mavenWrapperPropertyFile.exists()) { | |
FileInputStream mavenWrapperPropertyFileInputStream = null; | |
try { | |
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | |
Properties mavenWrapperProperties = new Properties(); | |
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | |
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | |
} catch (IOException e) { | |
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | |
} finally { | |
try { | |
if (mavenWrapperPropertyFileInputStream != null) { | |
mavenWrapperPropertyFileInputStream.close(); | |
} | |
} catch (IOException e) { | |
// Ignore ... | |
} | |
} | |
} | |
System.out.println("- Downloading from: " + url); | |
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | |
if (!outputFile.getParentFile().exists()) { | |
if (!outputFile.getParentFile().mkdirs()) { | |
System.out.println( | |
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | |
} | |
} | |
System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | |
try { | |
downloadFileFromURL(url, outputFile); | |
System.out.println("Done"); | |
System.exit(0); | |
} catch (Throwable e) { | |
System.out.println("- Error downloading"); | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
} | |
private static void downloadFileFromURL(String urlString, File destination) throws Exception { | |
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { | |
String username = System.getenv("MVNW_USERNAME"); | |
char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); | |
Authenticator.setDefault(new Authenticator() { | |
@Override | |
protected PasswordAuthentication getPasswordAuthentication() { | |
return new PasswordAuthentication(username, password); | |
} | |
}); | |
} | |
URL website = new URL(urlString); | |
ReadableByteChannel rbc; | |
rbc = Channels.newChannel(website.openStream()); | |
FileOutputStream fos = new FileOutputStream(destination); | |
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |
fos.close(); | |
rbc.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ---------------------------------------------------------------------------- | |
# Licensed to the Apache Software Foundation (ASF) under one | |
# or more contributor license agreements. See the NOTICE file | |
# distributed with this work for additional information | |
# regarding copyright ownership. The ASF licenses this file | |
# to you under the Apache License, Version 2.0 (the | |
# "License"); you may not use this file except in compliance | |
# with the License. You may obtain a copy of the License at | |
# | |
# https://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, | |
# software distributed under the License is distributed on an | |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
# KIND, either express or implied. See the License for the | |
# specific language governing permissions and limitations | |
# under the License. | |
# ---------------------------------------------------------------------------- | |
# ---------------------------------------------------------------------------- | |
# Maven Start Up Batch script | |
# | |
# Required ENV vars: | |
# ------------------ | |
# JAVA_HOME - location of a JDK home dir | |
# | |
# Optional ENV vars | |
# ----------------- | |
# M2_HOME - location of maven2's installed home dir | |
# MAVEN_OPTS - parameters passed to the Java VM when running Maven | |
# e.g. to debug Maven itself, use | |
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 | |
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files | |
# ---------------------------------------------------------------------------- | |
if [ -z "$MAVEN_SKIP_RC" ]; then | |
if [ -f /etc/mavenrc ]; then | |
. /etc/mavenrc | |
fi | |
if [ -f "$HOME/.mavenrc" ]; then | |
. "$HOME/.mavenrc" | |
fi | |
fi | |
# OS specific support. $var _must_ be set to either true or false. | |
cygwin=false | |
darwin=false | |
mingw=false | |
case "$(uname)" in | |
CYGWIN*) cygwin=true ;; | |
MINGW*) mingw=true ;; | |
Darwin*) | |
darwin=true | |
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home | |
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html | |
if [ -z "$JAVA_HOME" ]; then | |
if [ -x "/usr/libexec/java_home" ]; then | |
export JAVA_HOME="$(/usr/libexec/java_home)" | |
else | |
export JAVA_HOME="/Library/Java/Home" | |
fi | |
fi | |
;; | |
esac | |
if [ -z "$JAVA_HOME" ]; then | |
if [ -r /etc/gentoo-release ]; then | |
JAVA_HOME=$(java-config --jre-home) | |
fi | |
fi | |
if [ -z "$M2_HOME" ]; then | |
## resolve links - $0 may be a link to maven's home | |
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 | |
saveddir=$(pwd) | |
M2_HOME=$(dirname "$PRG")/.. | |
# make it fully qualified | |
M2_HOME=$(cd "$M2_HOME" && pwd) | |
cd "$saveddir" | |
# echo Using m2 at $M2_HOME | |
fi | |
# For Cygwin, ensure paths are in UNIX format before anything is touched | |
if $cygwin; then | |
[ -n "$M2_HOME" ] && | |
M2_HOME=$(cygpath --unix "$M2_HOME") | |
[ -n "$JAVA_HOME" ] && | |
JAVA_HOME=$(cygpath --unix "$JAVA_HOME") | |
[ -n "$CLASSPATH" ] && | |
CLASSPATH=$(cygpath --path --unix "$CLASSPATH") | |
fi | |
# For Mingw, ensure paths are in UNIX format before anything is touched | |
if $mingw; then | |
[ -n "$M2_HOME" ] && | |
M2_HOME="$( ( | |
cd "$M2_HOME" | |
pwd | |
))" | |
[ -n "$JAVA_HOME" ] && | |
JAVA_HOME="$( ( | |
cd "$JAVA_HOME" | |
pwd | |
))" | |
fi | |
if [ -z "$JAVA_HOME" ]; then | |
javaExecutable="$(which javac)" | |
if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then | |
# readlink(1) is not available as standard on Solaris 10. | |
readLink=$(which readlink) | |
if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then | |
if $darwin; then | |
javaHome="$(dirname \"$javaExecutable\")" | |
javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" | |
else | |
javaExecutable="$(readlink -f \"$javaExecutable\")" | |
fi | |
javaHome="$(dirname \"$javaExecutable\")" | |
javaHome=$(expr "$javaHome" : '\(.*\)/bin') | |
JAVA_HOME="$javaHome" | |
export JAVA_HOME | |
fi | |
fi | |
fi | |
if [ -z "$JAVACMD" ]; then | |
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 | |
else | |
JAVACMD="$(which java)" | |
fi | |
fi | |
if [ ! -x "$JAVACMD" ]; then | |
echo "Error: JAVA_HOME is not defined correctly." >&2 | |
echo " We cannot execute $JAVACMD" >&2 | |
exit 1 | |
fi | |
if [ -z "$JAVA_HOME" ]; then | |
echo "Warning: JAVA_HOME environment variable is not set." | |
fi | |
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher | |
# traverses directory structure from process work directory to filesystem root | |
# first directory with .mvn subdirectory is considered project base directory | |
find_maven_basedir() { | |
if [ -z "$1" ]; then | |
echo "Path not specified to find_maven_basedir" | |
return 1 | |
fi | |
basedir="$1" | |
wdir="$1" | |
while [ "$wdir" != '/' ]; do | |
if [ -d "$wdir"/.mvn ]; then | |
basedir=$wdir | |
break | |
fi | |
# workaround for JBEAP-8937 (on Solaris 10/Sparc) | |
if [ -d "${wdir}" ]; then | |
wdir=$( | |
cd "$wdir/.." | |
pwd | |
) | |
fi | |
# end of workaround | |
done | |
echo "${basedir}" | |
} | |
# concatenates all lines of a file | |
concat_lines() { | |
if [ -f "$1" ]; then | |
echo "$(tr -s '\n' ' ' <"$1")" | |
fi | |
} | |
BASE_DIR=$(find_maven_basedir "$(pwd)") | |
if [ -z "$BASE_DIR" ]; then | |
exit 1 | |
fi | |
########################################################################################## | |
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | |
# This allows using the maven wrapper in projects that prohibit checking in binary data. | |
########################################################################################## | |
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo "Found .mvn/wrapper/maven-wrapper.jar" | |
fi | |
else | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." | |
fi | |
if [ -n "$MVNW_REPOURL" ]; then | |
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |
else | |
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |
fi | |
while IFS="=" read key value; do | |
case "$key" in wrapperUrl) | |
jarUrl="$value" | |
break | |
;; | |
esac | |
done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo "Downloading from: $jarUrl" | |
fi | |
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" | |
if $cygwin; then | |
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") | |
fi | |
if command -v wget >/dev/null; then | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo "Found wget ... using wget" | |
fi | |
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | |
wget "$jarUrl" -O "$wrapperJarPath" | |
else | |
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" | |
fi | |
elif command -v curl >/dev/null; then | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo "Found curl ... using curl" | |
fi | |
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | |
curl -o "$wrapperJarPath" "$jarUrl" -f | |
else | |
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f | |
fi | |
else | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo "Falling back to using Java to download" | |
fi | |
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" | |
# For Cygwin, switch paths to Windows format before running javac | |
if $cygwin; then | |
javaClass=$(cygpath --path --windows "$javaClass") | |
fi | |
if [ -e "$javaClass" ]; then | |
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo " - Compiling MavenWrapperDownloader.java ..." | |
fi | |
# Compiling the Java class | |
("$JAVA_HOME/bin/javac" "$javaClass") | |
fi | |
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | |
# Running the downloader | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo " - Running MavenWrapperDownloader.java ..." | |
fi | |
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") | |
fi | |
fi | |
fi | |
fi | |
########################################################################################## | |
# End of extension | |
########################################################################################## | |
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} | |
if [ "$MVNW_VERBOSE" = true ]; then | |
echo $MAVEN_PROJECTBASEDIR | |
fi | |
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" | |
# For Cygwin, switch paths to Windows format before running java | |
if $cygwin; then | |
[ -n "$M2_HOME" ] && | |
M2_HOME=$(cygpath --path --windows "$M2_HOME") | |
[ -n "$JAVA_HOME" ] && | |
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") | |
[ -n "$CLASSPATH" ] && | |
CLASSPATH=$(cygpath --path --windows "$CLASSPATH") | |
[ -n "$MAVEN_PROJECTBASEDIR" ] && | |
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") | |
fi | |
# Provide a "standardized" way to retrieve the CLI args that will | |
# work with both Windows and non-Windows executions. | |
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" | |
export MAVEN_CMD_LINE_ARGS | |
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain | |
exec "$JAVACMD" \ | |
$MAVEN_OPTS \ | |
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ | |
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ | |
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@REM ---------------------------------------------------------------------------- | |
@REM Licensed to the Apache Software Foundation (ASF) under one | |
@REM or more contributor license agreements. See the NOTICE file | |
@REM distributed with this work for additional information | |
@REM regarding copyright ownership. The ASF licenses this file | |
@REM to you under the Apache License, Version 2.0 (the | |
@REM "License"); you may not use this file except in compliance | |
@REM with the License. You may obtain a copy of the License at | |
@REM | |
@REM https://www.apache.org/licenses/LICENSE-2.0 | |
@REM | |
@REM Unless required by applicable law or agreed to in writing, | |
@REM software distributed under the License is distributed on an | |
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
@REM KIND, either express or implied. See the License for the | |
@REM specific language governing permissions and limitations | |
@REM under the License. | |
@REM ---------------------------------------------------------------------------- | |
@REM ---------------------------------------------------------------------------- | |
@REM Maven Start Up Batch script | |
@REM | |
@REM Required ENV vars: | |
@REM JAVA_HOME - location of a JDK home dir | |
@REM | |
@REM Optional ENV vars | |
@REM M2_HOME - location of maven2's installed home dir | |
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands | |
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending | |
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven | |
@REM e.g. to debug Maven itself, use | |
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 | |
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files | |
@REM ---------------------------------------------------------------------------- | |
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' | |
@echo off | |
@REM set title of command window | |
title %0 | |
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' | |
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% | |
@REM set %HOME% to equivalent of $HOME | |
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") | |
@REM Execute a user defined script before this one | |
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre | |
@REM check for pre script, once with legacy .bat ending and once with .cmd ending | |
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" | |
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" | |
:skipRcPre | |
@setlocal | |
set ERROR_CODE=0 | |
@REM To isolate internal variables from possible post scripts, we use another setlocal | |
@setlocal | |
@REM ==== START VALIDATION ==== | |
if not "%JAVA_HOME%" == "" goto OkJHome | |
echo. | |
echo Error: JAVA_HOME not found in your environment. >&2 | |
echo Please set the JAVA_HOME variable in your environment to match the >&2 | |
echo location of your Java installation. >&2 | |
echo. | |
goto error | |
:OkJHome | |
if exist "%JAVA_HOME%\bin\java.exe" goto init | |
echo. | |
echo Error: JAVA_HOME is set to an invalid directory. >&2 | |
echo JAVA_HOME = "%JAVA_HOME%" >&2 | |
echo Please set the JAVA_HOME variable in your environment to match the >&2 | |
echo location of your Java installation. >&2 | |
echo. | |
goto error | |
@REM ==== END VALIDATION ==== | |
:init | |
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". | |
@REM Fallback to current working directory if not found. | |
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% | |
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir | |
set EXEC_DIR=%CD% | |
set WDIR=%EXEC_DIR% | |
:findBaseDir | |
IF EXIST "%WDIR%"\.mvn goto baseDirFound | |
cd .. | |
IF "%WDIR%"=="%CD%" goto baseDirNotFound | |
set WDIR=%CD% | |
goto findBaseDir | |
:baseDirFound | |
set MAVEN_PROJECTBASEDIR=%WDIR% | |
cd "%EXEC_DIR%" | |
goto endDetectBaseDir | |
:baseDirNotFound | |
set MAVEN_PROJECTBASEDIR=%EXEC_DIR% | |
cd "%EXEC_DIR%" | |
:endDetectBaseDir | |
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig | |
@setlocal EnableExtensions EnableDelayedExpansion | |
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a | |
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% | |
:endReadAdditionalConfig | |
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" | |
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" | |
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain | |
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( | |
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B | |
) | |
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | |
@REM This allows using the maven wrapper in projects that prohibit checking in binary data. | |
if exist %WRAPPER_JAR% ( | |
if "%MVNW_VERBOSE%" == "true" ( | |
echo Found %WRAPPER_JAR% | |
) | |
) else ( | |
if not "%MVNW_REPOURL%" == "" ( | |
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |
) | |
if "%MVNW_VERBOSE%" == "true" ( | |
echo Couldn't find %WRAPPER_JAR%, downloading it ... | |
echo Downloading from: %DOWNLOAD_URL% | |
) | |
powershell -Command "&{"^ | |
"$webclient = new-object System.Net.WebClient;"^ | |
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ | |
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ | |
"}"^ | |
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ | |
"}" | |
if "%MVNW_VERBOSE%" == "true" ( | |
echo Finished downloading %WRAPPER_JAR% | |
) | |
) | |
@REM End of extension | |
@REM Provide a "standardized" way to retrieve the CLI args that will | |
@REM work with both Windows and non-Windows executions. | |
set MAVEN_CMD_LINE_ARGS=%* | |
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* | |
if ERRORLEVEL 1 goto error | |
goto end | |
:error | |
set ERROR_CODE=1 | |
:end | |
@endlocal & set ERROR_CODE=%ERROR_CODE% | |
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost | |
@REM check for post script, once with legacy .bat ending and once with .cmd ending | |
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" | |
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" | |
:skipRcPost | |
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' | |
if "%MAVEN_BATCH_PAUSE%" == "on" pause | |
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% | |
exit /B %ERROR_CODE% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>2.3.0.M3</version> | |
<relativePath/> <!-- lookup parent from repository --> | |
</parent> | |
<groupId>com.ravi</groupId> | |
<artifactId>recipe</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<name>recipe</name> | |
<description>Recipe Project</description> | |
<properties> | |
<java.version>11</java.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-data-jpa</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-thymeleaf</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-devtools</artifactId> | |
<scope>runtime</scope> | |
<optional>true</optional> | |
</dependency> | |
<dependency> | |
<groupId>com.h2database</groupId> | |
<artifactId>h2</artifactId> | |
<scope>runtime</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.projectlombok</groupId> | |
<artifactId>lombok</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.webjars</groupId> | |
<artifactId>bootstrap</artifactId> | |
<version>4.4.1-1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.webjars</groupId> | |
<artifactId>jquery</artifactId> | |
<version>3.4.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-test</artifactId> | |
<scope>test</scope> | |
<exclusions> | |
<exclusion> | |
<groupId>org.junit.vintage</groupId> | |
<artifactId>junit-vintage-engine</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-maven-plugin</artifactId> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.8.0</version> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-surefire-plugin</artifactId> | |
<version>2.22.0</version> | |
<configuration> | |
<argLine> | |
--illegal-access=permit | |
</argLine> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-failsafe-plugin</artifactId> | |
<version>2.22.0</version> | |
<configuration> | |
<argLine> | |
--illegal-access=permit | |
</argLine> | |
</configuration> | |
<executions> | |
<execution> | |
<goals> | |
<goal>integration-test</goal> | |
<goal>verify</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
<repositories> | |
<repository> | |
<id>spring-milestones</id> | |
<name>Spring Milestones</name> | |
<url>https://repo.spring.io/milestone</url> | |
</repository> | |
</repositories> | |
<pluginRepositories> | |
<pluginRepository> | |
<id>spring-milestones</id> | |
<name>Spring Milestones</name> | |
<url>https://repo.spring.io/milestone</url> | |
</pluginRepository> | |
</pluginRepositories> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.bootstrap; | |
import com.ravi.recipe.domain.*; | |
import com.ravi.recipe.repositories.CategoryRepository; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import com.ravi.recipe.repositories.UnitOfMeasureRepository; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.context.ApplicationListener; | |
import org.springframework.context.event.ContextRefreshedEvent; | |
import org.springframework.stereotype.Component; | |
import org.springframework.transaction.annotation.Transactional; | |
import java.math.BigDecimal; | |
import java.util.HashSet; | |
import java.util.Optional; | |
import java.util.Set; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/29/2020 */ | |
@Component | |
@Slf4j | |
public class BootStrap implements ApplicationListener<ContextRefreshedEvent> { | |
private RecipeRepository recipeRepository; | |
private CategoryRepository categoryRepository; | |
private UnitOfMeasureRepository unitOfMeasureRepository; | |
public BootStrap(RecipeRepository recipeRepository, | |
CategoryRepository categoryRepository, | |
UnitOfMeasureRepository unitOfMeasureRepository) { | |
this.recipeRepository = recipeRepository; | |
this.categoryRepository = categoryRepository; | |
this.unitOfMeasureRepository = unitOfMeasureRepository; | |
} | |
@Override | |
@Transactional | |
public void onApplicationEvent(ContextRefreshedEvent event) { | |
Optional<UnitOfMeasure> ounceUom = unitOfMeasureRepository.findByDescription("Ounce"); | |
if(!ounceUom.isPresent()) | |
throw new RuntimeException("Expected UOM for ounce is not found"); | |
Optional<UnitOfMeasure> teaSpoonUom = unitOfMeasureRepository.findByDescription("Teaspoon"); | |
if (!teaSpoonUom.isPresent()) | |
throw new RuntimeException("Expected UOM for teaspoon is not found"); | |
Optional<Category> american = categoryRepository.findByDescription("American"); | |
if (!american.isPresent()) | |
throw new RuntimeException("Expected Category American is not found"); | |
Optional<Category> mexican = categoryRepository.findByDescription("Mexican"); | |
if(!mexican.isPresent()) | |
throw new RuntimeException("Expected Category Mexican is not found"); | |
// Guacamole Recipe | |
Recipe guac = new Recipe(); | |
Ingredient avocados = new Ingredient("Avocados", BigDecimal.valueOf(2), ounceUom.get()); | |
Ingredient salt = new Ingredient("Salt", BigDecimal.valueOf(0.25), teaSpoonUom.get()); | |
Notes guacNotes = new Notes(); | |
//guacNotes.setRecipe(guac); | |
guacNotes.setRecipeNotes("Guac Recipe Notes"); | |
guac.setDescription("Perfect Guacamole"); | |
guac.setCookTime(10); | |
guac.setPrepTime(10); | |
guac.setDifficulty(Difficulty.EASY); | |
guac.setDirections("Directions to make Guac"); | |
guac.setNotes(guacNotes); | |
guac.setServings(4); | |
guac.setUrl("https://www.simplyrecipes.com/recipes/perfect_guacamole/"); | |
guac.setSource("Simply Recipes"); | |
Set<Ingredient> guacIngredients = new HashSet<>(); | |
guacIngredients.add(avocados); | |
guacIngredients.add(salt); | |
guac.setIngredients(guacIngredients); | |
Set<Category> guacCategories = new HashSet<>(); | |
guacCategories.add(american.get()); | |
guacCategories.add(mexican.get()); | |
guac.setCategories(guacCategories); | |
recipeRepository.save(guac); | |
log.debug("Created Guacamole recipe and saved it to the repo"); | |
// Chicken Taco | |
Recipe chickenTaco = new Recipe(); | |
chickenTaco.setDirections("Making of Chicken Taco"); | |
chickenTaco.setDescription("Spicy Chicken Taco"); | |
chickenTaco.setDifficulty(Difficulty.MODERATE); | |
chickenTaco.setSource("Simply Recipes"); | |
chickenTaco.setUrl("https://www.simplyrecipes.com/recipes/spicy_grilled_chicken_tacos/"); | |
chickenTaco.setServings(6); | |
chickenTaco.setCookTime(15); | |
chickenTaco.setPrepTime(20); | |
Notes chickenTacoNotes = new Notes(); | |
chickenTaco.setNotes(chickenTacoNotes); | |
chickenTacoNotes.setRecipeNotes("Chicken Taco Recipe Notes"); | |
Ingredient oil = new Ingredient("Chicken Taco Oil", BigDecimal.valueOf(2), | |
teaSpoonUom.get() ); | |
Ingredient chicken = new Ingredient("Chicken", BigDecimal.valueOf(6), | |
ounceUom.get()); | |
HashSet<Ingredient> chickenTacoIngredients = new HashSet<>(); | |
chickenTacoIngredients.add(oil); | |
chickenTacoIngredients.add(chicken); | |
chickenTaco.setIngredients(chickenTacoIngredients); | |
HashSet<Category> chickenTacoCategories = new HashSet<>(); | |
chickenTacoCategories.add(american.get()); | |
chickenTacoCategories.add(mexican.get()); | |
chickenTaco.setCategories(chickenTacoCategories); | |
recipeRepository.save(chickenTaco); | |
log.debug("Created Chicken Taco and saved it to the repository"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.commands; | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Setter | |
@Getter | |
@NoArgsConstructor | |
public class CategoryCommand { | |
private Long id; | |
private String description; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.commands; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
import java.math.BigDecimal; | |
@Getter | |
@Setter | |
@NoArgsConstructor | |
public class IngredientCommand { | |
private Long id; | |
private Long recipeId; | |
private String description; | |
private BigDecimal amount; | |
private UnitOfMeasureCommand unitOfMeasure; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.commands; | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Getter | |
@Setter | |
@NoArgsConstructor | |
public class NotesCommand { | |
private Long id; | |
private String recipeNotes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.commands; | |
import com.ravi.recipe.domain.Difficulty; | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
import java.util.HashSet; | |
import java.util.Set; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Getter | |
@Setter | |
@NoArgsConstructor | |
public class RecipeCommand { | |
private Long id; | |
private String description; | |
private Integer prepTime; | |
private Integer cookTime; | |
private Integer servings; | |
private String source; | |
private String url; | |
private String directions; | |
private Byte[] image; | |
private Set<IngredientCommand> ingredients = new HashSet<>(); | |
private Difficulty difficulty; | |
private NotesCommand notes; | |
private Set<CategoryCommand> categories = new HashSet<>(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.commands; | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Getter | |
@Setter | |
@NoArgsConstructor | |
public class UnitOfMeasureCommand { | |
private Long id; | |
private String description; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.controller; | |
import com.ravi.recipe.domain.Category; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import com.ravi.recipe.repositories.CategoryRepository; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import com.ravi.recipe.repositories.UnitOfMeasureRepository; | |
import com.ravi.recipe.service.RecipeService; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.Model; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import java.util.Optional; | |
@Controller | |
@Slf4j | |
public class IndexController { | |
private CategoryRepository categoryRepository; | |
private UnitOfMeasureRepository unitOfMeasureRepository; | |
private RecipeRepository recipeRepository; | |
private final RecipeService recipeService; | |
public IndexController(CategoryRepository categoryRepository, UnitOfMeasureRepository unitOfMeasureRepository, RecipeRepository recipeRepository, RecipeService recipeService) { | |
this.categoryRepository = categoryRepository; | |
this.unitOfMeasureRepository = unitOfMeasureRepository; | |
this.recipeRepository = recipeRepository; | |
this.recipeService = recipeService; | |
} | |
@RequestMapping({"/", "", "/index", "/index.html"}) | |
public String mapIndex(Model model){ | |
Optional<Category> optionalCategory = categoryRepository.findByDescription("American"); | |
Optional<UnitOfMeasure> optionalUnitOfMeasure = unitOfMeasureRepository.findByDescription("Teaspoon"); | |
//Iterable<Recipe> recipes = recipeRepository.findAll(); | |
System.out.println("Category ID = "+optionalCategory.get().getId()); | |
System.out.println("Unit of Measure ID = "+optionalUnitOfMeasure.get().getId()); | |
System.out.println("hi 123"); | |
log.debug("Calling index page"); | |
//model.addAttribute("recipes", recipeRepository.findAll()); | |
model.addAttribute("recipes", recipeService.getRecipes()); | |
return "index"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.controller; | |
import com.ravi.recipe.service.IngredientService; | |
import com.ravi.recipe.service.RecipeService; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.Model; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.PathVariable; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/7/2020 */ | |
@Controller | |
public class IngredientController { | |
private final RecipeService recipeService; | |
private final IngredientService ingredientService; | |
public IngredientController(RecipeService recipeService, IngredientService ingredientService) { | |
this.recipeService = recipeService; | |
this.ingredientService = ingredientService; | |
} | |
@GetMapping | |
@RequestMapping({"/recipe/{id}/ingredients"}) | |
public String getIngredients(@PathVariable String id, Model model){ | |
model.addAttribute("recipe", recipeService.findCommandById(Long.valueOf(id))); | |
return "recipe/ingredient/list"; | |
} | |
@GetMapping | |
@RequestMapping({"/recipe/{recipe_id}/ingredient/{ingredient_id}/show"}) | |
public String showIngredients(@PathVariable String recipe_id, | |
@PathVariable String ingredient_id, | |
Model model){ | |
model.addAttribute("ingredient", ingredientService.findByRecipeIdAndIngredientId(Long.valueOf(recipe_id), | |
Long.valueOf(ingredient_id))); | |
return "recipe/ingredient/show"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.controller; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.service.RecipeService; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.Model; | |
import org.springframework.web.bind.annotation.*; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Controller | |
@Slf4j | |
public class RecipeController { | |
RecipeService recipeService; | |
public RecipeController(RecipeService recipeService) { | |
this.recipeService = recipeService; | |
} | |
@GetMapping | |
@RequestMapping({"recipe/{id}/show"}) | |
public String getRecipeById(@PathVariable String id, Model model){ | |
model.addAttribute("recipe", recipeService.findById(Long.valueOf(id))); | |
return "recipe/show"; | |
} | |
@GetMapping | |
@RequestMapping({"recipe/new"}) | |
public String recipeForm(Model model){ | |
model.addAttribute("recipe", new RecipeCommand()); | |
return "recipe/recipeform"; | |
} | |
@PostMapping | |
@RequestMapping("recipe") | |
public String saveOrUpdate(@ModelAttribute RecipeCommand command){ | |
RecipeCommand savedCommand = recipeService.saveRecipeCommand(command); | |
return "redirect:/recipe/" + savedCommand.getId() + "/show"; | |
} | |
@GetMapping | |
@RequestMapping("recipe/{id}/update") | |
public String updateRecipe(@PathVariable String id, Model model){ | |
model.addAttribute("recipe", recipeService.findCommandById(Long.valueOf(id))); | |
return "recipe/recipeform"; | |
} | |
@GetMapping | |
@RequestMapping("recipe/{id}/delete") | |
public String deleteRecipe(@PathVariable String id){ | |
log.debug("Deleting id: " + id); | |
recipeService.deleteById(Long.valueOf(id)); | |
return "redirect:/"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.CategoryCommand; | |
import com.ravi.recipe.domain.Category; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class CategoryCommandToCategory implements Converter<CategoryCommand, Category> { | |
@Synchronized | |
@Override | |
@Nullable | |
public Category convert(CategoryCommand source) { | |
if (source == null) | |
return null; | |
final Category category = new Category(); | |
category.setId(source.getId()); | |
category.setDescription(source.getDescription()); | |
return category; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.CategoryCommand; | |
import com.ravi.recipe.domain.Category; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class CategoryToCategoryCommand implements Converter<Category, CategoryCommand> { | |
@Synchronized | |
@Override | |
@Nullable | |
public CategoryCommand convert(Category source) { | |
if(source == null) | |
return null; | |
final CategoryCommand categoryCommand = new CategoryCommand(); | |
categoryCommand.setDescription(source.getDescription()); | |
categoryCommand.setId(source.getId()); | |
return categoryCommand; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.domain.Ingredient; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class IngredientCommandToIngredient implements Converter<IngredientCommand, Ingredient> { | |
private final UnitOfMeasureCommandToUnitOfMeasure uomConverter; | |
public IngredientCommandToIngredient(UnitOfMeasureCommandToUnitOfMeasure uomConverter) { | |
this.uomConverter = uomConverter; | |
} | |
@Override | |
@Nullable | |
@Synchronized | |
public Ingredient convert(IngredientCommand source) { | |
if (source == null) | |
return null; | |
final Ingredient ingredient = new Ingredient(); | |
ingredient.setId(source.getId()); | |
ingredient.setAmount(source.getAmount()); | |
ingredient.setDescription(source.getDescription()); | |
ingredient.setUom(uomConverter.convert(source.getUnitOfMeasure())); | |
return ingredient; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.domain.Ingredient; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class IngredientToIngredientCommand implements Converter<Ingredient, IngredientCommand> { | |
private final UnitOfMeasureToUnitOfMeasureCommand uomConverter; | |
public IngredientToIngredientCommand(UnitOfMeasureToUnitOfMeasureCommand uomConverter) { | |
this.uomConverter = uomConverter; | |
} | |
@Synchronized | |
@Nullable | |
@Override | |
public IngredientCommand convert(Ingredient ingredient) { | |
if (ingredient == null) { | |
return null; | |
} | |
IngredientCommand ingredientCommand = new IngredientCommand(); | |
ingredientCommand.setId(ingredient.getId()); | |
ingredientCommand.setAmount(ingredient.getAmount()); | |
ingredientCommand.setDescription(ingredient.getDescription()); | |
ingredientCommand.setUnitOfMeasure(uomConverter.convert(ingredient.getUom())); | |
return ingredientCommand; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.NotesCommand; | |
import com.ravi.recipe.domain.Notes; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class NotesCommandToNotes implements Converter<NotesCommand, Notes> { | |
@Synchronized | |
@Nullable | |
@Override | |
public Notes convert(NotesCommand source) { | |
if(source == null) { | |
return null; | |
} | |
final Notes notes = new Notes(); | |
notes.setId(source.getId()); | |
notes.setRecipeNotes(source.getRecipeNotes()); | |
return notes; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.NotesCommand; | |
import com.ravi.recipe.domain.Notes; | |
import com.sun.istack.Nullable; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class NotesToNotesCommand implements Converter<Notes, NotesCommand> { | |
@Synchronized | |
@Nullable | |
@Override | |
public NotesCommand convert(Notes source) { | |
if (source == null) { | |
return null; | |
} | |
final NotesCommand notesCommand = new NotesCommand(); | |
notesCommand.setId(source.getId()); | |
notesCommand.setRecipeNotes(source.getRecipeNotes()); | |
return notesCommand; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.domain.Recipe; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class RecipeCommandToRecipe implements Converter<RecipeCommand, Recipe> { | |
private final CategoryCommandToCategory categoryConveter; | |
private final IngredientCommandToIngredient ingredientConverter; | |
private final NotesCommandToNotes notesConverter; | |
public RecipeCommandToRecipe(CategoryCommandToCategory categoryConveter, IngredientCommandToIngredient ingredientConverter, | |
NotesCommandToNotes notesConverter) { | |
this.categoryConveter = categoryConveter; | |
this.ingredientConverter = ingredientConverter; | |
this.notesConverter = notesConverter; | |
} | |
@Override | |
@Nullable | |
@Synchronized | |
public Recipe convert(RecipeCommand source) { | |
if (source == null) { | |
return null; | |
} | |
final Recipe recipe = new Recipe(); | |
recipe.setId(source.getId()); | |
recipe.setCookTime(source.getCookTime()); | |
recipe.setPrepTime(source.getPrepTime()); | |
recipe.setDescription(source.getDescription()); | |
recipe.setDifficulty(source.getDifficulty()); | |
recipe.setDirections(source.getDirections()); | |
recipe.setServings(source.getServings()); | |
recipe.setSource(source.getSource()); | |
recipe.setUrl(source.getUrl()); | |
recipe.setNotes(notesConverter.convert(source.getNotes())); | |
if (source.getCategories() != null && source.getCategories().size() > 0){ | |
source.getCategories() | |
.forEach( category -> recipe.getCategories().add(categoryConveter.convert(category))); | |
} | |
if (source.getIngredients() != null && source.getIngredients().size() > 0){ | |
source.getIngredients() | |
.forEach(ingredient -> recipe.getIngredients().add(ingredientConverter.convert(ingredient))); | |
} | |
return recipe; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.domain.Category; | |
import com.ravi.recipe.domain.Recipe; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class RecipeToRecipeCommand implements Converter<Recipe, RecipeCommand> { | |
private final CategoryToCategoryCommand categoryConveter; | |
private final IngredientToIngredientCommand ingredientConverter; | |
private final NotesToNotesCommand notesConverter; | |
public RecipeToRecipeCommand(CategoryToCategoryCommand categoryConveter, IngredientToIngredientCommand ingredientConverter, | |
NotesToNotesCommand notesConverter) { | |
this.categoryConveter = categoryConveter; | |
this.ingredientConverter = ingredientConverter; | |
this.notesConverter = notesConverter; | |
} | |
@Synchronized | |
@Nullable | |
@Override | |
public RecipeCommand convert(Recipe source) { | |
if (source == null) { | |
return null; | |
} | |
final RecipeCommand command = new RecipeCommand(); | |
command.setId(source.getId()); | |
command.setCookTime(source.getCookTime()); | |
command.setPrepTime(source.getPrepTime()); | |
command.setDescription(source.getDescription()); | |
command.setDifficulty(source.getDifficulty()); | |
command.setDirections(source.getDirections()); | |
command.setServings(source.getServings()); | |
command.setSource(source.getSource()); | |
command.setUrl(source.getUrl()); | |
command.setNotes(notesConverter.convert(source.getNotes())); | |
if (source.getCategories() != null && source.getCategories().size() > 0){ | |
source.getCategories() | |
.forEach((Category category) -> command.getCategories().add(categoryConveter.convert(category))); | |
} | |
if (source.getIngredients() != null && source.getIngredients().size() > 0){ | |
source.getIngredients() | |
.forEach(ingredient -> command.getIngredients().add(ingredientConverter.convert(ingredient))); | |
} | |
return command; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.UnitOfMeasureCommand; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class UnitOfMeasureCommandToUnitOfMeasure implements Converter<UnitOfMeasureCommand, UnitOfMeasure> { | |
@Synchronized | |
@Override | |
@Nullable | |
public UnitOfMeasure convert(UnitOfMeasureCommand source) { | |
if (source == null) | |
return null; | |
final UnitOfMeasure uom = new UnitOfMeasure(); | |
uom.setId(source.getId()); | |
uom.setDescription(source.getDescription()); | |
return uom; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.UnitOfMeasureCommand; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import lombok.Synchronized; | |
import org.springframework.core.convert.converter.Converter; | |
import org.springframework.lang.Nullable; | |
import org.springframework.stereotype.Component; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@Component | |
public class UnitOfMeasureToUnitOfMeasureCommand implements Converter<UnitOfMeasure, UnitOfMeasureCommand> { | |
@Override | |
@Nullable | |
@Synchronized | |
public UnitOfMeasureCommand convert(UnitOfMeasure source) { | |
if(source == null) | |
return null; | |
final UnitOfMeasureCommand unitOfMeasureCommand = new UnitOfMeasureCommand(); | |
unitOfMeasureCommand.setId(source.getId()); | |
unitOfMeasureCommand.setDescription(source.getDescription()); | |
return unitOfMeasureCommand; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.domain; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/29/2020 */ | |
import lombok.Data; | |
import lombok.EqualsAndHashCode; | |
import javax.persistence.*; | |
import java.util.HashSet; | |
import java.util.Set; | |
@Entity | |
@EqualsAndHashCode(exclude = {"recipes"}) | |
@Data | |
public class Category { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Long id; | |
private String description; | |
@ManyToMany(mappedBy = "categories") | |
private Set<Recipe> recipes = new HashSet<>(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.domain; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/28/2020 */ | |
public enum Difficulty { | |
EASY, | |
MODERATE, | |
DIFFICULT | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.domain; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/28/2020 */ | |
import lombok.EqualsAndHashCode; | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
import javax.persistence.*; | |
import java.math.BigDecimal; | |
@EqualsAndHashCode(exclude = {"recipe"}) | |
@Entity | |
@NoArgsConstructor | |
@Getter | |
@Setter | |
public class Ingredient { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Long id; | |
private String description; | |
private BigDecimal amount; | |
@ManyToOne | |
private Recipe recipe; | |
@OneToOne(fetch = FetchType.EAGER) | |
private UnitOfMeasure uom; | |
public Ingredient(String description, BigDecimal amount, UnitOfMeasure uom) { | |
this.description = description; | |
this.amount = amount; | |
this.uom = uom; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.domain; | |
import lombok.Data; | |
import lombok.EqualsAndHashCode; | |
import javax.persistence.*; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/28/2020 */ | |
@Data | |
@EqualsAndHashCode(exclude = {"recipe"}) | |
@Entity | |
public class Notes { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Long id; | |
@OneToOne | |
private Recipe recipe; | |
@Lob | |
private String recipeNotes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.domain; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/28/2020 */ | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
import javax.persistence.*; | |
import java.util.HashSet; | |
import java.util.Set; | |
@Entity | |
@NoArgsConstructor | |
@Getter | |
@Setter | |
public class Recipe { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Long id; | |
private String description; | |
private Integer prepTime; | |
private Integer cookTime; | |
private Integer servings; | |
private String source; | |
private String url; | |
@Lob | |
private String directions; | |
@Lob | |
private Byte[] image; | |
@Enumerated(value = EnumType.STRING) | |
private Difficulty difficulty; | |
@OneToOne(cascade = CascadeType.ALL) | |
private Notes notes; | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "recipe") | |
private Set<Ingredient> ingredients = new HashSet<>(); | |
@ManyToMany | |
@JoinTable(name = "recipe_category", | |
joinColumns = @JoinColumn(name = "recipe_id"), | |
inverseJoinColumns = @JoinColumn(name = "category_id")) | |
private Set<Category> categories = new HashSet<>(); | |
public void setNotes(Notes notes) { | |
if (notes != null){ | |
this.notes = notes; | |
notes.setRecipe(this); | |
} | |
} | |
public Recipe addIngredient(Ingredient ingredient){ | |
ingredient.setRecipe(this); | |
this.ingredients.add(ingredient); | |
return this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.domain; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/28/2020 */ | |
import lombok.Data; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
@Data | |
@Entity | |
public class UnitOfMeasure { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Long id; | |
private String description; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
@SpringBootApplication | |
public class RecipeApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(RecipeApplication.class, args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.repositories; | |
import com.ravi.recipe.domain.Category; | |
import org.springframework.data.repository.CrudRepository; | |
import java.util.Optional; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/29/2020 */ | |
public interface CategoryRepository extends CrudRepository<Category, Long> { | |
Optional<Category> findByDescription(String description); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.repositories; | |
import com.ravi.recipe.domain.Recipe; | |
import org.springframework.data.repository.CrudRepository; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/29/2020 */ | |
public interface RecipeRepository extends CrudRepository<Recipe, Long> { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.repositories; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import org.springframework.data.repository.CrudRepository; | |
import java.util.Optional; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/29/2020 */ | |
public interface UnitOfMeasureRepository extends CrudRepository<UnitOfMeasure, Long> { | |
Optional<UnitOfMeasure> findByDescription(String description); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
public interface BasicService { | |
public String getRecipe(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import org.springframework.stereotype.Service; | |
@Service | |
public class BasicServiceImpl implements BasicService { | |
@Override | |
public String getRecipe() { | |
return "Basic Recipe"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import com.ravi.recipe.commands.IngredientCommand; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/11/2020 */ | |
public interface IngredientService { | |
IngredientCommand findByRecipeIdAndIngredientId(Long recipeId, Long ingredientId); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.converters.IngredientToIngredientCommand; | |
import com.ravi.recipe.domain.Ingredient; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.stereotype.Service; | |
import java.util.Optional; | |
import java.util.Set; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/11/2020 */ | |
@Service | |
@Slf4j | |
public class IngredientServiceImpl implements IngredientService { | |
private final IngredientToIngredientCommand ingredientToIngredientCommand; | |
private final RecipeRepository recipeRepository; | |
public IngredientServiceImpl(IngredientToIngredientCommand ingredientToIngredientCommand, | |
RecipeRepository recipeRepository) { | |
this.ingredientToIngredientCommand = ingredientToIngredientCommand; | |
this.recipeRepository = recipeRepository; | |
} | |
@Override | |
public IngredientCommand findByRecipeIdAndIngredientId(Long recipeId, Long ingredientId) { | |
Optional<Recipe> recipeOptional = recipeRepository.findById(recipeId); | |
if (!recipeOptional.isPresent()){ | |
// TODO: Yet to implement error handling | |
log.error("Recipe id not found. Id: "+ recipeId); | |
} | |
Recipe recipe = recipeOptional.get(); | |
Optional<IngredientCommand> ingredientCommand = recipe.getIngredients().stream() | |
.filter(ingredient -> ingredient.getId().equals(ingredientId)) | |
.map(ingredient -> ingredientToIngredientCommand.convert(ingredient)).findFirst(); | |
if (!ingredientCommand.isPresent()){ | |
// TODO: Yet to implement error handling | |
log.error("Ingredient id not found. Id: "+ ingredientId); | |
} | |
return ingredientCommand.get(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.domain.Recipe; | |
import java.util.Set; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/29/2020 */ | |
public interface RecipeService { | |
Set<Recipe> getRecipes(); | |
Recipe findById(Long id); | |
RecipeCommand saveRecipeCommand(RecipeCommand command); | |
RecipeCommand findCommandById(Long id); | |
void deleteById(Long id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.converters.RecipeCommandToRecipe; | |
import com.ravi.recipe.converters.RecipeToRecipeCommand; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.stereotype.Service; | |
import org.springframework.transaction.annotation.Transactional; | |
import java.util.HashSet; | |
import java.util.Optional; | |
import java.util.Set; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 3/29/2020 */ | |
@Service | |
@Slf4j | |
public class RecipeServiceImpl implements RecipeService { | |
private final RecipeRepository recipeRepository; | |
private final RecipeToRecipeCommand recipeToRecipeCommand; | |
private final RecipeCommandToRecipe recipeCommandToRecipe; | |
public RecipeServiceImpl(RecipeRepository recipeRepository, RecipeToRecipeCommand recipeToRecipeCommand, RecipeCommandToRecipe recipeCommandToRecipe) { | |
this.recipeRepository = recipeRepository; | |
this.recipeToRecipeCommand = recipeToRecipeCommand; | |
this.recipeCommandToRecipe = recipeCommandToRecipe; | |
} | |
@Override | |
public Set<Recipe> getRecipes() { | |
log.debug("getting the recipes"); | |
Set<Recipe> recipeSet = new HashSet<>(); | |
recipeRepository.findAll().iterator().forEachRemaining(recipeSet::add); | |
return recipeSet; | |
} | |
@Override | |
public Recipe findById(Long id) { | |
Optional<Recipe> recipe = recipeRepository.findById(id); | |
if (!recipe.isPresent()) | |
throw new RuntimeException("Recipe Not Found"); | |
return recipe.get(); | |
} | |
@Override | |
public RecipeCommand saveRecipeCommand(RecipeCommand command) { | |
Recipe detachedRecipe = recipeCommandToRecipe.convert(command); | |
Recipe savedRecipe = recipeRepository.save(detachedRecipe); | |
log.debug("Saved RecipeId: "+savedRecipe.getId()); | |
return recipeToRecipeCommand.convert(savedRecipe); | |
} | |
@Transactional | |
@Override | |
public RecipeCommand findCommandById(Long id) { | |
return recipeToRecipeCommand.convert(findById(id)); | |
} | |
@Override | |
public void deleteById(Long id){ | |
recipeRepository.deleteById(id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring.datasource.url=jdbc:h2:mem:testdb | |
logging.level.com.ravi.recipe=debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO category (description) VALUES ('American'); | |
INSERT INTO category (description) VALUES ('Italian'); | |
INSERT INTO category (description) VALUES ('Mexican'); | |
INSERT INTO category (description) VALUES ('Fast Food'); | |
INSERT INTO unit_of_measure (description) VALUES ('Teaspoon'); | |
INSERT INTO unit_of_measure (description) VALUES ('Tablespoon'); | |
INSERT INTO unit_of_measure (description) VALUES ('Cup'); | |
INSERT INTO unit_of_measure (description) VALUES ('Pinch'); | |
INSERT INTO unit_of_measure (description) VALUES ('Ounce'); | |
INSERT INTO unit_of_measure (description) VALUES ('Dash'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Index Page</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | |
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" | |
th:href="@{/webjars/bootstrap/4.4.1-1/css/bootstrap.min.css}"> | |
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" | |
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | |
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" | |
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous" | |
th:src="@{/webjars/bootstrap/4.4.1/css/bootstrap.min.css}"></script> | |
</head> | |
<body> | |
<!--/*@thymesVar id="recipe" type="com.ravi.recipe"*/--> | |
<!--/*@thymesVar id="recipes" type="java.util.List"*/--> | |
<div class="container-fluid" style="margin-top: 20px"> | |
<div class="row"> | |
<div class="col-md-6 col-md-offset-3"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title">Recipe Page</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="table-responsive" th:if="${not #lists.isEmpty(recipes)}"> | |
<table class="table table-hover "> | |
<thead class="thead-inverse"> | |
<tr> | |
<th>ID</th> | |
<th>Description</th> | |
<th>View</th> | |
<th>Update</th> | |
<th>Delete</th> | |
<!--<th>Prep Time</th> | |
<th>Cook Time</th> | |
<th>Servings</th> | |
<th>Source</th> | |
<th>URL</th> | |
<th>Directions</th> | |
<th>Difficulty</th>--> | |
</tr> | |
</thead> | |
<tr th:remove="all"> | |
<!--/*@thymesVar id="recipe" type="com.ravi.recipe"*/--> | |
<td th:text="${recipe.id}">123</td> | |
<td th:text="${recipe.description}">Tasty Goodnees 1</td> | |
<td><a href="#">View</a></td> | |
</tr> | |
<tr th:remove="all"> | |
<!--/*@thymesVar id="recipe" type="com.ravi.recipe"*/--> | |
<td th:text="${recipe.id}">12333</td> | |
<td th:text="${recipe.description}">Tasty Goodnees 2</td> | |
<td><a href="#">View</a></td> | |
</tr> | |
<!--<tr th:each="recipe : ${recipes}"> | |
<td th:text="${recipe.id}">334</td> | |
<td th:text="${recipe.description}">Tasty Goodnees 3</td> | |
<td th:text="${recipe.prepTime}"></td> | |
<td th:text="${recipe.cookTime}"></td> | |
<td th:text="${recipe.servings}"></td> | |
<td th:text="${recipe.source}"></td> | |
<td th:text="${recipe.url}"></td> | |
<td th:text="${recipe.directions}"></td> | |
<td th:text="${recipe.difficulty}"></td> | |
</tr>--> | |
<tr th:each="recipe : ${recipes}"> | |
<!--/*@thymesVar id="recipe" type="com.ravi.recipe"*/--> | |
<td th:text="${recipe.id}">334</td> | |
<td th:text="${recipe.description}">Tasty Goodnees 3</td> | |
<td><a href="#" th:href="@{'/recipe/'+ ${recipe.id} +'/show/'}">View</a></td> | |
<td><a href="#" th:href="@{'/recipe/' + ${recipe.id} + '/update'}">Update</a></td> | |
<td><a href="#" th:href="@{'/recipe/' + ${recipe.id} + '/delete'}">Delete</a></td> | |
</tr> | |
<!--<tbody> | |
<tr th:each="recipe : ${recipes}"> | |
<td th:text="${recipe.id}"></td> | |
<td th:text="${recipe.description}"></td> | |
<td th:text="${recipe.prepTime}"></td> | |
<td th:text="${recipe.cookTime}"></td> | |
<td th:text="${recipe.servings}"></td> | |
<td th:text="${recipe.source}"></td> | |
<td th:text="${recipe.url}"></td> | |
<td th:text="${recipe.directions}"></td> | |
<td th:text="${recipe.difficulty}"></td> | |
</tr> | |
</tbody>--> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | |
<head> | |
<meta charset="UTF-8"/> | |
<title>List Ingredients</title> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | |
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" | |
th:href="@{/webjars/bootstrap/4.4.1-1/css/bootstrap.min.css}"> | |
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" | |
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | |
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" | |
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous" | |
th:src="@{/webjars/bootstrap/4.4.1/css/bootstrap.min.css}"></script> | |
</head> | |
<body> | |
<!--/*@thymesVar id="recipe" type="com.ravi.recipe"*/--> | |
<!--/*@thymesVar id="ingredients" type="java.util.Set<com.ravi.recipe.commands.IngredientCommand>"*/--> | |
<div class="container-fluid" style="margin-top: 20px"> | |
<div class="row"> | |
<div class="col-md-6 col-md-offset-3"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title">Ingredients</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="table-responsive" th:if="${not #lists.isEmpty(recipe.ingredients)}"> | |
<table class="table table-hover "> | |
<thead class="thead-inverse"> | |
<tr> | |
<th>ID</th> | |
<th>Description</th> | |
<th>View</th> | |
<th>Update</th> | |
<th>Delete</th> | |
</tr> | |
</thead> | |
<tr th:remove="all"> | |
<td>123</td> | |
<td>Tasty Goodnees 1</td> | |
<td><a href="#">View</a></td> | |
<td><a href="#">Update</a></td> | |
<td><a href="#">Delete</a></td> | |
</tr> | |
<tr th:remove="all"> | |
<td>12333</td> | |
<td>Tasty Goodnees 2</td> | |
<td><a href="#">View</a></td> | |
<td><a href="#">Update</a></td> | |
<td><a href="#">Delete</a></td> | |
</tr> | |
<tr th:each="ingredient : ${recipe.ingredients}"> | |
<td th:text="${ingredient.id}">334</td> | |
<td th:text="${ingredient.amount} + ' ' + ${ingredient.uom.getDescription()} + ' ' + ${ingredient.description} + '/show'">Tasty Goodnees 3</td> | |
<td><a href="#" th:href="@{'/recipe/' + ${recipe.id} + '/ingredient/' + ${ingredient.id} + '/show'}">View</a></td> | |
<td><a href="#" th:href="@{'/recipe/' + ${recipe.id} + '/ingredient/' + ${ingredient.id} + '/update'}">Update</a></td> | |
<td><a href="#" th:href="@{'/recipe/' + ${recipe.id} + '/ingredient/' + ${ingredient.id} + '/delete'}">Delete</a></td> | |
</tr> | |
</table> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | |
<head> | |
<meta charset="UTF-8"/> | |
<title>Recipe Form</title> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | |
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" | |
th:href="@{/webjars/bootstrap/4.4.1-1/css/bootstrap.min.css}"> | |
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" | |
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | |
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" | |
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous" | |
th:src="@{/webjars/bootstrap/4.4.1/css/bootstrap.min.css}"></script> | |
</head> | |
<body> | |
<!--/*@thymesVar id="recipe" type="com.ravi.Recipe"*/--> | |
<div class="container-fluid" style="margin-top: 20px"> | |
<div class="row"> | |
<div class="col-md-6 col-md-offset-3"> | |
<form th:object="${recipe}" th:action="@{/recipe/}" method="post"> | |
<input type="hidden" th:field="*{id}"/> | |
<div class="pannel-group"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title">Edit Recipe Information</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-3 form-group"> | |
<label>Recipe Description:</label> | |
<input type="text" class="form-control" th:field="*{description}"/> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-3 form-group"> | |
<label>Categories:</label> | |
</div> | |
<div class="col-md-9 form-group"> | |
<div class="radio"> | |
<label> | |
<input type="checkbox" value=""/> | |
Cat 1 | |
</label> | |
</div> | |
<div class="radio" th:remove="all"> | |
<label> | |
<input type="checkbox" value=""/> | |
Cat 2 | |
</label> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-3 form-group"> | |
<label>Prep Time:</label> | |
<input type="text" class="form-control" th:field="*{prepTime}"/> | |
</div> | |
<div class="col-md-3 form-group"> | |
<label>Cooktime:</label> | |
<input type="text" class="form-control" th:field="*{cookTime}"/> | |
</div> | |
<div class="col-md-3 form-group"> | |
<label>Difficulty:</label> | |
<select class="form-control"> | |
<option>Easy</option> | |
<option>Medium</option> | |
<option>Hard</option> | |
</select> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-3 form-group"> | |
<label>Servings:</label> | |
<input type="text" class="form-control" th:field="*{servings}"/> | |
</div> | |
<div class="col-md-3 form-group"> | |
<label>Source:</label> | |
<input type="text" class="form-control" th:field="*{source}"/> | |
</div> | |
<div class="col-md-3 form-group"> | |
<label>URL:</label> | |
<input type="text" class="form-control" th:field="*{url}"/> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<div class="row"> | |
<div class="col-md-11 "> | |
<h1 class="panel-title">Ingredients</h1> | |
</div> | |
<div class="col-md-1"> | |
<a class="btn btn-default" href="#" role="button">Edit</a> | |
</div> | |
</div> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<ul> | |
<li th:remove="all">1 Cup of milk</li> | |
<li th:remove="all">1 Teaspoon of chocolate</li> | |
<li th:each="ingredient : ${recipe.ingredients}" | |
th:text="${(ingredient.getAmount() + | |
' ' + ingredient.uom.getDescription() + | |
' - ' + ingredient.getDescription())}">1 Teaspoon of Sugar | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title">Directions</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-12 form-group"> | |
<textarea class="form-control" rows="3" th:field="*{directions}"></textarea></div> | |
</div> | |
</div> | |
</div> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title">Notes</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-12 form-group"> | |
<textarea class="form-control" rows="3" th:field="*{notes.recipeNotes}"></textarea> | |
</div> | |
</div> | |
</div> | |
</div> | |
<button type="submit" class="btn btn-primary">Submit</button> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Recipe Page</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | |
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" | |
th:href="@{/webjars/bootstrap/4.4.1-1/css/bootstrap.min.css}"> | |
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" | |
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | |
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" | |
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous" | |
th:src="@{/webjars/bootstrap/4.4.1/css/bootstrap.min.css}"></script> | |
</head> | |
<!--/*@thymesVar id="recipe" type="com.ravi.recipe"*/--> | |
<div class="container-fluid" style="margin-top: 20px"> | |
<div class="row"> | |
<div class="col-md-6 col-md-offset-3"> | |
<div class="pannel-group"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title" th:text="${recipe.description}">Recipe Description Here!</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-3"> | |
<h5>Categories:</h5> | |
</div> | |
<div class="col-md-9"> | |
<ul> | |
<li th:remove="all">cat one</li> | |
<li th:remove="all">cat two</li> | |
<li th:each="category : ${recipe.categories}" th:text="${category.getDescription()}">cat three</li> | |
</ul> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-3"> | |
<h5>Prep Time:</h5> | |
</div> | |
<div class="col-md-3"> | |
<p th:text="${(recipe.prepTime) + ' Min'}">30 min</p> | |
</div> | |
<div class="col-md-3"> | |
<h5>Difficulty:</h5> | |
</div> | |
<div class="col-md-3"> | |
<p th:text="${recipe.difficulty}">Easy</p> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-3"> | |
<h5>Cooktime:</h5> | |
</div> | |
<div class="col-md-3"> | |
<p th:text="${recipe.cookTime + ' Min'}">30 min</p> | |
</div> | |
<div class="col-md-3"> | |
<h5>Servings:</h5> | |
</div> | |
<div class="col-md-3"> | |
<p th:text="${recipe.servings}">4</p> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-3"> | |
<h5>Source:</h5> | |
</div> | |
<div class="col-md-3"> | |
<p th:text="${recipe.source}">30 min</p> | |
</div> | |
<div class="col-md-3"> | |
<h5>URL:</h5> | |
</div> | |
<div class="col-md-3"> | |
<p><a href="#" th:href="${recipe.url}" >View Original</a></p> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title" >Ingredients</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<ul> | |
<li >Salt</li> | |
<li >Pepper</li> | |
<li th:each="ingredient : ${recipe.ingredients}" | |
th:text="${(ingredient.getAmount() + | |
' ' + ingredient.uom.getDescription() + | |
' - ' + ingredient.getDescription())}">1 Teaspoon of Sugar</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title" >Directions</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<p th:text="${recipe.directions}">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum.</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title" >Notes</h1> | |
</div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<p th:text="${recipe.notes.recipeNotes}">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum.</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.controller; | |
import com.ravi.recipe.converters.RecipeCommandToRecipe; | |
import com.ravi.recipe.converters.RecipeToRecipeCommand; | |
import com.ravi.recipe.domain.Category; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import com.ravi.recipe.repositories.CategoryRepository; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import com.ravi.recipe.repositories.UnitOfMeasureRepository; | |
import com.ravi.recipe.service.RecipeServiceImpl; | |
import lombok.extern.slf4j.Slf4j; | |
import org.junit.jupiter.api.BeforeAll; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.ArgumentCaptor; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | |
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | |
import org.springframework.ui.Model; | |
import java.util.HashSet; | |
import java.util.Optional; | |
import java.util.Set; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.mockito.Mockito.*; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; | |
@Slf4j | |
class IndexControllerTest { | |
public static IndexController indexController; | |
public static RecipeServiceImpl recipeService; | |
@Mock | |
static RecipeCommandToRecipe recipeCommandToRecipe; | |
@Mock | |
static RecipeToRecipeCommand recipeToRecipeCommand; | |
@Mock | |
public static CategoryRepository categoryRepository; | |
@Mock | |
public static UnitOfMeasureRepository unitOfMeasureRepository; | |
@Mock | |
public static RecipeRepository recipeRepository; | |
@Mock | |
public static Model model; | |
@BeforeAll | |
public static void setUp(){ | |
MockitoAnnotations.initMocks(new IndexControllerTest()); | |
recipeService = new RecipeServiceImpl(recipeRepository, recipeToRecipeCommand, recipeCommandToRecipe); | |
indexController = new IndexController(categoryRepository, unitOfMeasureRepository, recipeRepository, recipeService); | |
} | |
@Test | |
void testMockMvc() throws Exception { | |
Category category = new Category(); | |
category.setId(Long.valueOf(1)); | |
UnitOfMeasure unitOfMeasure = new UnitOfMeasure(); | |
unitOfMeasure.setId(Long.valueOf(1)); | |
when(categoryRepository.findByDescription("American")).thenReturn(Optional.of(category)); | |
when(unitOfMeasureRepository.findByDescription("Teaspoon")).thenReturn(Optional.of(unitOfMeasure)); | |
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(indexController).build(); | |
mockMvc.perform(MockMvcRequestBuilders.get("/")) | |
.andExpect(status().is2xxSuccessful()) | |
.andExpect(view().name("index")); | |
} | |
@Test | |
void mapIndex() { | |
Set<Recipe> recipes = new HashSet<>(); | |
Recipe recipe = new Recipe(); | |
recipe.setDescription("recipe"); | |
Recipe recipe2 = new Recipe(); | |
recipe2.setDescription("recipe2"); | |
recipes.add(recipe); | |
recipes.add(recipe2); | |
log.debug("recipes size = "+recipes.size()); | |
Category category = new Category(); | |
category.setId(Long.valueOf(1)); | |
UnitOfMeasure unitOfMeasure = new UnitOfMeasure(); | |
unitOfMeasure.setId(Long.valueOf(1)); | |
when(categoryRepository.findByDescription("American")).thenReturn(Optional.of(category)); | |
when(unitOfMeasureRepository.findByDescription("Teaspoon")).thenReturn(Optional.of(unitOfMeasure)); | |
assertEquals(1, categoryRepository.findByDescription("American").get().getId()); | |
verify(categoryRepository, times(1)).findByDescription("American"); | |
when(recipeRepository.findAll()).thenReturn(recipes); | |
assertEquals(2, recipeService.getRecipes().size()); | |
verify(recipeRepository, times(1)).findAll(); | |
ArgumentCaptor<Set<Recipe>> argumentCaptor = ArgumentCaptor.forClass(Set.class); | |
assertEquals("index", indexController.mapIndex(model)); | |
//verify(model, times(1)).addAttribute(eq("recipes"), anySet()); | |
verify(model, times(1)).addAttribute(eq("recipes"), argumentCaptor.capture()); | |
Set<Recipe> capturedRecipes = argumentCaptor.getValue(); | |
assertEquals(2, capturedRecipes.size()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.controller; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.service.IngredientService; | |
import com.ravi.recipe.service.RecipeService; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | |
import static org.mockito.ArgumentMatchers.anyLong; | |
import static org.mockito.Mockito.*; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | |
public class IngredientControllerTest { | |
IngredientController ingredientController; | |
MockMvc mockMvc; | |
@Mock | |
IngredientService ingredientService; | |
@Mock | |
RecipeService recipeService; | |
@BeforeEach | |
public void setUp() throws Exception { | |
MockitoAnnotations.initMocks(this); | |
ingredientController = new IngredientController(recipeService, ingredientService); | |
mockMvc = MockMvcBuilders.standaloneSetup(ingredientController).build(); | |
} | |
@Test | |
public void getIngredients() throws Exception { | |
// given | |
RecipeCommand recipeCommand = new RecipeCommand(); | |
when(recipeService.findCommandById(anyLong())).thenReturn(recipeCommand); | |
// when | |
mockMvc.perform(get("/recipe/1/ingredients")) | |
.andExpect(status().isOk()) | |
.andExpect(view().name("recipe/ingredient/list")) | |
.andExpect(model().attributeExists("recipe")); | |
// then | |
verify(recipeService, times(1)).findCommandById(anyLong()); | |
} | |
@Test | |
public void testShowIngredients() throws Exception { | |
// given | |
IngredientCommand ingredientCommand = new IngredientCommand(); | |
// when | |
when(ingredientService.findByRecipeIdAndIngredientId(anyLong(), anyLong())).thenReturn(ingredientCommand); | |
// then | |
mockMvc.perform(get("/recipe/1/ingredient/2/show")) | |
.andExpect(status().isOk()) | |
.andExpect(view().name("recipe/ingredient/show")) | |
.andExpect(model().attributeExists("ingredient")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.controller; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.service.RecipeService; | |
import org.junit.jupiter.api.BeforeAll; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import org.springframework.http.MediaType; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | |
import static org.mockito.ArgumentMatchers.any; | |
import static org.mockito.ArgumentMatchers.anyLong; | |
import static org.mockito.Mockito.*; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/3/2020 */ | |
public class RecipeControllerTest { | |
static RecipeController recipeController; | |
static MockMvc mockMvc; | |
@Mock | |
static RecipeService recipeService; | |
@BeforeAll | |
public static void setUp(){ | |
MockitoAnnotations.initMocks(new RecipeControllerTest()); | |
recipeController = new RecipeController(recipeService); | |
mockMvc = MockMvcBuilders.standaloneSetup(recipeController).build(); | |
} | |
@Test | |
public void testGetRecipe() throws Exception { | |
Recipe recipe = new Recipe(); | |
recipe.setDescription("Test recipe"); | |
recipe.setId(1L); | |
when(recipeService.findById(anyLong())).thenReturn(recipe); | |
mockMvc.perform(get("/recipe/1/show")) | |
.andExpect(status().isOk()) | |
.andExpect(view().name("recipe/show")) | |
.andExpect(model().attributeExists("recipe")); | |
} | |
@Test | |
public void testGetNewRecipeForm() throws Exception { | |
mockMvc.perform(get("/recipe/new")) | |
.andExpect(status().isOk()) | |
.andExpect(view().name("recipe/recipeform")) | |
.andExpect(model().attributeExists("recipe")); | |
} | |
@Test | |
public void testPostNewRecipeForm() throws Exception { | |
RecipeCommand command = new RecipeCommand(); | |
command.setId(2L); | |
when(recipeService.saveRecipeCommand(any())).thenReturn(command); | |
mockMvc.perform(post("/recipe") | |
.contentType(MediaType.APPLICATION_FORM_URLENCODED) | |
.param("id", "") | |
.param("description", "some string") | |
) | |
.andExpect(status().is3xxRedirection()) | |
.andExpect(view().name("redirect:/recipe/2/show")); | |
} | |
@Test | |
public void testGetUpdateView() throws Exception { | |
RecipeCommand command = new RecipeCommand(); | |
command.setId(2L); | |
when(recipeService.findCommandById(anyLong())).thenReturn(command); | |
mockMvc.perform(get("/recipe/1/update")) | |
.andExpect(status().isOk()) | |
.andExpect(view().name("recipe/recipeform")) | |
.andExpect(model().attributeExists("recipe")); | |
} | |
@Test | |
public void testDelete() throws Exception { | |
mockMvc.perform(get("/recipe/3/delete")) | |
.andExpect(status().is3xxRedirection()) | |
.andExpect(view().name("redirect:/")); | |
verify(recipeService, times(1)).deleteById(anyLong()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.CategoryCommand; | |
import com.ravi.recipe.domain.Category; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class CategoryCommandToCategoryTest { | |
public static final Long ID_VALUE = new Long(1L); | |
public static final String DESCRIPTION = "description"; | |
CategoryCommandToCategory conveter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
conveter = new CategoryCommandToCategory(); | |
} | |
@Test | |
public void testNullObject() throws Exception { | |
assertNull(conveter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(conveter.convert(new CategoryCommand())); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
CategoryCommand categoryCommand = new CategoryCommand(); | |
categoryCommand.setId(ID_VALUE); | |
categoryCommand.setDescription(DESCRIPTION); | |
//when | |
Category category = conveter.convert(categoryCommand); | |
//then | |
assertEquals(ID_VALUE, category.getId()); | |
assertEquals(DESCRIPTION, category.getDescription()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.CategoryCommand; | |
import com.ravi.recipe.domain.Category; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class CategoryToCategoryCommandTest { | |
public static final Long ID_VALUE = new Long(1L); | |
public static final String DESCRIPTION = "descript"; | |
CategoryToCategoryCommand convter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
convter = new CategoryToCategoryCommand(); | |
} | |
@Test | |
public void testNullObject() throws Exception { | |
assertNull(convter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(convter.convert(new Category())); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
Category category = new Category(); | |
category.setId(ID_VALUE); | |
category.setDescription(DESCRIPTION); | |
//when | |
CategoryCommand categoryCommand = convter.convert(category); | |
//then | |
assertEquals(ID_VALUE, categoryCommand.getId()); | |
assertEquals(DESCRIPTION, categoryCommand.getDescription()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.commands.UnitOfMeasureCommand; | |
import com.ravi.recipe.domain.Ingredient; | |
import com.ravi.recipe.domain.Recipe; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import java.math.BigDecimal; | |
import static org.junit.jupiter.api.Assertions.*; | |
class IngredientCommandToIngredientTest { | |
public static final Recipe RECIPE = new Recipe(); | |
public static final BigDecimal AMOUNT = new BigDecimal("1"); | |
public static final String DESCRIPTION = "Cheeseburger"; | |
public static final Long ID_VALUE = 1L; | |
public static final Long UOM_ID = 2L; | |
IngredientCommandToIngredient converter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
converter = new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure()); | |
} | |
@Test | |
public void testNullObject() throws Exception { | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(converter.convert(new IngredientCommand())); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
IngredientCommand command = new IngredientCommand(); | |
command.setId(ID_VALUE); | |
command.setAmount(AMOUNT); | |
command.setDescription(DESCRIPTION); | |
UnitOfMeasureCommand unitOfMeasureCommand = new UnitOfMeasureCommand(); | |
unitOfMeasureCommand.setId(UOM_ID); | |
command.setUnitOfMeasure(unitOfMeasureCommand); | |
//when | |
Ingredient ingredient = converter.convert(command); | |
//then | |
assertNotNull(ingredient); | |
assertNotNull(ingredient.getUom()); | |
assertEquals(ID_VALUE, ingredient.getId()); | |
assertEquals(AMOUNT, ingredient.getAmount()); | |
assertEquals(DESCRIPTION, ingredient.getDescription()); | |
assertEquals(UOM_ID, ingredient.getUom().getId()); | |
} | |
@Test | |
public void convertWithNullUOM() throws Exception { | |
//given | |
IngredientCommand command = new IngredientCommand(); | |
command.setId(ID_VALUE); | |
command.setAmount(AMOUNT); | |
command.setDescription(DESCRIPTION); | |
UnitOfMeasureCommand unitOfMeasureCommand = new UnitOfMeasureCommand(); | |
//when | |
Ingredient ingredient = converter.convert(command); | |
//then | |
assertNotNull(ingredient); | |
assertNull(ingredient.getUom()); | |
assertEquals(ID_VALUE, ingredient.getId()); | |
assertEquals(AMOUNT, ingredient.getAmount()); | |
assertEquals(DESCRIPTION, ingredient.getDescription()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.domain.Ingredient; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import java.math.BigDecimal; | |
import static org.junit.jupiter.api.Assertions.*; | |
class IngredientToIngredientCommandTest { | |
public static final Recipe RECIPE = new Recipe(); | |
public static final BigDecimal AMOUNT = new BigDecimal("1"); | |
public static final String DESCRIPTION = "Cheeseburger"; | |
public static final Long UOM_ID = 2L; | |
public static final Long ID_VALUE = 1L; | |
IngredientToIngredientCommand converter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
converter = new IngredientToIngredientCommand(new UnitOfMeasureToUnitOfMeasureCommand()); | |
} | |
@Test | |
public void testNullConvert() throws Exception { | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(converter.convert(new Ingredient())); | |
} | |
@Test | |
public void testConvertNullUOM() throws Exception { | |
//given | |
Ingredient ingredient = new Ingredient(); | |
ingredient.setId(ID_VALUE); | |
ingredient.setRecipe(RECIPE); | |
ingredient.setAmount(AMOUNT); | |
ingredient.setDescription(DESCRIPTION); | |
ingredient.setUom(null); | |
//when | |
IngredientCommand ingredientCommand = converter.convert(ingredient); | |
//then | |
assertNull(ingredientCommand.getUnitOfMeasure()); | |
assertEquals(ID_VALUE, ingredientCommand.getId()); | |
// assertEquals(RECIPE, ingredientCommand.get); | |
assertEquals(AMOUNT, ingredientCommand.getAmount()); | |
assertEquals(DESCRIPTION, ingredientCommand.getDescription()); | |
} | |
@Test | |
public void testConvertWithUom() throws Exception { | |
//given | |
Ingredient ingredient = new Ingredient(); | |
ingredient.setId(ID_VALUE); | |
ingredient.setRecipe(RECIPE); | |
ingredient.setAmount(AMOUNT); | |
ingredient.setDescription(DESCRIPTION); | |
UnitOfMeasure uom = new UnitOfMeasure(); | |
uom.setId(UOM_ID); | |
ingredient.setUom(uom); | |
//when | |
IngredientCommand ingredientCommand = converter.convert(ingredient); | |
//then | |
assertEquals(ID_VALUE, ingredientCommand.getId()); | |
assertNotNull(ingredientCommand.getUnitOfMeasure()); | |
assertEquals(UOM_ID, ingredientCommand.getUnitOfMeasure().getId()); | |
// assertEquals(RECIPE, ingredientCommand.get); | |
assertEquals(AMOUNT, ingredientCommand.getAmount()); | |
assertEquals(DESCRIPTION, ingredientCommand.getDescription()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.NotesCommand; | |
import com.ravi.recipe.domain.Notes; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class NotesCommandToNotesTest { | |
public static final Long ID_VALUE = new Long(1L); | |
public static final String RECIPE_NOTES = "Notes"; | |
NotesCommandToNotes converter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
converter = new NotesCommandToNotes(); | |
} | |
@Test | |
public void testNullParameter() throws Exception { | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(converter.convert(new NotesCommand())); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
NotesCommand notesCommand = new NotesCommand(); | |
notesCommand.setId(ID_VALUE); | |
notesCommand.setRecipeNotes(RECIPE_NOTES); | |
//when | |
Notes notes = converter.convert(notesCommand); | |
//then | |
assertNotNull(notes); | |
assertEquals(ID_VALUE, notes.getId()); | |
assertEquals(RECIPE_NOTES, notes.getRecipeNotes()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.NotesCommand; | |
import com.ravi.recipe.domain.Notes; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class NotesToNotesCommandTest { | |
public static final Long ID_VALUE = new Long(1L); | |
public static final String RECIPE_NOTES = "Notes"; | |
NotesToNotesCommand converter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
converter = new NotesToNotesCommand(); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
Notes notes = new Notes(); | |
notes.setId(ID_VALUE); | |
notes.setRecipeNotes(RECIPE_NOTES); | |
//when | |
NotesCommand notesCommand = converter.convert(notes); | |
//then | |
assertEquals(ID_VALUE, notesCommand.getId()); | |
assertEquals(RECIPE_NOTES, notesCommand.getRecipeNotes()); | |
} | |
@Test | |
public void testNull() throws Exception { | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(converter.convert(new Notes())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.CategoryCommand; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.commands.NotesCommand; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.domain.Difficulty; | |
import com.ravi.recipe.domain.Recipe; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class RecipeCommandToRecipeTest { | |
public static final Long RECIPE_ID = 1L; | |
public static final Integer COOK_TIME = Integer.valueOf("5"); | |
public static final Integer PREP_TIME = Integer.valueOf("7"); | |
public static final String DESCRIPTION = "My Recipe"; | |
public static final String DIRECTIONS = "Directions"; | |
public static final Difficulty DIFFICULTY = Difficulty.EASY; | |
public static final Integer SERVINGS = Integer.valueOf("3"); | |
public static final String SOURCE = "Source"; | |
public static final String URL = "Some URL"; | |
public static final Long CAT_ID_1 = 1L; | |
public static final Long CAT_ID2 = 2L; | |
public static final Long INGRED_ID_1 = 3L; | |
public static final Long INGRED_ID_2 = 4L; | |
public static final Long NOTES_ID = 9L; | |
RecipeCommandToRecipe converter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
converter = new RecipeCommandToRecipe(new CategoryCommandToCategory(), | |
new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure()), | |
new NotesCommandToNotes()); | |
} | |
@Test | |
public void testNullObject() throws Exception { | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(converter.convert(new RecipeCommand())); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
RecipeCommand recipeCommand = new RecipeCommand(); | |
recipeCommand.setId(RECIPE_ID); | |
recipeCommand.setCookTime(COOK_TIME); | |
recipeCommand.setPrepTime(PREP_TIME); | |
recipeCommand.setDescription(DESCRIPTION); | |
recipeCommand.setDifficulty(DIFFICULTY); | |
recipeCommand.setDirections(DIRECTIONS); | |
recipeCommand.setServings(SERVINGS); | |
recipeCommand.setSource(SOURCE); | |
recipeCommand.setUrl(URL); | |
NotesCommand notes = new NotesCommand(); | |
notes.setId(NOTES_ID); | |
recipeCommand.setNotes(notes); | |
CategoryCommand category = new CategoryCommand(); | |
category.setId(CAT_ID_1); | |
CategoryCommand category2 = new CategoryCommand(); | |
category2.setId(CAT_ID2); | |
recipeCommand.getCategories().add(category); | |
recipeCommand.getCategories().add(category2); | |
IngredientCommand ingredient = new IngredientCommand(); | |
ingredient.setId(INGRED_ID_1); | |
IngredientCommand ingredient2 = new IngredientCommand(); | |
ingredient2.setId(INGRED_ID_2); | |
recipeCommand.getIngredients().add(ingredient); | |
recipeCommand.getIngredients().add(ingredient2); | |
//when | |
Recipe recipe = converter.convert(recipeCommand); | |
assertNotNull(recipe); | |
assertEquals(RECIPE_ID, recipe.getId()); | |
assertEquals(COOK_TIME, recipe.getCookTime()); | |
assertEquals(PREP_TIME, recipe.getPrepTime()); | |
assertEquals(DESCRIPTION, recipe.getDescription()); | |
assertEquals(DIFFICULTY, recipe.getDifficulty()); | |
assertEquals(DIRECTIONS, recipe.getDirections()); | |
assertEquals(SERVINGS, recipe.getServings()); | |
assertEquals(SOURCE, recipe.getSource()); | |
assertEquals(URL, recipe.getUrl()); | |
assertEquals(NOTES_ID, recipe.getNotes().getId()); | |
assertEquals(2, recipe.getCategories().size()); | |
assertEquals(2, recipe.getIngredients().size()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.domain.*; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class RecipeToRecipeCommandTest { | |
public static final Long RECIPE_ID = 1L; | |
public static final Integer COOK_TIME = Integer.valueOf("5"); | |
public static final Integer PREP_TIME = Integer.valueOf("7"); | |
public static final String DESCRIPTION = "My Recipe"; | |
public static final String DIRECTIONS = "Directions"; | |
public static final Difficulty DIFFICULTY = Difficulty.EASY; | |
public static final Integer SERVINGS = Integer.valueOf("3"); | |
public static final String SOURCE = "Source"; | |
public static final String URL = "Some URL"; | |
public static final Long CAT_ID_1 = 1L; | |
public static final Long CAT_ID2 = 2L; | |
public static final Long INGRED_ID_1 = 3L; | |
public static final Long INGRED_ID_2 = 4L; | |
public static final Long NOTES_ID = 9L; | |
RecipeToRecipeCommand converter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
converter = new RecipeToRecipeCommand( | |
new CategoryToCategoryCommand(), | |
new IngredientToIngredientCommand(new UnitOfMeasureToUnitOfMeasureCommand()), | |
new NotesToNotesCommand()); | |
} | |
@Test | |
public void testNullObject() throws Exception { | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
public void testEmptyObject() throws Exception { | |
assertNotNull(converter.convert(new Recipe())); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
Recipe recipe = new Recipe(); | |
recipe.setId(RECIPE_ID); | |
recipe.setCookTime(COOK_TIME); | |
recipe.setPrepTime(PREP_TIME); | |
recipe.setDescription(DESCRIPTION); | |
recipe.setDifficulty(DIFFICULTY); | |
recipe.setDirections(DIRECTIONS); | |
recipe.setServings(SERVINGS); | |
recipe.setSource(SOURCE); | |
recipe.setUrl(URL); | |
Notes notes = new Notes(); | |
notes.setId(NOTES_ID); | |
recipe.setNotes(notes); | |
Category category = new Category(); | |
category.setId(CAT_ID_1); | |
Category category2 = new Category(); | |
category2.setId(CAT_ID2); | |
recipe.getCategories().add(category); | |
recipe.getCategories().add(category2); | |
Ingredient ingredient = new Ingredient(); | |
ingredient.setId(INGRED_ID_1); | |
Ingredient ingredient2 = new Ingredient(); | |
ingredient2.setId(INGRED_ID_2); | |
recipe.getIngredients().add(ingredient); | |
recipe.getIngredients().add(ingredient2); | |
//when | |
RecipeCommand command = converter.convert(recipe); | |
//then | |
assertNotNull(command); | |
assertEquals(RECIPE_ID, command.getId()); | |
assertEquals(COOK_TIME, command.getCookTime()); | |
assertEquals(PREP_TIME, command.getPrepTime()); | |
assertEquals(DESCRIPTION, command.getDescription()); | |
assertEquals(DIFFICULTY, command.getDifficulty()); | |
assertEquals(DIRECTIONS, command.getDirections()); | |
assertEquals(SERVINGS, command.getServings()); | |
assertEquals(SOURCE, command.getSource()); | |
assertEquals(URL, command.getUrl()); | |
assertEquals(NOTES_ID, command.getNotes().getId()); | |
assertEquals(2, command.getCategories().size()); | |
assertEquals(2, command.getIngredients().size()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.UnitOfMeasureCommand; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class UnitOfMeasureCommandToUnitOfMeasureTest { | |
public UnitOfMeasureCommandToUnitOfMeasure converter; | |
public static final Long ID = 1L; | |
public static final String DESCRIPTION = "UOMCommand Description"; | |
@BeforeEach | |
void setUp() throws Exception{ | |
converter = new UnitOfMeasureCommandToUnitOfMeasure(); | |
} | |
@Test | |
void testNullParameter() throws Exception{ | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
void testEmptyObject() throws Exception{ | |
assertNotNull(converter.convert(new UnitOfMeasureCommand())); | |
} | |
@Test | |
void convert() throws Exception{ | |
// given | |
UnitOfMeasureCommand unitOfMeasureCommand = new UnitOfMeasureCommand(); | |
unitOfMeasureCommand.setId(ID); | |
unitOfMeasureCommand.setDescription(DESCRIPTION); | |
// when | |
UnitOfMeasure unitOfMeasure = converter.convert(unitOfMeasureCommand); | |
// then | |
assertNotNull(unitOfMeasure); | |
assertEquals(unitOfMeasure.getDescription(), DESCRIPTION); | |
assertEquals(unitOfMeasure.getId(), ID); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.converters; | |
import com.ravi.recipe.commands.UnitOfMeasureCommand; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class UnitOfMeasureToUnitOfMeasureCommandTest { | |
public static final String DESCRIPTION = "description"; | |
public static final Long LONG_VALUE = new Long(1L); | |
UnitOfMeasureToUnitOfMeasureCommand converter; | |
@BeforeEach | |
public void setUp() throws Exception { | |
converter = new UnitOfMeasureToUnitOfMeasureCommand(); | |
} | |
@Test | |
public void testNullObjectConvert() throws Exception { | |
assertNull(converter.convert(null)); | |
} | |
@Test | |
public void testEmptyObj() throws Exception { | |
assertNotNull(converter.convert(new UnitOfMeasure())); | |
} | |
@Test | |
public void convert() throws Exception { | |
//given | |
UnitOfMeasure uom = new UnitOfMeasure(); | |
uom.setId(LONG_VALUE); | |
uom.setDescription(DESCRIPTION); | |
//when | |
UnitOfMeasureCommand uomc = converter.convert(uom); | |
//then | |
assertEquals(LONG_VALUE, uomc.getId()); | |
assertEquals(DESCRIPTION, uomc.getDescription()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.domain; | |
import org.junit.jupiter.api.BeforeAll; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
class CategoryTest { | |
static Category category; | |
@BeforeAll | |
public static void setUp(){ | |
category = new Category(); | |
} | |
@Test | |
void getId() { | |
Long newId = 4L; | |
category.setId(newId); | |
assertEquals(newId, category.getId()); | |
} | |
@Test | |
void getDescription() { | |
} | |
@Test | |
void getRecipes() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe; | |
import org.junit.jupiter.api.Test; | |
import org.springframework.boot.test.context.SpringBootTest; | |
@SpringBootTest | |
class RecipeApplicationTests { | |
@Test | |
void contextLoads() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.repositories; | |
import com.ravi.recipe.domain.UnitOfMeasure; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | |
import java.util.Optional; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
@DataJpaTest | |
class UnitOfMeasureRepositoryTest { | |
@Autowired | |
UnitOfMeasureRepository unitOfMeasureRepository; | |
@BeforeEach | |
void setUp() { | |
} | |
@Test | |
//@DirtiesContext | |
void findByDescription() { | |
Optional<UnitOfMeasure> optionalUnitOfMeasure = unitOfMeasureRepository.findByDescription("Teaspoon"); | |
assertEquals(1, optionalUnitOfMeasure.get().getId()); | |
assertEquals("Teaspoon", optionalUnitOfMeasure.get().getDescription()); | |
} | |
@Test | |
void findById(){ | |
Optional<UnitOfMeasure> optionalUnitOfMeasure = unitOfMeasureRepository.findByDescription("Tablespoon"); | |
assertEquals(2, optionalUnitOfMeasure.get().getId()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import com.ravi.recipe.commands.IngredientCommand; | |
import com.ravi.recipe.converters.IngredientToIngredientCommand; | |
import com.ravi.recipe.domain.Ingredient; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import java.util.HashSet; | |
import java.util.Optional; | |
import java.util.Set; | |
import static org.junit.jupiter.api.Assertions.*; | |
import static org.mockito.ArgumentMatchers.anyLong; | |
import static org.mockito.Mockito.*; | |
class IngredientServiceImplTest { | |
@Mock | |
RecipeRepository recipeRepository; | |
@Mock | |
IngredientToIngredientCommand ingredientToIngredientCommand; | |
IngredientServiceImpl ingredientServiceImpl; | |
@BeforeEach | |
void setUp() { | |
MockitoAnnotations.initMocks(this); | |
ingredientServiceImpl = new IngredientServiceImpl(ingredientToIngredientCommand, recipeRepository); | |
} | |
@Test | |
void findByRecipeIdAndIngredientIdTrueCase() throws Exception { | |
// given | |
Recipe recipe = new Recipe(); | |
recipe.setId(1L); | |
Ingredient ingredient1 = new Ingredient(); | |
ingredient1.setId(1L); | |
Ingredient ingredient2 = new Ingredient(); | |
ingredient2.setId(2L); | |
Ingredient ingredient3 = new Ingredient(); | |
ingredient3.setId(3L); | |
Set<Ingredient> ingredientSet = new HashSet<>(); | |
ingredientSet.add(ingredient1); | |
ingredientSet.add(ingredient2); | |
ingredientSet.add(ingredient3); | |
recipe.addIngredient(ingredient1); | |
recipe.addIngredient(ingredient2); | |
recipe.addIngredient(ingredient3); | |
recipe.setIngredients(ingredientSet); | |
// when | |
when(recipeRepository.findById(anyLong())).thenReturn(Optional.of(recipe)); | |
// then | |
IngredientCommand ingredientCommand = ingredientServiceImpl.findByRecipeIdAndIngredientId(1L, 1L); | |
assertEquals(ingredientCommand.getId(), 3L); | |
assertEquals(ingredientCommand.getRecipeId(), 2L); | |
verify(recipeRepository, times(1)).findById(anyLong()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import com.ravi.recipe.converters.RecipeCommandToRecipe; | |
import com.ravi.recipe.converters.RecipeToRecipeCommand; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import org.junit.jupiter.api.BeforeAll; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import java.util.HashSet; | |
import java.util.Optional; | |
import java.util.Set; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
import static org.mockito.Mockito.*; | |
class RecipeServiceImplTest { | |
static RecipeServiceImpl recipeService; | |
@Mock | |
static RecipeToRecipeCommand recipeToRecipeCommand; | |
@Mock | |
static RecipeCommandToRecipe recipeCommandToRecipe; | |
@Mock | |
static RecipeRepository recipeRepository; | |
@BeforeAll | |
public static void setUp() throws Exception{ | |
MockitoAnnotations.initMocks(new RecipeServiceImplTest()); | |
recipeService = new RecipeServiceImpl(recipeRepository, recipeToRecipeCommand, recipeCommandToRecipe); | |
} | |
@Test | |
public void getRecipes() throws Exception{ | |
Recipe recipe = new Recipe(); | |
Set<Recipe> recipeSet = new HashSet<>(); | |
recipeSet.add(recipe); | |
when(recipeRepository.findAll()).thenReturn(recipeSet); | |
assertEquals(1, | |
recipeService.getRecipes().size()); | |
verify(recipeRepository, times(1)).findAll(); | |
} | |
@Test | |
public void getRecipesByIdTest() { | |
Recipe recipe = new Recipe(); | |
recipe.setId(1L); | |
recipe.setDescription("New Recipe"); | |
when(recipeRepository.findById(anyLong())).thenReturn(Optional.of(recipe)); | |
assertNotNull(recipeService.findById(1L), "Null Recipe returned"); | |
assertEquals(recipe.getDescription(), recipeService.findById(1L).getDescription()); | |
verify(recipeRepository, times(2)).findById(anyLong()); | |
verify(recipeRepository, never()).findAll(); | |
} | |
@Test | |
public void deleteRecipeById(){ | |
// given | |
Long id = 4L; | |
// when | |
recipeService.deleteById(id); | |
// then | |
verify(recipeRepository, times(1)).deleteById(anyLong()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ravi.recipe.service; | |
import com.ravi.recipe.commands.RecipeCommand; | |
import com.ravi.recipe.converters.RecipeCommandToRecipe; | |
import com.ravi.recipe.converters.RecipeToRecipeCommand; | |
import com.ravi.recipe.domain.Recipe; | |
import com.ravi.recipe.repositories.RecipeRepository; | |
import lombok.extern.slf4j.Slf4j; | |
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.extension.ExtendWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.test.context.junit.jupiter.SpringExtension; | |
import org.springframework.transaction.annotation.Transactional; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
/* Created by: Venkata Ravichandra Cherukuri | |
Created on: 4/4/2020 */ | |
@ExtendWith(SpringExtension.class) | |
@SpringBootTest | |
@Slf4j | |
public class RecipeServiceIT { | |
public static final String NEW_DESC = "New Desc"; | |
@Autowired | |
RecipeService recipeService; | |
@Autowired | |
RecipeRepository recipeRepository; | |
@Autowired | |
RecipeCommandToRecipe recipeCommandToRecipe; | |
@Autowired | |
RecipeToRecipeCommand recipeToRecipeCommand; | |
@Transactional | |
@Test | |
public void testSaveOfDescription() throws Exception { | |
//given | |
Iterable<Recipe> recipes = recipeRepository.findAll(); | |
if (recipes.iterator().hasNext()) | |
log.debug("There are recipes"); | |
else | |
log.debug("There are no recipes"); | |
Recipe testRecipe = recipes.iterator().next(); | |
RecipeCommand testRecipeCommand = recipeToRecipeCommand.convert(testRecipe); | |
//when | |
testRecipeCommand.setDescription(NEW_DESC); | |
RecipeCommand savedRecipeCommand = recipeService.saveRecipeCommand(testRecipeCommand); | |
//then | |
assertEquals(NEW_DESC, savedRecipeCommand.getDescription()); | |
assertEquals(testRecipe.getId(), savedRecipeCommand.getId()); | |
assertEquals(testRecipe.getCategories().size(), savedRecipeCommand.getCategories().size()); | |
assertEquals(testRecipe.getIngredients().size(), savedRecipeCommand.getIngredients().size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment