Skip to content
Permalink
Browse files
Related to #423 added generator plugin testing.
  • Loading branch information
valdar committed Oct 25, 2021
1 parent c088849 commit c9f275d3801f71c19e3d0a1f8a5aabd6f73fe76f
Showing 13 changed files with 152 additions and 24 deletions.
@@ -38,7 +38,6 @@
import org.apache.kafka.connect.sink.ErrantRecordReporter;
import org.apache.kafka.connect.sink.SinkRecord;
import org.apache.kafka.connect.sink.SinkTask;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -157,7 +156,6 @@ public void start(Map<String, String> props) {
}
}

@NotNull
protected String getSinkKamelet() {
return DEFAULT_KAMELET_CKC_SINK;
}
@@ -182,7 +182,6 @@ public Integer get() {
}
}

@NotNull
protected String getSourceKamelet() {
return DEFAULT_KAMELET_CKC_SOURCE;
}
@@ -6,6 +6,7 @@

* <<running-the-tests,Running The Tests>>
* <<writing-new-tests,Writing New Tests>>
* <<running-generator-plugin-tests,Running Maven Generator Plugin tests>>

[#running-the-tests]
== Running The Tests
@@ -219,3 +220,14 @@ Kafka's Connect own runtime libraries.

The test code should avoid printing data to the stdout. Instead, the default project logger should be used. Every
connector module has its own log file. Tests for new connectors should ensure that the relevant information is logged.

[#running-generator-plugin-tests]
== Running Maven Generator Plugin tests
In order to run tests for `tooling/camel-kafka-generator-maven-plugin` please run:

[source,bash]
----
$ ./mvnw clean install -pl :camel-kafka-connector-generator-maven-plugin -am -Pmaven-it
----

this can be useful during adjustments or new features development of `tooling/camel-kafka-generator-maven-plugin`.
@@ -30,6 +30,7 @@
<kafka.version>2.8.0</kafka.version>
<camel.version>3.11.1</camel.version>
<camel.kamelet.catalog.version>0.3.0</camel.kamelet.catalog.version>
<camel.k.runtime.version>1.8.0</camel.k.runtime.version>
<apicurio.registry.version>1.3.2.Final</apicurio.registry.version>
<resteasy.version>4.5.6.Final</resteasy.version>
<version.java>1.8</version.java>
@@ -117,6 +118,14 @@
<version>${version.guava}</version>
</dependency>

<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-bom</artifactId>
<version>${camel.k.runtime.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifactId>camel-kamelets-catalog</artifactId>
@@ -33,6 +33,7 @@

<properties>
<maven-version>3.6.3</maven-version>
<classgraph.version>4.8.110</classgraph.version>
</properties>

<dependencyManagement>
@@ -115,12 +116,10 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<!-- <version>${jackson.version}</version>-->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<!-- <version>${jackson.version}</version>-->
</dependency>

<!-- camel -->
@@ -195,6 +194,12 @@
</dependency>

<!-- testing -->
<dependency>
<groupId>org.apache.camel.kafkaconnector</groupId>
<artifactId>camel-kafka-connector</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
@@ -273,6 +278,31 @@
</activation>
<build>
<plugins>
<!-- <plugin>-->
<!-- <artifactId>maven-resources-plugin</artifactId>-->
<!-- <version>3.0.2</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>copy-resource-one</id>-->
<!-- <phase>generate-sources</phase>-->
<!-- <goals>-->
<!-- <goal>copy-resources</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <outputDirectory>${basedir}/src/test/resources-its/org/apache/camel/kafkaconnector/maven/GenerateCamelKafkaConnectorsMojoIT/.predefined-repo/org/apache/camel/kafkaconnector/camel-kafka-connector/${project.version}</outputDirectory>-->
<!-- <resources>-->
<!-- <resource>-->
<!-- <directory>${basedir}/../../core/target/</directory>-->
<!-- <includes>-->
<!-- <include>camel-kafka-connector-${project.version}.jar</include>-->
<!-- </includes>-->
<!-- </resource>-->
<!-- </resources>-->
<!-- <overwrite>true</overwrite>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>com.soebes.itf.jupiter.extension</groupId>
<artifactId>itf-maven-plugin</artifactId>
@@ -451,7 +451,7 @@ private void createClassesAndDocumentation(String sanitizedName, File connectorD
}

Method getSinkOrSourceKameletMethod = javaClassTask.addMethod().setConstructor(false).setName("get" + ctCapitalizedName + "Kamelet").setProtected().setReturnType("String")
.setBody("return \"kamelet:" + name + "\"");
.setBody("return \"kamelet:" + name + "\";");
getSinkOrSourceKameletMethod.addAnnotation(Override.class);

String javaClassTaskFileName = packageName.replaceAll("\\.", "\\/") + File.separator + javaClassTaskName + ".java";
@@ -596,9 +596,9 @@ private void addConnectorOptions(String sanitizedName, ConnectorType ct, JavaCla
javaClass.addField().setFinal(true).setPublic().setStatic(true).setName(confFieldName).setType(String.class).setStringInitializer(propertyValue);

String docFieldName = propertyPrefix + "DOC";
String docLiteralInitializer = kameletProperty.getDescription();
String docLiteralInitializer = kameletProperty.getDescription().replace("\n", " ");
if (kameletProperty.getExample() != null) {
docLiteralInitializer = docLiteralInitializer + " Example: " + kameletProperty.getExample();
docLiteralInitializer = docLiteralInitializer + " Example: " + kameletProperty.getExample().replace("\n", " ");
}
javaClass.addField().setFinal(true).setPublic().setStatic(true).setName(docFieldName).setType(String.class).setStringInitializer(docLiteralInitializer);

@@ -19,9 +19,9 @@
# Use comma-separated values to include multiple dependencies

# Global dependencies included in all modules (except the ones in the list)
global=
global=org.apache.camel.kafkaconnector:camel-kafka-connector,org.apache.camel:camel-jackson

# we add a default connection factory maven variables can be used as ${varname}
#camel-sjms2=org.apache.activemq:activemq-client::runtime,org.apache.activemq:artemis-jms-client::runtime
#exclude_camel-sjms2=
#additional_properties_camel-sjms2=camel.component.sjms2.connection-factory=#class:org.apache.activemq.ActiveMQConnectionFactory,camel.component.sjms2.connection-factory.brokerURL=tcp://localhost:61616
camel-sjms2=org.apache.activemq:activemq-client::runtime,org.apache.activemq:artemis-jms-client::runtime
exclude_camel-sjms2=
additional_properties_camel-sjms2=camel.component.sjms2.connection-factory=#class:org.apache.activemq.ActiveMQConnectionFactory,camel.component.sjms2.connection-factory.brokerURL=tcp://localhost:61616
@@ -21,9 +21,7 @@
# Global dependencies included in all modules (except the ones in the list)
global=org.apache.camel.kafkaconnector:camel-kafka-connector

camel-couchbase=com.couchbase.client:java-client::runtime

# we add a default connection factory maven variables can be used as ${varname}
camel-sjms2=org.apache.activemq:activemq-client::runtime,org.apache.activemq:artemis-jms-client::runtime
exclude_camel-sjms2=
additional_properties_camel-sjms2=camel.component.sjms2.connection-factory=#class:org.apache.activemq.ActiveMQConnectionFactory,camel.component.sjms2.connection-factory.brokerURL=tcp://localhost:61616
#camel-sjms2=org.apache.activemq:activemq-client::runtime,org.apache.activemq:artemis-jms-client::runtime
#exclude_camel-sjms2=
#additional_properties_camel-sjms2=camel.component.sjms2.connection-factory=#class:org.apache.activemq.ActiveMQConnectionFactory,camel.component.sjms2.connection-factory.brokerURL=tcp://localhost:61616
@@ -27,21 +27,35 @@
import java.util.Set;
import java.util.stream.Collectors;

import com.soebes.itf.jupiter.extension.MavenGoal;
import com.soebes.itf.jupiter.extension.MavenJupiterExtension;
import com.soebes.itf.jupiter.extension.MavenOption;
import com.soebes.itf.jupiter.extension.MavenPredefinedRepository;
import com.soebes.itf.jupiter.extension.MavenProject;
import com.soebes.itf.jupiter.extension.MavenRepository;
import com.soebes.itf.jupiter.extension.MavenTest;
import com.soebes.itf.jupiter.maven.MavenExecutionResult;
import org.apache.camel.kafkaconnector.maven.utils.MavenUtils;
import org.apache.camel.tooling.util.Strings;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;

import static com.soebes.itf.extension.assertj.MavenExecutionResultAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

@MavenJupiterExtension
@MavenRepository
//@MavenPredefinedRepository
@MavenProject
@TestMethodOrder( MethodOrderer.OrderAnnotation.class )
class GenerateCamelKafkaConnectorsMojoIT {

@MavenTest
@Order(10)
@MavenGoal("clean")
@MavenGoal("verify")
// @MavenOption("--no-snapshot-updates")
// @MavenOption(MavenCLIOptions.DEBUG)
public void test_generate(MavenExecutionResult result) throws IOException {
assertThat(result).isSuccessful();
@@ -53,6 +67,7 @@ public void test_generate(MavenExecutionResult result) throws IOException {
.anyMatch(s -> s.startsWith("Kamelets found to be used to generate/update a kafka connector: ["))
.anyMatch(s -> s.startsWith("Creating camel kafka connector for"))
.anyMatch(s -> s.startsWith("Creating camel kafka kamelet connector for"))
.anyMatch(s -> s.startsWith("Connectors previously generated found to be removed: []"))
.containsSequence(
"Creating a new pom.xml for the connector from scratch",
"Creating a new package.xml for the connector.")
@@ -78,6 +93,15 @@ public void test_generate(MavenExecutionResult result) throws IOException {
.forEach(m -> assertFalse(files.contains(m), "component should be excluded"));
}

@MavenTest
@Order(20)
@MavenGoal("package")
// @MavenOption("--no-snapshot-updates")
// @MavenOption(MavenCLIOptions.DEBUG)
public void test_build(MavenExecutionResult result) throws IOException {
assertThat(result).isSuccessful();
}

private List<String> extractExcluded(List<String> stdout) {
return stdout.stream()
.filter(s -> s.startsWith("[INFO] Excluded Components that won't be used to generate a kafka connector: ["))
@@ -21,21 +21,63 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.kafkaconnector</groupId>
<artifactId>parent</artifactId>
<version>@project.version@</version>
</parent>

<groupId>org.apache.camel.kafkaconnector.test</groupId>
<artifactId>test-project</artifactId>
<version>1.0-SNAPSHOT</version>
<version>@project.version@</version>
<packaging>pom</packaging>
<name>Test Project</name>

<repositories>
<!-- camel-jira -->
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/maven-external</url>
<name>Atlassian Public Repo</name>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<!-- camel-ipfs and camel-weka -->
<repository>
<id>jboss.thirdparty</id>
<name>JBoss Thirdparty Repository</name>
<url>https://repository.jboss.org/nexus/service/local/repositories/thirdparty-releases/content/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.kafkaconnector</groupId>
<artifactId>camel-kafka-connector</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.camel.kafkaconnector</groupId>
<artifactId>camel-kafka-connector-generator-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<connectorsProjectName>\${project.artifactId}</connectorsProjectName>
<connectorsProjectName>test-project</connectorsProjectName>
<!-- set to true to make build fail fast if missing documentation in docs files -->
<!-- <failFast>false</failFast> -->
<!-- set to true to make build fail if an option has no description -->
@@ -72,6 +114,7 @@
<exampleSinkPropertiesFileTemplate>
${project.build.testOutputDirectory}/camel-kafka-connector-template-example-sink-properties.template
</exampleSinkPropertiesFileTemplate>
<removeMissingComponents>true</removeMissingComponents>
<excludedComponents>
<param>bonita</param>
<param>bean-validator</param>
@@ -114,6 +157,22 @@
</plugins>
</build>

<profiles>
<profile>
<id>java11-build</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</profile>
</profiles>

<modules>
</modules>
</project>
@@ -22,8 +22,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.kafkaconnector</groupId>
<artifactId>connectors</artifactId>
<groupId>org.apache.camel.kafkaconnector.test</groupId>
<artifactId>test-project</artifactId>
<version>${version}</version>
</parent>

@@ -22,8 +22,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.kafkaconnector</groupId>
<artifactId>connectors</artifactId>
<groupId>org.apache.camel.kafkaconnector.test</groupId>
<artifactId>test-project</artifactId>
<version>${version}</version>
</parent>

@@ -51,7 +51,6 @@
<jandex-version>2.1.1.Final</jandex-version>
<mvel-version>2.4.12.Final</mvel-version>
<roaster-version>2.20.1.Final</roaster-version>
<classgraph.version>4.8.110</classgraph.version>
</properties>

<build>

0 comments on commit c9f275d

Please sign in to comment.