diff --git a/.editorconfig b/.editorconfig index d60f5ef..ede4e0b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,7 @@ [*] charset=utf-8 end_of_line=lf -insert_final_newline=false +insert_final_newline=true indent_style=tab indent_size=4 diff --git a/build.gradle b/build.gradle index e914236..6dcc967 100644 --- a/build.gradle +++ b/build.gradle @@ -27,12 +27,38 @@ buildscript { } } +ext { + springBootVersion = project.findProperty("springBootVersion") ?: "2.1.10.RELEASE" + springFrameworkVersion = project.findProperty("springFrameworkVersion") ?: "5.1.11.RELEASE" + reactorVersion = project.findProperty("reactorVersion") ?: "Californium-SR13" + openServiceBrokerVersion = "3.0.4.RELEASE" + springCredhubVersion = "2.0.1.RELEASE" + cfJavaClientVersion = "3.16.0.RELEASE" + checkstyleVersion = "8.21" + pmdVersion = "6.19.0" + + javadocLinks = [ + "https://docs.oracle.com/javase/8/docs/api/", + "https://docs.spring.io/spring/docs/${springFrameworkVersion}/javadoc-api/", + ] as String[] +} + +//override managed Spring Boot versions +if (project.hasProperty("springFrameworkVersion")) { + ext['spring-framework.version'] = ext.springFrameworkVersion +} +if (project.hasProperty("reactorVersion")) { + ext['reactor-bom.version'] = ext.reactorVersion +} + // NoHttp has to be applied at the root level // so that it reads all the root files, including the gradle ones. apply plugin: "io.spring.nohttp" +// nohttp requires a valid checkstyle configuration checkstyle { - toolVersion = 8.16 + configFile = file("${project.rootDir}/src/checkstyle/checkstyle-nohttp.xml") + toolVersion = "${checkstyleVersion}" } configure(allprojects) { @@ -49,22 +75,7 @@ configure(allprojects) { apply plugin: "propdeps-eclipse" apply plugin: "io.spring.dependency-management" - ext { - springBootVersion = project.findProperty("springBootVersion") ?: "2.1.10.RELEASE" - springVersion = project.findProperty("springFrameworkVersion") ?: "5.1.11.RELEASE" - reactorVersion = project.findProperty("reactorVersion") ?: "Californium-SR13" - openServiceBrokerVersion = "3.0.4.RELEASE" - springCredhubVersion = "2.0.1.RELEASE" - cfJavaClientVersion = "3.16.0.RELEASE" - } - - //override managed Spring Boot versions - if (project.hasProperty("springFrameworkVersion")) { - ext['spring-framework.version'] = ext.springFrameworkVersion - } - if (project.hasProperty("reactorVersion")) { - ext['reactor-bom.version'] = ext.reactorVersion - } + apply from: "${rootProject.projectDir}/publish-maven.gradle" repositories { mavenCentral() @@ -80,51 +91,36 @@ configure(allprojects) { maven { url "https://repo.spring.io/libs-snapshot" } } } - - ext.javadocLinks = [ - "https://docs.oracle.com/javase/8/docs/api/", - "https://docs.spring.io/spring/docs/${springFrameworkVersion}/javadoc-api/", - ] as String[] } -subprojects { - apply from: "${rootProject.projectDir}/publish-maven.gradle" -} +configure(allprojects - [project(":spring-cloud-app-broker-docs")]) { + apply plugin: "checkstyle" + apply plugin: "pmd" -configure(subprojects - [project(":spring-cloud-starter-app-broker"), - project(":spring-cloud-starter-app-broker-cloudfoundry")]) { - compileJava { - sourceCompatibility=1.8 - targetCompatibility=1.8 - options.encoding = "UTF-8" + checkstyle { + configFile = file("${project.rootDir}/src/checkstyle/checkstyle.xml") + toolVersion = "${checkstyleVersion}" } - compileTestJava { - sourceCompatibility=1.8 - targetCompatibility=1.8 - options.encoding = "UTF-8" + checkstyleMain { + source = "src/main/java" + } + checkstyleTest { + source = "src/test/java" } - [compileJava, compileTestJava]*.options*.compilerArgs = [ - "-Xlint:serial", - "-Xlint:varargs", - "-Xlint:cast", - "-Xlint:classfile", - "-Xlint:dep-ann", - "-Xlint:divzero", - "-Xlint:empty", - "-Xlint:finally", - "-Xlint:overrides", - "-Xlint:path", - "-Xlint:-processing", - "-Xlint:static", - "-Xlint:try", - "-Xlint:fallthrough", - "-Xlint:rawtypes", - "-Xlint:deprecation", - "-Xlint:unchecked", - "-Xlint:-options", - "-Werror" - ] + pmd { + toolVersion = "${pmdVersion}" + } + pmdMain { + ruleSets = [] + ruleSetFiles = files("${project.rootDir}/src/pmd/pmdRuleSet.xml") + source = "src/main/java" + } + pmdTest { + ruleSets = [] + ruleSetFiles = files("${project.rootDir}/src/pmd/pmdTestRuleSet.xml") + source = "src/test/java" + } test { // enable JUnit 5 @@ -160,21 +156,41 @@ configure(subprojects - [project(":spring-cloud-starter-app-broker"), afterSuite { failedTests.each { test -> println "FAILED test: ${test.className} > ${test.name}" } } - } +} - pmd { - ruleSetFiles = files("${project.rootDir}/ci/config/pmdRuleSet.xml") - } +subprojects { + task allDependencyInsight(type: DependencyInsightReportTask) + task dependencyReport(type: DependencyReportTask) +} - pmdTest { - ruleSetFiles = files("${project.rootDir}/ci/config/pmdTestRuleSet.xml") - } +configure(subprojects - [project(":spring-cloud-starter-app-broker"), + project(":spring-cloud-starter-app-broker-cloudfoundry")]) { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + [compileJava, compileTestJava]*.options*.encoding = "UTF-8" - checkstyle { - configDir = file("${project.rootDir}/ci/config/") - toolVersion = 8.16 - } + [compileJava, compileTestJava]*.options*.compilerArgs = [ + "-Xlint:serial", + "-Xlint:varargs", + "-Xlint:cast", + "-Xlint:classfile", + "-Xlint:dep-ann", + "-Xlint:divzero", + "-Xlint:empty", + "-Xlint:finally", + "-Xlint:overrides", + "-Xlint:path", + "-Xlint:-processing", + "-Xlint:static", + "-Xlint:try", + "-Xlint:fallthrough", + "-Xlint:rawtypes", + "-Xlint:deprecation", + "-Xlint:unchecked", + "-Xlint:-options", + "-Werror" + ] jar { manifest.attributes["Created-By"] = @@ -196,7 +212,7 @@ configure(subprojects - [project(":spring-cloud-starter-app-broker"), options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED options.author = true options.header = project.name - options.links(project.ext.javadocLinks) + options.links(javadocLinks) options.addStringOption('Xdoclint:none', '-quiet') } @@ -220,9 +236,6 @@ configure(subprojects - [project(":spring-cloud-starter-app-broker"), // exclude JUnit 4 globally, in favor of JUnit 5 testImplementation.exclude group: "junit", module: "junit" } - - task allDependencyInsight(type: DependencyInsightReportTask) {} - task allDependencies(type: DependencyReportTask) {} } configure(rootProject) { @@ -242,7 +255,7 @@ configure(rootProject) { options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED options.author = true options.header = rootProject.description - options.links(project.ext.javadocLinks) + options.links(javadocLinks) options.addStringOption('Xdoclint:none', '-quiet') source subprojects.collect { project -> diff --git a/ci/config/pmdRuleSet.xml b/ci/config/pmdRuleSet.xml deleted file mode 100644 index 1236862..0000000 --- a/ci/config/pmdRuleSet.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ci/config/pmdTestRuleSet.xml b/ci/config/pmdTestRuleSet.xml deleted file mode 100644 index d93ff3e..0000000 --- a/ci/config/pmdTestRuleSet.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/AppBrokerApplication.java b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/AppBrokerApplication.java index dbe8402..9051bb3 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/AppBrokerApplication.java +++ b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/AppBrokerApplication.java @@ -18,11 +18,69 @@ package org.springframework.cloud.appbroker.acceptance; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.appbroker.acceptance.services.NoOpCreateServiceInstanceWorkflow; +import org.springframework.cloud.appbroker.acceptance.services.NoOpDeleteServiceInstanceWorkflow; +import org.springframework.cloud.appbroker.acceptance.services.NoOpServiceInstanceBindingService; +import org.springframework.cloud.appbroker.acceptance.services.NoOpUpdateServiceInstanceWorkflow; +import org.springframework.cloud.appbroker.service.CreateServiceInstanceWorkflow; +import org.springframework.cloud.appbroker.service.DeleteServiceInstanceWorkflow; +import org.springframework.cloud.appbroker.service.UpdateServiceInstanceWorkflow; +import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService; +import org.springframework.context.annotation.Bean; +/** + * A Spring Boot application for running acceptance tests + */ @SpringBootApplication public class AppBrokerApplication { + /** + * main application entry point + * + * @param args the args + */ public static void main(String[] args) { SpringApplication.run(AppBrokerApplication.class, args); } + + /** + * A no-op CreateServiceInstanceWorkflow bean + * + * @return the bean + */ + @Bean + public CreateServiceInstanceWorkflow createServiceInstanceWorkflow() { + return new NoOpCreateServiceInstanceWorkflow(); + } + + /** + * A no-op UpdateServiceInstanceWorkflow bean + * + * @return the bean + */ + @Bean + public UpdateServiceInstanceWorkflow updateServiceInstanceWorkflow() { + return new NoOpUpdateServiceInstanceWorkflow(); + } + + /** + * A no-op DeleteServiceInstanceWorkflow bean + * + * @return the bean + */ + @Bean + public DeleteServiceInstanceWorkflow deleteServiceInstanceWorkflow() { + return new NoOpDeleteServiceInstanceWorkflow(); + } + + /** + * A no-op ServiceInstanceBindingService bean + * + * @return the bean + */ + @Bean + public ServiceInstanceBindingService serviceInstanceBindingService() { + return new NoOpServiceInstanceBindingService(); + } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/ManagementController.java b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/ManagementController.java index c4b04d4..d79c591 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/ManagementController.java +++ b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/ManagementController.java @@ -23,36 +23,69 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; +/** + * A controller for testing the {@link BackingAppManagementService} + */ @RestController public class ManagementController { private final BackingAppManagementService service; + /** + * Construct a new {@literal ManagementController} + * + * @param service the service to test + */ public ManagementController(BackingAppManagementService service) { this.service = service; } + /** + * Tests service start + * + * @param serviceInstanceId the id of the service to test + * @return a response + */ @GetMapping("/start/{serviceInstanceId}") public Mono startApplications(@PathVariable String serviceInstanceId) { return service.start(serviceInstanceId) .thenReturn("starting " + serviceInstanceId); } + /** + * Tests service stop + * + * @param serviceInstanceId the id of the service to test + * @return a response + */ @GetMapping("/stop/{serviceInstanceId}") public Mono stopApplications(@PathVariable String serviceInstanceId) { return service.stop(serviceInstanceId) .thenReturn("stopping " + serviceInstanceId); } + /** + * Tests service restart + * + * @param serviceInstanceId the id of the service to test + * @return a response + */ @GetMapping("/restart/{serviceInstanceId}") public Mono restartApplications(@PathVariable String serviceInstanceId) { return service.restart(serviceInstanceId) .thenReturn("restarting " + serviceInstanceId); } + /** + * Tests service restage + * + * @param serviceInstanceId the id of the service to test + * @return a response + */ @GetMapping("/restage/{serviceInstanceId}") public Mono restageApplications(@PathVariable String serviceInstanceId) { return service.restage(serviceInstanceId) .thenReturn("restaging " + serviceInstanceId); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpCreateServiceInstanceWorkflow.java b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpCreateServiceInstanceWorkflow.java index 9059648..a392186 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpCreateServiceInstanceWorkflow.java +++ b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpCreateServiceInstanceWorkflow.java @@ -18,17 +18,20 @@ package org.springframework.cloud.appbroker.acceptance.services; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import reactor.core.publisher.Mono; + import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.appbroker.service.CreateServiceInstanceWorkflow; import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest; import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse; import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse.CreateServiceInstanceResponseBuilder; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; -@Service +/** + * A no-op implementation of {@link CreateServiceInstanceWorkflow} + */ public class NoOpCreateServiceInstanceWorkflow implements CreateServiceInstanceWorkflow { - private static final Logger LOGGER = LoggerFactory.getLogger(NoOpCreateServiceInstanceWorkflow.class); + + private static final Logger LOG = LoggerFactory.getLogger(NoOpCreateServiceInstanceWorkflow.class); @Value("${spring.cloud.openservicebroker.catalog.services[1].id}") private String backingServiceId; @@ -40,14 +43,19 @@ public class NoOpCreateServiceInstanceWorkflow implements CreateServiceInstanceW @Override public Mono accept(CreateServiceInstanceRequest request) { - LOGGER.info("Got request to create service instance: " + request); + if (LOG.isInfoEnabled()) { + LOG.info("Got request to create service instance: " + request); + } return Mono.just(request.getServiceDefinitionId().equals(backingServiceId)); } @Override public Mono buildResponse(CreateServiceInstanceRequest request, - CreateServiceInstanceResponseBuilder responseBuilder) { - LOGGER.info("Got request to create service instance: " + request); + CreateServiceInstanceResponseBuilder responseBuilder) { + if (LOG.isInfoEnabled()) { + LOG.info("Got request to create service instance: " + request); + } return Mono.just(responseBuilder); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpDeleteServiceInstanceWorkflow.java b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpDeleteServiceInstanceWorkflow.java index 59719ef..7e804f9 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpDeleteServiceInstanceWorkflow.java +++ b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpDeleteServiceInstanceWorkflow.java @@ -16,16 +16,19 @@ package org.springframework.cloud.appbroker.acceptance.services; +import reactor.core.publisher.Mono; + import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.appbroker.service.DeleteServiceInstanceWorkflow; import org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest; import org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse; import org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse.DeleteServiceInstanceResponseBuilder; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; -@Service +/** + * A no-op implementation of {@link DeleteServiceInstanceWorkflow} + */ public class NoOpDeleteServiceInstanceWorkflow implements DeleteServiceInstanceWorkflow { + @Value("${spring.cloud.openservicebroker.catalog.services[1].id}") private String backingServiceId; @@ -41,7 +44,8 @@ public class NoOpDeleteServiceInstanceWorkflow implements DeleteServiceInstanceW @Override public Mono buildResponse(DeleteServiceInstanceRequest request, - DeleteServiceInstanceResponseBuilder responseBuilder) { + DeleteServiceInstanceResponseBuilder responseBuilder) { return Mono.just(responseBuilder); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpServiceInstanceBindingService.java b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpServiceInstanceBindingService.java index 65ba822..b944cef 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpServiceInstanceBindingService.java +++ b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpServiceInstanceBindingService.java @@ -16,24 +16,30 @@ package org.springframework.cloud.appbroker.acceptance.services; +import reactor.core.publisher.Mono; + import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse; import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest; import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse; import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingRequest; import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingResponse; import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; -@Service +/** + * A no-op implementation of {@link ServiceInstanceBindingService} + */ public class NoOpServiceInstanceBindingService implements ServiceInstanceBindingService { + @Override - public Mono createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) { + public Mono createServiceInstanceBinding( + CreateServiceInstanceBindingRequest request) { return Mono.just(CreateServiceInstanceAppBindingResponse.builder().build()); } @Override - public Mono deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request) { + public Mono deleteServiceInstanceBinding( + DeleteServiceInstanceBindingRequest request) { return Mono.just(DeleteServiceInstanceBindingResponse.builder().build()); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpUpdateServiceInstanceWorkflow.java b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpUpdateServiceInstanceWorkflow.java index bec0e8f..2b830fb 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpUpdateServiceInstanceWorkflow.java +++ b/spring-cloud-app-broker-acceptance-tests/src/main/java/org/springframework/cloud/appbroker/acceptance/services/NoOpUpdateServiceInstanceWorkflow.java @@ -16,16 +16,19 @@ package org.springframework.cloud.appbroker.acceptance.services; +import reactor.core.publisher.Mono; + import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.appbroker.service.UpdateServiceInstanceWorkflow; import org.springframework.cloud.servicebroker.model.instance.UpdateServiceInstanceRequest; import org.springframework.cloud.servicebroker.model.instance.UpdateServiceInstanceResponse; import org.springframework.cloud.servicebroker.model.instance.UpdateServiceInstanceResponse.UpdateServiceInstanceResponseBuilder; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; -@Service +/** + * A no-op implementation of {@link UpdateServiceInstanceWorkflow} + */ public class NoOpUpdateServiceInstanceWorkflow implements UpdateServiceInstanceWorkflow { + @Value("${spring.cloud.openservicebroker.catalog.services[1].id}") private String backingServiceId; @@ -41,7 +44,8 @@ public class NoOpUpdateServiceInstanceWorkflow implements UpdateServiceInstanceW @Override public Mono buildResponse(UpdateServiceInstanceRequest request, - UpdateServiceInstanceResponseBuilder responseBuilder) { + UpdateServiceInstanceResponseBuilder responseBuilder) { return Mono.just(responseBuilder); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AcceptanceTestProperties.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AcceptanceTestProperties.java similarity index 95% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AcceptanceTestProperties.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AcceptanceTestProperties.java index f88ba88..3d71865 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AcceptanceTestProperties.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AcceptanceTestProperties.java @@ -18,7 +18,7 @@ package org.springframework.cloud.appbroker.acceptance; import org.springframework.boot.context.properties.ConfigurationProperties; -@ConfigurationProperties(value = "tests") +@ConfigurationProperties("tests") public class AcceptanceTestProperties { private String brokerAppPath; diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppBrokerTestProperties.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppBrokerTestProperties.java similarity index 100% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppBrokerTestProperties.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppBrokerTestProperties.java diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementRestageAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementRestageAcceptanceTest.java similarity index 89% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementRestageAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementRestageAcceptanceTest.java index 35bdb1f..19613dc 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementRestageAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementRestageAcceptanceTest.java @@ -32,11 +32,14 @@ class AppManagementRestageAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String SUFFIX = "app-management-restage"; private static final String APP_1 = "app-1-" + SUFFIX; + private static final String APP_2 = "app-2" + SUFFIX; + private static final String SI_NAME = "si-managed" + SUFFIX; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -56,23 +59,23 @@ class AppManagementRestageAcceptanceTest extends CloudFoundryAcceptanceTest { @BeforeEach void setUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.createServiceInstance(PLAN_NAME, APP_SERVICE_NAME, SI_NAME, null)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.getServiceInstance(SI_NAME)) - .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) - .verifyComplete(); + .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) + .verifyComplete(); } @AfterEach void cleanUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(getApplications(APP_1, APP_2)) - .verifyError(); + .verifyError(); } @Test @@ -91,8 +94,8 @@ class AppManagementRestageAcceptanceTest extends CloudFoundryAcceptanceTest { assertThat(apps).extracting("runningInstances").containsOnly(1); StepVerifier.create(manageApps(SI_NAME, "restage")) - .assertNext(result -> assertThat(result).contains("restaging")) - .verifyComplete(); + .assertNext(result -> assertThat(result).contains("restaging")) + .verifyComplete(); List restagedApps = getApplications(APP_1, APP_2).block(); Date since1 = restagedApps.get(0).getInstanceDetails().get(0).getSince(); @@ -102,4 +105,4 @@ class AppManagementRestageAcceptanceTest extends CloudFoundryAcceptanceTest { assertThat(since2).isAfter(originallySince2); } -} \ No newline at end of file +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementRestartAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementRestartAcceptanceTest.java similarity index 88% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementRestartAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementRestartAcceptanceTest.java index 5ac0ac3..52f3796 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementRestartAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementRestartAcceptanceTest.java @@ -32,11 +32,14 @@ class AppManagementRestartAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String SUFFIX = "app-management-restart"; private static final String APP_1 = "app-1-" + SUFFIX; + private static final String APP_2 = "app-2" + SUFFIX; + private static final String SI_NAME = "si-managed" + SUFFIX; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -56,23 +59,23 @@ class AppManagementRestartAcceptanceTest extends CloudFoundryAcceptanceTest { @BeforeEach void setUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.createServiceInstance(PLAN_NAME, APP_SERVICE_NAME, SI_NAME, null)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.getServiceInstance(SI_NAME)) - .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) - .verifyComplete(); + .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) + .verifyComplete(); } @AfterEach void cleanUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(getApplications(APP_1, APP_2)) - .verifyError(); + .verifyError(); } @Test @@ -90,8 +93,8 @@ class AppManagementRestartAcceptanceTest extends CloudFoundryAcceptanceTest { Date originallySince2 = apps.get(1).getInstanceDetails().get(0).getSince(); StepVerifier.create(manageApps(SI_NAME, "restart")) - .assertNext(result -> assertThat(result).contains("restarting")) - .verifyComplete(); + .assertNext(result -> assertThat(result).contains("restarting")) + .verifyComplete(); List restagedApps = getApplications(APP_1, APP_2).block(); Date since1 = restagedApps.get(0).getInstanceDetails().get(0).getSince(); @@ -101,4 +104,4 @@ class AppManagementRestartAcceptanceTest extends CloudFoundryAcceptanceTest { assertThat(since2).isAfter(originallySince2); } -} \ No newline at end of file +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementStartAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementStartAcceptanceTest.java similarity index 78% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementStartAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementStartAcceptanceTest.java index 67c9368..bf59879 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementStartAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementStartAcceptanceTest.java @@ -28,11 +28,14 @@ class AppManagementStartAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String SUFFIX = "app-management-start"; private static final String APP_1 = "app-1-" + SUFFIX; + private static final String APP_2 = "app-2" + SUFFIX; + private static final String SI_NAME = "si-managed" + SUFFIX; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -52,23 +55,23 @@ class AppManagementStartAcceptanceTest extends CloudFoundryAcceptanceTest { @BeforeEach void setUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.createServiceInstance(PLAN_NAME, APP_SERVICE_NAME, SI_NAME, null)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.getServiceInstance(SI_NAME)) - .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) - .verifyComplete(); + .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) + .verifyComplete(); } @AfterEach void cleanUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(getApplications(APP_1, APP_2)) - .verifyError(); + .verifyError(); } @Test @@ -82,19 +85,20 @@ class AppManagementStartAcceptanceTest extends CloudFoundryAcceptanceTest { }) void startApps() { StepVerifier.create(cloudFoundryService.stopApplication(APP_1) - .then(cloudFoundryService.stopApplication(APP_2))) - .verifyComplete(); + .then(cloudFoundryService.stopApplication(APP_2))) + .verifyComplete(); StepVerifier.create(getApplications(APP_1, APP_2)) - .assertNext(apps -> assertThat(apps).extracting("runningInstances").containsOnly(0)) - .verifyComplete(); + .assertNext(apps -> assertThat(apps).extracting("runningInstances").containsOnly(0)) + .verifyComplete(); StepVerifier.create(manageApps(SI_NAME, "start")) - .assertNext(result -> assertThat(result).contains("starting")) - .verifyComplete(); + .assertNext(result -> assertThat(result).contains("starting")) + .verifyComplete(); StepVerifier.create(getApplications(APP_1, APP_2)) - .assertNext(apps -> assertThat(apps).extracting("runningInstances").containsOnly(1)) - .verifyComplete(); + .assertNext(apps -> assertThat(apps).extracting("runningInstances").containsOnly(1)) + .verifyComplete(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementStopAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementStopAcceptanceTest.java similarity index 83% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementStopAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementStopAcceptanceTest.java index ddcee63..1c0cf92 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/AppManagementStopAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/AppManagementStopAcceptanceTest.java @@ -28,11 +28,14 @@ class AppManagementStopAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String SUFFIX = "app-management-stop"; private static final String APP_1 = "app-1-" + SUFFIX; + private static final String APP_2 = "app-2" + SUFFIX; + private static final String SI_NAME = "si-managed" + SUFFIX; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -52,23 +55,23 @@ class AppManagementStopAcceptanceTest extends CloudFoundryAcceptanceTest { @BeforeEach void setUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.createServiceInstance(PLAN_NAME, APP_SERVICE_NAME, SI_NAME, null)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(cloudFoundryService.getServiceInstance(SI_NAME)) - .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) - .verifyComplete(); + .assertNext(serviceInstance -> assertThat(serviceInstance.getStatus()).isEqualTo("succeeded")) + .verifyComplete(); } @AfterEach void cleanUp() { StepVerifier.create(cloudFoundryService.deleteServiceInstance(SI_NAME)) - .verifyComplete(); + .verifyComplete(); StepVerifier.create(getApplications(APP_1, APP_2)) - .verifyError(); + .verifyError(); } @Test @@ -82,11 +85,12 @@ class AppManagementStopAcceptanceTest extends CloudFoundryAcceptanceTest { }) void stopApps() { StepVerifier.create(manageApps(SI_NAME, "stop")) - .assertNext(result -> assertThat(result).contains("stopping")) - .verifyComplete(); + .assertNext(result -> assertThat(result).contains("stopping")) + .verifyComplete(); StepVerifier.create(getApplications(APP_1, APP_2)) - .assertNext(apps -> assertThat(apps).extracting("runningInstances").containsOnly(0)) - .verifyComplete(); + .assertNext(apps -> assertThat(apps).extracting("runningInstances").containsOnly(0)) + .verifyComplete(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/BrokerProperties.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/BrokerProperties.java similarity index 61% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/BrokerProperties.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/BrokerProperties.java index dc52cf4..d57baea 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/BrokerProperties.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/BrokerProperties.java @@ -16,15 +16,27 @@ package org.springframework.cloud.appbroker.acceptance; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.springframework.util.CollectionUtils; + class BrokerProperties { - private final String[] properties; + private final List properties = new ArrayList<>(); - BrokerProperties(String... properties) { - this.properties = properties; + public BrokerProperties(List properties) { + if (!CollectionUtils.isEmpty(properties)) { + this.properties.addAll(properties); + } } - String[] getProperties() { + public BrokerProperties(String... properties) { + this(Arrays.asList(properties)); + } + + public List getProperties() { return properties; } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/BrokerPropertiesParameterResolver.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/BrokerPropertiesParameterResolver.java similarity index 83% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/BrokerPropertiesParameterResolver.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/BrokerPropertiesParameterResolver.java index ae86d4e..23a47f1 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/BrokerPropertiesParameterResolver.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/BrokerPropertiesParameterResolver.java @@ -18,6 +18,7 @@ package org.springframework.cloud.appbroker.acceptance; import java.lang.reflect.Method; import java.util.Optional; + import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.api.extension.ParameterResolutionException; @@ -25,13 +26,17 @@ import org.junit.jupiter.api.extension.ParameterResolver; class BrokerPropertiesParameterResolver implements ParameterResolver { + @SuppressWarnings("PMD.AvoidUncheckedExceptionsInSignatures") @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { return parameterContext.getParameter().getType() == BrokerProperties.class; } + @SuppressWarnings("PMD.AvoidUncheckedExceptionsInSignatures") @Override - public BrokerProperties resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + public BrokerProperties resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { String[] properties = getValueHolderProperties(extensionContext); return new BrokerProperties(properties); } @@ -40,7 +45,7 @@ class BrokerPropertiesParameterResolver implements ParameterResolver { Optional testInstance = extensionContext.getTestMethod(); return testInstance .map(method -> method.getAnnotation(AppBrokerTestProperties.class).value()) - .orElseGet(() -> new String[]{}); + .orElseGet(() -> new String[] {}); } -} \ No newline at end of file +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CloudFoundryAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CloudFoundryAcceptanceTest.java similarity index 78% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CloudFoundryAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CloudFoundryAcceptanceTest.java index 369b4b9..e73f263 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CloudFoundryAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CloudFoundryAcceptanceTest.java @@ -16,10 +16,11 @@ package org.springframework.cloud.appbroker.acceptance; -import javax.net.ssl.SSLException; import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; import java.util.List; @@ -29,6 +30,8 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CountDownLatch; +import javax.net.ssl.SSLException; + import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; @@ -39,7 +42,6 @@ import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; import com.jayway.jsonpath.spi.mapper.MappingProvider; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; -import org.apache.commons.lang3.ArrayUtils; import org.cloudfoundry.operations.applications.ApplicationDetail; import org.cloudfoundry.operations.applications.ApplicationEnvironments; import org.cloudfoundry.operations.applications.ApplicationSummary; @@ -50,6 +52,8 @@ import org.cloudfoundry.uaa.clients.GetClientResponse; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; @@ -83,8 +87,11 @@ import static org.springframework.cloud.appbroker.acceptance.fixtures.cf.CloudFo @EnableConfigurationProperties(AcceptanceTestProperties.class) abstract class CloudFoundryAcceptanceTest { - static final String PLAN_NAME = "standard"; - static final String BACKING_APP_PATH = "classpath:backing-app.jar"; + private static final Logger LOG = LoggerFactory.getLogger(CloudFoundryAcceptanceTest.class); + + protected static final String PLAN_NAME = "standard"; + + protected static final String BACKING_APP_PATH = "classpath:backing-app.jar"; @Autowired protected CloudFoundryService cloudFoundryService; @@ -98,12 +105,15 @@ abstract class CloudFoundryAcceptanceTest { private final WebClient webClient = getSslIgnoringWebClient(); protected abstract String testSuffix(); + protected abstract String appServiceName(); + protected abstract String backingServiceName(); private String testBrokerAppName() { return "test-broker-app-" + testSuffix(); } + private String serviceBrokerName() { return "test-broker-" + testSuffix(); } @@ -119,12 +129,11 @@ abstract class CloudFoundryAcceptanceTest { "spring.cloud.openservicebroker.catalog.services[0].name=" + appServiceName(), "spring.cloud.openservicebroker.catalog.services[0].description=A service that deploys a backing app", "spring.cloud.openservicebroker.catalog.services[0].bindable=true", - "spring.cloud.openservicebroker.catalog.services[0].plans[0].id=" + UUID.randomUUID().toString() , + "spring.cloud.openservicebroker.catalog.services[0].plans[0].id=" + UUID.randomUUID().toString(), "spring.cloud.openservicebroker.catalog.services[0].plans[0].name=standard", "spring.cloud.openservicebroker.catalog.services[0].plans[0].bindable=true", "spring.cloud.openservicebroker.catalog.services[0].plans[0].description=A simple plan", "spring.cloud.openservicebroker.catalog.services[0].plans[0].free=true", - "spring.cloud.openservicebroker.catalog.services[1].id=" + UUID.randomUUID().toString(), "spring.cloud.openservicebroker.catalog.services[1].name=" + backingServiceName(), "spring.cloud.openservicebroker.catalog.services[1].description=A backing service that can be bound to backing apps", @@ -136,9 +145,9 @@ abstract class CloudFoundryAcceptanceTest { "spring.cloud.openservicebroker.catalog.services[1].plans[0].free=true" }; - String[] appBrokerProperties = ArrayUtils.addAll( - openServiceBrokerProperties, - brokerProperties.getProperties()); + List appBrokerProperties = new ArrayList<>(); + appBrokerProperties.addAll(Arrays.asList(openServiceBrokerProperties)); + appBrokerProperties.addAll(brokerProperties.getProperties()); blockingSubscribe(initializeBroker(appBrokerProperties)); } @@ -147,6 +156,7 @@ abstract class CloudFoundryAcceptanceTest { void configureJsonPath() { Configuration.setDefaults(new Configuration.Defaults() { private final JsonProvider jacksonJsonProvider = new JacksonJsonProvider(); + private final MappingProvider jacksonMappingProvider = new JacksonMappingProvider(); @Override @@ -167,7 +177,7 @@ abstract class CloudFoundryAcceptanceTest { } @AfterEach - void tearDown() { + public void tearDown() { blockingSubscribe(cloudFoundryService.getOrCreateDefaultOrganization() .map(OrganizationSummary::getId) .flatMap(orgId -> cloudFoundryService.getOrCreateDefaultSpace() @@ -175,7 +185,7 @@ abstract class CloudFoundryAcceptanceTest { .flatMap(spaceId -> cleanup(orgId, spaceId)))); } - private Mono initializeBroker(String... appBrokerProperties) { + private Mono initializeBroker(List appBrokerProperties) { return cloudFoundryService .getOrCreateDefaultOrganization() .map(OrganizationSummary::getId) @@ -188,7 +198,9 @@ abstract class CloudFoundryAcceptanceTest { APP_BROKER_CLIENT_SECRET, APP_BROKER_CLIENT_AUTHORITIES)) .then(cloudFoundryService.associateAppBrokerClientWithOrgAndSpace(brokerClientId(), orgId, spaceId)) - .then(cloudFoundryService.pushBrokerApp(testBrokerAppName(), getTestBrokerAppPath(), brokerClientId(), appBrokerProperties)) + .then(cloudFoundryService + .pushBrokerApp(testBrokerAppName(), getTestBrokerAppPath(), brokerClientId(), + appBrokerProperties)) .then(cloudFoundryService.createServiceBroker(serviceBrokerName(), testBrokerAppName())) .then(cloudFoundryService.enableServiceBrokerAccess(appServiceName())) .then(cloudFoundryService.enableServiceBrokerAccess(backingServiceName())))); @@ -201,18 +213,18 @@ abstract class CloudFoundryAcceptanceTest { .onErrorResume(e -> Mono.empty()); } - void createServiceInstance(String serviceInstanceName) { + protected void createServiceInstance(String serviceInstanceName) { createServiceInstance(serviceInstanceName, Collections.emptyMap()); } - void createServiceInstance(String serviceInstanceName, Map parameters) { + protected void createServiceInstance(String serviceInstanceName, Map parameters) { createServiceInstance(appServiceName(), PLAN_NAME, serviceInstanceName, parameters); } - void createServiceInstance(String serviceName, - String planName, - String serviceInstanceName, - Map parameters) { + protected void createServiceInstance(String serviceName, + String planName, + String serviceInstanceName, + Map parameters) { cloudFoundryService.createServiceInstance(planName, serviceName, serviceInstanceName, parameters) .then(getServiceInstanceMono(serviceInstanceName)) .flatMap(serviceInstance -> { @@ -224,7 +236,7 @@ abstract class CloudFoundryAcceptanceTest { .block(); } - void updateServiceInstance(String serviceInstanceName, Map parameters) { + protected void updateServiceInstance(String serviceInstanceName, Map parameters) { cloudFoundryService.updateServiceInstance(serviceInstanceName, parameters) .then(getServiceInstanceMono(serviceInstanceName)) .flatMap(serviceInstance -> { @@ -236,19 +248,19 @@ abstract class CloudFoundryAcceptanceTest { .block(); } - void deleteServiceInstance(String serviceInstanceName) { + protected void deleteServiceInstance(String serviceInstanceName) { blockingSubscribe(cloudFoundryService.deleteServiceInstance(serviceInstanceName)); } - ServiceInstance getServiceInstance(String serviceInstanceName) { + protected ServiceInstance getServiceInstance(String serviceInstanceName) { return getServiceInstanceMono(serviceInstanceName).block(); } - ServiceInstance getServiceInstance(String serviceInstanceName, String space) { + protected ServiceInstance getServiceInstance(String serviceInstanceName, String space) { return cloudFoundryService.getServiceInstance(serviceInstanceName, space).block(); } - String getServiceInstanceGuid(String serviceInstanceName) { + protected String getServiceInstanceGuid(String serviceInstanceName) { return getServiceInstanceMono(serviceInstanceName) .map(ServiceInstance::getId) .block(); @@ -258,7 +270,7 @@ abstract class CloudFoundryAcceptanceTest { return cloudFoundryService.getServiceInstance(serviceInstanceName); } - Optional getApplicationSummary(String appName) { + protected Optional getApplicationSummary(String appName) { return cloudFoundryService .getApplications() .flatMapMany(Flux::fromIterable) @@ -267,44 +279,44 @@ abstract class CloudFoundryAcceptanceTest { .blockOptional(); } - Optional getApplicationSummary(String appName, String space) { + protected Optional getApplicationSummary(String appName, String space) { return cloudFoundryService.getApplication(appName, space).blockOptional(); } - ApplicationEnvironments getApplicationEnvironment(String appName) { + private ApplicationEnvironments getApplicationEnvironment(String appName) { return cloudFoundryService.getApplicationEnvironment(appName).block(); } - ApplicationEnvironments getApplicationEnvironment(String appName, String space) { + private ApplicationEnvironments getApplicationEnvironment(String appName, String space) { return cloudFoundryService.getApplicationEnvironment(appName, space).block(); } - DocumentContext getSpringAppJson(String appName) { + protected DocumentContext getSpringAppJson(String appName) { ApplicationEnvironments env = getApplicationEnvironment(appName); String saj = (String) env.getUserProvided().get("SPRING_APPLICATION_JSON"); return JsonPath.parse(saj); } - DocumentContext getSpringAppJson(String appName, String space) { + protected DocumentContext getSpringAppJson(String appName, String space) { ApplicationEnvironments env = getApplicationEnvironment(appName, space); String saj = (String) env.getUserProvided().get("SPRING_APPLICATION_JSON"); return JsonPath.parse(saj); } - List getSpaces() { + protected List getSpaces() { return cloudFoundryService.getSpaces().block(); } - Optional getUaaClient(String clientId) { + protected Optional getUaaClient(String clientId) { return uaaService.getUaaClient(clientId) .blockOptional(); } - void createDomain(String domain) { + protected void createDomain(String domain) { cloudFoundryService.createDomain(domain).block(); } - void deleteDomain(String domain) { + protected void deleteDomain(String domain) { cloudFoundryService.deleteDomain(domain).block(); } @@ -315,7 +327,9 @@ abstract class CloudFoundryAcceptanceTest { private void blockingSubscribe(Mono publisher) { CountDownLatch latch = new CountDownLatch(1); publisher.subscribe(System.out::println, t -> { - t.printStackTrace(); + if (LOG.isDebugEnabled()) { + LOG.debug("error subscribing to publisher", t); + } latch.countDown(); }, latch::countDown); try { @@ -326,7 +340,7 @@ abstract class CloudFoundryAcceptanceTest { } } - Mono manageApps(String serviceInstanceName, String operation) { + protected Mono manageApps(String serviceInstanceName, String operation) { return cloudFoundryService .getServiceInstance(serviceInstanceName) .map(ServiceInstance::getId) @@ -335,37 +349,39 @@ abstract class CloudFoundryAcceptanceTest { .getApplicationRoute(testBrokerAppName()) .flatMap(appRoute -> webClient.get() - .uri(URI.create(appRoute + "/" + operation + "/" + serviceInstanceId)) - .exchange() - .flatMap(clientResponse -> clientResponse.toEntity(String.class)) - .map(HttpEntity::getBody))); + .uri(URI.create(appRoute + "/" + operation + "/" + serviceInstanceId)) + .exchange() + .flatMap(clientResponse -> clientResponse.toEntity(String.class)) + .map(HttpEntity::getBody))); } private WebClient getSslIgnoringWebClient() { return WebClient.builder() - .clientConnector(new ReactorClientHttpConnector(HttpClient - .create() - .secure(t -> { - try { - t.sslContext(SslContextBuilder - .forClient() - .trustManager(InsecureTrustManagerFactory.INSTANCE) - .build()); - } - catch (SSLException e) { - e.printStackTrace(); - } - }))) - .build(); + .clientConnector(new ReactorClientHttpConnector(HttpClient + .create() + .secure(t -> { + try { + t.sslContext(SslContextBuilder + .forClient() + .trustManager(InsecureTrustManagerFactory.INSTANCE) + .build()); + } + catch (SSLException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("problem ignoring SSL in WebClient", e); + } + } + }))) + .build(); } protected Mono> getApplications(String app1, String app2) { return Flux.merge(cloudFoundryService.getApplication(app1), cloudFoundryService.getApplication(app2)) - .parallel() - .runOn(Schedulers.parallel()) - .sequential() - .collectList(); + .parallel() + .runOn(Schedulers.parallel()) + .sequential() + .collectList(); } } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceAcceptanceTest.java similarity index 97% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceAcceptanceTest.java index a496c1e..d1fbd5a 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceAcceptanceTest.java @@ -27,12 +27,16 @@ import static org.assertj.core.api.Assertions.assertThat; class CreateInstanceAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_CREATE_1 = "app-create-1"; + private static final String APP_CREATE_2 = "app-create-2"; + private static final String SI_NAME = "si-create"; private static final String SUFFIX = "create-instance"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -115,4 +119,5 @@ class CreateInstanceAcceptanceTest extends CloudFoundryAcceptanceTest { assertThat(json.read("$.['spring.security.user.password']").toString()) .matches("[a-zA-Z]{14}"); } -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithOAuth2CredentialsAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithOAuth2CredentialsAcceptanceTest.java similarity index 95% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithOAuth2CredentialsAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithOAuth2CredentialsAcceptanceTest.java index adaec3c..60c95a9 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithOAuth2CredentialsAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithOAuth2CredentialsAcceptanceTest.java @@ -29,11 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat; class CreateInstanceWithOAuth2CredentialsAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME = "app-create-oauth2"; + private static final String SI_NAME = "si-create-oauth2"; private static final String SUFFIX = "create-instance-oauth2"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -57,7 +60,7 @@ class CreateInstanceWithOAuth2CredentialsAcceptanceTest extends CloudFoundryAcce "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME, "spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH, - + "spring.cloud.appbroker.services[0].apps[0].credential-providers[0].name=SpringSecurityOAuth2", "spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.registration=sample-app-client", "spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.grant-types=[\"client_credentials\"]", @@ -83,7 +86,8 @@ class CreateInstanceWithOAuth2CredentialsAcceptanceTest extends CloudFoundryAcce DocumentContext json = getSpringAppJson(APP_NAME); assertThat(json.read("$.['spring.security.oauth2.client.registration.sample-app-client.client-id']").toString()) .isEqualTo(uaaClientId(serviceInstanceGuid)); - assertThat(json.read("$.['spring.security.oauth2.client.registration.sample-app-client.client-secret']").toString()) + assertThat( + json.read("$.['spring.security.oauth2.client.registration.sample-app-client.client-secret']").toString()) .matches("[a-zA-Z]{12}"); // and a UAA client is created @@ -108,4 +112,5 @@ class CreateInstanceWithOAuth2CredentialsAcceptanceTest extends CloudFoundryAcce private String uaaClientId(String serviceInstanceGuid) { return APP_NAME + "-" + serviceInstanceGuid; } -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithParametersAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithParametersAcceptanceTest.java similarity index 96% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithParametersAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithParametersAcceptanceTest.java index ccfe02d..c45ccc3 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithParametersAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithParametersAcceptanceTest.java @@ -29,11 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat; class CreateInstanceWithParametersAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME = "app-create-params"; + private static final String SI_NAME = "si-create-params"; private static final String SUFFIX = "create-instance-with-params"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -54,18 +57,15 @@ class CreateInstanceWithParametersAcceptanceTest extends CloudFoundryAcceptanceT @AppBrokerTestProperties({ "spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME, "spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME, - "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME, "spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH, "spring.cloud.appbroker.services[0].apps[0].environment.parameter1=config1", "spring.cloud.appbroker.services[0].apps[0].environment.parameter2=config2", "spring.cloud.appbroker.services[0].apps[0].environment.parameter3=config3", - "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].name=EnvironmentMapping", "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].args.include=parameter1,parameter3", - "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].name=PropertyMapping", - "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].args.include=memory", + "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].args.include=memory" }) void deployAppsWithParametersOnCreateService() { // when a service instance is created @@ -96,4 +96,4 @@ class CreateInstanceWithParametersAcceptanceTest extends CloudFoundryAcceptanceT deleteServiceInstance(SI_NAME); } -} \ No newline at end of file +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest.java similarity index 97% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest.java index e8261b4..bbec35d 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest.java @@ -27,13 +27,16 @@ import static org.assertj.core.api.Assertions.assertThat; class CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String SUFFIX = "create-si-guid"; + private static final String APP_NAME_1 = "app-create-" + SUFFIX; + private static final String SI_NAME = "si-create-" + SUFFIX; private static final String BACKING_SI_NAME = "backing-si"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -54,15 +57,12 @@ class CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest extends Cl @AppBrokerTestProperties({ "spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME, "spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME, - "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME_1, "spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH, "spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + BACKING_SI_NAME, - "spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME, "spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME, "spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_NAME, - "spring.cloud.appbroker.services[0].target.name=ServiceInstanceGuidSuffix" }) void deployAppsWithServiceInstanceGuidSuffixOnCreateService() { @@ -88,4 +88,5 @@ class CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest extends Cl // when the service instance is deleted deleteServiceInstance(SI_NAME); } -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithServicesAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServicesAcceptanceTest.java similarity index 96% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithServicesAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServicesAcceptanceTest.java index ed882d2..7e7722e 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithServicesAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServicesAcceptanceTest.java @@ -28,14 +28,18 @@ import static org.assertj.core.api.Assertions.assertThat; class CreateInstanceWithServicesAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME = "app-create-services"; + private static final String SI_NAME = "si-create-services"; private static final String BACKING_SI_1_NAME = "backing-service-instance-created"; + private static final String BACKING_SI_2_NAME = "backing-service-instance-existing"; private static final String SUFFIX = "create-instance-with-services"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -56,15 +60,13 @@ class CreateInstanceWithServicesAcceptanceTest extends CloudFoundryAcceptanceTes @AppBrokerTestProperties({ "spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME, "spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME, - "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME, "spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH, "spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + BACKING_SI_1_NAME, "spring.cloud.appbroker.services[0].apps[0].services[1].service-instance-name=" + BACKING_SI_2_NAME, - "spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME, "spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME, - "spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_1_NAME, + "spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_1_NAME }) void deployAppsAndCreateServicesOnCreateService() { // given that a service is available in the marketplace @@ -94,4 +96,5 @@ class CreateInstanceWithServicesAcceptanceTest extends CloudFoundryAcceptanceTes deleteServiceInstance(BACKING_SI_2_NAME); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest.java similarity index 97% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest.java index 119b541..22f3c52 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest.java @@ -28,14 +28,18 @@ import static org.assertj.core.api.Assertions.assertThat; class CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME_1 = "app-create-space-per1"; + private static final String APP_NAME_2 = "app-create-space-per2"; + private static final String SI_NAME = "si-create-space-per"; private static final String BACKING_SI_NAME = "backing-service-space-per-target"; private static final String SUFFIX = "create-instance-space-per-si"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Override protected String testSuffix() { @@ -101,4 +105,5 @@ class CreateInstanceWithSpacePerServiceInstanceTargetAcceptanceTest extends Clou List spaces = getSpaces(); assertThat(spaces).doesNotContain(spaceName); } -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/HealthListener.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/HealthListener.java similarity index 75% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/HealthListener.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/HealthListener.java index a042fd0..e8f290f 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/HealthListener.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/HealthListener.java @@ -20,25 +20,36 @@ import java.net.URI; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; +@SuppressWarnings("PMD.DoNotUseThreads") @Service -public class HealthListener { +class HealthListener { + + private static final Logger LOG = LoggerFactory.getLogger(HealthListener.class); private final AtomicInteger requests = new AtomicInteger(); + private final AtomicInteger errors = new AtomicInteger(); + private final AtomicBoolean running = new AtomicBoolean(false); + private Thread runner; + private final RestTemplate restTemplate; public HealthListener(RestTemplate restTemplate) { this.restTemplate = restTemplate; } - void start(String path) { + public void start(String path) { if (running.get()) { throw new IllegalStateException("cannot start when test is already running"); } @@ -50,8 +61,9 @@ public class HealthListener { while (running.get()) { try { requests.incrementAndGet(); - ResponseEntity response = restTemplate.getForEntity(URI.create("http://" + path + "/actuator/health"), String.class); - if (response.getStatusCodeValue() != 200) { + ResponseEntity response = restTemplate + .getForEntity(URI.create("http://" + path + "/actuator/health"), String.class); + if (response.getStatusCode() != HttpStatus.OK) { errors.incrementAndGet(); } Thread.sleep(1000); @@ -64,21 +76,23 @@ public class HealthListener { runner.start(); } - void stop() { + public void stop() { running.set(false); try { runner.join(); } catch (InterruptedException e) { - e.printStackTrace(); + if (LOG.isDebugEnabled()) { + LOG.debug("thread was interrupted while waiting to die", e); + } } } - int getSuccesses() { + public int getSuccesses() { return requests.get(); } - int getFailures() { + public int getFailures() { return errors.get(); } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceAcceptanceTest.java similarity index 97% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceAcceptanceTest.java index 8dbb475..9c52eb2 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceAcceptanceTest.java @@ -31,11 +31,14 @@ import static org.assertj.core.api.Assertions.assertThat; class UpdateInstanceAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME = "app-update"; + private static final String SI_NAME = "si-update"; private static final String SUFFIX = "update-instance"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Autowired private HealthListener healthListener; @@ -59,7 +62,6 @@ class UpdateInstanceAcceptanceTest extends CloudFoundryAcceptanceTest { @AppBrokerTestProperties({ "spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME, "spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME, - "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME, "spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH, "spring.cloud.appbroker.services[0].apps[0].environment.parameter1=config1", @@ -71,7 +73,7 @@ class UpdateInstanceAcceptanceTest extends CloudFoundryAcceptanceTest { "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].name=PropertyMapping", "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].args.include=count" }) - void deployAppsOnUpdateService() { + public void deployAppsOnUpdateService() { // given a service instance is created createServiceInstance(SI_NAME); @@ -119,4 +121,5 @@ class UpdateInstanceAcceptanceTest extends CloudFoundryAcceptanceTest { Optional backingApplicationAfterDeletion = getApplicationSummary(APP_NAME); assertThat(backingApplicationAfterDeletion).isEmpty(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithHostAndDomainAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithHostAndDomainAcceptanceTest.java similarity index 97% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithHostAndDomainAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithHostAndDomainAcceptanceTest.java index 9e7fb97..32f7d1b 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithHostAndDomainAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithHostAndDomainAcceptanceTest.java @@ -30,11 +30,14 @@ import static org.assertj.core.api.Assertions.assertThat; class UpdateInstanceWithHostAndDomainAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME = "app-update-domain"; + private static final String SI_NAME = "si-update-domain"; private static final String SUFFIX = "update-instance-domain"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Autowired private HealthListener healthListener; @@ -103,4 +106,5 @@ class UpdateInstanceWithHostAndDomainAcceptanceTest extends CloudFoundryAcceptan deleteDomain("mydomain.com"); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithServicesAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithServicesAcceptanceTest.java similarity index 97% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithServicesAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithServicesAcceptanceTest.java index c93ea1e..9c8bbc1 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithServicesAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithServicesAcceptanceTest.java @@ -16,14 +16,14 @@ package org.springframework.cloud.appbroker.acceptance; -import org.cloudfoundry.operations.applications.ApplicationSummary; -import org.cloudfoundry.operations.services.ServiceInstance; -import org.junit.jupiter.api.Test; - import java.util.HashMap; import java.util.Map; import java.util.Optional; +import org.cloudfoundry.operations.applications.ApplicationSummary; +import org.cloudfoundry.operations.services.ServiceInstance; +import org.junit.jupiter.api.Test; + import org.springframework.beans.factory.annotation.Autowired; import static org.assertj.core.api.Assertions.assertThat; @@ -31,13 +31,16 @@ import static org.assertj.core.api.Assertions.assertThat; class UpdateInstanceWithServicesAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME = "app-update-services"; + private static final String SI_NAME = "si-update-services"; private static final String BACKING_SI_NAME = "backing-service-instance-update"; private static final String SUFFIX = "update-instance-with-services"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Autowired private HealthListener healthListener; @@ -111,4 +114,5 @@ class UpdateInstanceWithServicesAcceptanceTest extends CloudFoundryAcceptanceTes // then the service instance is deleted deleteServiceInstance(SI_NAME); } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithTargetAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithTargetAcceptanceTest.java similarity index 97% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithTargetAcceptanceTest.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithTargetAcceptanceTest.java index a4a1a3f..e369e13 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/UpdateInstanceWithTargetAcceptanceTest.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/UpdateInstanceWithTargetAcceptanceTest.java @@ -31,11 +31,14 @@ import static org.assertj.core.api.Assertions.assertThat; class UpdateInstanceWithTargetAcceptanceTest extends CloudFoundryAcceptanceTest { private static final String APP_NAME = "app-update-target"; + private static final String SI_NAME = "si-update-target"; private static final String SUFFIX = "update-instance-with-target"; - private static final String APP_SERVICE_NAME = "app-service-"+ SUFFIX; - private static final String BACKING_SERVICE_NAME = "backing-service-"+ SUFFIX; + + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; @Autowired private HealthListener healthListener; @@ -105,4 +108,4 @@ class UpdateInstanceWithTargetAcceptanceTest extends CloudFoundryAcceptanceTest assertThat(spaces).doesNotContain(spaceName); } -} \ No newline at end of file +} diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryClientConfiguration.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryClientConfiguration.java similarity index 80% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryClientConfiguration.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryClientConfiguration.java index 3da4c49..2a25cb0 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryClientConfiguration.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryClientConfiguration.java @@ -42,16 +42,23 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(CloudFoundryProperties.class) public class CloudFoundryClientConfiguration { + /** + * The client secret + */ public static final String APP_BROKER_CLIENT_SECRET = "app-broker-client-secret"; + + /** + * The client authorities + */ public static final String[] APP_BROKER_CLIENT_AUTHORITIES = { "cloud_controller.read", "cloud_controller.write", "clients.write" }; @Bean - CloudFoundryOperations cloudFoundryOperations(CloudFoundryProperties properties, - CloudFoundryClient client, - DopplerClient dopplerClient, - UaaClient uaaClient) { + protected CloudFoundryOperations cloudFoundryOperations(CloudFoundryProperties properties, + CloudFoundryClient client, + DopplerClient dopplerClient, + UaaClient uaaClient) { return DefaultCloudFoundryOperations.builder() .cloudFoundryClient(client) .dopplerClient(dopplerClient) @@ -62,8 +69,8 @@ public class CloudFoundryClientConfiguration { } @Bean - CloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, - @Qualifier("userCredentials") TokenProvider tokenProvider) { + protected CloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, + @Qualifier("userCredentials") TokenProvider tokenProvider) { return ReactorCloudFoundryClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) @@ -71,7 +78,7 @@ public class CloudFoundryClientConfiguration { } @Bean - ConnectionContext connectionContext(CloudFoundryProperties properties) { + protected ConnectionContext connectionContext(CloudFoundryProperties properties) { return DefaultConnectionContext.builder() .apiHost(properties.getApiHost()) .port(Optional.ofNullable(properties.getApiPort())) @@ -81,8 +88,8 @@ public class CloudFoundryClientConfiguration { } @Bean - DopplerClient dopplerClient(ConnectionContext connectionContext, - @Qualifier("userCredentials") TokenProvider tokenProvider) { + protected DopplerClient dopplerClient(ConnectionContext connectionContext, + @Qualifier("userCredentials") TokenProvider tokenProvider) { return ReactorDopplerClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) @@ -90,8 +97,8 @@ public class CloudFoundryClientConfiguration { } @Bean - UaaClient uaaClient(ConnectionContext connectionContext, - @Qualifier("clientCredentials") TokenProvider tokenProvider) { + protected UaaClient uaaClient(ConnectionContext connectionContext, + @Qualifier("clientCredentials") TokenProvider tokenProvider) { return ReactorUaaClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) @@ -104,7 +111,7 @@ public class CloudFoundryClientConfiguration { CloudFoundryProperties.PROPERTY_PREFIX + ".username", CloudFoundryProperties.PROPERTY_PREFIX + ".password" }) - PasswordGrantTokenProvider passwordTokenProvider(CloudFoundryProperties properties) { + protected PasswordGrantTokenProvider passwordTokenProvider(CloudFoundryProperties properties) { return PasswordGrantTokenProvider.builder() .password(properties.getPassword()) .username(properties.getUsername()) @@ -117,7 +124,7 @@ public class CloudFoundryClientConfiguration { CloudFoundryProperties.PROPERTY_PREFIX + ".client-id", CloudFoundryProperties.PROPERTY_PREFIX + ".client-secret" }) - ClientCredentialsGrantTokenProvider clientTokenProvider(CloudFoundryProperties properties) { + protected ClientCredentialsGrantTokenProvider clientTokenProvider(CloudFoundryProperties properties) { return ClientCredentialsGrantTokenProvider.builder() .clientId(properties.getClientId()) .clientSecret(properties.getClientSecret()) diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryProperties.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryProperties.java similarity index 96% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryProperties.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryProperties.java index 4cbb33f..ea0b0ea 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryProperties.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryProperties.java @@ -27,18 +27,28 @@ import static org.springframework.cloud.appbroker.acceptance.fixtures.cf.CloudFo @ConfigurationProperties(PROPERTY_PREFIX) public class CloudFoundryProperties { - static final String PROPERTY_PREFIX = "spring.cloud.appbroker.acceptancetest.cloudfoundry"; + protected static final String PROPERTY_PREFIX = "spring.cloud.appbroker.acceptancetest.cloudfoundry"; private String apiHost; + private Integer apiPort; + private String defaultOrg; + private String defaultSpace; + private String username; + private String password; + private String clientId; + private String clientSecret; + private String identityZoneSubdomain; + private boolean secure = true; + private boolean skipSslValidation; public String getApiHost() { diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryService.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryService.java similarity index 94% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryService.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryService.java index f974b34..2422be7 100644 --- a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/cf/CloudFoundryService.java +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryService.java @@ -73,9 +73,11 @@ import static java.lang.String.format; public class CloudFoundryService { private static final Logger LOGGER = LoggerFactory.getLogger(CloudFoundryService.class); - + private static final String DEPLOYER_PROPERTY_PREFIX = "spring.cloud.appbroker.deployer.cloudfoundry."; + private static final int EXPECTED_PROPERTY_PARTS = 2; + private final CloudFoundryClient cloudFoundryClient; private final CloudFoundryOperations cloudFoundryOperations; @@ -83,8 +85,8 @@ public class CloudFoundryService { private final CloudFoundryProperties cloudFoundryProperties; public CloudFoundryService(CloudFoundryClient cloudFoundryClient, - CloudFoundryOperations cloudFoundryOperations, - CloudFoundryProperties cloudFoundryProperties) { + CloudFoundryOperations cloudFoundryOperations, + CloudFoundryProperties cloudFoundryProperties) { this.cloudFoundryClient = cloudFoundryClient; this.cloudFoundryOperations = cloudFoundryOperations; this.cloudFoundryProperties = cloudFoundryProperties; @@ -125,7 +127,8 @@ public class CloudFoundryService { .map(url -> "https://" + url); } - public Mono pushBrokerApp(String appName, Path appPath, String brokerClientId, String... appBrokerProperties) { + public Mono pushBrokerApp(String appName, Path appPath, String brokerClientId, + List appBrokerProperties) { return cloudFoundryOperations.applications() .pushManifest(PushApplicationManifestRequest.builder() .manifest(ApplicationManifest.builder() @@ -168,16 +171,17 @@ public class CloudFoundryService { .name(si.getName()) .build()) .doOnSuccess(item -> LOGGER.info("Deleted service instance " + serviceInstanceName)) - .doOnError(error -> LOGGER.error("Error deleting service instance " + serviceInstanceName + ": " + error)) + .doOnError( + error -> LOGGER.error("Error deleting service instance " + serviceInstanceName + ": " + error)) .onErrorResume(e -> Mono.empty())) .doOnError(error -> LOGGER.warn("Error getting service instance " + serviceInstanceName + ": " + error)) .onErrorResume(e -> Mono.empty()); } public Mono createServiceInstance(String planName, - String serviceName, - String serviceInstanceName, - Map parameters) { + String serviceName, + String serviceInstanceName, + Map parameters) { return cloudFoundryOperations.services() .createInstance(CreateServiceInstanceRequest.builder() .planName(planName) @@ -208,7 +212,7 @@ public class CloudFoundryService { } private Mono getServiceInstance(CloudFoundryOperations operations, - String serviceInstanceName) { + String serviceInstanceName) { return operations.services() .getInstance(GetServiceInstanceRequest.builder() .name(serviceInstanceName) @@ -338,28 +342,28 @@ public class CloudFoundryService { public Mono createDomain(String domain) { return cloudFoundryOperations - .domains() - .create(CreateDomainRequest - .builder() - .domain(domain) - .organization(cloudFoundryProperties.getDefaultOrg()) - .build()) - .onErrorResume(e -> Mono.empty()); + .domains() + .create(CreateDomainRequest + .builder() + .domain(domain) + .organization(cloudFoundryProperties.getDefaultOrg()) + .build()) + .onErrorResume(e -> Mono.empty()); } public Mono deleteDomain(String domain) { return cloudFoundryOperations - .domains() - .list() - .filter(d -> d.getName().equals(domain)) - .map(Domain::getId) - .flatMap(domainId -> cloudFoundryClient - .privateDomains() - .delete(DeletePrivateDomainRequest - .builder() - .privateDomainId(domainId) - .build())) - .then(); + .domains() + .list() + .filter(d -> d.getName().equals(domain)) + .map(Domain::getId) + .flatMap(domainId -> cloudFoundryClient + .privateDomains() + .delete(DeletePrivateDomainRequest + .builder() + .privateDomainId(domainId) + .build())) + .then(); } private Mono associateOrgUser(String orgId, String userId) { @@ -432,17 +436,19 @@ public class CloudFoundryService { return deployerVariables; } - private Map propertiesToEnvironment(String... properties) { + private Map propertiesToEnvironment(List properties) { Map environment = new HashMap<>(); for (String property : properties) { final String[] propertyKeyValue = property.split("="); - if (propertyKeyValue.length == 2) { + if (propertyKeyValue.length == EXPECTED_PROPERTY_PARTS) { environment.put(propertyKeyValue[0], propertyKeyValue[1]); - } else { + } + else { throw new IllegalArgumentException(format("App Broker property '%s' is incorrectly formatted", Arrays.toString(propertyKeyValue))); } } return environment; } + } diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/uaa/UaaService.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/uaa/UaaService.java similarity index 100% rename from spring-cloud-app-broker-acceptance-tests/src/test/java/org.springframework.cloud.appbroker.acceptance/fixtures/uaa/UaaService.java rename to spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/uaa/UaaService.java diff --git a/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfiguration.java b/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfiguration.java index 173c3db..a970659 100644 --- a/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfiguration.java +++ b/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfiguration.java @@ -24,12 +24,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.appbroker.deployer.AppDeployer; -import org.springframework.cloud.appbroker.deployer.DefaultBackingAppDeploymentService; import org.springframework.cloud.appbroker.deployer.BackingAppDeploymentService; import org.springframework.cloud.appbroker.deployer.BackingApplication; import org.springframework.cloud.appbroker.deployer.BackingService; import org.springframework.cloud.appbroker.deployer.BackingServicesProvisionService; import org.springframework.cloud.appbroker.deployer.BrokeredServices; +import org.springframework.cloud.appbroker.deployer.DefaultBackingAppDeploymentService; import org.springframework.cloud.appbroker.deployer.DefaultBackingServicesProvisionService; import org.springframework.cloud.appbroker.deployer.DeployerClient; import org.springframework.cloud.appbroker.extensions.credentials.CredentialGenerator; @@ -71,6 +71,10 @@ import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingSer import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +/** + * App Broker Auto-configuration + */ +@SuppressWarnings("PMD.CouplingBetweenObjects") @Configuration @AutoConfigureAfter(CloudFoundryAppDeployerAutoConfiguration.class) @ConditionalOnBean(AppDeployer.class) @@ -78,124 +82,251 @@ public class AppBrokerAutoConfiguration { private static final String PROPERTY_PREFIX = "spring.cloud.appbroker"; + /** + * Provide a {@link DeployerClient} bean + * + * @param appDeployer the AppDeployer bean + * @return the bean + */ @Bean public DeployerClient deployerClient(AppDeployer appDeployer) { return new DeployerClient(appDeployer); } + /** + * Provide a {@link BackingAppDeploymentService} bean + * + * @param deployerClient the DeployerClient bean + * @return the bean + */ @Bean @ConditionalOnMissingBean public BackingAppDeploymentService backingAppDeploymentService(DeployerClient deployerClient) { return new DefaultBackingAppDeploymentService(deployerClient); } + /** + * Provide a {@link ManagementClient} bean + * + * @param appManager the AppManager bean + * @return the bean + */ @Bean public ManagementClient managementClient(AppManager appManager) { return new ManagementClient(appManager); } + /** + * Provide a {@link BackingAppManagementService} bean + * + * @param managementClient the ManagementClient bean + * @param appDeployer the AppDeployer bean + * @param brokeredServices the BrokeredServices bean + * @param targetService the TargetService bean + * @return the bean + */ @Bean public BackingAppManagementService backingAppManagementService(ManagementClient managementClient, AppDeployer appDeployer, BrokeredServices brokeredServices, TargetService targetService) { return new BackingAppManagementService(managementClient, appDeployer, brokeredServices, targetService); } + /** + * Provide a {@link BrokeredServices} bean + * + * @return the bean + */ @Bean @ConfigurationProperties(PROPERTY_PREFIX + ".services") public BrokeredServices brokeredServices() { return BrokeredServices.builder().build(); } + /** + * Provide a {@link ServiceInstanceStateRepository} bean + * + * @return the bean + */ @Bean @ConditionalOnMissingBean(ServiceInstanceStateRepository.class) public ServiceInstanceStateRepository serviceInstanceStateRepository() { return new InMemoryServiceInstanceStateRepository(); } + /** + * Provide a {@link ServiceInstanceBindingStateRepository} bean + * + * @return the bean + */ @Bean @ConditionalOnMissingBean(ServiceInstanceBindingStateRepository.class) public ServiceInstanceBindingStateRepository serviceInstanceBindingStateRepository() { return new InMemoryServiceInstanceBindingStateRepository(); } + /** + * Provide an {@link EnvironmentMappingParametersTransformerFactory} bean + * + * @return the bean + */ @Bean public EnvironmentMappingParametersTransformerFactory environmentMappingParametersTransformerFactory() { return new EnvironmentMappingParametersTransformerFactory(); } + /** + * Provide a {@link ParameterMappingParametersTransformerFactory} bean + * + * @return the bean + */ @Bean public PropertyMappingParametersTransformerFactory propertyMappingParametersTransformerFactory() { return new PropertyMappingParametersTransformerFactory(); } + /** + * Provide a {@link ParameterMappingParametersTransformerFactory} bean + * + * @return the bean + */ @Bean public ParameterMappingParametersTransformerFactory parameterMappingParametersTransformerFactory() { return new ParameterMappingParametersTransformerFactory(); } + /** + * Provide a {@link BackingApplicationsParametersTransformationService} bean + * + * @param transformers a collection of parameter transformers + * @return the bean + */ @Bean public BackingApplicationsParametersTransformationService backingApplicationsParametersTransformationService( List> transformers) { return new BackingApplicationsParametersTransformationService(transformers); } + /** + * Provide a {@link BackingServicesParametersTransformationService} bean + * + * @param transformers a collection of parameter transformers + * @return the bean + */ @Bean public BackingServicesParametersTransformationService backingServicesParametersTransformationService( List> transformers) { return new BackingServicesParametersTransformationService(transformers); } + /** + * Provide a {@link SimpleCredentialGenerator} bean + * + * @return the bean + */ @ConditionalOnMissingBean(CredentialGenerator.class) @Bean public SimpleCredentialGenerator simpleCredentialGenerator() { return new SimpleCredentialGenerator(); } + /** + * Provide a {@link SpringSecurityBasicAuthCredentialProviderFactory} bean + * + * @param credentialGenerator the CredentialGenerator bean + * @return the bean + */ @Bean - public SpringSecurityBasicAuthCredentialProviderFactory springSecurityBasicAuthCredentialProvider(CredentialGenerator credentialGenerator) { + public SpringSecurityBasicAuthCredentialProviderFactory springSecurityBasicAuthCredentialProvider( + CredentialGenerator credentialGenerator) { return new SpringSecurityBasicAuthCredentialProviderFactory(credentialGenerator); } + /** + * Provide a {@link SpringSecurityOAuth2CredentialProviderFactory} bean + * + * @param credentialGenerator the CredentialGenerator bean + * @param oAuth2Client the OAuth2Client bean + * @return the bean + */ @Bean - public SpringSecurityOAuth2CredentialProviderFactory springSecurityOAuth2CredentialProvider(CredentialGenerator credentialGenerator, - OAuth2Client oAuth2Client) { + public SpringSecurityOAuth2CredentialProviderFactory springSecurityOAuth2CredentialProvider( + CredentialGenerator credentialGenerator, + OAuth2Client oAuth2Client) { return new SpringSecurityOAuth2CredentialProviderFactory(credentialGenerator, oAuth2Client); } + /** + * Provide a {@link CredentialProviderService} bean + * + * @param providers a collection of credential providers + * @return the bean + */ @Bean public CredentialProviderService credentialProviderService(List> providers) { return new CredentialProviderService(providers); } + /** + * Provide a {@link SpacePerServiceInstance} bean + * + * @return the bean + */ @Bean public SpacePerServiceInstance spacePerServiceInstance() { return new SpacePerServiceInstance(); } + /** + * Provide a {@link ServiceInstanceGuidSuffix} bean + * + * @return the bean + */ @Bean public ServiceInstanceGuidSuffix serviceInstanceGuidSuffix() { return new ServiceInstanceGuidSuffix(); } + /** + * Provide a {@link TargetService} bean + * + * @param targets a collection of targets + * @return the bean + */ @Bean public TargetService targetService(List> targets) { return new TargetService(targets); } + /** + * Provide a {@link BackingServicesProvisionService} bean + * + * @param deployerClient the DeployerClient bean + * @return the bean + */ @Bean @ConditionalOnMissingBean public BackingServicesProvisionService backingServicesProvisionService(DeployerClient deployerClient) { return new DefaultBackingServicesProvisionService(deployerClient); } + /** + * Provide a {@link CreateServiceInstanceWorkflow} bean + * + * @param brokeredServices the BrokeredServices bean + * @param backingAppDeploymentService the BackingAppDeploymentService bean + * @param appsParametersTransformationService the BackingApplicationsParametersTransformationService bean + * @param servicesParametersTransformationService the BackingServicesParametersTransformationService bean + * @param credentialProviderService the CredentialProviderService bean + * @param targetService the TargetService bean + * @param backingServicesProvisionService the BackingServicesProvisionService bean + * @return the bean + */ @Bean public CreateServiceInstanceWorkflow appDeploymentCreateServiceInstanceWorkflow( - BrokeredServices brokeredServices, - BackingAppDeploymentService backingAppDeploymentService, + BrokeredServices brokeredServices, BackingAppDeploymentService backingAppDeploymentService, BackingApplicationsParametersTransformationService appsParametersTransformationService, BackingServicesParametersTransformationService servicesParametersTransformationService, - CredentialProviderService credentialProviderService, - TargetService targetService, + CredentialProviderService credentialProviderService, TargetService targetService, BackingServicesProvisionService backingServicesProvisionService) { return new AppDeploymentCreateServiceInstanceWorkflow( brokeredServices, @@ -207,10 +338,20 @@ public class AppBrokerAutoConfiguration { targetService); } + /** + * Provide a {@link UpdateServiceInstanceWorkflow} bean + * + * @param brokeredServices the BrokeredServices bean + * @param backingAppDeploymentService the BackingAppDeploymentService bean + * @param backingServicesProvisionService the BackingServicesProvisionService bean + * @param appsParametersTransformationService the BackingApplicationsParametersTransformationService bean + * @param servicesParametersTransformationService the BackingServicesParametersTransformationService bean + * @param targetService the TargetService bean + * @return the bean + */ @Bean public UpdateServiceInstanceWorkflow appDeploymentUpdateServiceInstanceWorkflow( - BrokeredServices brokeredServices, - BackingAppDeploymentService backingAppDeploymentService, + BrokeredServices brokeredServices, BackingAppDeploymentService backingAppDeploymentService, BackingServicesProvisionService backingServicesProvisionService, BackingApplicationsParametersTransformationService appsParametersTransformationService, BackingServicesParametersTransformationService servicesParametersTransformationService, @@ -225,13 +366,21 @@ public class AppBrokerAutoConfiguration { targetService); } + /** + * Provide a {@link DeleteServiceInstanceWorkflow} bean + * + * @param brokeredServices the BrokeredServices bean + * @param backingAppDeploymentService the BackingAppDeploymentService bean + * @param backingServicesProvisionService the BackingServicesProvisionService bean + * @param credentialProviderService the CredentialProviderService bean + * @param targetService the TargetService bean + * @return the bean + */ @Bean public DeleteServiceInstanceWorkflow appDeploymentDeleteServiceInstanceWorkflow( - BrokeredServices brokeredServices, - BackingAppDeploymentService backingAppDeploymentService, + BrokeredServices brokeredServices, BackingAppDeploymentService backingAppDeploymentService, BackingServicesProvisionService backingServicesProvisionService, - CredentialProviderService credentialProviderService, - TargetService targetService) { + CredentialProviderService credentialProviderService, TargetService targetService) { return new AppDeploymentDeleteServiceInstanceWorkflow( brokeredServices, @@ -241,14 +390,31 @@ public class AppBrokerAutoConfiguration { ); } + /** + * Provide a {@link WorkflowServiceInstanceService} bean + * + * @param stateRepository the ServiceInstanceStateRepository bean + * @param createWorkflows a collection of create workflows + * @param deleteWorkflows a collection of delete workflows + * @param updateWorkflows a collection of update workflows + * @return the bean + */ @Bean public WorkflowServiceInstanceService serviceInstanceService(ServiceInstanceStateRepository stateRepository, - List createWorkflows, - List deleteWorkflows, - List updateWorkflows) { + List createWorkflows, List deleteWorkflows, + List updateWorkflows) { return new WorkflowServiceInstanceService(stateRepository, createWorkflows, deleteWorkflows, updateWorkflows); } + /** + * Provide a {@link WorkflowServiceInstanceBindingService} bean + * + * @param stateRepository the ServiceInstanceBindingStateRepository bean + * @param createServiceInstanceAppBindingWorkflows a collection of create app binding workflows + * @param createServiceInstanceRouteBindingWorkflows a collection of create route binding workflows + * @param deleteServiceInstanceBindingWorkflows a collection of update workflows + * @return the bean + */ @Bean @ConditionalOnMissingBean(ServiceInstanceBindingService.class) public WorkflowServiceInstanceBindingService serviceInstanceBindingService( @@ -257,8 +423,8 @@ public class AppBrokerAutoConfiguration { @Autowired(required = false) List createServiceInstanceRouteBindingWorkflows, @Autowired(required = false) List deleteServiceInstanceBindingWorkflows) { return new WorkflowServiceInstanceBindingService(stateRepository, - createServiceInstanceAppBindingWorkflows, - createServiceInstanceRouteBindingWorkflows, + createServiceInstanceAppBindingWorkflows, createServiceInstanceRouteBindingWorkflows, deleteServiceInstanceBindingWorkflows); } + } diff --git a/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfiguration.java b/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfiguration.java index 23dd12c..6ecda05 100644 --- a/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfiguration.java +++ b/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfiguration.java @@ -42,11 +42,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.appbroker.deployer.AppDeployer; -import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryAppManager; -import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryOperationsUtils; import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryAppDeployer; +import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryAppManager; import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryDeploymentProperties; import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryOAuth2Client; +import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryOperationsUtils; import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryTargetProperties; import org.springframework.cloud.appbroker.manager.AppManager; import org.springframework.cloud.appbroker.oauth2.OAuth2Client; @@ -55,59 +55,108 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ResourceLoader; import org.springframework.util.StringUtils; +/** + * Auto-configuration support for deploying apps to Cloud Foundry + */ @Configuration @ConditionalOnProperty(CloudFoundryAppDeployerAutoConfiguration.PROPERTY_PREFIX + ".api-host") @EnableConfigurationProperties public class CloudFoundryAppDeployerAutoConfiguration { - static final String PROPERTY_PREFIX = "spring.cloud.appbroker.deployer.cloudfoundry"; + protected static final String PROPERTY_PREFIX = "spring.cloud.appbroker.deployer.cloudfoundry"; + + /** + * Provide a {@link CloudFoundryDeploymentProperties} bean + * + * @return the bean + */ @Bean @ConfigurationProperties(PROPERTY_PREFIX + ".properties") - CloudFoundryDeploymentProperties cloudFoundryDeploymentProperties() { + public CloudFoundryDeploymentProperties cloudFoundryDeploymentProperties() { return new CloudFoundryDeploymentProperties(); } + /** + * Provide a {@link CloudFoundryTargetProperties} bean + * + * @return the bean + */ @Bean @ConfigurationProperties(PROPERTY_PREFIX) - CloudFoundryTargetProperties cloudFoundryTargetProperties() { + public CloudFoundryTargetProperties cloudFoundryTargetProperties() { return new CloudFoundryTargetProperties(); } + /** + * Provide a {@link AppDeployer} bean + * + * @param deploymentProperties the CloudFoundryDeploymentProperties bean + * @param cloudFoundryOperations the CloudFoundryOperations bean + * @param cloudFoundryClient the CloudFoundryClient bean + * @param operationsUtils the CloudFoundryOperationsUtils bean + * @param targetProperties the CloudFoundryTargetProperties bean + * @param resourceLoader the ResourceLoader bean + * @return the bean + */ @Bean - AppDeployer cloudFoundryAppDeployer(CloudFoundryDeploymentProperties deploymentProperties, - CloudFoundryOperations cloudFoundryOperations, - CloudFoundryClient cloudFoundryClient, - CloudFoundryOperationsUtils operationsUtils, - CloudFoundryTargetProperties targetProperties, - ResourceLoader resourceLoader) { + public AppDeployer cloudFoundryAppDeployer(CloudFoundryDeploymentProperties deploymentProperties, + CloudFoundryOperations cloudFoundryOperations, CloudFoundryClient cloudFoundryClient, + CloudFoundryOperationsUtils operationsUtils, CloudFoundryTargetProperties targetProperties, + ResourceLoader resourceLoader) { return new CloudFoundryAppDeployer(deploymentProperties, cloudFoundryOperations, cloudFoundryClient, operationsUtils, targetProperties, resourceLoader); } + /** + * Provide an {@link AppManager} bean + * + * @param cloudFoundryOperationsUtils the CloudFoundryOperationsUtils bean + * @return the bean + */ @Bean - AppManager cloudFoundryAppManager(CloudFoundryOperationsUtils cloudFoundryOperationsUtils) { + public AppManager cloudFoundryAppManager(CloudFoundryOperationsUtils cloudFoundryOperationsUtils) { return new CloudFoundryAppManager(cloudFoundryOperationsUtils); } + /** + * Provide an {@link OAuth2Client} bean + * + * @param uaaClient the UaaClient bean + * @return the bean + */ @Bean - OAuth2Client cloudFoundryOAuth2Client(@UaaClientQualifier UaaClient uaaClient) { + public OAuth2Client cloudFoundryOAuth2Client(@UaaClientQualifier UaaClient uaaClient) { return new CloudFoundryOAuth2Client(uaaClient); } + /** + * Provide a {@link ReactorCloudFoundryClient} bean + * + * @param connectionContext the ConnectionContext bean + * @param tokenProvider the TokenProvider bean + * @return the bean + */ @Bean - ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, - @TokenQualifier TokenProvider tokenProvider) { + public ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, + @TokenQualifier TokenProvider tokenProvider) { return ReactorCloudFoundryClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) .build(); } + /** + * Provide a {@link CloudFoundryOperations} bean + * + * @param properties the CloudFoundryTargetProperties bean + * @param client the CloudFoundryClient bean + * @param dopplerClient the DopplerClient bean + * @param uaaClient the UaaClient bean + * @return the bean + */ @Bean - CloudFoundryOperations cloudFoundryOperations(CloudFoundryTargetProperties properties, - CloudFoundryClient client, - DopplerClient dopplerClient, - @UaaClientQualifier UaaClient uaaClient) { + public CloudFoundryOperations cloudFoundryOperations(CloudFoundryTargetProperties properties, + CloudFoundryClient client, DopplerClient dopplerClient, @UaaClientQualifier UaaClient uaaClient) { return DefaultCloudFoundryOperations.builder() .cloudFoundryClient(client) .dopplerClient(dopplerClient) @@ -117,13 +166,25 @@ public class CloudFoundryAppDeployerAutoConfiguration { .build(); } + /** + * Provide a {@link CloudFoundryOperationsUtils} bean + * + * @param operations the CloudFoundryOperations bean + * @return the bean + */ @Bean - CloudFoundryOperationsUtils cloudFoundryOperationsUtils(CloudFoundryOperations operations) { + public CloudFoundryOperationsUtils cloudFoundryOperationsUtils(CloudFoundryOperations operations) { return new CloudFoundryOperationsUtils(operations); } + /** + * Provide a {@link DefaultConnectionContext} bean + * + * @param properties the CloudFoundryTargetProperties bean + * @return the bean + */ @Bean - DefaultConnectionContext connectionContext(CloudFoundryTargetProperties properties) { + public DefaultConnectionContext connectionContext(CloudFoundryTargetProperties properties) { return DefaultConnectionContext.builder() .apiHost(properties.getApiHost()) .port(Optional.ofNullable(properties.getApiPort())) @@ -132,22 +193,35 @@ public class CloudFoundryAppDeployerAutoConfiguration { .build(); } + /** + * Provide a {@link ReactorDopplerClient} bean + * + * @param connectionContext the ConnectionContext bean + * @param tokenProvider the TokenProvider bean + * @return the bean + */ @Bean - ReactorDopplerClient dopplerClient(ConnectionContext connectionContext, - @TokenQualifier TokenProvider tokenProvider) { + public ReactorDopplerClient dopplerClient(ConnectionContext connectionContext, + @TokenQualifier TokenProvider tokenProvider) { return ReactorDopplerClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) .build(); } + /** + * Provide a {@link TokenProvider} bean + * + * @param properties the CloudFoundryTargetProperties bean + * @return the bean + */ @TokenQualifier @Bean - TokenProvider uaaTokenProvider(CloudFoundryTargetProperties properties) { + public TokenProvider uaaTokenProvider(CloudFoundryTargetProperties properties) { boolean isClientIdAndSecretSet = Stream.of(properties.getClientId(), properties.getClientSecret()) - .allMatch(StringUtils::hasText); + .allMatch(StringUtils::hasText); boolean isUsernameAndPasswordSet = Stream.of(properties.getUsername(), properties.getPassword()) - .allMatch(StringUtils::hasText); + .allMatch(StringUtils::hasText); if (isClientIdAndSecretSet && isUsernameAndPasswordSet) { throw new IllegalStateException( String.format("(%1$s.client_id / %1$s.client_secret) must not be set when\n" + @@ -155,16 +229,16 @@ public class CloudFoundryAppDeployerAutoConfiguration { } else if (isClientIdAndSecretSet) { return ClientCredentialsGrantTokenProvider.builder() - .clientId(properties.getClientId()) - .clientSecret(properties.getClientSecret()) - .identityZoneSubdomain(properties.getIdentityZoneSubdomain()) - .build(); + .clientId(properties.getClientId()) + .clientSecret(properties.getClientSecret()) + .identityZoneSubdomain(properties.getIdentityZoneSubdomain()) + .build(); } else if (isUsernameAndPasswordSet) { return PasswordGrantTokenProvider.builder() - .password(properties.getPassword()) - .username(properties.getUsername()) - .build(); + .password(properties.getPassword()) + .username(properties.getUsername()) + .build(); } else { throw new IllegalStateException( @@ -173,10 +247,17 @@ public class CloudFoundryAppDeployerAutoConfiguration { } } + /** + * Provide a {@link ReactorUaaClient} bean + * + * @param connectionContext the ConnectionContext bean + * @param tokenProvider the TokenProvider bean + * @return the bean + */ @UaaClientQualifier @Bean - ReactorUaaClient uaaClient(ConnectionContext connectionContext, - @TokenQualifier TokenProvider tokenProvider) { + public ReactorUaaClient uaaClient(ConnectionContext connectionContext, + @TokenQualifier TokenProvider tokenProvider) { return ReactorUaaClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) @@ -189,13 +270,16 @@ public class CloudFoundryAppDeployerAutoConfiguration { public @interface TokenQualifier { String value() default "appBrokerTokenProvider"; + } @Qualifier @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) - public @interface UaaClientQualifier { + public @interface UaaClientQualifier { String value() default "appBrokerUaaClientQualifier"; + } + } diff --git a/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfiguration.java b/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfiguration.java index d41dcfc..ce8fff7 100644 --- a/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfiguration.java +++ b/spring-cloud-app-broker-autoconfigure/src/main/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfiguration.java @@ -31,6 +31,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.credhub.autoconfig.CredHubTemplateAutoConfiguration; import org.springframework.credhub.core.CredHubOperations; +/** + * CredHub auto-configuration + */ @Configuration @AutoConfigureBefore(AppBrokerAutoConfiguration.class) @AutoConfigureAfter(CredHubTemplateAutoConfiguration.class) @@ -41,16 +44,36 @@ public class CredHubAutoConfiguration { @Value("${spring.application.name}") private String appName; + /** + * Provide a {@link CreateServiceInstanceAppBindingWorkflow} bean + * + * @param credHubOperations the CredHubOperations bean + * @return the bean + */ @Bean - public CreateServiceInstanceAppBindingWorkflow credhubPersistingCreateServiceInstanceAppBindingWorkflow(CredHubOperations credHubOperations) { + public CreateServiceInstanceAppBindingWorkflow credhubPersistingCreateServiceInstanceAppBindingWorkflow( + CredHubOperations credHubOperations) { return new CredHubPersistingCreateServiceInstanceAppBindingWorkflow(credHubOperations, appName); } + /** + * Provide a {@link DeleteServiceInstanceBindingWorkflow} bean + * + * @param credHubOperations the CredHubOperations bean + * @return the bean + */ @Bean - public DeleteServiceInstanceBindingWorkflow credhubPersistingDeleteServiceInstanceAppBindingWorkflow(CredHubOperations credHubOperations) { + public DeleteServiceInstanceBindingWorkflow credhubPersistingDeleteServiceInstanceAppBindingWorkflow( + CredHubOperations credHubOperations) { return new CredHubPersistingDeleteServiceInstanceBindingWorkflow(credHubOperations, appName); } + /** + * Provide a {@link CredHubCredentialsGenerator} bean + * + * @param credHubOperations the CredHubOperations bean + * @return the bean + */ @Bean public CredHubCredentialsGenerator credHubCredentialsGenerator(CredHubOperations credHubOperations) { return new CredHubCredentialsGenerator(credHubOperations); diff --git a/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfigurationTest.java b/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfigurationTest.java index b301ffc..b3e41cf 100644 --- a/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfigurationTest.java +++ b/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfigurationTest.java @@ -266,10 +266,12 @@ class AppBrokerAutoConfigurationTest { public ServiceInstanceBindingService serviceInstanceBindingService() { return new TestServiceInstanceBindingService(); } + } @Configuration public static class CustomStateRepositoriesConfiguration { + @Bean public ServiceInstanceStateRepository serviceInstanceStateRepository() { return new TestServiceInstanceStateRepository(); @@ -279,6 +281,7 @@ class AppBrokerAutoConfigurationTest { public ServiceInstanceBindingStateRepository serviceInstanceBindingStateRepository() { return new TestServiceInstanceBindingStateRepository(); } + } private static class TestServiceInstanceBindingService implements ServiceInstanceBindingService { @@ -287,4 +290,5 @@ class AppBrokerAutoConfigurationTest { private static class TestServiceInstanceStateRepository implements ServiceInstanceStateRepository {} private static class TestServiceInstanceBindingStateRepository implements ServiceInstanceBindingStateRepository {} -} \ No newline at end of file + +} diff --git a/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfigurationTest.java b/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfigurationTest.java index 5ada592..71599c3 100644 --- a/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfigurationTest.java +++ b/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CloudFoundryAppDeployerAutoConfigurationTest.java @@ -69,7 +69,8 @@ class CloudFoundryAppDeployerAutoConfigurationTest { assertThat(targetProperties.getPassword()).isEqualTo("secret"); assertThat(context).hasSingleBean(CloudFoundryDeploymentProperties.class); - CloudFoundryDeploymentProperties deploymentProperties = context.getBean(CloudFoundryDeploymentProperties.class); + CloudFoundryDeploymentProperties deploymentProperties = context + .getBean(CloudFoundryDeploymentProperties.class); assertThat(deploymentProperties.getMemory()).isEqualTo("2G"); assertThat(deploymentProperties.getCount()).isEqualTo(3); assertThat(deploymentProperties.getBuildpack()).isEqualTo("example-buildpack"); @@ -139,4 +140,4 @@ class CloudFoundryAppDeployerAutoConfigurationTest { }); } -} \ No newline at end of file +} diff --git a/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfigurationTest.java b/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfigurationTest.java index c7cbe7b..f17418e 100644 --- a/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfigurationTest.java +++ b/spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/CredHubAutoConfigurationTest.java @@ -17,6 +17,7 @@ package org.springframework.cloud.appbroker.autoconfigure; import org.junit.jupiter.api.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.TestConfiguration; @@ -80,10 +81,12 @@ class CredHubAutoConfigurationTest { @TestConfiguration public static class CredHubConfiguration { + @Bean public CredHubOperations credHubOperations() { return mock(CredHubOperations.class); } + } -} \ No newline at end of file +} diff --git a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java index f111488..fd66e93 100644 --- a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java +++ b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java @@ -20,11 +20,36 @@ import java.util.List; import reactor.core.publisher.Flux; +/** + * This interface is implemented by service brokers to process requests to deploy, update, and undeploy backing + * applications associated with a service instance. + */ public interface BackingAppDeploymentService { + /** + * Deploy the backing applications and associate with the service instance + * + * @param backingApps a collection of backing applications + * @param serviceInstanceId the service instance ID + * @return a set of strings, where each corresponds to an application e.g. the application name + */ Flux deploy(List backingApps, String serviceInstanceId); + /** + * Update the backing applications and associate with the service instance + * + * @param backingApps a collection of backing applications + * @param serviceInstanceId the service instance ID + * @return a set of strings, where each corresponds to an application. e.g. the application name + */ Flux update(List backingApps, String serviceInstanceId); + /** + * Undeploy the backing applications + * + * @param backingApps a collection of backing applications + * @return a set of strings, where each corresponds to an application. e.g. the application name + */ Flux undeploy(List backingApps); + } diff --git a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingApplication.java b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingApplication.java index 5d51770..60390ea 100644 --- a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingApplication.java +++ b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingApplication.java @@ -26,28 +26,48 @@ import java.util.stream.Collectors; import org.springframework.util.CollectionUtils; +/** + * An application deployed as part of the service provisioning process + */ @SuppressWarnings("PMD.GodClass") public class BackingApplication { private static final String VALUE_HIDDEN = "