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 3afaee26 Ref #448: Add camel-csv integration test (#449)
3afaee26 is described below

commit 3afaee26b26dd64578b0a23379989c8d7292a624
Author: Stefan Tataru <[email protected]>
AuthorDate: Fri Jul 19 15:51:24 2024 +0200

    Ref #448: Add camel-csv integration test (#449)
---
 tests/features/camel-csv/pom.xml                   | 41 +++++++++++++
 .../karaf/camel/test/CamelCsvRouteSupplier.java    | 55 +++++++++++++++++
 .../apache/karaf/camel/itest/CamelCsvITest.java    | 71 ++++++++++++++++++++++
 tests/features/pom.xml                             |  1 +
 4 files changed, 168 insertions(+)

diff --git a/tests/features/camel-csv/pom.xml b/tests/features/camel-csv/pom.xml
new file mode 100644
index 00000000..eb8a71c2
--- /dev/null
+++ b/tests/features/camel-csv/pom.xml
@@ -0,0 +1,41 @@
+<?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-csv-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: CSV</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+            <version>${camel-version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-csv/src/main/java/org/apache/karaf/camel/test/CamelCsvRouteSupplier.java
 
b/tests/features/camel-csv/src/main/java/org/apache/karaf/camel/test/CamelCsvRouteSupplier.java
new file mode 100644
index 00000000..62f4de90
--- /dev/null
+++ 
b/tests/features/camel-csv/src/main/java/org/apache/karaf/camel/test/CamelCsvRouteSupplier.java
@@ -0,0 +1,55 @@
+/*
+ * 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.camel.model.dataformat.CsvDataFormat;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+        name = "karaf-camel-csv-test",
+        immediate = true,
+        service = CamelCsvRouteSupplier.class
+)
+public class CamelCsvRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    @Override
+    protected boolean consumerEnabled() {
+        return false;
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        CsvDataFormat csv = new CsvDataFormat();
+        csv.setDelimiter(",");
+        csv.setRecordSeparator("\n");
+        csv.setSkipHeaderRecord("false");
+        csv.setTrim("false");
+        csv.setUseMaps("false");
+        csv.setQuoteDisabled("true");
+
+        producerRoute.log("Will unmarshal: ${body}")
+                    .unmarshal(csv)
+                    .log("Unmarshal: ${body}")
+                    .toF("mock:%s", getResultMockName())
+                    .log("Will marshal: ${body}")
+                    .marshal(csv)
+                    .log("Marshal: ${body}")
+                    .toF("mock:%s", getResultMockName());
+    }
+}
\ No newline at end of file
diff --git 
a/tests/features/camel-csv/src/test/java/org/apache/karaf/camel/itest/CamelCsvITest.java
 
b/tests/features/camel-csv/src/test/java/org/apache/karaf/camel/itest/CamelCsvITest.java
new file mode 100644
index 00000000..c9681221
--- /dev/null
+++ 
b/tests/features/camel-csv/src/test/java/org/apache/karaf/camel/itest/CamelCsvITest.java
@@ -0,0 +1,71 @@
+/*
+ * 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 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;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelCsvITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    private static final String ORIGINAL_CSV_SAMPLE = """
+            Jack Dalton, 115, mad at Averell
+            Joe Dalton, 105, calming Joe
+            William Dalton, 105, keeping Joe from killing Averell
+            Averell Dalton, 80, playing with Rantanplan
+            Lucky Luke, 120, capturing the Daltons
+            """;
+
+    @Override
+    public String getBodyToSend() {
+        return ORIGINAL_CSV_SAMPLE;
+    }
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedMessageCount(2);
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testResultMock() throws Exception {
+        MockEndpoint endpoint = getMockEndpoint();
+        List<Exchange> exchanges = endpoint.getExchanges();
+        assertNotNull(exchanges);
+        assertEquals(2, exchanges.size());
+
+        List<List<String>> unmarshalResult = (List<List<String>>) 
exchanges.get(0).getIn().getBody();
+        assertNotNull(unmarshalResult);
+        assertEquals(5, unmarshalResult.size());
+        assertEquals(3, unmarshalResult.get(0).size());
+        assertEquals("Jack Dalton", unmarshalResult.get(0).get(0));
+
+        String marshalResult = exchanges.get(1).getIn().getBody(String.class);
+        assertEquals(ORIGINAL_CSV_SAMPLE, marshalResult);
+
+        assertMockEndpointsSatisfied();
+    }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index af363a3e..83a40c79 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-csv</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-->

Reply via email to