You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2022/08/18 17:15:51 UTC

[cxf] branch main updated (4e110842a3 -> 4ec898213e)

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

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


    from 4e110842a3 [CXF-8749]:Existing handler file fails the compile generated java source files
     new 9a9d8da3ea CXF-8750: only add trailing slash if necessary when locating webjars … (#982)
     new 6feef17508 Refactored JaxRsServiceTest to use single WebTarget instance
     new 3cb4023622 Attempt to fix flaky JaxRsServiceTest tests (CXF-8750 post merge) (#984)
     new 4ec898213e Attempt to fix flaky JaxRsServiceTest tests (CXF-8750 post merge): split into separate test cases (#986)

The 4 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:
 osgi/itests/pom.xml                                |   9 ++
 .../apache/cxf/osgi/itests/CXFOSGiTestSupport.java |   1 -
 .../apache/cxf/osgi/itests/jaxrs/BookStore.java    |   1 -
 .../cxf/osgi/itests/jaxrs/JaxRsServiceTest.java    |  33 +++++--
 .../cxf/osgi/itests/jaxrs/JaxRsTestActivator.java  |   1 -
 .../cxf/osgi/itests/jaxrs/OpenApiBookStore.java    | 101 +++++++++++++++++++
 ...xRsServiceTest.java => OpenApiServiceTest.java} | 107 +++++++++++++--------
 ...estActivator.java => OpenApiTestActivator.java} |  17 +++-
 .../jaxrs/swagger/ui/OsgiSwaggerUiResolver.java    |   4 +-
 9 files changed, 218 insertions(+), 56 deletions(-)
 create mode 100644 osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiBookStore.java
 copy osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/{JaxRsServiceTest.java => OpenApiServiceTest.java} (53%)
 copy osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/{JaxRsTestActivator.java => OpenApiTestActivator.java} (67%)


[cxf] 04/04: Attempt to fix flaky JaxRsServiceTest tests (CXF-8750 post merge): split into separate test cases (#986)

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

commit 4ec898213e8d5b2e12dfe4793ddd5129a41b99c3
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Wed Aug 17 13:19:22 2022 -0400

    Attempt to fix flaky JaxRsServiceTest tests (CXF-8750 post merge): split into separate test cases (#986)
---
 .../apache/cxf/osgi/itests/CXFOSGiTestSupport.java |   1 -
 .../apache/cxf/osgi/itests/jaxrs/BookStore.java    |  49 ---------
 .../cxf/osgi/itests/jaxrs/JaxRsServiceTest.java    |  47 +--------
 .../cxf/osgi/itests/jaxrs/JaxRsTestActivator.java  |  10 --
 .../cxf/osgi/itests/jaxrs/OpenApiBookStore.java    | 101 ++++++++++++++++++
 ...xRsServiceTest.java => OpenApiServiceTest.java} | 117 +++++++--------------
 ...estActivator.java => OpenApiTestActivator.java} |   6 +-
 7 files changed, 146 insertions(+), 185 deletions(-)

diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
index a330a924b8..b5d7f06e1e 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
@@ -23,7 +23,6 @@ package org.apache.cxf.osgi.itests;
 import java.io.File;
 
 import jakarta.inject.Inject;
-
 import org.apache.cxf.testutil.common.TestUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
index 1e2f735325..9c3fea39c0 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
@@ -49,14 +49,7 @@ import org.apache.cxf.validation.BeanValidationProvider;
 import org.hibernate.validator.HibernateValidator;
 import org.hibernate.validator.HibernateValidatorConfiguration;
 
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.tags.Tag;
-
 @Path("/bookstore")
-@Tag(name = "BookStore")
 @Produces("application/xml")
 public class BookStore {
     private Map<Long, Book> books = new HashMap<>();
@@ -79,15 +72,6 @@ public class BookStore {
 
     @GET
     @Path("/books/{id}")
-    @Operation(
-            summary = "Get book by ID",
-            description = "Get operation with path parameter",
-            responses = {
-                @ApiResponse(content = @Content(schema = @Schema(implementation = Book.class)),
-                    description = "Book found", responseCode = "200"),
-                @ApiResponse(description = "Book not found", responseCode = "404")
-            }
-    )
     public Response getBookRoot(@PathParam("id") Long id) {
         assertInjections();
         Book b = books.get(id);
@@ -97,14 +81,6 @@ public class BookStore {
         return Response.ok(b).build();
     }
 
-    @Operation(
-            summary = "Update book by ID",
-            description = "Put operation with path parameter",
-            responses = {
-                @ApiResponse(description = "Book found and updated", responseCode = "200"),
-                @ApiResponse(description = "Book not found", responseCode = "404")
-            }
-    )
     @PUT
     @Path("/books/{id}")
     public Response updateBook(@PathParam("id") Long id, Book book) {
@@ -117,14 +93,6 @@ public class BookStore {
         return Response.ok().build();
     }
 
-    @Operation(
-            summary = "Create a book with validation",
-            description = "Post operation with entity in body and validation",
-            responses = {
-                @ApiResponse(description = "Book created", responseCode = "201"),
-                @ApiResponse(description = "Validation failed", responseCode = "400")
-            }
-    )
     @POST
     @Path("/books-validate")
     public Response createBookValidate(Book book) {
@@ -154,15 +122,6 @@ public class BookStore {
         return createBook(book);
     }
 
-
-    @Operation(
-            summary = "Create new book",
-            description = "Post operation with entity in body",
-            responses = {
-                @ApiResponse(description = "Book created", responseCode = "201"),
-                @ApiResponse(description = "Book with given ID already exists", responseCode = "409")
-            }
-    )
     @POST
     @Path("/books")
     public Response createBook(Book book) {
@@ -177,14 +136,6 @@ public class BookStore {
         return Response.created(createdURI).build();
     }
 
-    @Operation(
-            summary = "Delete a book",
-            description = "Delete operation with path param",
-            responses = {
-                @ApiResponse(description = "Book deleted", responseCode = "200"),
-                @ApiResponse(description = "Book not found", responseCode = "404")
-            }
-    )
     @DELETE
     @Path("/books/{id}")
     public Response removeBook(@PathParam("id") Long id) {
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
index 2e6bc1f89f..52555def1e 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
@@ -25,11 +25,6 @@ import jakarta.ws.rs.client.Entity;
 import jakarta.ws.rs.client.WebTarget;
 import jakarta.ws.rs.core.Response;
 import jakarta.ws.rs.core.Response.Status;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
-
 import org.apache.cxf.helpers.JavaUtils;
 import org.apache.cxf.osgi.itests.AbstractServerActivator;
 import org.apache.cxf.osgi.itests.CXFOSGiTestSupport;
@@ -48,9 +43,6 @@ import org.ops4j.pax.tinybundles.core.TinyBundles;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
@@ -62,13 +54,8 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
 
     private static final String BASE_URL = "http://localhost:" + PORT + "/cxf/jaxrs/";
     private static final String BOOKSTORE_PATH = "bookstore";
-    private static final String SWAGGER_PATH = "api-docs";
-    private static final String OPEN_API_FILE_PATH = "openapi.json";
 
-    private final WebTarget wt = ClientBuilder
-        .newClient()
-        .register(JacksonJsonProvider.class)
-        .target(BASE_URL);
+    private final WebTarget wt = ClientBuilder.newClient().target(BASE_URL);
 
     @Test
     public void testJaxRsGet() throws Exception {
@@ -130,34 +117,6 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
         assertStatus(Status.OK, response);
     }
 
-    @Test
-    public void testGetSwaggerUi() {
-        WebTarget swaggerWt = wt.path(SWAGGER_PATH).queryParam("url", "/cxf/jaxrs/openapi.json");
-        Response response = swaggerWt.request().get();
-        String swaggerFileHtml = response.readEntity(String.class);
-
-        assertStatus(Status.OK, response);
-        assertTrue(swaggerFileHtml.contains("<html"));
-        assertTrue(swaggerFileHtml.contains("<head>"));
-        assertTrue(swaggerFileHtml.contains("<title>Swagger UI</title>"));
-        assertTrue(swaggerFileHtml.contains("</html>"));
-    }
-
-    @Test
-    public void testGetOpenApiJsonFile() {
-        WebTarget openApiWt = wt.path(OPEN_API_FILE_PATH);
-        Response response = openApiWt.request().get();
-        String openApiJson = response.readEntity(String.class);
-
-        assertStatus(Status.OK, response);
-        try {
-            new ObjectMapper().readValue(openApiJson, Object.class);
-            assertTrue(openApiJson.contains("/bookstore/"));
-        } catch (JsonProcessingException e) {
-            fail();
-        }
-    }
-
     private static void assertStatus(Status expectedStatus, Response response) {
         assertEquals(expectedStatus.getStatusCode(), response.getStatus());
     }
@@ -166,9 +125,7 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
     public Option[] config() {
         return OptionUtils.combine(
             cxfBaseConfig(),
-            features(cxfUrl, "cxf-core", "cxf-wsdl", "cxf-jaxrs", "cxf-bean-validation-core", "cxf-bean-validation",
-                    "cxf-rs-description-openapi-v3"),
-            mavenBundle("org.webjars", "swagger-ui").versionAsInProject(),
+            features(cxfUrl, "cxf-core", "cxf-wsdl", "cxf-jaxrs", "cxf-bean-validation-core", "cxf-bean-validation"),
             logLevel(LogLevel.INFO),
             testUtils(),
             provision(serviceBundle())
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
index b7176ba039..42eec4eada 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
@@ -22,8 +22,6 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.openapi.OpenApiFeature;
-import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiConfig;
 import org.apache.cxf.osgi.itests.AbstractServerActivator;
 
 public class JaxRsTestActivator extends AbstractServerActivator {
@@ -35,14 +33,6 @@ public class JaxRsTestActivator extends AbstractServerActivator {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setBus(bus);
         sf.setResourceClasses(BookStore.class);
-
-        OpenApiFeature openApiFeature = new OpenApiFeature();
-        openApiFeature.setScan(false);
-        SwaggerUiConfig swaggerUiConfig = new SwaggerUiConfig();
-        swaggerUiConfig.setUrl("/cxf/jaxrs/openapi.json");
-        openApiFeature.setSwaggerUiConfig(swaggerUiConfig);
-
-        sf.getFeatures().add(openApiFeature);
         sf.setAddress("/jaxrs");
         return sf.create();
     }
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiBookStore.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiBookStore.java
new file mode 100644
index 0000000000..9cf0b55894
--- /dev/null
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiBookStore.java
@@ -0,0 +1,101 @@
+/**
+ * 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.cxf.osgi.itests.jaxrs;
+
+
+import jakarta.ws.rs.DELETE;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
+@Tag(name = "BookStore")
+public class OpenApiBookStore extends BookStore {
+    @Operation(
+            summary = "Get book by ID",
+            description = "Get operation with path parameter",
+            responses = {
+                @ApiResponse(content = @Content(schema = @Schema(implementation = Book.class)),
+                    description = "Book found", responseCode = "200"),
+                @ApiResponse(description = "Book not found", responseCode = "404")
+            }
+    )
+    public Response getBookRoot(@PathParam("id") Long id) {
+        return super.getBookRoot(id);
+    }
+
+    @Operation(
+            summary = "Update book by ID",
+            description = "Put operation with path parameter",
+            responses = {
+                @ApiResponse(description = "Book found and updated", responseCode = "200"),
+                @ApiResponse(description = "Book not found", responseCode = "404")
+            }
+    )
+    public Response updateBook(@PathParam("id") Long id, Book book) {
+        return super.updateBook(id, book);
+    }
+
+    @Operation(
+            summary = "Create a book with validation",
+            description = "Post operation with entity in body and validation",
+            responses = {
+                @ApiResponse(description = "Book created", responseCode = "201"),
+                @ApiResponse(description = "Validation failed", responseCode = "400")
+            }
+    )
+    public Response createBookValidate(Book book) {
+        return super.createBookValidate(book);
+    }
+
+
+    @Operation(
+            summary = "Create new book",
+            description = "Post operation with entity in body",
+            responses = {
+                @ApiResponse(description = "Book created", responseCode = "201"),
+                @ApiResponse(description = "Book with given ID already exists", responseCode = "409")
+            }
+    )
+    public Response createBook(Book book) {
+        return super.createBook(book);
+    }
+
+    @Operation(
+            summary = "Delete a book",
+            description = "Delete operation with path param",
+            responses = {
+                @ApiResponse(description = "Book deleted", responseCode = "200"),
+                @ApiResponse(description = "Book not found", responseCode = "404")
+            }
+    )
+    @DELETE
+    @Path("/books/{id}")
+    public Response removeBook(@PathParam("id") Long id) {
+        return super.removeBook(id);
+    }
+}
+
+
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiServiceTest.java
similarity index 65%
copy from osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
copy to osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiServiceTest.java
index 2e6bc1f89f..7879305deb 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiServiceTest.java
@@ -19,17 +19,16 @@
 package org.apache.cxf.osgi.itests.jaxrs;
 
 import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 import jakarta.ws.rs.client.ClientBuilder;
-import jakarta.ws.rs.client.Entity;
 import jakarta.ws.rs.client.WebTarget;
 import jakarta.ws.rs.core.Response;
 import jakarta.ws.rs.core.Response.Status;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
-
 import org.apache.cxf.helpers.JavaUtils;
 import org.apache.cxf.osgi.itests.AbstractServerActivator;
 import org.apache.cxf.osgi.itests.CXFOSGiTestSupport;
@@ -47,7 +46,6 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
@@ -58,81 +56,21 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
-public class JaxRsServiceTest extends CXFOSGiTestSupport {
+public class OpenApiServiceTest extends CXFOSGiTestSupport {
 
     private static final String BASE_URL = "http://localhost:" + PORT + "/cxf/jaxrs/";
-    private static final String BOOKSTORE_PATH = "bookstore";
     private static final String SWAGGER_PATH = "api-docs";
     private static final String OPEN_API_FILE_PATH = "openapi.json";
 
-    private final WebTarget wt = ClientBuilder
-        .newClient()
-        .register(JacksonJsonProvider.class)
-        .target(BASE_URL);
-
-    @Test
-    public void testJaxRsGet() throws Exception {
-        Book book = wt.path(BOOKSTORE_PATH)
-            .path("/books/123")
-            .request("application/xml")
-            .get(Book.class);
-        assertNotNull(book);
-    }
-
-    @Test
-    public void testJaxRsPost() throws Exception {
-        Book book = new Book("New Book", 321);
-        Response response = wt.path(BOOKSTORE_PATH)
-            .path("/books/")
-            .request("application/xml")
-            .post(Entity.xml(book));
-        assertStatus(Status.CREATED, response);
-        assertNotNull(response.getLocation());
-    }
-    
-    @Test
-    public void postWithValidationError() throws Exception {
-        Book book = new Book(null, -1);
-        final Response response = wt.path(BOOKSTORE_PATH)
-            .path("/books-validate/")
-            .request("application/xml")
-            .post(Entity.xml(book));
-        assertStatus(Status.BAD_REQUEST, response);
-    }
-
-    @Test
-    public void postWithValidation() throws Exception {
-        Book book = new Book("A Book", 3212);
-        Response response = wt.path(BOOKSTORE_PATH)
-            .path("/books-validate/")
-            .request("application/xml")
-            .post(Entity.xml(book));
-        assertStatus(Status.CREATED, response);
-        assertNotNull(response.getLocation());
-    }
-
-    @Test
-    public void testJaxRsDelete() throws Exception {
-        Response response = wt.path(BOOKSTORE_PATH)
-            .path("/books/123")
-            .request("application/xml")
-            .delete();
-        assertStatus(Status.OK, response);
-    }
-
-    @Test
-    public void testJaxRsPut() throws Exception {
-        Book book = new Book("Updated Book", 123);
-        Response response = wt.path(BOOKSTORE_PATH)
-            .path("/books/123")
-            .request("application/xml")
-            .put(Entity.xml(book));
-        assertStatus(Status.OK, response);
-    }
+    private final WebTarget wt = ClientBuilder.newClient().target(BASE_URL);
 
     @Test
     public void testGetSwaggerUi() {
         WebTarget swaggerWt = wt.path(SWAGGER_PATH).queryParam("url", "/cxf/jaxrs/openapi.json");
+        
+        // It may take some time for all bundles to start and get activated
+        await(5, TimeUnit.SECONDS, () -> swaggerWt.request().head().getStatus() == 200);
+        
         Response response = swaggerWt.request().get();
         String swaggerFileHtml = response.readEntity(String.class);
 
@@ -146,6 +84,10 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
     @Test
     public void testGetOpenApiJsonFile() {
         WebTarget openApiWt = wt.path(OPEN_API_FILE_PATH);
+        
+        // It may take some time for all bundles to start and get activated
+        await(5, TimeUnit.SECONDS, () -> openApiWt.request().head().getStatus() == 200);
+
         Response response = openApiWt.request().get();
         String openApiJson = response.readEntity(String.class);
 
@@ -179,20 +121,41 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
         if (JavaUtils.isJava11Compatible()) {
             return TinyBundles.bundle()
                   .add(AbstractServerActivator.class)
-                  .add(JaxRsTestActivator.class)
+                  .add(OpenApiTestActivator.class)
                   .add(Book.class)
                   .add(BookStore.class)
-                  .set(Constants.BUNDLE_ACTIVATOR, JaxRsTestActivator.class.getName())
+                  .add(OpenApiBookStore.class)
+                  .set(Constants.BUNDLE_ACTIVATOR, OpenApiTestActivator.class.getName())
                   .set("Require-Capability", "osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=11))\"")
                   .build(TinyBundles.withBnd());
         } else {
             return TinyBundles.bundle()
                 .add(AbstractServerActivator.class)
-                .add(JaxRsTestActivator.class)
+                .add(OpenApiTestActivator.class)
                 .add(Book.class)
                 .add(BookStore.class)
-                .set(Constants.BUNDLE_ACTIVATOR, JaxRsTestActivator.class.getName())
+                .add(OpenApiBookStore.class)
+                .set(Constants.BUNDLE_ACTIVATOR, OpenApiTestActivator.class.getName())
                 .build(TinyBundles.withBnd());
         }
     }
+    
+    private static void await(int timeout, TimeUnit unit, Supplier<Boolean> condition) {
+        final int periods = 10;
+        final long millis = Math.max(1, unit.toMillis(timeout) / periods);
+        
+        for (int i = 0; i < periods; ++i) {
+            if (condition.get()) {
+                return;
+            }
+            
+            try {
+                Thread.sleep(millis);
+            } catch (InterruptedException e) {
+                break;
+            }
+        }
+        
+        fail("Waited at most " + unit.toMillis(timeout) + "ms, but condition was not met");
+    }
 }
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiTestActivator.java
similarity index 89%
copy from osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
copy to osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiTestActivator.java
index b7176ba039..aafc17fe39 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/OpenApiTestActivator.java
@@ -26,15 +26,15 @@ import org.apache.cxf.jaxrs.openapi.OpenApiFeature;
 import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiConfig;
 import org.apache.cxf.osgi.itests.AbstractServerActivator;
 
-public class JaxRsTestActivator extends AbstractServerActivator {
+public class OpenApiTestActivator extends AbstractServerActivator {
 
     @Override
     protected Server createServer() {
         Bus bus = BusFactory.newInstance().createBus();
-        bus.setExtension(JaxRsTestActivator.class.getClassLoader(), ClassLoader.class);
+        bus.setExtension(OpenApiTestActivator.class.getClassLoader(), ClassLoader.class);
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setBus(bus);
-        sf.setResourceClasses(BookStore.class);
+        sf.setResourceClasses(OpenApiBookStore.class);
 
         OpenApiFeature openApiFeature = new OpenApiFeature();
         openApiFeature.setScan(false);


[cxf] 01/04: CXF-8750: only add trailing slash if necessary when locating webjars … (#982)

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

commit 9a9d8da3eadb36ac32716988e28db544980c8e64
Author: Aleksy Wróblewski <34...@users.noreply.github.com>
AuthorDate: Sun Aug 14 19:13:14 2022 +0200

    CXF-8750: only add trailing slash if necessary when locating webjars … (#982)
    
    * CXF-8750: only add trailing slash if necessary when locating webjars resources for Swagger UI in OSGi environment
    
    * CXF-8750: read response body directly via Response.getEntity
    
    Co-authored-by: Aleksy Wróblewski <al...@bbbit.io>
---
 osgi/itests/pom.xml                                |  9 ++++
 .../apache/cxf/osgi/itests/jaxrs/BookStore.java    | 48 ++++++++++++++++++++++
 .../cxf/osgi/itests/jaxrs/JaxRsServiceTest.java    | 47 +++++++++++++++++++--
 .../cxf/osgi/itests/jaxrs/JaxRsTestActivator.java  | 11 ++++-
 .../jaxrs/swagger/ui/OsgiSwaggerUiResolver.java    |  4 +-
 5 files changed, 114 insertions(+), 5 deletions(-)

diff --git a/osgi/itests/pom.xml b/osgi/itests/pom.xml
index 836b2fc470..037c9332ba 100644
--- a/osgi/itests/pom.xml
+++ b/osgi/itests/pom.xml
@@ -56,10 +56,19 @@
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-transports-jms</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-service-description-openapi-v3</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.activemq</groupId>
             <artifactId>artemis-jakarta-client</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.webjars</groupId>
+            <artifactId>swagger-ui</artifactId>
+            <version>${cxf.swagger.ui.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.karaf</groupId>
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
index ea86895815..1e2f735325 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
@@ -49,7 +49,14 @@ import org.apache.cxf.validation.BeanValidationProvider;
 import org.hibernate.validator.HibernateValidator;
 import org.hibernate.validator.HibernateValidatorConfiguration;
 
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
 @Path("/bookstore")
+@Tag(name = "BookStore")
 @Produces("application/xml")
 public class BookStore {
     private Map<Long, Book> books = new HashMap<>();
@@ -72,6 +79,15 @@ public class BookStore {
 
     @GET
     @Path("/books/{id}")
+    @Operation(
+            summary = "Get book by ID",
+            description = "Get operation with path parameter",
+            responses = {
+                @ApiResponse(content = @Content(schema = @Schema(implementation = Book.class)),
+                    description = "Book found", responseCode = "200"),
+                @ApiResponse(description = "Book not found", responseCode = "404")
+            }
+    )
     public Response getBookRoot(@PathParam("id") Long id) {
         assertInjections();
         Book b = books.get(id);
@@ -81,6 +97,14 @@ public class BookStore {
         return Response.ok(b).build();
     }
 
+    @Operation(
+            summary = "Update book by ID",
+            description = "Put operation with path parameter",
+            responses = {
+                @ApiResponse(description = "Book found and updated", responseCode = "200"),
+                @ApiResponse(description = "Book not found", responseCode = "404")
+            }
+    )
     @PUT
     @Path("/books/{id}")
     public Response updateBook(@PathParam("id") Long id, Book book) {
@@ -93,6 +117,14 @@ public class BookStore {
         return Response.ok().build();
     }
 
+    @Operation(
+            summary = "Create a book with validation",
+            description = "Post operation with entity in body and validation",
+            responses = {
+                @ApiResponse(description = "Book created", responseCode = "201"),
+                @ApiResponse(description = "Validation failed", responseCode = "400")
+            }
+    )
     @POST
     @Path("/books-validate")
     public Response createBookValidate(Book book) {
@@ -123,6 +155,14 @@ public class BookStore {
     }
 
 
+    @Operation(
+            summary = "Create new book",
+            description = "Post operation with entity in body",
+            responses = {
+                @ApiResponse(description = "Book created", responseCode = "201"),
+                @ApiResponse(description = "Book with given ID already exists", responseCode = "409")
+            }
+    )
     @POST
     @Path("/books")
     public Response createBook(Book book) {
@@ -137,6 +177,14 @@ public class BookStore {
         return Response.created(createdURI).build();
     }
 
+    @Operation(
+            summary = "Delete a book",
+            description = "Delete operation with path param",
+            responses = {
+                @ApiResponse(description = "Book deleted", responseCode = "200"),
+                @ApiResponse(description = "Book not found", responseCode = "404")
+            }
+    )
     @DELETE
     @Path("/books/{id}")
     public Response removeBook(@PathParam("id") Long id) {
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
index 3243efa4b3..5b1aa5bd12 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
@@ -25,6 +25,10 @@ import jakarta.ws.rs.client.Entity;
 import jakarta.ws.rs.client.WebTarget;
 import jakarta.ws.rs.core.Response;
 import jakarta.ws.rs.core.Response.Status;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 import org.apache.cxf.helpers.JavaUtils;
 import org.apache.cxf.osgi.itests.AbstractServerActivator;
 import org.apache.cxf.osgi.itests.CXFOSGiTestSupport;
@@ -43,6 +47,9 @@ import org.ops4j.pax.tinybundles.core.TinyBundles;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
@@ -52,9 +59,12 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
 @ExamReactorStrategy(PerClass.class)
 public class JaxRsServiceTest extends CXFOSGiTestSupport {
 
-    private static final String BASE_URL = "http://localhost:" + PORT + "/cxf/jaxrs/bookstore";
+    private static final String BASE_URL = "http://localhost:" + PORT + "/cxf/jaxrs/";
+    private static final String BOOKSTORE_URL = BASE_URL + "bookstore";
+    private static final String SWAGGER_URL = BASE_URL + "api-docs";
+    private static final String OPEN_API_FILE_URL = BASE_URL + "openapi.json";
 
-    private final WebTarget wt = ClientBuilder.newClient().target(BASE_URL);
+    private final WebTarget wt = ClientBuilder.newClient().target(BOOKSTORE_URL);
 
     @Test
     public void testJaxRsGet() throws Exception {
@@ -98,6 +108,35 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
         assertStatus(Status.OK, response);
     }
 
+    @Test
+    public void testGetSwaggerUi() {
+        WebTarget swaggerWt = ClientBuilder.newClient().target(SWAGGER_URL)
+                .queryParam("url", "/cxf/jaxrs/openapi.json");
+        Response response = swaggerWt.request().get();
+        String swaggerFileHtml = response.readEntity(String.class);
+
+        assertStatus(Status.OK, response);
+        assertTrue(swaggerFileHtml.contains("<html"));
+        assertTrue(swaggerFileHtml.contains("<head>"));
+        assertTrue(swaggerFileHtml.contains("<title>Swagger UI</title>"));
+        assertTrue(swaggerFileHtml.contains("</html>"));
+    }
+
+    @Test
+    public void testGetOpenApiJsonFile() {
+        WebTarget openApiWt = ClientBuilder.newClient().target(OPEN_API_FILE_URL);
+        Response response = openApiWt.request().get();
+        String openApiJson = response.readEntity(String.class);
+
+        assertStatus(Status.OK, response);
+        try {
+            new ObjectMapper().readValue(openApiJson, Object.class);
+            assertTrue(openApiJson.contains("/bookstore/"));
+        } catch (JsonProcessingException e) {
+            fail();
+        }
+    }
+
     private static void assertStatus(Status expectedStatus, Response response) {
         assertEquals(expectedStatus.getStatusCode(), response.getStatus());
     }
@@ -106,7 +145,9 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
     public Option[] config() {
         return OptionUtils.combine(
             cxfBaseConfig(),
-            features(cxfUrl, "cxf-core", "cxf-wsdl", "cxf-jaxrs", "cxf-bean-validation-core", "cxf-bean-validation"),
+            features(cxfUrl, "cxf-core", "cxf-wsdl", "cxf-jaxrs", "cxf-bean-validation-core", "cxf-bean-validation",
+                    "cxf-rs-description-openapi-v3"),
+            mavenBundle("org.webjars", "swagger-ui").versionAsInProject(),
             logLevel(LogLevel.INFO),
             testUtils(),
             provision(serviceBundle())
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
index 4a28390f21..5e9238c09f 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
@@ -22,6 +22,8 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.openapi.OpenApiFeature;
+import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiConfig;
 import org.apache.cxf.osgi.itests.AbstractServerActivator;
 
 public class JaxRsTestActivator extends AbstractServerActivator {
@@ -33,8 +35,15 @@ public class JaxRsTestActivator extends AbstractServerActivator {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setBus(bus);
         sf.setResourceClasses(BookStore.class);
+        OpenApiFeature openApiFeature = new OpenApiFeature();
+        openApiFeature.setScan(false);
+        openApiFeature.setUseContextBasedConfig(true);
+        SwaggerUiConfig swaggerUiConfig = new SwaggerUiConfig();
+        swaggerUiConfig.setUrl("/cxf/jaxrs/openapi.json");
+        openApiFeature.setSwaggerUiConfig(swaggerUiConfig);
+
+        sf.getFeatures().add(openApiFeature);
         sf.setAddress("/jaxrs");
         return sf.create();
     }
-
 }
diff --git a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/ui/OsgiSwaggerUiResolver.java b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/ui/OsgiSwaggerUiResolver.java
index efb0456559..c494beea4b 100644
--- a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/ui/OsgiSwaggerUiResolver.java
+++ b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/ui/OsgiSwaggerUiResolver.java
@@ -88,7 +88,9 @@ public class OsgiSwaggerUiResolver extends SwaggerUiResolver {
         }
         URL entry = b.getEntry(SwaggerUiResolver.UI_RESOURCES_ROOT_START + swaggerUiVersion);
         if (entry != null) {
-            return entry.toString() + "/";
+            String entryAsString = entry.toString();
+            // add the trailing slash if it is missing, it depends on OSGi version/implementation
+            return entryAsString.endsWith("/") ? entryAsString : entryAsString + "/";
         }
         return null;
     }


[cxf] 02/04: Refactored JaxRsServiceTest to use single WebTarget instance

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

commit 6feef17508ced2a58f1bea07ab11264bd615e7fc
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sun Aug 14 15:23:38 2022 -0400

    Refactored JaxRsServiceTest to use single WebTarget instance
---
 .../cxf/osgi/itests/jaxrs/JaxRsServiceTest.java    | 43 +++++++++++++++-------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
index 5b1aa5bd12..6d50a9287f 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
@@ -60,22 +60,28 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
 public class JaxRsServiceTest extends CXFOSGiTestSupport {
 
     private static final String BASE_URL = "http://localhost:" + PORT + "/cxf/jaxrs/";
-    private static final String BOOKSTORE_URL = BASE_URL + "bookstore";
-    private static final String SWAGGER_URL = BASE_URL + "api-docs";
-    private static final String OPEN_API_FILE_URL = BASE_URL + "openapi.json";
+    private static final String BOOKSTORE_PATH = "bookstore";
+    private static final String SWAGGER_PATH = "api-docs";
+    private static final String OPEN_API_FILE_PATH = "openapi.json";
 
-    private final WebTarget wt = ClientBuilder.newClient().target(BOOKSTORE_URL);
+    private final WebTarget wt = ClientBuilder.newClient().target(BASE_URL);
 
     @Test
     public void testJaxRsGet() throws Exception {
-        Book book = wt.path("/books/123").request("application/xml").get(Book.class);
+        Book book = wt.path(BOOKSTORE_PATH)
+            .path("/books/123")
+            .request("application/xml")
+            .get(Book.class);
         assertNotNull(book);
     }
 
     @Test
     public void testJaxRsPost() throws Exception {
         Book book = new Book("New Book", 321);
-        Response response = wt.path("/books/").request("application/xml").post(Entity.xml(book));
+        Response response = wt.path(BOOKSTORE_PATH)
+            .path("/books/")
+            .request("application/xml")
+            .post(Entity.xml(book));
         assertStatus(Status.CREATED, response);
         assertNotNull(response.getLocation());
     }
@@ -83,35 +89,46 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
     @Test
     public void postWithValidationError() throws Exception {
         Book book = new Book(null, -1);
-        Response response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
+        final Response response = wt.path(BOOKSTORE_PATH)
+            .path("/books-validate/")
+            .request("application/xml")
+            .post(Entity.xml(book));
         assertStatus(Status.BAD_REQUEST, response);
     }
 
     @Test
     public void postWithValidation() throws Exception {
         Book book = new Book("A Book", 3212);
-        Response response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
+        Response response = wt.path(BOOKSTORE_PATH)
+            .path("/books-validate/")
+            .request("application/xml")
+            .post(Entity.xml(book));
         assertStatus(Status.CREATED, response);
         assertNotNull(response.getLocation());
     }
 
     @Test
     public void testJaxRsDelete() throws Exception {
-        Response response = wt.path("/books/123").request("application/xml").delete();
+        Response response = wt.path(BOOKSTORE_PATH)
+            .path("/books/123")
+            .request("application/xml")
+            .delete();
         assertStatus(Status.OK, response);
     }
 
     @Test
     public void testJaxRsPut() throws Exception {
         Book book = new Book("Updated Book", 123);
-        Response response = wt.path("/books/123").request("application/xml").put(Entity.xml(book));
+        Response response = wt.path(BOOKSTORE_PATH)
+            .path("/books/123")
+            .request("application/xml")
+            .put(Entity.xml(book));
         assertStatus(Status.OK, response);
     }
 
     @Test
     public void testGetSwaggerUi() {
-        WebTarget swaggerWt = ClientBuilder.newClient().target(SWAGGER_URL)
-                .queryParam("url", "/cxf/jaxrs/openapi.json");
+        WebTarget swaggerWt = wt.path(SWAGGER_PATH).queryParam("url", "/cxf/jaxrs/openapi.json");
         Response response = swaggerWt.request().get();
         String swaggerFileHtml = response.readEntity(String.class);
 
@@ -124,7 +141,7 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
 
     @Test
     public void testGetOpenApiJsonFile() {
-        WebTarget openApiWt = ClientBuilder.newClient().target(OPEN_API_FILE_URL);
+        WebTarget openApiWt = wt.path(OPEN_API_FILE_PATH);
         Response response = openApiWt.request().get();
         String openApiJson = response.readEntity(String.class);
 


[cxf] 03/04: Attempt to fix flaky JaxRsServiceTest tests (CXF-8750 post merge) (#984)

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

commit 3cb40236220b940573961a0607f9c6258589f54d
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Mon Aug 15 22:29:19 2022 -0400

    Attempt to fix flaky JaxRsServiceTest tests (CXF-8750 post merge) (#984)
---
 .../java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java     | 6 +++++-
 .../java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java   | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
index 6d50a9287f..2e6bc1f89f 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
@@ -28,6 +28,7 @@ import jakarta.ws.rs.core.Response.Status;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
 import org.apache.cxf.helpers.JavaUtils;
 import org.apache.cxf.osgi.itests.AbstractServerActivator;
@@ -64,7 +65,10 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
     private static final String SWAGGER_PATH = "api-docs";
     private static final String OPEN_API_FILE_PATH = "openapi.json";
 
-    private final WebTarget wt = ClientBuilder.newClient().target(BASE_URL);
+    private final WebTarget wt = ClientBuilder
+        .newClient()
+        .register(JacksonJsonProvider.class)
+        .target(BASE_URL);
 
     @Test
     public void testJaxRsGet() throws Exception {
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
index 5e9238c09f..b7176ba039 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
@@ -35,9 +35,9 @@ public class JaxRsTestActivator extends AbstractServerActivator {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setBus(bus);
         sf.setResourceClasses(BookStore.class);
+
         OpenApiFeature openApiFeature = new OpenApiFeature();
         openApiFeature.setScan(false);
-        openApiFeature.setUseContextBasedConfig(true);
         SwaggerUiConfig swaggerUiConfig = new SwaggerUiConfig();
         swaggerUiConfig.setUrl("/cxf/jaxrs/openapi.json");
         openApiFeature.setSwaggerUiConfig(swaggerUiConfig);