This is an automated email from the ASF dual-hosted git repository. reta pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push: new 383c9273a0 Include back jaxrs systests module (#1012) 383c9273a0 is described below commit 383c9273a0b88931fef8117c6f0e481fa31734e4 Author: Andriy Redko <drr...@gmail.com> AuthorDate: Tue Oct 25 18:49:54 2022 -0400 Include back jaxrs systests module (#1012) * Include back jaxrs systests module * Fixing JAXRS20ClientServerBookTest test cases * Fixing JAXRSClientServerBookTest test cases * Fixing Netty version conflicts (tests only) * Added missing jetty-client dependency (tests only) * Fixed com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider usage * Fixed jakarta.ws.rs.Application usage * Fixing JAXRSJmsTest test cases * Fixing JsrJsonbProviderTest test cases * Fixing OpenApiCustomPropertiesTest test cases * Fixing JAXRSRequestDispatcherTest test cases * Fixing JAXRSSpringSecurityClassTest test cases * Fixing JAXRSSpringSecurityInterfaceTest and JAXRSSpringSecurityNoAnnotationsTest test cases * Fixing JAXRSClientMetricsTest test cases * Fixing AsyncTest test cases --- .../apache/cxf/bus/spring/SpringBeanLocator.java | 2 +- parent/pom.xml | 1 + .../cxf/jaxrs/provider/JAXBElementProvider.java | 4 +- .../apache/cxf/microprofile/client/AsyncTest.java | 82 ++++++++++------------ .../cxf/transport/jms/JMSMessageHeadersType.java | 4 +- systests/jaxrs/pom.xml | 46 ++++++++++-- .../systest/jaxrs/JAXRS20ClientServerBookTest.java | 4 +- .../systest/jaxrs/JAXRSRequestDispatcherTest.java | 3 - .../org/apache/cxf/systest/jaxrs/JMSBookStore.java | 2 +- .../apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java | 25 ++++--- .../jaxrs/metrics/JAXRSClientMetricsTest.java | 65 +++++++++-------- .../security/BookServerSecuritySpringClass.java | 15 ++++ .../src/test/resources/files/swagger.properties | 5 ++ .../src/test/resources/jaxrs/WEB-INF/beans.xml | 4 +- .../test/resources/jaxrs_cors/WEB-INF/beans.xml | 2 +- .../test/resources/jaxrs_dispatch/WEB-INF/web.xml | 4 +- .../jaxrs_jackson_provider/WEB-INF/beans.xml | 4 +- .../resources/jaxrs_non_spring/WEB-INF/web.xml | 6 +- .../resources/jaxrs_security/WEB-INF/beans.xml | 1 + .../jaxrs_security_cglib/WEB-INF/beans.xml | 1 + .../WEB-INF/beans.xml | 1 + systests/pom.xml | 12 +--- 22 files changed, 172 insertions(+), 121 deletions(-) diff --git a/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java b/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java index 1c5433473b..e1a15e85c7 100644 --- a/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java +++ b/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java @@ -158,7 +158,7 @@ public class SpringBeanLocator implements ConfiguredBeanLocator { return lst; } private <T> void tryOSGI(Collection<T> lst, Class<T> type) { - if (!osgi) { + if (!osgi || bundleContext == null) { return; } try { diff --git a/parent/pom.xml b/parent/pom.xml index 1331258b02..d3d0f95390 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -87,6 +87,7 @@ <cxf.ehcache3.version>3.10.0</cxf.ehcache3.version> <cxf.el-api.version>3.0.3</cxf.el-api.version> <cxf.findbugs.version>3.0.2</cxf.findbugs.version> + <cxf.hoverfly.version>0.14.0</cxf.hoverfly.version> <cxf.geronimo.jta.version>1.1.1</cxf.geronimo.jta.version> <cxf.geronimo.openapi.version>1.0.15</cxf.geronimo.openapi.version> <cxf.glassfish.el.version>4.0.0</cxf.glassfish.el.version> diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java index 0918600aed..87cf39c62d 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java @@ -83,8 +83,8 @@ import org.apache.cxf.staxutils.transform.TransformUtils; @Provider public class JAXBElementProvider<T> extends AbstractJAXBProvider<T> { private static final String XML_PI_START = "<?xml version=\"1.0\" encoding=\""; - private static final String XML_PI_PROPERTY_RI = "com.sun.xml.bind.xmlHeaders"; - private static final String XML_PI_PROPERTY_RI_INT = "com.sun.xml.internal.bind.xmlHeaders"; + private static final String XML_PI_PROPERTY_RI = "org.glassfish.jaxb.xmlHeaders"; + private static final String XML_PI_PROPERTY_RI_INT = "org.glassfish.jaxb.internal.bind.xmlHeaders"; private static final String[] MARSHALLER_PROPERTIES = { Marshaller.JAXB_ENCODING, diff --git a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/AsyncTest.java b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/AsyncTest.java index b0e7f06022..a4b0243b44 100644 --- a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/AsyncTest.java +++ b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/AsyncTest.java @@ -18,70 +18,69 @@ */ package org.apache.cxf.microprofile.client; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; import java.net.URI; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CompletionStage; import java.util.concurrent.TimeUnit; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.Response; -import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; import org.apache.cxf.microprofile.client.mock.AsyncClient; import org.apache.cxf.microprofile.client.mock.NotFoundExceptionMapper; import org.eclipse.microprofile.rest.client.RestClientBuilder; -import org.junit.Rule; +import org.junit.After; +import org.junit.Before; import org.junit.Test; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.notFound; -import static com.github.tomakehurst.wiremock.client.WireMock.ok; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; public class AsyncTest { - @SuppressWarnings("unchecked") - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig() - .extensions(SimpleTransformer.class).dynamicPort()); - - public static class SimpleTransformer extends ResponseTransformer { - private final Queue<String> queue = new ArrayBlockingQueue<>(2); - - public SimpleTransformer() { - queue.add("Hello"); - queue.add("World"); - } - - @Override - public Response transform(Request request, Response response, FileSource fileSource, Parameters parameters) { - return Response.Builder - .like(response) - .but().body(queue.poll()) - .build(); - } + private HttpServer server; + private final Queue<String> queue = new ArrayBlockingQueue<>(2); + public class SimpleHandler implements HttpHandler { @Override - public boolean applyGlobally() { - return false; + public void handle(HttpExchange exchange) throws IOException { + final String body = queue.poll(); + if (body == null) { + exchange.sendResponseHeaders(404, 0); + } else { + exchange.sendResponseHeaders(200, body.length()); + try (OutputStream os = exchange.getResponseBody()) { + os.write(body.getBytes()); + } + } } + } - @Override - public String getName() { - return "enqueue-transformer"; - } + @Before + public void setUp() throws IOException { + server = HttpServer.create(new InetSocketAddress(0), 2); + server.createContext("/", new SimpleHandler()); + server.start(); } - + + @After + public void tearDown() throws IOException { + server.stop(0); + queue.clear(); + } + @Test public void testAsyncClient() throws Exception { - URI uri = URI.create(wireMockRule.baseUrl()); + queue.add("Hello"); + queue.add("World"); + + URI uri = URI.create("http://localhost:" + server.getAddress().getPort()); AsyncClient client = RestClientBuilder.newBuilder() .baseUri(uri) .connectTimeout(5, TimeUnit.SECONDS) @@ -89,8 +88,6 @@ public class AsyncTest { .build(AsyncClient.class); assertNotNull(client); - wireMockRule.stubFor(get("/").willReturn(ok().withTransformers("enqueue-transformer"))); - String combined = client.get().thenCombine(client.get(), (a, b) -> { return a + " " + b; }).toCompletableFuture().get(10, TimeUnit.SECONDS); @@ -100,14 +97,13 @@ public class AsyncTest { @Test public void testAsyncClientCanMapExceptionResponses() throws Exception { - URI uri = URI.create(wireMockRule.baseUrl()); + URI uri = URI.create("http://localhost:" + server.getAddress().getPort()); AsyncClient client = RestClientBuilder.newBuilder() .baseUri(uri) .connectTimeout(5, TimeUnit.SECONDS) .readTimeout(5, TimeUnit.SECONDS) .register(NotFoundExceptionMapper.class) .build(AsyncClient.class); - wireMockRule.stubFor(get("/").willReturn(notFound())); CompletionStage<?> cs = client.get().exceptionally(t -> { Throwable t2 = t.getCause(); diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java index 16e5a9fa66..de2db40b08 100644 --- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java +++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java @@ -373,13 +373,13 @@ public class JMSMessageHeadersType { while (enm.hasMoreElements()) { String name = enm.nextElement(); String val = message.getStringProperty(name); - String unescapedName = name.replace("__", "."); + String unescapedName = name.replace("_$_", "-").replace("__", "."); putProperty(unescapedName, val); } } public void writeProp(Message jmsMessage, String origName, Object value) throws JMSException { - String name = origName.replace(".", "__").replace("-", "___"); + String name = origName.replace(".", "__").replace("-", "_$_"); if (value == null) { jmsMessage.setStringProperty(name, null); return; diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml index 3f26188ff0..42ae8adca1 100644 --- a/systests/jaxrs/pom.xml +++ b/systests/jaxrs/pom.xml @@ -102,6 +102,11 @@ <groupId>org.webjars</groupId> <artifactId>swagger-ui</artifactId> <version>${cxf.swagger.ui.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-client</artifactId> + <version>${cxf.jetty.version}</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> @@ -217,6 +222,12 @@ <groupId>org.apache.activemq</groupId> <artifactId>artemis-jakarta-server</artifactId> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>io.netty</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.cxf</groupId> @@ -437,6 +448,12 @@ <groupId>org.asynchttpclient</groupId> <artifactId>async-http-client</artifactId> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>io.netty</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.lucene</groupId> @@ -506,14 +523,14 @@ <scope>test</scope> </dependency> <dependency> - <groupId>com.github.tomakehurst</groupId> - <artifactId>wiremock</artifactId> - <version>${cxf.wiremock.version}</version> + <groupId>io.specto</groupId> + <artifactId>hoverfly-java</artifactId> + <version>${cxf.hoverfly.version}</version> <scope>test</scope> <exclusions> <exclusion> - <groupId>org.xmlunit</groupId> - <artifactId>xmlunit-core</artifactId> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> </exclusion> </exclusions> </dependency> @@ -528,6 +545,25 @@ <classifier>jakarta</classifier> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.johnzon</groupId> + <artifactId>johnzon-mapper</artifactId> + <version>${cxf.johnzon.version}</version> + <classifier>jakarta</classifier> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.netty</groupId> + <artifactId>netty-codec-socks</artifactId> + <version>${cxf.netty.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.netty</groupId> + <artifactId>netty-handler-proxy</artifactId> + <version>${cxf.netty.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java index 69700e8505..1445238a8a 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java @@ -976,8 +976,8 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase .get() .readEntity(String.class); - assertThat(response, equalTo("2020-01-01{javax.ws.rs.GET,javax.ws.rs.Path,javax.ws.rs.Produces," - + "javax.ws.rs.ext.Provider,javax.ws.rs.Consumes}")); + assertThat(response, equalTo("2020-01-01{jakarta.ws.rs.GET,jakarta.ws.rs.Path,jakarta.ws.rs.Produces," + + "jakarta.ws.rs.ext.Provider,jakarta.ws.rs.Consumes}")); } private static class ReplaceBodyFilter implements ClientRequestFilter { diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java index 8497440d19..8707b2c68b 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java @@ -30,7 +30,6 @@ import org.apache.cxf.jaxrs.ext.xml.XMLSource; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import static org.hamcrest.CoreMatchers.containsString; @@ -80,7 +79,6 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase } @Test - @Ignore("JSP pages need to be precompiled by Maven build") public void testGetBookJSPRequestScope() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/the/bookstore2/books/html/123"; @@ -94,7 +92,6 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase } @Test - @Ignore("JSP pages need to be precompiled by Maven build") public void testGetBookJSPSessionScope() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/the/bookstore3/books/html/456"; diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java index a189e26f63..f12f105a51 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java @@ -152,7 +152,7 @@ public class JMSBookStore { private Context getContext() throws Exception { Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, - "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); + "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.setProperty(Context.PROVIDER_URL, "tcp://localhost:" + EmbeddedJMSBrokerLauncher.PORT); return new InitialContext(props); diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java index 50f02a2a4a..2d52a4cce7 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java @@ -379,9 +379,9 @@ public class JAXRSJmsTest extends AbstractBusClientServerTestBase { MessageProducer producer = session.createProducer(destination); Message message = session.createBytesMessage(); message.setJMSReplyTo(replyTo); - message.setStringProperty("Accept", "application/xml"); - message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books/123"); - message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "GET"); + setStringProperty(message, "Accept", "application/xml"); + setStringProperty(message, org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books/123"); + setStringProperty(message, org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "GET"); producer.send(message); producer.close(); } @@ -393,9 +393,9 @@ public class JAXRSJmsTest extends AbstractBusClientServerTestBase { byte[] payload = writeBook(new Book("JMS OneWay", 125L)); BytesMessage message = session.createBytesMessage(); message.writeBytes(payload); - message.setStringProperty("Content-Type", "application/xml"); - message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/oneway"); - message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "PUT"); + setStringProperty(message, "Content-Type", "application/xml"); + setStringProperty(message, org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/oneway"); + setStringProperty(message, org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "PUT"); producer.send(message); producer.close(); @@ -422,11 +422,11 @@ public class JAXRSJmsTest extends AbstractBusClientServerTestBase { // POST // Message.REQUEST_URI : "/" - message.setStringProperty("Content-Type", "application/xml"); - message.setStringProperty("Accept", "text/xml"); - message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books"); - message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "POST"); - message.setStringProperty("custom.protocol.header", "custom.value"); + setStringProperty(message, "Content-Type", "application/xml"); + setStringProperty(message, "Accept", "text/xml"); + setStringProperty(message, org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books"); + setStringProperty(message, org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "POST"); + setStringProperty(message, "custom.protocol.header", "custom.value"); producer.send(message); producer.close(); @@ -457,4 +457,7 @@ public class JAXRSJmsTest extends AbstractBusClientServerTestBase { } } + private static void setStringProperty(Message message, String name, String value) throws JMSException { + message.setStringProperty(name.replace(".", "__").replace("-", "_$_"), value); + } } diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java index c2438af86d..f25f5afaf9 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java @@ -22,7 +22,6 @@ package org.apache.cxf.systest.jaxrs.metrics; import java.util.Arrays; import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; -import com.github.tomakehurst.wiremock.junit.WireMockRule; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.ProcessingException; @@ -37,9 +36,13 @@ import org.apache.cxf.metrics.MetricsContext; import org.apache.cxf.metrics.MetricsFeature; import org.apache.cxf.metrics.MetricsProvider; import org.apache.cxf.service.model.BindingOperationInfo; -import org.springframework.util.SocketUtils; +import org.apache.cxf.testutil.common.TestUtil; + +import io.specto.hoverfly.junit.core.SimulationSource; +import io.specto.hoverfly.junit.rule.HoverflyRule; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -47,19 +50,16 @@ import org.junit.runner.RunWith; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static io.specto.hoverfly.junit.core.HoverflyConfig.localConfigs; +import static io.specto.hoverfly.junit.dsl.HoverflyDsl.response; +import static io.specto.hoverfly.junit.dsl.HoverflyDsl.service; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.times; @RunWith(MockitoJUnitRunner.class) public class JAXRSClientMetricsTest { - @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + @ClassRule public static HoverflyRule hoverflyRule = HoverflyRule.inSimulationMode(localConfigs().asWebServer()); @Rule public ExpectedException expectedException = ExpectedException.none(); private MetricsProvider provider; @@ -94,13 +94,14 @@ public class JAXRSClientMetricsTest { public void usingClientProxyStopIsCalledWhenServerReturnsNotFound() throws Exception { final JAXRSClientFactoryBean factory = new JAXRSClientFactoryBean(); factory.setResourceClass(Library.class); - factory.setAddress("http://localhost:" + wireMockRule.port() + "/"); + factory.setAddress("http://localhost:" + hoverflyRule.getProxyPort() + "/"); factory.setFeatures(Arrays.asList(new MetricsFeature(provider))); factory.setProvider(JacksonJsonProvider.class); - - stubFor(get(urlEqualTo("/books/10")) - .willReturn(aResponse() - .withStatus(404))); + + hoverflyRule.simulate(SimulationSource.dsl( + service("localhost") + .get("/books/10") + .willReturn(response().status(404)))); try { final Library client = factory.create(Library.class); @@ -122,14 +123,15 @@ public class JAXRSClientMetricsTest { .register(new MetricsFeature(provider)) .register(JacksonJsonProvider.class); - stubFor(get(urlEqualTo("/books/10")) - .willReturn(aResponse() - .withStatus(404))); + hoverflyRule.simulate(SimulationSource.dsl( + service("localhost") + .get("/books/10") + .willReturn(response().status(404)))); try { expectedException.expect(ProcessingException.class); client - .target("http://localhost:" + wireMockRule.port() + "/books/10") + .target("http://localhost:" + hoverflyRule.getProxyPort() + "/books/10") .request(MediaType.APPLICATION_JSON).get() .readEntity(Book.class); } finally { @@ -143,7 +145,7 @@ public class JAXRSClientMetricsTest { @Test public void usingClientStopIsCalledWhenConnectionIsRefused() throws Exception { - final int port = SocketUtils.findAvailableTcpPort(); + final int port = Integer.parseInt(TestUtil.getNewPortNumber(getClass())); final Client client = ClientBuilder .newClient() @@ -173,16 +175,18 @@ public class JAXRSClientMetricsTest { .register(new MetricsFeature(provider)) .register(JacksonJsonProvider.class); - stubFor(get(urlEqualTo("/books/10")) - .withHeader("Accept", equalTo(MediaType.APPLICATION_JSON)) - .willReturn(aResponse() - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody("{}") - .withStatus(200))); + hoverflyRule.simulate(SimulationSource.dsl( + service("localhost") + .get("/books/10") + .header("Accept", MediaType.APPLICATION_JSON) + .willReturn(response() + .header("Content-Type", MediaType.APPLICATION_JSON) + .body("{}") + .status(200)))); try { client - .target("http://localhost:" + wireMockRule.port() + "/books/10") + .target("http://localhost:" + hoverflyRule.getProxyPort() + "/books/10") .request(MediaType.APPLICATION_JSON) .get() .readEntity(Book.class); @@ -197,12 +201,13 @@ public class JAXRSClientMetricsTest { @Test public void usingWebClientStopIsCalledWhenServerReturnsNotFound() throws Exception { - final WebClient client = WebClient.create("http://localhost:" + wireMockRule.port() + "/books/10", + final WebClient client = WebClient.create("http://localhost:" + hoverflyRule.getProxyPort() + "/books/10", Arrays.asList(JacksonJsonProvider.class), Arrays.asList(new MetricsFeature(provider)), null); - stubFor(get(urlEqualTo("/books/10")) - .willReturn(aResponse() - .withStatus(404))); + hoverflyRule.simulate(SimulationSource.dsl( + service("localhost") + .get("/books/10") + .willReturn(response().status(404)))); try { expectedException.expect(ProcessingException.class); diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/BookServerSecuritySpringClass.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/BookServerSecuritySpringClass.java index f58dc9f138..b6493680ca 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/BookServerSecuritySpringClass.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/BookServerSecuritySpringClass.java @@ -20,6 +20,10 @@ package org.apache.cxf.systest.jaxrs.security; import org.apache.cxf.systest.jaxrs.AbstractSpringServer; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.webapp.WebAppContext; @@ -29,6 +33,17 @@ public class BookServerSecuritySpringClass extends AbstractSpringServer { public BookServerSecuritySpringClass() { super("/jaxrs_security_cglib", PORT); } + + @Override + protected void configureServer(Server server) throws Exception { + final HandlerCollection collection = (HandlerCollection) server.getHandler(); + for (Handler handler: collection.getHandlers()) { + if (handler instanceof WebAppContext) { + final WebAppContext webappcontext = (WebAppContext) handler; + webappcontext.setClassLoader(getClass().getClassLoader()); + } + } + } public static void main(String[] args) { try { diff --git a/systests/jaxrs/src/test/resources/files/swagger.properties b/systests/jaxrs/src/test/resources/files/swagger.properties new file mode 100644 index 0000000000..417045b753 --- /dev/null +++ b/systests/jaxrs/src/test/resources/files/swagger.properties @@ -0,0 +1,5 @@ +contact=c...@apache.org +title=CXF unittest +description=API Description +license=API License +license.url=API License URL \ No newline at end of file diff --git a/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml index 16c85c7080..c39ac77175 100644 --- a/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml +++ b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml @@ -148,7 +148,7 @@ <ref bean="serviceBean"/> </jaxrs:serviceBeans> <jaxrs:providers> - <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/> + <bean class="com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider"/> <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/> </jaxrs:providers> <jaxrs:inInterceptors> @@ -239,7 +239,7 @@ <bean class="org.apache.cxf.systest.jaxrs.DocumentResourceImpl"/> </jaxrs:serviceBeans> <jaxrs:providers> - <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/> + <bean class="com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider"/> </jaxrs:providers> </jaxrs:server> <bean id="jaxbProviderForTypes" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"> diff --git a/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml index 5b6dc21240..94b9249ce8 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml @@ -50,7 +50,7 @@ <ref bean="config-server"/> </jaxrs:serviceBeans> <jaxrs:providers> - <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/> + <bean class="com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider"/> </jaxrs:providers> </jaxrs:server> <bean id="config-server" class="org.apache.cxf.systest.jaxrs.cors.ConfigServer"> diff --git a/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml b/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml index 470c541190..29d65c062c 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml @@ -46,7 +46,7 @@ <init-param> <param-name>redirect-attributes</param-name> <param-value> - javax.servlet.include.request_uri + jakarta.servlet.include.request_uri </param-value> </init-param> <init-param> @@ -146,7 +146,7 @@ <init-param> <param-name>redirect-attributes</param-name> <param-value> - javax.servlet.include.request_uri + jakarta.servlet.include.request_uri </param-value> </init-param> <init-param> diff --git a/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml index 4ca5850c8d..52214292fe 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml @@ -121,8 +121,8 @@ http://cxf.apache.org/schemas/jaxrs.xsd"> </jaxrs:providers> </jaxrs:server> - <bean id="jackson" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/> - <bean id="jackson2" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/> + <bean id="jackson" class="com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider"/> + <bean id="jackson2" class="com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider"/> <bean id="jaxb" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"> <property name="unmarshallAsJaxbElement" value="true"/> <property name="marshallAsJaxbElement" value="true"/> diff --git a/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml b/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml index c0f0cb03b8..2a678fdbcb 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml @@ -64,7 +64,7 @@ org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet </servlet-class> <init-param> - <param-name>javax.ws.rs.Application</param-name> + <param-name>jakarta.ws.rs.Application</param-name> <param-value> org.apache.cxf.systest.jaxrs.BookApplication (defaultName=default defaultId=543) @@ -127,7 +127,7 @@ org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet </servlet-class> <init-param> - <param-name>javax.ws.rs.Application</param-name> + <param-name>jakarta.ws.rs.Application</param-name> <param-value>org.apache.cxf.systest.jaxrs.BookApplication</param-value> </init-param> <init-param> @@ -143,7 +143,7 @@ org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet </servlet-class> <init-param> - <param-name>javax.ws.rs.Application</param-name> + <param-name>jakarta.ws.rs.Application</param-name> <param-value> org.apache.cxf.systest.jaxrs.BookApplication, org.apache.cxf.systest.jaxrs.BookApplication2 diff --git a/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml index 5c2e625531..083dfd838c 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml @@ -56,6 +56,7 @@ <security:global-method-security secured-annotations="enabled"/> <security:http auto-config="true"> <security:http-basic/> + <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> </security:http> <bean id="bookstoreGenerics" class="org.apache.cxf.systest.jaxrs.security.SecureBookStoreGenerics"/> <security:authentication-manager> diff --git a/systests/jaxrs/src/test/resources/jaxrs_security_cglib/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_security_cglib/WEB-INF/beans.xml index 340b5a75fc..67ead8598d 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_security_cglib/WEB-INF/beans.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_security_cglib/WEB-INF/beans.xml @@ -58,6 +58,7 @@ <security:http auto-config="true"> <security:http-basic/> <security:csrf disabled="true"/> + <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> </security:http> <security:authentication-manager> <security:authentication-provider> diff --git a/systests/jaxrs/src/test/resources/jaxrs_security_no_annotations/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_security_no_annotations/WEB-INF/beans.xml index ffbf67e085..8cc834c147 100644 --- a/systests/jaxrs/src/test/resources/jaxrs_security_no_annotations/WEB-INF/beans.xml +++ b/systests/jaxrs/src/test/resources/jaxrs_security_no_annotations/WEB-INF/beans.xml @@ -53,6 +53,7 @@ </security:global-method-security> <security:http auto-config="true"> <security:http-basic/> + <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> </security:http> <security:authentication-manager> <security:authentication-provider> diff --git a/systests/pom.xml b/systests/pom.xml index 4f27033f7e..44097cc0c8 100644 --- a/systests/pom.xml +++ b/systests/pom.xml @@ -56,16 +56,6 @@ <module>transport-netty</module> <module>transport-hc5</module> <module>transport-jms</module> + <module>jaxrs</module> </modules> - - <profiles> - <!-- TODO: This profile includes modules which are still on 'javax.*' namespace and - are not migrated to Jakarta --> - <profile> - <id>javax</id> - <modules> - <module>jaxrs</module> - </modules> - </profile> - </profiles> </project>