This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 0f405a1 camel-chatscript: chores (#5461) 0f405a1 is described below commit 0f405a184589d5c6a821d3d296b990949bf7fa03 Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Fri Apr 23 15:26:34 2021 +0200 camel-chatscript: chores (#5461) * camel-test-infra-chatscript: added new test infra for chatscript * camel-chatscript: automated the previously manual IT test --- components/camel-chatscript/pom.xml | 17 ++++++ ...entManualIT.java => ChatScriptComponentIT.java} | 13 +++-- .../camel-test-infra-chatscript}/pom.xml | 51 ++++++++-------- .../src/main/resources/META-INF/MANIFEST.MF | 0 .../chatscript/common/ChatScriptProperties.java | 26 +++++++++ .../services/ChatScriptLocalContainerService.java | 67 ++++++++++++++++++++++ .../services/ChatScriptRemoteService.java | 42 ++++++++++++++ .../chatscript/services/ChatScriptService.java | 40 +++++++++++++ .../services/ChatScriptServiceFactory.java | 37 ++++++++++++ test-infra/pom.xml | 1 + 10 files changed, 263 insertions(+), 31 deletions(-) diff --git a/components/camel-chatscript/pom.xml b/components/camel-chatscript/pom.xml index 73c5821..6ef39e5 100644 --- a/components/camel-chatscript/pom.xml +++ b/components/camel-chatscript/pom.xml @@ -56,6 +56,23 @@ <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> + + <!-- test infra --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-chatscript</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/components/camel-chatscript/src/test/java/org/apache/camel/component/ChatScriptComponentManualIT.java b/components/camel-chatscript/src/test/java/org/apache/camel/component/ChatScriptComponentIT.java similarity index 88% rename from components/camel-chatscript/src/test/java/org/apache/camel/component/ChatScriptComponentManualIT.java rename to components/camel-chatscript/src/test/java/org/apache/camel/component/ChatScriptComponentIT.java index 7bc2820..c91a8ce 100644 --- a/components/camel-chatscript/src/test/java/org/apache/camel/component/ChatScriptComponentManualIT.java +++ b/components/camel-chatscript/src/test/java/org/apache/camel/component/ChatScriptComponentIT.java @@ -22,16 +22,19 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.chatscript.ChatScriptMessage; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.model.language.SimpleExpression; +import org.apache.camel.test.infra.chatscript.services.ChatScriptService; +import org.apache.camel.test.infra.chatscript.services.ChatScriptServiceFactory; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@EnabledIfSystemProperty(named = "chatscript.address", matches = ".*", - disabledReason = "The ChatScript address (host:port) was not provided") -public class ChatScriptComponentManualIT extends CamelTestSupport { - private static final Logger LOG = LoggerFactory.getLogger(ChatScriptComponentManualIT.class); +public class ChatScriptComponentIT extends CamelTestSupport { + @RegisterExtension + static ChatScriptService service = ChatScriptServiceFactory.createService(); + + private static final Logger LOG = LoggerFactory.getLogger(ChatScriptComponentIT.class); @Test public void testChatScript() throws Exception { diff --git a/components/camel-chatscript/pom.xml b/test-infra/camel-test-infra-chatscript/pom.xml similarity index 54% copy from components/camel-chatscript/pom.xml copy to test-infra/camel-test-infra-chatscript/pom.xml index 73c5821..0e3efaa 100644 --- a/components/camel-chatscript/pom.xml +++ b/test-infra/camel-test-infra-chatscript/pom.xml @@ -17,45 +17,44 @@ 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/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> +<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"> <parent> + <artifactId>camel-test-infra-parent</artifactId> <groupId>org.apache.camel</groupId> - <artifactId>components</artifactId> + <relativePath>../camel-test-infra-parent/pom.xml</relativePath> <version>3.10.0-SNAPSHOT</version> </parent> - <artifactId>camel-chatscript</artifactId> - <packaging>jar</packaging> - - <name>Camel :: ChatScript</name> - <description>Camel support for ChatScript</description> + <modelVersion>4.0.0</modelVersion> - <properties> - </properties> + <artifactId>camel-test-infra-chatscript</artifactId> + <name>Camel :: Test Infra :: ChatScript</name> <dependencies> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-support</artifactId> - </dependency> - <!-- for testing --> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test-junit5</artifactId> - <scope>test</scope> - </dependency> - <!-- logging --> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> <scope>test</scope> </dependency> + <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> </dependency> </dependencies> -</project> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + </plugin> + </plugins> + </build> + + +</project> \ No newline at end of file diff --git a/test-infra/camel-test-infra-chatscript/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-chatscript/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/common/ChatScriptProperties.java b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/common/ChatScriptProperties.java new file mode 100644 index 0000000..9ea58bc --- /dev/null +++ b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/common/ChatScriptProperties.java @@ -0,0 +1,26 @@ +/* + * 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.camel.test.infra.chatscript.common; + +public final class ChatScriptProperties { + public static final String CHATSCRIPT_ADDRESS = "chatscript.address"; + + private ChatScriptProperties() { + + } +} diff --git a/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptLocalContainerService.java b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptLocalContainerService.java new file mode 100644 index 0000000..bded97d --- /dev/null +++ b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptLocalContainerService.java @@ -0,0 +1,67 @@ +/* + * 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.camel.test.infra.chatscript.services; + +import org.apache.camel.test.infra.chatscript.common.ChatScriptProperties; +import org.apache.camel.test.infra.common.services.ContainerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; + +public class ChatScriptLocalContainerService implements ChatScriptService, ContainerService<GenericContainer> { + private static final Logger LOG = LoggerFactory.getLogger(ChatScriptLocalContainerService.class); + private static final String DEFAULT_CHATSCRIPT_CONTAINER = "claytantor/chatscript-docker:latest"; + private static final int SERVICE_PORT = 1024; + private GenericContainer container; + + public ChatScriptLocalContainerService() { + String containerName = System.getProperty("chatscript.container", DEFAULT_CHATSCRIPT_CONTAINER); + + container = new GenericContainer<>(containerName) + .withExposedPorts(SERVICE_PORT) + .withCreateContainerCmdModifier(createContainerCmd -> createContainerCmd.withTty(true)); + } + + @Override + public void registerProperties() { + System.setProperty(ChatScriptProperties.CHATSCRIPT_ADDRESS, serviceAddress()); + } + + @Override + public void initialize() { + LOG.info("Trying to start the ChatScript container"); + container.start(); + + LOG.info("ChatScript instance running at {}", serviceAddress()); + } + + @Override + public void shutdown() { + LOG.info("Stopping the ChatScript container"); + container.stop(); + } + + @Override + public GenericContainer getContainer() { + return container; + } + + @Override + public String serviceAddress() { + return container.getTestHostIpAddress() + ":" + container.getMappedPort(SERVICE_PORT); + } +} diff --git a/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptRemoteService.java b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptRemoteService.java new file mode 100644 index 0000000..2881e8d --- /dev/null +++ b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptRemoteService.java @@ -0,0 +1,42 @@ +/* + * 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.camel.test.infra.chatscript.services; + +import org.apache.camel.test.infra.chatscript.common.ChatScriptProperties; + +public class ChatScriptRemoteService implements ChatScriptService { + + @Override + public void registerProperties() { + // NO-OP + } + + @Override + public void initialize() { + registerProperties(); + } + + @Override + public void shutdown() { + // NO-OP + } + + @Override + public String serviceAddress() { + return System.getProperty(ChatScriptProperties.CHATSCRIPT_ADDRESS); + } +} diff --git a/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptService.java b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptService.java new file mode 100644 index 0000000..ede9d43 --- /dev/null +++ b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptService.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.camel.test.infra.chatscript.services; + +import org.apache.camel.test.infra.common.services.TestService; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * Test infra service for ChatScript + */ +public interface ChatScriptService extends BeforeAllCallback, AfterAllCallback, TestService { + + String serviceAddress(); + + @Override + default void beforeAll(ExtensionContext extensionContext) throws Exception { + initialize(); + } + + @Override + default void afterAll(ExtensionContext extensionContext) throws Exception { + shutdown(); + } +} diff --git a/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptServiceFactory.java b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptServiceFactory.java new file mode 100644 index 0000000..7ee6daf --- /dev/null +++ b/test-infra/camel-test-infra-chatscript/src/test/java/org/apache/camel/test/infra/chatscript/services/ChatScriptServiceFactory.java @@ -0,0 +1,37 @@ +/* + * 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.camel.test.infra.chatscript.services; + +import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder; + +public final class ChatScriptServiceFactory { + + private ChatScriptServiceFactory() { + + } + + public static SimpleTestServiceBuilder<ChatScriptService> builder() { + return new SimpleTestServiceBuilder<>("chatscript"); + } + + public static ChatScriptService createService() { + return builder() + .addLocalMapping(ChatScriptLocalContainerService::new) + .addRemoteMapping(ChatScriptRemoteService::new) + .build(); + } +} diff --git a/test-infra/pom.xml b/test-infra/pom.xml index b5085ef..9d433d1 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -71,6 +71,7 @@ <module>camel-test-infra-fhir</module> <module>camel-test-infra-mosquitto</module> <module>camel-test-infra-activemq</module> + <module>camel-test-infra-chatscript</module> </modules> <build>