From 0ce9bdf9480e30e81ed9285d7f10ceb0502072cc Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Thu, 25 May 2023 11:37:18 +0200 Subject: bug fix on passport validation required --- .../ticket/api/utils/OpenAsn2ApiDecoder.java | 6 ++ .../ticket/api/utils/OpenAsn2ApiDecoderV2.java | 7 ++ .../ticket/api/utils/OpenAsn2ApiDecoderV3.java | 7 ++ .../test/PassComplexPassportValidationTestV3.java | 109 +++++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java (limited to 'src') diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java index 4cccb18..f9c6b7e 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java @@ -2132,6 +2132,12 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { controlDetails.setOnlineValidationRequired(asnControlDetails.getOnlineValidationRequired()); } + if (asnControlDetails.getPassportValidationRequired() !=null){ + controlDetails.setPassportValidationRequired(asnControlDetails.getPassportValidationRequired()); + } else { + controlDetails.setPassportValidationRequired(true); + } + if (asnControlDetails.getRandomDetailedValidationRequired()!= null){ controlDetails.setRandomDetailedValidationRequired(asnControlDetails.getRandomDetailedValidationRequired().intValue()); } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java index 70017aa..f21a592 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java @@ -2140,6 +2140,13 @@ public class OpenAsn2ApiDecoderV2 implements Asn2ApiDecoder { controlDetails.setIdentificationByPassportId(asnControlDetails.getIdentificationByPassportId()); } + + if (asnControlDetails.getPassportValidationRequired() !=null){ + controlDetails.setPassportValidationRequired(asnControlDetails.getPassportValidationRequired()); + } else { + controlDetails.setPassportValidationRequired(true); + } + if(asnControlDetails.getIdentificationItem()!=null){ controlDetails.setIdentificationItem(asnControlDetails.getIdentificationItem().intValue()); } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java index a9cc0d3..66a0d22 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java @@ -2216,6 +2216,13 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { controlDetails.setIdentificationByPassportId(asnControlDetails.getIdentificationByPassportId()); } + + if (asnControlDetails.getPassportValidationRequired() !=null){ + controlDetails.setPassportValidationRequired(asnControlDetails.getPassportValidationRequired()); + } else { + controlDetails.setPassportValidationRequired(true); + } + if(asnControlDetails.getIdentificationItem()!=null){ controlDetails.setIdentificationItem(asnControlDetails.getIdentificationItem().intValue()); } diff --git a/src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java new file mode 100644 index 0000000..a7b3087 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java @@ -0,0 +1,109 @@ +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.logger.LoggerFactory; +import org.uic.barcode.ticket.api.asn.omv3.BoardingOrArrivalType; +import org.uic.barcode.ticket.api.asn.omv3.PassData; +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 PassComplexPassportValidationTestV3 { + + + /** The ticket decoded 1. */ + UicRailTicketData ticket = null; + + byte[] encodedInTimeZone1 = null; + + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + LoggerFactory.setActivateConsoleLog(true); + + 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); + ticket.getControlDetail().setPassportValidationRequired(true); + + + byte[] encoded = UperEncoder.encode(ticket); + + + + assert(encoded != null); + assert(encoded.length > 20); + + + assert(ticket.getTransportDocument().get(0).getTicket().getPass() != null); + + PassData p = ticket.getTransportDocument().get(0).getTicket().getPass(); + + + assert(p.getTrainValidity().getBordingOrArrival().equals(BoardingOrArrivalType.boarding)); + assert(p.getTrainValidity().getIncludedCarriersNum().contains(1234L)); + assert(p.getTrainValidity().getIncludedCarriersNum().contains(5678L)); + assert(p.getTrainValidity().getValidFromDay() == 0L); + assert(p.getTrainValidity().getValidFromTime() == 1000L); + assert(p.getTrainValidity().getValidUntilDay() == 1L); + assert(p.getTrainValidity().getValidUntilTime() == 1000L); + assert(ticket.getControlDetail().getPassportValidationRequired() == true); + + + } + +} -- cgit v1.2.3