This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push:
new b753326a3 Ref #315: Fix camel-mail and add integration tests (#316)
b753326a3 is described below
commit b753326a3e9738d88cefd6b7ef9b603d01ad29c0
Author: François de Parscau <[email protected]>
AuthorDate: Tue Jun 4 11:55:31 2024 +0200
Ref #315: Fix camel-mail and add integration tests (#316)
* Add camel-bean test
* fix PR comments
* Update
tests/features/camel-mail/src/main/java/org/apache/karaf/camel/test/CamelMailRouteSupplier.java
* Update
tests/features/camel-mail/src/main/java/org/apache/karaf/camel/test/CamelMailRouteSupplier.java
* Update
tests/features/camel-mail/src/test/java/org/apache/karaf/camel/itest/CamelMailITest.java
* fix PR comments for ports
---------
Co-authored-by: Nicolas Filotto <[email protected]>
---
components/camel-mail/pom.xml | 1 -
features/src/main/feature/camel-features.xml | 4 +-
.../camel/itests/GenericContainerResource.java | 2 +-
tests/features/camel-mail/pom.xml | 42 ++++++++++++++++
.../karaf/camel/test/CamelMailRouteSupplier.java | 53 ++++++++++++++++++++
.../apache/karaf/camel/itest/CamelMailITest.java | 58 ++++++++++++++++++++++
tests/features/pom.xml | 1 +
7 files changed, 158 insertions(+), 3 deletions(-)
diff --git a/components/camel-mail/pom.xml b/components/camel-mail/pom.xml
index 64fbf23ca..6e41346cc 100644
--- a/components/camel-mail/pom.xml
+++ b/components/camel-mail/pom.xml
@@ -38,7 +38,6 @@
</camel.osgi.export>
<camel.osgi.import>
jakarta.mail*;version="[2,3)",
- org.eclipse.angus*;resolution:=optional,
*
</camel.osgi.import>
</properties>
diff --git a/features/src/main/feature/camel-features.xml
b/features/src/main/feature/camel-features.xml
index a9b71ef09..52d31f837 100644
--- a/features/src/main/feature/camel-features.xml
+++ b/features/src/main/feature/camel-features.xml
@@ -1611,8 +1611,10 @@
<bundle>mvn:org.apache.camel.karaf/camel-lzf/${project.version}</bundle>
</feature>
<feature name='camel-mail' version='${project.version}' start-level='50'>
+ <feature prerequisite="true">spifly</feature>
<feature version='${camel.osgi.version.range}'>camel-core</feature>
- <bundle dependency='true'>mvn:com.sun.mail/jakarta.mail/2.0.1</bundle>
+ <bundle
dependency="true">mvn:jakarta.mail/jakarta.mail-api/2.1.3</bundle>
+ <bundle
dependency='true'>mvn:org.eclipse.angus/angus-mail/${angus-mail-version}</bundle>
<bundle>mvn:org.apache.camel.karaf/camel-attachments/${project.version}</bundle>
<bundle>mvn:org.apache.camel.karaf/camel-mail/${project.version}</bundle>
</feature>
diff --git
a/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/GenericContainerResource.java
b/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/GenericContainerResource.java
index 8a188ceed..5adbbba90 100644
---
a/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/GenericContainerResource.java
+++
b/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/GenericContainerResource.java
@@ -67,7 +67,6 @@ public class GenericContainerResource<T extends
GenericContainer<T>> implements
@Override
public void after() {
- container.stop();
for (ExternalResource dependency : dependencies) {
try {
dependency.after();
@@ -75,6 +74,7 @@ public class GenericContainerResource<T extends
GenericContainer<T>> implements
LOG.warn("Error cleaning dependency: {}",
dependency.getClass().getName(), e);
}
}
+ container.stop();
LOG.info("Container {} stopped", container.getDockerImageName());
}
diff --git a/tests/features/camel-mail/pom.xml
b/tests/features/camel-mail/pom.xml
new file mode 100644
index 000000000..83a6ad022
--- /dev/null
+++ b/tests/features/camel-mail/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ 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.karaf</groupId>
+ <artifactId>camel-karaf-features-test</artifactId>
+ <version>4.6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-mail-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: Mail</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>${testcontainers-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git
a/tests/features/camel-mail/src/main/java/org/apache/karaf/camel/test/CamelMailRouteSupplier.java
b/tests/features/camel-mail/src/main/java/org/apache/karaf/camel/test/CamelMailRouteSupplier.java
new file mode 100644
index 000000000..5bdfad012
--- /dev/null
+++
b/tests/features/camel-mail/src/main/java/org/apache/karaf/camel/test/CamelMailRouteSupplier.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.karaf.camel.test;
+
+import java.util.function.Function;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+
+@Component(
+ name = "karaf-camel-mail-test",
+ immediate = true,
+ service = CamelRouteSupplier.class
+)
+public class CamelMailRouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+
+ @Override
+ protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+ return builder ->
+ builder.fromF(
+
"pop3://camel@localhost:%s?password=foo&initialDelay=100&delay=500",
System.getProperty("pop3.port"))
+ .log("received message ${body} from:${header.from}
to:${header.to} subj: ${header.subject}");
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition
producerRoute) {
+ producerRoute.log("calling mail endpoint")
+ .setBody(builder.constant("OK"))
+ .setHeader("Subject", builder.constant("Test"))
+ .setHeader("From", builder.constant("origin@localhost"))
+ .setHeader("To", builder.constant("camel@localhost"))
+ .toF("smtp://camel@localhost:%s?password=foo",
System.getProperty("smtp.port"));
+ }
+}
+
diff --git
a/tests/features/camel-mail/src/test/java/org/apache/karaf/camel/itest/CamelMailITest.java
b/tests/features/camel-mail/src/test/java/org/apache/karaf/camel/itest/CamelMailITest.java
new file mode 100644
index 000000000..1a7dee35f
--- /dev/null
+++
b/tests/features/camel-mail/src/test/java/org/apache/karaf/camel/itest/CamelMailITest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+package org.apache.karaf.camel.itest;
+
+import java.util.function.Consumer;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.karaf.camel.itests.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.testcontainers.containers.GenericContainer;
+
+@CamelKarafTestHint(externalResourceProvider =
CamelMailITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelMailITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ private static final int SMTP_PORT = 3025;
+ private static final int POP3_PORT = 3110;
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived("OK\r\n");
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ assertMockEndpointsSatisfied();
+ }
+
+ public static final class ExternalResourceProviders {
+
+ public static GenericContainerResource createGreenMailContainer() {
+ final GenericContainer<?> greenMailContainer =
+ new GenericContainer<>("greenmail/standalone:2.0.1")
+ .withExposedPorts(SMTP_PORT, POP3_PORT)
+ .withEnv("GREENMAIL_OPTS",
"-Dgreenmail.users=camel:foo@localhost -Dgreenmail.setup.test.all
-Dgreenmail.hostname=0.0.0.0 -Dgreenmail.auth.disabled");
+
+ return new GenericContainerResource(greenMailContainer,
(Consumer<GenericContainerResource>) resource -> {
+ resource.setProperty("smtp.port",
Integer.toString(greenMailContainer.getMappedPort(SMTP_PORT)));
+ resource.setProperty("pop3.port",
Integer.toString(greenMailContainer.getMappedPort(POP3_PORT)));
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 451b6745c..9138cfc22 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -41,6 +41,7 @@
<module>camel-core</module>
<module>camel-elasticsearch</module>
<module>camel-jetty</module>
+ <module>camel-mail</module>
</modules>
<dependencyManagement>