diff --git a/starter-core/src/main/java/io/micronaut/starter/feature/database/Neo4jBolt.java b/starter-core/src/main/java/io/micronaut/starter/feature/database/Neo4jBolt.java index 2a7fcfe4d9d..c8468b89871 100644 --- a/starter-core/src/main/java/io/micronaut/starter/feature/database/Neo4jBolt.java +++ b/starter-core/src/main/java/io/micronaut/starter/feature/database/Neo4jBolt.java @@ -21,21 +21,30 @@ import io.micronaut.starter.build.dependencies.Dependency; import io.micronaut.starter.build.dependencies.MicronautDependencyUtils; import io.micronaut.starter.feature.Category; -import io.micronaut.starter.feature.Feature; +import io.micronaut.starter.feature.testcontainers.ContributingTestContainerArtifactId; +import io.micronaut.starter.feature.testresources.EaseTestingFeature; +import io.micronaut.starter.feature.testresources.TestResources; import jakarta.inject.Singleton; @Singleton -public class Neo4jBolt implements Feature { - private static final Dependency DEPENDENCY_NEO4J_HARNESS = Dependency.builder() - .groupId("org.neo4j.test") - .artifactId("neo4j-harness") - .testRuntime() +public class Neo4jBolt extends EaseTestingFeature implements ContributingTestContainerArtifactId { + + public static final String NAME = "neo4j-bolt"; + private static final String TEST_CONTAINERS_ARTIFACT_ID_NEO4J = "neo4j"; + + private static final Dependency DEPENDENCY_NEO4J = MicronautDependencyUtils.neo4j() + .artifactId("micronaut-neo4j-bolt") + .compile() .build(); + public Neo4jBolt(TestContainers testContainers, TestResources testResources) { + super(testContainers, testResources); + } + @Override @NonNull public String getName() { - return "neo4j-bolt"; + return NAME; } @Override @@ -52,10 +61,7 @@ public String getDescription() { @Override public void apply(GeneratorContext generatorContext) { generatorContext.getConfiguration().put("neo4j.uri", "bolt://${NEO4J_HOST:localhost}"); - generatorContext.addDependency(MicronautDependencyUtils.neo4j() - .artifactId("micronaut-neo4j-bolt") - .compile()); - generatorContext.addDependency(DEPENDENCY_NEO4J_HARNESS); + generatorContext.addDependency(DEPENDENCY_NEO4J); } @Override @@ -72,4 +78,14 @@ public String getCategory() { public String getMicronautDocumentation() { return "https://micronaut-projects.github.io/micronaut-neo4j/latest/guide/index.html"; } + + @Override + public String getThirdPartyDocumentation() { + return "https://neo4j.com/docs/java-manual/current/"; + } + + @Override + public String testContainersArtifactId() { + return TEST_CONTAINERS_ARTIFACT_ID_NEO4J; + } } diff --git a/starter-core/src/test/groovy/io/micronaut/starter/feature/database/Neo4jBoltSpec.groovy b/starter-core/src/test/groovy/io/micronaut/starter/feature/database/Neo4jBoltSpec.groovy index 8f4a0052a6b..b4c12d6b232 100644 --- a/starter-core/src/test/groovy/io/micronaut/starter/feature/database/Neo4jBoltSpec.groovy +++ b/starter-core/src/test/groovy/io/micronaut/starter/feature/database/Neo4jBoltSpec.groovy @@ -20,6 +20,7 @@ class Neo4jBoltSpec extends ApplicationContextSpec implements CommandOutputFixt then: readme readme.contains("https://micronaut-projects.github.io/micronaut-neo4j/latest/guide/index.html") + readme.contains("https://neo4j.com/docs/java-manual/current/") } void "test neo4j bolt features"() { @@ -30,26 +31,69 @@ class Neo4jBoltSpec extends ApplicationContextSpec implements CommandOutputFixt features.contains("neo4j-bolt") } - void "test dependencies are present for #buildTool"(BuildTool buildTool) { + void "test config"() { + when: + GeneratorContext ctx = buildGeneratorContext(['neo4j-bolt']) + + then: + ctx.getConfiguration().get("neo4j.uri") == "bolt://\${NEO4J_HOST:localhost}" + } + + void "neo4j-bolt dependency is present for build tool #buildTool"(BuildTool buildTool) { when: String template = new BuildBuilder(beanContext, buildTool) - .features(["neo4j-bolt"]) + .features(['neo4j-bolt']) .render() BuildTestVerifier verifier = BuildTestUtil.verifier(buildTool, template) then: - verifier.hasDependency("io.micronaut.neo4j", "micronaut-neo4j-bolt", Scope.COMPILE) - verifier.hasDependency("org.neo4j.test", "neo4j-harness", Scope.TEST_RUNTIME) + verifier.hasDependency("io.micronaut.neo4j","micronaut-neo4j-bolt") + !verifier.hasDependency("org.testcontainers","neo4j", Scope.TEST) where: buildTool << BuildTool.values() } - void "test config"() { + void "testcontainers neo4j-bolt dependency is present for build tool #buildTool"(BuildTool buildTool) { when: - GeneratorContext ctx = buildGeneratorContext(['neo4j-bolt']) + String template = new BuildBuilder(beanContext, buildTool) + .features(['neo4j-bolt','testcontainers']) + .render() + BuildTestVerifier verifier = BuildTestUtil.verifier(buildTool, template) then: - ctx.getConfiguration().get("neo4j.uri") == "bolt://\${NEO4J_HOST:localhost}" + verifier.hasDependency("org.testcontainers","neo4j", Scope.TEST) + + where: + buildTool << BuildTool.values() + } + + void "test neo4j-bolt test-resources for build tool #buildTool"(BuildTool buildTool) { + when: + String template = new BuildBuilder(beanContext, buildTool) + .features(['neo4j-bolt','test-resources']) + .render() + BuildTestVerifier verifier = BuildTestUtil.verifier(buildTool, template) + + then: + !verifier.hasDependency("org.testcontainers","neo4j", Scope.TEST) + !verifier.hasDependency("org.testcontainers","testcontainers", Scope.TEST) + verifier.hasBuildPlugin("io.micronaut.test-resources") + + where: + buildTool << BuildTool.valuesGradle() + } + + void "test neo4j-bolt test-resources for build tool Maven"() { + when: + String template = new BuildBuilder(beanContext, BuildTool.MAVEN) + .features(['neo4j-bolt','test-resources']) + .render() + BuildTestVerifier verifier = BuildTestUtil.verifier(BuildTool.MAVEN, template) + + then: + !verifier.hasDependency("org.testcontainers","neo4j", Scope.TEST) + !verifier.hasDependency("org.testcontainers","testcontainers", Scope.TEST) + verifier.hasDependency("io.micronaut.testresources","micronaut-test-resources-client") } } diff --git a/starter-core/src/test/groovy/io/micronaut/starter/feature/database/TestContainersSpec.groovy b/starter-core/src/test/groovy/io/micronaut/starter/feature/database/TestContainersSpec.groovy index 0600b9c0a6f..18f19ce7aa2 100644 --- a/starter-core/src/test/groovy/io/micronaut/starter/feature/database/TestContainersSpec.groovy +++ b/starter-core/src/test/groovy/io/micronaut/starter/feature/database/TestContainersSpec.groovy @@ -91,6 +91,17 @@ class TestContainersSpec extends ApplicationContextSpec { template.contains('testImplementation("org.testcontainers:testcontainers")') } + void "test neo4j dependency is present for gradle"() { + when: + String template = new BuildBuilder(beanContext, BuildTool.GRADLE) + .features([TestContainers.NAME, Neo4jBolt.NAME]) + .render() + + then: + template.contains('testImplementation("org.testcontainers:neo4j")') + template.contains('testImplementation("org.testcontainers:testcontainers")') + } + void "test testcontainers core is present when no testcontainer modules are present for gradle"() { when: String template = new BuildBuilder(beanContext, BuildTool.GRADLE) diff --git a/starter-core/src/test/groovy/io/micronaut/starter/feature/testresources/OptionalTestContainerSpec.groovy b/starter-core/src/test/groovy/io/micronaut/starter/feature/testresources/OptionalTestContainerSpec.groovy index fe3a4039f70..b3e3b5952fd 100644 --- a/starter-core/src/test/groovy/io/micronaut/starter/feature/testresources/OptionalTestContainerSpec.groovy +++ b/starter-core/src/test/groovy/io/micronaut/starter/feature/testresources/OptionalTestContainerSpec.groovy @@ -10,6 +10,7 @@ import io.micronaut.starter.feature.database.MariaDB import io.micronaut.starter.feature.database.MongoReactive import io.micronaut.starter.feature.database.MongoSync import io.micronaut.starter.feature.database.MySQL +import io.micronaut.starter.feature.database.Neo4jBolt import io.micronaut.starter.feature.database.Oracle import io.micronaut.starter.feature.database.PostgreSQL import io.micronaut.starter.feature.database.SQLServer @@ -34,6 +35,7 @@ class OptionalTestContainerSpec extends ApplicationContextSpec { Mqtt.NAME, MongoSync.NAME, MongoReactive.NAME, + Neo4jBolt.NAME, HibernateReactiveJpa.NAME, DataHibernateReactive.NAME, ]