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 e78f1bc0973 CAMEL-18456: converted camel-rss tests to
camel-test-infra-jetty
e78f1bc0973 is described below
commit e78f1bc09736b46da166b465cdf1acaa77bff644
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Sep 14 11:35:05 2022 +0200
CAMEL-18456: converted camel-rss tests to camel-test-infra-jetty
---
components/camel-rss/pom.xml | 15 +--
.../camel/component/rss/JettyTestServer.java | 130 ---------------------
...erWithBasicAuthTest.java => MyHttpServlet.java} | 36 +++---
.../RssEntryPollingConsumerWithBasicAuthTest.java | 36 +++---
.../rss/RssPollingConsumerWithBasicAuthTest.java | 36 +++---
5 files changed, 63 insertions(+), 190 deletions(-)
diff --git a/components/camel-rss/pom.xml b/components/camel-rss/pom.xml
index bdca76d173d..2b204f5496e 100644
--- a/components/camel-rss/pom.xml
+++ b/components/camel-rss/pom.xml
@@ -76,16 +76,13 @@
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
+
+ <!-- test infra -->
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-servlet</artifactId>
- <version>${jetty-version}</version>
- <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>
</dependencies>
diff --git
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/JettyTestServer.java
b/components/camel-rss/src/test/java/org/apache/camel/component/rss/JettyTestServer.java
deleted file mode 100644
index 37652b7183f..00000000000
---
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/JettyTestServer.java
+++ /dev/null
@@ -1,130 +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.rss;
-
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.jupiter.api.Assertions.fail;
-
-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/rss20.xml"), StandardCharsets.UTF_8));
- }
- }
-
-}
diff --git
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerWithBasicAuthTest.java
b/components/camel-rss/src/test/java/org/apache/camel/component/rss/MyHttpServlet.java
similarity index 52%
copy from
components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerWithBasicAuthTest.java
copy to
components/camel-rss/src/test/java/org/apache/camel/component/rss/MyHttpServlet.java
index 1f9a062d806..2cc9f339905 100644
---
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerWithBasicAuthTest.java
+++
b/components/camel-rss/src/test/java/org/apache/camel/component/rss/MyHttpServlet.java
@@ -14,33 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.camel.component.rss;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
-public class RssPollingConsumerWithBasicAuthTest extends
RssPollingConsumerTest {
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
- @Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- @Override
- public void configure() {
- from("rss:http://localhost:" +
JettyTestServer.getInstance().port
- +
"/?splitEntries=false&username=camel&password=camelPass").to("mock:result");
- }
- };
- }
+import org.apache.commons.io.FileUtils;
- @BeforeAll
- public static void startServer() {
- JettyTestServer.getInstance().startServer();
- }
+public class MyHttpServlet extends HttpServlet {
- @AfterAll
- public static void stopServer() {
- JettyTestServer.getInstance().stopServer();
- }
+ 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/rss20.xml"), StandardCharsets.UTF_8));
+ }
}
diff --git
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithBasicAuthTest.java
b/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithBasicAuthTest.java
index a7df22d34c0..dd035d3fa9b 100644
---
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithBasicAuthTest.java
+++
b/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithBasicAuthTest.java
@@ -18,13 +18,30 @@ package org.apache.camel.component.rss;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+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.apache.camel.test.junit5.CamelTestSupport;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
public class RssEntryPollingConsumerWithBasicAuthTest extends CamelTestSupport
{
+ private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+ @RegisterExtension
+ public JettyEmbeddedService service = new JettyEmbeddedService(
+ JettyConfigurationBuilder.bareTemplate()
+ .withPort(PORT)
+ .withServletConfiguration()
+ .addServletConfiguration(new
JettyConfiguration.ServletHandlerConfiguration.ServletConfiguration<>(
+ new MyHttpServlet(),
+
JettyConfiguration.ServletHandlerConfiguration.ServletConfiguration.ROOT_PATH_SPEC))
+ .addBasicAuthUser("camel", "camelPass", "Private!")
+ .build()
+ .build());
+
@Test
public void testListOfEntriesIsSplitIntoPieces() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -37,19 +54,10 @@ public class RssEntryPollingConsumerWithBasicAuthTest
extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() {
- from("rss:http://localhost:" +
JettyTestServer.getInstance().port
- +
"/?splitEntries=true&sortEntries=true&delay=100&username=camel&password=camelPass").to("mock:result");
+
fromF("rss:http://localhost:%d/?splitEntries=true&sortEntries=true&delay=100&username=camel&password=camelPass",
+ PORT)
+ .to("mock:result");
}
};
}
-
- @BeforeAll
- public static void startServer() {
- JettyTestServer.getInstance().startServer();
- }
-
- @AfterAll
- public static void stopServer() {
- JettyTestServer.getInstance().stopServer();
- }
}
diff --git
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerWithBasicAuthTest.java
b/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerWithBasicAuthTest.java
index 1f9a062d806..5e022381422 100644
---
a/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerWithBasicAuthTest.java
+++
b/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerWithBasicAuthTest.java
@@ -17,30 +17,36 @@
package org.apache.camel.component.rss;
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.extension.RegisterExtension;
public class RssPollingConsumerWithBasicAuthTest extends
RssPollingConsumerTest {
+ private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+ @RegisterExtension
+ public JettyEmbeddedService service = new JettyEmbeddedService(
+ JettyConfigurationBuilder.bareTemplate()
+ .withPort(PORT)
+ .withServletConfiguration()
+ .addServletConfiguration(new
JettyConfiguration.ServletHandlerConfiguration.ServletConfiguration<>(
+ new MyHttpServlet(),
+
JettyConfiguration.ServletHandlerConfiguration.ServletConfiguration.ROOT_PATH_SPEC))
+ .addBasicAuthUser("camel", "camelPass", "Private!")
+ .build()
+ .build());
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
- from("rss:http://localhost:" +
JettyTestServer.getInstance().port
- +
"/?splitEntries=false&username=camel&password=camelPass").to("mock:result");
+
fromF("rss:http://localhost:%d/?splitEntries=false&username=camel&password=camelPass",
PORT)
+ .to("mock:result");
}
};
}
-
- @BeforeAll
- public static void startServer() {
- JettyTestServer.getInstance().startServer();
- }
-
- @AfterAll
- public static void stopServer() {
- JettyTestServer.getInstance().stopServer();
- }
-
}