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 31f15eb79de3e335f1ff4bb280b3081b3d47e662
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Fri Sep 9 15:17:46 2022 +0200

    CAMEL-18456: converted camel-atom to camel-test-infra-jetty
---
 components/camel-atom/pom.xml                      |  18 ++-
 .../AtomEntryPollingConsumerWithBasicAuthTest.java |  31 ++---
 .../atom/AtomPollingConsumerWithBasicAuthTest.java |  32 ++---
 .../camel/component/atom/JettyTestServer.java      | 135 ---------------------
 .../apache/camel/component/atom/MyHttpServlet.java |  39 ++++++
 5 files changed, 85 insertions(+), 170 deletions(-)

diff --git a/components/camel-atom/pom.xml b/components/camel-atom/pom.xml
index 66ee57b15c3..749bdcc241a 100644
--- a/components/camel-atom/pom.xml
+++ b/components/camel-atom/pom.xml
@@ -185,18 +185,24 @@
             <artifactId>commons-io</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <!-- test infra -->
         <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-servlet</artifactId>
-            <version>${jetty-version}</version>
+            <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.eclipse.jetty</groupId>
-            <artifactId>jetty-security</artifactId>
-            <version>${jetty-version}</version>
+            <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>org.awaitility</groupId>
             <artifactId>awaitility</artifactId>
diff --git 
a/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerWithBasicAuthTest.java
 
b/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerWithBasicAuthTest.java
index a9f2778ae67..97d017eac7a 100644
--- 
a/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerWithBasicAuthTest.java
+++ 
b/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerWithBasicAuthTest.java
@@ -17,37 +17,40 @@
 package org.apache.camel.component.atom;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.apache.camel.test.AvailablePortFinder;
+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.junit.jupiter.api.condition.DisabledOnOs;
 import org.junit.jupiter.api.condition.OS;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 @DisabledOnOs(OS.AIX)
 public class AtomEntryPollingConsumerWithBasicAuthTest extends 
AtomEntryPollingConsumerTest {
+    private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+    @RegisterExtension
+    public JettyEmbeddedService service = new JettyEmbeddedService(
+            JettyConfigurationBuilder.bareTemplate()
+                    .withPort(PORT)
+                    .addBasicUser("camel", "camelPass", "Private!")
+                    .addServletConfiguration(new 
JettyConfiguration.ServletConfiguration<>(
+                            new MyHttpServlet(), 
JettyConfiguration.ServletConfiguration.ROOT_PATH_SPEC))
+                    .build());
 
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             @Override
             public void configure() {
-                from("atom:http://localhost:"; + 
JettyTestServer.getInstance().port
+                from("atom:http://localhost:"; + PORT
                      + 
"/?splitEntries=true&delay=500&username=camel&password=camelPass")
                              .to("mock:result1");
 
-                from("atom:http://localhost:"; + 
JettyTestServer.getInstance().port
+                from("atom:http://localhost:"; + PORT
                      + 
"/?splitEntries=true&filter=false&delay=500&username=camel&password=camelPass")
                              .to("mock:result2");
             }
         };
     }
-
-    @BeforeAll
-    static void startServer() {
-        JettyTestServer.getInstance().startServer();
-    }
-
-    @AfterAll
-    static void stopServer() {
-        JettyTestServer.getInstance().stopServer();
-    }
 }
diff --git 
a/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerWithBasicAuthTest.java
 
b/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerWithBasicAuthTest.java
index e2b0716f244..ab1e254073c 100644
--- 
a/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerWithBasicAuthTest.java
+++ 
b/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerWithBasicAuthTest.java
@@ -17,39 +17,41 @@
 package org.apache.camel.component.atom;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.apache.camel.test.AvailablePortFinder;
+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.junit.jupiter.api.condition.DisabledOnOs;
 import org.junit.jupiter.api.condition.OS;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 @DisabledOnOs(OS.AIX)
 public class AtomPollingConsumerWithBasicAuthTest extends 
AtomPollingConsumerTest {
+    private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+    @RegisterExtension
+    public JettyEmbeddedService service = new JettyEmbeddedService(
+            JettyConfigurationBuilder.bareTemplate()
+                    .withPort(PORT)
+                    .addBasicUser("camel", "camelPass", "Private!")
+                    .addServletConfiguration(new 
JettyConfiguration.ServletConfiguration<>(
+                            new MyHttpServlet(), 
JettyConfiguration.ServletConfiguration.ROOT_PATH_SPEC))
+                    .build());
 
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             @Override
             public void configure() {
-                from("atom:http://localhost:"; + 
JettyTestServer.getInstance().port
+                from("atom:http://localhost:"; + PORT
                      + 
"/?splitEntries=false&username=camel&password=camelPass")
                              .to("mock:result");
 
                 // this is a bit weird syntax that normally is not used using 
the feedUri parameter
-                from("atom:?feedUri=http://localhost:"; + 
JettyTestServer.getInstance().port
+                from("atom:?feedUri=http://localhost:"; + PORT
                      + 
"/&splitEntries=false&username=camel&password=camelPass")
                              .to("mock:result2");
             }
         };
     }
-
-    @BeforeAll
-    static void startServer() {
-        JettyTestServer.getInstance().startServer();
-    }
-
-    @AfterAll
-    static void stopServer() {
-        JettyTestServer.getInstance().stopServer();
-    }
-
 }
diff --git 
a/components/camel-atom/src/test/java/org/apache/camel/component/atom/JettyTestServer.java
 
b/components/camel-atom/src/test/java/org/apache/camel/component/atom/JettyTestServer.java
deleted file mode 100644
index afa4ff08d9b..00000000000
--- 
a/components/camel-atom/src/test/java/org/apache/camel/component/atom/JettyTestServer.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.component.atom;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.commons.io.FileUtils;
-import org.eclipse.jetty.security.ConstraintMapping;
-import org.eclipse.jetty.security.ConstraintSecurityHandler;
-import org.eclipse.jetty.security.HashLoginService;
-import org.eclipse.jetty.security.SecurityHandler;
-import org.eclipse.jetty.security.UserStore;
-import org.eclipse.jetty.security.authentication.BasicAuthenticator;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.util.security.Constraint;
-import org.eclipse.jetty.util.security.Credential;
-import org.junit.jupiter.api.condition.DisabledOnOs;
-import org.junit.jupiter.api.condition.OS;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.jupiter.api.Assertions.fail;
-
-@DisabledOnOs(OS.AIX)
-public final class JettyTestServer {
-
-    private static final Logger LOG = 
LoggerFactory.getLogger(JettyTestServer.class);
-    private static final int PORT = AvailablePortFinder.getNextAvailable();
-    private static JettyTestServer instance;
-
-    public int port;
-    private Server server;
-
-    private JettyTestServer() {
-    }
-
-    public void startServer() {
-        server = new Server(PORT);
-        port = PORT;
-
-        ServletContextHandler servletContext = new 
ServletContextHandler(ServletContextHandler.SESSIONS);
-        servletContext.setSecurityHandler(basicAuth("camel", "camelPass", 
"Private!"));
-        servletContext.setContextPath("/");
-        server.setHandler(servletContext);
-        servletContext.addServlet(new ServletHolder(new MyHttpServlet()), 
"/*");
-        try {
-            server.start();
-        } catch (Exception ex) {
-            LOG.error("Could not start Server!", ex);
-            fail(ex.getLocalizedMessage());
-        }
-    }
-
-    public void stopServer() {
-        if (server != null) {
-            try {
-                server.stop();
-            } catch (Exception ex) {
-                LOG.warn("Server doesn't stop normal...", ex);
-            } finally {
-                server = null;
-                port = 0;
-            }
-        }
-    }
-
-    private SecurityHandler basicAuth(String username, String password, String 
realm) {
-
-        HashLoginService l = new HashLoginService();
-        UserStore us = new UserStore();
-        us.addUser(username, Credential.getCredential(password), new String[] 
{ "user" });
-        l.setUserStore(us);
-        l.setName(realm);
-
-        Constraint constraint = new Constraint();
-        constraint.setName(Constraint.__BASIC_AUTH);
-        constraint.setRoles(new String[] { "user" });
-        constraint.setAuthenticate(true);
-
-        ConstraintMapping cm = new ConstraintMapping();
-        cm.setConstraint(constraint);
-        cm.setPathSpec("/*");
-
-        ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
-        csh.setAuthenticator(new BasicAuthenticator());
-        csh.setRealmName("myrealm");
-        csh.addConstraintMapping(cm);
-        csh.setLoginService(l);
-
-        return csh;
-
-    }
-
-    public static JettyTestServer getInstance() {
-        if (instance == null) {
-            instance = new JettyTestServer();
-        }
-        return instance;
-    }
-
-    private class MyHttpServlet extends HttpServlet {
-
-        private static final long serialVersionUID = 5594945031962091041L;
-
-        @Override
-        protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws IOException {
-            resp.getWriter().write(FileUtils.readFileToString(new 
File("src/test/data/feed.atom"),
-                    StandardCharsets.UTF_8));
-        }
-    }
-
-}
diff --git 
a/components/camel-atom/src/test/java/org/apache/camel/component/atom/MyHttpServlet.java
 
b/components/camel-atom/src/test/java/org/apache/camel/component/atom/MyHttpServlet.java
new file mode 100644
index 00000000000..944fa4f7187
--- /dev/null
+++ 
b/components/camel-atom/src/test/java/org/apache/camel/component/atom/MyHttpServlet.java
@@ -0,0 +1,39 @@
+/*
+ * 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.component.atom;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.io.FileUtils;
+
+public class MyHttpServlet extends HttpServlet {
+
+    private static final long serialVersionUID = 5594945031962091041L;
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws IOException {
+        resp.getWriter().write(FileUtils.readFileToString(new 
File("src/test/data/feed.atom"),
+                StandardCharsets.UTF_8));
+    }
+}

Reply via email to