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 54782f32 Ref #436: Add camel-flatpack integration test (#437) 54782f32 is described below commit 54782f32d92b4001ea34f6c93aca05d1e9d365f7 Author: François de Parscau <116000379+f2p...@users.noreply.github.com> AuthorDate: Wed Jul 17 15:28:52 2024 +0200 Ref #436: Add camel-flatpack integration test (#437) --- tests/features/camel-flatpack/pom.xml | 32 ++++++++++ .../camel/test/CamelFlatpackRouteSupplier.java | 46 ++++++++++++++ .../karaf/camel/itest/CamelFlatpackITest.java | 70 ++++++++++++++++++++++ .../test/resources/INVENTORY-Delimited.pzmap.xml | 27 +++++++++ tests/features/pom.xml | 1 + 5 files changed, 176 insertions(+) diff --git a/tests/features/camel-flatpack/pom.xml b/tests/features/camel-flatpack/pom.xml new file mode 100644 index 00000000..15cf698c --- /dev/null +++ b/tests/features/camel-flatpack/pom.xml @@ -0,0 +1,32 @@ +<?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-flatpack-test</artifactId> + <name>Apache Camel :: Karaf :: Tests :: Features :: Flatpack</name> +</project> \ No newline at end of file diff --git a/tests/features/camel-flatpack/src/main/java/org/apache/karaf/camel/test/CamelFlatpackRouteSupplier.java b/tests/features/camel-flatpack/src/main/java/org/apache/karaf/camel/test/CamelFlatpackRouteSupplier.java new file mode 100644 index 00000000..0174a9a6 --- /dev/null +++ b/tests/features/camel-flatpack/src/main/java/org/apache/karaf/camel/test/CamelFlatpackRouteSupplier.java @@ -0,0 +1,46 @@ +/* + * 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.osgi.service.component.annotations.Component; + +@Component( + name = "karaf-camel-flatpack-test", + immediate = true, + service = CamelFlatpackRouteSupplier.class +) +public class CamelFlatpackRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + @Override + protected Function<RouteBuilder, RouteDefinition> consumerRoute() { + return builder -> + builder.fromF("flatpack:delim:file:%s/test-classes/INVENTORY-Delimited.pzmap.xml", + System.getProperty("project.target")) + .log("received message ${body}"); + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute.toF("flatpack:delim:file:%s/test-classes/INVENTORY-Delimited.pzmap.xml", + System.getProperty("project.target")); + } +} + diff --git a/tests/features/camel-flatpack/src/test/java/org/apache/karaf/camel/itest/CamelFlatpackITest.java b/tests/features/camel-flatpack/src/test/java/org/apache/karaf/camel/itest/CamelFlatpackITest.java new file mode 100644 index 00000000..b6b7fd6e --- /dev/null +++ b/tests/features/camel-flatpack/src/test/java/org/apache/karaf/camel/itest/CamelFlatpackITest.java @@ -0,0 +1,70 @@ +/* + * 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 java.util.Map; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +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 CamelFlatpackITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest { + + private static final String TO_PARSE = """ + "ITEM_DESC","IN_STOCK","PRICE","LAST_RECV_DT" + "SOME VALVE","2","5.00","20050101" + "AN ENGINE","100","1000.00","20040601" + "A BELT","45",".50","20030101" + "A BOLT","1000","2.75","20050101" + """; + + private static final String[] EXPECTED_ITEM_DESCRIPTIONS = { "SOME VALVE", "AN ENGINE", "A BELT", "A BOLT" }; + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedMessageCount(4); + List<Exchange> list = mock.getReceivedExchanges(); + int counter = 0; + for (Exchange exchange : list) { + Message in = exchange.getIn(); + Map<?, ?> body = in.getBody(Map.class); + assertNotNull(body); + assertEquals(EXPECTED_ITEM_DESCRIPTIONS[counter], "ITEM_DESC", body.get("ITEM_DESC")); + counter++; + } + } + + @Test + public void testResultMock() throws Exception { + assertMockEndpointsSatisfied(); + } + + @Override + public String getBodyToSend() { + return TO_PARSE; + } + +} \ No newline at end of file diff --git a/tests/features/camel-flatpack/src/test/resources/INVENTORY-Delimited.pzmap.xml b/tests/features/camel-flatpack/src/test/resources/INVENTORY-Delimited.pzmap.xml new file mode 100644 index 00000000..1ae4fc0c --- /dev/null +++ b/tests/features/camel-flatpack/src/test/resources/INVENTORY-Delimited.pzmap.xml @@ -0,0 +1,27 @@ +<?xml version='1.0'?> +<!-- + + 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. + +--> +<!DOCTYPE PZMAP SYSTEM + "flatpack.dtd" > +<PZMAP> + <COLUMN name="ITEM_DESC" /> + <COLUMN name="IN_STOCK" /> + <COLUMN name="PRICE" /> + <COLUMN name="LAST_RECV_DT" /> +</PZMAP> diff --git a/tests/features/pom.xml b/tests/features/pom.xml index bd246aa1..3dacc348 100644 --- a/tests/features/pom.xml +++ b/tests/features/pom.xml @@ -64,6 +64,7 @@ <module>camel-ehcache</module> <module>camel-elasticsearch</module> <module>camel-fastjson</module> + <module>camel-flatpack</module> <module>camel-ftp</module> <module>camel-google-pubsub</module> <module>camel-gson</module>