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/10/30 15:00:22 UTC

[cxf] branch main updated: Added more test for using factory methods as parameter converters (#1004)

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 c378cb2326 Added more test for using factory methods as parameter converters (#1004)
c378cb2326 is described below

commit c378cb2326dde28f0c86e130791f31622b054c89
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sun Oct 30 10:42:49 2022 -0400

    Added more test for using factory methods as parameter converters (#1004)
---
 .../apache/cxf/jaxrs/utils/InjectionUtilsTest.java | 31 ++++++++++++++++++++++
 .../org/apache/cxf/systest/jaxrs/BookStore.java    | 29 ++++++++++++++++++++
 .../cxf/systest/jaxrs/JAXRSLocalTransportTest.java | 24 +++++++++++++++++
 3 files changed, 84 insertions(+)

diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
index be01b62198..16ed50613e 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.UUID;
 
 import jakarta.validation.constraints.NotNull;
 import jakarta.ws.rs.InternalServerErrorException;
@@ -158,6 +159,14 @@ public class InjectionUtilsTest {
         assertEquals("Type is wrong", CarType.AUDI, carType);
     }
 
+    @Test
+    public void testInstantiateClass() {
+        HelmId helmId = InjectionUtils.handleParameter("a6f7357f-6e7e-40e5-9b4a-c455c23b10a2", false, HelmId.class,
+                                                         HelmId.class, null,
+                                                         ParameterType.QUERY, null);
+        assertEquals("Type is wrong", "a6f7357f-6e7e-40e5-9b4a-c455c23b10a2", helmId.getId());
+    }
+
     @Test
     public void testInstantiateIntegerInQuery() {
         Integer integer = InjectionUtils.handleParameter("", false, Integer.class,
@@ -379,4 +388,26 @@ public class InjectionUtilsTest {
             this.birthDate = birthDate;
         }
     }
+
+    private abstract static class AbstractHelmId {
+        public static HelmId fromString(String id) {
+            return HelmId.of(UUID.fromString(id));
+        }
+    }
+
+    private static final class HelmId extends AbstractHelmId {
+        private final UUID uuid;
+
+        private HelmId(UUID uuid) {
+            this.uuid = uuid;
+        }
+
+        public String getId() {
+            return uuid.toString();
+        }
+
+        public static HelmId of(UUID uuid) {
+            return new HelmId(uuid);
+        }
+    }
 }
\ No newline at end of file
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index 0478f0061e..17eb487222 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -37,6 +37,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.UUID;
 
 import javax.xml.namespace.QName;
 import javax.xml.transform.dom.DOMSource;
@@ -660,6 +661,13 @@ public class BookStore {
     public boolean checkBook(@PathParam("id") Long id) {
         return books.containsKey(id);
     }
+    
+    @GET
+    @Path("books/check/uuid/{uuid}")
+    @Produces("text/plain,text/boolean")
+    public boolean checkBookUuid(@PathParam("uuid") BookId id) {
+        return books.containsKey(id.getId());
+    }
 
     @GET
     @Path("books/check/malformedmt/{id}")
@@ -2309,6 +2317,27 @@ public class BookStore {
         }
     }
 
+    public abstract static class AbstractBookId {
+        public static BookId fromString(String id) {
+            return BookId.of(UUID.fromString(id));
+        }
+    }
+
+    public static final class BookId extends AbstractBookId {
+        private final UUID uuid;
+
+        private BookId(UUID uuid) {
+            this.uuid = uuid;
+        }
+
+        public long getId() {
+            return uuid.getMostSignificantBits();
+        }
+
+        public static BookId of(UUID uuid) {
+            return new BookId(uuid);
+        }
+    }
 }
 
 
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
index 51b94ad3dc..4feedaefec 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
@@ -45,8 +45,10 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public class JAXRSLocalTransportTest extends AbstractBusClientServerTestBase {
@@ -206,6 +208,28 @@ public class JAXRSLocalTransportTest extends AbstractBusClientServerTestBase {
         assertEquals(123L, book.getId());
     }
 
+    
+    @Test
+    public void testWebClientDirectDispatchBookId() throws Exception {
+        WebClient localClient = WebClient.create("local://books");
+        localClient.accept("text/plain");
+
+        WebClient.getConfig(localClient).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
+        localClient.path("bookstore/books/check/uuid/a6f7357f-6e7e-40e5-9b4a-c455c23b10a2");
+        boolean hasBook = localClient.get(boolean.class);
+        assertThat(hasBook, equalTo(false));
+    }
+    
+    @Test
+    public void testWebClientPipedDispatchBookId() throws Exception {
+        WebClient localClient = WebClient.create("local://books");
+        localClient.accept("text/plain");
+
+        localClient.path("bookstore/books/check/uuid/a6f7357f-6e7e-40e5-9b4a-c455c23b10a2");
+        boolean hasBook = localClient.get(boolean.class);
+        assertThat(hasBook, equalTo(false));
+    }
+
     @Test
     public void testWebClientDirectDispatchBookType() throws Exception {
         WebClient localClient = WebClient.create("local://books",