You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/09/14 08:22:04 UTC

[camel] branch main updated (0dc54b78abb -> ec41afbadad)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 0dc54b78abb Attachment Handling: Allow the Mail Consumer to handle attachments with duplicate or missing filenames (#8322)
     new 74790dcd786 CAMEL-18456: improved support for Handler collections in camel-test-infra-jetty
     new ec41afbadad CAMEL-18456: converted camel-platform-http tests to camel-test-infra-jetty

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 components/camel-platform-http/pom.xml             | 15 +++-----
 .../component/platform/http/JettyServerTest.java   | 26 ++++++++-----
 .../infra/jetty/services/JettyConfiguration.java   | 15 ++++++--
 .../jetty/services/JettyConfigurationBuilder.java  | 36 +++++++++++++++++-
 .../infra/jetty/services/JettyEmbeddedService.java | 43 ++++++++++++++--------
 5 files changed, 97 insertions(+), 38 deletions(-)


[camel] 01/02: CAMEL-18456: improved support for Handler collections in camel-test-infra-jetty

Posted by or...@apache.org.
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

commit 74790dcd7867cae9c7359246cc6600c9af66a8e4
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Sep 13 15:43:39 2022 +0200

    CAMEL-18456: improved support for Handler collections in camel-test-infra-jetty
---
 .../infra/jetty/services/JettyConfiguration.java   | 15 ++++++--
 .../jetty/services/JettyConfigurationBuilder.java  | 36 +++++++++++++++++-
 .../infra/jetty/services/JettyEmbeddedService.java | 43 ++++++++++++++--------
 3 files changed, 74 insertions(+), 20 deletions(-)

diff --git a/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfiguration.java b/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfiguration.java
index 16fb864ec4b..5f2af982268 100644
--- a/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfiguration.java
+++ b/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfiguration.java
@@ -289,11 +289,20 @@ public class JettyConfiguration {
         }
     }
 
-    public static class HandlerCollectionConfiguration {
+    public static class HandlerCollectionConfiguration extends AbstractContextHandlerConfiguration<HandlerCollection> {
         private final HandlerCollection handlers = new HandlerCollection();
 
-        public void setHandlers(Handler[] handlers) {
-            this.handlers.setHandlers(handlers);
+        public HandlerCollectionConfiguration(String contextPath) {
+            super(contextPath);
+        }
+
+        public void addHandlers(Handler handler) {
+            handlers.addHandler(handler);
+        }
+
+        @Override
+        HandlerCollection resolve() {
+            return handlers;
         }
     }
 
diff --git a/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfigurationBuilder.java b/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfigurationBuilder.java
index ee47da7cae4..b69576015ab 100644
--- a/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfigurationBuilder.java
+++ b/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyConfigurationBuilder.java
@@ -26,6 +26,7 @@ import org.apache.camel.util.KeyValueHolder;
 import org.eclipse.jetty.server.Handler;
 import org.eclipse.jetty.server.handler.ContextHandler;
 import org.eclipse.jetty.server.handler.ErrorHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 
 /**
@@ -151,8 +152,37 @@ public final class JettyConfigurationBuilder {
         }
     }
 
-    public static class HandlerContextConfigurationBuilder {
+    public static class HandlerContextConfigurationBuilder implements ConfigurationBuilderDelegate {
+        private final JettyConfiguration jettyConfiguration;
+        private final JettyConfigurationBuilder jettyConfigurationBuilder;
+        private final JettyConfiguration.HandlerCollectionConfiguration handlerCollectionConfiguration;
+
+        public HandlerContextConfigurationBuilder(JettyConfigurationBuilder jettyConfigurationBuilder,
+                                                  JettyConfiguration jettyConfiguration) {
+            this.jettyConfiguration = jettyConfiguration;
+            this.jettyConfigurationBuilder = jettyConfigurationBuilder;
+
+            handlerCollectionConfiguration
+                    = new JettyConfiguration.HandlerCollectionConfiguration(jettyConfiguration.getContextPath());
+        }
+
+        public HandlerContextConfigurationBuilder addHandlers(Handler handler) {
+            handlerCollectionConfiguration.addHandlers(handler);
+
+            return this;
+        }
+
+        public HandlerContextConfigurationBuilder withCustomizer(Consumer<HandlerCollection> contextHandlerCustomizer) {
+            handlerCollectionConfiguration.customize(contextHandlerCustomizer);
+            return this;
+        }
 
+        @Override
+        public JettyConfigurationBuilder build() {
+            jettyConfiguration.setContextHandlerConfiguration(handlerCollectionConfiguration);
+
+            return jettyConfigurationBuilder;
+        }
     }
 
     private JettyConfiguration jettyConfiguration = new JettyConfiguration();
@@ -188,6 +218,10 @@ public final class JettyConfigurationBuilder {
         return new ContextHandlerConfigurationBuilder(this, jettyConfiguration);
     }
 
+    public HandlerContextConfigurationBuilder withHandlerCollectionConfiguration() {
+        return new HandlerContextConfigurationBuilder(this, jettyConfiguration);
+    }
+
     public JettyConfigurationBuilder withContextPath(String contextPath) {
         jettyConfiguration.setContextPath(contextPath);
 
diff --git a/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyEmbeddedService.java b/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyEmbeddedService.java
index db2eb902dd7..bffe10568bd 100644
--- a/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyEmbeddedService.java
+++ b/test-infra/camel-test-infra-jetty/src/test/java/org/apache/camel/test/infra/jetty/services/JettyEmbeddedService.java
@@ -70,8 +70,7 @@ public class JettyEmbeddedService implements JettyService, BeforeEachCallback, A
         System.setProperty(JettyProperties.JETTY_ADDRESS, "localhost:" + getPort());
     }
 
-    @Override
-    public void initialize() {
+    private void doInitialize() {
         try {
             server = new Server(jettyConfiguration.getPort());
 
@@ -90,36 +89,48 @@ public class JettyEmbeddedService implements JettyService, BeforeEachCallback, A
         }
     }
 
+    @Override
+    public void initialize() {
+        if (server == null || server.isStopped()) {
+            doInitialize();
+        }
+    }
+
     @Override
     public void shutdown() {
-        if (server == null) {
-            return;
+        if (server != null && server.isStarted()) {
+            doShutdown();
         }
+    }
 
+    private synchronized void doShutdown() {
         try {
-            server.stop();
-
-            Awaitility.await().atMost(10, TimeUnit.SECONDS).until(server::isStopped);
+            stop();
         } catch (Exception e) {
             throw new RuntimeException(e);
         } finally {
-            server.destroy();
+            if (server.isStopped()) {
+                server.destroy();
+            }
+
             server = null;
         }
     }
 
+    public void stop() throws Exception {
+        server.stop();
+
+        Awaitility.await().atMost(10, TimeUnit.SECONDS).until(server::isStopped);
+    }
+
     @Override
-    public void afterEach(ExtensionContext extensionContext) throws Exception {
-        if (server != null && server.isStarted()) {
-            shutdown();
-        }
+    public void afterEach(ExtensionContext extensionContext) {
+        shutdown();
     }
 
     @Override
-    public void beforeEach(ExtensionContext extensionContext) throws Exception {
-        if (server == null || server.isStopped()) {
-            initialize();
-        }
+    public void beforeEach(ExtensionContext extensionContext) {
+        initialize();
     }
 
     @Override


[camel] 02/02: CAMEL-18456: converted camel-platform-http tests to camel-test-infra-jetty

Posted by or...@apache.org.
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

commit ec41afbadaddd36df2bbf5f3e4e600105ded2366
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Sep 13 15:44:10 2022 +0200

    CAMEL-18456: converted camel-platform-http tests to camel-test-infra-jetty
---
 components/camel-platform-http/pom.xml             | 15 +++++--------
 .../component/platform/http/JettyServerTest.java   | 26 ++++++++++++++--------
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/components/camel-platform-http/pom.xml b/components/camel-platform-http/pom.xml
index 00e604be7df..908511348ac 100644
--- a/components/camel-platform-http/pom.xml
+++ b/components/camel-platform-http/pom.xml
@@ -42,18 +42,15 @@
             <artifactId>camel-console</artifactId>
         </dependency>
 
+        <!-- test infra -->
         <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-server</artifactId>
-            <version>${jetty9-version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.eclipse.jetty.orbit</groupId>
-                    <artifactId>javax.servlet</artifactId>
-                </exclusion>
-            </exclusions>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-jetty</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>io.rest-assured</groupId>
             <artifactId>rest-assured</artifactId>
diff --git a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyServerTest.java b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyServerTest.java
index 7af9f15a84b..3583fdacd21 100644
--- a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyServerTest.java
+++ b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyServerTest.java
@@ -16,30 +16,38 @@
  */
 package org.apache.camel.component.platform.http;
 
-import org.eclipse.jetty.server.Server;
+import org.apache.camel.test.infra.jetty.services.JettyConfiguration;
+import org.apache.camel.test.infra.jetty.services.JettyConfigurationBuilder;
+import org.apache.camel.test.infra.jetty.services.JettyEmbeddedService;
 import org.eclipse.jetty.server.handler.ContextHandler;
 import org.eclipse.jetty.server.handler.HandlerCollection;
 
 public class JettyServerTest {
     public static final String JETTY_SERVER_NAME = "JettyServerTest";
 
-    private Server server;
-    private int port;
-    private HandlerCollection contextHandlerCollection;
+    private final int port;
+    private final HandlerCollection contextHandlerCollection;
+    private final JettyEmbeddedService service;
 
     public JettyServerTest(int port) {
-        this.server = new Server(port);
+        contextHandlerCollection = new HandlerCollection(true);
+
+        final JettyConfiguration configuration = JettyConfigurationBuilder.bareTemplate()
+                .withPort(port)
+                .withHandlerCollectionConfiguration().addHandlers(contextHandlerCollection).build().build();
+        this.service = new JettyEmbeddedService(configuration);
+
         this.port = port;
-        this.contextHandlerCollection = new HandlerCollection(true);
-        this.server.setHandler(contextHandlerCollection);
+
     }
 
     public void start() throws Exception {
-        server.start();
+        service.initialize();
+
     }
 
     public void stop() throws Exception {
-        server.stop();
+        service.stop();
     }
 
     public void addHandler(ContextHandler contextHandler) throws Exception {