diff --git a/iso20022-core/src/test/java/com/prowidesoftware/swift/model/mx/adapters/MxWriteWithAdaptersTest.java b/iso20022-core/src/test/java/com/prowidesoftware/swift/model/mx/adapters/MxWriteWithAdaptersTest.java index 18f6bc732..c71d5d494 100644 --- a/iso20022-core/src/test/java/com/prowidesoftware/swift/model/mx/adapters/MxWriteWithAdaptersTest.java +++ b/iso20022-core/src/test/java/com/prowidesoftware/swift/model/mx/adapters/MxWriteWithAdaptersTest.java @@ -25,9 +25,9 @@ import com.prowidesoftware.swift.model.mx.dic.SettlementTimeRequest2; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.time.OffsetDateTime; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.TimeZone; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; @@ -37,16 +37,14 @@ public class MxWriteWithAdaptersTest { @Test public void testDocumentDateTime_DefaultAdapters_noFractionalSecond() throws DatatypeConfigurationException { - XMLGregorianCalendar noFractionalSecond = DatatypeFactory.newInstance() - .newXMLGregorianCalendar(new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14)); + XMLGregorianCalendar noFractionalSecond = sampleGregorianCalendar(); MxPacs00800102 mx1 = sample(noFractionalSecond); final String xml = mx1.message(); // System.out.println(xml); - assertTrue(xml.contains( - "2021-10-19T12:13:14" + OffsetDateTime.now().getOffset() + "")); + assertTrue(xml.contains("2021-10-19T12:13:14+00:00")); assertTrue(xml.contains("2021-10-19")); - assertTrue(xml.contains("12:13:14" + OffsetDateTime.now().getOffset() + "")); + assertTrue(xml.contains("12:13:14+00:00")); final MxPacs00800102 mx2 = MxPacs00800102.parse(xml); // System.out.println(mx2.message()); @@ -88,9 +86,7 @@ public void testDocumentDateTime_DefaultAdapters_noFractionalSecond() throws Dat @Test public void testDocumentDateTime_DefaultAdapters_Z() throws DatatypeConfigurationException { - XMLGregorianCalendar utc = DatatypeFactory.newInstance() - .newXMLGregorianCalendar(new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14)); - utc.setTimezone(0); + XMLGregorianCalendar utc = sampleGregorianCalendar(); MxPacs00800102 mx1 = sample(utc); final String xml = mx1.message(); @@ -139,18 +135,15 @@ public void testDocumentDateTime_DefaultAdapters_Z() throws DatatypeConfiguratio @Test public void testDocumentDateTime_DefaultAdapters_fractionalSecond() throws DatatypeConfigurationException { - XMLGregorianCalendar fractionalSecond = DatatypeFactory.newInstance() - .newXMLGregorianCalendar(new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14)); + XMLGregorianCalendar fractionalSecond = sampleGregorianCalendar(); fractionalSecond.setFractionalSecond(new BigDecimal("0.123")); MxPacs00800102 mx1 = sample(fractionalSecond); final String xml = mx1.message(); // System.out.println(xml); - assertTrue(xml.contains( - "2021-10-19T12:13:14.123" + OffsetDateTime.now().getOffset() + "")); + assertTrue(xml.contains("2021-10-19T12:13:14.123+00:00")); assertTrue(xml.contains("2021-10-19")); - assertTrue( - xml.contains("12:13:14.123" + OffsetDateTime.now().getOffset() + "")); + assertTrue(xml.contains("12:13:14.123+00:00")); final MxPacs00800102 mx2 = MxPacs00800102.parse(xml); // System.out.println(mx2.message()); @@ -192,8 +185,8 @@ public void testDocumentDateTime_DefaultAdapters_fractionalSecond() throws Datat @Test public void testDocumentDateTime_CustomPattern() throws DatatypeConfigurationException { - XMLGregorianCalendar noFractionalSecond = DatatypeFactory.newInstance() - .newXMLGregorianCalendar(new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14)); + GregorianCalendar calendar = new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14); + XMLGregorianCalendar noFractionalSecond = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); MxPacs00800102 mx1 = sample(noFractionalSecond); MxWriteConfiguration conf = new MxWriteConfiguration(); @@ -242,8 +235,7 @@ public void testDocumentDateTime_CustomPattern() throws DatatypeConfigurationExc @Test public void testDocumentDateTime_CustomAdapter() throws DatatypeConfigurationException { - XMLGregorianCalendar noFractionalSecond = DatatypeFactory.newInstance() - .newXMLGregorianCalendar(new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14)); + XMLGregorianCalendar noFractionalSecond = sampleGregorianCalendar(); MxPacs00800102 mx1 = sample(noFractionalSecond); MxWriteConfiguration conf = new MxWriteConfiguration(); @@ -263,12 +255,14 @@ public void testDocumentDateTime_CustomAdapter() throws DatatypeConfigurationExc @Test public void testAppHdrDateTime_DefaultAdapters() throws DatatypeConfigurationException { - AppHdr h1 = header(); + XMLGregorianCalendar gregorianCalendar = sampleGregorianCalendar(); + BusinessAppHdrV02 h1 = + AppHdrFactory.createBusinessAppHdrV02("AAAAUSXXXXX", "BBBBUSXXXXX", "ref", new MxId("pacs.008.001.08")); + h1.setCreDt(gregorianCalendar); final String xml = h1.xml(); // System.out.println(xml); - assertTrue( - xml.contains("2021-10-19T12:13:14" + OffsetDateTime.now().getOffset() + "")); + assertTrue(xml.contains("2021-10-19T12:13:14+00:00")); final BusinessAppHdrV02 h2 = (BusinessAppHdrV02) AppHdrParser.parse(xml).get(); // System.out.println(mx2.message()); @@ -288,12 +282,9 @@ private MxPacs00800102 sample(final XMLGregorianCalendar cal) { return mx; } - private AppHdr header() throws DatatypeConfigurationException { - final XMLGregorianCalendar cal = DatatypeFactory.newInstance() - .newXMLGregorianCalendar(new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14)); - BusinessAppHdrV02 bah = - AppHdrFactory.createBusinessAppHdrV02("AAAAUSXXXXX", "BBBBUSXXXXX", "ref", new MxId("pacs.008.001.08")); - bah.setCreDt(cal); - return bah; + private XMLGregorianCalendar sampleGregorianCalendar() throws DatatypeConfigurationException { + GregorianCalendar calendar = new GregorianCalendar(2021, Calendar.OCTOBER, 19, 12, 13, 14); + calendar.setTimeZone(TimeZone.getTimeZone("UTC")); + return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); } }