diff options
Diffstat (limited to 'src/org/uic')
34 files changed, 3688 insertions, 179 deletions
diff --git a/src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java b/src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java index af7dcd0..0060fcd 100644 --- a/src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java +++ b/src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java @@ -10,7 +10,7 @@ import org.uic.barcode.dynamicFrame.Level2DataType; import org.uic.barcode.dynamicFrame.SequenceOfDataType;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
-import org.uic.barcode.ticket.api.test.SimpleUicTestTicket;
+import org.uic.barcode.ticket.api.test.testtickets.SimpleUicTestTicket;
public class SimpleDynamicFrameTestBarcode {
diff --git a/src/org/uic/barcode/ticket/api/asn/omv1/FIPTicketData.java b/src/org/uic/barcode/ticket/api/asn/omv1/FIPTicketData.java index 0171ecf..bb0d273 100644 --- a/src/org/uic/barcode/ticket/api/asn/omv1/FIPTicketData.java +++ b/src/org/uic/barcode/ticket/api/asn/omv1/FIPTicketData.java @@ -29,11 +29,15 @@ import org.uic.barcode.asn1.datatypes.Asn1Default; import org.uic.barcode.asn1.datatypes.Asn1Optional;
import org.uic.barcode.asn1.datatypes.CharacterRestriction;
import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
import org.uic.barcode.asn1.datatypes.IntRange;
import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5;
import org.uic.barcode.ticket.api.utils.DateTimeUtils;
+@Sequence
+@HasExtensionMarker
public class FIPTicketData extends Object {
public FIPTicketData() {
}
@@ -254,15 +258,12 @@ public class FIPTicketData extends Object { }
public Date getValidFromDate(Date issuingDate){
-
- return DateTimeUtils.getDate(issuingDate, this.validFromDay,null);
-
+ return DateTimeUtils.getDate(issuingDate, this.validFromDay,0L);
}
public Date getValidUntilDate(Date issuingDate){
if (issuingDate == null) return null;
-
if (this.validFromDay == null) {
this.validFromDay = 0L;
}
@@ -270,60 +271,77 @@ public class FIPTicketData extends Object { if (this.validUntilDay == null) {
return null;
}
-
-
- return DateTimeUtils.getDate(issuingDate, this.validFromDay + this.validUntilDay, null);
-
+ return DateTimeUtils.getDate(issuingDate, this.validFromDay + this.validUntilDay, 1439L);
}
-
public void addActivatedDays(Collection<Long> days) {
-
if (days == null || days.isEmpty()) return;
-
if (this.activatedDay == null) {
this.activatedDay = new SequenceOfActivatedDays();
}
-
for (Long l : days) {
this.activatedDay.add(l);
}
-
}
- public void addActivatedDay(Date issuingDate, Date day){
-
- Long dayDiff = DateTimeUtils.getDateDifference(issuingDate, day);
-
+ /**
+ * Sets the activated days.
+ *
+ * @param dates the dates
+ * @param issuingDate the issuing date
+ * @param validFromDate the valid from date
+ */
+ public void setActivatedDays(Collection<Date> dates, Date issuingDate, Date validFromDate){
+ if (this.activatedDay != null) {
+ this.activatedDay.clear();
+ } else {
+ this.activatedDay= new SequenceOfActivatedDays();
+ }
+ long dateDif = 0L;
+ if (validFromDate != null) {
+ dateDif = DateTimeUtils.getDateDifference(issuingDate,validFromDate);
+ }
+ if (dates != null && !dates.isEmpty()) {
+ for (Date day : dates) {
+ this.addActivatedDay(issuingDate, dateDif, day);
+ }
+ }
+ }
+
+ /**
+ * Adds the activated day.
+ *
+ * @param issuingDate the issuing date in UTC
+ * @param dateOffset the date offset to be added to the issuing date
+ * @param day the day to be added
+ */
+ public void addActivatedDay(Date issuingDate, long dateOffset, Date day){
+ Long vDiff = DateTimeUtils.getDateDifferenceLocal(this.getValidFromDate(issuingDate), day);
if (this.activatedDay == null) {
this.activatedDay = new SequenceOfActivatedDays();
}
-
- if (dayDiff != null) {
- this.activatedDay.add(dayDiff);
+ if (vDiff != null) {
+ this.activatedDay.add(vDiff);
}
-
}
+ /**
+ * Gets the activated days.
+ *
+ * @param issuingDate the issuing date
+ * @return the activated days
+ */
public Collection<Date> getActivatedDays(Date issuingDate) {
-
if (this.activatedDay == null) return null;
-
ArrayList<Date> dates = new ArrayList<Date>();
-
for (Long diff: this.getActivatedDay()) {
-
- Date day = DateTimeUtils.getDate(issuingDate, diff, null);
-
+ Date day = DateTimeUtils.getDate(this.getValidFromDate(issuingDate), diff, null);
if (day != null) {
dates.add(day);
}
-
- }
-
+ }
return dates;
-
}
-
+
}
diff --git a/src/org/uic/barcode/ticket/api/asn/omv1/OpenTicketData.java b/src/org/uic/barcode/ticket/api/asn/omv1/OpenTicketData.java index 0e7a044..7d82232 100644 --- a/src/org/uic/barcode/ticket/api/asn/omv1/OpenTicketData.java +++ b/src/org/uic/barcode/ticket/api/asn/omv1/OpenTicketData.java @@ -595,65 +595,85 @@ public class OpenTicketData extends Object { if (this.validFromDay == null) {
this.validFromDay = 0L;
}
-
if (this.validUntilDay == null) {
return null;
}
-
-
return DateTimeUtils.getDate(issuingDate, this.validFromDay + this.validUntilDay, this.validUntilTime);
}
-
+
public void addActivatedDays(Collection<Long> days) {
-
if (days == null || days.isEmpty()) return;
-
if (this.activatedDay == null) {
this.activatedDay = new SequenceOfActivatedDays();
}
-
for (Long l : days) {
this.activatedDay.add(l);
}
-
}
+ /**
+ * Sets the activated days.
+ *
+ * @param dates the dates
+ * @param issuingDate the issuing date
+ * @param validFromDate the valid from date
+ */
+ public void setActivatedDays(Collection<Date> dates, Date issuingDate, Date validFromDate){
+ if (this.activatedDay != null) {
+ this.activatedDay.clear();
+ } else {
+ this.activatedDay= new SequenceOfActivatedDays();
+ }
+ long dateDif = 0L;
+ if (validFromDate != null) {
+ dateDif = DateTimeUtils.getDateDifference(issuingDate,validFromDate);
+ }
+ if (dates != null && !dates.isEmpty()) {
+ for (Date day : dates) {
+ this.addActivatedDay(issuingDate, dateDif, day);
+ }
+ }
+ }
+
- public void addActivatedDay(Date issuingDate, Date day){
-
- Long dayDiff = DateTimeUtils.getDateDifference(issuingDate, day);
-
+ /**
+ * Adds the activated day.
+ *
+ * @param issuingDate the issuing date in UTC
+ * @param dateOffset the date offset to be added to the issuing date
+ * @param day the day to be added
+ */
+ public void addActivatedDay(Date issuingDate, long dateOffset, Date day){
+ Long vDiff = DateTimeUtils.getDateDifferenceLocal(this.getValidFromDate(issuingDate), day);
if (this.activatedDay == null) {
this.activatedDay = new SequenceOfActivatedDays();
}
-
- if (dayDiff != null) {
- this.activatedDay.add(dayDiff);
+ if (vDiff != null) {
+ this.activatedDay.add(vDiff);
}
-
}
+ /**
+ * Gets the activated days.
+ *
+ * @param issuingDate the issuing date
+ * @return the activated days
+ */
public Collection<Date> getActivatedDays(Date issuingDate) {
-
if (this.activatedDay == null) return null;
-
ArrayList<Date> dates = new ArrayList<Date>();
-
for (Long diff: this.getActivatedDay()) {
-
- Date day = DateTimeUtils.getDate(issuingDate, diff, null);
-
+ Date day = DateTimeUtils.getDate(this.getValidFromDate(issuingDate), diff, null);
if (day != null) {
dates.add(day);
}
-
- }
-
+ }
return dates;
-
}
+
+
public Long getValidFromUTCOffset() {
return validFromUTCOffset;
}
diff --git a/src/org/uic/barcode/ticket/api/asn/omv1/PassData.java b/src/org/uic/barcode/ticket/api/asn/omv1/PassData.java index 1139a80..701b076 100644 --- a/src/org/uic/barcode/ticket/api/asn/omv1/PassData.java +++ b/src/org/uic/barcode/ticket/api/asn/omv1/PassData.java @@ -894,17 +894,14 @@ public class PassData extends Object { public void addActivatedDays(Collection<Long> days) {
-
if (days == null || days.isEmpty()) return;
if (this.activatedDay == null) {
this.activatedDay = new SequenceOfActivatedDays();
}
-
for (Long l : days) {
this.activatedDay.add(l);
}
-
}
/**
@@ -915,26 +912,20 @@ public class PassData extends Object { * @param validFromDate the valid from date
*/
public void setActivatedDays(Collection<Date> dates, Date issuingDate, Date validFromDate){
-
if (this.activatedDay != null) {
this.activatedDay.clear();
} else {
this.activatedDay= new SequenceOfActivatedDays();
}
-
long dateDif = 0L;
if (validFromDate != null) {
dateDif = DateTimeUtils.getDateDifference(issuingDate,validFromDate);
}
-
if (dates != null && !dates.isEmpty()) {
-
for (Date day : dates) {
this.addActivatedDay(issuingDate, dateDif, day);
}
-
}
-
}
/**
@@ -945,19 +936,13 @@ public class PassData extends Object { * @param day the day to be added
*/
public void addActivatedDay(Date issuingDate, long dateOffset, Date day){
-
- Long dayDiff = DateTimeUtils.getDateDifferenceLocal(issuingDate, day);
-
Long vDiff = DateTimeUtils.getDateDifferenceLocal(this.getValidFromDate(issuingDate), day);
-
if (this.activatedDay == null) {
this.activatedDay = new SequenceOfActivatedDays();
}
-
- if (dayDiff != null) {
+ if (vDiff != null) {
this.activatedDay.add(vDiff);
}
-
}
/**
@@ -967,23 +952,15 @@ public class PassData extends Object { * @return the activated days
*/
public Collection<Date> getActivatedDays(Date issuingDate) {
-
if (this.activatedDay == null) return null;
-
ArrayList<Date> dates = new ArrayList<Date>();
-
for (Long diff: this.getActivatedDay()) {
-
Date day = DateTimeUtils.getDate(this.getValidFromDate(issuingDate), diff, null);
-
if (day != null) {
dates.add(day);
}
-
- }
-
+ }
return dates;
-
}
/**
diff --git a/src/org/uic/barcode/ticket/api/asn/omv2/CarCarriageReservationData.java b/src/org/uic/barcode/ticket/api/asn/omv2/CarCarriageReservationData.java index 6b2beb4..4e0bb5f 100644 --- a/src/org/uic/barcode/ticket/api/asn/omv2/CarCarriageReservationData.java +++ b/src/org/uic/barcode/ticket/api/asn/omv2/CarCarriageReservationData.java @@ -33,7 +33,6 @@ import org.uic.barcode.asn1.datatypes.IntRange; import org.uic.barcode.asn1.datatypes.RestrictedString;
import org.uic.barcode.asn1.datatypes.Sequence;
import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5;
-import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCarrierNum;
import org.uic.barcode.ticket.api.utils.DateTimeUtils;
diff --git a/src/org/uic/barcode/ticket/api/asn/omv2/FIPTicketData.java b/src/org/uic/barcode/ticket/api/asn/omv2/FIPTicketData.java index dbf35e2..c6a98e4 100644 --- a/src/org/uic/barcode/ticket/api/asn/omv2/FIPTicketData.java +++ b/src/org/uic/barcode/ticket/api/asn/omv2/FIPTicketData.java @@ -29,12 +29,15 @@ import org.uic.barcode.asn1.datatypes.Asn1Default; import org.uic.barcode.asn1.datatypes.Asn1Optional;
import org.uic.barcode.asn1.datatypes.CharacterRestriction;
import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
import org.uic.barcode.asn1.datatypes.IntRange;
import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5;
-import org.uic.barcode.ticket.api.asn.omv1.SequenceOfActivatedDays;
import org.uic.barcode.ticket.api.utils.DateTimeUtils;
+@Sequence
+@HasExtensionMarker
public class FIPTicketData extends Object {
public FIPTicketData() {
}
@@ -256,7 +259,7 @@ public class FIPTicketData extends Object { public Date getValidFromDate(Date issuingDate){
- return DateTimeUtils.getDate(issuingDate, this.validFromDay,null);
+ return DateTimeUtils.getDate(issuingDate, this.validFromDay,0L);
}
@@ -273,7 +276,7 @@ public class FIPTicketData extends Object { }
- return DateTimeUtils.getDate(issuingDate, this.validFromDay + this.validUntilDay, null);
+ return DateTimeUtils.getDate(issuingDate, this.validFromDay + this.validUntilDay, 1439L);
}
@@ -305,6 +308,12 @@ public class FIPTicketData extends Object { }
+ /**
+ * Gets the activated days.
+ *
+ * @param issuingDate the issuing date
+ * @return the activated days
+ */
public Collection<Date> getActivatedDays(Date issuingDate) {
if (this.activatedDay == null) return null;
@@ -313,7 +322,7 @@ public class FIPTicketData extends Object { for (Long diff: this.getActivatedDay()) {
- Date day = DateTimeUtils.getDate(issuingDate, diff, null);
+ Date day = DateTimeUtils.getDate(this.getValidFromDate(issuingDate), diff, null);
if (day != null) {
dates.add(day);
diff --git a/src/org/uic/barcode/ticket/api/asn/omv2/OpenTicketData.java b/src/org/uic/barcode/ticket/api/asn/omv2/OpenTicketData.java index c0dac70..9900640 100644 --- a/src/org/uic/barcode/ticket/api/asn/omv2/OpenTicketData.java +++ b/src/org/uic/barcode/ticket/api/asn/omv2/OpenTicketData.java @@ -35,7 +35,7 @@ import org.uic.barcode.asn1.datatypes.RestrictedString; import org.uic.barcode.asn1.datatypes.Sequence;
import org.uic.barcode.asn1.datatypes.SizeRange;
import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5;
-import org.uic.barcode.ticket.api.asn.omv1.SequenceOfActivatedDays;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfActivatedDays;
import org.uic.barcode.ticket.api.utils.DateTimeUtils;
@Sequence
@@ -631,6 +631,12 @@ public class OpenTicketData extends Object { }
+ /**
+ * Gets the activated days.
+ *
+ * @param issuingDate the issuing date
+ * @return the activated days
+ */
public Collection<Date> getActivatedDays(Date issuingDate) {
if (this.activatedDay == null) return null;
@@ -639,7 +645,7 @@ public class OpenTicketData extends Object { for (Long diff: this.getActivatedDay()) {
- Date day = DateTimeUtils.getDate(issuingDate, diff, null);
+ Date day = DateTimeUtils.getDate(this.getValidFromDate(issuingDate), diff, null);
if (day != null) {
dates.add(day);
@@ -650,6 +656,7 @@ public class OpenTicketData extends Object { return dates;
}
+
public Long getValidFromUTCOffset() {
return validFromUTCOffset;
}
diff --git a/src/org/uic/barcode/ticket/api/asn/omv2/PassData.java b/src/org/uic/barcode/ticket/api/asn/omv2/PassData.java index b5c8429..dbc81c3 100644 --- a/src/org/uic/barcode/ticket/api/asn/omv2/PassData.java +++ b/src/org/uic/barcode/ticket/api/asn/omv2/PassData.java @@ -34,7 +34,7 @@ import org.uic.barcode.asn1.datatypes.IntRange; import org.uic.barcode.asn1.datatypes.RestrictedString;
import org.uic.barcode.asn1.datatypes.Sequence;
import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5;
-import org.uic.barcode.ticket.api.asn.omv1.SequenceOfActivatedDays;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfActivatedDays;
import org.uic.barcode.ticket.api.utils.DateTimeUtils;
@Sequence
@@ -546,6 +546,12 @@ public class PassData extends Object { }
+ /**
+ * Gets the activated days.
+ *
+ * @param issuingDate the issuing date
+ * @return the activated days
+ */
public Collection<Date> getActivatedDays(Date issuingDate) {
if (this.activatedDay == null) return null;
@@ -554,7 +560,7 @@ public class PassData extends Object { for (Long diff: this.getActivatedDay()) {
- Date day = DateTimeUtils.getDate(issuingDate, diff, null);
+ Date day = DateTimeUtils.getDate(this.getValidFromDate(issuingDate), diff, null);
if (day != null) {
dates.add(day);
diff --git a/src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV2.java b/src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV2.java new file mode 100644 index 0000000..89b6562 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV2.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.omv2.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.FipTimeZoneTestTicketV2; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV2; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV2; + + +/** + * The Class FipTimeZoneTestV1. + * + * + * + */ +public class FipTimeZoneTestV2 { + + /** 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 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 = FipTimeZoneTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket2 = FipTimeZoneTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket3 = FipTimeZoneTestTicketV2.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/OpenTicketTimeZoneTestV1.java b/src/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV1.java new file mode 100644 index 0000000..c2d288e --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV1.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.IOpenTicket; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.OpenTicketTimeZoneTestTicketV1; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder; + + +/** + * The Class FipTimeZoneTestV1. + * + * + * + */ +public class OpenTicketTimeZoneTestV1 { + + /** 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 = OpenTicketTimeZoneTestTicketV1.getUicTestTicket(); + UicRailTicketData ticket2 = OpenTicketTimeZoneTestTicketV1.getUicTestTicket(); + UicRailTicketData ticket3 = OpenTicketTimeZoneTestTicketV1.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 = ((IOpenTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString(); + validFrom2 = ((IOpenTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString(); + validFrom3 = ((IOpenTicket) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString(); + + validUntil1 = ((IOpenTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil2 = ((IOpenTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil3 = ((IOpenTicket) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString(); + + activationDate1 = ((IOpenTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); + activationDate2 = ((IOpenTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); + activationDate3 = ((IOpenTicket) 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); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IOpenTicket) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IOpenTicket) 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); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date); + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date); + ((IOpenTicket) 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); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date); + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date); + ((IOpenTicket) 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/OpenTicketTimeZoneTestV2.java b/src/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV2.java new file mode 100644 index 0000000..ab16716 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV2.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.omv2.UicRailTicketData; +import org.uic.barcode.ticket.api.spec.IOpenTicket; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.OpenTicketTimeZoneTestTicketV2; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV2; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV2; + + +/** + * The Class FipTimeZoneTestV2. + * + * + * + */ +public class OpenTicketTimeZoneTestV2 { + + /** 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 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 = OpenTicketTimeZoneTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket2 = OpenTicketTimeZoneTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket3 = OpenTicketTimeZoneTestTicketV2.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 = ((IOpenTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString(); + validFrom2 = ((IOpenTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString(); + validFrom3 = ((IOpenTicket) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString(); + + validUntil1 = ((IOpenTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil2 = ((IOpenTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil3 = ((IOpenTicket) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString(); + + activationDate1 = ((IOpenTicket) iTicketDecodedCase1.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); + activationDate2 = ((IOpenTicket) iTicketDecodedCase2.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); + activationDate3 = ((IOpenTicket) 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); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IOpenTicket) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IOpenTicket) 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); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date); + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date); + ((IOpenTicket) 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); + ((IOpenTicket) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date); + ((IOpenTicket) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date); + ((IOpenTicket) 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/PassTimeZoneTestV1.java b/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestV1.java index 1c0553f..e7aeae8 100644 --- a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestV1.java +++ b/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestV1.java @@ -1,8 +1,10 @@ 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; @@ -13,6 +15,9 @@ import org.uic.barcode.ticket.EncodingFormatException; import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData; import org.uic.barcode.ticket.api.spec.IPass; import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.PassTimeZoneTestTicketCase1V1; +import org.uic.barcode.ticket.api.test.testtickets.PassTimeZoneTestTicketCase2V1; +import org.uic.barcode.ticket.api.test.testtickets.PassTimeZoneTestTicketCase3V1; import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder; import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder; @@ -112,6 +117,10 @@ public class PassTimeZoneTestV1 { String validFrom2 = null; String validFrom3 = null; + String validUntil1 = null; + String validUntil2 = null; + String validUntil3 = null; + String activationDate1 = null; String activationDate2 = null; String activationDate3 = null; @@ -168,6 +177,10 @@ public class PassTimeZoneTestV1 { 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" )); @@ -193,11 +206,15 @@ public class PassTimeZoneTestV1 { 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" )); @@ -222,20 +239,11 @@ public class PassTimeZoneTestV1 { 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" )); - - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - + + setValidFromTo("2021.03.14-00:00"); + setValidUntilTo("2021.03.24-23:59"); + setActivatedDayTo("2021.03.14-00:00"); + encode("CET"); decode("CET"); decodedDateToStrings(); @@ -248,12 +256,17 @@ public class PassTimeZoneTestV1 { 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. * @@ -272,19 +285,10 @@ public class PassTimeZoneTestV1 { 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" )); - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - + setValidFromTo("2021.03.14-00:00"); + setValidUntilTo("2021.03.24-23:59"); + setActivatedDayTo("2021.03.14-00:00"); + encode("GMT"); decode("CET"); decodedDateToStrings(); @@ -297,6 +301,10 @@ public class PassTimeZoneTestV1 { 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" )); @@ -320,20 +328,11 @@ public class PassTimeZoneTestV1 { 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" )); - - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00")); - - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); - - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear(); - ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().add((new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse("2021.03.14-00:00"))); + setValidFromTo("2021.03.14-00:00"); + setValidUntilTo("2021.03.24-23:59"); + setActivatedDayTo("2021.03.14-00:00"); + encode("CET"); decode("GMT"); decodedDateToStrings(); @@ -346,6 +345,10 @@ public class PassTimeZoneTestV1 { 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" )); @@ -358,17 +361,50 @@ public class PassTimeZoneTestV1 { issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString(); issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString(); - validFrom1 = ((IPass) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString(); validFrom2 = ((IPass) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString(); validFrom3 = ((IPass) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString(); - + + validUntil1 = ((IPass) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil2 = ((IPass) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil3 = ((IPass) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString(); + activationDate1 = ((IPass) iTicketDecodedCase1.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); activationDate2 = ((IPass) iTicketDecodedCase2.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); activationDate3 = ((IPass) 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); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IPass) 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); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date); + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date); + ((IPass) 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); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date); + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date); + ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidUntil(date); + } /** diff --git a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestV2.java b/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestV2.java new file mode 100644 index 0000000..decc26b --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestV2.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.omv2.UicRailTicketData; +import org.uic.barcode.ticket.api.spec.IPass; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.PassTimeZoneTestTicketV2; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV2; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV2; + + +/** + * The Class FipTimeZoneTestV2. + * + * + * + */ +public class PassTimeZoneTestV2 { + + /** 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 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 = PassTimeZoneTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket2 = PassTimeZoneTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket3 = PassTimeZoneTestTicketV2.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 = ((IPass) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString(); + validFrom2 = ((IPass) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString(); + validFrom3 = ((IPass) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString(); + + validUntil1 = ((IPass) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil2 = ((IPass) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntil3 = ((IPass) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString(); + + activationDate1 = ((IPass) iTicketDecodedCase1.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); + activationDate2 = ((IPass) iTicketDecodedCase2.getDocumentData().iterator().next()).getActivatedDays().iterator().next().toString(); + activationDate3 = ((IPass) 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); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).getActivatedDays().add(date); + + ((IPass) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).getActivatedDays().clear(); + ((IPass) 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); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date); + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date); + ((IPass) 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); + ((IPass) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date); + ((IPass) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date); + ((IPass) 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/UperEncodeOpenTicketTestV1.java b/src/org/uic/barcode/ticket/api/test/UperEncodeOpenTicketTestV1.java new file mode 100644 index 0000000..cb20d79 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/UperEncodeOpenTicketTestV1.java @@ -0,0 +1,54 @@ +package org.uic.barcode.ticket.api.test; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.logging.Level; + +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.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.OpenTestTicketV1; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder; + + +public class UperEncodeOpenTicketTestV1 { + + + + @Test public void testDecodeTicket() throws IllegalArgumentException, IllegalAccessException { + UicRailTicketData ticket = OpenTestTicketV1.getUicTestTicket(); + byte[] encoded = UperEncoder.encode(ticket); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + //String expectedHex = "78022020050DD3CF9F5CBCAA65E7D284EA40218A02D000822537B43701A237BB82B164CDA358088373CBBB4EFE40EDAF28EE4DEEAE004A03AD12B01416D08000000004039BDC195B951A58DAD95D125B999BC48088040EE0C2E6E6C2CECA021282DAE6E8CAE4C8C2DA0080BDA60100402C800131B20081013A65E7D00805881416D00B20283DA0"; + //assertEquals(hex,expectedHex); + UicRailTicketData decodedTicket = UperEncoder.decode(encoded, UicRailTicketData.class); + OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder(); + IUicRailTicket iTicket = null; + try { + iTicket = decoder.decodeFromAsn(encoded); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Api2OpenAsnEncoder encoder = new Api2OpenAsnEncoder(); + try { + encoded = encoder.encode(iTicket); + } catch (EncodingFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assert(decodedTicket != null); + assertEquals(decodedTicket.controlDetail.ageCheckRequired , false ); + assertEquals(decodedTicket.controlDetail.getInfoText() , "cd" ); + assertEquals(decodedTicket.controlDetail.getIncludedTickets().get(0).getProductOwnerIA5() , "test" ); + assert(decodedTicket.controlDetail.getIdentificationByCardReference().get(0).getTrailingCardIdNum() == 100L ); + } + +} diff --git a/src/org/uic/barcode/ticket/api/test/UperEncodePassTestV1.java b/src/org/uic/barcode/ticket/api/test/UperEncodePassTestV1.java new file mode 100644 index 0000000..7436f5d --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/UperEncodePassTestV1.java @@ -0,0 +1,53 @@ +package org.uic.barcode.ticket.api.test; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.logging.Level; + +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.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.PassTestTicketV1; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder; + + +public class UperEncodePassTestV1 { + + + @Test public void testDecodeTicket() throws IllegalArgumentException, IllegalAccessException { + UicRailTicketData ticket = PassTestTicketV1.getUicTestTicket(); + byte[] encoded = UperEncoder.encode(ticket); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + + UicRailTicketData decodedTicket = UperEncoder.decode(encoded, UicRailTicketData.class); + + OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder(); + IUicRailTicket iTicket = null; + try { + iTicket = decoder.decodeFromAsn(encoded); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Api2OpenAsnEncoder encoder = new Api2OpenAsnEncoder(); + try { + encoded = encoder.encode(iTicket); + } catch (EncodingFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assert(decodedTicket != null); + assertEquals(decodedTicket.controlDetail.ageCheckRequired , false ); + assertEquals(decodedTicket.controlDetail.getInfoText() , "cd" ); + assertEquals(decodedTicket.controlDetail.getIncludedTickets().get(0).getProductOwnerIA5() , "test" ); + assert(decodedTicket.controlDetail.getIdentificationByCardReference().get(0).getTrailingCardIdNum() == 100L ); + } + +} diff --git a/src/org/uic/barcode/ticket/api/test/UperEncodeTicketLinkTestV1.java b/src/org/uic/barcode/ticket/api/test/UperEncodeTicketLinkTestV1.java index 96d003d..0a4b04c 100644 --- a/src/org/uic/barcode/ticket/api/test/UperEncodeTicketLinkTestV1.java +++ b/src/org/uic/barcode/ticket/api/test/UperEncodeTicketLinkTestV1.java @@ -12,6 +12,7 @@ import org.uic.barcode.ticket.api.spec.ILinkMode; import org.uic.barcode.ticket.api.spec.ITicketLink; import org.uic.barcode.ticket.api.spec.ITicketType; import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.SimpleTicketLinkTestTicket; import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder; diff --git a/src/org/uic/barcode/ticket/api/test/UperEncodeTicketTestV1.java b/src/org/uic/barcode/ticket/api/test/UperEncodeTicketTestV1.java index e2a5558..cf8eec6 100644 --- a/src/org/uic/barcode/ticket/api/test/UperEncodeTicketTestV1.java +++ b/src/org/uic/barcode/ticket/api/test/UperEncodeTicketTestV1.java @@ -7,6 +7,7 @@ import java.util.logging.Level; import org.junit.Test; import org.uic.barcode.asn1.uper.UperEncoder; import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData; +import org.uic.barcode.ticket.api.test.testtickets.SimpleUicTestTicket; public class UperEncodeTicketTestV1 { diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/AsnLevelPassTimeZoneTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/AsnLevelPassTimeZoneTestTicketV1.java new file mode 100644 index 0000000..5408638 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/AsnLevelPassTimeZoneTestTicketV1.java @@ -0,0 +1,578 @@ +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.LinkMode;
+import org.uic.barcode.ticket.api.asn.omv1.OpenTicketData;
+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.TicketType;
+import org.uic.barcode.ticket.api.asn.omv1.TokenType;
+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 AsnLevelPassTimeZoneTestTicketV1 {
+
+ public static UicRailTicketData getUicTestTicket() {
+ UicRailTicketData ticket = new UicRailTicketData();
+ populateTicket(ticket);
+ return ticket;
+ }
+
+ /*
+ value UicRailTicketData ::= {
+ issuingDetail {
+ issuingYear 2018
+ issuingDay 1
+ specimen TRUE,
+ securePaperTicket FALSE,
+ activated TRUE,
+ issuerPNR "issuerTestPNR",
+ issuedOnLine 12
+ }
+ ,travelerDetail{
+ traveler {
+ {
+ firstName "John"
+ ,secondName "Dow"
+ ,idCard "12345"
+ ,ticketHolder TRUE
+ ,status {{customerStatusDescr "senior" }}
+ }
+ }
+ ,groupName "myGroup"
+ }
+ ,transportDocument {
+ {
+ token {tokenProviderIA5 "VDV", token '82DA'H }
+ ,ticket openTicket : {
+ returnIncluded FALSE
+ ,infoText "openTicketInfo"
+ ,classCode "second"
+ }
+ }
+ ,{
+ ticket stationPassage : {
+ productName "passage"
+ ,stationNameUTF8 { "Amsterdam" }
+ ,validFromDay 0
+ ,numberOfDaysValid 123
+ }
+ }
+ }
+ ,controlDetail {
+ identificationByCardReference {
+ { trailingCardIdNum 100 }
+ }
+ ,identificationByIdCard FALSE
+ ,identificationByPassportId FALSE
+ ,passportValidationRequired FALSE
+ ,onlineValidationRequired FALSE
+ ,ageCheckRequired FALSE
+ ,reductionCardCheckRequired FALSE
+ ,infoText "cd"
+ ,includedTickets {
+ { referenceIA5 "UED12435867"
+ ,issuerName "OEBB"
+ ,issuerPNR "PNR"
+ ,productOwnerIA5 "test"
+ ,ticketType pass
+ ,linkMode onlyValidInCombination
+
+ }
+ }
+ }
+ ,extension {
+ { extensionId "1", extensionData '82DA'H }
+ ,{ extensionId "2", extensionData '83DA'H }
+ }
+ }
+ */
+
+ /*
+ * asn.1 version 1.3 encoding:
+Encoding to the file 'data.uper' using PER UNALIGNED encoding rule...
+UicRailTicketData SEQUENCE [root fieldcount (not encoded) = 5]
+ issuingDetail IssuingData SEQUENCE [root fieldcount (not encoded) = 7]
+ issuingYear INTEGER [length (not encoded) = 1.0]
+ 2018
+ issuingDay INTEGER [length (not encoded) = 1.1]
+ 1
+ specimen BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ securePaperTicket BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ activated BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ issuerPNR IA5String [length = 13.0]
+ "issuerTestPNR"
+ issuedOnLine INTEGER [length = 1.0]
+ 12
+ travelerDetail TravelerData SEQUENCE [root fieldcount (not encoded) = 2]
+ traveler SEQUENCE OF [count = 1]
+ TravelerType SEQUENCE [root fieldcount (not encoded) = 5]
+ firstName UTF8String [length = 4.0]
+ 0x4a6f686e
+ secondName UTF8String [length = 3.0]
+ 0x446f77
+ idCard IA5String [length = 5.0]
+ "12345"
+ ticketHolder BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ status SEQUENCE OF [count = 1]
+ CustomerStatusType SEQUENCE [fieldcount (not encoded) = 1]
+ customerStatusDescr IA5String [length = 6.0]
+ "senior"
+ groupName UTF8String [length = 7.0]
+ 0x6d7947726f7570
+ transportDocument SEQUENCE OF [count = 2]
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 2]
+ token TokenType SEQUENCE [fieldcount (not encoded) = 2]
+ tokenProviderIA5 IA5String [length = 3.0]
+ "VDV"
+ token OCTET STRING [length = 2.0]
+ 0x82da
+ ticket CHOICE [index = 2]
+ openTicket OpenTicketData SEQUENCE [root fieldcount (not encoded) = 2]
+ returnIncluded BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 14.0]
+ 0x6f70656e5469636b6574496e666f
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 1]
+ ticket CHOICE [index = 9]
+ stationPassage StationPassageData SEQUENCE [root fieldcount (not encoded) = 4]
+ productName UTF8String [length = 7.0]
+ 0x70617373616765
+ stationNameUTF8 SEQUENCE OF [count = 1]
+ UTF8String [length = 9.0]
+ 0x416d7374657264616d
+ validFromDay INTEGER [length (not encoded) = 1.2]
+ 0
+ numberOfDaysValid INTEGER [length = 1.0]
+ 123
+ controlDetail ControlData SEQUENCE [root fieldcount (not encoded) = 9]
+ identificationByCardReference SEQUENCE OF [count = 1]
+ CardReferenceType SEQUENCE [root fieldcount (not encoded) = 1]
+ trailingCardIdNum INTEGER [length = 1.0]
+ 100
+ identificationByIdCard BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ identificationByPassportId BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ passportValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ onlineValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ageCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ reductionCardCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 2.0]
+ 0x6364
+ includedTickets SEQUENCE OF [count = 1]
+ TicketLinkType SEQUENCE [root fieldcount (not encoded) = 6]
+ referenceIA5 IA5String [length = 11.0]
+ "UED12435867"
+ issuerName UTF8String [length = 4.0]
+ 0x4f454242
+ issuerPNR IA5String [length = 3.0]
+ "PNR"
+ productOwnerIA5 IA5String [length = 4.0]
+ "test"
+ ticketType TicketType ENUMERATED [length (not encoded) = 0.2]
+ 1
+ linkMode LinkMode ENUMERATED [length (not encoded) = 0.1]
+ 1
+ extension SEQUENCE OF [count = 2]
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "1"
+ extensionData OCTET STRING [length = 2.0]
+ 0x82da
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "2"
+ extensionData OCTET STRING [length = 2.0]
+ 0x83da
+Total encoded length = 154.3
+Encoded successfully in 155 bytes:
+78022020 050DD3CF 9F5CBCAA 65E7D284 EA40218A 02D00082 2537B437 01A237BB
+82B164CD A3580883 73CBBB4E FE40EDAF 28EE4DEE AE004A03 AD12B014 16D08000
+00000403 9BDC195B 951A58DA D95D125B 999BC480 88040EE0 C2E6E6C2 CECA0212
+82DAE6E8 CAE4C8C2 DA0080BD A6010040 2C800131 B200ADC2 EAC588C5 93466D5C
+366E089E 8A848407 4275204E 9979F428 100B1028 2DA01640 507B40
+ *
+ *
+ */
+
+ /*
+ * asn.1 version 2.0 encoding
+ *
+ Encoding to the file 'data.uper' using PER UNALIGNED encoding rule...
+UicRailTicketData SEQUENCE [root fieldcount (not encoded) = 5]
+ issuingDetail IssuingData SEQUENCE [root fieldcount (not encoded) = 7]
+ issuingYear INTEGER [length (not encoded) = 1.0]
+ 2018
+ issuingDay INTEGER [length (not encoded) = 1.1]
+ 1
+ specimen BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ securePaperTicket BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ activated BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ issuerPNR IA5String [length = 13.0]
+ "issuerTestPNR"
+ issuedOnLine INTEGER [length = 1.0]
+ 12
+ travelerDetail TravelerData SEQUENCE [root fieldcount (not encoded) = 2]
+ traveler SEQUENCE OF [count = 1]
+ TravelerType SEQUENCE [root fieldcount (not encoded) = 5]
+ firstName UTF8String [length = 4.0]
+ 0x4a6f686e
+ secondName UTF8String [length = 3.0]
+ 0x446f77
+ idCard IA5String [length = 5.0]
+ "12345"
+ ticketHolder BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ status SEQUENCE OF [count = 1]
+ CustomerStatusType SEQUENCE [fieldcount (not encoded) = 1]
+ customerStatusDescr IA5String [length = 6.0]
+ "senior"
+ groupName UTF8String [length = 7.0]
+ 0x6d7947726f7570
+ transportDocument SEQUENCE OF [count = 2]
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 2]
+ token TokenType SEQUENCE [fieldcount (not encoded) = 2]
+ tokenProviderIA5 IA5String [length = 3.0]
+ "VDV"
+ token OCTET STRING [length = 2.0]
+ 0x82da
+ ticket CHOICE [index = 2]
+ openTicket OpenTicketData SEQUENCE [root fieldcount (not encoded) = 2]
+ returnIncluded BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 14.0]
+ 0x6f70656e5469636b6574496e666f
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 1]
+ ticket CHOICE [index = 9]
+ stationPassage StationPassageData SEQUENCE [root fieldcount (not encoded) = 4]
+ productName UTF8String [length = 7.0]
+ 0x70617373616765
+ stationNameUTF8 SEQUENCE OF [count = 1]
+ UTF8String [length = 9.0]
+ 0x416d7374657264616d
+ validFromDay INTEGER [length (not encoded) = 1.2]
+ 0
+ numberOfDaysValid INTEGER [length = 1.0]
+ 123
+ controlDetail ControlData SEQUENCE [root fieldcount (not encoded) = 9]
+ identificationByCardReference SEQUENCE OF [count = 1]
+ CardReferenceType SEQUENCE [root fieldcount (not encoded) = 1]
+ trailingCardIdNum INTEGER [length = 1.0]
+ 100
+ identificationByIdCard BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ identificationByPassportId BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ passportValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ onlineValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ageCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ reductionCardCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 2.0]
+ 0x6364
+ includedTickets SEQUENCE OF [count = 1]
+ TicketLinkType SEQUENCE [root fieldcount (not encoded) = 6]
+ referenceIA5 IA5String [length = 11.0]
+ "UED12435867"
+ issuerName UTF8String [length = 4.0]
+ 0x4f454242
+ issuerPNR IA5String [length = 3.0]
+ "PNR"
+ productOwnerIA5 IA5String [length = 4.0]
+ "test"
+ ticketType TicketType ENUMERATED [length (not encoded) = 0.2]
+ 1
+ linkMode LinkMode ENUMERATED [length (not encoded) = 0.1]
+ 1
+ extension SEQUENCE OF [count = 2]
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "1"
+ extensionData OCTET STRING [length = 2.0]
+ 0x82da
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "2"
+ extensionData OCTET STRING [length = 2.0]
+ 0x83da
+Total encoded length = 154.6
+Encoded successfully in 155 bytes:
+78022020 050DD3CF 9F5CBCAA 65E7D284 EA40218A 02D00041 129BDA1B 80D11BDD
+C158B266 D1AC0441 B9E5DDA7 7F2076D7 947726F7 57002501 D689580A 0B684000
+00000200 737B832B 72A34B1B 5B2BA24B 73337890 110081DC 185CDCD8 59D94042
+505B5CDD 195C9918 5B401017 B4C02008 05900026 364015B8 5D58B118 B268CDAB
+86CDC113 D1509080 E84EA409 D32F3E85 02016205 05B402C8 0A0F68
+ *
+ *
+ *
+ */
+
+ public static String getEncodingV1Hex() {
+ return "78022020050DD3CF9F5CBCAA65E7D284EA40218A02D000822537B43701A237BB" +
+ "82B164CDA358088373CBBB4EFE40EDAF28EE4DEEAE004A03AD12B01416D08000" +
+ "000004039BDC195B951A58DAD95D125B999BC48088040EE0C2E6E6C2CECA0212" +
+ "82DAE6E8CAE4C8C2DA0080BDA60100402C800131B200ADC2EAC588C593466D5C" +
+ "366E089E8A8484074275204E9979F428100B10282DA01640507B40";
+ }
+
+ public static String getEncodingV2Hex() {
+ return "78022020050DD3CF9F5CBCAA65E7D284EA40218A02D00041129BDA1B80D11BDD" +
+ "C158B266D1AC0441B9E5DDA77F2076D7947726F757002501D689580A0B684000" +
+ "00000200737B832B72A34B1B5B2BA24B73337890110081DC185CDCD859D94042" +
+ "505B5CDD195C99185B401017B4C0200805900026364015B85D58B118B268CDAB" +
+ "86CDC113D1509080E84EA409D32F3E850201620505B402C80A0F68";
+ }
+
+
+ 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();
+ addOpenTicketData(do1);
+ ds.add(do1);
+
+ //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(0L);
+ sp.setNumberOfDaysValid(123L);
+ SequenceOfStringUTF8 ss = new SequenceOfStringUTF8();
+ ss.add("Amsterdam");
+ sp.setStationNameUTF8(ss);
+ tdd.setStationPassage(sp);
+ dd.setTicket(tdd);
+ }
+
+ /*
+ {
+ token {tokenProviderIA5 "VDV", token '82DA'H }
+ ,ticket openTicket : {
+ returnIncluded FALSE
+ infoText "openTicketInfo"
+ }
+ }
+ */
+
+
+
+ private static void addOpenTicketData(DocumentData dd) {
+ TokenType to = new TokenType();
+ to.setTokenProviderIA5("VDV");
+ byte[] ba = { (byte) 0x82, (byte) 0xDA };
+ to.setToken(ba);
+ dd.setToken(to);
+
+ TicketDetailData tdd = new TicketDetailData();
+ OpenTicketData otd = new OpenTicketData();
+ otd.setInfoText("openTicketInfo");
+ otd.setClassCode(TravelClassType.first);
+ otd.setReturnIncluded(false);
+ tdd.setOpenTicket(otd);
+ dd.setTicket(tdd);
+ }
+
+
+ /*
+ ,travelerDetail{
+ traveler {
+ {
+ firstName "John"
+ ,secondName "Dow"
+ ,idCard "12345"
+ ,ticketHolder TRUE
+ ,status {{customerStatusDescr "senior" }}
+ }
+ }
+ ,groupName "myGroup"
+ }
+ */
+
+ 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);
+ }
+
+ /*
+ ,issuingDetail {
+ issuingYear 2018
+ issuingDay 1
+ specimen TRUE,
+ securePaperTicket FALSE,
+ activated TRUE,
+ issuerPNR "issuerTestPNR",
+ issuedOnLine 12
+ }
+ */
+ 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);
+ }
+
+ /*
+ ,extension {
+ { extensionId "1", extensionData '82DA'H }
+ ,{ extensionId "2", extensionData '83DA'H }
+ }
+ */
+ 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";
+ tlt.setTicketType(TicketType.pass);
+ tlt.setIssuerPNR("PNR");
+ tlt.setReferenceIA5("UED12435867");
+ tlt.setLinkMode(LinkMode.onlyValidInCombination);
+ tlt.setIssuerName("OEBB");
+ 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/FipTimeZoneTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV1.java new file mode 100644 index 0000000..bfd54fe --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV1.java @@ -0,0 +1,155 @@ +package org.uic.barcode.ticket.api.test.testtickets;
+
+import org.uic.barcode.asn1.datatypes.Asn1BigInteger;
+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.FIPTicketData;
+import org.uic.barcode.ticket.api.asn.omv1.IssuingData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfActivatedDays;
+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.SequenceOfTravelerType;
+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 FipTimeZoneTestTicketV1 {
+
+ 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();
+
+
+ //FipTicket
+ DocumentData do1 = new DocumentData();
+ addFip(do1);
+ ds.add(do1);
+
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+ //issue date: 04-03-2021 12:30 UTC
+ private static void populateIssuingData(IssuingData issuingDetail) {
+ issuingDetail.setIssuingYear(2021L);
+ issuingDetail.setIssuingTime(750L);
+ issuingDetail.setIssuingDay(63L);
+ issuingDetail.setIssuerPNR("issuerTestPNR");
+ issuingDetail.setSpecimen(true);
+ issuingDetail.setSecurePaperTicket(false);
+ issuingDetail.setActivated(true);
+ issuingDetail.setIssuedOnLine(12L);
+ }
+
+ private static void addFip(DocumentData dd) {
+
+ TicketDetailData tdd = new TicketDetailData();
+ FIPTicketData otd = new FIPTicketData();
+ otd.setClassCode(TravelClassType.first);
+ otd.setNumberOfTravelDays(8L);
+ otd.setValidFromDay(10L);
+ otd.setValidUntilDay(10L);
+ SequenceOfCarrierNum carriers = new SequenceOfCarrierNum();
+ carriers.add(1080L);
+ carriers.add(1181L);
+ otd.setCarrierNum(carriers);
+ otd.setIncludesSupplements(true);
+ otd.setReferenceNum(Asn1BigInteger.toAsn1(123456789));
+ SequenceOfActivatedDays s = new SequenceOfActivatedDays();
+ s.add(0L);
+ otd.setActivatedDay(s);
+
+ tdd.setFipTicket(otd);
+ dd.setTicket(tdd);
+ }
+
+
+
+ private static void populateTravelerData(TravelerData td) {
+ 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("employee");
+ ts.add(cst);
+ tr.setStatus(ts);
+ trs.add(tr);
+ td.setTraveler(trs);
+ }
+
+
+
+
+
+ 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());
+ }
+
+
+ private static CardReferenceType populateCardRefrence() {
+ CardReferenceType cr = new CardReferenceType();
+ cr.setTrailingCardIdNum(100L);
+ return cr;
+ }
+
+
+
+ }
diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV2.java b/src/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV2.java new file mode 100644 index 0000000..08b4507 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV2.java @@ -0,0 +1,155 @@ +package org.uic.barcode.ticket.api.test.testtickets;
+
+import org.uic.barcode.asn1.datatypes.Asn1BigInteger;
+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.FIPTicketData;
+import org.uic.barcode.ticket.api.asn.omv2.IssuingData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfActivatedDays;
+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.SequenceOfTravelerType;
+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 FipTimeZoneTestTicketV2 {
+
+ 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();
+
+
+ //FipTicket
+ DocumentData do1 = new DocumentData();
+ addFip(do1);
+ ds.add(do1);
+
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+ //issue date: 04-03-2021 12:30 UTC
+ private static void populateIssuingData(IssuingData issuingDetail) {
+ issuingDetail.setIssuingYear(2021L);
+ issuingDetail.setIssuingTime(750L);
+ issuingDetail.setIssuingDay(63L);
+ issuingDetail.setIssuerPNR("issuerTestPNR");
+ issuingDetail.setSpecimen(true);
+ issuingDetail.setSecurePaperTicket(false);
+ issuingDetail.setActivated(true);
+ issuingDetail.setIssuedOnLine(12L);
+ }
+
+ private static void addFip(DocumentData dd) {
+
+ TicketDetailData tdd = new TicketDetailData();
+ FIPTicketData otd = new FIPTicketData();
+ otd.setClassCode(TravelClassType.first);
+ otd.setNumberOfTravelDays(8L);
+ otd.setValidFromDay(10L);
+ otd.setValidUntilDay(10L);
+ SequenceOfCarrierNum carriers = new SequenceOfCarrierNum();
+ carriers.add(1080L);
+ carriers.add(1181L);
+ otd.setCarrierNum(carriers);
+ otd.setIncludesSupplements(true);
+ otd.setReferenceNum(Asn1BigInteger.toAsn1(123445));
+ SequenceOfActivatedDays s = new SequenceOfActivatedDays();
+ s.add(0L);
+ otd.setActivatedDay(s);
+
+ tdd.setFipTicket(otd);
+ dd.setTicket(tdd);
+ }
+
+
+
+ private static void populateTravelerData(TravelerData td) {
+ 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("employee");
+ ts.add(cst);
+ tr.setStatus(ts);
+ trs.add(tr);
+ td.setTraveler(trs);
+ }
+
+
+
+
+
+ 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());
+ }
+
+
+ private static CardReferenceType populateCardRefrence() {
+ CardReferenceType cr = new CardReferenceType();
+ cr.setTrailingCardIdNum(100L);
+ return cr;
+ }
+
+
+
+ }
diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/OpenTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/OpenTestTicketV1.java new file mode 100644 index 0000000..69a61a9 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/OpenTestTicketV1.java @@ -0,0 +1,578 @@ +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.LinkMode;
+import org.uic.barcode.ticket.api.asn.omv1.OpenTicketData;
+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.TicketType;
+import org.uic.barcode.ticket.api.asn.omv1.TokenType;
+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 OpenTestTicketV1 {
+
+ public static UicRailTicketData getUicTestTicket() {
+ UicRailTicketData ticket = new UicRailTicketData();
+ populateTicket(ticket);
+ return ticket;
+ }
+
+ /*
+ value UicRailTicketData ::= {
+ issuingDetail {
+ issuingYear 2018
+ issuingDay 1
+ specimen TRUE,
+ securePaperTicket FALSE,
+ activated TRUE,
+ issuerPNR "issuerTestPNR",
+ issuedOnLine 12
+ }
+ ,travelerDetail{
+ traveler {
+ {
+ firstName "John"
+ ,secondName "Dow"
+ ,idCard "12345"
+ ,ticketHolder TRUE
+ ,status {{customerStatusDescr "senior" }}
+ }
+ }
+ ,groupName "myGroup"
+ }
+ ,transportDocument {
+ {
+ token {tokenProviderIA5 "VDV", token '82DA'H }
+ ,ticket openTicket : {
+ returnIncluded FALSE
+ ,infoText "openTicketInfo"
+ ,classCode "second"
+ }
+ }
+ ,{
+ ticket stationPassage : {
+ productName "passage"
+ ,stationNameUTF8 { "Amsterdam" }
+ ,validFromDay 0
+ ,numberOfDaysValid 123
+ }
+ }
+ }
+ ,controlDetail {
+ identificationByCardReference {
+ { trailingCardIdNum 100 }
+ }
+ ,identificationByIdCard FALSE
+ ,identificationByPassportId FALSE
+ ,passportValidationRequired FALSE
+ ,onlineValidationRequired FALSE
+ ,ageCheckRequired FALSE
+ ,reductionCardCheckRequired FALSE
+ ,infoText "cd"
+ ,includedTickets {
+ { referenceIA5 "UED12435867"
+ ,issuerName "OEBB"
+ ,issuerPNR "PNR"
+ ,productOwnerIA5 "test"
+ ,ticketType pass
+ ,linkMode onlyValidInCombination
+
+ }
+ }
+ }
+ ,extension {
+ { extensionId "1", extensionData '82DA'H }
+ ,{ extensionId "2", extensionData '83DA'H }
+ }
+ }
+ */
+
+ /*
+ * asn.1 version 1.3 encoding:
+Encoding to the file 'data.uper' using PER UNALIGNED encoding rule...
+UicRailTicketData SEQUENCE [root fieldcount (not encoded) = 5]
+ issuingDetail IssuingData SEQUENCE [root fieldcount (not encoded) = 7]
+ issuingYear INTEGER [length (not encoded) = 1.0]
+ 2018
+ issuingDay INTEGER [length (not encoded) = 1.1]
+ 1
+ specimen BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ securePaperTicket BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ activated BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ issuerPNR IA5String [length = 13.0]
+ "issuerTestPNR"
+ issuedOnLine INTEGER [length = 1.0]
+ 12
+ travelerDetail TravelerData SEQUENCE [root fieldcount (not encoded) = 2]
+ traveler SEQUENCE OF [count = 1]
+ TravelerType SEQUENCE [root fieldcount (not encoded) = 5]
+ firstName UTF8String [length = 4.0]
+ 0x4a6f686e
+ secondName UTF8String [length = 3.0]
+ 0x446f77
+ idCard IA5String [length = 5.0]
+ "12345"
+ ticketHolder BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ status SEQUENCE OF [count = 1]
+ CustomerStatusType SEQUENCE [fieldcount (not encoded) = 1]
+ customerStatusDescr IA5String [length = 6.0]
+ "senior"
+ groupName UTF8String [length = 7.0]
+ 0x6d7947726f7570
+ transportDocument SEQUENCE OF [count = 2]
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 2]
+ token TokenType SEQUENCE [fieldcount (not encoded) = 2]
+ tokenProviderIA5 IA5String [length = 3.0]
+ "VDV"
+ token OCTET STRING [length = 2.0]
+ 0x82da
+ ticket CHOICE [index = 2]
+ openTicket OpenTicketData SEQUENCE [root fieldcount (not encoded) = 2]
+ returnIncluded BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 14.0]
+ 0x6f70656e5469636b6574496e666f
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 1]
+ ticket CHOICE [index = 9]
+ stationPassage StationPassageData SEQUENCE [root fieldcount (not encoded) = 4]
+ productName UTF8String [length = 7.0]
+ 0x70617373616765
+ stationNameUTF8 SEQUENCE OF [count = 1]
+ UTF8String [length = 9.0]
+ 0x416d7374657264616d
+ validFromDay INTEGER [length (not encoded) = 1.2]
+ 0
+ numberOfDaysValid INTEGER [length = 1.0]
+ 123
+ controlDetail ControlData SEQUENCE [root fieldcount (not encoded) = 9]
+ identificationByCardReference SEQUENCE OF [count = 1]
+ CardReferenceType SEQUENCE [root fieldcount (not encoded) = 1]
+ trailingCardIdNum INTEGER [length = 1.0]
+ 100
+ identificationByIdCard BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ identificationByPassportId BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ passportValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ onlineValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ageCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ reductionCardCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 2.0]
+ 0x6364
+ includedTickets SEQUENCE OF [count = 1]
+ TicketLinkType SEQUENCE [root fieldcount (not encoded) = 6]
+ referenceIA5 IA5String [length = 11.0]
+ "UED12435867"
+ issuerName UTF8String [length = 4.0]
+ 0x4f454242
+ issuerPNR IA5String [length = 3.0]
+ "PNR"
+ productOwnerIA5 IA5String [length = 4.0]
+ "test"
+ ticketType TicketType ENUMERATED [length (not encoded) = 0.2]
+ 1
+ linkMode LinkMode ENUMERATED [length (not encoded) = 0.1]
+ 1
+ extension SEQUENCE OF [count = 2]
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "1"
+ extensionData OCTET STRING [length = 2.0]
+ 0x82da
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "2"
+ extensionData OCTET STRING [length = 2.0]
+ 0x83da
+Total encoded length = 154.3
+Encoded successfully in 155 bytes:
+78022020 050DD3CF 9F5CBCAA 65E7D284 EA40218A 02D00082 2537B437 01A237BB
+82B164CD A3580883 73CBBB4E FE40EDAF 28EE4DEE AE004A03 AD12B014 16D08000
+00000403 9BDC195B 951A58DA D95D125B 999BC480 88040EE0 C2E6E6C2 CECA0212
+82DAE6E8 CAE4C8C2 DA0080BD A6010040 2C800131 B200ADC2 EAC588C5 93466D5C
+366E089E 8A848407 4275204E 9979F428 100B1028 2DA01640 507B40
+ *
+ *
+ */
+
+ /*
+ * asn.1 version 2.0 encoding
+ *
+ Encoding to the file 'data.uper' using PER UNALIGNED encoding rule...
+UicRailTicketData SEQUENCE [root fieldcount (not encoded) = 5]
+ issuingDetail IssuingData SEQUENCE [root fieldcount (not encoded) = 7]
+ issuingYear INTEGER [length (not encoded) = 1.0]
+ 2018
+ issuingDay INTEGER [length (not encoded) = 1.1]
+ 1
+ specimen BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ securePaperTicket BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ activated BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ issuerPNR IA5String [length = 13.0]
+ "issuerTestPNR"
+ issuedOnLine INTEGER [length = 1.0]
+ 12
+ travelerDetail TravelerData SEQUENCE [root fieldcount (not encoded) = 2]
+ traveler SEQUENCE OF [count = 1]
+ TravelerType SEQUENCE [root fieldcount (not encoded) = 5]
+ firstName UTF8String [length = 4.0]
+ 0x4a6f686e
+ secondName UTF8String [length = 3.0]
+ 0x446f77
+ idCard IA5String [length = 5.0]
+ "12345"
+ ticketHolder BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ status SEQUENCE OF [count = 1]
+ CustomerStatusType SEQUENCE [fieldcount (not encoded) = 1]
+ customerStatusDescr IA5String [length = 6.0]
+ "senior"
+ groupName UTF8String [length = 7.0]
+ 0x6d7947726f7570
+ transportDocument SEQUENCE OF [count = 2]
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 2]
+ token TokenType SEQUENCE [fieldcount (not encoded) = 2]
+ tokenProviderIA5 IA5String [length = 3.0]
+ "VDV"
+ token OCTET STRING [length = 2.0]
+ 0x82da
+ ticket CHOICE [index = 2]
+ openTicket OpenTicketData SEQUENCE [root fieldcount (not encoded) = 2]
+ returnIncluded BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 14.0]
+ 0x6f70656e5469636b6574496e666f
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 1]
+ ticket CHOICE [index = 9]
+ stationPassage StationPassageData SEQUENCE [root fieldcount (not encoded) = 4]
+ productName UTF8String [length = 7.0]
+ 0x70617373616765
+ stationNameUTF8 SEQUENCE OF [count = 1]
+ UTF8String [length = 9.0]
+ 0x416d7374657264616d
+ validFromDay INTEGER [length (not encoded) = 1.2]
+ 0
+ numberOfDaysValid INTEGER [length = 1.0]
+ 123
+ controlDetail ControlData SEQUENCE [root fieldcount (not encoded) = 9]
+ identificationByCardReference SEQUENCE OF [count = 1]
+ CardReferenceType SEQUENCE [root fieldcount (not encoded) = 1]
+ trailingCardIdNum INTEGER [length = 1.0]
+ 100
+ identificationByIdCard BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ identificationByPassportId BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ passportValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ onlineValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ageCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ reductionCardCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 2.0]
+ 0x6364
+ includedTickets SEQUENCE OF [count = 1]
+ TicketLinkType SEQUENCE [root fieldcount (not encoded) = 6]
+ referenceIA5 IA5String [length = 11.0]
+ "UED12435867"
+ issuerName UTF8String [length = 4.0]
+ 0x4f454242
+ issuerPNR IA5String [length = 3.0]
+ "PNR"
+ productOwnerIA5 IA5String [length = 4.0]
+ "test"
+ ticketType TicketType ENUMERATED [length (not encoded) = 0.2]
+ 1
+ linkMode LinkMode ENUMERATED [length (not encoded) = 0.1]
+ 1
+ extension SEQUENCE OF [count = 2]
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "1"
+ extensionData OCTET STRING [length = 2.0]
+ 0x82da
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "2"
+ extensionData OCTET STRING [length = 2.0]
+ 0x83da
+Total encoded length = 154.6
+Encoded successfully in 155 bytes:
+78022020 050DD3CF 9F5CBCAA 65E7D284 EA40218A 02D00041 129BDA1B 80D11BDD
+C158B266 D1AC0441 B9E5DDA7 7F2076D7 947726F7 57002501 D689580A 0B684000
+00000200 737B832B 72A34B1B 5B2BA24B 73337890 110081DC 185CDCD8 59D94042
+505B5CDD 195C9918 5B401017 B4C02008 05900026 364015B8 5D58B118 B268CDAB
+86CDC113 D1509080 E84EA409 D32F3E85 02016205 05B402C8 0A0F68
+ *
+ *
+ *
+ */
+
+ public static String getEncodingV1Hex() {
+ return "78022020050DD3CF9F5CBCAA65E7D284EA40218A02D000822537B43701A237BB" +
+ "82B164CDA358088373CBBB4EFE40EDAF28EE4DEEAE004A03AD12B01416D08000" +
+ "000004039BDC195B951A58DAD95D125B999BC48088040EE0C2E6E6C2CECA0212" +
+ "82DAE6E8CAE4C8C2DA0080BDA60100402C800131B200ADC2EAC588C593466D5C" +
+ "366E089E8A8484074275204E9979F428100B10282DA01640507B40";
+ }
+
+ public static String getEncodingV2Hex() {
+ return "78022020050DD3CF9F5CBCAA65E7D284EA40218A02D00041129BDA1B80D11BDD" +
+ "C158B266D1AC0441B9E5DDA77F2076D7947726F757002501D689580A0B684000" +
+ "00000200737B832B72A34B1B5B2BA24B73337890110081DC185CDCD859D94042" +
+ "505B5CDD195C99185B401017B4C0200805900026364015B85D58B118B268CDAB" +
+ "86CDC113D1509080E84EA409D32F3E850201620505B402C80A0F68";
+ }
+
+
+ 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();
+ addOpenTicketData(do1);
+ ds.add(do1);
+
+ //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(0L);
+ sp.setNumberOfDaysValid(123L);
+ SequenceOfStringUTF8 ss = new SequenceOfStringUTF8();
+ ss.add("Amsterdam");
+ sp.setStationNameUTF8(ss);
+ tdd.setStationPassage(sp);
+ dd.setTicket(tdd);
+ }
+
+ /*
+ {
+ token {tokenProviderIA5 "VDV", token '82DA'H }
+ ,ticket openTicket : {
+ returnIncluded FALSE
+ infoText "openTicketInfo"
+ }
+ }
+ */
+
+
+
+ private static void addOpenTicketData(DocumentData dd) {
+ TokenType to = new TokenType();
+ to.setTokenProviderIA5("VDV");
+ byte[] ba = { (byte) 0x82, (byte) 0xDA };
+ to.setToken(ba);
+ dd.setToken(to);
+
+ TicketDetailData tdd = new TicketDetailData();
+ OpenTicketData otd = new OpenTicketData();
+ otd.setInfoText("openTicketInfo");
+ otd.setClassCode(TravelClassType.first);
+ otd.setReturnIncluded(false);
+ tdd.setOpenTicket(otd);
+ dd.setTicket(tdd);
+ }
+
+
+ /*
+ ,travelerDetail{
+ traveler {
+ {
+ firstName "John"
+ ,secondName "Dow"
+ ,idCard "12345"
+ ,ticketHolder TRUE
+ ,status {{customerStatusDescr "senior" }}
+ }
+ }
+ ,groupName "myGroup"
+ }
+ */
+
+ 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);
+ }
+
+ /*
+ ,issuingDetail {
+ issuingYear 2018
+ issuingDay 1
+ specimen TRUE,
+ securePaperTicket FALSE,
+ activated TRUE,
+ issuerPNR "issuerTestPNR",
+ issuedOnLine 12
+ }
+ */
+ 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);
+ }
+
+ /*
+ ,extension {
+ { extensionId "1", extensionData '82DA'H }
+ ,{ extensionId "2", extensionData '83DA'H }
+ }
+ */
+ 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";
+ tlt.setTicketType(TicketType.pass);
+ tlt.setIssuerPNR("PNR");
+ tlt.setReferenceIA5("UED12435867");
+ tlt.setLinkMode(LinkMode.onlyValidInCombination);
+ tlt.setIssuerName("OEBB");
+ 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/OpenTicketTimeZoneTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV1.java new file mode 100644 index 0000000..5ca6b73 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV1.java @@ -0,0 +1,157 @@ +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.OpenTicketData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfActivatedDays;
+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.SequenceOfTravelerType;
+import org.uic.barcode.ticket.api.asn.omv1.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv1.TokenType;
+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 OpenTicketTimeZoneTestTicketV1 {
+
+ 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();
+ addOpenTicketData(do1);
+ ds.add(do1);
+
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+
+ private static void addOpenTicketData(DocumentData dd) {
+ TokenType to = new TokenType();
+ to.setTokenProviderIA5("VDV");
+ byte[] ba = { (byte) 0x82, (byte) 0xDA };
+ to.setToken(ba);
+ dd.setToken(to);
+
+ TicketDetailData tdd = new TicketDetailData();
+ OpenTicketData otd = new OpenTicketData();
+ otd.setInfoText("openTicketInfo");
+ otd.setClassCode(TravelClassType.first);
+ otd.setReturnIncluded(false);
+ otd.setValidFromDay(10L);
+ otd.setValidFromTime(0L);
+ otd.setValidUntilDay(10L);
+ otd.setValidUntilTime(1439L);
+ SequenceOfActivatedDays s = new SequenceOfActivatedDays();
+ otd.setActivatedDay(s);
+ s.add(0L);
+ tdd.setOpenTicket(otd);
+ 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);
+ }
+
+ 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/OpenTicketTimeZoneTestTicketV2.java b/src/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV2.java new file mode 100644 index 0000000..3acc754 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV2.java @@ -0,0 +1,157 @@ +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.OpenTicketData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfActivatedDays;
+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.SequenceOfTravelerType;
+import org.uic.barcode.ticket.api.asn.omv2.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv2.TokenType;
+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 OpenTicketTimeZoneTestTicketV2 {
+
+ 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();
+ addOpenTicketData(do1);
+ ds.add(do1);
+
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+
+ private static void addOpenTicketData(DocumentData dd) {
+ TokenType to = new TokenType();
+ to.setTokenProviderIA5("VDV");
+ byte[] ba = { (byte) 0x82, (byte) 0xDA };
+ to.setToken(ba);
+ dd.setToken(to);
+
+ TicketDetailData tdd = new TicketDetailData();
+ OpenTicketData otd = new OpenTicketData();
+ otd.setInfoText("openTicketInfo");
+ otd.setClassCode(TravelClassType.first);
+ otd.setReturnIncluded(false);
+ otd.setValidFromDay(10L);
+ otd.setValidFromTime(0L);
+ otd.setValidUntilDay(10L);
+ otd.setValidUntilTime(1439L);
+ SequenceOfActivatedDays s = new SequenceOfActivatedDays();
+ otd.setActivatedDay(s);
+ s.add(0L);
+ tdd.setOpenTicket(otd);
+ 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);
+ }
+
+ 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/PassTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTestTicketV1.java index 80a337c..a165308 100644 --- a/src/org/uic/barcode/ticket/api/test/PassTestTicketV1.java +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTestTicketV1.java @@ -1,4 +1,4 @@ -package org.uic.barcode.ticket.api.test;
+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;
diff --git a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase1V1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase1V1.java index b037440..8bea50a 100644 --- a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase1V1.java +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase1V1.java @@ -1,4 +1,4 @@ -package org.uic.barcode.ticket.api.test;
+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;
@@ -85,10 +85,8 @@ import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData; otd.setPassDescription("ONE COUNTRY");
otd.setValidFromDay(10L);
otd.setValidFromTime(0L);
- otd.setValidFromUTCOffset(0L);
- otd.setValidUntilDay(11L);
- otd.setValidUntilTime(0L);
- otd.setValidUntilUTCOffset(0L);
+ otd.setValidUntilDay(10L);
+ otd.setValidUntilTime(1439L);
SequenceOfActivatedDays s = new SequenceOfActivatedDays();
otd.setActivatedDay(s);
s.add(0L);
diff --git a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase2V1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase2V1.java index 69db492..cc30e72 100644 --- a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase2V1.java +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase2V1.java @@ -1,4 +1,4 @@ -package org.uic.barcode.ticket.api.test;
+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;
@@ -86,10 +86,8 @@ import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData; otd.setPassDescription("ONE COUNTRY");
otd.setValidFromDay(10L);
otd.setValidFromTime(0L);
- otd.setValidFromUTCOffset(0L);
- otd.setValidUntilDay(11L);
- otd.setValidUntilTime(0L);
- otd.setValidUntilUTCOffset(0L);
+ otd.setValidUntilDay(10L);
+ otd.setValidUntilTime(1439L);
SequenceOfActivatedDays s = new SequenceOfActivatedDays();
otd.setActivatedDay(s);
s.add(0L);
diff --git a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase3V1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase3V1.java index 8323baa..715a292 100644 --- a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase3V1.java +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase3V1.java @@ -1,4 +1,4 @@ -package org.uic.barcode.ticket.api.test;
+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;
@@ -122,10 +122,8 @@ import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData; otd.setPassDescription("ONE COUNTRY");
otd.setValidFromDay(11L);
otd.setValidFromTime(0L);
- otd.setValidFromUTCOffset(0L);
- otd.setValidUntilDay(12L);
- otd.setValidUntilTime(0L);
- otd.setValidUntilUTCOffset(0L);
+ otd.setValidUntilDay(10L);
+ otd.setValidUntilTime(1439L);
SequenceOfActivatedDays s = new SequenceOfActivatedDays();
otd.setActivatedDay(s);
s.add(0L);
diff --git a/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV2.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV2.java new file mode 100644 index 0000000..7539f0d --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV2.java @@ -0,0 +1,168 @@ +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.LinkMode;
+import org.uic.barcode.ticket.api.asn.omv2.PassData;
+import org.uic.barcode.ticket.api.asn.omv2.SequenceOfActivatedDays;
+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.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv2.TicketLinkType;
+import org.uic.barcode.ticket.api.asn.omv2.TicketType;
+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 PassTimeZoneTestTicketV2 {
+
+ 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();
+ addPass1(do1);
+ ds.add(do1);
+
+
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+ //issue date: 04-03-2021 12:30 UTC
+ private static void populateIssuingData(IssuingData issuingDetail) {
+ issuingDetail.setIssuingYear(2021L);
+ issuingDetail.setIssuingTime(750L);
+ issuingDetail.setIssuingDay(63L);
+ issuingDetail.setIssuerPNR("issuerTestPNR");
+ issuingDetail.setSpecimen(true);
+ issuingDetail.setSecurePaperTicket(false);
+ issuingDetail.setActivated(true);
+ issuingDetail.setIssuedOnLine(12L);
+ }
+
+ private static void addPass1(DocumentData dd) {
+
+ TicketDetailData tdd = new TicketDetailData();
+ PassData otd = new PassData();
+ otd.setInfoText("pass");
+ otd.setClassCode(TravelClassType.first);
+ otd.setPassDescription("ONE COUNTRY");
+ otd.setValidFromDay(10L);
+ otd.setValidFromTime(0L);
+ otd.setValidUntilDay(10L);
+ otd.setValidUntilTime(1439L);
+ SequenceOfActivatedDays s = new SequenceOfActivatedDays();
+ otd.setActivatedDay(s);
+ s.add(0L);
+
+ tdd.setPass(otd);
+ 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 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());
+ SequenceOfTicketLinkType sit = new SequenceOfTicketLinkType();
+ populateLinkedTickets(sit);
+ controlDetail.setIncludedTickets(sit);
+ }
+
+ private static void populateLinkedTickets(SequenceOfTicketLinkType sequenceOfTicketLinkType) {
+ TicketLinkType tlt = new TicketLinkType();
+ tlt.productOwnerIA5="test";
+ tlt.setTicketType(TicketType.pass);
+ tlt.setIssuerPNR("PNR");
+ tlt.setReferenceIA5("UED12435867");
+ tlt.setLinkMode(LinkMode.onlyValidInCombination);
+ tlt.setIssuerName("OEBB");
+ sequenceOfTicketLinkType.add(tlt);
+ }
+
+ private static CardReferenceType populateCardRefrence() {
+ CardReferenceType cr = new CardReferenceType();
+ cr.setTrailingCardIdNum(100L);
+ return cr;
+ }
+
+
+
+ }
diff --git a/src/org/uic/barcode/ticket/api/test/SimpleTicketLinkTestTicket.java b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleTicketLinkTestTicket.java index 483d97e..d752043 100644 --- a/src/org/uic/barcode/ticket/api/test/SimpleTicketLinkTestTicket.java +++ b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleTicketLinkTestTicket.java @@ -1,4 +1,4 @@ -package org.uic.barcode.ticket.api.test;
+package org.uic.barcode.ticket.api.test.testtickets;
import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8;
import org.uic.barcode.ticket.api.asn.omv1.CardReferenceType;
diff --git a/src/org/uic/barcode/ticket/api/test/SimpleUicTestTicket.java b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleUicTestTicket.java index dc191a5..d8adb3d 100644 --- a/src/org/uic/barcode/ticket/api/test/SimpleUicTestTicket.java +++ b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleUicTestTicket.java @@ -1,4 +1,4 @@ -package org.uic.barcode.ticket.api.test;
+package org.uic.barcode.ticket.api.test.testtickets;
import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8;
import org.uic.barcode.ticket.api.asn.omv1.CardReferenceType;
diff --git a/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java b/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java index 5bc419c..d3136e1 100644 --- a/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java +++ b/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java @@ -881,7 +881,9 @@ public class Api2OpenAsnEncoder { asnData.setTariffs(encodeTariffCollection(document.getTariffs()));
- asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ if (document.getActivatedDays() != null && !document.getActivatedDays().isEmpty()) {
+ asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ }
if (document.getClassCode() != ITravelClassType.second){
asnData.setClassCode(convertTravelClass(document.getClassCode()));
@@ -1557,8 +1559,9 @@ public class Api2OpenAsnEncoder { }
}
-
- asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ if (document.getActivatedDays() != null && !document.getActivatedDays().isEmpty()) {
+ asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ }
asnData.setClassCode(convertTravelClass(document.getClassCode()));
@@ -1691,7 +1694,9 @@ public class Api2OpenAsnEncoder { asnData.setValidityDates(document.getValidFrom(), document.getValidUntil(), issuingDate);
- asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ if (document.getActivatedDays() != null && !document.getActivatedDays().isEmpty()) {
+ asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ }
asnData.setExtension(encodeExtension(document.getExtension()));
diff --git a/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java b/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java index 48583b9..61bdba1 100644 --- a/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java +++ b/src/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java @@ -886,8 +886,9 @@ public class Api2OpenAsnEncoderV2 { asnData.setTariffs(encodeTariffCollection(document.getTariffs()));
- asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
-
+ if (document.getActivatedDays() != null && !document.getActivatedDays().isEmpty()) {
+ asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ }
if (document.getClassCode() != ITravelClassType.second && document.getClassCode() != null){
asnData.setClassCode(TravelClassType.valueOf(document.getClassCode().name()));
}
@@ -1562,8 +1563,9 @@ public class Api2OpenAsnEncoderV2 { }
}
- asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
-
+ if (document.getActivatedDays() != null && !document.getActivatedDays().isEmpty()) {
+ asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ }
if (document.getClassCode() != null) {
asnData.setClassCode(TravelClassType.valueOf(document.getClassCode().name()));
}
@@ -1697,8 +1699,9 @@ public class Api2OpenAsnEncoderV2 { asnData.setValidityDates(document.getValidFrom(), document.getValidUntil(), issuingDate);
- asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
-
+ if (document.getActivatedDays() != null && !document.getActivatedDays().isEmpty()) {
+ asnData.addActivatedDays(DateTimeUtils.getActivatedDays(document.getValidFrom(), document.getActivatedDays()));
+ }
asnData.setExtension(encodeExtension(document.getExtension()));
return asnDocument;
diff --git a/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java b/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java index 46d2c1b..d203487 100644 --- a/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java +++ b/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java @@ -1593,9 +1593,9 @@ public class OpenAsn2ApiDecoder { document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5()));
document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5()));
- if (asnDocument.getActivatedDay()!=null && !asnDocument.getActivatedDay().isEmpty()) {
- document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
- }
+ if (asnDocument.getActivatedDay() != null && !asnDocument.getActivatedDay().isEmpty()) {
+ document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
+ }
if(asnDocument.getIncludesSupplements()!=null) {
document.setIncludesSupplements(asnDocument.getIncludesSupplements());
@@ -1632,7 +1632,9 @@ public class OpenAsn2ApiDecoder { document.setValidUntil(asnDocument.getValidUntilDate(issuingDate));
document.setValidUntilUTCoffset(asnDocument.getValidUntilUTCOffset());
- document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
+ if (asnDocument.getActivatedDay() != null && !asnDocument.getActivatedDay().isEmpty()) {
+ document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
+ }
document.setExtension(convertExtension(asnDocument.getExtension()));
document.setInfoText(asnDocument.getInfoText());
diff --git a/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java b/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java index c6eac0e..b8ee363 100644 --- a/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java +++ b/src/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java @@ -1621,9 +1621,9 @@ public class OpenAsn2ApiDecoderV2 { document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5()));
document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5()));
- if (asnDocument.getActivatedDay()!=null && !asnDocument.getActivatedDay().isEmpty()) {
- document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
- }
+ if (asnDocument.getActivatedDay() != null && !asnDocument.getActivatedDay().isEmpty()) {
+ document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
+ }
if(asnDocument.getIncludesSupplements()!=null) {
document.setIncludesSupplements(asnDocument.getIncludesSupplements());
@@ -1660,13 +1660,9 @@ public class OpenAsn2ApiDecoderV2 { document.setValidUntil(asnDocument.getValidUntilDate(issuingDate));
document.setValidUntilUTCoffset(asnDocument.getValidUntilUTCOffset());
- if (asnDocument.getActivatedDay()!=null && !asnDocument.getActivatedDay().isEmpty()) {
- if (document.getValidFrom() != null) {
- document.getActivatedDays().addAll(asnDocument.getActivatedDays(document.getValidFrom()));
- } else {
- document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
- }
- }
+ if (asnDocument.getActivatedDay() != null && !asnDocument.getActivatedDay().isEmpty()) {
+ document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate));
+ }
document.setExtension(convertExtension(asnDocument.getExtension()));
document.setInfoText(asnDocument.getInfoText());
|