Skip to content

Commit

Permalink
Test JAXB serializing javax.xml.datatype.XMLGregorianCalendar #1133
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Dec 25, 2023
1 parent cfffe21 commit a96e52a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

import javax.xml.datatype.XMLGregorianCalendar;

import jakarta.jws.WebMethod;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
Expand All @@ -25,6 +27,9 @@ public interface DateService {
@WebMethod
Calendar calendarAdd(Calendar base, int days);

@WebMethod
XMLGregorianCalendar xmlGregorianCalendarAdd(XMLGregorianCalendar base, int days);

@WebMethod
@RequestWrapper(className = "io.quarkiverse.cxf.it.server.DateService$DateTimeRequest")
@ResponseWrapper(className = "io.quarkiverse.cxf.it.server.DateService$DateTimeResponse")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.time.temporal.ChronoUnit;
import java.util.Calendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import jakarta.jws.WebService;

/**
Expand All @@ -19,6 +23,17 @@ public Calendar calendarAdd(Calendar base, int days) {
return result;
}

@Override
public XMLGregorianCalendar xmlGregorianCalendarAdd(XMLGregorianCalendar base, int days) {
XMLGregorianCalendar result = (XMLGregorianCalendar) base.clone();
try {
result.add(DatatypeFactory.newInstance().newDuration(true, 0, 0, days, 0, 0, 0));
return result;
} catch (DatatypeConfigurationException e) {
throw new RuntimeException(e);
}
}

@Override
public LocalDateTime localDateTimeAdd(LocalDateTime base, int days) {
return base.plus(days, ChronoUnit.DAYS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Locale;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -31,6 +36,18 @@ public void calendarAdd() {
Assertions.assertThat(result.getTimeInMillis()).isEqualTo(1000L * 60 * 60 * 24);
}

@Test
public void xmlGregorianCalendarAdd() throws DatatypeConfigurationException {
final DateService dateService = QuarkusCxfClientTestUtil.getClient(DateService.class, "/soap/date");
final LocalDateTime b = LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC);
final XMLGregorianCalendar base = DatatypeFactory.newInstance()
.newXMLGregorianCalendar(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(b));
final XMLGregorianCalendar actual = dateService.xmlGregorianCalendarAdd(base, 1);
final XMLGregorianCalendar expected = DatatypeFactory.newInstance()
.newXMLGregorianCalendar(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(b.plusDays(1)));
Assertions.assertThat(actual).isEqualTo(expected);
}

@Test
public void localDateTimeAdd() {
final DateService dateService = QuarkusCxfClientTestUtil.getClient(DateService.class, "/soap/date");
Expand Down

0 comments on commit a96e52a

Please sign in to comment.