From 4126ba5a9a78c1e24da4d026b579919f2baf98bb Mon Sep 17 00:00:00 2001 From: Nicolas Filotto Date: Wed, 15 Jan 2025 17:21:00 +0100 Subject: [PATCH] Ref #571: Add an integration test for Groovy --- tests/features/camel-groovy/pom.xml | 31 +++++++++++ .../camel/test/CamelGroovyRouteSupplier.java | 55 +++++++++++++++++++ .../karaf/camel/itest/CamelGroovyITest.java | 42 ++++++++++++++ tests/features/pom.xml | 1 + 4 files changed, 129 insertions(+) create mode 100644 tests/features/camel-groovy/pom.xml create mode 100644 tests/features/camel-groovy/src/main/java/org/apache/karaf/camel/test/CamelGroovyRouteSupplier.java create mode 100644 tests/features/camel-groovy/src/test/java/org/apache/karaf/camel/itest/CamelGroovyITest.java diff --git a/tests/features/camel-groovy/pom.xml b/tests/features/camel-groovy/pom.xml new file mode 100644 index 000000000..609e31893 --- /dev/null +++ b/tests/features/camel-groovy/pom.xml @@ -0,0 +1,31 @@ + + + + 4.0.0 + + org.apache.camel.karaf + camel-karaf-features-test + 4.9.0-SNAPSHOT + + + camel-groovy-test + Apache Camel :: Karaf :: Tests :: Features :: Groovy + + \ No newline at end of file diff --git a/tests/features/camel-groovy/src/main/java/org/apache/karaf/camel/test/CamelGroovyRouteSupplier.java b/tests/features/camel-groovy/src/main/java/org/apache/karaf/camel/test/CamelGroovyRouteSupplier.java new file mode 100644 index 000000000..b2363c401 --- /dev/null +++ b/tests/features/camel-groovy/src/main/java/org/apache/karaf/camel/test/CamelGroovyRouteSupplier.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.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.apache.karaf.camel.itests.CamelRouteSupplier; +import org.osgi.service.component.annotations.Component; + +import static org.apache.camel.builder.Builder.constant; + + +@Component( + name = "karaf-camel-groovy-test", + immediate = true, + service = CamelRouteSupplier.class +) +public class CamelGroovyRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + @Override + protected boolean consumerEnabled() { + return false; + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute + .log("received message ${body}") + .setBody().groovy("groovy.lang.Tuple.tuple(body)") + .log("message modified ${body}") + .choice() + .when().groovy("body instanceof groovy.lang.Tuple && body.size() == 1") + .setBody(constant("OK")) + .otherwise() + .setBody(constant("KO")) + .end() + .log("sending message ${body}") + .toF("mock:%s", getResultMockName()); + } +} + diff --git a/tests/features/camel-groovy/src/test/java/org/apache/karaf/camel/itest/CamelGroovyITest.java b/tests/features/camel-groovy/src/test/java/org/apache/karaf/camel/itest/CamelGroovyITest.java new file mode 100644 index 000000000..904abd84b --- /dev/null +++ b/tests/features/camel-groovy/src/test/java/org/apache/karaf/camel/itest/CamelGroovyITest.java @@ -0,0 +1,42 @@ +/* + * 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 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 CamelGroovyITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest { + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedBodiesReceived("OK"); + } + + @Test + public void testResultMock() throws Exception { + assertMockEndpointsSatisfied(); + } + + @Override + public String getBodyToSend() { + return "Hello Groovy"; + } +} \ No newline at end of file diff --git a/tests/features/pom.xml b/tests/features/pom.xml index f7512069c..c4ee0b948 100644 --- a/tests/features/pom.xml +++ b/tests/features/pom.xml @@ -85,6 +85,7 @@ camel-flatpack camel-ftp camel-google-pubsub + camel-groovy camel-gson camel-hazelcast camel-http