Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions packaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,63 @@
<artifactId>source-connector</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>connect-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<filtering>true</filtering>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>test-resources</id>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down Expand Up @@ -104,7 +158,21 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>test-compile</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<testOutputDirectory>target/test-classes</testOutputDirectory>
</build>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Neo4jSinkCypher
topics=people
topics=knows
connector.class=org.neo4j.connectors.kafka.sink.Neo4jConnector
neo4j.uri=neo4j://neo4j:7687
neo4j.authentication.type=BASIC
Expand Down
155 changes: 155 additions & 0 deletions packaging/src/test/kotlin/ConfigPropertiesTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.types.shouldBeInstanceOf
import java.io.File
import java.io.FileInputStream
import java.util.*
import org.junit.jupiter.api.Test
import org.neo4j.connectors.kafka.sink.SinkConfiguration
import org.neo4j.connectors.kafka.sink.strategy.pattern.NodePattern
import org.neo4j.connectors.kafka.sink.strategy.pattern.Pattern
import org.neo4j.connectors.kafka.sink.strategy.pattern.RelationshipPattern
import org.neo4j.connectors.kafka.source.SourceConfiguration
import org.neo4j.cypherdsl.core.renderer.Renderer

class ConfigPropertiesTest {

// This test checks that the number of config files is fixed.
// If a new file is added, the test will fail, reminding the developer to update this test and add
// unit tests for the new file.
@Test
fun `should be specific amount of config files`() {
val configDirectory = File(BASE_CONFIG_PATH)
configDirectory.listFiles()!!.size shouldBe 8
}

@Test
fun `sink cdc schema quick start config should be valid`() {
val properties = loadConfigProperties("sink-cdc-schema-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.sink.Neo4jConnector"
properties["neo4j.cdc.schema.topics"] shouldNotBe null

shouldNotThrowAny { SinkConfiguration(properties, Renderer.getDefaultRenderer()) }
}

@Test
fun `sink cdc source id quick start config should be valid`() {
val properties = loadConfigProperties("sink-cdc-source-id-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.sink.Neo4jConnector"
properties["neo4j.cdc.source-id.topics"] shouldNotBe null

shouldNotThrowAny { SinkConfiguration(properties, Renderer.getDefaultRenderer()) }
}

@Test
fun `sink cud quick start config should be valid`() {
val properties = loadConfigProperties("sink-cud-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.sink.Neo4jConnector"
properties["neo4j.cud.topics"] shouldNotBe null

shouldNotThrowAny { SinkConfiguration(properties, Renderer.getDefaultRenderer()) }
}

@Test
fun `sink cypher quick start config should be valid`() {
val properties = loadConfigProperties("sink-cypher-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.sink.Neo4jConnector"
properties.keys.any { it.startsWith("neo4j.cypher.topic") } shouldBe true

shouldNotThrowAny { SinkConfiguration(properties, Renderer.getDefaultRenderer()) }
}

@Test
fun `sink pattern node quick start config should be valid`() {
val properties = loadConfigProperties("sink-pattern-node-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.sink.Neo4jConnector"

val patternKey = properties.keys.first { it.startsWith("neo4j.pattern.topic") }
patternKey shouldNotBe null

val parsedPattern = Pattern.parse(properties[patternKey] as String)
parsedPattern.shouldBeInstanceOf<NodePattern>()

shouldNotThrowAny { SinkConfiguration(properties, Renderer.getDefaultRenderer()) }
}

@Test
fun `sink pattern relationship quick start config should be valid`() {
val properties = loadConfigProperties("sink-pattern-relationship-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.sink.Neo4jConnector"

val patternKey = properties.keys.first { it.startsWith("neo4j.pattern.topic") }
patternKey shouldNotBe null

val parsedPattern = Pattern.parse(properties[patternKey] as String)
parsedPattern.shouldBeInstanceOf<RelationshipPattern>()

shouldNotThrowAny { SinkConfiguration(properties, Renderer.getDefaultRenderer()) }
}

@Test
fun `source cdc quick start config should be valid`() {
val properties = loadConfigProperties("source-cdc-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.source.Neo4jConnector"
properties["neo4j.source-strategy"] shouldBe "CDC"
properties.keys.any { it.startsWith("neo4j.cdc.topic") } shouldBe true

shouldNotThrowAny { SourceConfiguration(properties) }
}

@Test
fun `source query quick start config should be valid`() {
val properties = loadConfigProperties("source-query-quickstart.properties")

properties["connector.class"] shouldBe "org.neo4j.connectors.kafka.source.Neo4jConnector"
properties["neo4j.source-strategy"] shouldBe "QUERY"
properties["neo4j.query.topic"] shouldNotBe null
properties["neo4j.query"] shouldNotBe null

shouldNotThrowAny { SourceConfiguration(properties) }
}

private fun loadConfigProperties(fileName: String): Map<String, Any> {
val properties = Properties()
FileInputStream("$BASE_CONFIG_PATH/$fileName").use { properties.load(it) }
val originals = mutableMapOf<String, Any>()
properties.map { (k, v) -> originals[k as String] = v }
return originals
}

companion object {
var BASE_CONFIG_PATH: String

init {
val properties = Properties()
ConfigPropertiesTest::class.java.getResourceAsStream("/test.properties").use {
properties.load(it)
}
BASE_CONFIG_PATH = properties.getProperty("quickstart.config.properties.path")
}
}
}
1 change: 1 addition & 0 deletions packaging/src/test/resources/test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quickstart.config.properties.path=${project.basedir}/src/main/distributions/text/config