summaryrefslogtreecommitdiffstats
path: root/src/org/uic/barcode/ticket
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-03-25 16:33:26 +0100
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-03-25 16:33:26 +0100
commit1eabc780b807daade9220e004a301a1c5969ef66 (patch)
tree3e14bb13b851d2228b765db0cb0191bb5e9e9403 /src/org/uic/barcode/ticket
parentversion 1.2.3 (diff)
downloadUIC-barcode-1eabc780b807daade9220e004a301a1c5969ef66.tar
UIC-barcode-1eabc780b807daade9220e004a301a1c5969ef66.tar.gz
UIC-barcode-1eabc780b807daade9220e004a301a1c5969ef66.tar.bz2
UIC-barcode-1eabc780b807daade9220e004a301a1c5969ef66.tar.lz
UIC-barcode-1eabc780b807daade9220e004a301a1c5969ef66.tar.xz
UIC-barcode-1eabc780b807daade9220e004a301a1c5969ef66.tar.zst
UIC-barcode-1eabc780b807daade9220e004a301a1c5969ef66.zip
Diffstat (limited to 'src/org/uic/barcode/ticket')
-rw-r--r--src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV1.java345
-rw-r--r--src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV1.java312
-rw-r--r--src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV2.java312
-rw-r--r--src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV1.java312
-rw-r--r--src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV2.java312
-rw-r--r--src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV1.java201
-rw-r--r--src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV2.java201
-rw-r--r--src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV1.java183
-rw-r--r--src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV2.java183
-rw-r--r--src/org/uic/barcode/ticket/api/utils/DateTimeUtils.java18
10 files changed, 2364 insertions, 15 deletions
diff --git a/src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV1.java b/src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV1.java
new file mode 100644
index 0000000..c9b0f31
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV1.java
@@ -0,0 +1,345 @@
+package org.uic.barcode.ticket.api.test;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
+import org.uic.barcode.ticket.api.spec.IFipTicket;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+import org.uic.barcode.ticket.api.test.testtickets.FipTimeZoneTestTicketV1;
+import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder;
+import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder;
+
+
+/**
+ * The Class FipTimeZoneTestV1.
+ *
+ *
+ *
+ */
+public class FipTimeZoneTestV1 {
+
+ /** The low level encoded test ticket test case 1 . */
+ private byte[] encoded1 = null;
+
+ /** The low level encoded test ticket test case 2 . */
+ private byte[] encoded2 = null;
+
+ /** The low level encoded test ticket test case 3 . */
+ private byte[] encoded3 = null;
+
+ /** The decoder. */
+ OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder();
+
+ /** The encoder. */
+ Api2OpenAsnEncoder encoder = new Api2OpenAsnEncoder();
+
+ /** The API ticket low level encoded for case 1. */
+ IUicRailTicket iTicketDecodedFromAsn1Case1 = null;
+
+ /** The API ticket low level encoded for case 2. */
+ IUicRailTicket iTicketDecodedFromAsn1Case2 = null;
+
+ /** The API ticket low level encoded for case 3. */
+ IUicRailTicket iTicketDecodedFromAsn1Case3 = null;
+
+
+ /** The ticket decoded 1. */
+ IUicRailTicket iTicketDecodedCase1 = null;
+
+ /** The i ticket decoded 2. */
+ IUicRailTicket iTicketDecodedCase2 = null;
+
+ /** The i ticket decoded 3. */
+ IUicRailTicket iTicketDecodedCase3 = null;
+
+ byte[] encodedInTimeZone1 = null;
+ byte[] encodedInTimeZone2 = null;
+ byte[] encodedInTimeZone3 = null;
+
+ String issuingDate1 = null;
+ String issuingDate2 = null;
+ String issuingDate3 = null;
+
+ String validFrom1 = null;
+ String validFrom2 = null;
+ String validFrom3 = null;
+
+ String validUntil1 = null;
+ String validUntil2 = null;
+ String validUntil3 = null;
+
+ String activationDate1 = null;
+ String activationDate2 = null;
+ String activationDate3 = null;
+
+ TimeZone defaulttimeZone = null;
+
+ /**
+ * Prepare tickets.
+ */
+ @Before public void prepare() {
+
+ defaulttimeZone = TimeZone.getDefault();
+
+ UicRailTicketData ticket1 = FipTimeZoneTestTicketV1.getUicTestTicket();
+ UicRailTicketData ticket2 = FipTimeZoneTestTicketV1.getUicTestTicket();
+ UicRailTicketData ticket3 = FipTimeZoneTestTicketV1.getUicTestTicket();
+
+ //encode in UTC time zone
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+ encoded1 = UperEncoder.encode(ticket1);
+ encoded2 = UperEncoder.encode(ticket2);
+ encoded3 = UperEncoder.encode(ticket3);
+
+ }
+
+ /**
+ * clean up
+ */
+ @After public void resetTimeZone() {
+ TimeZone.setDefault(defaulttimeZone);
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone CET
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromTo("2021.03.14-00:00");
+ setValidUntilTo("2021.03.24-23:59");
+ setActivatedDayTo("2021.03.14-00:00");
+
+ encode("CET");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(validFrom1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFrom2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFrom3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(validUntil1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntil2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntil3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+ assert(activationDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(activationDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(activationDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromTo("2021.03.14-00:00");
+ setValidUntilTo("2021.03.24-23:59");
+ setActivatedDayTo("2021.03.14-00:00");
+
+ encode("GMT");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(validFrom1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFrom2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFrom3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(validUntil1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntil2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntil3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+ assert(activationDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(activationDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(activationDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ }
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromTo("2021.03.14-00:00");
+ setValidUntilTo("2021.03.24-23:59");
+ setActivatedDayTo("2021.03.14-00:00");
+
+ encode("CET");
+ decode("GMT");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" ));
+ assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" ));
+
+ assert(validFrom1.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(validFrom2.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(validFrom3.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+
+ assert(validUntil1.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(validUntil2.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(validUntil3.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+
+ assert(activationDate1.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(activationDate2.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(activationDate3.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+
+ }
+
+ private void decodedDateToStrings() {
+
+ issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString();
+ issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString();
+ issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString();
+
+ validFrom1 = ((IFipTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString();
+ validFrom2 = ((IFipTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString();
+ validFrom3 = ((IFipTicket) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString();
+
+ validUntil1 = ((IFipTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString();
+ validUntil2 = ((IFipTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString();
+ validUntil3 = ((IFipTicket) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString();
+
+ activationDate1 = ((IFipTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString();
+ activationDate2 = ((IFipTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString();
+ activationDate3 = ((IFipTicket) iTicketDecodedCase3.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString();
+
+ }
+
+
+ private void setActivatedDayTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IFipTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear();
+ ((IFipTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add(date);
+
+ ((IFipTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear();
+ ((IFipTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add(date);
+
+ ((IFipTicket) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear();
+ ((IFipTicket) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().add(date);
+
+ }
+
+ private void setValidFromTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IFipTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date);
+ ((IFipTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date);
+ ((IFipTicket) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(date);
+ }
+
+ private void setValidUntilTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IFipTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date);
+ ((IFipTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date);
+ ((IFipTicket) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidUntil(date);
+ }
+
+
+ /**
+ * Encode in Time Zone
+ */
+ private void encode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+ try {
+ encodedInTimeZone1 = encoder.encode(iTicketDecodedFromAsn1Case1);
+ encodedInTimeZone2 = encoder.encode(iTicketDecodedFromAsn1Case2);
+ encodedInTimeZone3 = encoder.encode(iTicketDecodedFromAsn1Case3);
+ } catch (EncodingFormatException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Decode in Time Zone
+ */
+ private void decode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+
+ try {
+ iTicketDecodedCase1 = decoder.decodeFromAsn(encodedInTimeZone1);
+ iTicketDecodedCase2 = decoder.decodeFromAsn(encodedInTimeZone2);
+ iTicketDecodedCase3 = decoder.decodeFromAsn(encodedInTimeZone3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Encode decode.
+ */
+ private void decodeTestTicketUTC() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ try {
+ iTicketDecodedFromAsn1Case1 = decoder.decodeFromAsn(encoded1);
+ iTicketDecodedFromAsn1Case2 = decoder.decodeFromAsn(encoded2);
+ iTicketDecodedFromAsn1Case3 = decoder.decodeFromAsn(encoded3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV1.java b/src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV1.java
new file mode 100644
index 0000000..5bf78cb
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV1.java
@@ -0,0 +1,312 @@
+package org.uic.barcode.ticket.api.test;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
+import org.uic.barcode.ticket.api.spec.IReservation;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+import org.uic.barcode.ticket.api.test.testtickets.ReservationTestTicketV1;
+import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder;
+import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder;
+
+
+/**
+ * The Class FipTimeZoneTestV1.
+ *
+ *
+ *
+ */
+public class ReservationTimeZoneTestV1 {
+
+ /** The low level encoded test ticket test case 1 . */
+ private byte[] encoded1 = null;
+
+ /** The low level encoded test ticket test case 2 . */
+ private byte[] encoded2 = null;
+
+ /** The low level encoded test ticket test case 3 . */
+ private byte[] encoded3 = null;
+
+ /** The decoder. */
+ OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder();
+
+ /** The encoder. */
+ Api2OpenAsnEncoder encoder = new Api2OpenAsnEncoder();
+
+ /** The API ticket low level encoded for case 1. */
+ IUicRailTicket iTicketDecodedFromAsn1Case1 = null;
+
+ /** The API ticket low level encoded for case 2. */
+ IUicRailTicket iTicketDecodedFromAsn1Case2 = null;
+
+ /** The API ticket low level encoded for case 3. */
+ IUicRailTicket iTicketDecodedFromAsn1Case3 = null;
+
+
+ /** The ticket decoded 1. */
+ IUicRailTicket iTicketDecodedCase1 = null;
+
+ /** The i ticket decoded 2. */
+ IUicRailTicket iTicketDecodedCase2 = null;
+
+ /** The i ticket decoded 3. */
+ IUicRailTicket iTicketDecodedCase3 = null;
+
+ byte[] encodedInTimeZone1 = null;
+ byte[] encodedInTimeZone2 = null;
+ byte[] encodedInTimeZone3 = null;
+
+ String issuingDate1 = null;
+ String issuingDate2 = null;
+ String issuingDate3 = null;
+
+ String departureDate1 = null;
+ String departureDate2 = null;
+ String departureDate3 = null;
+
+ String arrivalDate1 = null;
+ String arrivalDate2 = null;
+ String arrivalDate3 = null;
+
+ TimeZone defaulttimeZone = null;
+
+ /**
+ * Prepare tickets.
+ */
+ @Before public void prepare() {
+
+ defaulttimeZone = TimeZone.getDefault();
+
+ UicRailTicketData ticket1 = ReservationTestTicketV1.getUicTestTicket();
+ UicRailTicketData ticket2 = ReservationTestTicketV1.getUicTestTicket();
+ UicRailTicketData ticket3 = ReservationTestTicketV1.getUicTestTicket();
+
+ //encode in UTC time zone
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+ encoded1 = UperEncoder.encode(ticket1);
+ encoded2 = UperEncoder.encode(ticket2);
+ encoded3 = UperEncoder.encode(ticket3);
+
+ }
+
+ /**
+ * clean up
+ */
+ @After public void resetTimeZone() {
+ TimeZone.setDefault(defaulttimeZone);
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone CET
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setdepartureDateTo("2021.03.14-00:00");
+ setarrivalDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(departureDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(arrivalDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setdepartureDateTo("2021.03.14-00:00");
+ setarrivalDateTo("2021.03.24-23:59");
+
+ encode("GMT");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(departureDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(arrivalDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setdepartureDateTo("2021.03.14-00:00");
+ setarrivalDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("GMT");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" ));
+ assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" ));
+
+ assert(departureDate1.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(departureDate2.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(departureDate3.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+
+ assert(arrivalDate1.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(arrivalDate2.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(arrivalDate3.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+
+
+ }
+
+ private void decodedDateToStrings() {
+
+ issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString();
+ issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString();
+ issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString();
+
+ departureDate1 = ((IReservation) iTicketDecodedCase1.getDocumentData().iterator().next()).getDepartureDate().toString();
+ departureDate2 = ((IReservation) iTicketDecodedCase2.getDocumentData().iterator().next()).getDepartureDate().toString();
+ departureDate3 = ((IReservation) iTicketDecodedCase3.getDocumentData().iterator().next()).getDepartureDate().toString();
+
+ arrivalDate1 = ((IReservation) iTicketDecodedCase1.getDocumentData().iterator().next()).getArrivalDate().toString();
+ arrivalDate2 = ((IReservation) iTicketDecodedCase2.getDocumentData().iterator().next()).getArrivalDate().toString();
+ arrivalDate3 = ((IReservation) iTicketDecodedCase3.getDocumentData().iterator().next()).getArrivalDate().toString();
+
+
+ }
+
+
+ private void setdepartureDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IReservation) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setDepartureDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setDepartureDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setDepartureDate(date);
+ }
+
+ private void setarrivalDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IReservation) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setArrivalDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setArrivalDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setArrivalDate(date);
+ }
+
+
+ /**
+ * Encode in Time Zone
+ */
+ private void encode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+ try {
+ encodedInTimeZone1 = encoder.encode(iTicketDecodedFromAsn1Case1);
+ encodedInTimeZone2 = encoder.encode(iTicketDecodedFromAsn1Case2);
+ encodedInTimeZone3 = encoder.encode(iTicketDecodedFromAsn1Case3);
+ } catch (EncodingFormatException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Decode in Time Zone
+ */
+ private void decode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+
+ try {
+ iTicketDecodedCase1 = decoder.decodeFromAsn(encodedInTimeZone1);
+ iTicketDecodedCase2 = decoder.decodeFromAsn(encodedInTimeZone2);
+ iTicketDecodedCase3 = decoder.decodeFromAsn(encodedInTimeZone3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Encode decode.
+ */
+ private void decodeTestTicketUTC() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ try {
+ iTicketDecodedFromAsn1Case1 = decoder.decodeFromAsn(encoded1);
+ iTicketDecodedFromAsn1Case2 = decoder.decodeFromAsn(encoded2);
+ iTicketDecodedFromAsn1Case3 = decoder.decodeFromAsn(encoded3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV2.java b/src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV2.java
new file mode 100644
index 0000000..34d3bc2
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV2.java
@@ -0,0 +1,312 @@
+package org.uic.barcode.ticket.api.test;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.asn.omv2.UicRailTicketData;
+import org.uic.barcode.ticket.api.spec.IReservation;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+import org.uic.barcode.ticket.api.test.testtickets.ReservationTestTicketV2;
+import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV2;
+import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV2;
+
+
+/**
+ * The Class FipTimeZoneTestV1.
+ *
+ *
+ *
+ */
+public class ReservationTimeZoneTestV2 {
+
+ /** The low level encoded test ticket test case 1 . */
+ private byte[] encoded1 = null;
+
+ /** The low level encoded test ticket test case 2 . */
+ private byte[] encoded2 = null;
+
+ /** The low level encoded test ticket test case 3 . */
+ private byte[] encoded3 = null;
+
+ /** The decoder. */
+ OpenAsn2ApiDecoderV2 decoder = new OpenAsn2ApiDecoderV2();
+
+ /** The encoder. */
+ Api2OpenAsnEncoderV2 encoder = new Api2OpenAsnEncoderV2();
+
+ /** The API ticket low level encoded for case 1. */
+ IUicRailTicket iTicketDecodedFromAsn1Case1 = null;
+
+ /** The API ticket low level encoded for case 2. */
+ IUicRailTicket iTicketDecodedFromAsn1Case2 = null;
+
+ /** The API ticket low level encoded for case 3. */
+ IUicRailTicket iTicketDecodedFromAsn1Case3 = null;
+
+
+ /** The ticket decoded 1. */
+ IUicRailTicket iTicketDecodedCase1 = null;
+
+ /** The i ticket decoded 2. */
+ IUicRailTicket iTicketDecodedCase2 = null;
+
+ /** The i ticket decoded 3. */
+ IUicRailTicket iTicketDecodedCase3 = null;
+
+ byte[] encodedInTimeZone1 = null;
+ byte[] encodedInTimeZone2 = null;
+ byte[] encodedInTimeZone3 = null;
+
+ String issuingDate1 = null;
+ String issuingDate2 = null;
+ String issuingDate3 = null;
+
+ String departureDate1 = null;
+ String departureDate2 = null;
+ String departureDate3 = null;
+
+ String arrivalDate1 = null;
+ String arrivalDate2 = null;
+ String arrivalDate3 = null;
+
+ TimeZone defaulttimeZone = null;
+
+ /**
+ * Prepare tickets.
+ */
+ @Before public void prepare() {
+
+ defaulttimeZone = TimeZone.getDefault();
+
+ UicRailTicketData ticket1 = ReservationTestTicketV2.getUicTestTicket();
+ UicRailTicketData ticket2 = ReservationTestTicketV2.getUicTestTicket();
+ UicRailTicketData ticket3 = ReservationTestTicketV2.getUicTestTicket();
+
+ //encode in UTC time zone
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+ encoded1 = UperEncoder.encode(ticket1);
+ encoded2 = UperEncoder.encode(ticket2);
+ encoded3 = UperEncoder.encode(ticket3);
+
+ }
+
+ /**
+ * clean up
+ */
+ @After public void resetTimeZone() {
+ TimeZone.setDefault(defaulttimeZone);
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone CET
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setdepartureDateTo("2021.03.14-00:00");
+ setarrivalDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(departureDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(arrivalDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setdepartureDateTo("2021.03.14-00:00");
+ setarrivalDateTo("2021.03.24-23:59");
+
+ encode("GMT");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(departureDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(departureDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(arrivalDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(arrivalDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setdepartureDateTo("2021.03.14-00:00");
+ setarrivalDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("GMT");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" ));
+ assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" ));
+
+ assert(departureDate1.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(departureDate2.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(departureDate3.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+
+ assert(arrivalDate1.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(arrivalDate2.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(arrivalDate3.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+
+
+ }
+
+ private void decodedDateToStrings() {
+
+ issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString();
+ issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString();
+ issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString();
+
+ departureDate1 = ((IReservation) iTicketDecodedCase1.getDocumentData().iterator().next()).getDepartureDate().toString();
+ departureDate2 = ((IReservation) iTicketDecodedCase2.getDocumentData().iterator().next()).getDepartureDate().toString();
+ departureDate3 = ((IReservation) iTicketDecodedCase3.getDocumentData().iterator().next()).getDepartureDate().toString();
+
+ arrivalDate1 = ((IReservation) iTicketDecodedCase1.getDocumentData().iterator().next()).getArrivalDate().toString();
+ arrivalDate2 = ((IReservation) iTicketDecodedCase2.getDocumentData().iterator().next()).getArrivalDate().toString();
+ arrivalDate3 = ((IReservation) iTicketDecodedCase3.getDocumentData().iterator().next()).getArrivalDate().toString();
+
+
+ }
+
+
+ private void setdepartureDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IReservation) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setDepartureDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setDepartureDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setDepartureDate(date);
+ }
+
+ private void setarrivalDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IReservation) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setArrivalDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setArrivalDate(date);
+ ((IReservation) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setArrivalDate(date);
+ }
+
+
+ /**
+ * Encode in Time Zone
+ */
+ private void encode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+ try {
+ encodedInTimeZone1 = encoder.encode(iTicketDecodedFromAsn1Case1);
+ encodedInTimeZone2 = encoder.encode(iTicketDecodedFromAsn1Case2);
+ encodedInTimeZone3 = encoder.encode(iTicketDecodedFromAsn1Case3);
+ } catch (EncodingFormatException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Decode in Time Zone
+ */
+ private void decode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+
+ try {
+ iTicketDecodedCase1 = decoder.decodeFromAsn(encodedInTimeZone1);
+ iTicketDecodedCase2 = decoder.decodeFromAsn(encodedInTimeZone2);
+ iTicketDecodedCase3 = decoder.decodeFromAsn(encodedInTimeZone3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Encode decode.
+ */
+ private void decodeTestTicketUTC() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ try {
+ iTicketDecodedFromAsn1Case1 = decoder.decodeFromAsn(encoded1);
+ iTicketDecodedFromAsn1Case2 = decoder.decodeFromAsn(encoded2);
+ iTicketDecodedFromAsn1Case3 = decoder.decodeFromAsn(encoded3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV1.java b/src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV1.java
new file mode 100644
index 0000000..aedf569
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV1.java
@@ -0,0 +1,312 @@
+package org.uic.barcode.ticket.api.test;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
+import org.uic.barcode.ticket.api.spec.IStationPassage;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+import org.uic.barcode.ticket.api.test.testtickets.StationPassageTestTicketV1;
+import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder;
+import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder;
+
+
+/**
+ * The Class FipTimeZoneTestV1.
+ *
+ *
+ *
+ */
+public class StationPassageTimeZoneTestV1 {
+
+ /** The low level encoded test ticket test case 1 . */
+ private byte[] encoded1 = null;
+
+ /** The low level encoded test ticket test case 2 . */
+ private byte[] encoded2 = null;
+
+ /** The low level encoded test ticket test case 3 . */
+ private byte[] encoded3 = null;
+
+ /** The decoder. */
+ OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder();
+
+ /** The encoder. */
+ Api2OpenAsnEncoder encoder = new Api2OpenAsnEncoder();
+
+ /** The API ticket low level encoded for case 1. */
+ IUicRailTicket iTicketDecodedFromAsn1Case1 = null;
+
+ /** The API ticket low level encoded for case 2. */
+ IUicRailTicket iTicketDecodedFromAsn1Case2 = null;
+
+ /** The API ticket low level encoded for case 3. */
+ IUicRailTicket iTicketDecodedFromAsn1Case3 = null;
+
+
+ /** The ticket decoded 1. */
+ IUicRailTicket iTicketDecodedCase1 = null;
+
+ /** The i ticket decoded 2. */
+ IUicRailTicket iTicketDecodedCase2 = null;
+
+ /** The i ticket decoded 3. */
+ IUicRailTicket iTicketDecodedCase3 = null;
+
+ byte[] encodedInTimeZone1 = null;
+ byte[] encodedInTimeZone2 = null;
+ byte[] encodedInTimeZone3 = null;
+
+ String issuingDate1 = null;
+ String issuingDate2 = null;
+ String issuingDate3 = null;
+
+ String validFromDate1 = null;
+ String validFromDate2 = null;
+ String validFromDate3 = null;
+
+ String validUntilDate1 = null;
+ String validUntilDate2 = null;
+ String validUntilDate3 = null;
+
+ TimeZone defaulttimeZone = null;
+
+ /**
+ * Prepare tickets.
+ */
+ @Before public void prepare() {
+
+ defaulttimeZone = TimeZone.getDefault();
+
+ UicRailTicketData ticket1 = StationPassageTestTicketV1.getUicTestTicket();
+ UicRailTicketData ticket2 = StationPassageTestTicketV1.getUicTestTicket();
+ UicRailTicketData ticket3 = StationPassageTestTicketV1.getUicTestTicket();
+
+ //encode in UTC time zone
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+ encoded1 = UperEncoder.encode(ticket1);
+ encoded2 = UperEncoder.encode(ticket2);
+ encoded3 = UperEncoder.encode(ticket3);
+
+ }
+
+ /**
+ * clean up
+ */
+ @After public void resetTimeZone() {
+ TimeZone.setDefault(defaulttimeZone);
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone CET
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromDateTo("2021.03.14-00:00");
+ setUntilDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromDateTo("2021.03.14-00:00");
+ setUntilDateTo("2021.03.24-23:59");
+
+ encode("GMT");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromDateTo("2021.03.14-00:00");
+ setUntilDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("GMT");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" ));
+ assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" ));
+
+ assert(validFromDate1.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(validFromDate2.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(validFromDate3.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+
+ assert(validUntilDate1.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(validUntilDate2.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(validUntilDate3.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+
+
+ }
+
+ private void decodedDateToStrings() {
+
+ issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString();
+ issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString();
+ issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString();
+
+ validFromDate1 = ((IStationPassage) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString();
+ validFromDate2 = ((IStationPassage) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString();
+ validFromDate3 = ((IStationPassage) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString();
+
+ validUntilDate1 = ((IStationPassage) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString();
+ validUntilDate2 = ((IStationPassage) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString();
+ validUntilDate3 = ((IStationPassage) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString();
+
+
+ }
+
+
+ private void setValidFromDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IStationPassage) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(date);
+ }
+
+ private void setUntilDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IStationPassage) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidUntil(date);
+ }
+
+
+ /**
+ * Encode in Time Zone
+ */
+ private void encode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+ try {
+ encodedInTimeZone1 = encoder.encode(iTicketDecodedFromAsn1Case1);
+ encodedInTimeZone2 = encoder.encode(iTicketDecodedFromAsn1Case2);
+ encodedInTimeZone3 = encoder.encode(iTicketDecodedFromAsn1Case3);
+ } catch (EncodingFormatException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Decode in Time Zone
+ */
+ private void decode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+
+ try {
+ iTicketDecodedCase1 = decoder.decodeFromAsn(encodedInTimeZone1);
+ iTicketDecodedCase2 = decoder.decodeFromAsn(encodedInTimeZone2);
+ iTicketDecodedCase3 = decoder.decodeFromAsn(encodedInTimeZone3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Encode decode.
+ */
+ private void decodeTestTicketUTC() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ try {
+ iTicketDecodedFromAsn1Case1 = decoder.decodeFromAsn(encoded1);
+ iTicketDecodedFromAsn1Case2 = decoder.decodeFromAsn(encoded2);
+ iTicketDecodedFromAsn1Case3 = decoder.decodeFromAsn(encoded3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV2.java b/src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV2.java
new file mode 100644
index 0000000..e87e968
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV2.java
@@ -0,0 +1,312 @@
+package org.uic.barcode.ticket.api.test;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.asn.omv2.UicRailTicketData;
+import org.uic.barcode.ticket.api.spec.IStationPassage;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+import org.uic.barcode.ticket.api.test.testtickets.StationPassageTestTicketV2;
+import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV2;
+import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV2;
+
+
+/**
+ * The Class FipTimeZoneTestV2.
+ *
+ *
+ *
+ */
+public class StationPassageTimeZoneTestV2 {
+
+ /** The low level encoded test ticket test case 1 . */
+ private byte[] encoded1 = null;
+
+ /** The low level encoded test ticket test case 2 . */
+ private byte[] encoded2 = null;
+
+ /** The low level encoded test ticket test case 3 . */
+ private byte[] encoded3 = null;
+
+ /** The decoder. */
+ OpenAsn2ApiDecoderV2 decoder = new OpenAsn2ApiDecoderV2();
+
+ /** The encoder. */
+ Api2OpenAsnEncoderV2 encoder = new Api2OpenAsnEncoderV2();
+
+ /** The API ticket low level encoded for case 1. */
+ IUicRailTicket iTicketDecodedFromAsn1Case1 = null;
+
+ /** The API ticket low level encoded for case 2. */
+ IUicRailTicket iTicketDecodedFromAsn1Case2 = null;
+
+ /** The API ticket low level encoded for case 3. */
+ IUicRailTicket iTicketDecodedFromAsn1Case3 = null;
+
+
+ /** The ticket decoded 1. */
+ IUicRailTicket iTicketDecodedCase1 = null;
+
+ /** The i ticket decoded 2. */
+ IUicRailTicket iTicketDecodedCase2 = null;
+
+ /** The i ticket decoded 3. */
+ IUicRailTicket iTicketDecodedCase3 = null;
+
+ byte[] encodedInTimeZone1 = null;
+ byte[] encodedInTimeZone2 = null;
+ byte[] encodedInTimeZone3 = null;
+
+ String issuingDate1 = null;
+ String issuingDate2 = null;
+ String issuingDate3 = null;
+
+ String validFromDate1 = null;
+ String validFromDate2 = null;
+ String validFromDate3 = null;
+
+ String validUntilDate1 = null;
+ String validUntilDate2 = null;
+ String validUntilDate3 = null;
+
+ TimeZone defaulttimeZone = null;
+
+ /**
+ * Prepare tickets.
+ */
+ @Before public void prepare() {
+
+ defaulttimeZone = TimeZone.getDefault();
+
+ UicRailTicketData ticket1 = StationPassageTestTicketV2.getUicTestTicket();
+ UicRailTicketData ticket2 = StationPassageTestTicketV2.getUicTestTicket();
+ UicRailTicketData ticket3 = StationPassageTestTicketV2.getUicTestTicket();
+
+ //encode in UTC time zone
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+ encoded1 = UperEncoder.encode(ticket1);
+ encoded2 = UperEncoder.encode(ticket2);
+ encoded3 = UperEncoder.encode(ticket3);
+
+ }
+
+ /**
+ * clean up
+ */
+ @After public void resetTimeZone() {
+ TimeZone.setDefault(defaulttimeZone);
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone CET
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromDateTo("2021.03.14-00:00");
+ setUntilDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromDateTo("2021.03.14-00:00");
+ setUntilDateTo("2021.03.24-23:59");
+
+ encode("GMT");
+ decode("CET");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" ));
+ assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" ));
+
+ assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" ));
+ assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" ));
+
+ assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" ));
+ assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" ));
+
+
+ }
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ decodeTestTicketUTC();
+
+ //set the dates in the time zone GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("CET"));
+ iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" ));
+ iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" ));
+
+ setValidFromDateTo("2021.03.14-00:00");
+ setUntilDateTo("2021.03.24-23:59");
+
+ encode("CET");
+ decode("GMT");
+ decodedDateToStrings();
+
+ assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" ));
+ assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" ));
+ assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" ));
+
+ assert(validFromDate1.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(validFromDate2.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+ assert(validFromDate3.equals("Sun Mar 14 00:00:00 GMT 2021" ));
+
+ assert(validUntilDate1.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(validUntilDate2.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+ assert(validUntilDate3.equals("Wed Mar 24 23:59:00 GMT 2021" ));
+
+
+ }
+
+ private void decodedDateToStrings() {
+
+ issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString();
+ issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString();
+ issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString();
+
+ validFromDate1 = ((IStationPassage) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString();
+ validFromDate2 = ((IStationPassage) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString();
+ validFromDate3 = ((IStationPassage) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString();
+
+ validUntilDate1 = ((IStationPassage) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString();
+ validUntilDate2 = ((IStationPassage) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString();
+ validUntilDate3 = ((IStationPassage) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString();
+
+
+ }
+
+
+ private void setValidFromDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IStationPassage) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(date);
+ }
+
+ private void setUntilDateTo(String dateString) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" );
+ Date date = dateFormat.parse(dateString);
+ ((IStationPassage) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date);
+ ((IStationPassage) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidUntil(date);
+ }
+
+
+ /**
+ * Encode in Time Zone
+ */
+ private void encode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+ try {
+ encodedInTimeZone1 = encoder.encode(iTicketDecodedFromAsn1Case1);
+ encodedInTimeZone2 = encoder.encode(iTicketDecodedFromAsn1Case2);
+ encodedInTimeZone3 = encoder.encode(iTicketDecodedFromAsn1Case3);
+ } catch (EncodingFormatException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Decode in Time Zone
+ */
+ private void decode(String timeZone) {
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+
+ try {
+ iTicketDecodedCase1 = decoder.decodeFromAsn(encodedInTimeZone1);
+ iTicketDecodedCase2 = decoder.decodeFromAsn(encodedInTimeZone2);
+ iTicketDecodedCase3 = decoder.decodeFromAsn(encodedInTimeZone3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Encode decode.
+ */
+ private void decodeTestTicketUTC() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ try {
+ iTicketDecodedFromAsn1Case1 = decoder.decodeFromAsn(encoded1);
+ iTicketDecodedFromAsn1Case2 = decoder.decodeFromAsn(encoded2);
+ iTicketDecodedFromAsn1Case3 = decoder.decodeFromAsn(encoded3);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV1.java
new file mode 100644
index 0000000..840b584
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV1.java
@@ -0,0 +1,201 @@
+package org.uic.barcode.ticket.api.test.testtickets;
+
+import org.uic.barcode.ticket.api.asn.omv1.CardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv1.ControlData;
+import org.uic.barcode.ticket.api.asn.omv1.CustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv1.DocumentData;
+import org.uic.barcode.ticket.api.asn.omv1.ExtensionData;
+import org.uic.barcode.ticket.api.asn.omv1.IssuingData;
+import org.uic.barcode.ticket.api.asn.omv1.PassengerType;
+import org.uic.barcode.ticket.api.asn.omv1.PlacesType;
+import org.uic.barcode.ticket.api.asn.omv1.PriceTypeType;
+import org.uic.barcode.ticket.api.asn.omv1.ReservationData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCarrierNum;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfDocumentData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfExtensionData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfTariffType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfTravelerType;
+import org.uic.barcode.ticket.api.asn.omv1.ServiceType;
+import org.uic.barcode.ticket.api.asn.omv1.TariffType;
+import org.uic.barcode.ticket.api.asn.omv1.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv1.TravelClassType;
+import org.uic.barcode.ticket.api.asn.omv1.TravelerData;
+import org.uic.barcode.ticket.api.asn.omv1.TravelerType;
+import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
+
+
+ public class ReservationTestTicketV1 {
+
+ public static UicRailTicketData getUicTestTicket() {
+ UicRailTicketData ticket = new UicRailTicketData();
+ populateTicket(ticket);
+ return ticket;
+ }
+
+
+ private static void populateTicket(UicRailTicketData ticket) {
+
+ ticket.setControlDetail(new ControlData());
+ populate(ticket.getControlDetail());
+
+
+ ticket.setIssuingDetail(new IssuingData());
+ populateIssuingData(ticket.getIssuingDetail());
+
+ TravelerData td = new TravelerData();
+ populateTravelerData(td);
+ ticket.setTravelerDetail(td);
+
+ SequenceOfDocumentData ds = new SequenceOfDocumentData();
+
+
+ //OpenTicket
+ DocumentData do1 = new DocumentData();
+ addReservation(do1);
+ ds.add(do1);
+
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+
+ private static void addReservation(DocumentData dd) {
+
+ TicketDetailData tdd = new TicketDetailData();
+ ReservationData ticket = new ReservationData();
+ ticket.setTrainNum(123L);
+ ticket.setService(ServiceType.seat);
+ ticket.setReferenceNum(810123456789L);
+ ticket.setServiceBrandAbrUTF8("XYZ");
+ ticket.setServiceBrandNameUTF8("special train");
+ SequenceOfCarrierNum carriers = new SequenceOfCarrierNum();
+ carriers.add(1080L);
+ carriers.add(1181L);
+ ticket.setCarrierNum(carriers);
+ ticket.setFromStationNum(8100001L);
+ ticket.setToStationNum(800001L);
+ ticket.setNumberOfSupplements(1L);
+ ticket.setServiceBrand(100L);
+ ticket.setPrice(12345L);
+ ticket.setPriceType(PriceTypeType.supplement);
+
+ ticket.setPlaces(getPlaces());
+ ticket.setTariff(getTariffs());
+
+ ticket.setInfoText("reservation");
+ ticket.setClassCode(TravelClassType.first);
+ ticket.setDepartureDate(10L);
+ ticket.setDepartureTime(0L);
+ ticket.setArrivalDate(10L);
+ ticket.setArrivalTime(1439L);
+ tdd.setReservation(ticket);
+ dd.setTicket(tdd);
+ }
+
+
+
+ private static SequenceOfTariffType getTariffs() {
+ SequenceOfTariffType tariffs = new SequenceOfTariffType();
+
+ TariffType tariff = new TariffType();
+ tariff.setNumberOfPassengers(1L);
+ tariff.setRestrictedToCountryOfResidence(false);
+ tariff.setPassengerType(PassengerType.adult);
+ tariff.setTariffIdNum(72L);
+ tariff.setTariffDesc("Full Fare Adult");
+ tariffs.add(tariff);
+ TariffType tariff2 = new TariffType();
+ tariff2.setRestrictedToCountryOfResidence(false);
+ tariff2.setNumberOfPassengers(2L);
+ tariff2.setPassengerType(PassengerType.child);
+ tariff2.setTariffIdNum(73L);
+ tariff2.setTariffDesc("Full Fare Child");
+ tariffs.add(tariff2);
+ return tariffs;
+ }
+
+
+ private static PlacesType getPlaces() {
+ PlacesType places = new PlacesType();
+ places.setPlaceDescription("11-13");
+ places.setCoach("12");
+ return places;
+ }
+
+
+ private static void populateTravelerData(TravelerData td) {
+ td.setGroupName("myGroup");
+ SequenceOfTravelerType trs = new SequenceOfTravelerType();
+ TravelerType tr = new TravelerType();
+ tr.setIdCard("12345");
+ tr.setFirstName("John");
+ tr.setSecondName("Dow");
+ tr.setTicketHolder(true);
+ SequenceOfCustomerStatusType ts = new SequenceOfCustomerStatusType();
+ CustomerStatusType cst = new CustomerStatusType();
+ cst.setCustomerStatusDescr("senior");
+ ts.add(cst);
+ tr.setStatus(ts);
+ trs.add(tr);
+ td.setTraveler(trs);
+ }
+
+ private static void populateIssuingData(IssuingData issuingDetail) {
+ issuingDetail.setIssuingYear(2018L);
+ issuingDetail.setIssuingDay(1L);
+ issuingDetail.setIssuerPNR("issuerTestPNR");
+ issuingDetail.setSpecimen(true);
+ issuingDetail.setSecurePaperTicket(false);
+ issuingDetail.setActivated(true);
+ issuingDetail.setIssuedOnLine(12L);
+ }
+
+
+ private static void populateExtensionSequence(SequenceOfExtensionData ed) {
+ ExtensionData ed1 = new ExtensionData();
+ ed1.setExtensionId("1");
+ byte[] ba1 = { (byte) 0x82, (byte) 0xDA };
+ ed1.setExtensionData(ba1);
+ ExtensionData ed2 = new ExtensionData();
+ ed2.setExtensionId("2");
+ byte[] ba2 = { (byte) 0x83, (byte) 0xDA };
+ ed2.setExtensionData(ba2);
+ ed.add(ed1);
+ ed.add(ed2);
+ }
+
+ private static void populate(ControlData controlDetail) {
+ controlDetail.infoText = "cd";
+ controlDetail.setAgeCheckRequired(false);
+ controlDetail.setIdentificationByIdCard(false);
+ controlDetail.setIdentificationByPassportId(false);
+ controlDetail.setOnlineValidationRequired(false);
+ controlDetail.setPassportValidationRequired(false);
+ controlDetail.setReductionCardCheckRequired(false);
+ controlDetail.setIdentificationByCardReference(new SequenceOfCardReferenceType());
+ controlDetail.getIdentificationByCardReference().add(populateCardRefrence());
+ }
+
+
+ /*
+ {
+ trailingCardIdNum 100
+ }
+ */
+ private static CardReferenceType populateCardRefrence() {
+ CardReferenceType cr = new CardReferenceType();
+ cr.setTrailingCardIdNum(100L);
+ return cr;
+ }
+
+
+
+ }
diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV2.java b/src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV2.java
new file mode 100644
index 0000000..ef84644
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV2.java
@@ -0,0 +1,201 @@
+package org.uic.barcode.ticket.api.test.testtickets;
+
+import org.uic.barcode.ticket.api.asn.omv2.CardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv2.ControlData;
+import org.uic.barcode.ticket.api.asn.omv2.CustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv2.DocumentData;
+import org.uic.barcode.ticket.api.asn.omv2.ExtensionData;
+import org.uic.barcode.ticket.api.asn.omv2.IssuingData;
+import org.uic.barcode.ticket.api.asn.omv2.PassengerType;
+import org.uic.barcode.ticket.api.asn.omv2.PlacesType;
+import org.uic.barcode.ticket.api.asn.omv2.PriceTypeType;
+import org.uic.barcode.ticket.api.asn.omv2.ReservationData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfCardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfCarrierNum;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfCustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfDocumentData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfExtensionData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfTariffType;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfTravelerType;
+import org.uic.barcode.ticket.api.asn.omv2.ServiceType;
+import org.uic.barcode.ticket.api.asn.omv2.TariffType;
+import org.uic.barcode.ticket.api.asn.omv2.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv2.TravelClassType;
+import org.uic.barcode.ticket.api.asn.omv2.TravelerData;
+import org.uic.barcode.ticket.api.asn.omv2.TravelerType;
+import org.uic.barcode.ticket.api.asn.omv2.UicRailTicketData;
+
+
+ public class ReservationTestTicketV2 {
+
+ public static UicRailTicketData getUicTestTicket() {
+ UicRailTicketData ticket = new UicRailTicketData();
+ populateTicket(ticket);
+ return ticket;
+ }
+
+
+ private static void populateTicket(UicRailTicketData ticket) {
+
+ ticket.setControlDetail(new ControlData());
+ populate(ticket.getControlDetail());
+
+
+ ticket.setIssuingDetail(new IssuingData());
+ populateIssuingData(ticket.getIssuingDetail());
+
+ TravelerData td = new TravelerData();
+ populateTravelerData(td);
+ ticket.setTravelerDetail(td);
+
+ SequenceOfDocumentData ds = new SequenceOfDocumentData();
+
+
+ //OpenTicket
+ DocumentData do1 = new DocumentData();
+ addReservation(do1);
+ ds.add(do1);
+
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+
+ private static void addReservation(DocumentData dd) {
+
+ TicketDetailData tdd = new TicketDetailData();
+ ReservationData ticket = new ReservationData();
+ ticket.setTrainNum(123L);
+ ticket.setService(ServiceType.seat);
+ ticket.setReferenceNum(810123456789L);
+ ticket.setServiceBrandAbrUTF8("XYZ");
+ ticket.setServiceBrandNameUTF8("special train");
+ SequenceOfCarrierNum carriers = new SequenceOfCarrierNum();
+ carriers.add(1080L);
+ carriers.add(1181L);
+ ticket.setCarrierNum(carriers);
+ ticket.setFromStationNum(8100001L);
+ ticket.setToStationNum(800001L);
+ ticket.setNumberOfSupplements(1L);
+ ticket.setServiceBrand(100L);
+ ticket.setPrice(12345L);
+ ticket.setPriceType(PriceTypeType.supplement);
+
+ ticket.setPlaces(getPlaces());
+ ticket.setTariff(getTariffs());
+
+ ticket.setInfoText("reservation");
+ ticket.setClassCode(TravelClassType.first);
+ ticket.setDepartureDate(10L);
+ ticket.setDepartureTime(0L);
+ ticket.setArrivalDate(10L);
+ ticket.setArrivalTime(1439L);
+ tdd.setReservation(ticket);
+ dd.setTicket(tdd);
+ }
+
+
+
+ private static SequenceOfTariffType getTariffs() {
+ SequenceOfTariffType tariffs = new SequenceOfTariffType();
+
+ TariffType tariff = new TariffType();
+ tariff.setNumberOfPassengers(1L);
+ tariff.setRestrictedToCountryOfResidence(false);
+ tariff.setPassengerType(PassengerType.adult);
+ tariff.setTariffIdNum(72L);
+ tariff.setTariffDesc("Full Fare Adult");
+ tariffs.add(tariff);
+ TariffType tariff2 = new TariffType();
+ tariff2.setRestrictedToCountryOfResidence(false);
+ tariff2.setNumberOfPassengers(2L);
+ tariff2.setPassengerType(PassengerType.child);
+ tariff2.setTariffIdNum(73L);
+ tariff2.setTariffDesc("Full Fare Child");
+ tariffs.add(tariff2);
+ return tariffs;
+ }
+
+
+ private static PlacesType getPlaces() {
+ PlacesType places = new PlacesType();
+ places.setPlaceDescription("11-13");
+ places.setCoach("12");
+ return places;
+ }
+
+
+ private static void populateTravelerData(TravelerData td) {
+ td.setGroupName("myGroup");
+ SequenceOfTravelerType trs = new SequenceOfTravelerType();
+ TravelerType tr = new TravelerType();
+ tr.setIdCard("12345");
+ tr.setFirstName("John");
+ tr.setSecondName("Dow");
+ tr.setTicketHolder(true);
+ SequenceOfCustomerStatusType ts = new SequenceOfCustomerStatusType();
+ CustomerStatusType cst = new CustomerStatusType();
+ cst.setCustomerStatusDescr("senior");
+ ts.add(cst);
+ tr.setStatus(ts);
+ trs.add(tr);
+ td.setTraveler(trs);
+ }
+
+ private static void populateIssuingData(IssuingData issuingDetail) {
+ issuingDetail.setIssuingYear(2018L);
+ issuingDetail.setIssuingDay(1L);
+ issuingDetail.setIssuerPNR("issuerTestPNR");
+ issuingDetail.setSpecimen(true);
+ issuingDetail.setSecurePaperTicket(false);
+ issuingDetail.setActivated(true);
+ issuingDetail.setIssuedOnLine(12L);
+ }
+
+
+ private static void populateExtensionSequence(SequenceOfExtensionData ed) {
+ ExtensionData ed1 = new ExtensionData();
+ ed1.setExtensionId("1");
+ byte[] ba1 = { (byte) 0x82, (byte) 0xDA };
+ ed1.setExtensionData(ba1);
+ ExtensionData ed2 = new ExtensionData();
+ ed2.setExtensionId("2");
+ byte[] ba2 = { (byte) 0x83, (byte) 0xDA };
+ ed2.setExtensionData(ba2);
+ ed.add(ed1);
+ ed.add(ed2);
+ }
+
+ private static void populate(ControlData controlDetail) {
+ controlDetail.infoText = "cd";
+ controlDetail.setAgeCheckRequired(false);
+ controlDetail.setIdentificationByIdCard(false);
+ controlDetail.setIdentificationByPassportId(false);
+ controlDetail.setOnlineValidationRequired(false);
+ controlDetail.setPassportValidationRequired(false);
+ controlDetail.setReductionCardCheckRequired(false);
+ controlDetail.setIdentificationByCardReference(new SequenceOfCardReferenceType());
+ controlDetail.getIdentificationByCardReference().add(populateCardRefrence());
+ }
+
+
+ /*
+ {
+ trailingCardIdNum 100
+ }
+ */
+ private static CardReferenceType populateCardRefrence() {
+ CardReferenceType cr = new CardReferenceType();
+ cr.setTrailingCardIdNum(100L);
+ return cr;
+ }
+
+
+
+ }
diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV1.java
new file mode 100644
index 0000000..b0626f1
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV1.java
@@ -0,0 +1,183 @@
+package org.uic.barcode.ticket.api.test.testtickets;
+
+import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8;
+import org.uic.barcode.ticket.api.asn.omv1.CardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv1.ControlData;
+import org.uic.barcode.ticket.api.asn.omv1.CustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv1.DocumentData;
+import org.uic.barcode.ticket.api.asn.omv1.ExtensionData;
+import org.uic.barcode.ticket.api.asn.omv1.IssuingData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfDocumentData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfExtensionData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfTicketLinkType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfTravelerType;
+import org.uic.barcode.ticket.api.asn.omv1.StationPassageData;
+import org.uic.barcode.ticket.api.asn.omv1.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv1.TicketLinkType;
+import org.uic.barcode.ticket.api.asn.omv1.TravelerData;
+import org.uic.barcode.ticket.api.asn.omv1.TravelerType;
+import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
+
+public class StationPassageTestTicketV1 {
+
+
+ public static UicRailTicketData getUicTestTicket() {
+ UicRailTicketData ticket = new UicRailTicketData();
+ populateTicket(ticket);
+ return ticket;
+ }
+
+
+
+ private static void populateTicket(UicRailTicketData ticket) {
+
+ ticket.setControlDetail(new ControlData());
+ populate(ticket.getControlDetail());
+
+
+ ticket.setIssuingDetail(new IssuingData());
+ populateIssuingData(ticket.getIssuingDetail());
+
+ TravelerData td = new TravelerData();
+ populateTravelerData(td);
+ ticket.setTravelerDetail(td);
+
+ SequenceOfDocumentData ds = new SequenceOfDocumentData();
+
+
+ //StationPassage
+ DocumentData do2 = new DocumentData();
+ addStationPassage(do2);
+ ds.add(do2);
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+ /*
+ ticket stationPassage : {
+ productName "passage"
+ ,stationNameUTF8 { "Amsterdam" }
+ ,validFromDay 0
+ ,numberOfDaysValid 123
+ }
+ */
+ private static void addStationPassage(DocumentData dd) {
+ TicketDetailData tdd = new TicketDetailData();
+ StationPassageData sp = new StationPassageData();
+ sp.setProductName("passage");
+ sp.setValidFromDay(5L);
+ sp.setValidFromTime(0L);
+ sp.setValidUntilDay(5L);
+ sp.setValidUntilTime(1000L);
+ sp.setNumberOfDaysValid(5L);
+ SequenceOfStringUTF8 ss = new SequenceOfStringUTF8();
+ ss.add("Amsterdam");
+ sp.setStationNameUTF8(ss);
+ tdd.setStationPassage(sp);
+ dd.setTicket(tdd);
+ }
+
+
+ private static void populateTravelerData(TravelerData td) {
+ td.setGroupName("myGroup");
+ SequenceOfTravelerType trs = new SequenceOfTravelerType();
+ TravelerType tr = new TravelerType();
+ tr.setIdCard("12345");
+ tr.setFirstName("John");
+ tr.setSecondName("Dow");
+ tr.setTicketHolder(true);
+ SequenceOfCustomerStatusType ts = new SequenceOfCustomerStatusType();
+ CustomerStatusType cst = new CustomerStatusType();
+ cst.setCustomerStatusDescr("senior");
+ ts.add(cst);
+ tr.setStatus(ts);
+ trs.add(tr);
+ td.setTraveler(trs);
+ }
+
+ private static void populateIssuingData(IssuingData issuingDetail) {
+ issuingDetail.setIssuingYear(2018L);
+ issuingDetail.setIssuingDay(1L);
+ issuingDetail.setIssuerPNR("issuerTestPNR");
+ issuingDetail.setSpecimen(true);
+ issuingDetail.setSecurePaperTicket(false);
+ issuingDetail.setActivated(true);
+ issuingDetail.setIssuedOnLine(12L);
+ }
+
+ private static void populateExtensionSequence(SequenceOfExtensionData ed) {
+ ExtensionData ed1 = new ExtensionData();
+ ed1.setExtensionId("1");
+ byte[] ba1 = { (byte) 0x82, (byte) 0xDA };
+ ed1.setExtensionData(ba1);
+ ExtensionData ed2 = new ExtensionData();
+ ed2.setExtensionId("2");
+ byte[] ba2 = { (byte) 0x83, (byte) 0xDA };
+ ed2.setExtensionData(ba2);
+ ed.add(ed1);
+ ed.add(ed2);
+ }
+
+ /*
+ ,controlDetail {
+ identificationByCardReference {
+ { trailingCardIdNum 100 }
+ }
+ ,identificationByIdCard FALSE
+ ,identificationByPassportId FALSE
+ ,passportValidationRequired FALSE
+ ,onlineValidationRequired FALSE
+ ,ageCheckRequired FALSE
+ ,reductionCardCheckRequired FALSE
+ ,infoText "cd"
+ ,includedTickets {
+ { productOwnerIA5 "test" }
+ }
+ }
+ */
+ private static void populate(ControlData controlDetail) {
+ controlDetail.infoText = "cd";
+ controlDetail.setAgeCheckRequired(false);
+ controlDetail.setIdentificationByIdCard(false);
+ controlDetail.setIdentificationByPassportId(false);
+ controlDetail.setOnlineValidationRequired(false);
+ controlDetail.setPassportValidationRequired(false);
+ controlDetail.setReductionCardCheckRequired(false);
+ controlDetail.setIdentificationByCardReference(new SequenceOfCardReferenceType());
+ controlDetail.getIdentificationByCardReference().add(populateCardRefrence());
+ SequenceOfTicketLinkType sit = new SequenceOfTicketLinkType();
+ populateLinkedTickets(sit);
+ controlDetail.setIncludedTickets(sit);
+ }
+
+
+ /*
+ *
+ */
+ private static void populateLinkedTickets(SequenceOfTicketLinkType sequenceOfTicketLinkType) {
+ TicketLinkType tlt = new TicketLinkType();
+ tlt.productOwnerIA5="test";
+ sequenceOfTicketLinkType.add(tlt);
+ }
+
+ /*
+ {
+ trailingCardIdNum 100
+ }
+ */
+ private static CardReferenceType populateCardRefrence() {
+ CardReferenceType cr = new CardReferenceType();
+ cr.setTrailingCardIdNum(100L);
+ return cr;
+ }
+
+
+
+}
diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV2.java b/src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV2.java
new file mode 100644
index 0000000..c551293
--- /dev/null
+++ b/src/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV2.java
@@ -0,0 +1,183 @@
+package org.uic.barcode.ticket.api.test.testtickets;
+
+import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8;
+import org.uic.barcode.ticket.api.asn.omv2.CardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv2.ControlData;
+import org.uic.barcode.ticket.api.asn.omv2.CustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv2.DocumentData;
+import org.uic.barcode.ticket.api.asn.omv2.ExtensionData;
+import org.uic.barcode.ticket.api.asn.omv2.IssuingData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfCardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfCustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfDocumentData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfExtensionData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfTicketLinkType;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfTravelerType;
+import org.uic.barcode.ticket.api.asn.omv2.StationPassageData;
+import org.uic.barcode.ticket.api.asn.omv2.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv2.TicketLinkType;
+import org.uic.barcode.ticket.api.asn.omv2.TravelerData;
+import org.uic.barcode.ticket.api.asn.omv2.TravelerType;
+import org.uic.barcode.ticket.api.asn.omv2.UicRailTicketData;
+
+public class StationPassageTestTicketV2 {
+
+
+ public static UicRailTicketData getUicTestTicket() {
+ UicRailTicketData ticket = new UicRailTicketData();
+ populateTicket(ticket);
+ return ticket;
+ }
+
+
+
+ private static void populateTicket(UicRailTicketData ticket) {
+
+ ticket.setControlDetail(new ControlData());
+ populate(ticket.getControlDetail());
+
+
+ ticket.setIssuingDetail(new IssuingData());
+ populateIssuingData(ticket.getIssuingDetail());
+
+ TravelerData td = new TravelerData();
+ populateTravelerData(td);
+ ticket.setTravelerDetail(td);
+
+ SequenceOfDocumentData ds = new SequenceOfDocumentData();
+
+
+ //StationPassage
+ DocumentData do2 = new DocumentData();
+ addStationPassage(do2);
+ ds.add(do2);
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+ /*
+ ticket stationPassage : {
+ productName "passage"
+ ,stationNameUTF8 { "Amsterdam" }
+ ,validFromDay 0
+ ,numberOfDaysValid 123
+ }
+ */
+ private static void addStationPassage(DocumentData dd) {
+ TicketDetailData tdd = new TicketDetailData();
+ StationPassageData sp = new StationPassageData();
+ sp.setProductName("passage");
+ sp.setValidFromDay(5L);
+ sp.setValidFromTime(0L);
+ sp.setValidUntilDay(5L);
+ sp.setValidUntilTime(1000L);
+ sp.setNumberOfDaysValid(5L);
+ SequenceOfStringUTF8 ss = new SequenceOfStringUTF8();
+ ss.add("Amsterdam");
+ sp.setStationNameUTF8(ss);
+ tdd.setStationPassage(sp);
+ dd.setTicket(tdd);
+ }
+
+
+ private static void populateTravelerData(TravelerData td) {
+ td.setGroupName("myGroup");
+ SequenceOfTravelerType trs = new SequenceOfTravelerType();
+ TravelerType tr = new TravelerType();
+ tr.setIdCard("12345");
+ tr.setFirstName("John");
+ tr.setSecondName("Dow");
+ tr.setTicketHolder(true);
+ SequenceOfCustomerStatusType ts = new SequenceOfCustomerStatusType();
+ CustomerStatusType cst = new CustomerStatusType();
+ cst.setCustomerStatusDescr("senior");
+ ts.add(cst);
+ tr.setStatus(ts);
+ trs.add(tr);
+ td.setTraveler(trs);
+ }
+
+ private static void populateIssuingData(IssuingData issuingDetail) {
+ issuingDetail.setIssuingYear(2018L);
+ issuingDetail.setIssuingDay(1L);
+ issuingDetail.setIssuerPNR("issuerTestPNR");
+ issuingDetail.setSpecimen(true);
+ issuingDetail.setSecurePaperTicket(false);
+ issuingDetail.setActivated(true);
+ issuingDetail.setIssuedOnLine(12L);
+ }
+
+ private static void populateExtensionSequence(SequenceOfExtensionData ed) {
+ ExtensionData ed1 = new ExtensionData();
+ ed1.setExtensionId("1");
+ byte[] ba1 = { (byte) 0x82, (byte) 0xDA };
+ ed1.setExtensionData(ba1);
+ ExtensionData ed2 = new ExtensionData();
+ ed2.setExtensionId("2");
+ byte[] ba2 = { (byte) 0x83, (byte) 0xDA };
+ ed2.setExtensionData(ba2);
+ ed.add(ed1);
+ ed.add(ed2);
+ }
+
+ /*
+ ,controlDetail {
+ identificationByCardReference {
+ { trailingCardIdNum 100 }
+ }
+ ,identificationByIdCard FALSE
+ ,identificationByPassportId FALSE
+ ,passportValidationRequired FALSE
+ ,onlineValidationRequired FALSE
+ ,ageCheckRequired FALSE
+ ,reductionCardCheckRequired FALSE
+ ,infoText "cd"
+ ,includedTickets {
+ { productOwnerIA5 "test" }
+ }
+ }
+ */
+ private static void populate(ControlData controlDetail) {
+ controlDetail.infoText = "cd";
+ controlDetail.setAgeCheckRequired(false);
+ controlDetail.setIdentificationByIdCard(false);
+ controlDetail.setIdentificationByPassportId(false);
+ controlDetail.setOnlineValidationRequired(false);
+ controlDetail.setPassportValidationRequired(false);
+ controlDetail.setReductionCardCheckRequired(false);
+ controlDetail.setIdentificationByCardReference(new SequenceOfCardReferenceType());
+ controlDetail.getIdentificationByCardReference().add(populateCardRefrence());
+ SequenceOfTicketLinkType sit = new SequenceOfTicketLinkType();
+ populateLinkedTickets(sit);
+ controlDetail.setIncludedTickets(sit);
+ }
+
+
+ /*
+ *
+ */
+ private static void populateLinkedTickets(SequenceOfTicketLinkType sequenceOfTicketLinkType) {
+ TicketLinkType tlt = new TicketLinkType();
+ tlt.productOwnerIA5="test";
+ sequenceOfTicketLinkType.add(tlt);
+ }
+
+ /*
+ {
+ trailingCardIdNum 100
+ }
+ */
+ private static CardReferenceType populateCardRefrence() {
+ CardReferenceType cr = new CardReferenceType();
+ cr.setTrailingCardIdNum(100L);
+ return cr;
+ }
+
+
+
+}
diff --git a/src/org/uic/barcode/ticket/api/utils/DateTimeUtils.java b/src/org/uic/barcode/ticket/api/utils/DateTimeUtils.java
index a0283c7..c8664a5 100644
--- a/src/org/uic/barcode/ticket/api/utils/DateTimeUtils.java
+++ b/src/org/uic/barcode/ticket/api/utils/DateTimeUtils.java
@@ -110,10 +110,7 @@ public class DateTimeUtils {
}
int time = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
- if (time > 0) {
- return new Long (time );
- }
- return null;
+ return new Long (time );
}
public static Long getTime (Date date) {
@@ -121,18 +118,9 @@ public class DateTimeUtils {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.setTime(date);
-
- if (cal == null ||
- !cal.isSet(Calendar.HOUR_OF_DAY) ||
- !cal.isSet(Calendar.MINUTE) ) {
- return null;
- }
-
+
int time = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
- if (time > 0) {
- return new Long (time );
- }
- return null;
+ return new Long (time );
}
public static Date getDate(Date issuingDate, Long date, Long time){