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 1c380ffd Ref #406: Add camel-as2 integration test and fix feature 
(#407)
1c380ffd is described below

commit 1c380ffd65aa5b4232eeae84d5b3ce4f109cde4d
Author: François de Parscau <116000379+f2p...@users.noreply.github.com>
AuthorDate: Mon Jul 8 14:06:45 2024 +0200

    Ref #406: Add camel-as2 integration test and fix feature (#407)
---
 features/src/main/feature/camel-features.xml       |   1 +
 tests/features/camel-as2/pom.xml                   |  46 ++++++++
 .../karaf/camel/test/CamelAs2RouteSupplier.java    | 126 +++++++++++++++++++++
 .../apache/karaf/camel/itest/CamelAs2ITest.java    |  48 ++++++++
 tests/features/pom.xml                             |   1 +
 5 files changed, 222 insertions(+)

diff --git a/features/src/main/feature/camel-features.xml 
b/features/src/main/feature/camel-features.xml
index 3ad1f8c1..f42e432c 100644
--- a/features/src/main/feature/camel-features.xml
+++ b/features/src/main/feature/camel-features.xml
@@ -343,6 +343,7 @@
         <feature version='${camel-osgi-version-range}'>camel-core</feature>
         <feature version="[5,6)">http-client</feature>
         <feature version="[${bouncycastle-version},2)">bouncycastle</feature>
+        <bundle 
dependency='true'>wrap:mvn:org.apache.httpcomponents.core5/httpcore5-h2/${httpclient-version}</bundle>
         <!-- Wrap protocol used to export a private package that is used by 
camel-as2  -->
         <bundle 
dependency='true'>wrap:mvn:org.bouncycastle/bcutil-jdk18on/${bouncycastle-version}$overwrite=merge&amp;Export-Package=org.bouncycastle.*;version=${bouncycastle-version}</bundle>
         <bundle 
dependency='true'>mvn:org.apache.velocity/velocity-engine-core/${velocity-version}</bundle>
diff --git a/tests/features/camel-as2/pom.xml b/tests/features/camel-as2/pom.xml
new file mode 100644
index 00000000..c4a1e49a
--- /dev/null
+++ b/tests/features/camel-as2/pom.xml
@@ -0,0 +1,46 @@
+<?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.6.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-as2-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: AS2</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-as2-api</artifactId>
+            <version>${camel-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-as2</artifactId>
+            <version>${camel-version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-as2/src/main/java/org/apache/karaf/camel/test/CamelAs2RouteSupplier.java
 
b/tests/features/camel-as2/src/main/java/org/apache/karaf/camel/test/CamelAs2RouteSupplier.java
new file mode 100644
index 00000000..8e862cf5
--- /dev/null
+++ 
b/tests/features/camel-as2/src/main/java/org/apache/karaf/camel/test/CamelAs2RouteSupplier.java
@@ -0,0 +1,126 @@
+/*
+ * 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 static org.apache.camel.builder.Builder.constant;
+
+import java.nio.charset.StandardCharsets;
+import java.util.function.Function;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.as2.AS2Component;
+import org.apache.camel.component.as2.AS2Configuration;
+import org.apache.camel.component.as2.api.AS2MediaType;
+import org.apache.camel.component.as2.api.AS2MessageStructure;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.hc.core5.http.ContentType;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+
+@Component(
+        name = "karaf-camel-as2-test",
+        immediate = true,
+        service = CamelRouteSupplier.class
+)
+public class CamelAs2RouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    private static final String REQUEST_URI = "/";
+    private static final String SUBJECT = "Test Case";
+    private static final String AS2_NAME = "878051556";
+    private static final String FROM = "m...@example.org";
+
+    private static final String EDI_MESSAGE = 
"UNB+UNOA:1+005435656:1+006415160:1+060515:1434+00000000000778'\n"
+            + "UNH+00000000000117+INVOIC:D:97B:UN'\n"
+            + "BGM+380+342459+9'\n"
+            + "DTM+3:20060515:102'\n"
+            + "RFF+ON:521052'\n"
+            + "NAD+BY+792820524::16++CUMMINS MID-RANGE ENGINE PLANT'\n"
+            + "NAD+SE+005435656::16++GENERAL WIDGET COMPANY'\n"
+            + "CUX+1:USD'\n"
+            + "LIN+1++157870:IN'\n"
+            + "IMD+F++:::WIDGET'\n"
+            + "QTY+47:1020:EA'\n"
+            + "ALI+US'\n"
+            + "MOA+203:1202.58'\n"
+            + "PRI+INV:1.179'\n"
+            + "LIN+2++157871:IN'\n"
+            + "IMD+F++:::DIFFERENT WIDGET'\n"
+            + "QTY+47:20:EA'\n"
+            + "ALI+JP'\n"
+            + "MOA+203:410'\n"
+            + "PRI+INV:20.5'\n"
+            + "UNS+S'\n"
+            + "MOA+39:2137.58'\n"
+            + "ALC+C+ABG'\n"
+            + "MOA+8:525'\n"
+            + "UNT+23+00000000000117'\n"
+            + "UNZ+1+00000000000778'\n";
+    private static final String EDI_MESSAGE_CONTENT_TRANSFER_ENCODING = "7bit";
+
+    @Override
+    public void configure(CamelContext context) {
+        final int port = Integer.parseInt(System.getProperty("as2.port"));
+        final AS2Configuration configuration = new AS2Configuration();
+        configuration.setTargetHostname("localhost");
+        configuration.setTargetPortNumber(port);
+        configuration.setServerFqdn("example.com");
+        configuration.setServerPortNumber(port);
+
+        final AS2Component component = new AS2Component(context);
+        component.setConfiguration(configuration);
+        context.addComponent("as2", component);
+    }
+
+
+    @Override
+    protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+        return builder ->
+                builder.from("as2://server/listen?requestUriPattern=/")
+                        .log("received message ${body}")
+                        .setBody(constant("OK"));
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        producerRoute.setHeader("CamelAS2.requestUri", constant(REQUEST_URI))
+                .setHeader("CamelAS2.subject", constant(SUBJECT))
+                .setHeader("CamelAS2.from", constant(FROM))
+                .setHeader("CamelAS2.as2From", constant(AS2_NAME))
+                .setHeader("CamelAS2.as2To", constant(AS2_NAME))
+                .setHeader("CamelAS2.as2MessageStructure", 
constant(AS2MessageStructure.PLAIN))
+                .setHeader("CamelAS2.ediMessageContentType",
+                        
constant(ContentType.create(AS2MediaType.APPLICATION_EDIFACT, 
StandardCharsets.US_ASCII.name())))
+                .setHeader("CamelAS2.ediMessageTransferEncoding", 
constant(EDI_MESSAGE_CONTENT_TRANSFER_ENCODING))
+                .setHeader("CamelAS2.dispositionNotificationTo", 
constant(FROM))
+                .setHeader("CamelAS2.attachedFileName", constant(""))
+                .setBody(constant(EDI_MESSAGE))
+                .to("as2:client/send?inBody=ediMessage")
+                .log("message sent successfully");
+    }
+
+    @Override
+    public void createRoutes(RouteBuilder builder) {
+        //creating producer before consumer as in the parent class causes an 
http connection exception
+        //so invert the order for this specific supplier
+        configureConsumer(consumerRoute().apply(builder));
+        configureProducer(builder,
+                builder.fromF("direct:%s", 
getTestComponentName()).routeId("producer-%s".formatted(getTestComponentName())));
+    }
+}
+
diff --git 
a/tests/features/camel-as2/src/test/java/org/apache/karaf/camel/itest/CamelAs2ITest.java
 
b/tests/features/camel-as2/src/test/java/org/apache/karaf/camel/itest/CamelAs2ITest.java
new file mode 100644
index 00000000..2c845613
--- /dev/null
+++ 
b/tests/features/camel-as2/src/test/java/org/apache/karaf/camel/itest/CamelAs2ITest.java
@@ -0,0 +1,48 @@
+/*
+ * 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 java.util.List;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.AvailablePortProvider;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+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;
+
+@CamelKarafTestHint(externalResourceProvider = 
CamelAs2ITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelAs2ITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedBodiesReceived("OK");
+    }
+
+    @Test
+    public void testResultMock() throws Exception {
+        assertMockEndpointsSatisfied();
+    }
+
+    public static final class ExternalResourceProviders {
+        public static AvailablePortProvider createAvailablePortProvider() {
+            return new AvailablePortProvider(List.of("as2.port"));
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 6090f1f5..e3e7f7c8 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -40,6 +40,7 @@
         <module>camel-activemq</module>
         <module>camel-amqp</module>
         <module>camel-arangodb</module>
+        <module>camel-as2</module>
         <module>camel-asn1</module>
         <module>camel-aws2-iam</module>
         <module>camel-aws2-s3</module>

Reply via email to