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 1d9c947d Ref #489: Add camel-exec integration test (#490)
1d9c947d is described below

commit 1d9c947d57de41743595675f0774cc4d1aa9a4e2
Author: François de Parscau <[email protected]>
AuthorDate: Tue Aug 27 12:40:36 2024 +0200

    Ref #489: Add camel-exec integration test (#490)
---
 tests/features/camel-exec/pom.xml                  | 40 ++++++++++++++++
 .../karaf/camel/test/CamelExecRouteSupplier.java   | 40 ++++++++++++++++
 .../apache/karaf/camel/itest/CamelExecITest.java   | 55 ++++++++++++++++++++++
 tests/features/pom.xml                             |  1 +
 4 files changed, 136 insertions(+)

diff --git a/tests/features/camel-exec/pom.xml 
b/tests/features/camel-exec/pom.xml
new file mode 100644
index 00000000..87d22285
--- /dev/null
+++ b/tests/features/camel-exec/pom.xml
@@ -0,0 +1,40 @@
+<?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-exec-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: Exec</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-exec</artifactId>
+            <version>${camel-version}</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-exec/src/main/java/org/apache/karaf/camel/test/CamelExecRouteSupplier.java
 
b/tests/features/camel-exec/src/main/java/org/apache/karaf/camel/test/CamelExecRouteSupplier.java
new file mode 100644
index 00000000..18dc4c05
--- /dev/null
+++ 
b/tests/features/camel-exec/src/main/java/org/apache/karaf/camel/test/CamelExecRouteSupplier.java
@@ -0,0 +1,40 @@
+/*
+ * 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.osgi.service.component.annotations.Component;
+
+@Component(
+        name = "karaf-camel-exec-test",
+        immediate = true,
+        service = CamelExecRouteSupplier.class
+)
+public class CamelExecRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    @Override
+    protected boolean consumerEnabled() {
+        return false;
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        configureConsumer(producerRoute.to("exec:java?args=-server -version"));
+    }
+}
+
diff --git 
a/tests/features/camel-exec/src/test/java/org/apache/karaf/camel/itest/CamelExecITest.java
 
b/tests/features/camel-exec/src/test/java/org/apache/karaf/camel/itest/CamelExecITest.java
new file mode 100644
index 00000000..c480da6d
--- /dev/null
+++ 
b/tests/features/camel-exec/src/test/java/org/apache/karaf/camel/itest/CamelExecITest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.io.IOException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Predicate;
+import org.apache.camel.component.exec.ExecResult;
+import org.apache.camel.component.mock.MockEndpoint;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.PaxExamWithExternalResource;
+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;
+
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelExecITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedMessageCount(1);
+        mock.expectedMessagesMatches(new Predicate() {
+
+            @Override
+            public boolean matches(Exchange exchange) {
+                ExecResult execResult = 
exchange.getIn().getBody(ExecResult.class);
+                try {
+                    String out = new 
String(execResult.getStderr().readAllBytes());
+                    return out.contains("Server VM") && 
execResult.getExitValue() == 0;
+                } catch (IOException e) {
+                    return false;
+                }
+            }
+        });
+    }
+
+    @Test
+    public void testResultMock() throws Exception {
+        assertMockEndpointsSatisfied();
+    }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 41c1eba7..1c7dfe1f 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -72,6 +72,7 @@
         <module>camel-drill</module>
         <module>camel-ehcache</module>
         <module>camel-elasticsearch</module>
+        <module>camel-exec</module>
         <module>camel-fastjson</module>
         <module>camel-flatpack</module>
         <module>camel-ftp</module>

Reply via email to