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 7995e767abd Add a few test cases with records serialization /
deserialization (#3595)
7995e767abd is described below
commit 7995e767abd3288d5099f7de8692450b831ee257
Author: Andriy Redko <[email protected]>
AuthorDate: Sat Oct 17 19:39:53 2026 -0400
Add a few test cases with records serialization / deserialization (#3595)
---
.../provider/jsrjsonb/JsrJsonbProviderTest.java | 15 ++-
.../org/apache/cxf/jaxrs/resources/BookRecord.java | 28 +++++
.../org/apache/cxf/systest/jaxrs/BookRecord.java | 38 ++++++
.../jaxrs/JAXRSClientServerBookRecordTest.java | 132 +++++++++++++++++++++
4 files changed, 212 insertions(+), 1 deletion(-)
diff --git
a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsrjsonb/JsrJsonbProviderTest.java
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsrjsonb/JsrJsonbProviderTest.java
index a382122897c..40a653d97f7 100644
---
a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsrjsonb/JsrJsonbProviderTest.java
+++
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsrjsonb/JsrJsonbProviderTest.java
@@ -31,6 +31,7 @@ import java.util.List;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.jaxrs.resources.BookRecord;
import org.apache.cxf.jaxrs.resources.CollectionsResource;
import org.junit.Before;
@@ -93,7 +94,19 @@ public class JsrJsonbProviderTest {
assertThat(book.getId(), equalTo(1L));
assertThat(book.getName(), equalTo("CXF 1"));
}
-
+
+ @Test
+ public void testReadBookRecord() throws Exception {
+ String input = "{"
+ + "\"id\":1,"
+ + "\"name\":\"CXF 1\""
+ + "}";
+
+ final BookRecord book = read(BookRecord.class, input.getBytes());
+ assertThat(book.id(), equalTo(1L));
+ assertThat(book.name(), equalTo("CXF 1"));
+ }
+
@Test
public void testWriteListOfBooks() throws Exception {
final List<Book> books = new ArrayList<>();
diff --git
a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/BookRecord.java
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/BookRecord.java
new file mode 100644
index 00000000000..07aa97493cf
--- /dev/null
+++
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/BookRecord.java
@@ -0,0 +1,28 @@
+/**
+ * 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.jaxrs.resources;
+
+import jakarta.xml.bind.annotation.XmlRootElement;
+import jakarta.xml.bind.annotation.XmlSeeAlso;
+
+@XmlRootElement(name = "Book")
+@XmlSeeAlso({SuperBook.class })
+public record BookRecord(String name, long id) {
+}
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookRecord.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookRecord.java
new file mode 100644
index 00000000000..048e16a8f84
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookRecord.java
@@ -0,0 +1,38 @@
+/**
+ * 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.systest.jaxrs;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
+
+import jakarta.ws.rs.GET;
+import jakarta.xml.bind.annotation.XmlRootElement;
+import jakarta.xml.bind.annotation.XmlSeeAlso;
+
+@JsonTypeInfo(use = Id.CLASS, include = As.PROPERTY, property = "class")
+@XmlRootElement(name = "Book")
+@XmlSeeAlso(SuperBook.class)
+public record BookRecord(String name, long id) {
+ @GET
+ public BookRecord retrieveState() {
+ return this;
+ }
+}
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookRecordTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookRecordTest.java
new file mode 100644
index 00000000000..ce3d91c8c74
--- /dev/null
+++
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookRecordTest.java
@@ -0,0 +1,132 @@
+/**
+ * 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.systest.jaxrs;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.concurrent.ThreadLocalRandom;
+
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.UriBuilder;
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractServerTestServerBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
+import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
+
+public class JAXRSClientServerBookRecordTest extends
AbstractBusClientServerTestBase {
+ public static final String PORT = BookRecordServer.PORT;
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ assertTrue("server did not launch correctly",
launchServer(BookRecordServer.class, true));
+ }
+
+ @Test
+ public final void postBook() throws URISyntaxException {
+ final String origin = String.format("Origin(%d)",
ThreadLocalRandom.current().nextInt(1000));
+ try (Client client = ClientBuilder
+ .newBuilder()
+ .build()) {
+
+ final BookRecord book = new BookRecord(origin, 1L);
+
+ final URI effectiveUri = UriBuilder
+ .fromUri("http://localhost:" + PORT + "/")
+ .path("bookstore")
+ .build();
+
+ final BookRecord response = client
+ .target(effectiveUri)
+ .request(APPLICATION_JSON_TYPE)
+ .buildPost(Entity.entity(book, APPLICATION_JSON_TYPE))
+ .invoke(BookRecord.class);
+
+ assertThat(response.name(), is(origin + ",BookResource"));
+ }
+ }
+
+ @Test
+ public final void getBook() throws URISyntaxException {
+ try (Client client = ClientBuilder
+ .newBuilder()
+ .build()) {
+
+ final URI effectiveUri = UriBuilder
+ .fromUri("http://localhost:" + PORT + "/")
+ .path("bookstore/sub")
+ .build();
+
+ final BookRecord response = client
+ .target(effectiveUri)
+ .request(APPLICATION_JSON_TYPE)
+ .buildGet()
+ .invoke(BookRecord.class);
+
+ assertThat(response.name(), is("BookResourceSub"));
+ }
+ }
+
+ public static final class BookRecordServer extends
AbstractServerTestServerBase {
+ public static final String PORT = allocatePort(BookRecordServer.class);
+
+ @Override
+ protected Server createServer(Bus bus) throws Exception {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setResourceClasses(BookStoreResource.class);
+ sf.setAddress("http://localhost:" + PORT + "/");
+ return sf.create();
+ }
+
+ public static void main(String[] args) throws Exception {
+ new BookRecordServer().start();
+ }
+ }
+
+ @Path("/bookstore")
+ public static class BookStoreResource {
+ @POST
+ @Consumes(APPLICATION_JSON)
+ @Produces(APPLICATION_JSON)
+ public BookRecord echo(final BookRecord book) {
+ return new BookRecord(String.join(",", book.name(),
"BookResource"), book.id());
+ }
+
+ @Path("/sub")
+ public BookRecord getBookRecord() {
+ return new BookRecord("BookResourceSub", 1L);
+ }
+ }
+}