diff --git a/.github/actions/setup-java/action.yaml b/.github/actions/setup-java/action.yaml new file mode 100644 index 0000000..184fee0 --- /dev/null +++ b/.github/actions/setup-java/action.yaml @@ -0,0 +1,11 @@ +name: "Setup JDK 17" +description: "Setup JDK 17" +runs: + using: "composite" + steps: + - name: Setup JDK 17 + uses: actions/setup-java@v4.1.0 + with: + java-version: '17' + distribution: 'temurin' + cache: 'gradle' diff --git a/artifacts/.gitignore b/artifacts/.gitignore new file mode 100644 index 0000000..f0c4bf3 --- /dev/null +++ b/artifacts/.gitignore @@ -0,0 +1,45 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +.idea +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + + diff --git a/artifacts/README.md b/artifacts/README.md new file mode 100644 index 0000000..549c504 --- /dev/null +++ b/artifacts/README.md @@ -0,0 +1,2 @@ +# dsp-schemas +Tools for defining and generating DSP schemas diff --git a/artifacts/build.gradle.kts b/artifacts/build.gradle.kts new file mode 100644 index 0000000..3f58705 --- /dev/null +++ b/artifacts/build.gradle.kts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +plugins { + `java-library` + checkstyle +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("com.networknt:json-schema-validator:1.5.2") { + exclude("com.fasterxml.jackson.dataformat", "jackson-dataformat-yaml") + } + + testImplementation("org.assertj:assertj-core:3.26.3") + testImplementation("com.apicatalog:titanium-json-ld:1.4.1") + testImplementation("org.glassfish:jakarta.json:2.0.1") + testImplementation("com.fasterxml.jackson.core:jackson-databind:2.18.0") + testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jakarta-jsonp:2.18.0") +} + +testing { + suites { + val test by getting(JvmTestSuite::class) { + useJUnitJupiter("5.8.1") + } + } +} \ No newline at end of file diff --git a/artifacts/config/checkstyle/checkstyle.xml b/artifacts/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..6aea985 --- /dev/null +++ b/artifacts/config/checkstyle/checkstyle.xml @@ -0,0 +1,450 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/artifacts/config/checkstyle/suppressions.xml b/artifacts/config/checkstyle/suppressions.xml new file mode 100644 index 0000000..5a94c92 --- /dev/null +++ b/artifacts/config/checkstyle/suppressions.xml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/artifacts/gradle/wrapper/gradle-wrapper.jar b/artifacts/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/artifacts/gradle/wrapper/gradle-wrapper.jar differ diff --git a/artifacts/gradle/wrapper/gradle-wrapper.properties b/artifacts/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..016a94a --- /dev/null +++ b/artifacts/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Oct 25 08:20:36 CEST 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/artifacts/gradlew b/artifacts/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/artifacts/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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 () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/artifacts/gradlew.bat b/artifacts/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/artifacts/gradlew.bat @@ -0,0 +1,89 @@ +@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 +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@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 + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/artifacts/settings.gradle.kts b/artifacts/settings.gradle.kts new file mode 100644 index 0000000..91b4b62 --- /dev/null +++ b/artifacts/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "artifacts" diff --git a/artifacts/src/main/resources/catalog/catalog-error-schema.json b/artifacts/src/main/resources/catalog/catalog-error-schema.json new file mode 100644 index 0000000..3ab5daf --- /dev/null +++ b/artifacts/src/main/resources/catalog/catalog-error-schema.json @@ -0,0 +1,35 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "CatalogErrorSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/CatalogError" + } + ], + "$id": "https://w3id.org/dspace/2024/1/catalog/catalog-error-schema.json", + "definitions": { + "CatalogError": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "CatalogError" + }, + "code": { + "type": "string" + }, + "reason": { + "type": "array" + } + }, + "required": [ + "@context", + "@type" + ] + } + } +} diff --git a/artifacts/src/main/resources/catalog/catalog-schema.json b/artifacts/src/main/resources/catalog/catalog-schema.json new file mode 100644 index 0000000..7961c55 --- /dev/null +++ b/artifacts/src/main/resources/catalog/catalog-schema.json @@ -0,0 +1,83 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "CatalogSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/RootCatalog" + } + ], + "$id": "https://w3id.org/dspace/2024/1/catalog/catalog-schema.json", + "definitions": { + "RootCatalog": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/Catalog" + } + ], + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "participantId": { + "type": "string" + } + }, + "required": [ + "@context", + "participantId" + ] + }, + "Catalog": { + "type": "object", + "allOf": [ + { + "$ref": "https://w3id.org/dspace/2024/1/catalog/dataset-schema.json#/definitions/AbstractDataset" + }, + { + "properties": { + "@type": { + "type": "string", + "const": "Catalog" + }, + "dataset": { + "type": "array", + "items": { + "$ref": "https://w3id.org/dspace/2024/1/catalog/dataset-schema.json#/definitions/Dataset" + }, + "minItems": 1 + }, + "catalog": { + "type": "array", + "items": { + "$ref": "#/definitions/Catalog" + }, + "minItems": 1 + }, + "service": { + "type": "array", + "items": { + "$ref": "https://w3id.org/dspace/2024/1/catalog/dataset-schema.json#/definitions/DataService" + }, + "minItems": 1 + } + } + } + ], + "required": [ + "@id", + "@type" + ], + "anyOf": [ + { + "not": { + "required": [ + "hasPolicy" + ] + } + } + ] + } + } +} diff --git a/artifacts/src/main/resources/catalog/dataset-request-message-schema.json b/artifacts/src/main/resources/catalog/dataset-request-message-schema.json new file mode 100644 index 0000000..4378ad7 --- /dev/null +++ b/artifacts/src/main/resources/catalog/dataset-request-message-schema.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "DatasetRequestMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/DatasetRequestMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/catalog/dataset-request-message-schema.json", + "definitions": { + "DatasetRequestMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "DatasetRequestMessage" + }, + "dataset": { + "type": "string" + } + }, + "required": [ + "@context", + "@type", + "dataset" + ] + } + } +} diff --git a/artifacts/src/main/resources/catalog/dataset-schema.json b/artifacts/src/main/resources/catalog/dataset-schema.json new file mode 100644 index 0000000..8191540 --- /dev/null +++ b/artifacts/src/main/resources/catalog/dataset-schema.json @@ -0,0 +1,136 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "DatasetSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/Dataset" + } + ], + "$id": "https://w3id.org/dspace/2024/1/catalog/dataset-schema.json", + "definitions": { + "AbstractDataset": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/Resource" + }, + { + "properties": { + "hasPolicy": { + "type": "array", + "items": { + "$ref": "https://w3id.org/dspace/2024/1/negotiation/contract-schema.json#/definitions/Offer" + }, + "minItems": 1 + }, + "distribution": { + "type": "array", + "items": { + "$ref": "#/definitions/Distribution" + }, + "minItems": 1 + } + } + } + ] + }, + "Dataset": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/AbstractDataset" + } + ], + "required": [ + "hasPolicy", + "distribution" + ] + }, + "Resource": { + "type": "object", + "properties": { + "@id": { + "type": "string" + } + }, + "required": [ + "@id" + ] + }, + "Distribution": { + "type": "object", + "properties": { + "hasPolicy": { + "type": "array", + "items": { + "$ref": "https://w3id.org/dspace/2024/1/negotiation/contract-schema.json#/definitions/Offer" + }, + "minItems": 1 + }, + "accessService": { + "oneOf": [ + { + "type": "string" + }, + { + "$ref": "#/definitions/DataService" + } + ] + }, + "format": { + "type": "string" + } + }, + "required": [ + "accessService", + "format" + ] + }, + "DataService": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/Resource" + }, + { + "properties": { + "@id": { + "type": "string" + }, + "@type": { + "type": "string", + "const": "DataService" + }, + "endpointURL": { + "type": "string" + }, + "servesDataset": { + "type": "array", + "items": { + "$ref": "#/definitions/Dataset" + }, + "minItems": 1 + } + }, + "required": [ + "@id", + "@type", + "endpointURL" + ] + } + ] + }, + "Reference": { + "type": "object", + "properties": { + "@id": { + "type": "string" + } + }, + "required": [ + "@id" + ] + } + } +} diff --git a/artifacts/src/main/resources/catalog/example/catalog-error.json b/artifacts/src/main/resources/catalog/example/catalog-error.json new file mode 100644 index 0000000..8d02124 --- /dev/null +++ b/artifacts/src/main/resources/catalog/example/catalog-error.json @@ -0,0 +1,10 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "CatalogError", + "code": "123-A", + "reason": [ + "Catalog not provisioned for this requester." + ] +} \ No newline at end of file diff --git a/artifacts/src/main/resources/catalog/example/catalog.json b/artifacts/src/main/resources/catalog/example/catalog.json new file mode 100644 index 0000000..fad45ec --- /dev/null +++ b/artifacts/src/main/resources/catalog/example/catalog.json @@ -0,0 +1,49 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Catalog", + "participantId": "urn:example:DataProviderA", + "service": [ + { + "@id": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77", + "@type": "DataService", + "endpointURL": "https://provider-a.com/connector" + } + ], + "dataset": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Dataset", + "hasPolicy": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "spatial", + "operator": "eq", + "rightOperand": "http://example.org/EU" + } + ], + "duty": { + "action": "Attribution" + } + } + ] + } + ], + "distribution": [ + { + "@type": "Distribution", + "format": "HttpData-PULL", + "accessService": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77" + } + ] + } + ] +} diff --git a/artifacts/src/main/resources/catalog/example/dataset-request-message.json b/artifacts/src/main/resources/catalog/example/dataset-request-message.json new file mode 100644 index 0000000..6148c9e --- /dev/null +++ b/artifacts/src/main/resources/catalog/example/dataset-request-message.json @@ -0,0 +1,7 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "DatasetRequestMessage", + "dataset": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57" +} diff --git a/artifacts/src/main/resources/catalog/example/dataset.json b/artifacts/src/main/resources/catalog/example/dataset.json new file mode 100644 index 0000000..751d445 --- /dev/null +++ b/artifacts/src/main/resources/catalog/example/dataset.json @@ -0,0 +1,37 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Dataset", + "hasPolicy": [ + { + "@type": "Offer", + "@id": "urn:uuid:2828282:3dd1add8-4d2d-569e-d634-8394a8836a88", + "assigner": "http://example.com/Provider", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "spatial", + "rightOperand": "_:EU", + "operator": "eq" + } + ] + } + ] + } + ], + "distribution": [ + { + "@type": "Distribution", + "format": "HttpData-PULL", + "accessService": { + "@id": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77", + "@type": "DataService", + "endpointURL": "https://provider-a.com/connector" + } + } + ] +} diff --git a/artifacts/src/main/resources/catalog/example/nested-catalog.json b/artifacts/src/main/resources/catalog/example/nested-catalog.json new file mode 100644 index 0000000..8075923 --- /dev/null +++ b/artifacts/src/main/resources/catalog/example/nested-catalog.json @@ -0,0 +1,28 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Catalog", + "participantId": "urn:example:DataProviderA", + "catalog": [ + { + "@id": "02e83f88-f025-4a1c-89f2-8723c98fa92b", + "@type": "Catalog", + "distribution": [ + { + "@type": "Distribution", + "format": "Catalog", + "accessService": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77" + } + ], + "service": [ + { + "@id": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77", + "@type": "DataService", + "endpointURL": "https://provder-a.com/subcatalog" + } + ] + } + ] +} diff --git a/artifacts/src/main/resources/common/context-schema.json b/artifacts/src/main/resources/common/context-schema.json new file mode 100644 index 0000000..af6fcf5 --- /dev/null +++ b/artifacts/src/main/resources/common/context-schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContextSchema", + "type": "array", + "allOf": [ + { + "$ref": "#/definitions/ContextSchema" + } + ], + "$id": "https://w3id.org/dspace/2024/1/common/context-schema.json", + "definitions": { + "ContextSchema": { + "type": "array", + "items": { + "type": "string", + "items": { + "type": "string" + } + }, + "contains": { + "const": "https://w3id.org/dspace/2024/1/context.json" + } + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/context/dspace.jsonld b/artifacts/src/main/resources/context/dspace.jsonld new file mode 100644 index 0000000..5d10d50 --- /dev/null +++ b/artifacts/src/main/resources/context/dspace.jsonld @@ -0,0 +1,441 @@ +{ + "@context": { + "@version": 1.1, + "@protected": true, + "xsd": "http://www.w3.org/2001/XMLSchema#", + "dct": "http://purl.org/dc/terms/", + "dcat": "http://www.w3.org/ns/dcat#", + "odrl": "http://www.w3.org/ns/odrl/2/", + "dspace": "https://w3id.org/dspace/2024/1/", + "DatasetRequestMessage": { + "@id": "dspace:DatasetRequestMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "dataset": "dspace:dataset" + } + }, + "CatalogRequestMessage": { + "@id": "dspace:CatalogRequestMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "filter": { + "@id": "dspace:filter", + "@container": "@set" + } + } + }, + "CatalogError": { + "@id": "dspace:CatalogError", + "@context": { + "@version": 1.1, + "@protected": true, + "code": "dspace:code", + "reason": { + "@id": "dspace:reason", + "@container": "@set" + } + } + }, + "ContractRequestMessage": { + "@id": "dspace:ContractRequestMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "@import": "http://www.w3.org/dspace-odrl/odrl.jsonld", + "@propagate": true, + "callbackAddress": "dspace:callbackAddress", + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "offer": { + "@type": "@id", + "@id": "dspace:offer" + } + } + }, + "ContractOfferMessage": { + "@id": "dspace:ContractOfferMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "@import": "http://www.w3.org/dspace-odrl/odrl.jsonld", + "@propagate": true, + "callbackAddress": "dspace:callbackAddress", + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "offer": { + "@type": "@id", + "@id": "dspace:offer" + } + } + }, + "ContractAgreementMessage": { + "@id": "dspace:ContractAgreementMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "@import": "http://www.w3.org/dspace-odrl/odrl.jsonld", + "@propagate": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "agreement": { + "@id": "dspace:agreement", + "@type": "@id" + }, + "callbackAddress": "dspace:callbackAddress", + "timestamp": "dspace:timestamp" + } + }, + "ContractAgreementVerificationMessage": { + "@id": "dspace:ContractAgreementVerificationMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + } + } + }, + "ContractNegotiationEventMessage": { + "@id": "dspace:ContractNegotiationEventMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "eventType": { + "@type": "@vocab", + "@id": "dspace:eventType" + } + } + }, + "ContractNegotiationTerminationMessage": { + "@id": "dspace:ContractNegotiationTerminationMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "code": "dspace:code", + "reason": { + "@id": "dspace:reason", + "@container": "@set" + }, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + } + } + }, + "ContractNegotiation": { + "@id": "dspace:ContractNegotiation", + "@context": { + "@version": 1.1, + "@protected": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "state": { + "@type": "@vocab", + "@id": "dspace:state" + } + } + }, + "ContractNegotiationError": { + "@id": "dspace:ContractNegotiationError", + "@context": { + "@version": 1.1, + "@protected": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "code": "dspace:code", + "reason": { + "@id": "dspace:reason", + "@container": "@set" + } + } + }, + "TransferRequestMessage": { + "@id": "dspace:TransferRequestMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "callbackAddress": "dspace:callbackAddress", + "dataAddress": "dspace:dataAddress", + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "format": { + "@type": "@vocab", + "@id": "dct:format" + }, + "agreementId": { + "@type": "@id", + "@id": "dspace:agreementId" + } + } + }, + "TransferStartMessage": { + "@id": "dspace:TransferStartMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "dataAddress": "dspace:dataAddress" + } + }, + "TransferCompletionMessage": { + "@id": "dspace:TransferCompletionMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + } + } + }, + "TransferTerminationMessage": { + "@id": "dspace:TransferTerminationMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "code": "dspace:code", + "reason": { + "@id": "dspace:reason", + "@container": "@set" + }, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + } + } + }, + "TransferSuspensionMessage": { + "@id": "dspace:TransferSuspensionMessage", + "@context": { + "@version": 1.1, + "@protected": true, + "code": "dspace:code", + "reason": { + "@id": "dspace:reason", + "@container": "@set" + }, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + } + } + }, + "TransferError": { + "@id": "dspace:TransferError", + "@context": { + "@version": 1.1, + "@protected": true, + "code": "dspace:code", + "consumerPid": "dspace:consumerPid", + "providerPid": "dspace:providerPid", + "reason": { + "@id": "dspace:reason", + "@container": "@set" + } + } + }, + "DataAddress": { + "@id": "dspace:DataAddress", + "@context": { + "@version": 1.1, + "@protected": true, + "endpointType": { + "@type": "@vocab", + "@id": "dspace:endpointType" + }, + "endpointProperties": { + "@id": "dspace:endpointProperties", + "@container": "@set" + }, + "endpoint": "dspace:endpoint" + } + }, + "EndpointProperty": { + "@id": "dspace:EndpointProperty", + "@context": { + "@version": 1.1, + "@protected": true, + "name": "dspace:name", + "value": "dspace:value" + } + }, + "TransferProcess": { + "@id": "dspace:TransferProcess", + "@context": { + "@version": 1.1, + "@protected": true, + "providerPid": { + "@type": "@id", + "@id": "dspace:providerPid" + }, + "consumerPid": { + "@type": "@id", + "@id": "dspace:consumerPid" + }, + "state": { + "@type": "@vocab", + "@id": "dspace:state" + } + } + }, + "VersionsError": { + "@id": "dspace:VersionsError", + "@context": { + "@version": 1.1, + "@protected": true, + "code": "dspace:code", + "reason": { + "@id": "dspace:reason", + "@container": "@set" + } + } + }, + "Catalog": { + "@id": "dcat:Catalog", + "@context": { + "@version": 1.1, + "@protected": true, + "service": { + "@id": "dcat:service", + "@container": "@set" + }, + "participantId": { + "@type": "@id", + "@id": "dspace:participantId" + }, + "catalog": { + "@id": "dcat:catalog", + "@container": "@set" + }, + "dataset": { + "@id": "dcat:dataset", + "@container": "@set" + }, + "distribution": { + "@id": "dcat:distribution", + "@container": "@set" + } + } + }, + "Dataset": { + "@id": "dcat:Dataset", + "@context": { + "@version": 1.1, + "@protected": true, + "@import": "http://www.w3.org/dspace-odrl/odrl.jsonld", + "@propagate": true, + "distribution": { + "@id": "dcat:distribution", + "@container": "@set" + }, + "hasPolicy": { + "@id": "odrl:hasPolicy", + "@container": "@set" + } + } + }, + "DataService": { + "@id": "dcat:DataService", + "@context": { + "@version": 1.1, + "@protected": true, + "endpointDescription": "dcat:endpointDescription", + "endpointURL": "dcat:endpointURL" + } + }, + "Distribution": { + "@id": "dcat:Distribution", + "@context": { + "@version": 1.1, + "@protected": true, + "format": { + "@type": "@vocab", + "@id": "dct:format" + }, + "accessService": { + "@id": "dcat:accessService" + } + } + }, + "ACCEPTED": "dspace:ACCEPTED", + "FINALIZED": "dspace:FINALIZED", + "REQUESTED": "dspace:REQUESTED", + "STARTED": "dspace:STARTED", + "COMPLETED": "dspace:COMPLETED", + "SUSPENDED": "dspace:SUSPENDED", + "TERMINATED": "dspace:TERMINATED", + "OFFERED": "dspace:OFFERED", + "AGREED": "dspace:AGREED", + "VERIFIED": "dspace:VERIFIED" + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/context/odrl.jsonld b/artifacts/src/main/resources/context/odrl.jsonld new file mode 100644 index 0000000..60e8590 --- /dev/null +++ b/artifacts/src/main/resources/context/odrl.jsonld @@ -0,0 +1,95 @@ +{ + "@context": { + "odrl": "http://www.w3.org/ns/odrl/2/", + "Policy": "odrl:Policy", + "Rule": "odrl:Rule", + "profile": { + "@type": "@id", + "@id": "odrl:profile" + }, + "prohibit": "odrl:prohibit", + "Agreement": "odrl:Agreement", + "Assertion": "odrl:Assertion", + "Offer": "odrl:Offer", + "Set": "odrl:Set", + "Asset": "odrl:Asset", + "hasPolicy": { + "@type": "@id", + "@id": "odrl:hasPolicy" + }, + "target": { + "@type": "@id", + "@id": "odrl:target" + }, + "assignee": { + "@type": "@id", + "@id": "odrl:assignee" + }, + "assigner": { + "@type": "@id", + "@id": "odrl:assigner" + }, + "Action": "odrl:Action", + "action": { + "@type": "@vocab", + "@id": "odrl:action" + }, + "Permission": "odrl:Permission", + "permission": { + "@type": "@id", + "@id": "odrl:permission", + "@container": "@set" + }, + "Prohibition": "odrl:Prohibition", + "prohibition": { + "@type": "@id", + "@id": "odrl:prohibition", + "@container": "@set" + }, + "obligation": { + "@type": "@id", + "@id": "odrl:obligation", + "@container": "@set" + }, + "use": "odrl:use", + "Duty": "odrl:Duty", + "duty": { + "@type": "@id", + "@id": "odrl:duty" + }, + "Constraint": "odrl:Constraint", + "constraint": { + "@type": "@id", + "@id": "odrl:constraint", + "@container": "@set" + }, + "Operator": "odrl:Operator", + "operator": { + "@type": "@vocab", + "@id": "odrl:operator" + }, + "RightOperand": "odrl:RightOperand", + "rightOperand": "odrl:rightOperand", + "LeftOperand": "odrl:LeftOperand", + "leftOperand": { + "@type": "@vocab", + "@id": "odrl:leftOperand" + }, + "eq": "odrl:eq", + "gt": "odrl:gt", + "gteq": "odrl:gteq", + "lt": "odrl:lt", + "lteq": "odrl:lteq", + "neq": "odrl:neq", + "isA": "odrl:isA", + "hasPart": "odrl:hasPart", + "isPartOf": "odrl:isPartOf", + "isAllOf": "odrl:isAllOf", + "isAnyOf": "odrl:isAnyOf", + "isNoneOf": "odrl:isNoneOf", + "or": "odrl:or", + "xone": "odrl:xone", + "and": "odrl:and", + "andSequence": "odrl:andSequence" + } +} diff --git a/artifacts/src/main/resources/negotiation/contract-agreement-message-schema.json b/artifacts/src/main/resources/negotiation/contract-agreement-message-schema.json new file mode 100644 index 0000000..e8c36aa --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-agreement-message-schema.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractAgreementMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractAgreementMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-agreement-message-schema.json", + "definitions": { + "ContractAgreementMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractAgreementMessage" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "agreement": { + "$ref": "https://w3id.org/dspace/2024/1/negotiation/contract-schema.json#/definitions/Agreement" + }, + "callbackAddress": { + "type": "string" + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid", + "agreement", + "callbackAddress" + ] + } + } +} diff --git a/artifacts/src/main/resources/negotiation/contract-agreement-verification-message-schema.json b/artifacts/src/main/resources/negotiation/contract-agreement-verification-message-schema.json new file mode 100644 index 0000000..4c4671e --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-agreement-verification-message-schema.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractAgreementVerificationMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractAgreementVerificationMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-agreement-verification-message-schema.json", + "definitions": { + "ContractAgreementVerificationMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractAgreementVerificationMessage" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/negotiation/contract-negotiation-error-schema.json b/artifacts/src/main/resources/negotiation/contract-negotiation-error-schema.json new file mode 100644 index 0000000..f4f9ad9 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-negotiation-error-schema.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractNegotiationErrorSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractNegotiationError" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-negotiation-error-schema.json", + "definitions": { + "ContractNegotiationError": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractNegotiationError" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "code": { + "type": "string" + }, + "reason": { + "type": "array", + "minItems": 1, + "items": {} + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/negotiation/contract-negotiation-event-message-schema.json b/artifacts/src/main/resources/negotiation/contract-negotiation-event-message-schema.json new file mode 100644 index 0000000..b92a5e7 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-negotiation-event-message-schema.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractNegotiationEventMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractNegotiationEventMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-negotiation-event-message-schema.json", + "definitions": { + "ContractNegotiationEventMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractNegotiationEventMessage" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "eventType": { + "type": "string", + "enum": [ + "ACCEPTED", + "FINALIZED" + ] + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid", + "eventType" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/negotiation/contract-negotiation-schema.json b/artifacts/src/main/resources/negotiation/contract-negotiation-schema.json new file mode 100644 index 0000000..6ae4c04 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-negotiation-schema.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractNegotiationSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractNegotiation" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-negotiation-schema.json", + "definitions": { + "ContractNegotiation": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractNegotiation" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "state": { + "type": "string", + "enum": [ + "REQUESTED", + "OFFERED", + "ACCEPTED", + "AGREED", + "VERIFIED", + "FINALIZED", + "TERMINATED" + ] + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid", + "state" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/negotiation/contract-negotiation-termination-message-schema.json b/artifacts/src/main/resources/negotiation/contract-negotiation-termination-message-schema.json new file mode 100644 index 0000000..39c808b --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-negotiation-termination-message-schema.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractNegotiationTerminationMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractNegotiationTerminationMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-negotiation-termination-message-schema.json", + "definitions": { + "ContractNegotiationTerminationMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractNegotiationTerminationMessage" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "code": { + "type": "string" + }, + "reason": { + "type": "array", + "minItems": 1, + "items": {} + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/negotiation/contract-offer-message-schema.json b/artifacts/src/main/resources/negotiation/contract-offer-message-schema.json new file mode 100644 index 0000000..aa14e91 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-offer-message-schema.json @@ -0,0 +1,62 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractOfferMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractOfferMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-offer-message-schema.json", + "definitions": { + "ContractOfferMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractOfferMessage" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "offer": { + "allOf": [ + { + "$ref": "https://w3id.org/dspace/2024/1/negotiation/contract-schema.json#/definitions/MessageOffer" + }, + { + "properties": { + "@id": { + "type": "string" + }, + "target": { + "type": "string" + } + }, + "required": [ + "@id", + "target" + ] + } + ] + }, + "callbackAddress": { + "type": "string" + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "offer", + "callbackAddress" + ] + } + } +} diff --git a/artifacts/src/main/resources/negotiation/contract-request-message-schema.json b/artifacts/src/main/resources/negotiation/contract-request-message-schema.json new file mode 100644 index 0000000..876357a --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-request-message-schema.json @@ -0,0 +1,72 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "ContractRequestMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ContractRequestMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-request-message-schema.json", + "definitions": { + "ContractRequestMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "ContractRequestMessage" + }, + "consumerPid": { + "type": "string" + }, + "providerPid": { + "type": "string" + }, + "offer": { + "oneOf": [ + { + "$ref": "https://w3id.org/dspace/2024/1/negotiation/contract-schema.json#/definitions/MessageOffer" + }, + { + "properties": { + "@id": { + "type": "string" + } + }, + "required": [ + "@id" + ], + "not": { + "anyOf": [ + { + "required": [ + "permission" + ] + }, + { + "required": [ + "prohibition" + ] + } + ] + } + } + ] + }, + "callbackAddress": { + "type": "string" + } + }, + "required": [ + "@context", + "@type", + "consumerPid", + "offer", + "callbackAddress" + ] + } + } +} diff --git a/artifacts/src/main/resources/negotiation/contract-schema.json b/artifacts/src/main/resources/negotiation/contract-schema.json new file mode 100644 index 0000000..e98d33e --- /dev/null +++ b/artifacts/src/main/resources/negotiation/contract-schema.json @@ -0,0 +1,328 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "PolicySchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/Policy" + } + ], + "$id": "https://w3id.org/dspace/2024/1/negotiation/contract-schema.json", + "definitions": { + "Policy": { + "oneOf": [ + { + "$ref": "#/definitions/MessageOffer" + }, + { + "$ref": "#/definitions/Offer" + }, + { + "$ref": "#/definitions/Agreement" + } + ] + }, + "PolicyClass": { + "type": "object", + "properties": { + "@id": { + "type": "string" + }, + "profile": { + "oneOf": [ + { + "type": "array", + "items": "string" + }, + { + "type": "string" + } + ] + }, + "permission": { + "type": "array", + "items": { + "$ref": "#/definitions/Permission" + }, + "minItems": 1 + }, + "obligation": { + "type": "array", + "items": { + "$ref": "#/definitions/Duty" + }, + "minItems": 1 + } + }, + "required": [ + "@id" + ] + }, + "MessageOffer": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/PolicyClass" + }, + { + "properties": { + "@type": { + "type": "string", + "const": "Offer" + } + } + }, + { + "anyOf": [ + { + "required": [ + "permission" + ] + }, + { + "required": [ + "prohibition" + ] + } + ] + } + ], + "required": [ + "@type" + ] + }, + "Offer": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/MessageOffer" + } + ], + "not": { + "required": [ + "target" + ] + } + }, + "Agreement": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/PolicyClass" + }, + { + "properties": { + "@type": { + "type": "string", + "const": "Agreement" + }, + "target": { + "type": "string" + }, + "assigner": { + "type": "string" + }, + "assignee": { + "type": "string" + }, + "timestamp": { + "type": "string", + "pattern": "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?" + } + } + }, + { + "anyOf": [ + { + "required": [ + "permission" + ] + }, + { + "required": [ + "prohibition" + ] + } + ] + } + ], + "required": [ + "@type", + "target", + "assignee", + "assigner" + ] + }, + "Permission": { + "type": "object", + "properties": { + "action": { + "$ref": "#/definitions/Action" + }, + "constraint": { + "type": "array", + "items": { + "$ref": "#/definitions/Constraint" + } + }, + "duty": { + "$ref": "#/definitions/Duty" + } + }, + "required": [ + "action" + ] + }, + "Duty": { + "type": "object", + "allOf": [ + { + "properties": { + "action": { + "$ref": "#/definitions/Action" + }, + "constraint": { + "type": "array", + "items": { + "$ref": "#/definitions/Constraint" + } + } + }, + "required": [ + "action" + ] + } + ] + }, + "Action": { + "type": "string" + }, + "Constraint": { + "type": "object", + "oneOf": [ + { + "$ref": "#/definitions/LogicalConstraint" + }, + { + "$ref": "#/definitions/AtomicConstraint" + } + ] + }, + "LogicalConstraint": { + "type": "object", + "properties": { + "and": { + "type": "array", + "items": "object" + }, + "andSequence": { + "type": "array", + "items": "object" + }, + "or": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/LogicalConstraint" + }, + { + "$ref": "#/definitions/AtomicConstraint" + } + ] + } + }, + "xone": { + "type": "array", + "items": "object" + } + }, + "oneOf": [ + { + "required": [ + "and" + ] + }, + { + "required": [ + "andSequence" + ] + }, + { + "required": [ + "or" + ] + }, + { + "required": [ + "xone" + ] + } + ] + }, + "AtomicConstraint": { + "type": "object", + "properties": { + "rightOperand": { + "$ref": "#/definitions/RightOperand" + }, + "leftOperand": { + "$ref": "#/definitions/LeftOperand" + }, + "operator": { + "$ref": "#/definitions/Operator" + } + }, + "required": [ + "rightOperand", + "operator", + "leftOperand" + ] + }, + "Operator": { + "type": "string", + "enum": [ + "eq", + "gt", + "gteq", + "lteq", + "hasPart", + "isA", + "isAllOf", + "isAnyOf", + "isNoneOf", + "isPartOf", + "lt", + "term-lteq", + "neq" + ] + }, + "RightOperand": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object" + }, + { + "type": "array" + } + ] + }, + "LeftOperand": { + "type": "string" + }, + "Reference": { + "type": "object", + "properties": { + "@id": { + "type": "string" + } + }, + "required": [ + "@id" + ] + } + } +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-agreement-message-full.json b/artifacts/src/main/resources/negotiation/example/contract-agreement-message-full.json new file mode 100644 index 0000000..f4d8132 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-agreement-message-full.json @@ -0,0 +1,154 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreement": { + "@id": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "@type": "Agreement", + "target": "urn:uuid:3dd1add4-4d2d-569e-d634-8394a8836d23", + "profile": "https://test.com/profile", + "timestamp": "2023-01-01T01:00:00Z", + "assigner": "http://example.com/Provider", + "assignee": "http://example.com/Consumer", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "dateTime", + "operator": "lteq", + "rightOperand": "2023-12-31T06:00Z" + } + ] + }, + { + "action": "use", + "constraint": [ + { + "and": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + } + ] + }, + { + "action": "use", + "constraint": [ + { + "or": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + } + ] + }, + { + "action": "use", + "constraint": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + } + ], + "duty": { + "action": "report", + "constraint": [ + { + "leftOperand": "event", + "operator": "gt", + "rightOperand": "use" + } + ] + } + }, + { + "action": "use", + "constraint": [ + { + "andSequence": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + } + ] + }, + { + "action": "use", + "constraint": [ + { + "xone": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + } + ] + }, + { + "action": "use", + "constraint": [ + { + "or": [ + { + "and": [ + { + "leftOperand": "constraint1", + "operator": "eq", + "rightOperand": "value1" + }, + { + "leftOperand": "constraint2", + "operator": "eq", + "rightOperand": "value2" + } + ] + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + } + ] + } + ] + }, + "callbackAddress": "https://example.com/callback" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-agreement-message.json b/artifacts/src/main/resources/negotiation/example/contract-agreement-message.json new file mode 100644 index 0000000..6fd95ab --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-agreement-message.json @@ -0,0 +1,29 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreement": { + "@id": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "@type": "Agreement", + "target": "urn:uuid:3dd1add4-4d2d-569e-d634-8394a8836d23", + "timestamp": "2023-01-01T01:00:00Z", + "assigner": "http://example.com/Provider", + "assignee": "http://example.com/Consumer", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "dateTime", + "operator": "lteq", + "rightOperand": "2023-12-31T06:00Z" + } + ] + } + ] + }, + "callbackAddress": "https://example.com/callback" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-agreement-verification-message.json b/artifacts/src/main/resources/negotiation/example/contract-agreement-verification-message.json new file mode 100644 index 0000000..abdedef --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-agreement-verification-message.json @@ -0,0 +1,8 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementVerificationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-negotiation-error.json b/artifacts/src/main/resources/negotiation/example/contract-negotiation-error.json new file mode 100644 index 0000000..1b2e53e --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-negotiation-error.json @@ -0,0 +1,12 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "code": "99", + "reason": [ + "Catalog not provisioned for this requester." + ] +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-negotiation-event-message.json b/artifacts/src/main/resources/negotiation/example/contract-negotiation-event-message.json new file mode 100644 index 0000000..55bc975 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-negotiation-event-message.json @@ -0,0 +1,9 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationEventMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "eventType": "ACCEPTED" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-negotiation-termination-message.json b/artifacts/src/main/resources/negotiation/example/contract-negotiation-termination-message.json new file mode 100644 index 0000000..199d885 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-negotiation-termination-message.json @@ -0,0 +1,12 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationTerminationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "code": "99", + "reason": [ + "License model does not fit." + ] +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-negotiation.json b/artifacts/src/main/resources/negotiation/example/contract-negotiation.json new file mode 100644 index 0000000..a5a03df --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-negotiation.json @@ -0,0 +1,9 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiation", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-offer-message.json b/artifacts/src/main/resources/negotiation/example/contract-offer-message.json new file mode 100644 index 0000000..d83b866 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-offer-message.json @@ -0,0 +1,26 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractOfferMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@type": "Offer", + "@id": "urn:uuid:6bcea82e-c509-443d-ba8c-8eef25984c07", + "target": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "dateTime", + "operator": "lteq", + "rightOperand": "2023-12-31T06:00Z" + } + ] + } + ] + }, + "callbackAddress": "https://example.com/callback" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-offer-message_initial.json b/artifacts/src/main/resources/negotiation/example/contract-offer-message_initial.json new file mode 100644 index 0000000..e67d08b --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-offer-message_initial.json @@ -0,0 +1,19 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractOfferMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "offer": { + "@type": "Offer", + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a518", + "assigner": "urn:tsdshhs636378", + "target": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "permission": [ + { + "action": "use" + } + ] + }, + "callbackAddress": "https://example.com/callback" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-request-message.json b/artifacts/src/main/resources/negotiation/example/contract-request-message.json new file mode 100644 index 0000000..e34481b --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-request-message.json @@ -0,0 +1,26 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@type": "Offer", + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a815", + "target": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "dateTime", + "operator": "lteq", + "rightOperand": "2023-12-31T06:00Z" + } + ] + } + ] + }, + "callbackAddress": "https://example.com/callback" +} diff --git a/artifacts/src/main/resources/negotiation/example/contract-request-message_initial.json b/artifacts/src/main/resources/negotiation/example/contract-request-message_initial.json new file mode 100644 index 0000000..a4c17d4 --- /dev/null +++ b/artifacts/src/main/resources/negotiation/example/contract-request-message_initial.json @@ -0,0 +1,18 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@type": "Offer", + "@id": "urn:uuid:2828282:3dd1add8-4d2d-569e-d634-8394a8836a89", + "target": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "permission": [ + { + "action": "use" + } + ] + }, + "callbackAddress": "https://example.com/callback" +} diff --git a/artifacts/src/main/resources/transfer/data-address-schema.json b/artifacts/src/main/resources/transfer/data-address-schema.json new file mode 100644 index 0000000..ad59dee --- /dev/null +++ b/artifacts/src/main/resources/transfer/data-address-schema.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/DataAddress" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-schema.json", + "definitions": { + "DataAddress": { + "type": "object", + "properties": { + "@type": { + "type": "string", + "const": "DataAddress" + }, + "endpointType": { + "type": "string" + }, + "endpoint": { + "type": "string" + }, + "endpointProperties": { + "type": "array", + "items": { + "type": "object", + "properties": { + "@type": { + "type": "string", + "const": "EndpointProperty" + }, + "name": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "required": [ + "@type", + "name", + "value" + ] + }, + "minItems": 1 + } + }, + "required": [ + "@type", + "endpointType", + "endpoint" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/example/transfer-completion-message.json b/artifacts/src/main/resources/transfer/example/transfer-completion-message.json new file mode 100644 index 0000000..574a273 --- /dev/null +++ b/artifacts/src/main/resources/transfer/example/transfer-completion-message.json @@ -0,0 +1,8 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferCompletionMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" +} diff --git a/artifacts/src/main/resources/transfer/example/transfer-error.json b/artifacts/src/main/resources/transfer/example/transfer-error.json new file mode 100644 index 0000000..ee4dda2 --- /dev/null +++ b/artifacts/src/main/resources/transfer/example/transfer-error.json @@ -0,0 +1,12 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "code": "99", + "reason": [ + "Internal error" + ] +} diff --git a/artifacts/src/main/resources/transfer/example/transfer-process.json b/artifacts/src/main/resources/transfer/example/transfer-process.json new file mode 100644 index 0000000..4a1fe00 --- /dev/null +++ b/artifacts/src/main/resources/transfer/example/transfer-process.json @@ -0,0 +1,9 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferProcess", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/example/transfer-request-message.json b/artifacts/src/main/resources/transfer/example/transfer-request-message.json new file mode 100644 index 0000000..8c8e864 --- /dev/null +++ b/artifacts/src/main/resources/transfer/example/transfer-request-message.json @@ -0,0 +1,27 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "dataAddress": { + "@type": "DataAddress", + "endpointType": "https://w3id.org/idsa/v4.1/HTTP", + "endpoint": "http://example.com", + "endpointProperties": [ + { + "@type": "EndpointProperty", + "name": "authorization", + "value": "TOKEN-ABCDEFG" + }, + { + "@type": "EndpointProperty", + "name": "authType", + "value": "bearer" + } + ] + }, + "callbackAddress": "https://example.com/callback" +} diff --git a/artifacts/src/main/resources/transfer/example/transfer-start-message.json b/artifacts/src/main/resources/transfer/example/transfer-start-message.json new file mode 100644 index 0000000..959c904 --- /dev/null +++ b/artifacts/src/main/resources/transfer/example/transfer-start-message.json @@ -0,0 +1,25 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferStartMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "dataAddress": { + "@type": "DataAddress", + "endpointType": "https://w3id.org/idsa/v4.1/HTTP", + "endpoint": "http://example.com", + "endpointProperties": [ + { + "@type": "EndpointProperty", + "name": "authorization", + "value": "TOKEN-ABCDEFG" + }, + { + "@type": "EndpointProperty", + "name": "authType", + "value": "bearer" + } + ] + } +} diff --git a/artifacts/src/main/resources/transfer/example/transfer-suspension-message.json b/artifacts/src/main/resources/transfer/example/transfer-suspension-message.json new file mode 100644 index 0000000..b5c1930 --- /dev/null +++ b/artifacts/src/main/resources/transfer/example/transfer-suspension-message.json @@ -0,0 +1,11 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json"], + "@type": "TransferSuspensionMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "code": "99", + "reason": [ + "Policy violation" + ] +} diff --git a/artifacts/src/main/resources/transfer/example/transfer-termination-message.json b/artifacts/src/main/resources/transfer/example/transfer-termination-message.json new file mode 100644 index 0000000..66a59e3 --- /dev/null +++ b/artifacts/src/main/resources/transfer/example/transfer-termination-message.json @@ -0,0 +1,12 @@ +{ + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferTerminationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "code": "99", + "reason": [ + "Policy violation" + ] +} diff --git a/artifacts/src/main/resources/transfer/transfer-completion-message-schema.json b/artifacts/src/main/resources/transfer/transfer-completion-message-schema.json new file mode 100644 index 0000000..9fbc2fc --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-completion-message-schema.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferCompletionMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/TransferCompletionMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-completion-message-schema.json", + "definitions": { + "TransferCompletionMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "TransferCompletionMessage" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/transfer-error-schema.json b/artifacts/src/main/resources/transfer/transfer-error-schema.json new file mode 100644 index 0000000..ae44c10 --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-error-schema.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferErrorSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/TransferError" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-error-schema.json", + "definitions": { + "TransferError": { + "allOf": [ + { + "$ref": "https://w3id.org/dspace/2024/1/transfer/transfer-schema.json#definitions/AbstractTransferCodeMessage" + }, + { + "properties": { + "@type": { + "type": "string", + "const": "TransferError" + } + }, + "required": [ + "@type" + ] + } + ], + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/transfer-process-schema.json b/artifacts/src/main/resources/transfer/transfer-process-schema.json new file mode 100644 index 0000000..f50597b --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-process-schema.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferProcessSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/TransferProcess" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-process-schema.json", + "definitions": { + "TransferProcess": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "TransferProcess" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "state": { + "type": "string", + "enum": [ + "REQUESTED", + "STARTED", + "TERMINATED", + "COMPLETED", + "SUSPENDED" + ] + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid", + "state" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/transfer-request-message-schema.json b/artifacts/src/main/resources/transfer/transfer-request-message-schema.json new file mode 100644 index 0000000..56f15c9 --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-request-message-schema.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferRequestMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/TransferRequestMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-request-message-schema.json", + "definitions": { + "TransferRequestMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "TransferRequestMessage" + }, + "agreementId": { + "type": "string" + }, + "format": { + "type": "string" + }, + "dataAddress": { + "$ref": "https://w3id.org/dspace/2024/1/transfer/data-address-schema.json" + }, + "callbackAddress": { + "type": "string" + }, + "consumerPid": { + "type": "string" + } + }, + "required": [ + "@context", + "@type", + "agreementId", + "format", + "callbackAddress", + "consumerPid" + ] + } + } +} diff --git a/artifacts/src/main/resources/transfer/transfer-schema.json b/artifacts/src/main/resources/transfer/transfer-schema.json new file mode 100644 index 0000000..ede1229 --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-schema.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/AbstractTransferCodeMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-schema.json", + "definitions": { + "AbstractTransferCodeMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "code": { + "type": "string" + }, + "reason": { + "type": "array", + "minItems": 1, + "items": { + } + } + }, + "required": [ + "@context", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/transfer-start-message-schema.json b/artifacts/src/main/resources/transfer/transfer-start-message-schema.json new file mode 100644 index 0000000..73efc38 --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-start-message-schema.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferStartMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/TransferStartMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-start-message-schema.json", + "definitions": { + "TransferStartMessage": { + "type": "object", + "properties": { + "@context": { + "$ref": "https://w3id.org/dspace/2024/1/common/context-schema.json" + }, + "@type": { + "type": "string", + "const": "TransferStartMessage" + }, + "providerPid": { + "type": "string" + }, + "consumerPid": { + "type": "string" + }, + "dataAddress": { + "$ref": "https://w3id.org/dspace/2024/1/transfer/data-address-schema.json" + } + }, + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/transfer-suspension-message-schema.json b/artifacts/src/main/resources/transfer/transfer-suspension-message-schema.json new file mode 100644 index 0000000..99452f4 --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-suspension-message-schema.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferSuspensionMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/TransferSuspensionMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-suspension-message-schema.json", + "definitions": { + "TransferSuspensionMessage": { + "allOf": [ + { + "$ref": "https://w3id.org/dspace/2024/1/transfer/transfer-schema.json#definitions/AbstractTransferCodeMessage" + }, + { + "properties": { + "@type": { + "type": "string", + "const": "TransferSuspensionMessage" + } + }, + "required": [ + "@type" + ] + } + ], + "required": [ + "@context", + "@type", + "providerPid", + "consumerPid" + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/main/resources/transfer/transfer-termination-message-schema.json b/artifacts/src/main/resources/transfer/transfer-termination-message-schema.json new file mode 100644 index 0000000..d36fcab --- /dev/null +++ b/artifacts/src/main/resources/transfer/transfer-termination-message-schema.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "TransferTerminationMessageSchema", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/TransferTerminationMessage" + } + ], + "$id": "https://w3id.org/dspace/2024/1/transfer/transfer-termination-message-schema.json", + "definitions": { + "TransferTerminationMessage": { + "allOf": [ + { + "$ref": "https://w3id.org/dspace/2024/1/transfer/transfer-schema.json#definitions/AbstractTransferCodeMessage" + }, + { + "properties": { + "@type": { + "type": "string", + "const": "TransferTerminationMessage" + } + }, + "required": [ + "@type" + ] + } + ] + } + } +} \ No newline at end of file diff --git a/artifacts/src/test/java/org/eclipse/dsp/DspConstants.java b/artifacts/src/test/java/org/eclipse/dsp/DspConstants.java new file mode 100644 index 0000000..d64df76 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/DspConstants.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp; + +/** + * Defines constants for schema validation. + */ +public interface DspConstants { + + String DSP_CONTEXT = "https://w3id.org/dspace/2024/1/context.json"; + String DSP_PREFIX = "https://w3id.org/dspace/2024/1/"; + + String ODRL_CONTEXT = "http://www.w3.org/dspace-odrl/odrl.jsonld"; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/context/catalog/CatalogContextTest.java b/artifacts/src/test/java/org/eclipse/dsp/context/catalog/CatalogContextTest.java new file mode 100644 index 0000000..e3aab4f --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/context/catalog/CatalogContextTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.context.catalog; + +import org.eclipse.dsp.context.fixtures.AbstractJsonLdTest; +import org.junit.jupiter.api.Test; + +public class CatalogContextTest extends AbstractJsonLdTest { + + @Test + void verifyCatalogError() { + verifyRoundTrip("/catalog/example/catalog-error.json", + "/catalog/catalog-error-schema.json"); + } + + @Test + void verifyCatalog() { + verifyRoundTrip("/catalog/example/catalog.json", + "/catalog/catalog-schema.json"); + } + + @Test + void verifyDatasetRequestMessage() { + verifyRoundTrip("/catalog/example/dataset-request-message.json", + "/catalog/dataset-request-message-schema.json"); + } + + @Test + void verifyDataset() { + verifyRoundTrip("/catalog/example/dataset.json", + "/catalog/dataset-schema.json"); + } + + @Test + void verifyNestedCatalog() { + verifyRoundTrip("/catalog/example/nested-catalog.json", + "/catalog/catalog-schema.json"); + } +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/context/fixtures/AbstractJsonLdTest.java b/artifacts/src/test/java/org/eclipse/dsp/context/fixtures/AbstractJsonLdTest.java new file mode 100644 index 0000000..ee55589 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/context/fixtures/AbstractJsonLdTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.context.fixtures; + +import com.apicatalog.jsonld.JsonLdError; +import com.apicatalog.jsonld.JsonLdOptions; +import com.apicatalog.jsonld.document.Document; +import com.apicatalog.jsonld.document.JsonDocument; +import com.apicatalog.jsonld.loader.DocumentLoader; +import com.apicatalog.jsonld.loader.DocumentLoaderOptions; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsonp.JSONPModule; +import com.networknt.schema.JsonSchemaFactory; +import com.networknt.schema.SchemaLocation; +import jakarta.json.JsonObject; +import jakarta.json.JsonStructure; +import org.junit.jupiter.api.BeforeEach; + +import java.io.IOException; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import static com.apicatalog.jsonld.JsonLd.compact; +import static com.apicatalog.jsonld.JsonLd.expand; +import static com.networknt.schema.SpecVersion.VersionFlag.V202012; +import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.dsp.DspConstants.DSP_CONTEXT; +import static org.eclipse.dsp.DspConstants.DSP_PREFIX; +import static org.eclipse.dsp.DspConstants.ODRL_CONTEXT; + +/** + * Base class for Json-Ld expansion and compaction tests. + */ +public abstract class AbstractJsonLdTest { + protected ObjectMapper mapper; + protected JsonStructure compactionContext; + protected JsonLdOptions options; + + private static final String CLASSPATH_SCHEMA = "classpath:/"; + private static final String CONTEXT_REFERENCE = format("{\"@context\": [\"%s\"]}", DSP_CONTEXT); + + protected void verifyRoundTrip(String jsonFile, String schemaFile) { + try { + var stream = getClass().getResourceAsStream(jsonFile); + var message = mapper.readValue(stream, JsonObject.class); + var expanded = expand(JsonDocument.of(message)).options(options).get(); + var compacted = compact(JsonDocument.of(expanded), JsonDocument.of(compactionContext)).options(options).get(); + + var schemaFactory = JsonSchemaFactory.getInstance(V202012, builder -> + builder.schemaMappers(schemaMappers -> schemaMappers.mapPrefix(DSP_PREFIX, CLASSPATH_SCHEMA)) + ); + + var schema = schemaFactory.getSchema(SchemaLocation.of(DSP_PREFIX + schemaFile)); + var result = schema.validate(mapper.convertValue(compacted, JsonNode.class)); + assertThat(result.isEmpty()).isTrue(); + } catch (IOException | JsonLdError e) { + throw new RuntimeException(e); + } + } + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + mapper.registerModule(new JSONPModule()); + + try (var dspaceStream = getClass().getResourceAsStream("/context/dspace.jsonld"); + var odrlStream = getClass().getResourceAsStream("/context/odrl.jsonld")) { + var dspaceContext = mapper.readValue(dspaceStream, JsonObject.class); + @SuppressWarnings("DataFlowIssue") + Map cache = Map.of(DSP_CONTEXT, JsonDocument.of(dspaceContext), + ODRL_CONTEXT, JsonDocument.of(odrlStream) + ); + var documentLoader = new LocalDocumentLoader(cache); + compactionContext = mapper.readValue(CONTEXT_REFERENCE, JsonStructure.class); + options = new JsonLdOptions(); + options.setDocumentLoader(documentLoader); + } catch (IOException | JsonLdError e) { + throw new RuntimeException(e); + } + } + + private static class LocalDocumentLoader implements DocumentLoader { + private final Map contexts = new HashMap<>(); + + LocalDocumentLoader(Map contexts) { + this.contexts.putAll(contexts); + } + + @Override + public Document loadDocument(URI url, DocumentLoaderOptions options) { + return contexts.get(url.toString()); + } + } +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/context/negotiation/ContractNegotiationContextTest.java b/artifacts/src/test/java/org/eclipse/dsp/context/negotiation/ContractNegotiationContextTest.java new file mode 100644 index 0000000..e0f17cc --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/context/negotiation/ContractNegotiationContextTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.context.negotiation; + +import org.eclipse.dsp.context.fixtures.AbstractJsonLdTest; +import org.junit.jupiter.api.Test; + +public class ContractNegotiationContextTest extends AbstractJsonLdTest { + + @Test + void verifyContractAgreementMessage() { + verifyRoundTrip("/negotiation/example/contract-agreement-message.json", + "/negotiation/contract-agreement-message-schema.json"); + } + + @Test + void verifyFullAgreementMessage() { + verifyRoundTrip("/negotiation/example/contract-agreement-message-full.json", + "/negotiation/contract-agreement-message-schema.json"); + } + + @Test + void verifyContractAgreementVerificationMessage() { + verifyRoundTrip("/negotiation/example/contract-agreement-verification-message.json", + "/negotiation/contract-agreement-verification-message-schema.json"); + } + + @Test + void verifyContractNegotiation() { + verifyRoundTrip("/negotiation/example/contract-negotiation.json", + "/negotiation/contract-negotiation-schema.json"); + } + + @Test + void verifyContractNegotiationEventMessage() { + verifyRoundTrip("/negotiation/example/contract-negotiation-event-message.json", + "/negotiation/contract-negotiation-event-message-schema.json"); + } + + @Test + void verifyContractNegotiationError() { + verifyRoundTrip("/negotiation/example/contract-negotiation-error.json", + "/negotiation/contract-negotiation-error-schema.json"); + } + + @Test + void verifyContractNegotiationTerminationMessage() { + verifyRoundTrip("/negotiation/example/contract-negotiation-termination-message.json", + "/negotiation/contract-negotiation-termination-message-schema.json"); + } + + @Test + void verifyContractOfferMessage() { + verifyRoundTrip("/negotiation/example/contract-offer-message.json", + "/negotiation/contract-offer-message-schema.json"); + } + + @Test + void verifyContractRequestMessage() { + verifyRoundTrip("/negotiation/example/contract-request-message.json", + "/negotiation/contract-request-message-schema.json"); + } + + @Test + void verifyContractRequestMessageInitial() { + verifyRoundTrip("/negotiation/example/contract-request-message_initial.json", + "/negotiation/contract-request-message-schema.json"); + } + + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/context/transfer/TransferContextTest.java b/artifacts/src/test/java/org/eclipse/dsp/context/transfer/TransferContextTest.java new file mode 100644 index 0000000..feb8e17 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/context/transfer/TransferContextTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.context.transfer; + +import org.eclipse.dsp.context.fixtures.AbstractJsonLdTest; +import org.junit.jupiter.api.Test; + +public class TransferContextTest extends AbstractJsonLdTest { + + @Test + void verifyTransferCompletionMessage() { + verifyRoundTrip("/transfer/example/transfer-completion-message.json", + "/transfer/transfer-completion-message-schema.json"); + } + + @Test + void verifyTransferError() { + verifyRoundTrip("/transfer/example/transfer-error.json", + "/transfer/transfer-error-schema.json"); + } + + @Test + void verifyTransferProcess() { + verifyRoundTrip("/transfer/example/transfer-process.json", + "/transfer/transfer-process-schema.json"); + } + + @Test + void verifyTransferRequestMessage() { + verifyRoundTrip("/transfer/example/transfer-request-message.json", + "/transfer/transfer-request-message-schema.json"); + } + + @Test + void verifyTransferStartMessage() { + verifyRoundTrip("/transfer/example/transfer-start-message.json", + "/transfer/transfer-start-message-schema.json"); + } + + @Test + void verifyTransferSuspensionMessage() { + verifyRoundTrip("/transfer/example/transfer-suspension-message.json", + "/transfer/transfer-suspension-message-schema.json"); + } + + @Test + void verifyTransferTerminationMessage() { + verifyRoundTrip("/transfer/example/transfer-termination-message.json", + "/transfer/transfer-termination-message-schema.json"); + } + + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/CatalogErrorSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/CatalogErrorSchemaTest.java new file mode 100644 index 0000000..db569d1 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/CatalogErrorSchemaTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class CatalogErrorSchemaTest extends AbstractSchemaTest { + + @Test + void verifyExamples() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/catalog/example/catalog-error.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyNodeCode() { + assertThat(schema.validate(VALID_NO_CODE, JSON)).isEmpty(); + } + + @Test + void verifyMissingContext() { + assertThat(schema.validate(INVALID_MISSING_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @Test + void verifyInvalidReason() { + assertThat(schema.validate(INVALID_REASON, JSON).iterator().next().getType()).isEqualTo(TYPE); + } + + @Test + void verifyInvalidCode() { + assertThat(schema.validate(INVALID_CODE_TYPE, JSON).iterator().next().getType()).isEqualTo(TYPE); + } + + @BeforeEach + void setUp() { + setUp("/catalog/catalog-error-schema.json"); + } + + private static final String INVALID_MISSING_CONTEXT = """ + { + "@type": "CatalogError", + "code": "123-A", + "reason": [ + "Catalog not provisioned for this requester." + ] + }"""; + + private static final String VALID_NO_CODE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "CatalogError" + }"""; + + private static final String INVALID_CODE_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "CatalogError", + "code": 123, + "reason": [ + "Catalog not provisioned for this requester." + ] + }"""; + + private static final String INVALID_REASON = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "CatalogError", + "code": "123-A", + "reason": "Catalog not provisioned for this requester." + }"""; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/CatalogSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/CatalogSchemaTest.java new file mode 100644 index 0000000..5f79353 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/CatalogSchemaTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class CatalogSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/catalog/example/catalog.json")); + assertThat(schema.validate(node)).isEmpty(); + assertThat(schema.validate(MINIMAL_CATALOG, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/catalog/catalog-schema.json"); + } + + private static final String MINIMAL_CATALOG = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Catalog", + "participantId": "urn:example:DataProviderA" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetRequestMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetRequestMessageSchemaTest.java new file mode 100644 index 0000000..2e2cb26 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetRequestMessageSchemaTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DatasetRequestMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/catalog/example/dataset-request-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/catalog/dataset-request-message-schema.json"); + } + + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetResponseTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetResponseTest.java new file mode 100644 index 0000000..daa87ab --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetResponseTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DatasetResponseTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/catalog/example/dataset.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/catalog/dataset-schema.json"); + } + + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetSchemaTest.java new file mode 100644 index 0000000..5318fe8 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/DatasetSchemaTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class DatasetSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() { + assertThat(schema.validate(DATASET, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/catalog/dataset-schema.json"); + } + + private static final String DATASET = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "hasPolicy": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "spatial", + "operator": "eq", + "rightOperand": "http://example.org/EU" + }] + } + ] + } + ], + "distribution": [ + { + "@type": "Distribution", + "format": "HttpData-PULL", + "accessService": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77" + } + ] + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/InvalidCatalogSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/InvalidCatalogSchemaTest.java new file mode 100644 index 0000000..edf2dbb --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/InvalidCatalogSchemaTest.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidCatalogSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() throws IOException { + assertThat(schema.validate(INVALID_CATALOG_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_CATALOG_NO_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_CATALOG_NO_PARTICIPANT_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_SERVICE_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_SERVICE_ENDPOINT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/catalog/catalog-schema.json"); + } + + private static final String DATASET = """ + "dataset": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Dataset", + "hasPolicy": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "permission": [ + { + "action": "use" + } + ] + } + ], + "distribution": [ + { + "@type": "Distribution", + "format": "HttpData-PULL", + "accessService": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77" + } + ] + } + ] + """; + + private static final String INVALID_CATALOG_NO_CONTEXT = format(""" + { + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Catalog", + "participantId": "urn:example:DataProviderA", + "service": [ + { + "@id": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77", + "@type": "DataService", + "endpointURL": "https://provider-a.com/connector" + } + ], + %s + } + """, DATASET); + + private static final String INVALID_CATALOG_NO_ID = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "Catalog", + "participantId": "urn:example:DataProviderA", + "service": [ + { + "@id": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77", + "@type": "DataService", + "endpointURL": "https://provider-a.com/connector" + } + ], + %s + } + """, DATASET); + + private static final String INVALID_CATALOG_NO_PARTICIPANT_ID = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Catalog", + "service": [ + { + "@id": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77", + "@type": "DataService", + "endpointURL": "https://provider-a.com/connector" + } + ], + %s + } + """, DATASET); + + private static final String INVALID_NO_SERVICE_ID = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Catalog", + "participantId": "urn:example:DataProviderA", + "service": [ + { + "@type": "DataService", + "endpointURL": "https://provider-a.com/connector" + } + ], + %s + } + """, DATASET); + + private static final String INVALID_NO_SERVICE_ENDPOINT = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@id": "urn:uuid:3afeadd8-ed2d-569e-d634-8394a8836d57", + "@type": "Catalog", + "participantId": "urn:example:DataProviderA", + "service": [ + { + "@id": "urn:uuid:4aa2dcc8-4d2d-569e-d634-8394a8834d77", + "@type": "DataService" + } + ], + %s + } + """, DATASET); + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/InvalidDatasetSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/InvalidDatasetSchemaTest.java new file mode 100644 index 0000000..3c416eb --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/InvalidDatasetSchemaTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidDatasetSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_NO_ID_DATASET, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_ID_DATASET_NO_POLICY, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_DISTRIBUTION, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_DISTRIBUTION_FORMAT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/catalog/dataset-schema.json"); + } + + private static final String INVALID_NO_ID_DATASET = """ + { + "hasPolicy": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "spatial", + "operator": "eq", + "rightOperand": "http://example.org/EU" + }] + } + ] + } + ], + "distribution": [ + { + "accessService" : "urn:uuid:fdb94161-14b4-4319-9f45-09dda9f3ce83", + "format": "HttpData-PULL" + } + ] + } + """; + + private static final String INVALID_NO_ID_DATASET_NO_POLICY = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "distribution": [ + { + "accessService" : "urn:uuid:fdb94161-14b4-4319-9f45-09dda9f3ce83", + "format": "HttpData-PULL" + } + ] + } + """; + + private static final String INVALID_NO_DISTRIBUTION = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "hasPolicy": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "spatial", + "operator": "eq", + "rightOperand": "http://example.org/EU" + }] + } + ] + } + ] + } + """; + + private static final String INVALID_NO_DISTRIBUTION_FORMAT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "hasPolicy": [ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "spatial", + "operator": "eq", + "rightOperand": "http://example.org/EU" + }] + } + ] + } + ], + "distribution": [ + { + "accessService" : "urn:uuid:fdb94161-14b4-4319-9f45-09dda9f3ce83" + } + ] + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/NestedCatalogSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/NestedCatalogSchemaTest.java new file mode 100644 index 0000000..495ffef --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/catalog/NestedCatalogSchemaTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.catalog; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NestedCatalogSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/catalog/example/nested-catalog.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/catalog/catalog-schema.json"); + } +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/common/CommonSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/common/CommonSchemaTest.java new file mode 100644 index 0000000..e1ce6de --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/common/CommonSchemaTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.common; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class CommonSchemaTest extends AbstractSchemaTest { + + @Test + void verifyContext() { + var baseInput = """ + ["https://w3id.org/dspace/2024/1/context.json"] + """; + assertThat(schema.validate(baseInput, JSON)).isEmpty(); + + var multiValueInput = """ + [ + "https://w3id.org/dspace/2024/1/context.json", + "https://test.com/context.json" + ] + """; + assertThat(schema.validate(multiValueInput, JSON)).isEmpty(); + + var missingDspValueInput = """ + [ + "https://test.com/context.json" + ] + """; + + assertThat(schema.validate(missingDspValueInput, JSON).iterator().next().getType()).isEqualTo(MIN_CONTAINS); + + var emptyInput = "[]"; + assertThat(schema.validate(emptyInput, JSON).iterator().next().getType()).isEqualTo(MIN_CONTAINS); + } + + @BeforeEach + void setUp() { + setUp("/common/context-schema.json"); + } +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/fixtures/AbstractSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/fixtures/AbstractSchemaTest.java new file mode 100644 index 0000000..21af0db --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/fixtures/AbstractSchemaTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.fixtures; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.networknt.schema.JsonSchema; +import com.networknt.schema.JsonSchemaFactory; +import com.networknt.schema.SchemaLocation; + +import static com.networknt.schema.SpecVersion.VersionFlag.V202012; +import static org.eclipse.dsp.DspConstants.DSP_PREFIX; + +/** + * Base test class. + */ +public abstract class AbstractSchemaTest { + protected static final String MIN_CONTAINS = "minContains"; + protected static final String REQUIRED = "required"; + protected static final String ONE_OF = "oneOf"; + protected static final String TYPE = "type"; + protected static final String ENUM = "enum"; + + private static final String CLASSPATH_SCHEMA = "classpath:/"; + + protected ObjectMapper mapper = new ObjectMapper(); + protected JsonSchema schema; + + protected void setUp(String schemaFile) { + var schemaFactory = JsonSchemaFactory.getInstance(V202012, builder -> + builder.schemaMappers(schemaMappers -> schemaMappers.mapPrefix(DSP_PREFIX, CLASSPATH_SCHEMA)) + ); + + schema = schemaFactory.getSchema(SchemaLocation.of(DSP_PREFIX + schemaFile)); + } +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/AgreementSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/AgreementSchemaTest.java new file mode 100644 index 0000000..9022331 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/AgreementSchemaTest.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class AgreementSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() { + assertThat(schema.validate(AGREEMENT, JSON)).isEmpty(); + assertThat(schema.validate(MINIMAL_AGREEMENT, JSON)).isEmpty(); + assertThat(schema.validate(INVALID_AGREEMENT_NO_ASSIGNER, JSON)).isNotEmpty(); + assertThat(schema.validate(INVALID_AGREEMENT_NO_ASSIGNEE, JSON)).isNotEmpty(); + assertThat(schema.validate(INVALID_AGREEMENT_NO_TARGET, JSON)).isNotEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-schema.json"); + } + + private static final String AGREEMENT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Agreement", + "target": "asset:1", + "assigner": "did:web:provider", + "assignee": "did:web:consumer", + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }] + } + ] + }"""; + + private static final String MINIMAL_AGREEMENT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Agreement", + "target": "asset:1", + "assigner": "did:web:provider", + "assignee": "did:web:consumer", + "permission": [ + { + "action": "use" + } + ] + }"""; + + private static final String INVALID_AGREEMENT_NO_TARGET = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Agreement", + "assigner": "did:web:provider", + "assignee": "did:web:consumer", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + } + ] + } + ] + }"""; + + private static final String INVALID_AGREEMENT_NO_ASSIGNEE = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Agreement", + "target": "asset:1", + "assigner": "did:web:provider", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + } + ] + } + ] + }"""; + + private static final String INVALID_AGREEMENT_NO_ASSIGNER = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Agreement", + "target": "asset:1", + "assignee": "did:web:consumer", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + } + ] + } + ] + }"""; + + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractAgreementMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractAgreementMessageSchemaTest.java new file mode 100644 index 0000000..60aa2d0 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractAgreementMessageSchemaTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractAgreementMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-agreement-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-agreement-message-schema.json"); + } + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractAgreementVerificationMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractAgreementVerificationMessageSchemaTest.java new file mode 100644 index 0000000..7c574c2 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractAgreementVerificationMessageSchemaTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractAgreementVerificationMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-agreement-verification-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-agreement-verification-message-schema.json"); + } + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationErrorSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationErrorSchemaTest.java new file mode 100644 index 0000000..344261c --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationErrorSchemaTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractNegotiationErrorSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-negotiation-error.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyMinimal() { + assertThat(schema.validate(MINIMAL_ERROR, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-error-schema.json"); + } + + private static final String MINIMAL_ERROR = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationEventMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationEventMessageSchemaTest.java new file mode 100644 index 0000000..889c9f5 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationEventMessageSchemaTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractNegotiationEventMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-negotiation-event-message.json")); + assertThat(schema.validate(node)).isEmpty(); + assertThat(schema.validate(ACCEPTED_EVENT_TYPE, JSON)).isEmpty(); + assertThat(schema.validate(FINALIZED_EVENT_TYPE, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-event-message-schema.json"); + } + + private static final String ACCEPTED_EVENT_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationEventMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "eventType": "ACCEPTED" + } + """; + + private static final String FINALIZED_EVENT_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationEventMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "eventType": "FINALIZED" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationSchemaTest.java new file mode 100644 index 0000000..6fbb235 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationSchemaTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractNegotiationSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-negotiation.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-schema.json"); + } + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationTerminationMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationTerminationMessageSchemaTest.java new file mode 100644 index 0000000..3ae43b0 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractNegotiationTerminationMessageSchemaTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractNegotiationTerminationMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-negotiation-termination-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyMinimalMessage() { + assertThat(schema.validate(MINIMAL_MESSAGE, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-termination-message-schema.json"); + } + + private static final String MINIMAL_MESSAGE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationTerminationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractOfferMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractOfferMessageSchemaTest.java new file mode 100644 index 0000000..b8bd3c5 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractOfferMessageSchemaTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractOfferMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-offer-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyInitialRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-offer-message_initial.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-offer-message-schema.json"); + } + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractRequestMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractRequestMessageSchemaTest.java new file mode 100644 index 0000000..bbce7cb --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/ContractRequestMessageSchemaTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class ContractRequestMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-request-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyInitialRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/negotiation/example/contract-request-message_initial.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyIdRequest() { + assertThat(schema.validate(REQUEST_ID, JSON)).isEmpty(); + assertThat(schema.validate(REQUEST_INITIAL_ID, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-request-message-schema.json"); + } + + private static final String REQUEST_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a815" + }, + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String REQUEST_INITIAL_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a815" + }, + "callbackAddress": "https://example.com/callback" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractAgreementMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractAgreementMessageSchemaTest.java new file mode 100644 index 0000000..cd78711 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractAgreementMessageSchemaTest.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractAgreementMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_CALLBACK, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(NO_AGREEMENT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-agreement-message-schema.json"); + } + + private static final String AGREEMENT = """ + "agreement": { + "@id": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "@type": "Agreement", + "target": "urn:uuid:3dd1add4-4d2d-569e-d634-8394a8836d23", + "timestamp": "2023-01-01T01:00:00Z", + "assigner": "http://example.com/Provider", + "assignee": "http://example.com/Consumer", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "dateTime", + "operator": "lteq", + "rightOperand": "2023-12-31T06:00Z" + } + ] + } + ] + } + """; + + private static final String INVALID_NO_CONTEXT = format(""" + { + "@type": "ContractAgreementMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + %s, + "callbackAddress": "https://example.com/callback" + } + """, AGREEMENT); + + private static final String INVALID_NO_TYPE = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + %s, + "callbackAddress": "https://example.com/callback" + } + """, AGREEMENT); + + private static final String INVALID_NO_PROVIDER_ID = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + %s, + "callbackAddress": "https://example.com/callback" + } + """, AGREEMENT); + + private static final String INVALID_NO_CONSUMER_ID = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + %s, + "callbackAddress": "https://example.com/callback" + } + """, AGREEMENT); + + private static final String INVALID_NO_CALLBACK = format(""" + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + %s + } + """, AGREEMENT); + + private static final String NO_AGREEMENT = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "callbackAddress": "https://example.com/callback" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractAgreementVerificationMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractAgreementVerificationMessageSchemaTest.java new file mode 100644 index 0000000..e1b0ece --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractAgreementVerificationMessageSchemaTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractAgreementVerificationMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-agreement-verification-message-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_CONTEXT = """ + { + "@type": "ContractAgreementVerificationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementVerificationMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractAgreementVerificationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationErrorSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationErrorSchemaTest.java new file mode 100644 index 0000000..d235f25 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationErrorSchemaTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractNegotiationErrorSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-error-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_CONTEXT = """ + { + "@type": "ContractNegotiationError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationError", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationEventMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationEventMessageSchemaTest.java new file mode 100644 index 0000000..81b2624 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationEventMessageSchemaTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractNegotiationEventMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_EVENT_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_EVENT_TYPE, JSON).iterator().next().getType()).isEqualTo(ENUM); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-event-message-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_CONTEXT = """ + { + "@type": "ContractNegotiationEventMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "eventType": "ACCEPTED" + } + """; + + private static final String INVALID_MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "eventType": "ACCEPTED" + } + """; + + private static final String INVALID_MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationEventMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "eventType": "ACCEPTED" + } + """; + + private static final String INVALID_MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationEventMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "eventType": "ACCEPTED" + } + """; + + private static final String INVALID_MESSAGE_NO_EVENT_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationEventMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_EVENT_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationEventMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "eventType": "INVALID" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationSchemaTest.java new file mode 100644 index 0000000..bb37d9f --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationSchemaTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractNegotiationSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_STATE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_STATE, JSON).iterator().next().getType()).isEqualTo(ENUM); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_CONTEXT = """ + { + "@type": "ContractNegotiation", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiation", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiation", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_STATE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiation", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_STATE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiation", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "INVALID" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationTerminationMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationTerminationMessageSchemaTest.java new file mode 100644 index 0000000..8eca2a8 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractNegotiationTerminationMessageSchemaTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractNegotiationTerminationMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() { + assertThat(schema.validate(MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-negotiation-termination-message-schema.json"); + } + + private static final String MESSAGE_NO_CONTEXT = """ + { + "@type": "ContractNegotiationTerminationMessage", + "consumerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "code": "99", + "reason": [ + "License model does not fit." + ] + } + """; + + private static final String MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "consumerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "code": "99", + "reason": [ + "License model does not fit." + ] + } + """; + + private static final String MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationTerminationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "code": "99", + "reason": [ + "License model does not fit." + ] + } + """; + + private static final String MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractNegotiationTerminationMessage", + "consumerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "code": "99", + "reason": [ + "License model does not fit." + ] + } + """; +} + diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractOfferMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractOfferMessageSchemaTest.java new file mode 100644 index 0000000..0546b9b --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractOfferMessageSchemaTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractOfferMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_TARGET, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CALLBACK, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-offer-message-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_TARGET = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractOfferMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@type": "Offer", + "@id": "urn:uuid:6bcea82e-c509-443d-ba8c-8eef25984c07", + "permission": [ + { + "action": "use" + } + ] + }, + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_MESSAGE_NO_CALLBACK = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractOfferMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@type": "Offer", + "@id": "urn:uuid:6bcea82e-c509-443d-ba8c-8eef25984c07", + "target": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "permission": [ + { + "action": "use" + } + ] + } + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractRequestMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractRequestMessageSchemaTest.java new file mode 100644 index 0000000..22d2c61 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidContractRequestMessageSchemaTest.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidContractRequestMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_REQUEST_NO_OFFER, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_ID, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + assertThat(schema.validate(INVALID_REQUEST_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_CALLBACK, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-request-message-schema.json"); + } + + private static final String INVALID_REQUEST_NO_OFFER = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + }, + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "offer": { + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a815" + }, + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_CALLBACK = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "ContractRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a815" + } + } + """; + + private static final String INVALID_REQUEST_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a815" + }, + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_CONTEXT = """ + { + "@type": "ContractRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "offer": { + "@id": "urn:uuid:d526561f-528e-4d5a-ae12-9a9dd9b7a815" + }, + "callbackAddress": "https://example.com/callback" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidPolicySchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidPolicySchemaTest.java new file mode 100644 index 0000000..da01c0b --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/InvalidPolicySchemaTest.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidPolicySchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_NO_RULES, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + assertThat(schema.validate(INVALID_NO_ID, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + assertThat(schema.validate(INVALID_NO_ACTION, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + assertThat(schema.validate(INVALID_NO_LEFT_OPERAND, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + assertThat(schema.validate(INVALID_NO_OPERATOR, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + assertThat(schema.validate(INVALID_NO_RIGHT_OPERAND, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + assertThat(schema.validate(INVALID_MULTIPLICITY_CONSTRAINT, JSON).iterator().next().getType()).isEqualTo(ONE_OF); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-schema.json"); + } + + private static final String INVALID_NO_RULES = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1" + }"""; + + private static final String INVALID_NO_ID = """ + { + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + } + ] + } + ] + }"""; + + private static final String INVALID_NO_ACTION = """ + { + "@type": "Offer", + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "target": "asset:1", + "permission": [ + { + "constraint": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + } + ] + } + ] + }"""; + + private static final String INVALID_NO_LEFT_OPERAND = """ + { + "@type": "Offer", + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [ + { + "operator": "eq", + "rightOperand": "gold" + } + ] + } + ] + }"""; + private static final String INVALID_NO_OPERATOR = """ + { + "@type": "Offer", + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "partner", + "rightOperand": "gold" + } + ] + } + ] + }"""; + + private static final String INVALID_NO_RIGHT_OPERAND = """ + { + "@type": "Offer", + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [ + { + "leftOperand": "partner", + "operator": "eq" + } + ] + } + ] + }"""; + + private static final String INVALID_MULTIPLICITY_CONSTRAINT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": { + "invalid": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + } + } + ] + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/PolicySchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/PolicySchemaTest.java new file mode 100644 index 0000000..29c7858 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/negotiation/PolicySchemaTest.java @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.negotiation; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class PolicySchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() { + assertThat(schema.validate(POLICY, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_STRING_PROFILE, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_ARRAY_PROFILE, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_PERMISSION_DUTY, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_OR_CONSTRAINT, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_AND_CONSTRAINT, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_AND_SEQUENCE_CONSTRAINT, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_XONE_SEQUENCE_CONSTRAINT, JSON)).isEmpty(); + assertThat(schema.validate(POLICY_NESTED_MULTIPLICITY, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/negotiation/contract-schema.json"); + } + + private static final String POLICY = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }], + "duty": { + "action": "report" + } + } + ] + }"""; + + private static final String POLICY_STRING_PROFILE = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "profile": "https://test.com/profile", + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }], + "duty": { + "action": "report" + } + } + ] + }"""; + + private static final String POLICY_ARRAY_PROFILE = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "profile": ["https://test.com/profile"], + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }], + "duty": { + "action": "report" + } + } + ] + }"""; + + private static final String POLICY_PERMISSION_DUTY = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "profile": ["https://test.com/profile"], + "permission": [ + { + "action": "use", + "constraint": [{ + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }], + "duty": { + "action": "report", + "constraint": [{ + "leftOperand": "event", + "operator": "gt", + "rightOperand": "use" + }] + } + } + ] + }"""; + + + private static final String POLICY_OR_CONSTRAINT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [{ + "or": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + }] + } + ] + } + """; + + private static final String POLICY_AND_CONSTRAINT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [{ + "and": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + }] + } + ] + } + """; + + private static final String POLICY_AND_SEQUENCE_CONSTRAINT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [{ + "andSequence": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + }] + } + ] + } + """; + + private static final String POLICY_XONE_SEQUENCE_CONSTRAINT = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [{ + "xone": [ + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "gold" + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + }] + } + ] + } + """; + private static final String POLICY_NESTED_MULTIPLICITY = """ + { + "@id": "urn:uuid:3dd1add8-4d2d-569e-d634-8394a8836a88", + "@type": "Offer", + "target": "asset:1", + "permission": [ + { + "action": "use", + "constraint": [{ + "or": [ + { + "and": [ + { + "leftOperand": "constraint1", + "operator": "eq", + "rightOperand": "value1" + }, + { + "leftOperand": "constraint2", + "operator": "eq", + "rightOperand": "value2" + } + ] + }, + { + "leftOperand": "partner", + "operator": "eq", + "rightOperand": "silver" + } + ] + }] + } + ] + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferCompletionMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferCompletionMessageSchemaTest.java new file mode 100644 index 0000000..4131c6d --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferCompletionMessageSchemaTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferCompletionMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-completion-message-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_CONTEXT = """ + { + "@type": "TransferCompletionMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferCompletionMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferCompletionMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferErrorSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferErrorSchemaTest.java new file mode 100644 index 0000000..7a30073 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferErrorSchemaTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferErrorSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-error-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_CONTEXT = """ + { + "@type": "TransferError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferError", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferProcessSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferProcessSchemaTest.java new file mode 100644 index 0000000..2cdf4fb --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferProcessSchemaTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferProcessSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_MESSAGE_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_NO_STATE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_MESSAGE_STATE, JSON).iterator().next().getType()).isEqualTo(ENUM); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-process-schema.json"); + } + + private static final String INVALID_MESSAGE_NO_CONTEXT = """ + { + "@type": "TransferProcess", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferProcess", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferProcess", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "state": "REQUESTED" + } + """; + + private static final String INVALID_MESSAGE_NO_STATE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferProcess", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + + private static final String INVALID_MESSAGE_STATE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferProcess", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "state": "INVALID" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferRequestMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferRequestMessageSchemaTest.java new file mode 100644 index 0000000..2cbd3b3 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferRequestMessageSchemaTest.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferRequestMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_REQUEST_NO_CONTEXT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_AGREEMENT_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_FORMAT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_REQUEST_NO_CALLBACK, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + + assertThat(schema.validate(INVALID_NO_DA_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_DA_ENDPOINT_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_DA_ENDPOINT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-request-message-schema.json"); + } + + private static final String INVALID_REQUEST_NO_CONTEXT = """ + { + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_AGREEMENT_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "format": "example:HTTP_PUSH", + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_FORMAT = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_REQUEST_NO_CALLBACK = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH" + } + """; + + private static final String INVALID_NO_DA_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "dataAddress": { + "endpointType": "https://w3id.org/idsa/v4.1/HTTP", + "endpoint": "http://example.com" + }, + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_NO_DA_ENDPOINT_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "dataAddress": { + "@type": "DataAddress", + "endpoint": "http://example.com" + }, + "callbackAddress": "https://example.com/callback" + } + """; + + private static final String INVALID_NO_DA_ENDPOINT = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "dataAddress": { + "@type": "DataAddress", + "endpointType": "https://w3id.org/idsa/v4.1/HTTP" + }, + "callbackAddress": "https://example.com/callback" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferSchemaTest.java new file mode 100644 index 0000000..cd5aa6b --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferSchemaTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_ENDPOINT_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_ENDPOINT, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-schema.json"); + } + + + private static final String INVALID_NO_TYPE = """ + { + "endpointType": "https://w3id.org/idsa/v4.1/HTTP", + "endpoint": "http://example.com" + } + """; + + private static final String INVALID_NO_ENDPOINT_TYPE = """ + { + "@type": "DataAddress", + "endpoint": "http://example.com" + } + """; + + private static final String INVALID_NO_ENDPOINT = """ + { + "@type": "DataAddress", + "endpointType": "https://w3id.org/idsa/v4.1/HTTP" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferStartMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferStartMessageSchemaTest.java new file mode 100644 index 0000000..3db4172 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferStartMessageSchemaTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferStartMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-start-message-schema.json"); + } + + private static final String INVALID_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + private static final String INVALID_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferStartMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + private static final String INVALID_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferStartMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferSuspensionMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferSuspensionMessageSchemaTest.java new file mode 100644 index 0000000..ad18954 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferSuspensionMessageSchemaTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferSuspensionMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-suspension-message-schema.json"); + } + + private static final String INVALID_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + private static final String INVALID_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferSuspensionMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + private static final String INVALID_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferSuspensionMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferTerminationMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferTerminationMessageSchemaTest.java new file mode 100644 index 0000000..5075b7a --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/InvalidTransferTerminationMessageSchemaTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class InvalidTransferTerminationMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyInvalidCases() { + assertThat(schema.validate(INVALID_NO_TYPE, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_PROVIDER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + assertThat(schema.validate(INVALID_NO_CONSUMER_ID, JSON).iterator().next().getType()).isEqualTo(REQUIRED); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-suspension-message-schema.json"); + } + + private static final String INVALID_NO_TYPE = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + private static final String INVALID_NO_PROVIDER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferTerminationMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; + private static final String INVALID_NO_CONSUMER_ID = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferTerminationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab" + } + """; + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferCompletionMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferCompletionMessageSchemaTest.java new file mode 100644 index 0000000..8583952 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferCompletionMessageSchemaTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferCompletionMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/transfer/example/transfer-completion-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-completion-message-schema.json"); + } + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferErrorSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferErrorSchemaTest.java new file mode 100644 index 0000000..2215e89 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferErrorSchemaTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferErrorSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/transfer/example/transfer-error.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyMinimal() { + assertThat(schema.validate(MINIMAL_ERROR, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-error-schema.json"); + } + + private static final String MINIMAL_ERROR = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferError", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferProcessSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferProcessSchemaTest.java new file mode 100644 index 0000000..5141e57 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferProcessSchemaTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferProcessSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/transfer/example/transfer-process.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-process-schema.json"); + } + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferRequestMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferRequestMessageSchemaTest.java new file mode 100644 index 0000000..5bc4802 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferRequestMessageSchemaTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferRequestMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/transfer/example/transfer-request-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyMinimalRequestSchema() { + assertThat(schema.validate(MINIMAL_REQUEST, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-request-message-schema.json"); + } + + private static final String MINIMAL_REQUEST = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferRequestMessage", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833", + "agreementId": "urn:uuid:e8dc8655-44c2-46ef-b701-4cffdc2faa44", + "format": "example:HTTP_PUSH", + "callbackAddress": "https://example.com/callback" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferSchemaTest.java new file mode 100644 index 0000000..b15892d --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferSchemaTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferSchemaTest extends AbstractSchemaTest { + + @Test + void verifySchema() { + assertThat(schema.validate(PROPERTIES, JSON)).isEmpty(); + assertThat(schema.validate(NO_PROPERTIES, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/data-address-schema.json"); + } + + + private static final String PROPERTIES = """ + { + "@type": "DataAddress", + "endpointType": "https://w3id.org/idsa/v4.1/HTTP", + "endpoint": "http://example.com", + "endpointProperties": [ + { + "@type": "EndpointProperty", + "name": "authorization", + "value": "TOKEN-ABCDEFG" + }, + { + "@type": "EndpointProperty", + "name": "authType", + "value": "bearer" + } + ] + } + """; + + private static final String NO_PROPERTIES = """ + { + "@type": "DataAddress", + "endpointType": "https://w3id.org/idsa/v4.1/HTTP", + "endpoint": "http://example.com" + } + """; + + +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferStartMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferStartMessageSchemaTest.java new file mode 100644 index 0000000..0929c08 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferStartMessageSchemaTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferStartMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/transfer/example/transfer-start-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyMinimalRequestSchema() { + assertThat(schema.validate(MINIMAL_REQUEST, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-start-message-schema.json"); + } + + private static final String MINIMAL_REQUEST = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferStartMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferSuspensionMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferSuspensionMessageSchemaTest.java new file mode 100644 index 0000000..05d6fa3 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferSuspensionMessageSchemaTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferSuspensionMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/transfer/example/transfer-suspension-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyMinimalRequestSchema() { + assertThat(schema.validate(MINIMAL_REQUEST, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-suspension-message-schema.json"); + } + + private static final String MINIMAL_REQUEST = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferSuspensionMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; +} diff --git a/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferTerminationMessageSchemaTest.java b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferTerminationMessageSchemaTest.java new file mode 100644 index 0000000..6a86d51 --- /dev/null +++ b/artifacts/src/test/java/org/eclipse/dsp/schema/transfer/TransferTerminationMessageSchemaTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.dsp.schema.transfer; + +import org.eclipse.dsp.schema.fixtures.AbstractSchemaTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static com.networknt.schema.InputFormat.JSON; +import static org.assertj.core.api.Assertions.assertThat; + +public class TransferTerminationMessageSchemaTest extends AbstractSchemaTest { + + @Test + void verifyRequestSchema() throws IOException { + var node = mapper.readTree(getClass().getResourceAsStream("/transfer/example/transfer-termination-message.json")); + assertThat(schema.validate(node)).isEmpty(); + } + + @Test + void verifyMinimalRequestSchema() { + assertThat(schema.validate(MINIMAL_REQUEST, JSON)).isEmpty(); + } + + @BeforeEach + void setUp() { + setUp("/transfer/transfer-termination-message-schema.json"); + } + + private static final String MINIMAL_REQUEST = """ + { + "@context": [ + "https://w3id.org/dspace/2024/1/context.json" + ], + "@type": "TransferTerminationMessage", + "providerPid": "urn:uuid:a343fcbf-99fc-4ce8-8e9b-148c97605aab", + "consumerPid": "urn:uuid:32541fe6-c580-409e-85a8-8a9a32fbe833" + } + """; +}