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 8a760e43 Ref #475: Add camel-chatscript integration test (#476)
8a760e43 is described below

commit 8a760e4354de11e9cc36f376c2b93c79b7dd8173
Author: François de Parscau <[email protected]>
AuthorDate: Wed Jul 31 16:54:33 2024 +0200

    Ref #475: Add camel-chatscript integration test (#476)
---
 tests/features/camel-chatscript/pom.xml            | 45 +++++++++++++
 .../camel/test/CamelChatscriptRouteSupplier.java   | 57 +++++++++++++++++
 .../karaf/camel/itest/CamelChatscriptITest.java    | 73 ++++++++++++++++++++++
 tests/features/pom.xml                             |  1 +
 4 files changed, 176 insertions(+)

diff --git a/tests/features/camel-chatscript/pom.xml 
b/tests/features/camel-chatscript/pom.xml
new file mode 100644
index 00000000..74197219
--- /dev/null
+++ b/tests/features/camel-chatscript/pom.xml
@@ -0,0 +1,45 @@
+<?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-chatscript-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: ChatScript</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <version>${testcontainers-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-chatscript</artifactId>
+            <version>${camel-version}</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-chatscript/src/main/java/org/apache/karaf/camel/test/CamelChatscriptRouteSupplier.java
 
b/tests/features/camel-chatscript/src/main/java/org/apache/karaf/camel/test/CamelChatscriptRouteSupplier.java
new file mode 100644
index 00000000..dd339618
--- /dev/null
+++ 
b/tests/features/camel-chatscript/src/main/java/org/apache/karaf/camel/test/CamelChatscriptRouteSupplier.java
@@ -0,0 +1,57 @@
+/*
+ * 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.component.chatscript.ChatScriptMessage;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.language.SimpleExpression;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@Component(
+        name = "karaf-camel-chatscript-test",
+        immediate = true,
+        service = CamelChatscriptRouteSupplier.class
+)
+public class CamelChatscriptRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    @Override
+    public boolean consumerEnabled() {
+        return false;
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        String g = "CS" + Math.random();
+        ChatScriptMessage rqMsg = new ChatScriptMessage(g, "", "Hello");
+        String rq = "";
+        try {
+            rq = new ObjectMapper().writeValueAsString(rqMsg);
+        }  catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
+        configureConsumer(
+                producerRoute.setBody(new SimpleExpression(rq))
+                .toF("chatscript://localhost:%s/Harry?resetChat=true", 
System.getProperty("chatscript.port"))
+                .log("received ${body}"));
+    }
+
+}
+
diff --git 
a/tests/features/camel-chatscript/src/test/java/org/apache/karaf/camel/itest/CamelChatscriptITest.java
 
b/tests/features/camel-chatscript/src/test/java/org/apache/karaf/camel/itest/CamelChatscriptITest.java
new file mode 100644
index 00000000..2d063854
--- /dev/null
+++ 
b/tests/features/camel-chatscript/src/test/java/org/apache/karaf/camel/itest/CamelChatscriptITest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import java.util.function.Consumer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.chatscript.ChatScriptMessage;
+import org.apache.camel.component.mock.MockEndpoint;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+import org.apache.karaf.camel.itests.GenericContainerResource;
+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;
+import org.testcontainers.containers.GenericContainer;
+
+@CamelKarafTestHint(externalResourceProvider = 
CamelChatscriptITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelChatscriptITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedMessageCount(1);
+    }
+
+    @Test
+    public void testResultMock() throws Exception {
+        assertMockEndpointsSatisfied();
+        MockEndpoint endpoint = getMockEndpoint();
+        List<Exchange> exchanges = endpoint.getExchanges();
+        assertNotNull(exchanges);
+        assertEquals(1, exchanges.size());
+        Exchange ex = exchanges.get(0);
+
+        ChatScriptMessage event = ex.getIn().getBody(ChatScriptMessage.class);
+        assertFalse(event.getReply().isEmpty());
+    }
+
+    public static final class ExternalResourceProviders {
+
+        private static final int PORT_DEFAULT = 1024;
+
+        public static GenericContainerResource createArangoContainer() {
+            final GenericContainer<?> chatscriptContainer =
+                    new 
GenericContainer<>("claytantor/chatscript-docker:latest")
+                            .withExposedPorts(PORT_DEFAULT);
+
+            return new GenericContainerResource(chatscriptContainer, 
(Consumer<GenericContainerResource>) resource -> {
+                resource.setProperty("chatscript.port", 
Integer.toString(chatscriptContainer.getMappedPort(PORT_DEFAULT)));
+            });
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index f2dae2df..41c1eba7 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -57,6 +57,7 @@
         <module>camel-bindy</module>
         <module>camel-caffeine</module>
         <module>camel-cbor</module>
+        <module>camel-chatscript</module>
         <module>camel-coap</module>
         <module>camel-cometd</module>
         <module>camel-consul</module>

Reply via email to