Split Spring Boot autoconfiguration for Web MVC to a separate starter dependency. Rename the core library from spring-cloud-cloudfoundry-service-broker to spring-cloud-open-service-broker.
This commit is contained in:
committed by
Roy Clarkson
parent
7905d070c8
commit
bb7fdfd4b8
214
build.gradle
214
build.gradle
@@ -1,131 +1,141 @@
|
||||
apply plugin: 'base'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'http://repo.spring.io/plugins-release' }
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.build.gradle:propdeps-plugin:0.0.7")
|
||||
classpath("io.spring.gradle:spring-io-plugin:0.0.4.RELEASE")
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'http://repo.spring.io/plugins-release' }
|
||||
}
|
||||
dependencies {
|
||||
classpath("io.spring.gradle:propdeps-plugin:0.0.10.RELEASE")
|
||||
classpath("io.spring.gradle:spring-io-plugin:0.0.8.RELEASE")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'propdeps'
|
||||
apply plugin: 'propdeps-maven'
|
||||
apply plugin: 'propdeps-idea'
|
||||
apply plugin: 'propdeps-eclipse'
|
||||
|
||||
apply from: "${rootProject.projectDir}/publish-maven.gradle"
|
||||
|
||||
if (project.hasProperty('platformVersion')) {
|
||||
apply plugin: 'spring-io'
|
||||
|
||||
// necessary to resolve the Spring IO versions (which may include snapshots)
|
||||
repositories {
|
||||
maven { url "https://repo.spring.io/libs-snapshot" }
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
springIoTestRuntime {
|
||||
imports {
|
||||
mavenBom "io.spring.platform:platform-bom:${platformVersion}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
archivesBaseName = "spring-cloud-cloudfoundry-service-broker"
|
||||
group = "org.springframework.cloud"
|
||||
description = "Spring Cloud - Cloud Foundry Service Broker"
|
||||
|
||||
ext {
|
||||
springBootVersion = '1.2.7.RELEASE'
|
||||
hibernateValidatorVersion = '5.1.0.Final'
|
||||
jsonPathVersion = '0.9.1'
|
||||
springVersion = '4.3.12.RELEASE'
|
||||
springSecurityVersion = '4.2.3.RELEASE'
|
||||
|
||||
javadocLinks = [
|
||||
'http://docs.oracle.com/javase/8/docs/api/',
|
||||
'http://docs.spring.io/spring/docs/current/javadoc-api/',
|
||||
] as String[]
|
||||
junitVersion = "4.12"
|
||||
mockitoVersion = "2.7.22"
|
||||
hamcrestVersion = "1.3"
|
||||
jsonPathVersion = "2.4.0"
|
||||
|
||||
javadocLinks = [
|
||||
'http://docs.oracle.com/javase/8/docs/api/',
|
||||
'http://docs.spring.io/spring/docs/current/javadoc-api/',
|
||||
] as String[]
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.7
|
||||
targetCompatibility = 1.7
|
||||
description = "Spring Cloud Service Broker"
|
||||
|
||||
allprojects {
|
||||
group = "org.springframework.cloud"
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'propdeps'
|
||||
apply plugin: 'propdeps-maven'
|
||||
apply plugin: 'propdeps-idea'
|
||||
apply plugin: 'propdeps-eclipse'
|
||||
|
||||
apply from: "${rootProject.projectDir}/publish-maven.gradle"
|
||||
|
||||
if (project.hasProperty('platformVersion')) {
|
||||
apply plugin: 'spring-io'
|
||||
|
||||
// necessary to resolve the Spring IO versions (which may include snapshots)
|
||||
repositories {
|
||||
maven { url "https://repo.spring.io/libs-snapshot" }
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
springIoTestRuntime {
|
||||
imports {
|
||||
mavenBom "io.spring.platform:platform-bom:${platformVersion}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
|
||||
compile("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
|
||||
compile("org.hibernate:hibernate-validator:${hibernateValidatorVersion}")
|
||||
compile("commons-beanutils:commons-beanutils:1.9.2")
|
||||
provided("org.projectlombok:lombok:1.16.6")
|
||||
subprojects {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
|
||||
testCompile("com.jayway.jsonpath:json-path:${jsonPathVersion}")
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
task testsJar(type: Jar) {
|
||||
classifier = 'tests'
|
||||
from sourceSets.test.output
|
||||
}
|
||||
configure(rootProject) {
|
||||
task testsJar(type: Jar) {
|
||||
classifier = 'tests'
|
||||
from sourceSets.test.output
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc
|
||||
}
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc
|
||||
}
|
||||
|
||||
task apidocs(type: Javadoc) {
|
||||
group = "Documentation"
|
||||
description = "Generates aggregated Javadoc API documentation."
|
||||
title = "${project.description} ${version} API"
|
||||
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
|
||||
options.author = true
|
||||
options.header = rootProject.description
|
||||
options.links(project.ext.javadocLinks)
|
||||
task api(type: Javadoc) {
|
||||
group = "Documentation"
|
||||
description = "Generates aggregated Javadoc API documentation."
|
||||
title = "${rootProject.description} ${version} API"
|
||||
|
||||
source project.sourceSets.main.allJava
|
||||
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
|
||||
options.author = true
|
||||
options.header = rootProject.description
|
||||
options.links(project.ext.javadocLinks)
|
||||
|
||||
classpath = files(project.sourceSets.main.compileClasspath)
|
||||
source subprojects.collect { project ->
|
||||
project.sourceSets.main.allJava
|
||||
}
|
||||
|
||||
maxMemory = "1024m"
|
||||
destinationDir = new File(buildDir, "apidocs")
|
||||
}
|
||||
classpath = files(subprojects.collect { project ->
|
||||
project.sourceSets.main.compileClasspath
|
||||
})
|
||||
|
||||
task docsZip(type: Zip) {
|
||||
group = 'Distribution'
|
||||
classifier = 'docs'
|
||||
description = "Builds -${classifier} archive containing api and reference."
|
||||
maxMemory = "1024m"
|
||||
destinationDir = new File(buildDir, "api")
|
||||
}
|
||||
|
||||
from(apidocs) {
|
||||
into 'apidocs'
|
||||
}
|
||||
}
|
||||
task docsZip(type: Zip) {
|
||||
group = 'Distribution'
|
||||
classifier = 'docs'
|
||||
description = "Builds -${classifier} archive containing api and reference " +
|
||||
"for deployment."
|
||||
|
||||
artifacts {
|
||||
archives testsJar
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
archives docsZip
|
||||
}
|
||||
from(api) {
|
||||
into 'api'
|
||||
}
|
||||
}
|
||||
|
||||
task dist(dependsOn: assemble) {
|
||||
group = 'Distribution'
|
||||
description = 'Builds -dist and -docs distribution archives.'
|
||||
artifacts {
|
||||
archives docsZip
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives testsJar
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
archives docsZip
|
||||
}
|
||||
|
||||
task dist(dependsOn: assemble) {
|
||||
group = 'Distribution'
|
||||
description = 'Builds -dist and -docs distribution archives.'
|
||||
}
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.14'
|
||||
gradleVersion = '3.5'
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
version=1.0.3.BUILD-SNAPSHOT
|
||||
version=2.0.0.BUILD-SNAPSHOT
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Fri Jan 20 16:16:16 CST 2017
|
||||
#Mon Nov 06 15:59:38 CST 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
|
||||
|
||||
110
gradlew
vendored
110
gradlew
vendored
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@@ -6,47 +6,6 @@
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
@@ -61,9 +20,49 @@ while [ -h "$PRG" ] ; do
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
@@ -90,7 +89,7 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
@@ -114,6 +113,7 @@ fi
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
@@ -154,11 +154,19 @@ if $cygwin ; then
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
14
gradlew.bat
vendored
14
gradlew.bat
vendored
@@ -8,14 +8,14 @@
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
@@ -46,10 +46,9 @@ echo location of your Java installation.
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
@@ -60,11 +59,6 @@ set _SKIP=2
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
7
settings.gradle
Normal file
7
settings.gradle
Normal file
@@ -0,0 +1,7 @@
|
||||
rootProject.name = 'spring-cloud-service-broker'
|
||||
|
||||
include ':spring-cloud-open-service-broker'
|
||||
include ':spring-cloud-starter-service-broker-webmvc'
|
||||
|
||||
project(':spring-cloud-open-service-broker').projectDir = "$rootDir/spring-cloud-open-service-broker" as File
|
||||
project(':spring-cloud-starter-service-broker-webmvc').projectDir = "$rootDir/spring-cloud-starter-service-broker-webmvc" as File
|
||||
31
spring-cloud-open-service-broker/build.gradle
Normal file
31
spring-cloud-open-service-broker/build.gradle
Normal file
@@ -0,0 +1,31 @@
|
||||
description = "Spring Cloud Open Service Broker"
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework:spring-web:${springVersion}")
|
||||
compile("org.springframework.security:spring-security-core:${springSecurityVersion}")
|
||||
compile("com.fasterxml.jackson.core:jackson-databind:2.8.10")
|
||||
compile("org.hibernate:hibernate-validator:5.3.5.Final")
|
||||
compile("commons-beanutils:commons-beanutils:1.9.3")
|
||||
compile("org.slf4j:slf4j-api:1.7.12")
|
||||
provided("org.projectlombok:lombok:1.16.6")
|
||||
|
||||
testCompile("org.springframework:spring-test:${springVersion}")
|
||||
|
||||
testCompile("junit:junit:${junitVersion}")
|
||||
testCompile("org.hamcrest:hamcrest-library:${hamcrestVersion}")
|
||||
testCompile("org.mockito:mockito-core:${mockitoVersion}")
|
||||
testCompile("com.jayway.jsonpath:json-path:${jsonPathVersion}")
|
||||
}
|
||||
|
||||
task testsJar(type: Jar) {
|
||||
classifier = 'tests'
|
||||
from sourceSets.test.output
|
||||
}
|
||||
|
||||
configurations {
|
||||
testOutput
|
||||
}
|
||||
|
||||
artifacts {
|
||||
testOutput testsJar
|
||||
}
|
||||
@@ -22,12 +22,9 @@ public class CatalogController extends BaseController {
|
||||
super(service);
|
||||
}
|
||||
|
||||
@RequestMapping(value = {
|
||||
"/v2/catalog",
|
||||
"{cfInstanceId}/v2/catalog"
|
||||
}, method = RequestMethod.GET)
|
||||
@RequestMapping(value = {"/v2/catalog", "{cfInstanceId}/v2/catalog"}, method = RequestMethod.GET)
|
||||
public Catalog getCatalog() {
|
||||
log.debug("getCatalog()");
|
||||
log.debug("Retrieving catalog");
|
||||
return catalogService.getCatalog();
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import static org.springframework.cloud.servicebroker.model.ServiceBrokerRequest
|
||||
|
||||
/**
|
||||
* See: http://docs.cloudfoundry.org/services/api.html
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ public class ServiceInstanceController extends BaseController {
|
||||
private ServiceInstanceService service;
|
||||
|
||||
@Autowired
|
||||
public ServiceInstanceController(CatalogService catalogService, ServiceInstanceService serviceInstanceService) {
|
||||
public ServiceInstanceController(CatalogService catalogService, ServiceInstanceService serviceInstanceService) {
|
||||
super(catalogService);
|
||||
this.service = serviceInstanceService;
|
||||
}
|
||||
@@ -13,5 +13,5 @@ public class ServiceBrokerApiVersionException extends RuntimeException {
|
||||
+ "expected version=" + expectedVersion
|
||||
+ ", provided version = " + providedVersion);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package org.springframework.cloud.servicebroker.exception;
|
||||
/**
|
||||
* General exception for underlying broker errors (like connectivity to the service
|
||||
* being brokered).
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*
|
||||
*/
|
||||
@@ -2,15 +2,15 @@ package org.springframework.cloud.servicebroker.exception;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that a request includes a service definition ID does not exist.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*/
|
||||
public class ServiceDefinitionDoesNotExistException extends RuntimeException {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -62090827040416788L;
|
||||
|
||||
public ServiceDefinitionDoesNotExistException(String serviceDefinitionId) {
|
||||
super("Service definition does not exist: id=" + serviceDefinitionId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,13 +2,13 @@ package org.springframework.cloud.servicebroker.exception;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that a duplicate request to bind to a service instance is received.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*/
|
||||
public class ServiceInstanceBindingExistsException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -914571358227517785L;
|
||||
|
||||
|
||||
public ServiceInstanceBindingExistsException(String serviceInstanceId, String bindingId) {
|
||||
super("Service instance binding already exists: "
|
||||
+ "serviceInstanceId=" + serviceInstanceId
|
||||
@@ -2,13 +2,13 @@ package org.springframework.cloud.servicebroker.exception;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that a request is received for an unknown service instance ID.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*/
|
||||
public class ServiceInstanceDoesNotExistException extends RuntimeException {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -1879753092397657116L;
|
||||
|
||||
|
||||
public ServiceInstanceDoesNotExistException(String serviceInstanceId) {
|
||||
super("Service instance does not exist: id=" + serviceInstanceId);
|
||||
}
|
||||
@@ -2,13 +2,13 @@ package org.springframework.cloud.servicebroker.exception;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that a duplicate service instance creation request is received.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*/
|
||||
public class ServiceInstanceExistsException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -914571358227517785L;
|
||||
|
||||
|
||||
public ServiceInstanceExistsException(String serviceInstanceId, String serviceDefinitionId) {
|
||||
super("Service instance with the given ID already exists: " +
|
||||
"serviceInstanceId=" + serviceInstanceId +
|
||||
@@ -10,9 +10,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
public class AsyncRequiredErrorMessage extends ErrorMessage {
|
||||
|
||||
public final static String ASYNC_REQUIRED_ERROR = "AsyncRequired";
|
||||
|
||||
|
||||
/**
|
||||
* This broker requires asynchronous processing.
|
||||
* This broker requires asynchronous processing.
|
||||
*
|
||||
* @param description user facing error message.
|
||||
*/
|
||||
@@ -21,7 +21,7 @@ public class AsyncRequiredErrorMessage extends ErrorMessage {
|
||||
}
|
||||
|
||||
@JsonProperty("error")
|
||||
public String getError() {
|
||||
public String getError() {
|
||||
return ASYNC_REQUIRED_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public abstract class AsyncServiceInstanceRequest extends ServiceBrokerRequest {
|
||||
* <code>true</code> value indicates that clients do allow asynchronous processing.
|
||||
*/
|
||||
protected boolean asyncAccepted;
|
||||
|
||||
|
||||
public AsyncServiceInstanceRequest() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.servicebroker.model;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BrokerApiVersion {
|
||||
public final static String DEFAULT_API_VERSION_HEADER = "X-Broker-Api-Version";
|
||||
|
||||
public final static String API_VERSION_ANY = "*";
|
||||
public final static String API_VERSION_CURRENT = "2.13";
|
||||
|
||||
private final String brokerApiVersionHeader;
|
||||
|
||||
private final String apiVersion;
|
||||
|
||||
/**
|
||||
* Specify the name of the service broker API version header and the API version supported by the service broker.
|
||||
*
|
||||
* @param apiVersionHeader the name of the HTTP header field expected to contain the
|
||||
* service broker API version of the service broker client
|
||||
* @param apiVersion the version of the service broker API supported by the broker; a value of
|
||||
* {@literal null} or {@literal API_VERSION_ANY} will disable API version validation
|
||||
*/
|
||||
public BrokerApiVersion(String apiVersionHeader, String apiVersion) {
|
||||
this.brokerApiVersionHeader = apiVersionHeader;
|
||||
this.apiVersion = apiVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the service broker API version supported by the service broker.
|
||||
*
|
||||
* @param apiVersion the version of the broker API supported by the broker; a value of {@literal null}
|
||||
* or {@literal API_VERSION_ANY} will disable API version validation
|
||||
*/
|
||||
public BrokerApiVersion(String apiVersion) {
|
||||
this(DEFAULT_API_VERSION_HEADER, apiVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify that service broker API validation should be disabled.
|
||||
*/
|
||||
public BrokerApiVersion() {
|
||||
this(API_VERSION_ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the service broker API version supported by the service broker.
|
||||
*
|
||||
* @return the service broker API version supported by the service broker
|
||||
*/
|
||||
public String getApiVersion() {
|
||||
return apiVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the service broker API version header.
|
||||
*
|
||||
* @return the name of the service broker API version header
|
||||
*/
|
||||
public String getBrokerApiVersionHeader() {
|
||||
return brokerApiVersionHeader;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* The catalog of services offered by the service broker.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@@ -41,4 +41,3 @@ public class Catalog {
|
||||
this.serviceDefinitions = serviceDefinitions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
/**
|
||||
* Details of a response to a request to create a new service instance binding for an application.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
* @author <A href="mailto:josh@joshlong.com">Josh Long</A>
|
||||
* @author Scott Frederick
|
||||
@@ -15,7 +15,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
/**
|
||||
* Details of a request to bind to a service instance binding.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@@ -102,7 +102,7 @@ public class CreateServiceInstanceBindingRequest extends ServiceBrokerRequest {
|
||||
context = null;
|
||||
parameters = null;
|
||||
}
|
||||
|
||||
|
||||
public CreateServiceInstanceBindingRequest(String serviceDefinitionId, String planId,
|
||||
BindResource bindResource, Context context,
|
||||
Map<String, Object> parameters) {
|
||||
@@ -9,7 +9,7 @@ import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Details of a response to a service instance binding create request.
|
||||
*
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@Getter
|
||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Details of a request to create a new service instance.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@@ -9,7 +9,7 @@ import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Details of a response to a request to create a new service instance binding for a route.
|
||||
*
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@Getter
|
||||
@@ -7,7 +7,7 @@ import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Used to send errors back to the cloud controller.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*/
|
||||
@Getter
|
||||
@@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
/**
|
||||
* An instance of a ServiceDefinition.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*
|
||||
* @deprecated This class is no longer used internally to represent service instances. Implementing brokers should
|
||||
@@ -19,23 +19,23 @@ public class ServiceInstance {
|
||||
@JsonSerialize
|
||||
@JsonProperty("service_instance_id")
|
||||
private String serviceInstanceId;
|
||||
|
||||
|
||||
@JsonSerialize
|
||||
@JsonProperty("service_id")
|
||||
private String serviceDefinitionId;
|
||||
|
||||
|
||||
@JsonSerialize
|
||||
@JsonProperty("plan_id")
|
||||
private String planId;
|
||||
|
||||
|
||||
@JsonSerialize
|
||||
@JsonProperty("organization_guid")
|
||||
private String organizationGuid;
|
||||
|
||||
|
||||
@JsonSerialize
|
||||
@JsonProperty("space_guid")
|
||||
private String spaceGuid;
|
||||
|
||||
|
||||
@JsonSerialize
|
||||
@JsonProperty("dashboard_url")
|
||||
private String dashboardUrl;
|
||||
@@ -43,16 +43,16 @@ public class ServiceInstance {
|
||||
@JsonSerialize
|
||||
@JsonProperty("last_operation")
|
||||
private GetLastServiceOperationResponse lastOperation;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
private boolean async;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private ServiceInstance() {}
|
||||
|
||||
|
||||
/**
|
||||
* Create a ServiceInstance from a create request. If fields
|
||||
* are not present in the request they will remain null in the
|
||||
* Create a ServiceInstance from a create request. If fields
|
||||
* are not present in the request they will remain null in the
|
||||
* ServiceInstance.
|
||||
* @param request containing details of ServiceInstance
|
||||
*/
|
||||
@@ -66,10 +66,10 @@ public class ServiceInstance {
|
||||
.withOperationState(OperationState.IN_PROGRESS)
|
||||
.withDescription("Provisioning");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a ServiceInstance from a delete request. If fields
|
||||
* are not present in the request they will remain null in the
|
||||
* Create a ServiceInstance from a delete request. If fields
|
||||
* are not present in the request they will remain null in the
|
||||
* ServiceInstance.
|
||||
* @param request containing details of ServiceInstance
|
||||
*/
|
||||
@@ -81,10 +81,10 @@ public class ServiceInstance {
|
||||
.withOperationState(OperationState.IN_PROGRESS)
|
||||
.withDescription("Deprovisioning");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a service instance from an update request. If fields
|
||||
* are not present in the request they will remain null in the
|
||||
* are not present in the request they will remain null in the
|
||||
* ServiceInstance.
|
||||
* @param request containing details of ServiceInstance
|
||||
*/
|
||||
@@ -95,7 +95,7 @@ public class ServiceInstance {
|
||||
.withOperationState(OperationState.IN_PROGRESS)
|
||||
.withDescription("Updating");
|
||||
}
|
||||
|
||||
|
||||
public String getServiceInstanceId() {
|
||||
return serviceInstanceId;
|
||||
}
|
||||
@@ -146,5 +146,5 @@ public class ServiceInstance {
|
||||
public GetLastServiceOperationResponse getServiceInstanceLastOperation() {
|
||||
return lastOperation;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* A binding to a service instance
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*
|
||||
* @deprecated This class is no longer used internally to represent service instance bindings. Implementing brokers should
|
||||
@@ -20,8 +20,8 @@ public class ServiceInstanceBinding {
|
||||
private String syslogDrainUrl;
|
||||
private String appGuid;
|
||||
|
||||
public ServiceInstanceBinding(String id,
|
||||
String serviceInstanceId,
|
||||
public ServiceInstanceBinding(String id,
|
||||
String serviceInstanceId,
|
||||
Map<String,Object> credentials,
|
||||
String syslogDrainUrl, String appGuid) {
|
||||
this.id = id;
|
||||
@@ -54,9 +54,9 @@ public class ServiceInstanceBinding {
|
||||
public String getSyslogDrainUrl() {
|
||||
return syslogDrainUrl;
|
||||
}
|
||||
|
||||
|
||||
public String getAppGuid() {
|
||||
return appGuid;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,26 +9,26 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* An implementation of the CatalogService that allows the Catalog to be specified as a Spring Bean.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*/
|
||||
public class BeanCatalogService implements CatalogService {
|
||||
|
||||
private Catalog catalog;
|
||||
private Map<String,ServiceDefinition> serviceDefs = new HashMap<String,ServiceDefinition>();
|
||||
|
||||
|
||||
@Autowired
|
||||
public BeanCatalogService(Catalog catalog) {
|
||||
this.catalog = catalog;
|
||||
initializeMap();
|
||||
}
|
||||
|
||||
|
||||
private void initializeMap() {
|
||||
for (ServiceDefinition def: catalog.getServiceDefinitions()) {
|
||||
serviceDefs.put(def.getId(), def);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Catalog getCatalog() {
|
||||
return catalog;
|
||||
@@ -5,7 +5,7 @@ import org.springframework.cloud.servicebroker.model.ServiceDefinition;
|
||||
|
||||
/**
|
||||
* This interface is implemented by service brokers to process requests to retrieve the service catalog.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
*/
|
||||
public interface CatalogService {
|
||||
@@ -24,5 +24,5 @@ public interface CatalogService {
|
||||
* @return the service definition, or null if it doesn't exist
|
||||
*/
|
||||
ServiceDefinition getServiceDefinition(String serviceId);
|
||||
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.springframework.cloud.servicebroker.model.DeleteServiceInstanceBindin
|
||||
|
||||
/**
|
||||
* This interface is implemented by service brokers to process requests to create and delete service instance bindings.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@@ -16,7 +16,7 @@ import org.springframework.cloud.servicebroker.model.UpdateServiceInstanceRespon
|
||||
/**
|
||||
* This interface is implemented by service brokers to process requests related to provisioning, updating,
|
||||
* and deprovisioning service instances.
|
||||
*
|
||||
*
|
||||
* @author sgreenberg@pivotal.io
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@@ -3,7 +3,7 @@ package org.springframework.cloud.servicebroker.model;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.DataFixture;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.cloud.servicebroker.model.CloudFoundryContext.CLOUD_FOUNDRY_PLATFORM;
|
||||
@@ -3,13 +3,14 @@ package org.springframework.cloud.servicebroker.model;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.DataFixture;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.cloud.servicebroker.model.CloudFoundryContext.CLOUD_FOUNDRY_PLATFORM;
|
||||
import static org.springframework.cloud.servicebroker.model.KubernetesContext.KUBERNETES_PLATFORM;
|
||||
|
||||
@SuppressWarnings({"deprecation", "DeprecatedIsStillUsed"})
|
||||
public class CreateServiceInstanceBindingRequestTest {
|
||||
@Test
|
||||
public void requestWithAppGuidBindingIsRead() {
|
||||
@@ -9,9 +9,9 @@ public class ServiceFixture {
|
||||
|
||||
public static ServiceDefinition getSimpleService() {
|
||||
return new ServiceDefinition(
|
||||
"service-one-id",
|
||||
"Service One",
|
||||
"Description for Service One",
|
||||
"service-one-id",
|
||||
"Service One",
|
||||
"Description for Service One",
|
||||
true,
|
||||
PlanFixture.getAllPlans());
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.cloud.servicebroker.service.impl;
|
||||
package org.springframework.cloud.servicebroker.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@@ -8,18 +8,17 @@ import java.util.List;
|
||||
|
||||
import org.springframework.cloud.servicebroker.model.Catalog;
|
||||
import org.springframework.cloud.servicebroker.model.ServiceDefinition;
|
||||
import org.springframework.cloud.servicebroker.service.BeanCatalogService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BeanCatalogServiceTest {
|
||||
|
||||
private BeanCatalogService service;
|
||||
|
||||
|
||||
private Catalog catalog;
|
||||
private ServiceDefinition serviceDefinition;
|
||||
private static final String SVC_DEF_ID = "svc-def-id";
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
serviceDefinition = new ServiceDefinition(SVC_DEF_ID, "Name", "Description", true, null);
|
||||
@@ -27,20 +26,20 @@ public class BeanCatalogServiceTest {
|
||||
catalog = new Catalog(defs);
|
||||
service = new BeanCatalogService(catalog);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void catalogIsReturnedSuccessfully() {
|
||||
assertEquals(catalog, service.getCatalog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itFindsServiceDefinition() {
|
||||
|
||||
@Test
|
||||
public void serviceDefinitionIsFound() {
|
||||
assertEquals(serviceDefinition, service.getServiceDefinition(SVC_DEF_ID));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void itDoesNotFindServiceDefinition() {
|
||||
public void serviceDefinitionIsNotFound() {
|
||||
assertNull(service.getServiceDefinition("NOT_THERE"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
31
spring-cloud-starter-service-broker-webmvc/build.gradle
Normal file
31
spring-cloud-starter-service-broker-webmvc/build.gradle
Normal file
@@ -0,0 +1,31 @@
|
||||
description = "Spring Cloud Service Broker Starter"
|
||||
|
||||
buildscript {
|
||||
ext {
|
||||
springBootVersion = "1.5.8.RELEASE"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
bootRepackage {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(":spring-cloud-open-service-broker")
|
||||
compile("org.springframework.boot:spring-boot-starter-web")
|
||||
compile("org.springframework.boot:spring-boot-starter-security")
|
||||
|
||||
testCompile project(path: ":spring-cloud-open-service-broker", configuration: 'testOutput')
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
testCompile("org.mockito:mockito-core:${mockitoVersion}")
|
||||
testCompile("org.hamcrest:hamcrest-library:${hamcrestVersion}")
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.servicebroker.webmvc.autoconfig;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.cloud.servicebroker.model.Catalog;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceService;
|
||||
import org.springframework.cloud.servicebroker.webmvc.interceptor.ApiVersionInterceptor;
|
||||
import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for the service broker API validation.
|
||||
* Configures support for any service broker API version if a version is not specifically
|
||||
* configured.
|
||||
*
|
||||
* @author Benjamin Ihrig
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnBean({ Catalog.class, ServiceInstanceService.class })
|
||||
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
||||
public class ApiVersionAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(BrokerApiVersion.class)
|
||||
public BrokerApiVersion serviceBrokerApiVersion() {
|
||||
return new BrokerApiVersion();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApiVersionInterceptor serviceBrokerApiVersionInterceptor(BrokerApiVersion brokerApiVersion) {
|
||||
return new ApiVersionInterceptor(brokerApiVersion);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApiVersionWebMvcConfigurerAdapter serviceBrokerWebMvcConfigurerAdapter(
|
||||
ApiVersionInterceptor apiVersionInterceptor) {
|
||||
return new ApiVersionWebMvcConfigurerAdapter(
|
||||
apiVersionInterceptor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.servicebroker.webmvc.autoconfig;
|
||||
|
||||
import org.springframework.cloud.servicebroker.webmvc.interceptor.ApiVersionInterceptor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
/**
|
||||
* {@link WebMvcConfigurerAdapter} that configures checking for an appropriate service broker API version.
|
||||
*
|
||||
* @author Scott Frederick
|
||||
* @author Benjamin Ihrig
|
||||
*/
|
||||
public class ApiVersionWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
|
||||
private static final String V2_API_PATH_PATTERN = "/v2/**";
|
||||
|
||||
private final ApiVersionInterceptor apiVersionInterceptor;
|
||||
|
||||
ApiVersionWebMvcConfigurerAdapter(ApiVersionInterceptor apiVersionInterceptor) {
|
||||
this.apiVersionInterceptor = apiVersionInterceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(apiVersionInterceptor).addPathPatterns(V2_API_PATH_PATTERN);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.servicebroker.webmvc.autoconfig;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.cloud.servicebroker.model.Catalog;
|
||||
import org.springframework.cloud.servicebroker.service.BeanCatalogService;
|
||||
import org.springframework.cloud.servicebroker.service.CatalogService;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.cloud.servicebroker.service.NonBindableServiceInstanceBindingService;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for the service broker implementation beans.
|
||||
*
|
||||
* Provides a default {@link CatalogService} bean if a {@link Catalog} bean is provided.
|
||||
*
|
||||
* Provides a {@link NonBindableServiceInstanceBindingService} if a {@link ServiceInstanceBindingService}
|
||||
* is not provided, indicating that the service broker provides no bindable services.
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnBean({ Catalog.class, ServiceInstanceService.class })
|
||||
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
||||
public class ServiceBrokerAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(CatalogService.class)
|
||||
public CatalogService beanCatalogService(Catalog catalog) {
|
||||
return new BeanCatalogService(catalog);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ServiceInstanceBindingService.class)
|
||||
public ServiceInstanceBindingService nonBindableServiceInstanceBindingService() {
|
||||
return new NonBindableServiceInstanceBindingService();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.servicebroker.webmvc.autoconfig;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.cloud.servicebroker.controller.CatalogController;
|
||||
import org.springframework.cloud.servicebroker.controller.ServiceInstanceBindingController;
|
||||
import org.springframework.cloud.servicebroker.controller.ServiceInstanceController;
|
||||
import org.springframework.cloud.servicebroker.model.Catalog;
|
||||
import org.springframework.cloud.servicebroker.service.CatalogService;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for the service broker REST API endpoints.
|
||||
*
|
||||
* @author Benjamin Ihrig
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnBean({ Catalog.class, ServiceInstanceService.class })
|
||||
@AutoConfigureAfter(ServiceBrokerAutoConfiguration.class)
|
||||
public class ServiceBrokerWebMvcAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public CatalogController catalogController(CatalogService catalogService) {
|
||||
return new CatalogController(catalogService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServiceInstanceController serviceInstanceController(
|
||||
CatalogService catalogService,
|
||||
ServiceInstanceService serviceInstanceService) {
|
||||
return new ServiceInstanceController(catalogService, serviceInstanceService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServiceInstanceBindingController serviceInstanceBindingController(
|
||||
CatalogService catalogService,
|
||||
ServiceInstanceBindingService serviceInstanceBindingService) {
|
||||
return new ServiceInstanceBindingController(catalogService, serviceInstanceBindingService);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.servicebroker.webmvc.interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerApiVersionException;
|
||||
import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
/**
|
||||
* {@link HandlerInterceptor} that inspects the service broker API version passed in all request headers
|
||||
* and compares it to the API version supported by the broker.
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
public class ApiVersionInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
private final BrokerApiVersion version;
|
||||
|
||||
/**
|
||||
* Construct an interceptor that disables API version validation.
|
||||
*/
|
||||
public ApiVersionInterceptor() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an interceptor that validates the API version passed in request headers to the
|
||||
* configured version.
|
||||
*
|
||||
* @param version the API version supported by the broker.
|
||||
*/
|
||||
public ApiVersionInterceptor(BrokerApiVersion version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the service broker API version header to the supported version.
|
||||
*
|
||||
* @param request {@inheritDoc}
|
||||
* @param response {@inheritDoc}
|
||||
* @param handler {@inheritDoc}
|
||||
* @throws ServiceBrokerApiVersionException if the API version header value does not match the version
|
||||
* supported by the broker
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws ServiceBrokerApiVersionException {
|
||||
if (version != null && !anyVersionAllowed()) {
|
||||
String apiVersion = request.getHeader(version.getBrokerApiVersionHeader());
|
||||
if (!version.getApiVersion().equals(apiVersion)) {
|
||||
throw new ServiceBrokerApiVersionException(version.getApiVersion(), apiVersion);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean anyVersionAllowed() {
|
||||
return BrokerApiVersion.API_VERSION_ANY.equals(version.getApiVersion());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.servicebroker.webvmc.autoconfig.ServiceBrokerAutoConfiguration,\
|
||||
org.springframework.cloud.servicebroker.webvmc.autoconfig.ServiceBrokerWebMvcAutoConfiguration,\
|
||||
org.springframework.cloud.servicebroker.webvmc.autoconfig.ApiVersionAutoConfiguration
|
||||
@@ -1,33 +1,37 @@
|
||||
package org.springframework.cloud.servicebroker.controller;
|
||||
package org.springframework.cloud.servicebroker.webmvc.integration;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.cloud.servicebroker.controller.CatalogController;
|
||||
import org.springframework.cloud.servicebroker.model.Catalog;
|
||||
import org.springframework.cloud.servicebroker.model.Plan;
|
||||
import org.springframework.cloud.servicebroker.model.ServiceDefinition;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.PlanFixture;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.ServiceFixture;
|
||||
import org.springframework.cloud.servicebroker.service.CatalogService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||
import static org.hamcrest.collection.IsEmptyCollection.empty;
|
||||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
|
||||
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.cloud.servicebroker.model.ServiceDefinitionRequires.SERVICE_REQUIRES_ROUTE_FORWARDING;
|
||||
import static org.springframework.cloud.servicebroker.model.ServiceDefinitionRequires.SERVICE_REQUIRES_SYSLOG_DRAIN;
|
||||
import static org.springframework.cloud.servicebroker.model.fixture.CatalogFixture.getCatalog;
|
||||
import static org.springframework.cloud.servicebroker.model.fixture.CatalogFixture.getCatalogWithRequires;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
@@ -67,7 +71,7 @@ public class CatalogControllerIntegrationTest {
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$.services.", hasSize(1)))
|
||||
.andExpect(jsonPath("$.services", hasSize(1)))
|
||||
.andExpect(jsonPath("$.services[*].id", contains(service.getId())))
|
||||
.andExpect(jsonPath("$.services[*].name", contains(service.getName())))
|
||||
.andExpect(jsonPath("$.services[*].description", contains(service.getDescription())))
|
||||
@@ -98,7 +102,7 @@ public class CatalogControllerIntegrationTest {
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$.services.", hasSize(1)))
|
||||
.andExpect(jsonPath("$.services", hasSize(1)))
|
||||
.andExpect(jsonPath("$.services[*].id", contains(service.getId())))
|
||||
.andExpect(jsonPath("$.services[*].name", contains(service.getName())))
|
||||
.andExpect(jsonPath("$.services[*].description", contains(service.getDescription())))
|
||||
@@ -133,7 +137,7 @@ public class CatalogControllerIntegrationTest {
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$.services.", hasSize(1)))
|
||||
.andExpect(jsonPath("$.services", hasSize(1)))
|
||||
.andExpect(jsonPath("$.services[*].id", contains(service.getId())))
|
||||
.andExpect(jsonPath("$.services[*].name", contains(service.getName())))
|
||||
.andExpect(jsonPath("$.services[*].description", contains(service.getDescription())))
|
||||
@@ -1,17 +1,18 @@
|
||||
package org.springframework.cloud.servicebroker.controller;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.ServiceFixture;
|
||||
import org.springframework.cloud.servicebroker.service.CatalogService;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.security.crypto.codec.Base64;
|
||||
package org.springframework.cloud.servicebroker.webmvc.integration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.Matchers.eq;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import org.springframework.cloud.servicebroker.model.fixture.ServiceFixture;
|
||||
import org.springframework.cloud.servicebroker.service.CatalogService;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.security.crypto.codec.Base64;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public abstract class ControllerIntegrationTest {
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.springframework.cloud.servicebroker.controller;
|
||||
package org.springframework.cloud.servicebroker.webmvc.integration;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.servicebroker.controller.ServiceInstanceBindingController;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.DataFixture;
|
||||
import org.springframework.cloud.servicebroker.service.NonBindableServiceInstanceBindingService;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService;
|
||||
@@ -1,36 +1,36 @@
|
||||
package org.springframework.cloud.servicebroker.controller;
|
||||
package org.springframework.cloud.servicebroker.webmvc.integration;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.cloud.servicebroker.controller.ServiceInstanceBindingController;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingDoesNotExistException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingExistsException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException;
|
||||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceAppBindingResponse;
|
||||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceRouteBindingResponse;
|
||||
import org.springframework.cloud.servicebroker.model.DeleteServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.SharedVolumeDevice;
|
||||
import org.springframework.cloud.servicebroker.model.VolumeMount;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.DataFixture;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.ServiceInstanceBindingFixture;
|
||||
import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.StringContains.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -45,10 +45,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInstanceBindingIntegrationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
|
||||
@InjectMocks
|
||||
private ServiceInstanceBindingController controller;
|
||||
|
||||
|
||||
@Mock
|
||||
private ServiceInstanceBindingService serviceInstanceBindingService;
|
||||
|
||||
@@ -77,8 +77,8 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
.andExpect(jsonPath("$.credentials.uri", is(createResponse.getCredentials().get("uri"))))
|
||||
.andExpect(jsonPath("$.credentials.username", is(createResponse.getCredentials().get("username"))))
|
||||
.andExpect(jsonPath("$.credentials.password", is(createResponse.getCredentials().get("password"))))
|
||||
.andExpect(jsonPath("$.syslog_drain_url", nullValue()))
|
||||
.andExpect(jsonPath("$.route_service_url", nullValue()));
|
||||
.andExpect(jsonPath("$.syslog_drain_url").doesNotExist())
|
||||
.andExpect(jsonPath("$.route_service_url").doesNotExist());
|
||||
|
||||
CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding();
|
||||
assertNull(actualRequest.getCfInstanceId());
|
||||
@@ -106,8 +106,8 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
.andExpect(jsonPath("$.credentials.uri", is(createResponse.getCredentials().get("uri"))))
|
||||
.andExpect(jsonPath("$.credentials.username", is(createResponse.getCredentials().get("username"))))
|
||||
.andExpect(jsonPath("$.credentials.password", is(createResponse.getCredentials().get("password"))))
|
||||
.andExpect(jsonPath("$.syslog_drain_url", nullValue()))
|
||||
.andExpect(jsonPath("$.route_service_url", nullValue()));
|
||||
.andExpect(jsonPath("$.syslog_drain_url").doesNotExist())
|
||||
.andExpect(jsonPath("$.route_service_url").doesNotExist());
|
||||
|
||||
CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding();
|
||||
assertEquals(CF_INSTANCE_ID, actualRequest.getCfInstanceId());
|
||||
@@ -135,9 +135,9 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
.andExpect(jsonPath("$.credentials.uri", is(createResponse.getCredentials().get("uri"))))
|
||||
.andExpect(jsonPath("$.credentials.username", is(createResponse.getCredentials().get("username"))))
|
||||
.andExpect(jsonPath("$.credentials.password", is(createResponse.getCredentials().get("password"))))
|
||||
.andExpect(jsonPath("$.syslog_drain_url", nullValue()))
|
||||
.andExpect(jsonPath("$.volume_mounts", nullValue()))
|
||||
.andExpect(jsonPath("$.route_service_url", nullValue()));
|
||||
.andExpect(jsonPath("$.syslog_drain_url").doesNotExist())
|
||||
.andExpect(jsonPath("$.volume_mounts").doesNotExist())
|
||||
.andExpect(jsonPath("$.route_service_url").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,9 +155,9 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.credentials", nullValue()))
|
||||
.andExpect(jsonPath("$.syslog_drain_url", nullValue()))
|
||||
.andExpect(jsonPath("$.volume_mounts", nullValue()))
|
||||
.andExpect(jsonPath("$.credentials").doesNotExist())
|
||||
.andExpect(jsonPath("$.syslog_drain_url").doesNotExist())
|
||||
.andExpect(jsonPath("$.volume_mounts").doesNotExist())
|
||||
.andExpect(jsonPath("$.route_service_url", is(response.getRouteServiceUrl())));
|
||||
}
|
||||
|
||||
@@ -178,9 +178,9 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.credentials", nullValue()))
|
||||
.andExpect(jsonPath("$.syslog_drain_url", nullValue()))
|
||||
.andExpect(jsonPath("$.volume_mounts", nullValue()))
|
||||
.andExpect(jsonPath("$.credentials").doesNotExist())
|
||||
.andExpect(jsonPath("$.syslog_drain_url").doesNotExist())
|
||||
.andExpect(jsonPath("$.volume_mounts").doesNotExist())
|
||||
.andExpect(jsonPath("$.route_service_url", is(response.getRouteServiceUrl())));
|
||||
}
|
||||
|
||||
@@ -202,8 +202,8 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
.andExpect(jsonPath("$.credentials.username", is(response.getCredentials().get("username"))))
|
||||
.andExpect(jsonPath("$.credentials.password", is(response.getCredentials().get("password"))))
|
||||
.andExpect(jsonPath("$.syslog_drain_url", is(response.getSyslogDrainUrl())))
|
||||
.andExpect(jsonPath("$.volume_mounts", nullValue()))
|
||||
.andExpect(jsonPath("$.route_service_url", nullValue()));
|
||||
.andExpect(jsonPath("$.volume_mounts").doesNotExist())
|
||||
.andExpect(jsonPath("$.route_service_url").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,8 +223,8 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.credentials", nullValue()))
|
||||
.andExpect(jsonPath("$.syslog_drain_url", nullValue()))
|
||||
.andExpect(jsonPath("$.credentials").doesNotExist())
|
||||
.andExpect(jsonPath("$.syslog_drain_url").doesNotExist())
|
||||
.andExpect(jsonPath("$.volume_mounts[0].driver", is(volumeMount.getDriver())))
|
||||
.andExpect(jsonPath("$.volume_mounts[0].container_dir", is(volumeMount.getContainerDir())))
|
||||
.andExpect(jsonPath("$.volume_mounts[0].mode", is(volumeMount.getMode().toString())))
|
||||
@@ -363,7 +363,7 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
|
||||
@Test
|
||||
public void deleteBindingWithUnknownBindingIdFails() throws Exception {
|
||||
Mockito.doThrow(new ServiceInstanceBindingDoesNotExistException(deleteRequest.getBindingId()))
|
||||
doThrow(new ServiceInstanceBindingDoesNotExistException(deleteRequest.getBindingId()))
|
||||
.when(serviceInstanceBindingService).deleteServiceInstanceBinding(eq(deleteRequest));
|
||||
|
||||
setupCatalogService(deleteRequest.getServiceDefinitionId());
|
||||
@@ -388,13 +388,13 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ServiceInst
|
||||
|
||||
private CreateServiceInstanceBindingRequest verifyCreateBinding() {
|
||||
ArgumentCaptor<CreateServiceInstanceBindingRequest> argumentCaptor = ArgumentCaptor.forClass(CreateServiceInstanceBindingRequest.class);
|
||||
Mockito.verify(serviceInstanceBindingService).createServiceInstanceBinding(argumentCaptor.capture());
|
||||
verify(serviceInstanceBindingService).createServiceInstanceBinding(argumentCaptor.capture());
|
||||
return argumentCaptor.getValue();
|
||||
}
|
||||
|
||||
private DeleteServiceInstanceBindingRequest verifyDeleteBinding() {
|
||||
ArgumentCaptor<DeleteServiceInstanceBindingRequest> argumentCaptor = ArgumentCaptor.forClass(DeleteServiceInstanceBindingRequest.class);
|
||||
Mockito.verify(serviceInstanceBindingService).deleteServiceInstanceBinding(argumentCaptor.capture());
|
||||
verify(serviceInstanceBindingService).deleteServiceInstanceBinding(argumentCaptor.capture());
|
||||
return argumentCaptor.getValue();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.cloud.servicebroker.controller;
|
||||
package org.springframework.cloud.servicebroker.webmvc.integration;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.DeleteServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.fixture.ServiceInstanceBindingFixture;
|
||||
@@ -1,22 +1,15 @@
|
||||
package org.springframework.cloud.servicebroker.controller;
|
||||
package org.springframework.cloud.servicebroker.webmvc.integration;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.cloud.servicebroker.model.ServiceBrokerRequest.API_INFO_LOCATION_HEADER;
|
||||
import static org.springframework.cloud.servicebroker.model.ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.cloud.servicebroker.controller.ServiceInstanceController;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerAsyncRequiredException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerInvalidParametersException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException;
|
||||
@@ -41,6 +34,24 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.StringContains.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.cloud.servicebroker.model.ServiceBrokerRequest.API_INFO_LOCATION_HEADER;
|
||||
import static org.springframework.cloud.servicebroker.model.ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrationTest {
|
||||
|
||||
@@ -226,7 +237,7 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isUnprocessableEntity())
|
||||
.andExpect(jsonPath("$.error", org.hamcrest.Matchers.is(AsyncRequiredErrorMessage.ASYNC_REQUIRED_ERROR)))
|
||||
.andExpect(jsonPath("$.error", is(AsyncRequiredErrorMessage.ASYNC_REQUIRED_ERROR)))
|
||||
.andExpect(jsonPath("$.description", is("async required description")));
|
||||
}
|
||||
|
||||
@@ -248,9 +259,6 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
|
||||
@Test
|
||||
public void createServiceInstanceWithInvalidFieldsFails() throws Exception {
|
||||
when(serviceInstanceService.createServiceInstance(eq(syncCreateRequest)))
|
||||
.thenReturn(syncCreateResponse);
|
||||
|
||||
setupCatalogService(syncCreateRequest.getServiceDefinitionId());
|
||||
|
||||
String body = DataFixture.toJson(syncCreateRequest);
|
||||
@@ -267,9 +275,6 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
|
||||
@Test
|
||||
public void createServiceInstanceWithMissingFieldsFails() throws Exception {
|
||||
when(serviceInstanceService.createServiceInstance(any(CreateServiceInstanceRequest.class)))
|
||||
.thenReturn(syncCreateResponse);
|
||||
|
||||
String body = "{}";
|
||||
|
||||
mockMvc.perform(put(buildUrl(syncCreateRequest, false))
|
||||
@@ -286,9 +291,6 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
|
||||
@Test
|
||||
public void createServiceInstanceWithMissingIdentityPropertiesFails() throws Exception {
|
||||
when(serviceInstanceService.createServiceInstance(eq(syncCreateRequest)))
|
||||
.thenReturn(syncCreateResponse);
|
||||
|
||||
setupCatalogService(syncCreateRequest.getServiceDefinitionId());
|
||||
|
||||
mockMvc.perform(put(buildUrl(syncCreateRequest, false))
|
||||
@@ -304,9 +306,6 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
|
||||
@Test
|
||||
public void createServiceInstanceWithMalformedIdentityPropertiesFails() throws Exception {
|
||||
when(serviceInstanceService.createServiceInstance(eq(syncCreateRequest)))
|
||||
.thenReturn(syncCreateResponse);
|
||||
|
||||
setupCatalogService(syncCreateRequest.getServiceDefinitionId());
|
||||
|
||||
mockMvc.perform(put(buildUrl(syncCreateRequest, false))
|
||||
@@ -416,7 +415,7 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isUnprocessableEntity())
|
||||
.andExpect(jsonPath("$.error", org.hamcrest.Matchers.is(AsyncRequiredErrorMessage.ASYNC_REQUIRED_ERROR)))
|
||||
.andExpect(jsonPath("$.error", is(AsyncRequiredErrorMessage.ASYNC_REQUIRED_ERROR)))
|
||||
.andExpect(jsonPath("$.description", is("async required description")));
|
||||
}
|
||||
|
||||
@@ -497,7 +496,7 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isUnprocessableEntity())
|
||||
.andExpect(jsonPath("$.error", org.hamcrest.Matchers.is(AsyncRequiredErrorMessage.ASYNC_REQUIRED_ERROR)))
|
||||
.andExpect(jsonPath("$.error", is(AsyncRequiredErrorMessage.ASYNC_REQUIRED_ERROR)))
|
||||
.andExpect(jsonPath("$.description", is("async required description")));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.springframework.cloud.servicebroker.interceptor;
|
||||
package org.springframework.cloud.servicebroker.webmvc.interceptor;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.cloud.servicebroker.model.BrokerApiVersion.DEFAULT_API_VERSION_HEADER;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.servicebroker.controller.CatalogController;
|
||||
import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
|
||||
import org.springframework.cloud.servicebroker.service.CatalogService;
|
||||
@@ -13,14 +13,13 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BrokerApiVersionInterceptorIntegrationTest {
|
||||
public class ApiVersionInterceptorIntegrationTest {
|
||||
|
||||
private final static String CATALOG_PATH = "/v2/catalog";
|
||||
|
||||
@@ -35,23 +34,23 @@ public class BrokerApiVersionInterceptorIntegrationTest {
|
||||
mockWithExpectedVersion().perform(get(CATALOG_PATH)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isPreconditionFailed())
|
||||
.andExpect(jsonPath("$.description.", containsString("expected-version")));
|
||||
.andExpect(jsonPath("$.description", containsString("expected-version")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incorrectHeaderSent() throws Exception {
|
||||
mockWithExpectedVersion().perform(get(CATALOG_PATH)
|
||||
.header(DEFAULT_API_VERSION_HEADER, "wrong-version")
|
||||
.header(BrokerApiVersion.DEFAULT_API_VERSION_HEADER, "wrong-version")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isPreconditionFailed())
|
||||
.andExpect(jsonPath("$.description.", containsString("expected-version")))
|
||||
.andExpect(jsonPath("$.description.", containsString("wrong-version")));
|
||||
.andExpect(jsonPath("$.description", containsString("expected-version")))
|
||||
.andExpect(jsonPath("$.description", containsString("wrong-version")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchingHeaderSent() throws Exception {
|
||||
mockWithExpectedVersion().perform(get(CATALOG_PATH)
|
||||
.header(DEFAULT_API_VERSION_HEADER, "expected-version")
|
||||
.header(BrokerApiVersion.DEFAULT_API_VERSION_HEADER, "expected-version")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
@@ -66,20 +65,20 @@ public class BrokerApiVersionInterceptorIntegrationTest {
|
||||
@Test
|
||||
public void anyHeaderSent() throws Exception {
|
||||
mockWithDefaultVersion().perform(get(CATALOG_PATH)
|
||||
.header(DEFAULT_API_VERSION_HEADER, "ignored-version")
|
||||
.header(BrokerApiVersion.DEFAULT_API_VERSION_HEADER, "ignored-version")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
private MockMvc mockWithDefaultVersion() {
|
||||
return MockMvcBuilders.standaloneSetup(controller)
|
||||
.addInterceptors(new BrokerApiVersionInterceptor(new BrokerApiVersion()))
|
||||
.addInterceptors(new ApiVersionInterceptor(new BrokerApiVersion()))
|
||||
.setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
|
||||
}
|
||||
|
||||
private MockMvc mockWithExpectedVersion() {
|
||||
return MockMvcBuilders.standaloneSetup(controller)
|
||||
.addInterceptors(new BrokerApiVersionInterceptor(new BrokerApiVersion("expected-version")))
|
||||
.addInterceptors(new ApiVersionInterceptor(new BrokerApiVersion("expected-version")))
|
||||
.setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user