From 67bd1413dc47ec37a9ba042949973eff0a5045fd Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 29 Jun 2021 14:59:45 +0200 Subject: - test for FCB version 3 --- .../test/DynamicFrameDoubleSignatureTest.java | 57 +-- .../uic/barcode/test/DynamicFrameSimpleTest.java | 5 +- .../java/org/uic/barcode/test/utils/TestUtils.java | 5 +- .../api/test/CustomerCardTimeZoneTestV3.java | 314 +++++++++++++++ .../barcode/ticket/api/test/FipTimeZoneTestV3.java | 347 +++++++++++++++++ .../ticket/api/test/OpenTicketComplexTestV3.java | 95 +++++ .../ticket/api/test/OpenTicketTimeZoneTestV3.java | 347 +++++++++++++++++ .../ticket/api/test/ParkingTimeZoneTestV3.java | 314 +++++++++++++++ .../barcode/ticket/api/test/PassComplexTestV3.java | 92 +++++ .../ticket/api/test/PassTimeZoneTestV3.java | 347 +++++++++++++++++ .../ticket/api/test/ReservationTimeZoneTestV3.java | 314 +++++++++++++++ .../api/test/StationPassageTimeZoneTestV3.java | 314 +++++++++++++++ .../ticket/api/test/VoucherTimeZoneTestV2.java | 20 +- .../ticket/api/test/VoucherTimeZoneTestV3.java | 314 +++++++++++++++ .../test/testtickets/CustomerCardTestTicketV3.java | 170 ++++++++ .../test/testtickets/FipTimeZoneTestTicketV3.java | 155 ++++++++ .../test/testtickets/OpenTestComplexTicketV3.java | 413 ++++++++++++++++++++ .../OpenTicketTimeZoneTestTicketV3.java | 158 ++++++++ .../api/test/testtickets/ParkingTestTicketV3.java | 147 +++++++ .../api/test/testtickets/PassComplexTicketV3.java | 431 +++++++++++++++++++++ .../test/testtickets/PassTimeZoneTestTicketV3.java | 168 ++++++++ .../test/testtickets/ReservationTestTicketV3.java | 202 ++++++++++ .../testtickets/StationPassageTestTicketV3.java | 184 +++++++++ .../api/test/testtickets/VoucherTestTicketV3.java | 141 +++++++ 24 files changed, 4985 insertions(+), 69 deletions(-) create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/CustomerCardTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/FipTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/OpenTicketComplexTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/ParkingTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/PassComplexTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/PassTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/CustomerCardTestTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTestComplexTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/ParkingTestTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/PassComplexTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV3.java create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/testtickets/VoucherTestTicketV3.java (limited to 'src/test/java/org/uic/barcode') diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java index aa377e8..a316cfc 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java @@ -26,7 +26,6 @@ import org.uic.barcode.test.utils.Level2TestDataFactory; import org.uic.barcode.test.utils.SimpleUICTestTicket; import org.uic.barcode.ticket.EncodingFormatException; import org.uic.barcode.ticket.api.spec.IUicRailTicket; -import org.uic.barcode.utils.AlgorithmNameResolver; public class DynamicFrameDoubleSignatureTest { @@ -59,54 +58,12 @@ public class DynamicFrameDoubleSignatureTest { assert(keyPairLevel1 != null); + assert(keyPairLevel2 != null); + } - @Test public void testDynamicHeaderBarcodeEncoding() { - - IUicRailTicket ticket = testFCBticket; - Encoder enc = null; - - try { - enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 13); - } catch (IOException | EncodingFormatException e1) { - assert(false); - } - - assert(enc != null); - - try { - enc.setLevel1Algs(signatureAlgorithmOID, keyPairAlgorithmOID); - enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID,keyPairLevel2.getPublic()); - enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1"); - } catch (Exception e) { - assert(false); - } - - assert(enc != null); - - try { - enc.setLevel2Data(Level2TestDataFactory.getLevel2SimpleTestData()); - enc.signLevel2(keyPairLevel2.getPrivate()); - } catch (Exception e) { - assert(false); - } - - - byte[] encoded = null; - try { - encoded = enc.encode(); - } catch (Exception e) { - assert(false); - } - - assert(encoded != null); - - - - } - @Test public void testDynamicHeaderBarcodeDecoding() { IUicRailTicket ticket = testFCBticket; @@ -164,7 +121,7 @@ public class DynamicFrameDoubleSignatureTest { int signatureCheck = 0; try { - signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(),null); + signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(), null); } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException | UnsupportedOperationException | IOException | EncodingFormatException e) { assert(false); @@ -177,8 +134,7 @@ public class DynamicFrameDoubleSignatureTest { } catch (IllegalArgumentException | UnsupportedOperationException e) { assert(false); } - assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK); - + assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK); DataType level2DataDec = dec.getLevel2Data(); @@ -186,7 +142,6 @@ public class DynamicFrameDoubleSignatureTest { assert(Arrays.equals(level2Data.getData().toByteArray(),level2DataDec.getData().toByteArray())); SimpleUICTestTicket.compare(ticket, dec.getUicTicket()); - } @@ -199,9 +154,7 @@ public class DynamicFrameDoubleSignatureTest { public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{ - String keyAlgorithmName = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, keyAlgorithmOid, "BC"); - - keyAlgorithmName = "ECDSA"; + String keyAlgorithmName = "ECDSA"; ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve); KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC"); g.initialize(ecSpec, new SecureRandom()); diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameSimpleTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameSimpleTest.java index a3a1b0e..190924d 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameSimpleTest.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameSimpleTest.java @@ -23,7 +23,6 @@ import org.uic.barcode.dynamicFrame.Constants; import org.uic.barcode.test.utils.SimpleUICTestTicket; import org.uic.barcode.ticket.EncodingFormatException; import org.uic.barcode.ticket.api.spec.IUicRailTicket; -import org.uic.barcode.utils.AlgorithmNameResolver; public class DynamicFrameSimpleTest { @@ -158,9 +157,7 @@ public class DynamicFrameSimpleTest { public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{ - String keyAlgorithmName = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, keyAlgorithmOid, "BC"); - - keyAlgorithmName = "ECDSA"; + String keyAlgorithmName = "ECDSA"; ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve); KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC"); g.initialize(ecSpec, new SecureRandom()); diff --git a/src/test/java/org/uic/barcode/test/utils/TestUtils.java b/src/test/java/org/uic/barcode/test/utils/TestUtils.java index 20a21c4..9791b02 100644 --- a/src/test/java/org/uic/barcode/test/utils/TestUtils.java +++ b/src/test/java/org/uic/barcode/test/utils/TestUtils.java @@ -12,7 +12,6 @@ import java.util.Date; import org.bouncycastle.jce.ECNamedCurveTable; import org.bouncycastle.jce.spec.ECParameterSpec; -import org.uic.barcode.utils.AlgorithmNameResolver; public class TestUtils { @@ -61,9 +60,7 @@ public class TestUtils { public static KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{ - String keyAlgorithmName = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, keyAlgorithmOid, "BC"); - - keyAlgorithmName = "ECDSA"; + String keyAlgorithmName = "ECDSA"; ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve); KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC"); g.initialize(ecSpec, new SecureRandom()); diff --git a/src/test/java/org/uic/barcode/ticket/api/test/CustomerCardTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/CustomerCardTimeZoneTestV3.java new file mode 100644 index 0000000..da0879b --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/CustomerCardTimeZoneTestV3.java @@ -0,0 +1,314 @@ +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.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.spec.ICustomerCard; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.CustomerCardTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class CustomerCardTestV1. + * + * + * + */ +public class CustomerCardTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** The API ticket low level encoded for case 1. */ + IUicRailTicket iTicketDecodedFromAsn1Case1 = null; + + /** The API ticket low level encoded for case 2. */ + IUicRailTicket iTicketDecodedFromAsn1Case2 = null; + + /** The API ticket low level encoded for case 3. */ + IUicRailTicket iTicketDecodedFromAsn1Case3 = null; + + + /** The ticket decoded 1. */ + IUicRailTicket iTicketDecodedCase1 = null; + + /** The i ticket decoded 2. */ + IUicRailTicket iTicketDecodedCase2 = null; + + /** The i ticket decoded 3. */ + IUicRailTicket iTicketDecodedCase3 = null; + + byte[] encodedInTimeZone1 = null; + byte[] encodedInTimeZone2 = null; + byte[] encodedInTimeZone3 = null; + + String issuingDate1 = null; + String issuingDate2 = null; + String issuingDate3 = null; + + String validFromDate1 = null; + String validFromDate2 = null; + String validFromDate3 = null; + + String validUntilDate1 = null; + String validUntilDate2 = null; + String validUntilDate3 = null; + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + defaulttimeZone = TimeZone.getDefault(); + + UicRailTicketData ticket1 = CustomerCardTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = CustomerCardTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = CustomerCardTestTicketV3.getUicTestTicket(); + + //encode in UTC time zone + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + + encoded1 = UperEncoder.encode(ticket1); + encoded2 = UperEncoder.encode(ticket2); + encoded3 = UperEncoder.encode(ticket3); + + } + + /** + * clean up + */ + @After public void resetTimeZone() { + TimeZone.setDefault(defaulttimeZone); + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone CET + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setValidUntilDateTo("2022.03.24-23:59"); + + encode("CET"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(validUntilDate1.equals("Thu Mar 24 23:59:00 CET 2022" )); + assert(validUntilDate2.equals("Thu Mar 24 23:59:00 CET 2022" )); + assert(validUntilDate3.equals("Thu Mar 24 23:59:00 CET 2022" )); + + + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setValidUntilDateTo("2021.03.24-23:59"); + + encode("GMT"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setValidUntilDateTo("2022.03.24-23:59"); + + encode("CET"); + decode("GMT"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" )); + assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" )); + assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 GMT 2021" )); + + assert(validUntilDate1.equals("Thu Mar 24 23:59:00 GMT 2022" )); + assert(validUntilDate2.equals("Thu Mar 24 23:59:00 GMT 2022" )); + assert(validUntilDate3.equals("Thu Mar 24 23:59:00 GMT 2022" )); + + + } + + private void decodedDateToStrings() { + + issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString(); + issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString(); + issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString(); + + validFromDate1 = ((ICustomerCard) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString(); + validFromDate2 = ((ICustomerCard) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString(); + validFromDate3 = ((ICustomerCard) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString(); + + validUntilDate1 = ((ICustomerCard) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntilDate2 = ((ICustomerCard) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntilDate3 = ((ICustomerCard) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString(); + + + } + + + private void setValidFromDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((ICustomerCard) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date); + ((ICustomerCard) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date); + ((ICustomerCard) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(date); + } + + private void setValidUntilDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((ICustomerCard) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date); + ((ICustomerCard) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date); + ((ICustomerCard) 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/test/java/org/uic/barcode/ticket/api/test/FipTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/FipTimeZoneTestV3.java new file mode 100644 index 0000000..a4c542e --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/FipTimeZoneTestV3.java @@ -0,0 +1,347 @@ +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.omv3.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.FipTimeZoneTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class FipTimeZoneTestV1. + * + * + * + */ +public class FipTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** 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 = FipTimeZoneTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = FipTimeZoneTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = FipTimeZoneTestTicketV3.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/test/java/org/uic/barcode/ticket/api/test/OpenTicketComplexTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/OpenTicketComplexTestV3.java new file mode 100644 index 0000000..d39a0ba --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/OpenTicketComplexTestV3.java @@ -0,0 +1,95 @@ +package org.uic.barcode.ticket.api.test; + +import java.text.ParseException; +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.api.asn.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.test.testtickets.OpenTestComplexTicketV3; + + +/** + * The Class FipTimeZoneTestV3. + * + * + * + */ +public class OpenTicketComplexTestV3 { + + + + /** The ticket decoded 1. */ + UicRailTicketData ticket = null; + + byte[] encodedInTimeZone1 = null; + + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + defaulttimeZone = TimeZone.getDefault(); + + //encode in UTC time zone + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + + + } + + /** + * 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 decoding() { + + //get tickets + String hex = OpenTestComplexTicketV3.getEncodingHex(); + byte[] content = UperEncoder.bytesFromHexString(hex); + ticket = UperEncoder.decode(content, UicRailTicketData.class); + + assert(ticket != null); + + } + + @Test public void encoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + String hex = OpenTestComplexTicketV3.getEncodingHex(); + byte[] content = UperEncoder.bytesFromHexString(hex); + ticket = UperEncoder.decode(content, UicRailTicketData.class); + + + //ticket = OpenTestComplexTicketV2.getUicTestTicket(); + byte[] encoded = UperEncoder.encode(ticket); + + + + assert(encoded != null); + assert(encoded.length > 20); + + String encodedHex = UperEncoder.hexStringFromBytes(encoded); + String expectedHex = OpenTestComplexTicketV3.getEncodingHex(); + + assert(expectedHex.equals(encodedHex)); + + } + + +} diff --git a/src/test/java/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV3.java new file mode 100644 index 0000000..236d8b0 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/OpenTicketTimeZoneTestV3.java @@ -0,0 +1,347 @@ +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.omv3.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.OpenTicketTimeZoneTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class FipTimeZoneTestV2. + * + * + * + */ +public class OpenTicketTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** 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 = OpenTicketTimeZoneTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = OpenTicketTimeZoneTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = OpenTicketTimeZoneTestTicketV3.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/test/java/org/uic/barcode/ticket/api/test/ParkingTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/ParkingTimeZoneTestV3.java new file mode 100644 index 0000000..88c7a6e --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/ParkingTimeZoneTestV3.java @@ -0,0 +1,314 @@ +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.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.spec.IParkingGround; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.ParkingTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class ParkingTestV3. + * + * + * + */ +public class ParkingTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** 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 FromParkingDateDate1 = null; + String FromParkingDateDate2 = null; + String FromParkingDateDate3 = null; + + String ToParkingDateDate1 = null; + String ToParkingDateDate2 = null; + String ToParkingDateDate3 = null; + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + defaulttimeZone = TimeZone.getDefault(); + + UicRailTicketData ticket1 = ParkingTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = ParkingTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = ParkingTestTicketV3.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" )); + + setFromParkingDateDateTo("2021.03.14-00:00"); + setToParkingDateDateTo("2021.03.24-23:59"); + + encode("CET"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(FromParkingDateDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(FromParkingDateDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(FromParkingDateDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(ToParkingDateDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(ToParkingDateDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(ToParkingDateDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setFromParkingDateDateTo("2021.03.14-00:00"); + setToParkingDateDateTo("2021.03.24-23:59"); + + encode("GMT"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(FromParkingDateDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(FromParkingDateDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(FromParkingDateDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(ToParkingDateDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(ToParkingDateDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(ToParkingDateDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setFromParkingDateDateTo("2021.03.14-00:00"); + setToParkingDateDateTo("2021.03.24-23:59"); + + encode("CET"); + decode("GMT"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" )); + assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" )); + assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" )); + + assert(FromParkingDateDate1.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(FromParkingDateDate2.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(FromParkingDateDate3.equals("Sun Mar 14 00:00:00 GMT 2021" )); + + assert(ToParkingDateDate1.equals("Wed Mar 24 23:59:00 GMT 2021" )); + assert(ToParkingDateDate2.equals("Wed Mar 24 23:59:00 GMT 2021" )); + assert(ToParkingDateDate3.equals("Wed Mar 24 23:59:00 GMT 2021" )); + + + } + + private void decodedDateToStrings() { + + issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString(); + issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString(); + issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString(); + + FromParkingDateDate1 = ((IParkingGround) iTicketDecodedCase1.getDocumentData().iterator().next()).getFromParkingDate().toString(); + FromParkingDateDate2 = ((IParkingGround) iTicketDecodedCase2.getDocumentData().iterator().next()).getFromParkingDate().toString(); + FromParkingDateDate3 = ((IParkingGround) iTicketDecodedCase3.getDocumentData().iterator().next()).getFromParkingDate().toString(); + + ToParkingDateDate1 = ((IParkingGround) iTicketDecodedCase1.getDocumentData().iterator().next()).getToParkingDate().toString(); + ToParkingDateDate2 = ((IParkingGround) iTicketDecodedCase2.getDocumentData().iterator().next()).getToParkingDate().toString(); + ToParkingDateDate3 = ((IParkingGround) iTicketDecodedCase3.getDocumentData().iterator().next()).getToParkingDate().toString(); + + + } + + + private void setFromParkingDateDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IParkingGround) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setFromParkingDate(date); + ((IParkingGround) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setFromParkingDate(date); + ((IParkingGround) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setFromParkingDate(date); + } + + private void setToParkingDateDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IParkingGround) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setToParkingDate(date); + ((IParkingGround) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setToParkingDate(date); + ((IParkingGround) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setToParkingDate(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/test/java/org/uic/barcode/ticket/api/test/PassComplexTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/PassComplexTestV3.java new file mode 100644 index 0000000..de7fe88 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/PassComplexTestV3.java @@ -0,0 +1,92 @@ +package org.uic.barcode.ticket.api.test; + +import java.text.ParseException; +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.api.asn.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.test.testtickets.PassComplexTicketV3; + + +/** + * The Class Test asn.1 encoding of a pass. + * + * + * + */ +public class PassComplexTestV3 { + + + /** The ticket decoded 1. */ + UicRailTicketData ticket = null; + + byte[] encodedInTimeZone1 = null; + + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + defaulttimeZone = TimeZone.getDefault(); + + //encode in UTC time zone + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + + + } + + /** + * 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 decoding() { + + //get tickets + String hex = PassComplexTicketV3.getEncodingHex(); + byte[] content = UperEncoder.bytesFromHexString(hex); + ticket = UperEncoder.decode(content, UicRailTicketData.class); + + assert(ticket != null); + + } + + @Test public void encoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + String hex = PassComplexTicketV3.getEncodingHex(); + byte[] content = UperEncoder.bytesFromHexString(hex); + ticket = UperEncoder.decode(content, UicRailTicketData.class); + + + byte[] encoded = UperEncoder.encode(ticket); + + + + assert(encoded != null); + assert(encoded.length > 20); + + String encodedHex = UperEncoder.hexStringFromBytes(encoded); + String expectedHex = PassComplexTicketV3.getEncodingHex(); + + assert(expectedHex.equals(encodedHex)); + + } + +} diff --git a/src/test/java/org/uic/barcode/ticket/api/test/PassTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/PassTimeZoneTestV3.java new file mode 100644 index 0000000..d8ea9f3 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/PassTimeZoneTestV3.java @@ -0,0 +1,347 @@ +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.omv3.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.PassTimeZoneTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class FipTimeZoneTestV2. + * + * + * + */ +public class PassTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** 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 = PassTimeZoneTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = PassTimeZoneTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = PassTimeZoneTestTicketV3.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/test/java/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV3.java new file mode 100644 index 0000000..3eb43e1 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/ReservationTimeZoneTestV3.java @@ -0,0 +1,314 @@ +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.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.spec.IReservation; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.ReservationTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class FipTimeZoneTestV3. + * + * + * + */ +public class ReservationTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** The API ticket low level encoded for case 1. */ + IUicRailTicket iTicketDecodedFromAsn1Case1 = null; + + /** The API ticket low level encoded for case 2. */ + IUicRailTicket iTicketDecodedFromAsn1Case2 = null; + + /** The API ticket low level encoded for case 3. */ + IUicRailTicket iTicketDecodedFromAsn1Case3 = null; + + + /** The ticket decoded 1. */ + IUicRailTicket iTicketDecodedCase1 = null; + + /** The i ticket decoded 2. */ + IUicRailTicket iTicketDecodedCase2 = null; + + /** The i ticket decoded 3. */ + IUicRailTicket iTicketDecodedCase3 = null; + + byte[] encodedInTimeZone1 = null; + byte[] encodedInTimeZone2 = null; + byte[] encodedInTimeZone3 = null; + + String issuingDate1 = null; + String issuingDate2 = null; + String issuingDate3 = null; + + String departureDate1 = null; + String departureDate2 = null; + String departureDate3 = null; + + String arrivalDate1 = null; + String arrivalDate2 = null; + String arrivalDate3 = null; + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + defaulttimeZone = TimeZone.getDefault(); + + UicRailTicketData ticket1 = ReservationTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = ReservationTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = ReservationTestTicketV3.getUicTestTicket(); + + //encode in UTC time zone + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + + encoded1 = UperEncoder.encode(ticket1); + encoded2 = UperEncoder.encode(ticket2); + encoded3 = UperEncoder.encode(ticket3); + + } + + /** + * clean up + */ + @After public void resetTimeZone() { + TimeZone.setDefault(defaulttimeZone); + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone CET + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setdepartureDateTo("2021.03.14-00:00"); + setarrivalDateTo("2021.03.24-23:59"); + + encode("CET"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(departureDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(departureDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(departureDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(arrivalDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(arrivalDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(arrivalDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setdepartureDateTo("2021.03.14-00:00"); + setarrivalDateTo("2021.03.24-23:59"); + + encode("GMT"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(departureDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(departureDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(departureDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(arrivalDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(arrivalDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(arrivalDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setdepartureDateTo("2021.03.14-00:00"); + setarrivalDateTo("2021.03.24-23:59"); + + encode("CET"); + decode("GMT"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" )); + assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" )); + assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" )); + + assert(departureDate1.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(departureDate2.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(departureDate3.equals("Sun Mar 14 00:00:00 GMT 2021" )); + + assert(arrivalDate1.equals("Wed Mar 24 23:59:00 GMT 2021" )); + assert(arrivalDate2.equals("Wed Mar 24 23:59:00 GMT 2021" )); + assert(arrivalDate3.equals("Wed Mar 24 23:59:00 GMT 2021" )); + + + } + + private void decodedDateToStrings() { + + issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString(); + issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString(); + issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString(); + + departureDate1 = ((IReservation) iTicketDecodedCase1.getDocumentData().iterator().next()).getDepartureDate().toString(); + departureDate2 = ((IReservation) iTicketDecodedCase2.getDocumentData().iterator().next()).getDepartureDate().toString(); + departureDate3 = ((IReservation) iTicketDecodedCase3.getDocumentData().iterator().next()).getDepartureDate().toString(); + + arrivalDate1 = ((IReservation) iTicketDecodedCase1.getDocumentData().iterator().next()).getArrivalDate().toString(); + arrivalDate2 = ((IReservation) iTicketDecodedCase2.getDocumentData().iterator().next()).getArrivalDate().toString(); + arrivalDate3 = ((IReservation) iTicketDecodedCase3.getDocumentData().iterator().next()).getArrivalDate().toString(); + + + } + + + private void setdepartureDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IReservation) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setDepartureDate(date); + ((IReservation) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setDepartureDate(date); + ((IReservation) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setDepartureDate(date); + } + + private void setarrivalDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IReservation) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setArrivalDate(date); + ((IReservation) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setArrivalDate(date); + ((IReservation) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setArrivalDate(date); + } + + + /** + * Encode in Time Zone + */ + private void encode(String timeZone) { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + try { + encodedInTimeZone1 = encoder.encode(iTicketDecodedFromAsn1Case1); + encodedInTimeZone2 = encoder.encode(iTicketDecodedFromAsn1Case2); + encodedInTimeZone3 = encoder.encode(iTicketDecodedFromAsn1Case3); + } catch (EncodingFormatException e) { + e.printStackTrace(); + } + } + + /** + * Decode in Time Zone + */ + private void decode(String timeZone) { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + + try { + iTicketDecodedCase1 = decoder.decodeFromAsn(encodedInTimeZone1); + iTicketDecodedCase2 = decoder.decodeFromAsn(encodedInTimeZone2); + iTicketDecodedCase3 = decoder.decodeFromAsn(encodedInTimeZone3); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + /** + * Encode decode. + */ + private void decodeTestTicketUTC() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + try { + iTicketDecodedFromAsn1Case1 = decoder.decodeFromAsn(encoded1); + iTicketDecodedFromAsn1Case2 = decoder.decodeFromAsn(encoded2); + iTicketDecodedFromAsn1Case3 = decoder.decodeFromAsn(encoded3); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/test/java/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV3.java new file mode 100644 index 0000000..c60225d --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/StationPassageTimeZoneTestV3.java @@ -0,0 +1,314 @@ +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.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.spec.IStationPassage; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.StationPassageTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class FipTimeZoneTestV3. + * + * + * + */ +public class StationPassageTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** The API ticket low level encoded for case 1. */ + IUicRailTicket iTicketDecodedFromAsn1Case1 = null; + + /** The API ticket low level encoded for case 2. */ + IUicRailTicket iTicketDecodedFromAsn1Case2 = null; + + /** The API ticket low level encoded for case 3. */ + IUicRailTicket iTicketDecodedFromAsn1Case3 = null; + + + /** The ticket decoded 1. */ + IUicRailTicket iTicketDecodedCase1 = null; + + /** The i ticket decoded 2. */ + IUicRailTicket iTicketDecodedCase2 = null; + + /** The i ticket decoded 3. */ + IUicRailTicket iTicketDecodedCase3 = null; + + byte[] encodedInTimeZone1 = null; + byte[] encodedInTimeZone2 = null; + byte[] encodedInTimeZone3 = null; + + String issuingDate1 = null; + String issuingDate2 = null; + String issuingDate3 = null; + + String validFromDate1 = null; + String validFromDate2 = null; + String validFromDate3 = null; + + String validUntilDate1 = null; + String validUntilDate2 = null; + String validUntilDate3 = null; + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + defaulttimeZone = TimeZone.getDefault(); + + UicRailTicketData ticket1 = StationPassageTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = StationPassageTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = StationPassageTestTicketV3.getUicTestTicket(); + + //encode in UTC time zone + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + + encoded1 = UperEncoder.encode(ticket1); + encoded2 = UperEncoder.encode(ticket2); + encoded3 = UperEncoder.encode(ticket3); + + } + + /** + * clean up + */ + @After public void resetTimeZone() { + TimeZone.setDefault(defaulttimeZone); + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone CET + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setUntilDateTo("2021.03.24-23:59"); + + encode("CET"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setUntilDateTo("2021.03.24-23:59"); + + encode("GMT"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setUntilDateTo("2021.03.24-23:59"); + + encode("CET"); + decode("GMT"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" )); + assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" )); + assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 GMT 2021" )); + + assert(validUntilDate1.equals("Wed Mar 24 23:59:00 GMT 2021" )); + assert(validUntilDate2.equals("Wed Mar 24 23:59:00 GMT 2021" )); + assert(validUntilDate3.equals("Wed Mar 24 23:59:00 GMT 2021" )); + + + } + + private void decodedDateToStrings() { + + issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString(); + issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString(); + issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString(); + + validFromDate1 = ((IStationPassage) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString(); + validFromDate2 = ((IStationPassage) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString(); + validFromDate3 = ((IStationPassage) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString(); + + validUntilDate1 = ((IStationPassage) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntilDate2 = ((IStationPassage) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntilDate3 = ((IStationPassage) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString(); + + + } + + + private void setValidFromDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IStationPassage) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date); + ((IStationPassage) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date); + ((IStationPassage) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(date); + } + + private void setUntilDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IStationPassage) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date); + ((IStationPassage) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date); + ((IStationPassage) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidUntil(date); + } + + + /** + * Encode in Time Zone + */ + private void encode(String timeZone) { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + try { + encodedInTimeZone1 = encoder.encode(iTicketDecodedFromAsn1Case1); + encodedInTimeZone2 = encoder.encode(iTicketDecodedFromAsn1Case2); + encodedInTimeZone3 = encoder.encode(iTicketDecodedFromAsn1Case3); + } catch (EncodingFormatException e) { + e.printStackTrace(); + } + } + + /** + * Decode in Time Zone + */ + private void decode(String timeZone) { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + + try { + iTicketDecodedCase1 = decoder.decodeFromAsn(encodedInTimeZone1); + iTicketDecodedCase2 = decoder.decodeFromAsn(encodedInTimeZone2); + iTicketDecodedCase3 = decoder.decodeFromAsn(encodedInTimeZone3); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + /** + * Encode decode. + */ + private void decodeTestTicketUTC() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + try { + iTicketDecodedFromAsn1Case1 = decoder.decodeFromAsn(encoded1); + iTicketDecodedFromAsn1Case2 = decoder.decodeFromAsn(encoded2); + iTicketDecodedFromAsn1Case3 = decoder.decodeFromAsn(encoded3); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV2.java b/src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV2.java index 53dc248..c7c2512 100644 --- a/src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV2.java +++ b/src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV2.java @@ -12,12 +12,14 @@ 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.asn.omv2.UicRailTicketData; import org.uic.barcode.ticket.api.spec.IVoucher; import org.uic.barcode.ticket.api.spec.IUicRailTicket; -import org.uic.barcode.ticket.api.test.testtickets.VoucherTestTicketV1; -import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder; -import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder; +import org.uic.barcode.ticket.api.test.testtickets.VoucherTestTicketV2; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV2; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV2; /** @@ -38,10 +40,10 @@ public class VoucherTimeZoneTestV2 { private byte[] encoded3 = null; /** The decoder. */ - OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder(); + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV2(); /** The encoder. */ - Api2OpenAsnEncoder encoder = new Api2OpenAsnEncoder(); + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV2(); /** The API ticket low level encoded for case 1. */ IUicRailTicket iTicketDecodedFromAsn1Case1 = null; @@ -87,9 +89,9 @@ public class VoucherTimeZoneTestV2 { defaulttimeZone = TimeZone.getDefault(); - UicRailTicketData ticket1 = VoucherTestTicketV1.getUicTestTicket(); - UicRailTicketData ticket2 = VoucherTestTicketV1.getUicTestTicket(); - UicRailTicketData ticket3 = VoucherTestTicketV1.getUicTestTicket(); + UicRailTicketData ticket1 = VoucherTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket2 = VoucherTestTicketV2.getUicTestTicket(); + UicRailTicketData ticket3 = VoucherTestTicketV2.getUicTestTicket(); //encode in UTC time zone TimeZone.setDefault(TimeZone.getTimeZone("UTC")); diff --git a/src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV3.java new file mode 100644 index 0000000..22b17c2 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/VoucherTimeZoneTestV3.java @@ -0,0 +1,314 @@ +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.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.spec.IVoucher; +import org.uic.barcode.ticket.api.spec.IUicRailTicket; +import org.uic.barcode.ticket.api.test.testtickets.VoucherTestTicketV3; +import org.uic.barcode.ticket.api.utils.Api2AsnEncoder; +import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoderV3; +import org.uic.barcode.ticket.api.utils.Asn2ApiDecoder; +import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoderV3; + + +/** + * The Class VoucherTestV1. + * + * + * + */ +public class VoucherTimeZoneTestV3 { + + /** 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. */ + Asn2ApiDecoder decoder = new OpenAsn2ApiDecoderV3(); + + /** The encoder. */ + Api2AsnEncoder encoder = new Api2OpenAsnEncoderV3(); + + /** The API ticket low level encoded for case 1. */ + IUicRailTicket iTicketDecodedFromAsn1Case1 = null; + + /** The API ticket low level encoded for case 2. */ + IUicRailTicket iTicketDecodedFromAsn1Case2 = null; + + /** The API ticket low level encoded for case 3. */ + IUicRailTicket iTicketDecodedFromAsn1Case3 = null; + + + /** The ticket decoded 1. */ + IUicRailTicket iTicketDecodedCase1 = null; + + /** The i ticket decoded 2. */ + IUicRailTicket iTicketDecodedCase2 = null; + + /** The i ticket decoded 3. */ + IUicRailTicket iTicketDecodedCase3 = null; + + byte[] encodedInTimeZone1 = null; + byte[] encodedInTimeZone2 = null; + byte[] encodedInTimeZone3 = null; + + String issuingDate1 = null; + String issuingDate2 = null; + String issuingDate3 = null; + + String validFromDate1 = null; + String validFromDate2 = null; + String validFromDate3 = null; + + String validUntilDate1 = null; + String validUntilDate2 = null; + String validUntilDate3 = null; + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + defaulttimeZone = TimeZone.getDefault(); + + UicRailTicketData ticket1 = VoucherTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket2 = VoucherTestTicketV3.getUicTestTicket(); + UicRailTicketData ticket3 = VoucherTestTicketV3.getUicTestTicket(); + + //encode in UTC time zone + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + + encoded1 = UperEncoder.encode(ticket1); + encoded2 = UperEncoder.encode(ticket2); + encoded3 = UperEncoder.encode(ticket3); + + } + + /** + * clean up + */ + @After public void resetTimeZone() { + TimeZone.setDefault(defaulttimeZone); + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone CET + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setValidUntilDateTo("2022.03.24-23:59"); + + encode("CET"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(validUntilDate1.equals("Thu Mar 24 23:59:00 CET 2022" )); + assert(validUntilDate2.equals("Thu Mar 24 23:59:00 CET 2022" )); + assert(validUntilDate3.equals("Thu Mar 24 23:59:00 CET 2022" )); + + + } + + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testGMTCETencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setValidUntilDateTo("2021.03.24-23:59"); + + encode("GMT"); + decode("CET"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 13:30:00 CET 2021" )); + assert(issuingDate2.equals("Thu Mar 04 01:30:00 CET 2021" )); + assert(issuingDate3.equals("Thu Mar 04 00:30:00 CET 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 CET 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 CET 2021" )); + + assert(validUntilDate1.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate2.equals("Wed Mar 24 23:59:00 CET 2021" )); + assert(validUntilDate3.equals("Wed Mar 24 23:59:00 CET 2021" )); + + + } + + /** + * Test encode test tickets in UTC and decode in CET. + * + * @throws IllegalArgumentException the illegal argument exception + * @throws IllegalAccessException the illegal access exception + * @throws ParseException + */ + @Test public void testCETGMTencoding() throws IllegalArgumentException, IllegalAccessException, ParseException { + + //get tickets + decodeTestTicketUTC(); + + //set the dates in the time zone GMT + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + iTicketDecodedFromAsn1Case1.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + iTicketDecodedFromAsn1Case2.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-00:30" )); + iTicketDecodedFromAsn1Case3.getIssuerDetails().setIssuingDate(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.03-23:30" )); + + setValidFromDateTo("2021.03.14-00:00"); + setValidUntilDateTo("2022.03.24-23:59"); + + encode("CET"); + decode("GMT"); + decodedDateToStrings(); + + assert(issuingDate1.equals("Thu Mar 04 12:30:00 GMT 2021" )); + assert(issuingDate2.equals("Thu Mar 04 00:30:00 GMT 2021" )); + assert(issuingDate3.equals("Wed Mar 03 23:30:00 GMT 2021" )); + + assert(validFromDate1.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(validFromDate2.equals("Sun Mar 14 00:00:00 GMT 2021" )); + assert(validFromDate3.equals("Sun Mar 14 00:00:00 GMT 2021" )); + + assert(validUntilDate1.equals("Thu Mar 24 23:59:00 GMT 2022" )); + assert(validUntilDate2.equals("Thu Mar 24 23:59:00 GMT 2022" )); + assert(validUntilDate3.equals("Thu Mar 24 23:59:00 GMT 2022" )); + + + } + + private void decodedDateToStrings() { + + issuingDate1 = iTicketDecodedCase1.getIssuerDetails().getIssuingDate().toString(); + issuingDate2 = iTicketDecodedCase2.getIssuerDetails().getIssuingDate().toString(); + issuingDate3 = iTicketDecodedCase3.getIssuerDetails().getIssuingDate().toString(); + + validFromDate1 = ((IVoucher) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidFrom().toString(); + validFromDate2 = ((IVoucher) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidFrom().toString(); + validFromDate3 = ((IVoucher) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidFrom().toString(); + + validUntilDate1 = ((IVoucher) iTicketDecodedCase1.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntilDate2 = ((IVoucher) iTicketDecodedCase2.getDocumentData().iterator().next()).getValidUntil().toString(); + validUntilDate3 = ((IVoucher) iTicketDecodedCase3.getDocumentData().iterator().next()).getValidUntil().toString(); + + + } + + + private void setValidFromDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IVoucher) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidFrom(date); + ((IVoucher) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidFrom(date); + ((IVoucher) iTicketDecodedFromAsn1Case3.getDocumentData().iterator().next()).setValidFrom(date); + } + + private void setValidUntilDateTo(String dateString) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ); + Date date = dateFormat.parse(dateString); + ((IVoucher) iTicketDecodedFromAsn1Case1.getDocumentData().iterator().next()).setValidUntil(date); + ((IVoucher) iTicketDecodedFromAsn1Case2.getDocumentData().iterator().next()).setValidUntil(date); + ((IVoucher) 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/test/java/org/uic/barcode/ticket/api/test/testtickets/CustomerCardTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/CustomerCardTestTicketV3.java new file mode 100644 index 0000000..e41a3cd --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/CustomerCardTestTicketV3.java @@ -0,0 +1,170 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerCardData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.GenderType; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.LinkMode; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.TicketType; +import org.uic.barcode.ticket.api.asn.omv3.TravelClassType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; + + public class CustomerCardTestTicketV3 { + + 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(); + addCustomerCard(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 addCustomerCard(DocumentData dd) { + + TicketDetailData tdd = new TicketDetailData(); + CustomerCardData card = new CustomerCardData(); + card.setCustomer(getTraveler()); + card.setClassCode(TravelClassType.first); + card.setValidFromYear(2021L); + card.setValidFromDay(10L); + card.setValidUntilYear(1L); + card.setValidUntilDay(10L); + card.setCardTypeDescr("RAILPLUS"); + tdd.setCustomerCard(card); + 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 TravelerType getTraveler() { + TravelerType tr = new TravelerType(); + tr.setIdCard("12345"); + tr.setFirstName("John"); + tr.setSecondName("Dow"); + tr.setYearOfBirth(1990L); + tr.setMonthOfBirth(1L); + tr.setDayOfBirth(21L); + tr.setGender(GenderType.male); + tr.setIdCard("IEDZ235FT"); + return tr; + } + + 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/test/java/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV3.java new file mode 100644 index 0000000..34b2386 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/FipTimeZoneTestTicketV3.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.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.FIPTicketData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfActivatedDays; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCarrierNum; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TravelClassType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; + + public class FipTimeZoneTestTicketV3 { + + 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/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTestComplexTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTestComplexTicketV3.java new file mode 100644 index 0000000..c812dad --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTestComplexTicketV3.java @@ -0,0 +1,413 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8; +import org.uic.barcode.asn1.datatypesimpl.SequenceOfUnrestrictedLong; +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IncludedOpenTicketType; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.LinkMode; +import org.uic.barcode.ticket.api.asn.omv3.OpenTicketData; +import org.uic.barcode.ticket.api.asn.omv3.PassengerType; +import org.uic.barcode.ticket.api.asn.omv3.RegionalValidityType; +import org.uic.barcode.ticket.api.asn.omv3.RouteSectionType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfIncludedOpenTicketType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfRegionalValidityType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTariffType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfVatDetail; +import org.uic.barcode.ticket.api.asn.omv3.StationPassageData; +import org.uic.barcode.ticket.api.asn.omv3.TariffType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.TicketType; +import org.uic.barcode.ticket.api.asn.omv3.TokenType; +import org.uic.barcode.ticket.api.asn.omv3.TravelClassType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.asn.omv3.VatDetailType; +import org.uic.barcode.ticket.api.asn.omv3.ZoneType; + + + public class OpenTestComplexTicketV3 { + + public static UicRailTicketData getUicTestTicket() { + UicRailTicketData ticket = new UicRailTicketData(); + populateTicket(ticket); + return ticket; + } + + /* + value UicRailTicketData ::= { + issuingDetail { + issuingYear 2018 + issuingDay 1 + issuingTime 600 + 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 + ,classCode first + ,vatDetail { + { country 80 + ,percentage 70 + ,amount 10 + ,vatId "IUDGTE" + } + } + ,infoText "openTicketInfo" + ,includedAddOns { + { productOwnerNum 1080 + ,validRegion { zones : { zoneId { 100 } } } + ,validFromDay 0 + ,validFromTime 1000 + ,validUntilDay 1 + ,validUntilTime 1000 + ,classCode second + ,tariffs { + { numberOfPassengers 2 + ,passengerType adult + ,restrictedToCountryOfResidence FALSE + ,restrictedToRouteSection { fromStationNum 8000001 , toStationNum 8010000 } + } + } + ,infoText "included ticket" + } + } + } + } + ,{ + 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 } + } + } + */ + + + + public static String getEncodingHex() { + return + "7804404004B14374F3E7D72F2A9979F4A13A90086280B4001044A6F686E03446" + + "F770562C99B46B01106E797769DFC81DB5E51DC9BDD5C0094075A2560282DA10" + + "00000101C0101C4F11804281A4D5891EA450E6F70656E5469636B6574496E666" + + "F0140AD06021B8090020080B23E8013E8100B10008143D09003D1C8787B4B731" + + "B63AB232B2103A34B1B5B2BA090110081DC185CDCD859D94042505B5CDD195C9" + + "9185B4B780BDA60100402C800131B200ADC2EAC588C593466D5C366E089E8A84" + + "84074275204E9979F428100B10282DA01640507B40"; + + } + + + + 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); + + } + + 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); + } + + /* + * + * returnIncluded FALSE + ,classCode first + ,vatDetail { + { country 80 + ,percentage 70 + ,amount 10 + ,vatId "IUDGTE" + } + } + ,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); + + otd.setIncludedAddOns(new SequenceOfIncludedOpenTicketType()); + otd.getIncludedAddOns().add(getIncludedOpenTicket()); + + otd.setVatDetails(new SequenceOfVatDetail()); + otd.getVatDetails().add(getVatDetail()); + + tdd.setOpenTicket(otd); + dd.setTicket(tdd); + + } + + private static VatDetailType getVatDetail() { + VatDetailType v = new VatDetailType(); + v.setAmount(10L); + v.setCountry(80L); + v.setPercentage(70L); + v.setVatId("IUDGTE"); + return v; + } + + /* + { productOwnerNum 1080 + ,validRegion { zones : { zoneId { 100 } } } + ,validFromDay 0 + ,validFromTime 1000 + ,validUntilDay 1 + ,validUntilTime 1000 + ,classCode second + ,tariffs { + { numberOfPassengers 2 + ,passengerType adult + ,restrictedToCountryOfResidence FALSE + ,restrictedToRouteSection { fromStationNum 8000001 , toStationNum 8010000 } + } + } + ,infoText "included ticket" + } + */ + + private static IncludedOpenTicketType getIncludedOpenTicket() { + IncludedOpenTicketType t = new IncludedOpenTicketType(); + t.setClassCode(TravelClassType.second); + t.setInfoText("included ticket"); + t.setProductOwnerNum(1080L); + t.setValidRegion(new SequenceOfRegionalValidityType()); + t.getValidRegion().add(getZone()); + t.setValidFromDay(0L); + t.setValidFromTime(1000L); + t.setValidUntilDay(1L); + t.setValidUntilTime(1000L); + t.setTariffs(new SequenceOfTariffType()); + t.getTariffs().add(getTariff()); + return t; + } + + + + + private static RegionalValidityType getZone() { + + RegionalValidityType r = new RegionalValidityType(); + ZoneType z = new ZoneType(); + z.setZoneId(new SequenceOfUnrestrictedLong()); + z.getZoneId().add(100L); + r.setZones(z); + return r; + } + + 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); + } + + + 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); + } + + /* + { + trailingCardIdNum 100 + } + */ + private static CardReferenceType populateCardRefrence() { + CardReferenceType cr = new CardReferenceType(); + cr.setTrailingCardIdNum(100L); + return cr; + } + + private static TariffType getTariff() { + TariffType t = new TariffType(); + t.setNumberOfPassengers(2L); + t.setPassengerType(PassengerType.adult); + t.setRestrictedToRouteSection(getRouteSection()); + t.setRestrictedToCountryOfResidence(false); + return t; + } + + private static RouteSectionType getRouteSection() { + RouteSectionType r = new RouteSectionType(); + r.setFromStationNum(8000001L); + r.setToStationNum(8010000L); + + return r; + } + + } diff --git a/src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV3.java new file mode 100644 index 0000000..e80296b --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenTicketTimeZoneTestTicketV3.java @@ -0,0 +1,158 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.OpenTicketData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfActivatedDays; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TokenType; +import org.uic.barcode.ticket.api.asn.omv3.TravelClassType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; + + + public class OpenTicketTimeZoneTestTicketV3 { + + 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.setIssuingTime(600L); + 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/test/java/org/uic/barcode/ticket/api/test/testtickets/ParkingTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/ParkingTestTicketV3.java new file mode 100644 index 0000000..bacdb41 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/ParkingTestTicketV3.java @@ -0,0 +1,147 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.ParkingGroundData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; + + public class ParkingTestTicketV3 { + + 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(); + addTicket(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 addTicket(DocumentData dd) { + + TicketDetailData tdd = new TicketDetailData(); + ParkingGroundData ticket = new ParkingGroundData(); + ticket.setFromParkingDate(01L); + ticket.setToParkingDate(01L); + ticket.setReferenceIA5("ACHE12345"); + ticket.setLocation("Parking Frankfurt Main West"); + ticket.setNumberPlate("AA-DE-12345"); + ticket.setStationNum(8000001L); + ticket.setPrice(500L); + ticket.setParkingGroundId("P47623"); + ticket.setSpecialInformation("outdoor parking"); + + tdd.setParkingGround(ticket); + 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/test/java/org/uic/barcode/ticket/api/test/testtickets/PassComplexTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/PassComplexTicketV3.java new file mode 100644 index 0000000..03df203 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/PassComplexTicketV3.java @@ -0,0 +1,431 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.asn1.datatypes.Asn1BigInteger; +import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8; +import org.uic.barcode.asn1.datatypesimpl.SequenceOfUnrestrictedLong; +import org.uic.barcode.ticket.api.asn.omv3.BoardingOrArrivalType; +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.LinkMode; +import org.uic.barcode.ticket.api.asn.omv3.PassData; +import org.uic.barcode.ticket.api.asn.omv3.PassengerType; +import org.uic.barcode.ticket.api.asn.omv3.RegionalValidityType; +import org.uic.barcode.ticket.api.asn.omv3.RouteSectionType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfActivatedDays; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCarrierNum; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCountries; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfVatDetail; +import org.uic.barcode.ticket.api.asn.omv3.StationPassageData; +import org.uic.barcode.ticket.api.asn.omv3.TariffType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.TicketType; +import org.uic.barcode.ticket.api.asn.omv3.TokenType; +import org.uic.barcode.ticket.api.asn.omv3.TrainValidityType; +import org.uic.barcode.ticket.api.asn.omv3.TravelClassType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.asn.omv3.VatDetailType; +import org.uic.barcode.ticket.api.asn.omv3.ZoneType; + + + public class PassComplexTicketV3 { + + public static UicRailTicketData getUicTestTicket() { + UicRailTicketData ticket = new UicRailTicketData(); + populateTicket(ticket); + return ticket; + } + + /* + value UicRailTicketData ::= { + issuingDetail { + issuingYear 2018 + issuingDay 1 + issuingTime 600 + 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 "XYZ", token '82DA'H } + ,ticket pass : { + referenceNum 123456789 + ,productOwnerNum 4567 + ,passType 2 + ,passDescription "Eurail FlexPass" + ,classCode first + ,validFromDay 0 + ,validFromTime 1000 + ,validUntilDay 1 + ,validUntilTime 1000 + ,trainValidity { + ,validFromDay 0 + ,validFromTime 1000 + ,validUntilDay 1 + ,validUntilTime 1000 + ,includedCarrierNum {1234, 5678} + ,boardingOrArrival boarding + } + ,numberOfDaysOfTravel 10 + ,activatedDay {200, 201} + ,countries {10, 20} + ,price 10000 + ,vatDetail { + { country 80 + ,percentage 70 + ,amount 10 + ,vatId "IUDGTE" + } + } + ,infoText "pass info" + } + } + ,{ + 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 } + } + } + */ + + + + public static String getEncodingHex() { + return + "7804404004B14374F3E7D72F2A9979F4A13A90086280B4001044A6F686E03446" + + "F770562C99B46B01106E797769DFC81DB5E51DC9BDD5C00940762CDA0282DA1A" + + "8EB1700E04075BCD1523AC021E8AEAE4C2D2D8408CD8CAF0A0C2E6E617D0027D" + + "05A03E8013E80209A258B4240990C902091302271001C4F11804281A4D5891EA" + + "45097061737320696E666F120220103B830B9B9B0B3B28084A0B6B9BA32B9323" + + "0B696F017B4C0200805900026364015B85D58B118B268CDAB86CDC113D150908" + + "0E84EA409D32F3E850201620505B402C80A0F680"; + + } + + + + 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(); + addPassData(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); + + } + + 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 "XYZ", token '82DA'H } + ,ticket pass : { + referenceNum 123456789 + ,productOwnerNum 4567 + ,passType 2 + ,passDescription "Eurail FlexPass" + ,classCode first + ,validFromDay 0 + ,validFromTime 1000 + ,validUntilDay 1 + ,validUntilTime 1000 + ,trainValidity { + ,validFromDay 0 + ,validFromTime 1000 + ,validUntilDay 1 + ,validUntilTime 1000 + ,includedCarrierNum {1234, 5678} + ,boardingOrArrival boarding + } + ,numberOfDaysOfTravel 10 + ,activatedDay {200, 201} + ,countries {10, 20} + ,price 10000 + ,vatDetail { + { country 80 + ,percentage 70 + ,amount 10 + ,vatId "IUDGTE" + } + } + ,infoText "pass info" + * + */ + private static void addPassData(DocumentData dd) { + TokenType to = new TokenType(); + to.setTokenProviderIA5("XYZ"); + byte[] ba = { (byte) 0x82, (byte) 0xDA }; + to.setToken(ba); + dd.setToken(to); + + TicketDetailData tdd = new TicketDetailData(); + PassData otd = new PassData(); + + otd.setReferenceNum(Asn1BigInteger.toAsn1(123456789L)); + otd.setProductOwnerNum(4567L); + otd.setPassDescription("Eurail FlexPass"); + + otd.setInfoText("pass info"); + otd.setClassCode(TravelClassType.first); + + otd.setValidFromDay(0L); + otd.setValidFromTime(1000L); + otd.setValidUntilDay(1L); + otd.setValidUntilTime(1000L); + + SequenceOfCountries countries = new SequenceOfCountries(); + countries.add(10L); + countries.add(20L); + otd.setCountries(countries); + + otd.setTrainValidity(getTrainValidity()); + SequenceOfActivatedDays activatedDays = new SequenceOfActivatedDays(); + activatedDays.add(200L); + activatedDays.add(201L); + otd.setActivatedDay(activatedDays); + + otd.setNumberOfDaysOfTravel(10L); + + otd.setPrice(10000L); + otd.setVatDetails(new SequenceOfVatDetail()); + otd.getVatDetails().add(getVatDetail()); + + tdd.setPass(otd); + dd.setTicket(tdd); + + } + + private static TrainValidityType getTrainValidity() { + TrainValidityType t = new TrainValidityType(); + t.setValidFromDay(0L); + t.setValidFromTime(1000L); + t.setValidUntilDay(1L); + t.setValidUntilTime(1000L); + SequenceOfCarrierNum carriers = new SequenceOfCarrierNum(); + carriers.add(1234L); + carriers.add(5678L); + t.setIncludedCarriersNum(carriers); + + t.setBordingOrArrival(BoardingOrArrivalType.boarding); + + return t; + } + + + + private static VatDetailType getVatDetail() { + VatDetailType v = new VatDetailType(); + v.setAmount(10L); + v.setCountry(80L); + v.setPercentage(70L); + v.setVatId("IUDGTE"); + return v; + } + + + + + 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); + } + + + 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); + } + + /* + { + trailingCardIdNum 100 + } + */ + private static CardReferenceType populateCardRefrence() { + CardReferenceType cr = new CardReferenceType(); + cr.setTrailingCardIdNum(100L); + return cr; + } + + private static TariffType getTariff() { + TariffType t = new TariffType(); + t.setNumberOfPassengers(2L); + t.setPassengerType(PassengerType.adult); + t.setRestrictedToRouteSection(getRouteSection()); + t.setRestrictedToCountryOfResidence(false); + return t; + } + + private static RouteSectionType getRouteSection() { + RouteSectionType r = new RouteSectionType(); + r.setFromStationNum(8000001L); + r.setToStationNum(8010000L); + + return r; + } + + } diff --git a/src/test/java/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV3.java new file mode 100644 index 0000000..b45fd01 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/PassTimeZoneTestTicketV3.java @@ -0,0 +1,168 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.LinkMode; +import org.uic.barcode.ticket.api.asn.omv3.PassData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfActivatedDays; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.TicketType; +import org.uic.barcode.ticket.api.asn.omv3.TravelClassType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; + + public class PassTimeZoneTestTicketV3 { + + 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/test/java/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV3.java new file mode 100644 index 0000000..9f2d89f --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/ReservationTestTicketV3.java @@ -0,0 +1,202 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.PassengerType; +import org.uic.barcode.ticket.api.asn.omv3.PlacesType; +import org.uic.barcode.ticket.api.asn.omv3.PriceTypeType; +import org.uic.barcode.ticket.api.asn.omv3.ReservationData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCarrierNum; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTariffType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.ServiceType; +import org.uic.barcode.ticket.api.asn.omv3.TariffType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TravelClassType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; + + + public class ReservationTestTicketV3 { + + public static UicRailTicketData getUicTestTicket() { + UicRailTicketData ticket = new UicRailTicketData(); + populateTicket(ticket); + return ticket; + } + + + private static void populateTicket(UicRailTicketData ticket) { + + ticket.setControlDetail(new ControlData()); + populate(ticket.getControlDetail()); + + + ticket.setIssuingDetail(new IssuingData()); + populateIssuingData(ticket.getIssuingDetail()); + + TravelerData td = new TravelerData(); + populateTravelerData(td); + ticket.setTravelerDetail(td); + + SequenceOfDocumentData ds = new SequenceOfDocumentData(); + + + //OpenTicket + DocumentData do1 = new DocumentData(); + addReservation(do1); + ds.add(do1); + + + ticket.setTransportDocument(ds); + + SequenceOfExtensionData ed = new SequenceOfExtensionData(); + populateExtensionSequence(ed); + ticket.setExtension(ed); + + } + + + + private static void addReservation(DocumentData dd) { + + TicketDetailData tdd = new TicketDetailData(); + ReservationData ticket = new ReservationData(); + ticket.setTrainNum(123L); + ticket.setService(ServiceType.seat); + ticket.setReferenceNum(810123456789L); + ticket.setServiceBrandAbrUTF8("XYZ"); + ticket.setServiceBrandNameUTF8("special train"); + SequenceOfCarrierNum carriers = new SequenceOfCarrierNum(); + carriers.add(1080L); + carriers.add(1181L); + ticket.setCarrierNum(carriers); + ticket.setFromStationNum(8100001L); + ticket.setToStationNum(800001L); + ticket.setNumberOfSupplements(1L); + ticket.setServiceBrand(100L); + ticket.setPrice(12345L); + ticket.setPriceType(PriceTypeType.supplement); + + ticket.setPlaces(getPlaces()); + ticket.setTariff(getTariffs()); + + ticket.setInfoText("reservation"); + ticket.setClassCode(TravelClassType.first); + ticket.setDepartureDate(10L); + ticket.setDepartureTime(0L); + ticket.setArrivalDate(10L); + ticket.setArrivalTime(1439L); + tdd.setReservation(ticket); + dd.setTicket(tdd); + } + + + + private static SequenceOfTariffType getTariffs() { + SequenceOfTariffType tariffs = new SequenceOfTariffType(); + + TariffType tariff = new TariffType(); + tariff.setNumberOfPassengers(1L); + tariff.setRestrictedToCountryOfResidence(false); + tariff.setPassengerType(PassengerType.adult); + tariff.setTariffIdNum(72L); + tariff.setTariffDesc("Full Fare Adult"); + tariffs.add(tariff); + TariffType tariff2 = new TariffType(); + tariff2.setRestrictedToCountryOfResidence(false); + tariff2.setNumberOfPassengers(2L); + tariff2.setPassengerType(PassengerType.child); + tariff2.setTariffIdNum(73L); + tariff2.setTariffDesc("Full Fare Child"); + tariffs.add(tariff2); + return tariffs; + } + + + private static PlacesType getPlaces() { + PlacesType places = new PlacesType(); + places.setPlaceDescription("11-13"); + places.setCoach("12"); + return places; + } + + + private static void populateTravelerData(TravelerData td) { + td.setGroupName("myGroup"); + SequenceOfTravelerType trs = new SequenceOfTravelerType(); + TravelerType tr = new TravelerType(); + tr.setIdCard("12345"); + tr.setFirstName("John"); + tr.setSecondName("Dow"); + tr.setTicketHolder(true); + SequenceOfCustomerStatusType ts = new SequenceOfCustomerStatusType(); + CustomerStatusType cst = new CustomerStatusType(); + cst.setCustomerStatusDescr("senior"); + ts.add(cst); + tr.setStatus(ts); + trs.add(tr); + td.setTraveler(trs); + } + + private static void populateIssuingData(IssuingData issuingDetail) { + issuingDetail.setIssuingYear(2018L); + issuingDetail.setIssuingDay(1L); + issuingDetail.setIssuingTime(600L); + 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/test/java/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV3.java new file mode 100644 index 0000000..b2f1816 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/StationPassageTestTicketV3.java @@ -0,0 +1,184 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8; +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.StationPassageData; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; + +public class StationPassageTestTicketV3 { + + + public static UicRailTicketData getUicTestTicket() { + UicRailTicketData ticket = new UicRailTicketData(); + populateTicket(ticket); + return ticket; + } + + + + private static void populateTicket(UicRailTicketData ticket) { + + ticket.setControlDetail(new ControlData()); + populate(ticket.getControlDetail()); + + + ticket.setIssuingDetail(new IssuingData()); + populateIssuingData(ticket.getIssuingDetail()); + + TravelerData td = new TravelerData(); + populateTravelerData(td); + ticket.setTravelerDetail(td); + + SequenceOfDocumentData ds = new SequenceOfDocumentData(); + + + //StationPassage + DocumentData do2 = new DocumentData(); + addStationPassage(do2); + ds.add(do2); + + ticket.setTransportDocument(ds); + + SequenceOfExtensionData ed = new SequenceOfExtensionData(); + populateExtensionSequence(ed); + ticket.setExtension(ed); + + } + + /* + ticket stationPassage : { + productName "passage" + ,stationNameUTF8 { "Amsterdam" } + ,validFromDay 0 + ,numberOfDaysValid 123 + } + */ + private static void addStationPassage(DocumentData dd) { + TicketDetailData tdd = new TicketDetailData(); + StationPassageData sp = new StationPassageData(); + sp.setProductName("passage"); + sp.setValidFromDay(5L); + sp.setValidFromTime(0L); + sp.setValidUntilDay(5L); + sp.setValidUntilTime(1000L); + sp.setNumberOfDaysValid(5L); + SequenceOfStringUTF8 ss = new SequenceOfStringUTF8(); + ss.add("Amsterdam"); + sp.setStationNameUTF8(ss); + tdd.setStationPassage(sp); + dd.setTicket(tdd); + } + + + private static void populateTravelerData(TravelerData td) { + td.setGroupName("myGroup"); + SequenceOfTravelerType trs = new SequenceOfTravelerType(); + TravelerType tr = new TravelerType(); + tr.setIdCard("12345"); + tr.setFirstName("John"); + tr.setSecondName("Dow"); + tr.setTicketHolder(true); + SequenceOfCustomerStatusType ts = new SequenceOfCustomerStatusType(); + CustomerStatusType cst = new CustomerStatusType(); + cst.setCustomerStatusDescr("senior"); + ts.add(cst); + tr.setStatus(ts); + trs.add(tr); + td.setTraveler(trs); + } + + private static void populateIssuingData(IssuingData issuingDetail) { + issuingDetail.setIssuingYear(2018L); + issuingDetail.setIssuingDay(1L); + issuingDetail.setIssuingTime(600L); + issuingDetail.setIssuerPNR("issuerTestPNR"); + issuingDetail.setSpecimen(true); + issuingDetail.setSecurePaperTicket(false); + issuingDetail.setActivated(true); + issuingDetail.setIssuedOnLine(12L); + } + + private static void populateExtensionSequence(SequenceOfExtensionData ed) { + ExtensionData ed1 = new ExtensionData(); + ed1.setExtensionId("1"); + byte[] ba1 = { (byte) 0x82, (byte) 0xDA }; + ed1.setExtensionData(ba1); + ExtensionData ed2 = new ExtensionData(); + ed2.setExtensionId("2"); + byte[] ba2 = { (byte) 0x83, (byte) 0xDA }; + ed2.setExtensionData(ba2); + ed.add(ed1); + ed.add(ed2); + } + + /* + ,controlDetail { + identificationByCardReference { + { trailingCardIdNum 100 } + } + ,identificationByIdCard FALSE + ,identificationByPassportId FALSE + ,passportValidationRequired FALSE + ,onlineValidationRequired FALSE + ,ageCheckRequired FALSE + ,reductionCardCheckRequired FALSE + ,infoText "cd" + ,includedTickets { + { productOwnerIA5 "test" } + } + } + */ + private static void populate(ControlData controlDetail) { + controlDetail.infoText = "cd"; + controlDetail.setAgeCheckRequired(false); + controlDetail.setIdentificationByIdCard(false); + controlDetail.setIdentificationByPassportId(false); + controlDetail.setOnlineValidationRequired(false); + controlDetail.setPassportValidationRequired(false); + controlDetail.setReductionCardCheckRequired(false); + controlDetail.setIdentificationByCardReference(new SequenceOfCardReferenceType()); + controlDetail.getIdentificationByCardReference().add(populateCardRefrence()); + SequenceOfTicketLinkType sit = new SequenceOfTicketLinkType(); + populateLinkedTickets(sit); + controlDetail.setIncludedTickets(sit); + } + + + /* + * + */ + private static void populateLinkedTickets(SequenceOfTicketLinkType sequenceOfTicketLinkType) { + TicketLinkType tlt = new TicketLinkType(); + tlt.productOwnerIA5="test"; + sequenceOfTicketLinkType.add(tlt); + } + + /* + { + trailingCardIdNum 100 + } + */ + private static CardReferenceType populateCardRefrence() { + CardReferenceType cr = new CardReferenceType(); + cr.setTrailingCardIdNum(100L); + return cr; + } + + + +} diff --git a/src/test/java/org/uic/barcode/ticket/api/test/testtickets/VoucherTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/VoucherTestTicketV3.java new file mode 100644 index 0000000..20bfdaa --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/VoucherTestTicketV3.java @@ -0,0 +1,141 @@ +package org.uic.barcode.ticket.api.test.testtickets; + +import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.ControlData; +import org.uic.barcode.ticket.api.asn.omv3.CustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.DocumentData; +import org.uic.barcode.ticket.api.asn.omv3.ExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.IssuingData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCardReferenceType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfCustomerStatusType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfDocumentData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfExtensionData; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.TicketDetailData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerData; +import org.uic.barcode.ticket.api.asn.omv3.TravelerType; +import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData; +import org.uic.barcode.ticket.api.asn.omv3.VoucherData; + + public class VoucherTestTicketV3 { + + 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(); + + DocumentData do1 = new DocumentData(); + addTicket(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.setIssuingTime(600L); + issuingDetail.setIssuerPNR("issuerTestPNR"); + issuingDetail.setSpecimen(true); + issuingDetail.setSecurePaperTicket(false); + issuingDetail.setActivated(true); + issuingDetail.setIssuedOnLine(12L); + } + + private static void addTicket(DocumentData dd) { + + TicketDetailData tdd = new TicketDetailData(); + VoucherData ticket = new VoucherData(); + ticket.setInfoText("coffee voucher"); + ticket.setValidFromYear(2022L); + ticket.setValidFromDay(01L); + ticket.setValidUntilYear(2022L); + ticket.setValidUntilDay(01L); + ticket.setReferenceIA5("ACHE12345"); + ticket.setProductOwnerIA5("COFFEEMACHINE"); + ticket.setValue(500L); + tdd.setVoucher(ticket); + 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; + } + + + + } -- cgit v1.2.3