From 9f75546ee8fe2ad3ab07fee7bd9503340a5174fe Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 22 Mar 2021 11:47:46 +0100 Subject: additional tests for time zones fix for fip ticket --- .../barcode/ticket/api/test/FipTimeZoneTestV2.java | 345 ++++++++++++ .../ticket/api/test/OpenTicketTimeZoneTestV1.java | 345 ++++++++++++ .../ticket/api/test/OpenTicketTimeZoneTestV2.java | 345 ++++++++++++ .../barcode/ticket/api/test/PassTestTicketV1.java | 150 ------ .../api/test/PassTimeZoneTestTicketCase1V1.java | 170 ------ .../api/test/PassTimeZoneTestTicketCase2V1.java | 167 ------ .../api/test/PassTimeZoneTestTicketCase3V1.java | 206 -------- .../ticket/api/test/PassTimeZoneTestV1.java | 124 +++-- .../ticket/api/test/PassTimeZoneTestV2.java | 345 ++++++++++++ .../api/test/SimpleTicketLinkTestTicket.java | 574 -------------------- .../ticket/api/test/SimpleUicTestTicket.java | 244 --------- .../api/test/UperEncodeOpenTicketTestV1.java | 54 ++ .../ticket/api/test/UperEncodePassTestV1.java | 53 ++ .../api/test/UperEncodeTicketLinkTestV1.java | 1 + .../ticket/api/test/UperEncodeTicketTestV1.java | 1 + .../AsnLevelPassTimeZoneTestTicketV1.java | 578 +++++++++++++++++++++ .../test/testtickets/FipTimeZoneTestTicketV1.java | 155 ++++++ .../test/testtickets/FipTimeZoneTestTicketV2.java | 155 ++++++ .../api/test/testtickets/OpenTestTicketV1.java | 578 +++++++++++++++++++++ .../OpenTicketTimeZoneTestTicketV1.java | 157 ++++++ .../OpenTicketTimeZoneTestTicketV2.java | 157 ++++++ .../api/test/testtickets/PassTestTicketV1.java | 150 ++++++ .../testtickets/PassTimeZoneTestTicketCase1V1.java | 168 ++++++ .../testtickets/PassTimeZoneTestTicketCase2V1.java | 165 ++++++ .../testtickets/PassTimeZoneTestTicketCase3V1.java | 204 ++++++++ .../test/testtickets/PassTimeZoneTestTicketV2.java | 168 ++++++ .../testtickets/SimpleTicketLinkTestTicket.java | 574 ++++++++++++++++++++ .../api/test/testtickets/SimpleUicTestTicket.java | 244 +++++++++ 28 files changed, 5022 insertions(+), 1555 deletions(-) create mode 100644 src/org/uic/barcode/ticket/api/test/FipTimeZoneTestV2.java create mode 100644 src/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV2.java delete mode 100644 src/org/uic/barcode/ticket/api/test/PassTestTicketV1.java delete mode 100644 src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase1V1.java delete mode 100644 src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase2V1.java delete mode 100644 src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase3V1.java create mode 100644 src/org/uic/barcode/ticket/api/test/PassTimeZoneTestV2.java delete mode 100644 src/org/uic/barcode/ticket/api/test/SimpleTicketLinkTestTicket.java delete mode 100644 src/org/uic/barcode/ticket/api/test/SimpleUicTestTicket.java create mode 100644 src/org/uic/barcode/ticket/api/test/UperEncodeOpenTicketTestV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/UperEncodePassTestV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/AsnLevelPassTimeZoneTestTicketV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV2.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/OpenTestTicketV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV2.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/PassTestTicketV1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase1V1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase2V1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase3V1.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV2.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/SimpleTicketLinkTestTicket.java create mode 100644 src/org/uic/barcode/ticket/api/test/testtickets/SimpleUicTestTicket.java (limited to 'src/org/uic/barcode/ticket/api/test') 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/PassTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/PassTestTicketV1.java deleted file mode 100644 index 80a337c..0000000 --- a/src/org/uic/barcode/ticket/api/test/PassTestTicketV1.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.uic.barcode.ticket.api.test; - -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.PassData; -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.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.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 PassTestTicketV1 { - - 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(); - addPass(do1); - ds.add(do1); - - ticket.setTransportDocument(ds); - - SequenceOfExtensionData ed = new SequenceOfExtensionData(); - populateExtensionSequence(ed); - ticket.setExtension(ed); - - } - - - private static void addPass(DocumentData dd) { - - TicketDetailData tdd = new TicketDetailData(); - PassData otd = new PassData(); - otd.setInfoText("pass"); - otd.setClassCode(TravelClassType.first); - otd.setPassDescription("ONE COUNTRY"); - 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 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()); - 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/PassTimeZoneTestTicketCase1V1.java b/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase1V1.java deleted file mode 100644 index b037440..0000000 --- a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase1V1.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.uic.barcode.ticket.api.test; - -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.PassData; -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.SequenceOfTicketLinkType; -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.TicketLinkType; -import org.uic.barcode.ticket.api.asn.omv1.TicketType; -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 PassTimeZoneTestTicketCase1V1 { - - 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.setValidFromUTCOffset(0L); - otd.setValidUntilDay(11L); - otd.setValidUntilTime(0L); - otd.setValidUntilUTCOffset(0L); - 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/PassTimeZoneTestTicketCase2V1.java b/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase2V1.java deleted file mode 100644 index 69db492..0000000 --- a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase2V1.java +++ /dev/null @@ -1,167 +0,0 @@ -package org.uic.barcode.ticket.api.test; - -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.PassData; -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.SequenceOfTicketLinkType; -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.TicketLinkType; -import org.uic.barcode.ticket.api.asn.omv1.TicketType; -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 PassTimeZoneTestTicketCase2V1 { - - 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 00:30 UTC - private static void populateIssuingData(IssuingData issuingDetail) { - issuingDetail.setIssuingYear(2021L); - issuingDetail.setIssuingTime(30L); - 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.setValidFromUTCOffset(0L); - otd.setValidUntilDay(11L); - otd.setValidUntilTime(0L); - otd.setValidUntilUTCOffset(0L); - 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/PassTimeZoneTestTicketCase3V1.java b/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase3V1.java deleted file mode 100644 index 8323baa..0000000 --- a/src/org/uic/barcode/ticket/api/test/PassTimeZoneTestTicketCase3V1.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.uic.barcode.ticket.api.test; - -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.PassData; -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.SequenceOfTicketLinkType; -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.TicketLinkType; -import org.uic.barcode.ticket.api.asn.omv1.TicketType; -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 PassTimeZoneTestTicketCase3V1 { - - public static UicRailTicketData getUicTestTicket() { - UicRailTicketData ticket = new UicRailTicketData(); - populateTicket(ticket); - return ticket; - } - - /* - * - * Case 1: - issue date: 04-03-2021 12:30 UTC - issuingYear: 2021 - issuingDay: 63 - issuingTime: 750 - validFromDay: 10 - activatedDays: [0] - utcOffset: 0 - - expected: activated for 04-03-2021 + 10 + 0 00:00 UTC --> 14-03-2021 - - Case 2: - issue date: 04-03-2021 00:30 UTC - issuingYear: 2021 - issuingDay: 63 - issuingTime: 30 - validFromDay: 10 - activatedDays: [0] - utcOffset: 0 - - expected: activated for 04-03-2021 + 10 + 0 00:00 UTC --> 14-03-2021 - - Case 3: - issue date: 03-03-2021 23:30 UTC - issuingYear: 2021 - issuingDay: 62 - issuingTime: 1410 - validFromDay: 11 - activatedDays: [0] - - expected: activated for 03-03-2021 + 11 + 0 00:00 UTC --> 14-03-2021 - - - */ - - - - 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); - - } - - - //03-03-2021 23:30 UTC - private static void populateIssuingData(IssuingData issuingDetail) { - issuingDetail.setIssuingYear(2021L); - issuingDetail.setIssuingTime(1410L); - issuingDetail.setIssuingDay(62L); - 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(11L); - otd.setValidFromTime(0L); - otd.setValidFromUTCOffset(0L); - otd.setValidUntilDay(12L); - otd.setValidUntilTime(0L); - otd.setValidUntilUTCOffset(0L); - 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/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/SimpleTicketLinkTestTicket.java b/src/org/uic/barcode/ticket/api/test/SimpleTicketLinkTestTicket.java deleted file mode 100644 index 483d97e..0000000 --- a/src/org/uic/barcode/ticket/api/test/SimpleTicketLinkTestTicket.java +++ /dev/null @@ -1,574 +0,0 @@ -package org.uic.barcode.ticket.api.test; - - 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.TravelerData; - import org.uic.barcode.ticket.api.asn.omv1.TravelerType; - import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData; - - public class SimpleTicketLinkTestTicket { - - 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" - } - } - ,{ - 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.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/SimpleUicTestTicket.java b/src/org/uic/barcode/ticket/api/test/SimpleUicTestTicket.java deleted file mode 100644 index dc191a5..0000000 --- a/src/org/uic/barcode/ticket/api/test/SimpleUicTestTicket.java +++ /dev/null @@ -1,244 +0,0 @@ -package org.uic.barcode.ticket.api.test; - -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.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.TokenType; -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 SimpleUicTestTicket { - - - 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); - - //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.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"; - 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/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/testtickets/PassTestTicketV1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTestTicketV1.java new file mode 100644 index 0000000..a165308 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTestTicketV1.java @@ -0,0 +1,150 @@ +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.LinkMode; +import org.uic.barcode.ticket.api.asn.omv1.PassData; +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.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.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 PassTestTicketV1 { + + 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(); + addPass(do1); + ds.add(do1); + + ticket.setTransportDocument(ds); + + SequenceOfExtensionData ed = new SequenceOfExtensionData(); + populateExtensionSequence(ed); + ticket.setExtension(ed); + + } + + + private static void addPass(DocumentData dd) { + + TicketDetailData tdd = new TicketDetailData(); + PassData otd = new PassData(); + otd.setInfoText("pass"); + otd.setClassCode(TravelClassType.first); + otd.setPassDescription("ONE COUNTRY"); + 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 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()); + 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/testtickets/PassTimeZoneTestTicketCase1V1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase1V1.java new file mode 100644 index 0000000..8bea50a --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase1V1.java @@ -0,0 +1,168 @@ +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.LinkMode; +import org.uic.barcode.ticket.api.asn.omv1.PassData; +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.SequenceOfTicketLinkType; +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.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv1.TicketType; +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 PassTimeZoneTestTicketCase1V1 { + + 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/testtickets/PassTimeZoneTestTicketCase2V1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase2V1.java new file mode 100644 index 0000000..cc30e72 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase2V1.java @@ -0,0 +1,165 @@ +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.LinkMode; +import org.uic.barcode.ticket.api.asn.omv1.PassData; +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.SequenceOfTicketLinkType; +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.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv1.TicketType; +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 PassTimeZoneTestTicketCase2V1 { + + 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 00:30 UTC + private static void populateIssuingData(IssuingData issuingDetail) { + issuingDetail.setIssuingYear(2021L); + issuingDetail.setIssuingTime(30L); + 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/testtickets/PassTimeZoneTestTicketCase3V1.java b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase3V1.java new file mode 100644 index 0000000..715a292 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketCase3V1.java @@ -0,0 +1,204 @@ +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.LinkMode; +import org.uic.barcode.ticket.api.asn.omv1.PassData; +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.SequenceOfTicketLinkType; +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.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv1.TicketType; +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 PassTimeZoneTestTicketCase3V1 { + + public static UicRailTicketData getUicTestTicket() { + UicRailTicketData ticket = new UicRailTicketData(); + populateTicket(ticket); + return ticket; + } + + /* + * + * Case 1: + issue date: 04-03-2021 12:30 UTC + issuingYear: 2021 + issuingDay: 63 + issuingTime: 750 + validFromDay: 10 + activatedDays: [0] + utcOffset: 0 + + expected: activated for 04-03-2021 + 10 + 0 00:00 UTC --> 14-03-2021 + + Case 2: + issue date: 04-03-2021 00:30 UTC + issuingYear: 2021 + issuingDay: 63 + issuingTime: 30 + validFromDay: 10 + activatedDays: [0] + utcOffset: 0 + + expected: activated for 04-03-2021 + 10 + 0 00:00 UTC --> 14-03-2021 + + Case 3: + issue date: 03-03-2021 23:30 UTC + issuingYear: 2021 + issuingDay: 62 + issuingTime: 1410 + validFromDay: 11 + activatedDays: [0] + + expected: activated for 03-03-2021 + 11 + 0 00:00 UTC --> 14-03-2021 + + + */ + + + + 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); + + } + + + //03-03-2021 23:30 UTC + private static void populateIssuingData(IssuingData issuingDetail) { + issuingDetail.setIssuingYear(2021L); + issuingDetail.setIssuingTime(1410L); + issuingDetail.setIssuingDay(62L); + 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(11L); + 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/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/testtickets/SimpleTicketLinkTestTicket.java b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleTicketLinkTestTicket.java new file mode 100644 index 0000000..d752043 --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleTicketLinkTestTicket.java @@ -0,0 +1,574 @@ +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.TravelerData; + import org.uic.barcode.ticket.api.asn.omv1.TravelerType; + import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData; + + public class SimpleTicketLinkTestTicket { + + 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" + } + } + ,{ + 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.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/SimpleUicTestTicket.java b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleUicTestTicket.java new file mode 100644 index 0000000..d8adb3d --- /dev/null +++ b/src/org/uic/barcode/ticket/api/test/testtickets/SimpleUicTestTicket.java @@ -0,0 +1,244 @@ +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.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.TokenType; +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 SimpleUicTestTicket { + + + 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); + + //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.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"; + sequenceOfTicketLinkType.add(tlt); + } + + /* + { + trailingCardIdNum 100 + } + */ + private static CardReferenceType populateCardRefrence() { + CardReferenceType cr = new CardReferenceType(); + cr.setTrailingCardIdNum(100L); + return cr; + } + + + +} -- cgit v1.2.3