You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2024/07/19 11:29:54 UTC
(camel-karaf) branch main updated: Ref #442: Add dns integration test (#443)
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 58e426a3 Ref #442: Add dns integration test (#443)
58e426a3 is described below
commit 58e426a32b817b45e4f20d0597734ea501b75391
Author: Stefan Tataru <st...@gmail.com>
AuthorDate: Fri Jul 19 13:29:48 2024 +0200
Ref #442: Add dns integration test (#443)
---
.../CamelSingleFeatureResultMockBasedRoute.java | 8 ++-
tests/features/camel-dns/pom.xml | 42 +++++++++++++++
.../karaf/camel/test/CamelDnsRouteSupplier.java | 56 +++++++++++++++++++
.../apache/karaf/camel/itest/CamelDnsITest.java | 63 ++++++++++++++++++++++
tests/features/pom.xml | 1 +
5 files changed, 168 insertions(+), 2 deletions(-)
diff --git a/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSingleFeatureResultMockBasedRoute.java b/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSingleFeatureResultMockBasedRoute.java
index c36e4b9b..cfbffd82 100644
--- a/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSingleFeatureResultMockBasedRoute.java
+++ b/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSingleFeatureResultMockBasedRoute.java
@@ -6,7 +6,7 @@ import org.apache.camel.component.mock.MockEndpoint;
public interface CamelSingleFeatureResultMockBasedRoute extends CamelSingleFeatureRoute {
default void setupMock() {
- MockEndpoint endpoint = getContext().getEndpoint("mock:%s".formatted(getTestComponentName()), MockEndpoint.class);
+ MockEndpoint endpoint = getMockEndpoint();
endpoint.setFailFast(false);
configureMock(endpoint);
}
@@ -18,6 +18,10 @@ public interface CamelSingleFeatureResultMockBasedRoute extends CamelSingleFeatu
}
}
+ default MockEndpoint getMockEndpoint() {
+ return getContext().getEndpoint("mock:%s".formatted(getTestComponentName()), MockEndpoint.class);
+ }
+
default void configureMock(MockEndpoint mock) {
mock.expectedMinimumMessageCount(1);
}
@@ -25,4 +29,4 @@ public interface CamelSingleFeatureResultMockBasedRoute extends CamelSingleFeatu
default void assertMockEndpointsSatisfied() throws InterruptedException {
MockEndpoint.assertIsSatisfied(getContext());
}
-}
+}
\ No newline at end of file
diff --git a/tests/features/camel-dns/pom.xml b/tests/features/camel-dns/pom.xml
new file mode 100644
index 00000000..e96d44ee
--- /dev/null
+++ b/tests/features/camel-dns/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.7.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-dns-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: DNS</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>dnsjava</groupId>
+ <artifactId>dnsjava</artifactId>
+ <version>${dnsjava-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/tests/features/camel-dns/src/main/java/org/apache/karaf/camel/test/CamelDnsRouteSupplier.java b/tests/features/camel-dns/src/main/java/org/apache/karaf/camel/test/CamelDnsRouteSupplier.java
new file mode 100644
index 00000000..ba55db04
--- /dev/null
+++ b/tests/features/camel-dns/src/main/java/org/apache/karaf/camel/test/CamelDnsRouteSupplier.java
@@ -0,0 +1,56 @@
+/*
+ * 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 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-dns-test",
+ immediate = true,
+ service = CamelRouteSupplier.class
+)
+public class CamelDnsRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ public static final String LOCALHOST = "localhost";
+
+ @Override
+ protected boolean consumerEnabled() {
+ return false;
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) {
+ producerRoute.log("Will get IP")
+ .setHeader("dns.domain", builder.constant(LOCALHOST))
+ .to("dns:ip")
+ .log("IP: ${body}")
+ .toF("mock:%s", getResultMockName())
+ .log("Will lookup")
+ .setHeader("dns.name", builder.constant(LOCALHOST))
+ .to("dns:lookup")
+ .log("Lookup: ${body}")
+ .toF("mock:%s", getResultMockName())
+ .log("Will dig")
+ .setHeader("dns.type", builder.constant("A"))
+ .to("dns:dig")
+ .log("Dig: ${body}")
+ .toF("mock:%s", getResultMockName());
+ }
+}
\ No newline at end of file
diff --git a/tests/features/camel-dns/src/test/java/org/apache/karaf/camel/itest/CamelDnsITest.java b/tests/features/camel-dns/src/test/java/org/apache/karaf/camel/itest/CamelDnsITest.java
new file mode 100644
index 00000000..65da86ae
--- /dev/null
+++ b/tests/features/camel-dns/src/test/java/org/apache/karaf/camel/itest/CamelDnsITest.java
@@ -0,0 +1,63 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.xbill.DNS.Message;
+import org.xbill.DNS.Record;
+import org.xbill.DNS.Section;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelDnsITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedMessageCount(3);
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint();
+ List<Exchange> exchanges = endpoint.getExchanges();
+ assertNotNull(exchanges);
+ assertEquals(3, exchanges.size());
+
+ String ip = exchanges.get(0).getIn().getBody(String.class);
+ assertNotNull(ip);
+
+ Record[] lookupAnswers = exchanges.get(1).getIn().getBody(Record[].class);
+ assertTrue(lookupAnswers.length > 0);
+ assertNotNull((lookupAnswers[0].getName()));
+
+ Message digResult = exchanges.get(2).getIn().getBody(Message.class);
+ assertNotNull(digResult.getQuestion());
+ assertNotNull(digResult.getSection(Section.ANSWER));
+
+ assertMockEndpointsSatisfied();
+ }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index a16bdffa..af363a3e 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -59,6 +59,7 @@
<module>camel-caffeine</module>
<module>camel-cbor</module>
<module>camel-core</module>
+ <module>camel-dns</module>
<!-- TODO: Fix the integration test and re-add it https://github.com/apache/camel-karaf/issues/438 -->
<!--module>camel-docker</module-->
<module>camel-drill</module>