This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.5.x-fixes by this push:
new 07ba522dfd Added more test for using factory methods as parameter
converters (#1004)
07ba522dfd is described below
commit 07ba522dfd4bd3483b46e98b7fabddfc23f74288
Author: Andriy Redko <[email protected]>
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 8a33325c2d..9b6877cc0b 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 javax.validation.constraints.NotNull;
import javax.ws.rs.InternalServerErrorException;
@@ -161,6 +162,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,
@@ -382,4 +391,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 87bd56a57f..67bd97f8fa 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.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@@ -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 ba5af20a5e..e36ec49d88 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
@@ -46,8 +46,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 {
@@ -207,6 +209,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",