Skip to content

Commit

Permalink
Merge pull request #1595 from eddumelendez
Browse files Browse the repository at this point in the history
* pr/1595:
  Generate test app when kafka streams is selected

Closes gh-1595
  • Loading branch information
mhalbritter committed Sep 25, 2024
2 parents 30ae911 + d6d26c0 commit 4c30dab
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package io.spring.start.site.extension.dependency.springkafka;

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.start.site.container.DockerServiceResolver;
Expand All @@ -25,26 +26,35 @@
import org.springframework.context.annotation.Bean;

/**
* Configuration for generation of projects that depend on Spring Kafka.
* Configuration for generation of projects that depend on Spring Kafka and Kafka Streams.
*
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
@ProjectGenerationConfiguration
@ConditionalOnRequestedDependency("kafka")
class SpringKafkaProjectGenerationConfiguration {

private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.containers.KafkaContainer";

@Bean
@ConditionalOnRequestedDependency("kafka")
SpringKafkaBuildCustomizer springKafkaBuildCustomizer() {
return new SpringKafkaBuildCustomizer();
}

@Bean
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer kafkaServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("kafka", (service) -> serviceConnections
.addServiceConnection(ServiceConnection.ofContainer("kafka", service, TESTCONTAINERS_CLASS_NAME, false)));
ServiceConnectionsCustomizer kafkaServiceConnectionsCustomizer(Build build, DockerServiceResolver serviceResolver) {
return (serviceConnections) -> {
if (isKafkaEnabled(build)) {
serviceResolver.doWith("kafka", (service) -> serviceConnections.addServiceConnection(
ServiceConnection.ofContainer("kafka", service, TESTCONTAINERS_CLASS_NAME, false)));
}
};
}

private boolean isKafkaEnabled(Build build) {
return build.dependencies().has("kafka") || build.dependencies().has("kafka-streams");
}

}

0 comments on commit 4c30dab

Please sign in to comment.