diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..80a6f4f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,36 @@ +version: 2 +jobs: + build: + + working_directory: ~/repo + + docker: + - image: circleci/openjdk:8-jdk + + steps: + + - checkout + + - run: + name: Clean & install + command: ./gradlew clean build -x test --no-daemon -s + + - run: + name: Tests + command: ./gradlew test -s + + - store_test_results: + path: build/test-results + + - run: + name: Collect artifacts + command: | + mkdir -p artifacts/libs + mkdir -p artifacts/schema + cp -pR build/libs/* artifacts/libs || true + cp -pR build/resources/main/scenarioo-schemas/*.xsd artifacts/schema || true + cp -pR LICENSE.txt artifacts/ + + - store_artifacts: + path: artifacts + destination: / diff --git a/README.md b/README.md index 2a33883..a0b9e2d 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,13 @@ Scenarioo Writer API for Java to generate Scenarioo Documentations - http://www. ## Usage Scenarioo-Java is available on maven central: Include the latest version as a dependency in your favorite dependency management system: -`compile 'org.scenarioo:scenarioo-java:2.1.1'` +`implementation 'org.scenarioo:scenarioo-java:3.0.0'` + +Notice that at least Java 8 is required for version 3.0.0 of the writer library You will find more information in our [usage guide](docs/usage.md). ## Development Refer to our -[Release new API](docs/release-new-api.md) documentation for more information how to build and release scenarioo-java. \ No newline at end of file +[Release new API](docs/release-new-api.md) documentation for more information how to build and release scenarioo-java. diff --git a/build.gradle b/build.gradle index 590537a..7ad652f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,57 +1,70 @@ /* scenarioo-api * Copyright (C) 2014, scenarioo.org Development Team - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * As a special exception, the copyright holders of this library give you - * permission to link this library with independent modules, according + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules, according * to the GNU General Public License with "Classpath" exception as provided * in the LICENSE file that accompanied this code. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ group = 'org.scenarioo' -version = '2.1.2-SNAPSHOT' +version = '3.0.0-RC1' apply plugin: 'eclipse' apply plugin: 'java' -apply plugin: 'maven' +apply plugin: 'maven-publish' apply plugin: 'signing' -sourceCompatibility=1.6 -targetCompatibility=1.6 +sourceCompatibility = 1.8 +targetCompatibility = 1.8 repositories { - mavenCentral() + mavenCentral() } dependencies { - compile 'org.apache.commons:commons-lang3:3.0.1' - compile 'commons-io:commons-io:1.3.2' - compile 'commons-codec:commons-codec:1.2' - compile 'log4j:log4j:1.2.17' - testCompile 'junit:junit:4.11' + implementation 'org.apache.commons:commons-lang3:3.0.1' + implementation 'commons-io:commons-io:1.3.2' + implementation 'commons-codec:commons-codec:1.2' + implementation 'org.slf4j:slf4j-api:1.7.31' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2' + + //These libraries are no longer provided in Java 9+, thus we need to add them manually + implementation 'javax.xml.bind:jaxb-api:2.3.1' + implementation 'com.sun.xml.bind:jaxb-core:2.3.0.1' + implementation 'com.sun.xml.bind:jaxb-impl:2.3.2' } +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + } +} task javadocJar(type: Jar) { - classifier = 'javadoc' + archiveClassifier.set('javadoc') from javadoc } task sourcesJar(type: Jar) { - classifier = 'sources' + archiveClassifier.set('sources') from sourceSets.main.allSource } @@ -59,56 +72,66 @@ artifacts { archives javadocJar, sourcesJar } -signing { - sign configurations.archives -} - tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') } -uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar - pom.project { - name 'Scenarioo java' - packaging 'jar' - description 'Scenarioo Writer library for Java to generate Scenarioo Documentation http://www.scenarioo.org' - url 'http://www.scenarioo.org' + pom { + name = 'Scenarioo Java' + packaging = 'jar' + description = 'Scenarioo Writer library for Java to generate Scenarioo Documentation http://www.scenarioo.org' + url = 'http://www.scenarioo.org' scm { - connection 'https://github.com/scenarioo/scenarioo-java.git' - developerConnection 'https://github.com/scenarioo/scenarioo-java.git' - url 'https://github.com/scenarioo/scenarioo-java.git' + connection = 'https://github.com/scenarioo/scenarioo-java.git' + developerConnection = 'https://github.com/scenarioo/scenarioo-java.git' + url = 'https://github.com/scenarioo/scenarioo-java.git' } licenses { license { - name 'GNU GENERAL PUBLIC LICENCE with linking exception' - url 'https://github.com/scenarioo/scenarioo-java/blob/develop/LICENSE.txt' + name = 'GNU GENERAL PUBLIC LICENCE with linking exception' + url = 'https://github.com/scenarioo/scenarioo-java/blob/develop/LICENSE.txt' } } developers { developer { - id 'scenarioo' - name 'Scenarioo' - email 'contact@scenarioo.org' + id = 'scenarioo' + name = 'Scenarioo' + email = 'contact@scenarioo.org' } } } } } + + repositories { + maven { + if (version.contains("SNAPSHOT")) { + url "https://oss.sonatype.org/content/repositories/snapshots/" + } else { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } + credentials { + username ossrhUsername + password ossrhPassword + } + } + } +} + +if (ossrhPassword) { + signing { + sign publishing.publications.mavenJava + } } task generateSchema(type: JavaExec) { @@ -118,10 +141,9 @@ task generateSchema(type: JavaExec) { jar.dependsOn generateSchema -// Prevent Eclipse "Gradle -> Refresh All" to execute cleanEclipseJdt, -// because it would delete our version of the org.eclipse.jdt.ui.prefs file. -cleanEclipse.dependsOn = cleanEclipse.taskDependencies.values - cleanEclipseJdt +wrapper { + distributionType = Wrapper.DistributionType.ALL + gradleVersion = "6.7.1" +} + -task wrapper(type: Wrapper) { - gradleVersion = '3.3' -} \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md new file mode 100644 index 0000000..37d538c --- /dev/null +++ b/docs/CHANGELOG.md @@ -0,0 +1,24 @@ +# Scenarioo Writer Library for Java Release Notes + +## Version 3.0.0 + +### Upgrade to Java 8 + +* [#725 - Migrate to JUnit 5](https://github.com/scenarioo/scenarioo-java/issues/20) + +With version 3, the Java Writer Library needs at least Java 8 to run. + +### Readiness for Java 11 + +* [#22 - Runtime errors when using the writer with Java 11](https://github.com/scenarioo/scenarioo-java/issues/22) + +Java 11 does not include Java EE libraries anymore. Since scenarioo-java relies on JAXB for writing the XML files, +we need to provide the dependencies out of the box. Users of Java 11+ should switch to this version, if they don't want +to supply the missing dependencies themselves. + + +### Improvements to the details interface + +* [#1 - Improve details interface & API documentation](https://github.com/scenarioo/scenarioo-java/issues/1) + +The possibility to add details via the API has been improved by a few more method overloads. For more details see the [Details class](https://github.com/scenarioo/scenarioo-java/blob/develop/src/main/java/org/scenarioo/model/docu/entities/generic/Details.java) diff --git a/docs/release-new-api.md b/docs/release-new-api.md index 3a94647..36d8e4c 100644 --- a/docs/release-new-api.md +++ b/docs/release-new-api.md @@ -8,20 +8,18 @@ The `scenarioo-java` repository has two branches: `develop` for developing the n Precondition: Before considering a release, make sure that the new version is well tested. If you are not 100% sure about the quality of the code, make a release candidate first and test it well in a realistic environment. -## Release to master branch - -1. Finalize the code in the `develop` branch of `scenarioo-java` by setting the correct version number in the `build.gradle` file. This version number must not exist yet in mavem central. Remove `SNAPSHOT` from the version number and add `-RCx` for release candidates where `x` is the RC number. -2. Make sure the build runs on the `develop` branch by running `./gradlew clean build`. Then commit to `develop`. -3. Now checkout the `master` branch and merge `develop` into it, commit. -4. Still on the `master` branch, add a tag with the release version number and push the tag. -5. Checkout `develop` again, change the version in `build.gradle` to the next `x.y.z-SNAPSHOT` version and commit. `x.y` corresponds to the last release version and `z` is incremented by one compared to the last release. - -## Release to maven repository - -1. Checkout the `master` branch tag that contains the release you just made. -2. Follow the steps [Publish release to maven central](upload-to-maven-central.md). -3. Change the version used in the webapplication (repository 'scenarioo' on appropriate branch) to use the newer version and commit. - -## Write release notes - -Write release notes for the new release on GitHub ([here](https://github.com/scenarioo/scenarioo-java/releases)) +1. Finalize the code in the `develop` branch of `scenarioo-java` by setting the correct version number in the `build.gradle` file. This version number must not exist yet in mavem central. Remove `SNAPSHOT` from the version number and add `-RCx` for release candidates where `x` is the RC number for further release candidate testing. +2. You have to manually [Publish the signed snapshot to maven central](upload-to-maven-central.md)) this is currently not automated. +3. Make sure the changelog.md is updated for the new version + +## Final Release to master branch + +1. Precondition: see Prepare Release above. +2. Set the final version number in develop or release branch (without `-SNAPSHOT` or `-RC`) in `build.gradle` and merge it to the develop branch (or the release branch). +3. You have to manually [Publish the signed release to maven central](upload-to-maven-central.md)) this is currently not automated. +4. Promote the final release to maven central: http://central.sonatype.org/pages/releasing-the-deployment.html +5. Add a tag with the release version number to the commit where you set that version number and push the tag. +6. **Write Release Notes** for the new release on GitHub ([here](https://github.com/scenarioo/scenarioo-java/releases)) +7. Merge the release branch to master. +8. **IMPORTANT - Increase Version to next snapshot version on Develop Branch:** Checkout `develop` again, change the version in `build.gradle` to the next `x.y.z-SNAPSHOT` version and commit. `x.y` corresponds to the last release version and `z` is incremented by one compared to the last release. +9. **Switch Scenarioo Viewer Webapp to newest version:** Go to repo `scenarioo` and change the version of the writer library used to the newest version and commit and push (--> PR to next release branch or to develop). diff --git a/docs/upload-to-maven-central.md b/docs/upload-to-maven-central.md index 2b3ea55..333efcb 100644 --- a/docs/upload-to-maven-central.md +++ b/docs/upload-to-maven-central.md @@ -1,19 +1,25 @@ # Upload to maven central + ## Snapshot -1. You will need to specify the following properties in your gradle.properties located in your gradle home directory: -``` -signing.keyId=BDCAAE60 -signing.password=#private key goes here# -signing.secretKeyRingFile=#secret key file goes here# -ossrhUsername=scenarioo -ossrhPassword=#sonatype password goes here# -``` +1. You will need to specify the following properties in your `gradle.properties` located in your gradle home directory: + + ``` + signing.keyId=BDCAAE60 + signing.password=#private key goes here# + signing.secretKeyRingFile=#secret key file goes here# + ossrhUsername=scenarioo + ossrhPassword=#sonatype password goes here# + ``` +The credentials can be found in the internal MS Teams Channel. -2. Change the version appropriately in the build.gradle -3. `gradlew clean uploadArchives` + +2. Change the version appropriately in the `build.gradle` +3. `gradlew clean publish` +4. Promote build to maven central: http://central.sonatype.org/pages/releasing-the-deployment.html + Please note, we're using the old server https://oss.sonatype.org. ## Releases -Same steps as for snapshot releases and -4. Promote build to maven central: -http://central.sonatype.org/pages/releasing-the-deployment.html \ No newline at end of file + +Same steps as for snapshot releases and then promote build to maven central: +http://central.sonatype.org/pages/releasing-the-deployment.html diff --git a/docs/usage.md b/docs/usage.md index 02bee37..8409971 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -66,4 +66,4 @@ Capture step data from UI tests using one of three strategies ## More ... -* Just study the [Examples](http://scenarioo.org/docs/examples.html), there are a lot of comments in the code, that should help you a lot! +* Just study the [Examples in the Docu](http://scenarioo.org/docs/master/examples.html), there are a lot of comments in the code, that should help you a lot! diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e8c6bf7..5c2d1cf 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d70463..1f3fdbc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Feb 11 10:28:39 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/gradlew b/gradlew index 97fac78..83f2acf 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 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. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +75,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +105,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -105,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -150,11 +170,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 8a0b282..9618d8d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem 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, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,14 +24,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +62,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +75,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/src/main/java/org/scenarioo/api/ScenarioDocuReader.java b/src/main/java/org/scenarioo/api/ScenarioDocuReader.java index 96a37ce..41620aa 100644 --- a/src/main/java/org/scenarioo/api/ScenarioDocuReader.java +++ b/src/main/java/org/scenarioo/api/ScenarioDocuReader.java @@ -1,21 +1,21 @@ /* scenarioo-api * Copyright (C) 2014, scenarioo.org Development Team - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * As a special exception, the copyright holders of this library give you - * permission to link this library with independent modules, according + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules, according * to the GNU General Public License with "Classpath" exception as provided * in the LICENSE file that accompanied this code. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -40,28 +40,28 @@ * Gives access to the geenrated scenario docu files in the filesystem. */ public class ScenarioDocuReader { - + private final ScenarioDocuFiles docuFiles; - + public ScenarioDocuReader(final File rootDirectory) { this.docuFiles = new ScenarioDocuFiles(rootDirectory); } - + public Branch loadBranch(final String branchName) { File file = docuFiles.getBranchFile(checkIdentifier(branchName)); return ScenarioDocuXMLFileUtil.unmarshal(Branch.class, file); } - + public List loadBranches() { List branchFiles = docuFiles.getBranchFiles(); - return ScenarioDocuXMLFileUtil.unmarshalListOfFiles(Branch.class, branchFiles); + return ScenarioDocuXMLFileUtil.unmarshalListOfFilesIgnoreInvalid(Branch.class, branchFiles); } - + public Build loadBuild(final String branchName, final String buildName) { File file = docuFiles.getBuildFile(checkIdentifier(branchName), checkIdentifier(buildName)); return ScenarioDocuXMLFileUtil.unmarshal(Build.class, file); } - + /** * This method was changed in in Version 2.0 of the API to return a list of ObjectFromDirectory<Build> instead * of a list of BuildLinks. This was done because BuildLinks belongs to the Server now and is not part of the API @@ -69,47 +69,47 @@ public Build loadBuild(final String branchName, final String buildName) { */ public List> loadBuilds(final String branchName) { List buildFiles = docuFiles.getBuildFiles(checkIdentifier(branchName)); - return ScenarioDocuXMLFileUtil.unmarshalListOfFilesWithDirNames(buildFiles, Build.class); + return ScenarioDocuXMLFileUtil.unmarshalListOfFilesWithDirNamesIgnoreInvalid(buildFiles, Build.class); } - + public List loadUsecases(final String branchName, final String buildName) { List files = docuFiles.getUseCaseFiles(checkIdentifier(branchName), checkIdentifier(buildName)); return ScenarioDocuXMLFileUtil.unmarshalListOfFiles(UseCase.class, files); } - + public UseCase loadUsecase(final String branchName, final String buildName, final String useCaseName) { File file = docuFiles.getUseCaseFile(checkIdentifier(branchName), checkIdentifier(buildName), checkIdentifier(useCaseName)); return ScenarioDocuXMLFileUtil.unmarshal(UseCase.class, file); } - + public List loadScenarios(final String branchName, final String buildName, final String useCaseName) { List files = docuFiles.getScenarioFiles(checkIdentifier(branchName), checkIdentifier(buildName), checkIdentifier(useCaseName)); return ScenarioDocuXMLFileUtil.unmarshalListOfFiles(Scenario.class, files); } - + public Scenario loadScenario(final String branchName, final String buildName, final String useCaseName, final String scenarioName) { File file = docuFiles.getScenarioFile(checkIdentifier(branchName), checkIdentifier(buildName), checkIdentifier(useCaseName), checkIdentifier(scenarioName)); return ScenarioDocuXMLFileUtil.unmarshal(Scenario.class, file); } - + public List loadSteps(final String branchName, final String buildName, final String useCaseName, final String scenarioName) { List files = docuFiles.getStepFiles(checkIdentifier(branchName), checkIdentifier(buildName), checkIdentifier(useCaseName), checkIdentifier(scenarioName)); return ScenarioDocuXMLFileUtil.unmarshalListOfFiles(Step.class, files); } - + public Step loadStep(final String branchName, final String buildName, final String useCaseName, final String scenarioName, final int stepIndex) { File file = docuFiles.getStepFile(checkIdentifier(branchName), checkIdentifier(buildName), checkIdentifier(useCaseName), checkIdentifier(scenarioName), stepIndex); return ScenarioDocuXMLFileUtil.unmarshal(Step.class, file); } - + /** * Screenshot files are simply provided by path, the REST service will take care of streaming it. */ @@ -118,5 +118,5 @@ public File getScreenshotFile(final String branchName, final String buildName, f return new File(docuFiles.getScreenshotsDirectory(checkIdentifier(branchName), checkIdentifier(buildName), checkIdentifier(useCaseName), checkIdentifier(scenarioName)), imageName); } - + } diff --git a/src/main/java/org/scenarioo/api/util/IdentifierSanitizer.java b/src/main/java/org/scenarioo/api/util/IdentifierSanitizer.java index 76d7365..c28e387 100644 --- a/src/main/java/org/scenarioo/api/util/IdentifierSanitizer.java +++ b/src/main/java/org/scenarioo/api/util/IdentifierSanitizer.java @@ -3,7 +3,7 @@ import org.scenarioo.api.rules.CharacterChecker; /** - * Use this to make sure your identifiers are compilant with the Scenarioo APIs restrictions that are enforced in the + * Use this to make sure your identifiers are compliant with the Scenarioo APIs restrictions that are enforced in the * {@link CharacterChecker}. */ public class IdentifierSanitizer { diff --git a/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLFileUtil.java b/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLFileUtil.java index 1d5a2d5..ecbf1ce 100644 --- a/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLFileUtil.java +++ b/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLFileUtil.java @@ -1,21 +1,21 @@ /* scenarioo-api * Copyright (C) 2014, scenarioo.org Development Team - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * As a special exception, the copyright holders of this library give you - * permission to link this library with independent modules, according + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules, according * to the GNU General Public License with "Classpath" exception as provided * in the LICENSE file that accompanied this code. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -23,61 +23,56 @@ package org.scenarioo.api.util.xml; +import org.scenarioo.api.exception.ResourceNotFoundException; +import org.scenarioo.api.files.ObjectFromDirectory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.scenarioo.api.exception.ResourceNotFoundException; -import org.scenarioo.api.files.ObjectFromDirectory; - /** * Writing or reading of all ScenarioDocu entities to XML files and back */ public class ScenarioDocuXMLFileUtil { - + + private static final Logger LOGGER = LoggerFactory.getLogger(ScenarioDocuXMLFileUtil.class); + public static void marshal(final T object, final File destFile) { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(destFile); + try (FileOutputStream fos = new FileOutputStream(destFile)) { ScenarioDocuXMLUtil.marshal(object, fos); } catch (Exception e) { throw new RuntimeException("Could not marshall Object of type " + object.getClass().getName() + " into file: " + destFile.getAbsolutePath(), e); - } finally { - try { - if (fos != null) { - fos.close(); - } - } catch (IOException e) { - throw new RuntimeException("Could not close file output stream for " + destFile.getAbsolutePath(), e); - } } } - + public static T unmarshal(final Class targetClass, final File srcFile) { if (!srcFile.exists()) { throw new ResourceNotFoundException(srcFile.getAbsolutePath()); } - FileInputStream fis = null; - try { - fis = new FileInputStream(srcFile); + try (FileInputStream fis = new FileInputStream(srcFile)) { return ScenarioDocuXMLUtil.unmarshal(targetClass, fis); } catch (Exception e) { throw new RuntimeException("Could not unmarshall " + srcFile.getAbsolutePath(), e); - } finally { + } + } + + public static List unmarshalListOfFilesIgnoreInvalid(final Class targetClass, final List files) { + List result = new ArrayList(); + for (File file : files) { try { - if (fis != null) { - fis.close(); - } - } catch (IOException e) { - throw new RuntimeException("Could not close file input stream for " + srcFile.getAbsolutePath(), e); + result.add(unmarshal(targetClass, file)); + } catch (Throwable e) { + LOGGER.error("Could not parse invalid File: " + file.getAbsolutePath() + " - will ignore this object."); } } + return result; } - + public static List unmarshalListOfFiles(final Class targetClass, final List files) { List result = new ArrayList(); for (File file : files) { @@ -85,7 +80,7 @@ public static List unmarshalListOfFiles(final Class targetClass, final } return result; } - + /** * Read all passed files and unmarshall these to the given object type, also return the name of the directory the * object was loaded from. @@ -99,5 +94,23 @@ public static List> unmarshalListOfFilesWithDirNames( } return result; } - + + /** + * Read all passed files and unmarshall these to the given object type, also return the name of the directory the + * object was loaded from. + */ + public static List> unmarshalListOfFilesWithDirNamesIgnoreInvalid( + final List files, final Class targetClass, final Class... classesToBind) { + List> result = new ArrayList>(); + for (File file : files) { + try { + result.add(new ObjectFromDirectory(unmarshal(targetClass, file), file + .getParentFile().getName())); + } catch (Throwable e) { + LOGGER.error("Could not parse invalid File: " + file.getAbsolutePath() + " - will ignore this object."); + } + } + return result; + } + } diff --git a/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLUtil.java b/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLUtil.java index d9ed0c6..34b3b7f 100644 --- a/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLUtil.java +++ b/src/main/java/org/scenarioo/api/util/xml/ScenarioDocuXMLUtil.java @@ -1,21 +1,21 @@ /* scenarioo-api * Copyright (C) 2014, scenarioo.org Development Team - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * As a special exception, the copyright holders of this library give you - * permission to link this library with independent modules, according + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules, according * to the GNU General Public License with "Classpath" exception as provided * in the LICENSE file that accompanied this code. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -23,36 +23,31 @@ package org.scenarioo.api.util.xml; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.*; +import org.apache.commons.lang3.StringUtils; +import org.scenarioo.model.docu.entities.generic.*; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; - -import org.apache.commons.lang3.StringUtils; -import org.scenarioo.model.docu.entities.generic.Details; -import org.scenarioo.model.docu.entities.generic.ObjectDescription; -import org.scenarioo.model.docu.entities.generic.ObjectList; -import org.scenarioo.model.docu.entities.generic.ObjectReference; -import org.scenarioo.model.docu.entities.generic.ObjectTreeNode; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.*; /** * Streaming of all ScenarioDocu entities to XML and back from input streams or to output streams. */ public class ScenarioDocuXMLUtil { - private static Map jaxbContextCache = new HashMap(); + private static final Map jaxbContextCache = new HashMap<>(); + + private static final Class[] SUPPORTED_COLLECTION_CLASSES = new Class[]{HashMap.class, ArrayList.class}; + + private static final Class[] SUPPORTED_GENERIC_CLASSES = new Class[]{ObjectDescription.class, + ObjectReference.class, ObjectList.class, ObjectTreeNode.class, Details.class}; - private static final Class[] SUPPORTED_COLLECTION_CLASSES = new Class[] { HashMap.class, ArrayList.class }; - - private static final Class[] SUPPORTED_GENERIC_CLASSES = new Class[] { ObjectDescription.class, - ObjectReference.class, ObjectList.class, ObjectTreeNode.class, Details.class }; - public static void marshal(final T object, final OutputStream outStream) { - + try { JAXBContext contextObj = createJAXBContext(object.getClass()); Marshaller marshallerObj = contextObj.createMarshaller(); @@ -62,7 +57,7 @@ public static void marshal(final T object, final OutputStream outStream) { throw new RuntimeException("Could not marshall Object of type " + object.getClass().getName(), e); } } - + @SuppressWarnings("unchecked") public static T unmarshal(final Class targetClass, final InputStream inStream) { try { @@ -73,29 +68,29 @@ public static T unmarshal(final Class targetClass, final InputStream inSt throw new RuntimeException("Could not unmarshall object of type " + targetClass.getName(), e); } } - + public static JAXBContext createJAXBContext(Class... classesToBind) throws JAXBException { - String key = getKeyFromClassesArray(classesToBind); - JAXBContext cachedJaxbContext = jaxbContextCache.get(key); - if(cachedJaxbContext != null) { - return cachedJaxbContext; - } + String key = getKeyFromClassesArray(classesToBind); + JAXBContext cachedJaxbContext = jaxbContextCache.get(key); + if (cachedJaxbContext != null) { + return cachedJaxbContext; + } classesToBind = appendClasses(classesToBind, SUPPORTED_COLLECTION_CLASSES); classesToBind = appendClasses(classesToBind, SUPPORTED_GENERIC_CLASSES); - JAXBContext jaxbContext = JAXBContext.newInstance(classesToBind); - jaxbContextCache.put(key, jaxbContext); - return jaxbContext; + JAXBContext jaxbContext = JAXBContext.newInstance(classesToBind); + jaxbContextCache.put(key, jaxbContext); + return jaxbContext; } - private static String getKeyFromClassesArray(Class[] classesToBind) { - List keys = new ArrayList(); - for (Class aClass : classesToBind) { - keys.add(aClass.getCanonicalName()); - } - return StringUtils.join(keys, ","); - } + private static String getKeyFromClassesArray(Class[] classesToBind) { + List keys = new ArrayList(); + for (Class aClass : classesToBind) { + keys.add(aClass.getCanonicalName()); + } + return StringUtils.join(keys, ","); + } - private static Class[] appendClasses(Class[] classesToBind, final Class... additionalClasses) { + private static Class[] appendClasses(Class[] classesToBind, final Class... additionalClasses) { int index = classesToBind.length; classesToBind = Arrays.copyOf(classesToBind, classesToBind.length + additionalClasses.length); for (Class additionalClass : additionalClasses) { @@ -104,5 +99,5 @@ private static Class[] appendClasses(Class[] classesToBind, final Class } return classesToBind; } - + } diff --git a/src/main/java/org/scenarioo/model/docu/entities/generic/Details.java b/src/main/java/org/scenarioo/model/docu/entities/generic/Details.java index 07d7b1a..9e2d4ee 100755 --- a/src/main/java/org/scenarioo/model/docu/entities/generic/Details.java +++ b/src/main/java/org/scenarioo/model/docu/entities/generic/Details.java @@ -1,42 +1,41 @@ /* scenarioo-api * Copyright (C) 2014, scenarioo.org Development Team - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * As a special exception, the copyright holders of this library give you - * permission to link this library with independent modules, according + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules, according * to the GNU General Public License with "Classpath" exception as provided * in the LICENSE file that accompanied this code. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package org.scenarioo.model.docu.entities.generic; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; - /** * Collection of application specific additional information to store and display in the scenarioo documentation. - * + *

* A client of the scenarioo-API can add any key-value-data to this detail informations. - * + *

* Following type of objects are possible values inside the details: *

    *
  • {@link String}: for usual text information
  • @@ -52,17 +51,17 @@ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Details implements Map, Serializable { - - private final Map properties = new LinkedHashMap(); - + + private final Map properties = new LinkedHashMap<>(); + public Map getProperties() { return properties; } - + /** * Add a key value pair as a information item to this details. The details will be presented in same order as added * to the details object in the documentation. - * + *

    * See class description of {@link Details} about possible types to use as values. */ public Details addDetail(final String key, final Object value) { @@ -73,79 +72,121 @@ public Details addDetail(final String key, final Object value) { } return this; } - + + /** + * Use to describe an object (described through a type and a name and additional + * key-value-details again). + * + *

    + * See class description of {@link Details} about other possible types to use. + */ + public Details addDetail(final String key, final ObjectDescription objectDescription) { + return this.addDetail(key, (Object) objectDescription); + } + + /** + * Use to reference an {@link ObjectDescription} that was already stored elsewhere, only + * through its type and name without storing all the details information again. + * + *

    + * See class description of {@link Details} about other possible types to use. + */ + public Details addDetail(final String key, final ObjectReference objectReference) { + return this.addDetail(key, (Object) objectReference); + } + + /** + * Use for complex tree structures containing same content types as possible node objects. + * + *

    + * See class description of {@link Details} about other possible types to use. + */ + public Details addDetail(final String key, final ObjectTreeNode objectTreeNode) { + return this.addDetail(key, (Object) objectTreeNode); + } + + /** + * Use for a list of value items (same types allowed as content types again). + * + *

    + * See class description of {@link Details} about other possible types to use. + */ + public Details addDetail(final String key, final ObjectList objectList) { + return this.addDetail(key, (Object) objectList); + } + public Object getDetail(final String key) { return properties.get(key); } - + @Override public int size() { return properties.size(); } - + @Override public boolean isEmpty() { return properties.isEmpty(); } - + @Override public boolean containsKey(final Object key) { return properties.containsKey(key); } - + @Override public boolean containsValue(final Object value) { return properties.containsValue(value); } - + @Override public Object get(final Object key) { return properties.get(key); } - + @Override public Object put(final String key, final Object value) { return properties.put(key, value); } - + @Override public Object remove(final Object key) { return properties.remove(key); } - + @Override public void putAll(final Map m) { properties.putAll(m); } - + @Override public void clear() { properties.clear(); } - + @Override public Set keySet() { return properties.keySet(); } - + @Override public Collection values() { return properties.values(); } - + @Override public Set> entrySet() { return properties.entrySet(); } - + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((properties == null) ? 0 : properties.hashCode()); + result = prime * result + properties.hashCode(); return result; } - + @Override public boolean equals(final Object obj) { if (this == obj) { @@ -158,14 +199,7 @@ public boolean equals(final Object obj) { return false; } Details other = (Details) obj; - if (properties == null) { - if (other.properties != null) { - return false; - } - } else if (!properties.equals(other.properties)) { - return false; - } - return true; + return properties.equals(other.properties); } - + } diff --git a/src/main/resources/scenarioo-schemas/scenarioo-api.xsd b/src/main/resources/scenarioo-schemas/scenarioo-api.xsd index 7113e90..5899689 100644 --- a/src/main/resources/scenarioo-schemas/scenarioo-api.xsd +++ b/src/main/resources/scenarioo-schemas/scenarioo-api.xsd @@ -54,12 +54,9 @@ - + - - - - + @@ -77,9 +74,14 @@ - + - + + + + + + @@ -96,43 +98,37 @@ - + - - - - - - - - - - - - - - - - + - + - + - + - - + + + + + + + + + + + - + - + @@ -147,19 +143,17 @@ - - - - - - - + - + - + + + + + @@ -174,11 +168,22 @@ - + + + - + + + + + + + + + + @@ -201,13 +206,12 @@ - + - - - - - + + + + @@ -222,45 +226,39 @@ - - - - + - - - - + - + - - - - - + + - + + + + + + + + + - + - - - - - - + @@ -277,15 +275,10 @@ - - - - - - - + - + + @@ -303,7 +296,14 @@ - + + + + + + + + diff --git a/src/test/java/org/scenarioo/api/ForbiddenSlashesTest.java b/src/test/java/org/scenarioo/api/ForbiddenSlashesTest.java index 690d16a..d3e9057 100644 --- a/src/test/java/org/scenarioo/api/ForbiddenSlashesTest.java +++ b/src/test/java/org/scenarioo/api/ForbiddenSlashesTest.java @@ -1,15 +1,15 @@ package org.scenarioo.api; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.scenarioo.api.TestConstants.*; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.scenarioo.api.exception.IllegalCharacterException; import org.scenarioo.model.docu.entities.Page; import org.scenarioo.model.docu.entities.Scenario; @@ -37,7 +37,7 @@ *
  • object name
  • * */ -public class ForbiddenSlashesTest { +class ForbiddenSlashesTest { private static final String ILLEGAL_NAME = "/illegal"; private static final String LEGAL_NAME = "legal"; @@ -46,8 +46,8 @@ public class ForbiddenSlashesTest { private static ScenarioDocuWriter scenarioDocuWriter; private static ScenarioDocuReader scenarioDocuReader; - @BeforeClass - public static void beforeClass() { + @BeforeAll + static void beforeClass() { if (!dataDirectory.exists()) { dataDirectory.mkdirs(); } @@ -55,184 +55,137 @@ public static void beforeClass() { scenarioDocuReader = new ScenarioDocuReader(dataDirectory); } - @AfterClass - public static void cleanup() { + @AfterAll + static void cleanup() { deleteDirectory(TEST_ROOT_DIRECTORY); } @Test - public void creatingAScenarioDocuWriter_withAnIllegalBranchName_resultsInAnException() { - try { - new ScenarioDocuWriter(dataDirectory, ILLEGAL_NAME, LEGAL_NAME); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void creatingAScenarioDocuWriter_withAnIllegalBranchName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> new ScenarioDocuWriter(dataDirectory, ILLEGAL_NAME, LEGAL_NAME)); + assertException(e); } @Test - public void creatingAScenarioDocuWriter_withAnIllegalBuildName_resultsInAnException() { - try { - new ScenarioDocuWriter(dataDirectory, LEGAL_NAME, ILLEGAL_NAME); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void creatingAScenarioDocuWriter_withAnIllegalBuildName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> new ScenarioDocuWriter(dataDirectory, LEGAL_NAME, ILLEGAL_NAME)); + assertException(e); } @Test - public void writingAUseCase_withAnIllegalUseCaseName_resultsInAnException() { - try { - scenarioDocuWriter.saveUseCase(getUseCaseWithIllegalName()); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAUseCase_withAnIllegalUseCaseName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveUseCase(getUseCaseWithIllegalName())); + assertException(e); } @Test - public void writingAScenario_withAnIllegalUseCaseName_resultsInAnException() { - try { - scenarioDocuWriter.saveScenario(ILLEGAL_NAME, getScenarioWithName(LEGAL_NAME)); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAScenario_withAnIllegalUseCaseName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveScenario(ILLEGAL_NAME, getScenarioWithName(LEGAL_NAME))); + assertException(e); + } @Test - public void writingAScenario_withAnIllegalScenarioName_resultsInAnException() { - try { - scenarioDocuWriter.saveScenario(LEGAL_NAME, getScenarioWithName(ILLEGAL_NAME)); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAScenario_withAnIllegalScenarioName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveScenario(LEGAL_NAME, getScenarioWithName(ILLEGAL_NAME))); + assertException(e); } @Test - public void writingAStep_withAnIllegalUseCaseName_resultsInAnException() { - try { - scenarioDocuWriter.saveStep(ILLEGAL_NAME, LEGAL_NAME, getStepWithPageName(LEGAL_NAME)); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAStep_withAnIllegalUseCaseName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveStep(ILLEGAL_NAME, LEGAL_NAME, getStepWithPageName(LEGAL_NAME))); + assertException(e); } @Test - public void writingAStep_withAnIllegalScenarioName_resultsInAnException() { - try { - scenarioDocuWriter.saveStep(LEGAL_NAME, ILLEGAL_NAME, getStepWithPageName(LEGAL_NAME)); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAStep_withAnIllegalScenarioName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveStep(LEGAL_NAME, ILLEGAL_NAME, getStepWithPageName(LEGAL_NAME))); + assertException(e); } @Test - public void writingAStep_withAnIllegalPageName_resultsInAnException() { - try { - scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithPageName(ILLEGAL_NAME)); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAStep_withAnIllegalPageName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithPageName(ILLEGAL_NAME))); + assertException(e); } @Test - public void writingAStep_withAnIllegalObjectTypeInMetadata_resultsInAnException() { - try { - scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectTypeInMetadata()); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAStep_withAnIllegalObjectTypeInMetadata_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectTypeInMetadata())); + assertException(e); } @Test - public void writingAStep_withAnIllegalObjectNameInMetadata_resultsInAnException() { - try { - scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectNameInMetadata()); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAStep_withAnIllegalObjectNameInMetadata_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectNameInMetadata())); + assertException(e); } @Test - public void writingAStep_withAnIllegalObjectTypeInStepDescription_resultsInAnException() { - try { - scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectTypeInStepDescription()); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAStep_withAnIllegalObjectTypeInStepDescription_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectTypeInStepDescription())); + assertException(e); } @Test - public void writingAStep_withAnIllegalObjectNameInStepDescription_resultsInAnException() { - try { - scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectNameInStepDescription()); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void writingAStep_withAnIllegalObjectNameInStepDescription_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuWriter.saveStep(LEGAL_NAME, LEGAL_NAME, getStepWithIllegalObjectNameInStepDescription())); + assertException(e); } @Test - public void readingAUseCase_withAnIllegalBranchName_resultsInAnException() { - try { - scenarioDocuReader.loadUsecase(ILLEGAL_NAME, LEGAL_NAME, LEGAL_NAME); - fail(); - } catch (IllegalCharacterException e) { + void readingAUseCase_withAnIllegalBranchName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuReader.loadUsecase(ILLEGAL_NAME, LEGAL_NAME, LEGAL_NAME)); assertException(e); - } } @Test - public void readingAUseCase_withAnIllegalBuildName_resultsInAnException() { - try { - scenarioDocuReader.loadUsecase(LEGAL_NAME, ILLEGAL_NAME, LEGAL_NAME); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void readingAUseCase_withAnIllegalBuildName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuReader.loadUsecase(LEGAL_NAME, ILLEGAL_NAME, LEGAL_NAME)); + assertException(e); } @Test - public void readingAUseCase_withAnIllegalUseCaseName_resultsInAnException() { - try { - scenarioDocuReader.loadUsecase(LEGAL_NAME, LEGAL_NAME, ILLEGAL_NAME); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void readingAUseCase_withAnIllegalUseCaseName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuReader.loadUsecase(LEGAL_NAME, LEGAL_NAME, ILLEGAL_NAME)); + assertException(e); } @Test - public void readingAScenario_withAnIllegalScenarioName_resultsInAnException() { - try { - scenarioDocuReader.loadScenario(LEGAL_NAME, LEGAL_NAME, LEGAL_NAME, ILLEGAL_NAME); - fail(); - } catch (IllegalCharacterException e) { - assertException(e); - } + void readingAScenario_withAnIllegalScenarioName_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> scenarioDocuReader.loadScenario(LEGAL_NAME, LEGAL_NAME, LEGAL_NAME, ILLEGAL_NAME)); + assertException(e); } @Test - public void readingAStep_withAnIllegalPageName_works() { + void readingAStep_withAnIllegalPageName_works() { // The server takes care of these illegal page names and sanitizes them // TODO [#331] Implement this test } @Test - public void readingAStep_withAnIllegalObjectType_isAllowedButDiscouraged() { + void readingAStep_withAnIllegalObjectType_isAllowedButDiscouraged() { // TODO [#330] Maybe we should also sanitize object names and object types as we do it for page names } @Test - public void readingAStep_withAnIllegalObjectName_isAllowedButDiscouraged() { + void readingAStep_withAnIllegalObjectName_isAllowedButDiscouraged() { // TODO [#330] Maybe we should also sanitize object names and object types as we do it for page names } diff --git a/src/test/java/org/scenarioo/api/SaveScreenshotTest.java b/src/test/java/org/scenarioo/api/SaveScreenshotTest.java index ff5f389..8208001 100644 --- a/src/test/java/org/scenarioo/api/SaveScreenshotTest.java +++ b/src/test/java/org/scenarioo/api/SaveScreenshotTest.java @@ -1,25 +1,26 @@ package org.scenarioo.api; -import static org.scenarioo.api.TestConstants.*; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.scenarioo.api.TestConstants.*; -public class SaveScreenshotTest { +class SaveScreenshotTest { private static final String pngFileName = "/scenarioo-icon-unittest.png"; private static byte[] imageAsByteArray; private ScenarioDocuWriter writer; - @BeforeClass - public static void loadImage() { + @BeforeAll + static void loadImage() { try { imageAsByteArray = FileUtils.readFileToByteArray(new File(SaveScreenshotTest.class.getResource(pngFileName) .getFile())); @@ -28,14 +29,14 @@ public static void loadImage() { } } - @Before - public void setUp() { + @BeforeEach + void setUp() { TEST_ROOT_DIRECTORY.mkdirs(); writer = new ScenarioDocuWriter(TEST_ROOT_DIRECTORY, TEST_BRANCH_NAME, TEST_BUILD_NAME); } @Test - public void savePngScreenshot() { + void savePngScreenshot() { writer.saveScreenshotAsPng(TEST_CASE_NAME, TEST_SCENARIO_NAME, TEST_STEP_INDEX, imageAsByteArray); writer.flush(); @@ -49,12 +50,11 @@ private void assertStoredFileContentEqualsOriginalImage() { try { fileAsByteArray = FileUtils.readFileToByteArray(file); } catch (IOException e) { - Assert.fail("Could not read file " + file); - e.printStackTrace(); + fail("Could not read file " + file, e); return; } - Assert.assertArrayEquals(imageAsByteArray, fileAsByteArray); + assertArrayEquals(imageAsByteArray, fileAsByteArray); } } diff --git a/src/test/java/org/scenarioo/api/ScenarioDocuWriterAndReaderTest.java b/src/test/java/org/scenarioo/api/ScenarioDocuWriterAndReaderTest.java index e029f90..5e6ff23 100644 --- a/src/test/java/org/scenarioo/api/ScenarioDocuWriterAndReaderTest.java +++ b/src/test/java/org/scenarioo/api/ScenarioDocuWriterAndReaderTest.java @@ -22,7 +22,7 @@ package org.scenarioo.api; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.scenarioo.api.TestConstants.*; import java.io.File; @@ -30,9 +30,9 @@ import java.util.Date; import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.scenarioo.api.files.ScenarioDocuFiles; import org.scenarioo.model.docu.entities.Branch; import org.scenarioo.model.docu.entities.Build; @@ -55,7 +55,7 @@ /** * Some smoke tests for the Scenarioo generator API. */ -public class ScenarioDocuWriterAndReaderTest { +class ScenarioDocuWriterAndReaderTest { private static final String TEST_DETAILS_VERSION_KEY = "version"; @@ -70,16 +70,16 @@ public class ScenarioDocuWriterAndReaderTest { */ private ScenarioDocuFiles docuFiles; - @Before - public void setUp() { + @BeforeEach + void setUp() { TEST_ROOT_DIRECTORY.mkdirs(); writer = new ScenarioDocuWriter(TEST_ROOT_DIRECTORY, TEST_BRANCH_NAME, TEST_BUILD_NAME); reader = new ScenarioDocuReader(TEST_ROOT_DIRECTORY); docuFiles = new ScenarioDocuFiles(TEST_ROOT_DIRECTORY); } - @AfterClass - public static void tearDown() { + @AfterAll + static void tearDown() { deleteDirectory(TEST_ROOT_DIRECTORY); } @@ -92,7 +92,7 @@ private static void deleteDirectory(final File testRootDirectory) { } @Test - public void write_and_read_branch_description() { + void write_and_read_branch_description() { // GIVEN: a typical branch Branch branch = new Branch(); @@ -105,13 +105,13 @@ public void write_and_read_branch_description() { // THEN: the branch can be loaded successfully and correctly Branch branchFromFile = reader.loadBranch(TEST_BRANCH_NAME); - assertEquals("expected branch name", TEST_BRANCH_NAME, branchFromFile.getName()); - assertEquals("expected branch description", branch.getDescription(), branchFromFile.getDescription()); + assertEquals(TEST_BRANCH_NAME, branchFromFile.getName(), "expected branch name"); + assertEquals(branch.getDescription(), branchFromFile.getDescription(), "expected branch description"); } @Test - public void write_and_read_build_description() { + void write_and_read_build_description() { // GIVEN: a typical build Build build = new Build(); @@ -127,17 +127,17 @@ public void write_and_read_build_description() { // THEN: the build can be loaded successfully and correctly Build buildFromFile = reader.loadBuild(TEST_BRANCH_NAME, TEST_BUILD_NAME); - assertEquals("expected build name", TEST_BUILD_NAME, buildFromFile.getName()); - assertEquals("expected date", build.getDate(), buildFromFile.getDate()); - assertEquals("expected revision", build.getRevision(), buildFromFile.getRevision()); - assertEquals("expected state", build.getStatus(), buildFromFile.getStatus()); - assertEquals("expected details properties", build.getDetails().getProperties(), buildFromFile.getDetails() - .getProperties()); + assertEquals(TEST_BUILD_NAME, buildFromFile.getName(), "expected build name"); + assertEquals(build.getDate(), buildFromFile.getDate(), "expected date"); + assertEquals(build.getRevision(), buildFromFile.getRevision(), "expected revision"); + assertEquals(build.getStatus(), buildFromFile.getStatus(), "expected state"); + assertEquals(build.getDetails().getProperties(), buildFromFile.getDetails() + .getProperties(), "expected details properties"); } @Test - public void write_and_read_case_description() { + void write_and_read_case_description() { // GIVEN: a typical use case UseCase usecase = new UseCase(); @@ -153,16 +153,16 @@ public void write_and_read_case_description() { // THEN: the usecase can be loaded successfully and correctly UseCase usecaseFromFile = reader.loadUsecase(TEST_BRANCH_NAME, TEST_BUILD_NAME, TEST_CASE_NAME); - assertEquals("expected case name", TEST_CASE_NAME, usecaseFromFile.getName()); - assertEquals("expected case desription", usecase.getDescription(), usecaseFromFile.getDescription()); - assertEquals("expected case state", usecase.getStatus(), usecaseFromFile.getStatus()); - assertEquals("expected details properties", usecase.getDetails().getProperties(), usecaseFromFile.getDetails() - .getProperties()); + assertEquals(TEST_CASE_NAME, usecaseFromFile.getName(), "expected case name"); + assertEquals(usecase.getDescription(), usecaseFromFile.getDescription(), "expected case desription"); + assertEquals(usecase.getStatus(), usecaseFromFile.getStatus(), "expected case state"); + assertEquals(usecase.getDetails().getProperties(), usecaseFromFile.getDetails() + .getProperties(), "expected details properties"); assertExpectedLabels(usecaseFromFile.getLabels(), "label1", "label2"); } @Test - public void write_and_read_scenario_description() { + void write_and_read_scenario_description() { // GIVEN: a typical scenario Scenario scenario = new Scenario(); @@ -179,11 +179,11 @@ public void write_and_read_scenario_description() { // THEN: the scenario can be loaded successfully and correctly Scenario scenarioFromFile = reader.loadScenario(TEST_BRANCH_NAME, TEST_BUILD_NAME, TEST_CASE_NAME, TEST_SCENARIO_NAME); - assertEquals("expected scneario name", TEST_SCENARIO_NAME, scenarioFromFile.getName()); - assertEquals("expected scenario desription", scenario.getDescription(), scenarioFromFile.getDescription()); - assertEquals("expected scenario state", scenario.getStatus(), scenarioFromFile.getStatus()); - assertEquals("expected scenario details properties", scenario.getDetails().getProperties(), scenarioFromFile - .getDetails().getProperties()); + assertEquals(TEST_SCENARIO_NAME, scenarioFromFile.getName(), "expected scneario name"); + assertEquals(scenario.getDescription(), scenarioFromFile.getDescription(), "expected scenario desription"); + assertEquals(scenario.getStatus(), scenarioFromFile.getStatus(), "expected scenario state"); + assertEquals(scenario.getDetails().getProperties(), scenarioFromFile + .getDetails().getProperties(), "expected scenario details properties"); assertExpectedLabels(scenarioFromFile.getLabels(), "label1", "label2"); } @@ -193,7 +193,7 @@ public void write_and_read_scenario_description() { * correctly. */ @Test - public void write_and_read_step_minimal() { + void write_and_read_step_minimal() { // GIVEN: a typical step with only minimal required fields beeing set Step step = new Step(); @@ -209,16 +209,15 @@ public void write_and_read_step_minimal() { // THEN: the step can be loaded successfully and correctly Step stepFromFile = reader.loadStep(TEST_BRANCH_NAME, TEST_BUILD_NAME, TEST_CASE_NAME, TEST_SCENARIO_NAME, TEST_STEP_INDEX); - assertEquals("expected step index", TEST_STEP_INDEX, stepFromFile.getStepDescription().getIndex()); - assertEquals("expected empty step title", "", stepFromFile.getStepDescription().getTitle()); - assertEquals("expected no status", "", stepFromFile.getStepDescription().getStatus()); - assertEquals("expected no step step description details properties", 0, stepFromFile.getStepDescription() - .getDetails() - .getProperties().size()); - assertEquals("expected no step metadata details properties", 0, stepFromFile.getMetadata().getDetails() - .getProperties().size()); - assertEquals("expected no labels", 0, stepFromFile.getStepDescription().getLabels().size()); - assertNull("expected no page", stepFromFile.getPage()); + assertEquals(TEST_STEP_INDEX, stepFromFile.getStepDescription().getIndex(), "expected step index"); + assertEquals("", stepFromFile.getStepDescription().getTitle(), "expected empty step title"); + assertEquals("", stepFromFile.getStepDescription().getStatus(), "expected no status"); + assertEquals(0, stepFromFile.getStepDescription().getDetails().getProperties().size(), + "expected no step step description details properties"); + assertEquals(0, stepFromFile.getMetadata().getDetails().getProperties().size(), + "expected no step metadata details properties"); + assertEquals(0, stepFromFile.getStepDescription().getLabels().size(), "expected no labels"); + assertNull(stepFromFile.getPage(), "expected no page"); } @@ -226,7 +225,7 @@ public void write_and_read_step_minimal() { * This test tests also all optional fields of a step, that they can be set and are loaded again properly. */ @Test - public void write_and_read_step_with_major_optional_fields() { + void write_and_read_step_with_major_optional_fields() { // GIVEN: a typical step with all major optional fields also beeing set Step step = new Step(); @@ -253,21 +252,22 @@ public void write_and_read_step_with_major_optional_fields() { // THEN: the step can be loaded successfully and correctly Step stepFromFile = reader.loadStep(TEST_BRANCH_NAME, TEST_BUILD_NAME, TEST_CASE_NAME, TEST_SCENARIO_NAME, TEST_STEP_INDEX); - assertEquals("expected step name", TEST_STEP_INDEX, stepFromFile.getStepDescription().getIndex()); - assertEquals("expected step desription", step.getStepDescription().getTitle(), stepFromFile - .getStepDescription().getTitle()); - assertEquals("expected step status", step.getStepDescription().getStatus(), stepFromFile.getStepDescription() - .getStatus()); - assertEquals("expected step description details properties", step.getStepDescription().getDetails() - .getProperties(), stepFromFile.getStepDescription().getDetails().getProperties()); + assertEquals(TEST_STEP_INDEX, stepFromFile.getStepDescription().getIndex(), "expected step name"); + assertEquals(step.getStepDescription().getTitle(), stepFromFile.getStepDescription().getTitle(), + "expected step desription"); + assertEquals(step.getStepDescription().getStatus(), stepFromFile.getStepDescription().getStatus(), + "expected step status"); + assertEquals(step.getStepDescription().getDetails().getProperties(), + stepFromFile.getStepDescription().getDetails().getProperties(), + "expected step description details properties"); assertExpectedLabels(stepFromFile.getStepDescription().getLabels(), "label1", "label2"); - assertEquals("expected step html", step.getHtml().getHtmlSource(), stepFromFile.getHtml().getHtmlSource()); + assertEquals(step.getHtml().getHtmlSource(), stepFromFile.getHtml().getHtmlSource(), "expected step html"); Page pageFromFile = stepFromFile.getPage(); - assertEquals("expected step page name", step.getPage().getName(), pageFromFile.getName()); + assertEquals(step.getPage().getName(), pageFromFile.getName(), "expected step page name"); assertExpectedLabels(pageFromFile.getLabels(), "page-label1", "page-label2"); - assertEquals("expected step visible text", "just some page text", stepFromFile.getMetadata().getVisibleText()); - assertEquals("expected step metadata details properties", step.getMetadata().getDetails().getProperties(), - stepFromFile.getMetadata().getDetails().getProperties()); + assertEquals("just some page text", stepFromFile.getMetadata().getVisibleText(), "expected step visible text"); + assertEquals(step.getMetadata().getDetails().getProperties(), + stepFromFile.getMetadata().getDetails().getProperties(), "expected step metadata details properties"); } @@ -275,7 +275,7 @@ public void write_and_read_step_with_major_optional_fields() { * Test adding screen annotations to a step (which is optional too) */ @Test - public void write_and_read_step_with_screen_annotations() { + void write_and_read_step_with_screen_annotations() { // GIVEN: a typical step with only minimal required fields beeing set and two screen annotations Step step = new Step(); @@ -293,7 +293,7 @@ public void write_and_read_step_with_screen_annotations() { // THEN: the step can be loaded successfully and correctly Step stepFromFile = reader.loadStep(TEST_BRANCH_NAME, TEST_BUILD_NAME, TEST_CASE_NAME, TEST_SCENARIO_NAME, TEST_STEP_INDEX); - assertEquals("expected number of screen annotations", 2, stepFromFile.getScreenAnnotations().size()); + assertEquals(2, stepFromFile.getScreenAnnotations().size(), "expected number of screen annotations"); assertMinimalScreenAnnotation(stepFromFile.getScreenAnnotations().get(0)); assertFullScreenAnnotation(stepFromFile.getScreenAnnotations().get(1)); @@ -303,7 +303,7 @@ public void write_and_read_step_with_screen_annotations() { * Tests writing and reading of a scenario docu file containing some basic collections that need to be supported. */ @Test - public void write_and_read_generic_collections_in_details() { + void write_and_read_generic_collections_in_details() { // GIVEN: any object containing collections in details Scenario scenario = new Scenario(); @@ -342,7 +342,7 @@ public void write_and_read_generic_collections_in_details() { * written. */ @Test - public void async_write_of_multiple_files_and_flush() { + void async_write_of_multiple_files_and_flush() { // GIVEN: a lot of large steps to write, that have not yet been written Step[] steps = new Step[10]; @@ -373,17 +373,17 @@ private ScreenAnnotation createMinimalScreenAnnotation() { } private void assertMinimalScreenAnnotation(final ScreenAnnotation screenAnnotation) { - assertEquals("Expected x coordinate", 100, screenAnnotation.getRegion().getX()); - assertEquals("Expected y coordinate", 150, screenAnnotation.getRegion().getY()); - assertEquals("Expected width", 90, screenAnnotation.getRegion().getWidth()); - assertEquals("Expected height", 10, screenAnnotation.getRegion().getHeight()); - assertEquals("Expected no text", "", screenAnnotation.getScreenText()); - assertEquals("Expected no description", "", screenAnnotation.getDescription()); - assertEquals("Expected default style", screenAnnotation.getStyle(), ScreenAnnotationStyle.DEFAULT); - assertNull("Expected no click action", screenAnnotation.getClickAction()); - assertNull("Expected no click action url", screenAnnotation.getClickActionUrl()); - assertNull("Expected no click action text", screenAnnotation.getClickActionText()); - assertEquals("Expected no details", 0, screenAnnotation.getDetails().size()); + assertEquals(100, screenAnnotation.getRegion().getX(), "Expected x coordinate"); + assertEquals(150, screenAnnotation.getRegion().getY(), "Expected y coordinate"); + assertEquals(90, screenAnnotation.getRegion().getWidth(), "Expected width"); + assertEquals(10, screenAnnotation.getRegion().getHeight(), "Expected height"); + assertEquals("", screenAnnotation.getScreenText(), "Expected no text"); + assertEquals("", screenAnnotation.getDescription(), "Expected no description"); + assertEquals(screenAnnotation.getStyle(), ScreenAnnotationStyle.DEFAULT, "Expected default style"); + assertNull(screenAnnotation.getClickAction(), "Expected no click action"); + assertNull(screenAnnotation.getClickActionUrl(), "Expected no click action url"); + assertNull(screenAnnotation.getClickActionText(), "Expected no click action text"); + assertEquals(0, screenAnnotation.getDetails().size(), "Expected no details"); } /** @@ -403,18 +403,18 @@ private ScreenAnnotation createFullScreenAnnotation() { } private void assertFullScreenAnnotation(final ScreenAnnotation screenAnnotation) { - assertEquals("Expected x coordinate", 200, screenAnnotation.getRegion().getX()); - assertEquals("Expected y coordinate", 150, screenAnnotation.getRegion().getY()); - assertEquals("Expected width", 90, screenAnnotation.getRegion().getWidth()); - assertEquals("Expected height", 20, screenAnnotation.getRegion().getHeight()); - assertEquals("Expected screen text", "just a text", screenAnnotation.getScreenText()); - assertEquals("Expected title", "title", screenAnnotation.getTitle()); - assertEquals("Expected description", "just a description", screenAnnotation.getDescription()); - assertEquals("Expected style", ScreenAnnotationStyle.CLICK, screenAnnotation.getStyle()); - assertEquals("Expected clickAction", ScreenAnnotationClickAction.TO_URL, screenAnnotation.getClickAction()); - assertEquals("Expected clickActionUrl", "http://just-an-url.com", screenAnnotation.getClickActionUrl()); - assertEquals("Expected clickActionText", "just a click action text", screenAnnotation.getClickActionText()); - assertEquals("Expected details", 1, screenAnnotation.getDetails().size()); + assertEquals(200, screenAnnotation.getRegion().getX(), "Expected x coordinate"); + assertEquals(150, screenAnnotation.getRegion().getY(), "Expected y coordinate"); + assertEquals(90, screenAnnotation.getRegion().getWidth(), "Expected width"); + assertEquals(20, screenAnnotation.getRegion().getHeight(), "Expected height"); + assertEquals("just a text", screenAnnotation.getScreenText(), "Expected screen text"); + assertEquals("title", screenAnnotation.getTitle(), "Expected title"); + assertEquals("just a description", screenAnnotation.getDescription(), "Expected description"); + assertEquals(ScreenAnnotationStyle.CLICK, screenAnnotation.getStyle(), "Expected style"); + assertEquals(ScreenAnnotationClickAction.TO_URL, screenAnnotation.getClickAction(), "Expected clickAction"); + assertEquals("http://just-an-url.com", screenAnnotation.getClickActionUrl(), "Expected clickActionUrl"); + assertEquals("just a click action text", screenAnnotation.getClickActionText(), "Expected clickActionText"); + assertEquals(1, screenAnnotation.getDetails().size(), "Expected details"); } private Step createBigDataStepForLoadTestAsyncWriting(final int index) { @@ -461,9 +461,8 @@ private StepHtml createBigHtml() { builder.append(""); builder.append("

    This is just a dummy html code with lot of content to generate a lot of big data to write for load testing.

    "); for (int i = 0; i < 1000; i++) { - builder.append("

    This is just a dummy html code with lot of content to generate a lot of big data to write for load testing.
    "); + builder.append("
    This is just a dummy html code with lot of content to generate a lot of big data to write for load testing.
    "); } builder.append(""); @@ -474,10 +473,10 @@ private StepHtml createBigHtml() { } private void assertExpectedLabels(final Labels labels, final String... expectedLabels) { - assertEquals("Expected number of labels", expectedLabels.length, labels.size()); + assertEquals(expectedLabels.length, labels.size(), "Expected number of labels"); for (String expectedLabel : expectedLabels) { - assertTrue("expected label '" + expectedLabel + "' to be contained in labels.", - labels.contains(expectedLabel)); + assertTrue(labels.contains(expectedLabel), + "expected label '" + expectedLabel + "' to be contained in labels."); } } } diff --git a/src/test/java/org/scenarioo/api/TestConstants.java b/src/test/java/org/scenarioo/api/TestConstants.java index 49fdc89..ab87264 100644 --- a/src/test/java/org/scenarioo/api/TestConstants.java +++ b/src/test/java/org/scenarioo/api/TestConstants.java @@ -2,7 +2,7 @@ import java.io.File; -public class TestConstants { +class TestConstants { public static final File TEST_ROOT_DIRECTORY = new File("tmpScenarioDocuUnitTestFiles"); public static final String TEST_BRANCH_NAME = "testBranch"; diff --git a/src/test/java/org/scenarioo/api/rules/CharacterCheckerTest.java b/src/test/java/org/scenarioo/api/rules/CharacterCheckerTest.java index 792841a..d18526a 100644 --- a/src/test/java/org/scenarioo/api/rules/CharacterCheckerTest.java +++ b/src/test/java/org/scenarioo/api/rules/CharacterCheckerTest.java @@ -1,85 +1,70 @@ package org.scenarioo.api.rules; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.scenarioo.api.exception.IllegalCharacterException; -public class CharacterCheckerTest { +class CharacterCheckerTest { @Test - public void checkIdentifier_nullIdentifiers_areValid() { + void checkIdentifier_nullIdentifiers_areValid() { CharacterChecker.checkIdentifier(null); } @Test - public void checkIdentifier_stringsWithoutASlashOrBackslash_areValid() { + void checkIdentifier_stringsWithoutASlashOrBackslash_areValid() { CharacterChecker.checkIdentifier("Some5!*%&?+String"); } @Test - public void checkIdentifier_stringsWithASlash_resultInAnException() { - try { - CharacterChecker.checkIdentifier("abc/def"); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Identifier abc/def contains illegal characters.", e.getMessage()); - } + void checkIdentifier_stringsWithASlash_resultInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> CharacterChecker.checkIdentifier("abc/def")); + assertEquals("Identifier abc/def contains illegal characters.", e.getMessage()); } @Test - public void checkIdentifier_stringsWithABackslash_resultInAnException() { - try { - CharacterChecker.checkIdentifier("abc\\def"); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Identifier abc\\def contains illegal characters.", e.getMessage()); - } + void checkIdentifier_stringsWithABackslash_resultInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> CharacterChecker.checkIdentifier("abc\\def")); + assertEquals("Identifier abc\\def contains illegal characters.", e.getMessage()); } @Test - public void checkIdentifier_forValidIdentifiers_returnsTheIdentifier() { + void checkIdentifier_forValidIdentifiers_returnsTheIdentifier() { String identifier = "valid"; assertEquals(identifier, CharacterChecker.checkIdentifier(identifier)); } @Test - public void checkLabel_aNullLabel_resultsInAnException() { - try { - CharacterChecker.checkLabel(null); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Label null contains illegal characters.", e.getMessage()); - } + void checkLabel_aNullLabel_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> CharacterChecker.checkLabel(null)); + assertEquals("Label null contains illegal characters.", e.getMessage()); } @Test - public void checkLabel_aLabelContainingAllTypesOfAllowedCharacters_passesTheCheck() { + void checkLabel_aLabelContainingAllTypesOfAllowedCharacters_passesTheCheck() { CharacterChecker.checkLabel("abc_DEF-012 3456789"); } @Test - public void checkLabel_aLabelWithASlash_resultsInAnException() { - try { - CharacterChecker.checkLabel("abc/def"); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Label abc/def contains illegal characters.", e.getMessage()); - } + void checkLabel_aLabelWithASlash_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> CharacterChecker.checkLabel("abc/def")); + assertEquals("Label abc/def contains illegal characters.", e.getMessage()); } @Test - public void checkLabel_aLabelWithAnUmlaut_resultsInAnException() { - try { - CharacterChecker.checkLabel("äuäää"); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Label äuäää contains illegal characters.", e.getMessage()); - } + void checkLabel_aLabelWithAnUmlaut_resultsInAnException() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> CharacterChecker.checkLabel("äuäää")); + assertEquals("Label äuäää contains illegal characters.", e.getMessage()); } @Test - public void checkLabel_forValidLabels_returnsTheLabel() { + void checkLabel_forValidLabels_returnsTheLabel() { String label = "valid"; assertEquals(label, CharacterChecker.checkLabel(label)); } diff --git a/src/test/java/org/scenarioo/api/rules/DetailsCheckerTest.java b/src/test/java/org/scenarioo/api/rules/DetailsCheckerTest.java index bdd5c8e..06f1ac3 100644 --- a/src/test/java/org/scenarioo/api/rules/DetailsCheckerTest.java +++ b/src/test/java/org/scenarioo/api/rules/DetailsCheckerTest.java @@ -1,45 +1,41 @@ package org.scenarioo.api.rules; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.scenarioo.api.exception.IllegalCharacterException; import org.scenarioo.model.docu.entities.generic.Details; import org.scenarioo.model.docu.entities.generic.ObjectDescription; -public class DetailsCheckerTest { +class DetailsCheckerTest { private static final String ILLEGAL_IDENTIFIER = "/illegal"; private static final String LEGAL_IDENTIFIER = "legal"; @Test - public void ifDetailsIsNull_theCheckPasses() { + void ifDetailsIsNull_theCheckPasses() { DetailsChecker.checkIdentifiers(null); } @Test - public void ifAllIdentifiersAreValid_theCheckPasses() { + void ifAllIdentifiersAreValid_theCheckPasses() { DetailsChecker.checkIdentifiers(getDetailsWithValidIdentifiers()); } @Test - public void ifThereIsAnInvalidObjectType_anExceptionIsThrown() { - try { - DetailsChecker.checkIdentifiers(getDetailsWithInvalidObjectType()); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Identifier /illegal contains illegal characters.", e.getMessage()); - } + void ifThereIsAnInvalidObjectType_anExceptionIsThrown() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> DetailsChecker.checkIdentifiers(getDetailsWithInvalidObjectType())); + assertEquals("Identifier /illegal contains illegal characters.", e.getMessage()); + } @Test - public void ifThereIsAnInvalidObjectName_anExceptionIsThrown() { - try { - DetailsChecker.checkIdentifiers(getDetailsWithInvalidObjectName()); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Identifier /illegal contains illegal characters.", e.getMessage()); - } + void ifThereIsAnInvalidObjectName_anExceptionIsThrown() { + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> DetailsChecker.checkIdentifiers(getDetailsWithInvalidObjectName())); + assertEquals("Identifier /illegal contains illegal characters.", e.getMessage()); + } private Details getDetailsWithInvalidObjectType() { diff --git a/src/test/java/org/scenarioo/api/util/IdentifierSanitizerTest.java b/src/test/java/org/scenarioo/api/util/IdentifierSanitizerTest.java index 55719ea..59aaf37 100644 --- a/src/test/java/org/scenarioo/api/util/IdentifierSanitizerTest.java +++ b/src/test/java/org/scenarioo/api/util/IdentifierSanitizerTest.java @@ -1,23 +1,23 @@ package org.scenarioo.api.util; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class IdentifierSanitizerTest { +class IdentifierSanitizerTest { @Test - public void nullIdentifiersStayNull() { - assertEquals(null, IdentifierSanitizer.sanitize(null)); + void nullIdentifiersStayNull() { + assertNull(IdentifierSanitizer.sanitize(null)); } @Test - public void slashesAreReplacedWithUnderscores() { + void slashesAreReplacedWithUnderscores() { assertEquals("test_identifier__", IdentifierSanitizer.sanitize("test/identifier//")); } @Test - public void backslashesAreReplacedWithUnderscores() { + void backslashesAreReplacedWithUnderscores() { assertEquals("test_identifier__", IdentifierSanitizer.sanitize("test\\identifier\\\\")); } diff --git a/src/test/java/org/scenarioo/model/docu/entities/LabelsTest.java b/src/test/java/org/scenarioo/model/docu/entities/LabelsTest.java index 0744c39..d0d6cc2 100644 --- a/src/test/java/org/scenarioo/model/docu/entities/LabelsTest.java +++ b/src/test/java/org/scenarioo/model/docu/entities/LabelsTest.java @@ -1,23 +1,23 @@ package org.scenarioo.model.docu.entities; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.LinkedHashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.scenarioo.api.exception.IllegalCharacterException; -public class LabelsTest { +class LabelsTest { @Test - public void singleLabelsCanBeAddedInAChainedFashion() { + void singleLabelsCanBeAddedInAChainedFashion() { Labels labels = new Labels().addLabel("test-1").addLabel("test-2"); assertEquals(2, labels.getLabels().size()); } @Test - public void aSetOfLabelCanBeSetAtOnce() { + void aSetOfLabelCanBeSetAtOnce() { Labels labels = new Labels(); Set labelsToSet = new LinkedHashSet(); labelsToSet.add("valid"); @@ -29,39 +29,29 @@ public void aSetOfLabelCanBeSetAtOnce() { } @Test - public void ifAnInvalidSingleLabelIsAdded_anExceptionIsThrown() { - try { - Labels labels = new Labels(); - labels.addLabel("test-1").addLabel("test.2"); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Label test.2 contains illegal characters.", e.getMessage()); - } + void ifAnInvalidSingleLabelIsAdded_anExceptionIsThrown() { + Labels labels = new Labels(); + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> labels.addLabel("test-1").addLabel("test.2")); + assertEquals("Label test.2 contains illegal characters.", e.getMessage()); } @Test - public void ifASetOfLabelsContainingInvalidCharactersIsSet_anExceptionIsThrown() { - try { - Labels labels = new Labels(); - Set labelsToSet = new LinkedHashSet(); - labelsToSet.add("valid"); - labelsToSet.add(".invalid"); - labels.setLabels(labelsToSet); - fail(); - } catch (IllegalCharacterException e) { - assertEquals("Label .invalid contains illegal characters.", e.getMessage()); - } + void ifASetOfLabelsContainingInvalidCharactersIsSet_anExceptionIsThrown() { + Labels labels = new Labels(); + Set labelsToSet = new LinkedHashSet(); + labelsToSet.add("valid"); + labelsToSet.add(".invalid"); + IllegalCharacterException e = assertThrows(IllegalCharacterException.class, + () -> labels.setLabels(labelsToSet)); + assertEquals("Label .invalid contains illegal characters.", e.getMessage()); } @Test - public void ifANullSetOfLabelsIsSet_anExceptionIsThrown() { - try { - Labels labels = new Labels(); - labels.setLabels(null); - fail(); - } catch (NullPointerException e) { - assertEquals("Labels must not be null.", e.getMessage()); - } + void ifANullSetOfLabelsIsSet_anExceptionIsThrown() { + Labels labels = new Labels(); + NullPointerException e = assertThrows(NullPointerException.class, () -> labels.setLabels(null)); + assertEquals("Labels must not be null.", e.getMessage()); } }