Polish "Add Spring Cloud Function"

Closes gh-670
This commit is contained in:
Stephane Nicoll
2018-07-13 16:32:33 +02:00
parent 411b096fec
commit 3bf4e019c3
3 changed files with 44 additions and 22 deletions

View File

@@ -16,6 +16,9 @@
package io.spring.initializr.service.extension;
import java.util.ArrayList;
import java.util.List;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
@@ -32,7 +35,7 @@ import org.springframework.stereotype.Component;
class SpringCloudFunctionRequestPostProcessor
extends AbstractProjectRequestPostProcessor {
static final Dependency STREAM_ADAPTER = Dependency.withId("cloud-function-stream",
static final Dependency SCS_ADAPTER = Dependency.withId("cloud-function-stream",
"org.springframework.cloud", "spring-cloud-function-stream");
static final Dependency WEB_ADAPTER = Dependency.withId("cloud-function-web",
@@ -41,14 +44,20 @@ class SpringCloudFunctionRequestPostProcessor
@Override
public void postProcessAfterResolution(ProjectRequest request,
InitializrMetadata metadata) {
boolean hasSpringCloudStream = hasDependency(request, "cloud-stream") || hasDependency(request, "reactive-cloud-stream");
// TODO: add webflux when s-c-f is ready
boolean hasWeb = hasDependency(request, "web");
if (hasSpringCloudStream) {
request.getResolvedDependencies().add(STREAM_ADAPTER);
}
if (hasWeb) {
request.getResolvedDependencies().add(WEB_ADAPTER);
Dependency cloudFunction = getDependency(request, "cloud-function");
if (cloudFunction != null) {
List<Dependency> swap = new ArrayList<>();
if (hasDependency(request, "cloud-stream")
|| hasDependency(request, "reactive-cloud-stream")) {
swap.add(SCS_ADAPTER);
}
if (hasDependency(request, "web")) {
swap.add(WEB_ADAPTER);
}
if (!swap.isEmpty()) {
request.getResolvedDependencies().remove(cloudFunction);
request.getResolvedDependencies().addAll(swap);
}
}
}

View File

@@ -821,12 +821,11 @@ initializr:
description: Functions as Spring Beans
versionRange: 2.0.2.RELEASE
links:
- rel: home
- rel: reference
href: https://cloud.spring.io/spring-cloud-function/
description: Spring Cloud Function home page
- rel: sample
href: https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-samples/function-sample
description: A sample app using Spring Cloud Function
href: https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-samples
description: Various sample apps using Spring Cloud Function
- name: Cloud Security
id: cloud-security
description: Secure load balancing and routing with spring-cloud-security

View File

@@ -17,12 +17,8 @@
package io.spring.initializr.service.extension;
import io.spring.initializr.generator.ProjectRequest;
import org.junit.Test;
import static io.spring.initializr.service.extension.SpringCloudFunctionRequestPostProcessor.STREAM_ADAPTER;
import static io.spring.initializr.service.extension.SpringCloudFunctionRequestPostProcessor.WEB_ADAPTER;
/**
* Tests for {@link SpringCloudFunctionRequestPostProcessor}.
*
@@ -31,21 +27,39 @@ import static io.spring.initializr.service.extension.SpringCloudFunctionRequestP
public class SpringCloudFunctionRequestPostProcessorTests
extends AbstractRequestPostProcessorTests {
@Test
public void functionOnly() {
ProjectRequest request = createProjectRequest("cloud-function");
generateMavenPom(request).hasDependency(getDependency("cloud-function"))
.hasSpringBootStarterTest().hasDependenciesCount(2);
}
@Test
public void springCloudStreamWithRabbit() {
ProjectRequest request = createProjectRequest("cloud-stream", "amqp",
"cloud-function");
generateMavenPom(request).hasDependency(getDependency("cloud-stream"))
.hasDependency(getDependency("amqp")).hasDependency(STREAM_ADAPTER)
.hasDependenciesCount(7);
.hasDependency(getDependency("amqp"))
.hasDependency(SpringCloudFunctionRequestPostProcessor.SCS_ADAPTER)
.hasDependenciesCount(6);
}
@Test
public void reactiveSpringCloudStreamWithKafka() {
ProjectRequest request = createProjectRequest("reactive-cloud-stream", "kafka",
"cloud-function");
generateMavenPom(request).hasDependency(getDependency("reactive-cloud-stream"))
.hasDependency(getDependency("kafka"))
.hasDependency(SpringCloudFunctionRequestPostProcessor.SCS_ADAPTER)
.hasDependenciesCount(6);
}
@Test
public void web() {
ProjectRequest request = createProjectRequest("web", "cloud-function");
generateMavenPom(request).hasDependency(getDependency("cloud-function"))
.hasDependency(getDependency("web")).hasDependency(WEB_ADAPTER)
.hasDependenciesCount(4);
generateMavenPom(request).hasDependency(getDependency("web"))
.hasDependency(SpringCloudFunctionRequestPostProcessor.WEB_ADAPTER)
.hasDependenciesCount(3);
}
}