diff options
author | CGantert345 <57003061+CGantert345@users.noreply.github.com> | 2021-11-25 16:39:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 16:39:28 +0100 |
commit | c9f27f2de9b3fa713d10cb2f8014aad4e8af3070 (patch) | |
tree | ca00d8bae19bfcb5d7d55b388b568136ea62b57d /src/test/java/org/uic/barcode | |
parent | Merge pull request #34 from UnionInternationalCheminsdeFer/1.2.7 (diff) | |
parent | test and bug fix on countermark and viaStation (diff) | |
download | UIC-barcode-1.2.8.tar UIC-barcode-1.2.8.tar.gz UIC-barcode-1.2.8.tar.bz2 UIC-barcode-1.2.8.tar.lz UIC-barcode-1.2.8.tar.xz UIC-barcode-1.2.8.tar.zst UIC-barcode-1.2.8.zip |
Diffstat (limited to 'src/test/java/org/uic/barcode')
13 files changed, 2483 insertions, 0 deletions
diff --git a/src/test/java/org/uic/barcode/asn1/test/GenAlphabet.java b/src/test/java/org/uic/barcode/asn1/test/GenAlphabet.java new file mode 100644 index 0000000..a08392e --- /dev/null +++ b/src/test/java/org/uic/barcode/asn1/test/GenAlphabet.java @@ -0,0 +1,11 @@ +package org.uic.barcode.asn1.test;
+
+import org.uic.barcode.asn1.datatypes.Alphabet;
+
+public class GenAlphabet extends Alphabet {
+
+ public GenAlphabet() {
+ super("ACGT");
+ }
+
+}
diff --git a/src/test/java/org/uic/barcode/asn1/test/UperEncodeBitStringTest.java b/src/test/java/org/uic/barcode/asn1/test/UperEncodeBitStringTest.java new file mode 100644 index 0000000..94f29c2 --- /dev/null +++ b/src/test/java/org/uic/barcode/asn1/test/UperEncodeBitStringTest.java @@ -0,0 +1,82 @@ +package org.uic.barcode.asn1.test; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.logging.Level; + +import org.junit.Test; +import org.uic.barcode.asn1.datatypes.Asn1Optional; +import org.uic.barcode.asn1.datatypes.Bitstring; +import org.uic.barcode.asn1.datatypes.FieldOrder; +import org.uic.barcode.asn1.datatypes.FixedSize; +import org.uic.barcode.asn1.datatypes.Sequence; +import org.uic.barcode.asn1.uper.UperEncoder; + + +public class UperEncodeBitStringTest { + + /** + * Example from the Standard on UPER. + <pre> + World-Schema DEFINITIONS AUTOMATIC TAGS ::= + BEGIN + TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { + value BIT STRING (SIZE(3)) OPTIONAL + } + END + + + rec1value TestRecord ::= { + value '001'B + } + </pre> + + + + */ + @Sequence + public static class TestRecord { + + @FieldOrder(order = 0) + @Asn1Optional() + @Bitstring() + @FixedSize(3) + ArrayList<Boolean> booleans = null; + + public TestRecord() { + this(false,false,true); + } + + public TestRecord(Boolean value1,Boolean value2,Boolean value3 ) { + booleans = new ArrayList<Boolean>(); + booleans.add(value1); + booleans.add(value2); + booleans.add(value3); + } + } + + + @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { + TestRecord record = new TestRecord(false,false,true); + byte[] encoded = UperEncoder.encode(record); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + assertEquals("90",hex); + } + + + @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { + TestRecord record = new TestRecord(false,false,true); + byte[] encoded = UperEncoder.encode(record); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + assertEquals("90",hex); + TestRecord result = UperEncoder.decode(encoded, TestRecord.class); + assertEquals(result.booleans.get(0),record.booleans.get(0)); + assertEquals(result.booleans.get(1),record.booleans.get(1)); + assertEquals(result.booleans.get(2),record.booleans.get(2)); + + } + +} diff --git a/src/test/java/org/uic/barcode/asn1/test/UperEncodeStringCustomAlphabetTest.java b/src/test/java/org/uic/barcode/asn1/test/UperEncodeStringCustomAlphabetTest.java new file mode 100644 index 0000000..03b8bac --- /dev/null +++ b/src/test/java/org/uic/barcode/asn1/test/UperEncodeStringCustomAlphabetTest.java @@ -0,0 +1,82 @@ +package org.uic.barcode.asn1.test; + +import static org.junit.Assert.assertEquals; + +import java.util.logging.Level; + +import org.junit.Test; +import org.uic.barcode.asn1.datatypes.Asn1Optional; +import org.uic.barcode.asn1.datatypes.CharacterRestriction; +import org.uic.barcode.asn1.datatypes.FieldOrder; +import org.uic.barcode.asn1.datatypes.RestrictedString; +import org.uic.barcode.asn1.datatypes.Sequence; +import org.uic.barcode.asn1.uper.UperEncoder; + + +public class UperEncodeStringCustomAlphabetTest { + + /** + * Example from the Standard on UPER. + <pre> + World-Schema DEFINITIONS AUTOMATIC TAGS ::= + BEGIN + TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { + value1 PrintableString ( FROM ("ACGT") ) OPTIONAL, + value2 PrintableString ( FROM ("ACGT") ) OPTIONAL + } + END + + rec1value TestRecord ::= { + value1 "ACGT", + value2 "ACTGCATCGA" + } + </pre> + */ + @Sequence + public static class TestRecord { + + @FieldOrder(order = 0) + @RestrictedString(value = CharacterRestriction.VisibleString, alphabet = GenAlphabet.class) + @Asn1Optional() String value1; + + @FieldOrder(order = 1) + @RestrictedString(value = CharacterRestriction.VisibleString, alphabet = GenAlphabet.class) + @Asn1Optional() String value2; + + public TestRecord() { + } + + public TestRecord(String v1, String v2) { + this.value1 = v1; + this.value2 = v2; + } + } + + + @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { + + + TestRecord record = new TestRecord("ACGT", "ACTGCATCGA"); + byte[] encoded = UperEncoder.encode(record); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + assertEquals("C106C2879360",hex); + + } + + + @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { + + TestRecord record = new TestRecord("ACGT", "ACTGCATCGA"); + byte[] encoded = UperEncoder.encode(record); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + assertEquals("C106C2879360",hex); + TestRecord result = UperEncoder.decode(encoded, TestRecord.class); + assertEquals(result.value1,record.value1); + assertEquals(result.value2,record.value2); + } + + + +} diff --git a/src/test/java/org/uic/barcode/asn1/test/UperEncodeVarBitStringTest.java b/src/test/java/org/uic/barcode/asn1/test/UperEncodeVarBitStringTest.java new file mode 100644 index 0000000..d6212e2 --- /dev/null +++ b/src/test/java/org/uic/barcode/asn1/test/UperEncodeVarBitStringTest.java @@ -0,0 +1,81 @@ +package org.uic.barcode.asn1.test; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +import org.junit.Test; +import org.uic.barcode.asn1.datatypes.Asn1Optional; +import org.uic.barcode.asn1.datatypes.Asn1VarSizeBitstring; +import org.uic.barcode.asn1.datatypes.FieldOrder; +import org.uic.barcode.asn1.datatypes.Sequence; +import org.uic.barcode.asn1.uper.UperEncoder; + + +public class UperEncodeVarBitStringTest { + + /** + * Example from the Standard on UPER. + <pre> + World-Schema DEFINITIONS AUTOMATIC TAGS ::= + BEGIN + TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { + value BIT STRING OPTIONAL, + } + END + + + rec1value TestRecord ::= { + value '001'B + } + </pre> + + + + */ + @Sequence + public static class TestRecord { + + @FieldOrder(order = 0) + @Asn1Optional() Asn1VarSizeBitstring value; + + public TestRecord() { + this(false,false,true); + } + + public TestRecord(Boolean value1,Boolean value2,Boolean value3 ) { + List<Boolean> booleans = new ArrayList<Boolean>(); + booleans.add(value1); + booleans.add(value2); + booleans.add(value3); + this.value = new Asn1VarSizeBitstring(booleans); + + } + } + + + @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { + TestRecord record = new TestRecord(false,false,true); + byte[] encoded = UperEncoder.encode(record); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + assertEquals("8190",hex); + } + + + @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { + TestRecord record = new TestRecord(false,false,true); + byte[] encoded = UperEncoder.encode(record); + String hex = UperEncoder.hexStringFromBytes(encoded); + UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); + assertEquals("8190",hex); + TestRecord result = UperEncoder.decode(encoded, TestRecord.class); + assertEquals(result.value.get(0),record.value.get(0)); + assertEquals(result.value.get(1),record.value.get(1)); + assertEquals(result.value.get(2),record.value.get(2)); + + } + +} diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java new file mode 100644 index 0000000..84f7795 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java @@ -0,0 +1,169 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.util.Arrays;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.DataType;
+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;
+
+public class DynamicFrameDoubleSignatureProviderSelectionTest {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPairLevel1 = null;
+ public KeyPair keyPairLevel2 = null;
+
+ public IUicRailTicket testFCBticket = null;
+
+ public Provider prov = null;
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ prov = new BouncyCastleProvider();
+
+ Security.addProvider(prov);
+
+ try {
+ keyPairLevel1 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ keyPairLevel2 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(keyPairLevel1 != null);
+
+ assert(keyPairLevel2 != null);
+
+ }
+
+
+
+ @Test public void testDynamicHeaderBarcodeDecoding() {
+
+ 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",prov);
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+
+ DataType level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
+ try {
+ enc.setLevel2Data(level2Data);
+ enc.signLevel2(keyPairLevel2.getPrivate(),prov);
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(), null, prov);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel2(prov);
+ } catch (IllegalArgumentException | UnsupportedOperationException e) {
+ assert(false);
+ }
+ assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
+
+ DataType level2DataDec = dec.getLevel2Data();
+
+ assert(level2Data.getFormat().equals(level2DataDec.getFormat()));
+ assert(Arrays.equals(level2Data.getData().toByteArray(),level2DataDec.getData().toByteArray()));
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java new file mode 100644 index 0000000..f3e4f54 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java @@ -0,0 +1,258 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.temporal.ChronoUnit;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateSystemType;
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType;
+import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
+import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1;
+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;
+
+public class DynamicFrameDynamicContentTest {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPairLevel1 = null;
+ public KeyPair keyPairLevel2 = null;
+
+ public byte[] passIdHash = "PassId".getBytes();
+ public byte[] phoneIdHash = "myPhone".getBytes();
+
+ ZonedDateTime originalTimeStamp = ZonedDateTime.now(ZoneId.of("UTC"));
+
+ public IUicRailTicket testFCBticket = null;
+
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPairLevel1 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ keyPairLevel2 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(keyPairLevel1 != null);
+
+ assert(keyPairLevel2 != null);
+
+ }
+
+
+ @Test public void testDynamicContentEncoding() {
+
+ 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);
+
+ enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID, keyPairLevel2.getPublic());
+
+ try {
+ enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ try {
+ UicDynamicContentDataFDC1 dcd = new UicDynamicContentDataFDC1();
+ dcd.setChallengeString("CHALLENGE");
+ dcd.setAppId("MyApp");
+ dcd.setPhoneIdHash(phoneIdHash);
+ dcd.setPassIdHash(passIdHash);
+ TimeStamp ts = new TimeStamp();
+ ts.setDateTime(Date.from(originalTimeStamp.toInstant()));
+ dcd.setTimeStamp(ts);
+
+ GeoCoordinateType geo = new GeoCoordinateType();
+ geo.setLatitude(123456L);
+ geo.setLongitude(823456L);
+ dcd.setGeoCoordinate(geo);
+
+ enc.setDynamicContentDataUIC1(dcd);
+ 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 testDynamicContentDecoding() {
+
+ 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);
+
+ enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID, keyPairLevel2.getPublic());
+
+ try {
+ enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ try {
+ UicDynamicContentDataFDC1 dcd = new UicDynamicContentDataFDC1();
+ dcd.setChallengeString("CHALLENGE");
+ dcd.setAppId("MyApp");
+ dcd.setPhoneIdHash(phoneIdHash);
+ dcd.setPassIdHash(passIdHash);
+
+ GeoCoordinateType geo = new GeoCoordinateType();
+ geo.setLatitude(123456L);
+ geo.setLongitude(823456L);
+ dcd.setGeoCoordinate(geo);
+
+ TimeStamp ts = new TimeStamp();
+ ts.setDateTime(Date.from(originalTimeStamp.toInstant()));
+ dcd.setTimeStamp(ts);
+
+ enc.setDynamicContentDataUIC1(dcd);
+ enc.signLevel2(keyPairLevel2.getPrivate());
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+ int level2check = 0;
+ try {
+ level2check = dec.validateLevel2();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(level2check == Constants.LEVEL2_VALIDATION_OK);
+
+ UicDynamicContentDataFDC1 dynamicData = dec.getDynamicHeader().getDynamicDataFDC1();
+
+ assert(dynamicData.getChallengeString().equals("CHALLENGE"));
+
+ assert(dynamicData.getAppId().equals("MyApp"));
+
+ assert(Arrays.equals(dynamicData.getPassIdHash(),passIdHash));
+
+ assert(Arrays.equals(dynamicData.getPhoneIdHash(),phoneIdHash));
+
+ assert(dynamicData.getGeoCoordinate().getLatitude() == 123456L);
+ assert(dynamicData.getGeoCoordinate().getLongitude() == 823456L);
+
+ Date timeStamp = dynamicData.getTimeStamp().getTimeAsDate();
+ ZonedDateTime retrievedTimeStamp = timeStamp.toInstant().atZone(ZoneId.of("UTC"));
+ long diff = ChronoUnit.SECONDS.between(originalTimeStamp, retrievedTimeStamp);
+
+ assert(diff == 0);
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java new file mode 100644 index 0000000..63ba68e --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java @@ -0,0 +1,174 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+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;
+
+public class DynamicFrameFcbVersion1Test {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPair = null;
+
+ public IUicRailTicket testFCBticket = null;
+
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPair = generateECKeys(Constants.KG_EC, elipticCurve);
+ //keyPair = generateECDSAKeys("ECDSA", "B-571");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(keyPair != null);
+
+ }
+
+
+ @Test public void testDynamicHeaderBarcodeEncodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 1);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+
+ }
+
+ @Test public void testDynamicHeaderBarcodeDecodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 1);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ assert(dec.getDynamicHeader().getFormat().equals("U1"));
+
+ assert(dec.getDynamicHeader().getLevel2SignedData().getLevel1Data().getData().get(0).getFormat().equals("FCB1"));
+
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+
+
+
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java new file mode 100644 index 0000000..4f0897e --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java @@ -0,0 +1,174 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+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;
+
+public class DynamicFrameFcbVersion3Test {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPair = null;
+
+ public IUicRailTicket testFCBticket = null;
+
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPair = generateECKeys(Constants.KG_EC, elipticCurve);
+ //keyPair = generateECDSAKeys("ECDSA", "B-571");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(keyPair != null);
+
+ }
+
+
+ @Test public void testDynamicHeaderBarcodeEncodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+
+ }
+
+ @Test public void testDynamicHeaderBarcodeDecodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ assert(dec.getDynamicHeader().getFormat().equals("U1"));
+
+ assert(dec.getDynamicHeader().getLevel2SignedData().getLevel1Data().getData().get(0).getFormat().equals("FCB3"));
+
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+
+
+
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java new file mode 100644 index 0000000..41ce365 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java @@ -0,0 +1,193 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.staticFrame.ticketLayoutBarcode.TicketLayout;
+import org.uic.barcode.test.utils.SimpleTestTicketLayout;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+
+/**
+ * The Class StaticFrameBarcodeTest.
+ */
+public class StaticFrameBarcodeTestFCB3 {
+
+ /** The algorithm OID. */
+ public String algorithmOID = Constants.DSA_SHA224;
+
+ public int keySize = 2048;
+
+ /** The key pair. */
+ public KeyPair keyPair = null;
+
+
+ public IUicRailTicket testFCBticket = null;
+
+ public TicketLayout testLayout = null;
+
+
+ /**
+ * Initialize.
+ *
+ * set the signature algorithm
+ * generate a key pair
+ * set the test content
+ * for ticket and layout
+ */
+ @Before public void initialize() {
+
+ algorithmOID = Constants.DSA_SHA224;
+ keySize = 2048;
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+ testLayout = SimpleTestTicketLayout.getSimpleTestTicketLayout();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPair = generateDSAKeys(keySize);
+ } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
+ e.printStackTrace();
+ }
+
+ assert(keyPair != null);
+
+ }
+
+
+ /**
+ * Test dynamic header barcode encoding.
+ */
+ @Test public void testStaticHeaderBarcodeEncoding() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ TicketLayout layout = testLayout;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ enc.setStaticHeaderParams("123456789012", "de");
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ }
+
+ /**
+ * Test dynamic header barcode decoding.
+ */
+ @Test public void testStaticHeaderBarcodeDecoding() {
+
+
+ IUicRailTicket ticket = testFCBticket;
+
+ TicketLayout layout = testLayout;
+
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ enc.setStaticHeaderParams("123456789012", "de");
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),algorithmOID);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+ SimpleTestTicketLayout.compare(layout, dec.getLayout());
+
+ }
+
+ /**
+ * Generate DSA keys.
+ *
+ * @return the key pair
+ * @throws NoSuchAlgorithmException the no such algorithm exception
+ * @throws NoSuchProviderException the no such provider exception
+ * @throws InvalidAlgorithmParameterException the invalid algorithm parameter exception
+ */
+ public KeyPair generateDSAKeys(int keySize) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ KeyPairGenerator g = KeyPairGenerator.getInstance("DSA", "BC");
+ g.initialize(keySize, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+}
diff --git a/src/test/java/org/uic/barcode/ticket/api/test/CountermarkComplexTestV1.java b/src/test/java/org/uic/barcode/ticket/api/test/CountermarkComplexTestV1.java new file mode 100644 index 0000000..5226880 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/CountermarkComplexTestV1.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.omv1.UicRailTicketData;
+import org.uic.barcode.ticket.api.test.testtickets.CountermarkTestComplexTicketV1;
+
+
+/**
+ * The Class FipTimeZoneTestV3.
+ *
+ *
+ *
+ */
+public class CountermarkComplexTestV1 {
+
+
+
+ /** 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 = CountermarkTestComplexTicketV1.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 = CountermarkTestComplexTicketV1.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 = CountermarkTestComplexTicketV1.getEncodingHex();
+
+ assert(expectedHex.equals(encodedHex));
+
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/ticket/api/test/CountermarkComplexTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/CountermarkComplexTestV3.java new file mode 100644 index 0000000..86495f0 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/CountermarkComplexTestV3.java @@ -0,0 +1,111 @@ +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.CountermarkTestComplexTicketV3;
+
+
+/**
+ * The Class FipTimeZoneTestV3.
+ *
+ *
+ *
+ */
+public class CountermarkComplexTestV3 {
+
+
+
+ /** 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 = CountermarkTestComplexTicketV3.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 = CountermarkTestComplexTicketV3.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 = CountermarkTestComplexTicketV3.getEncodingHex();
+
+ assert(expectedHex.equals(encodedHex));
+
+ }
+
+ @Test public void encodingDecoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ ticket = CountermarkTestComplexTicketV3.getUicTestTicket();
+ byte[] encoded = UperEncoder.encode(ticket);
+
+
+
+ assert(encoded != null);
+ assert(encoded.length > 20);
+
+ String encodedHex = UperEncoder.hexStringFromBytes(encoded);
+ String expectedHex = CountermarkTestComplexTicketV3.getEncodingHex();
+
+ assert(expectedHex.equals(encodedHex));
+
+ }
+}
diff --git a/src/test/java/org/uic/barcode/ticket/api/test/testtickets/CountermarkTestComplexTicketV1.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/CountermarkTestComplexTicketV1.java new file mode 100644 index 0000000..4e6fd8e --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/CountermarkTestComplexTicketV1.java @@ -0,0 +1,509 @@ +package org.uic.barcode.ticket.api.test.testtickets;
+
+import org.uic.barcode.asn1.datatypesimpl.SequenceOfUnrestrictedLong;
+import org.uic.barcode.ticket.api.asn.omv1.CardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv1.ControlData;
+import org.uic.barcode.ticket.api.asn.omv1.CountermarkData;
+import org.uic.barcode.ticket.api.asn.omv1.CustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv1.DocumentData;
+import org.uic.barcode.ticket.api.asn.omv1.ExtensionData;
+import org.uic.barcode.ticket.api.asn.omv1.IssuingData;
+import org.uic.barcode.ticket.api.asn.omv1.LinkMode;
+import org.uic.barcode.ticket.api.asn.omv1.RegionalValidityType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCardReferenceType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfCustomerStatusType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfDocumentData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfExtensionData;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfRegionalValidityType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfTicketLinkType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfTravelerType;
+import org.uic.barcode.ticket.api.asn.omv1.SequenceOfViaStationType;
+import org.uic.barcode.ticket.api.asn.omv1.TicketDetailData;
+import org.uic.barcode.ticket.api.asn.omv1.TicketLinkType;
+import org.uic.barcode.ticket.api.asn.omv1.TicketType;
+import org.uic.barcode.ticket.api.asn.omv1.TravelClassType;
+import org.uic.barcode.ticket.api.asn.omv1.TravelerData;
+import org.uic.barcode.ticket.api.asn.omv1.TravelerType;
+import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
+import org.uic.barcode.ticket.api.asn.omv1.ViaStationType;
+import org.uic.barcode.ticket.api.asn.omv1.ZoneType;
+
+
+ public class CountermarkTestComplexTicketV1 {
+
+ 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 {
+ {
+ ticket counterMark : {
+ numberOfCountermark 12
+ ,totalOfCountermarks 24
+ ,groupName "groupName"
+ ,validRegion
+ { viaStations {
+ route {
+ { stationNum 123455, border FALSE }
+ ,{ stationNum 123456, border FALSE }
+ ,{ alternativeRoutes {
+ { route { {stationNum 23455, border FALSE},{stationNum 23456, border FALSE }}, border FALSE }
+ ,{ route { {stationNum 3455, border FALSE },{stationNum 3456, border FALSE }}, border FALSE }
+ }
+ ,border FALSE
+ }
+ ,{ stationNum 123457, border FALSE }
+ }
+ ,border FALSE
+ ,seriesId 999
+ }
+ ,zones { zoneId {100,200}}
+ }
+ ,returnIncluded FALSE
+ ,classCode first
+ ,infoText "counterMark"
+ }
+ }
+ }
+ ,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 }
+ }
+ }
+
+Encoding to the file 'data.uper' using PER UNALIGNED encoding rule...
+UicRailTicketData SEQUENCE [root fieldcount (not encoded) = 5]
+ issuingDetail IssuingData SEQUENCE [root fieldcount (not encoded) = 8]
+ issuingYear INTEGER [length (not encoded) = 1.0]
+ 2018
+ issuingDay INTEGER [length (not encoded) = 1.1]
+ 1
+ issuingTime INTEGER [length (not encoded) = 1.3]
+ 600
+ specimen BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ securePaperTicket BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ activated BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ issuerPNR IA5String [length = 13.0]
+ "issuerTestPNR"
+ issuedOnLine INTEGER [length = 1.0]
+ 12
+ travelerDetail TravelerData SEQUENCE [root fieldcount (not encoded) = 2]
+ traveler SEQUENCE OF [count = 1]
+ TravelerType SEQUENCE [root fieldcount (not encoded) = 5]
+ firstName UTF8String [length = 4.0]
+ 0x4a6f686e
+ secondName UTF8String [length = 3.0]
+ 0x446f77
+ idCard IA5String [length = 5.0]
+ "12345"
+ ticketHolder BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ status SEQUENCE OF [count = 1]
+ CustomerStatusType SEQUENCE [fieldcount (not encoded) = 1]
+ customerStatusDescr IA5String [length = 6.0]
+ "senior"
+ groupName UTF8String [length = 7.0]
+ 0x6d7947726f7570
+ transportDocument SEQUENCE OF [count = 1]
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 1]
+ ticket CHOICE [index = 6]
+ counterMark CountermarkData SEQUENCE [root fieldcount (not encoded) = 7]
+ numberOfCountermark INTEGER [length (not encoded) = 1.0]
+ 12
+ totalOfCountermarks INTEGER [length (not encoded) = 1.0]
+ 24
+ groupName UTF8String [length = 9.0]
+ 0x67726f75704e616d65
+ validRegion SEQUENCE OF [count = 2]
+ RegionalValidityType CHOICE [index = 1]
+ viaStations ViaStationType SEQUENCE [root fieldcount (not encoded) = 3]
+ route SEQUENCE OF [count = 4]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 123455
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 123456
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ alternativeRoutes SEQUENCE OF [count = 2]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ route SEQUENCE OF [count = 2]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 23455
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 23456
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ route SEQUENCE OF [count = 2]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 3455
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 3456
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 123457
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ seriesId INTEGER [length = 2.0]
+ 999
+ RegionalValidityType CHOICE [index = 2]
+ zones ZoneType SEQUENCE [root fieldcount (not encoded) = 1]
+ zoneId SEQUENCE OF [count = 2]
+ INTEGER [length = 1.0]
+ 100
+ INTEGER [length = 2.0]
+ 200
+ returnIncluded BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ classCode TravelClassType ENUMERATED [length (not encoded) = 0.3]
+ 1
+ infoText UTF8String [length = 11.0]
+ 0x636f756e7465724d61726b
+ controlDetail ControlData SEQUENCE [root fieldcount (not encoded) = 9]
+ identificationByCardReference SEQUENCE OF [count = 1]
+ CardReferenceType SEQUENCE [root fieldcount (not encoded) = 1]
+ trailingCardIdNum INTEGER [length = 1.0]
+ 100
+ identificationByIdCard BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ identificationByPassportId BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ passportValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ onlineValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ageCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ reductionCardCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 2.0]
+ 0x6364
+ includedTickets SEQUENCE OF [count = 1]
+ TicketLinkType SEQUENCE [root fieldcount (not encoded) = 6]
+ referenceIA5 IA5String [length = 11.0]
+ "UED12435867"
+ issuerName UTF8String [length = 4.0]
+ 0x4f454242
+ issuerPNR IA5String [length = 3.0]
+ "PNR"
+ productOwnerIA5 IA5String [length = 4.0]
+ "test"
+ ticketType TicketType ENUMERATED [length (not encoded) = 0.2]
+ 1
+ linkMode LinkMode ENUMERATED [length (not encoded) = 0.1]
+ 1
+ extension SEQUENCE OF [count = 2]
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "1"
+ extensionData OCTET STRING [length = 2.0]
+ 0x82da
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "2"
+ extensionData OCTET STRING [length = 2.0]
+ 0x83da
+Total encoded length = 184.1
+Encoded successfully in 185 bytes:
+78222020 0258A1BA 79F3EB97 954CBCFA 509D4804 31405A00 1044A6F6 86E03446
+F770562C 99B46B01 106E7977 69DFC81D B5E51DC9 BDD5C004 30000202 1058B84B
+3B937BAB 82730B6B 28108240 84000F11 F08001E2 3F040040 80110000 B73C2000
+16E7C040 0880000D 7E100001 AFE08001 E2400080 F9C80100 80590080 320216C6
+DEEADCE8 CAE49AC2 E4D69804 0100B200 04C6C802 B70BAB16 23164D19 B570D9B8
+227A2A12 101D09D4 813A65E7 D0A0402C 40A0B680 590141ED 00
+
+ */
+
+
+
+ public static String getEncodingHex() {
+ return
+ "782220200258A1BA79F3EB97954CBCFA509D480431405A001044A6F686E03446" +
+ "F770562C99B46B01106E797769DFC81DB5E51DC9BDD5C004300002021058B84B" +
+ "3B937BAB82730B6B2810824084000F11F08001E23F04004080110000B73C2000" +
+ "16E7C0400880000D7E100001AFE08001E2400080F9C8010080590080320216C6" +
+ "DEEADCE8CAE49AC2E4D698040100B20004C6C802B70BAB1623164D19B570D9B8" +
+ "227A2A12101D09D4813A65E7D0A0402C40A0B680590141ED00";
+ }
+
+
+
+ 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();
+ addCounterMark(do1);
+ ds.add(do1);
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+ private static void addCounterMark(DocumentData dd) {
+
+ TicketDetailData tdd = new TicketDetailData();
+ CountermarkData otd = new CountermarkData();
+ otd.setInfoText("counterMark");
+ otd.setClassCode(TravelClassType.first);
+ otd.setReturnIncluded(false);
+
+ otd.setNumberOfCountermark(12L);
+ otd.setTotalOfCountermarks(24L);;
+ otd.setGroupName("groupName");
+
+ otd.setValidRegion(getValidRegion());
+
+ tdd.setCounterMark(otd);
+ dd.setTicket(tdd);
+
+ }
+
+ private static SequenceOfRegionalValidityType getValidRegion() {
+ SequenceOfRegionalValidityType sr = new SequenceOfRegionalValidityType();
+ sr.add(getRegionalValidity());
+ sr.add(getZone());
+ return sr;
+ }
+
+ private static RegionalValidityType getRegionalValidity() {
+ RegionalValidityType r = new RegionalValidityType();
+ r.setViaStations(getRoute());
+ return r;
+ }
+
+ private static ViaStationType getRoute() {
+ ViaStationType m = new ViaStationType();
+ m.setRoute(getMainRoute());
+ m.setSeriesId(999L);
+ return m;
+ }
+
+
+
+ private static ViaStationType getAlternativeRoute() {
+ ViaStationType s = new ViaStationType();
+ s.setAlternativeRoutes(new SequenceOfViaStationType());
+ s.getAlternativeRoutes().add(getAltRoute1());
+ s.getAlternativeRoutes().add(getAltRoute2());
+ return s;
+ }
+
+ /*
+ * { route { {stationNum 23455, border FALSE},{stationNum 23456, border FALSE }}, border FALSE }
+ */
+ private static ViaStationType getAltRoute1() {
+ ViaStationType m = new ViaStationType();
+ m.setRoute(new SequenceOfViaStationType());
+ m.getRoute().add(getViaStation(23455L));
+ m.getRoute().add(getViaStation(23456L));
+ return m;
+ }
+
+ /*
+ * { route { {stationNum 3455, border FALSE },{stationNum 3456, border FALSE }}, border FALSE }
+ */
+
+
+ private static ViaStationType getAltRoute2() {
+ ViaStationType m = new ViaStationType();
+ m.setRoute(new SequenceOfViaStationType());
+ m.getRoute().add(getViaStation(3455L));
+ m.getRoute().add(getViaStation(3456L));
+ return m;
+ }
+
+
+ private static ViaStationType getViaStation(long i) {
+ ViaStationType s = new ViaStationType();
+ s.setStationNum(i);
+ return s;
+ }
+
+ private static SequenceOfViaStationType getMainRoute() {
+ SequenceOfViaStationType s = new SequenceOfViaStationType();
+ s.add(getViaStation(123455L));
+ s.add(getViaStation(123456L));
+ s.add(getAlternativeRoute());
+ s.add(getViaStation(123457L));
+ return s;
+ }
+
+ private static RegionalValidityType getZone() {
+ RegionalValidityType r = new RegionalValidityType();
+ ZoneType z = new ZoneType();
+ z.setZoneId(new SequenceOfUnrestrictedLong());
+ z.getZoneId().add(100L);
+ z.getZoneId().add(200L);
+ 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);
+ }
+
+ 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());
+ 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/CountermarkTestComplexTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/CountermarkTestComplexTicketV3.java new file mode 100644 index 0000000..1843ec3 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/CountermarkTestComplexTicketV3.java @@ -0,0 +1,544 @@ +package org.uic.barcode.ticket.api.test.testtickets;
+
+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.CountermarkData;
+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.RegionalValidityType;
+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.SequenceOfRegionalValidityType;
+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.SequenceOfViaStationType;
+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;
+import org.uic.barcode.ticket.api.asn.omv3.ViaStationType;
+import org.uic.barcode.ticket.api.asn.omv3.ZoneType;
+
+
+ public class CountermarkTestComplexTicketV3 {
+
+ 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 {
+ {
+ ticket counterMark : {
+ numberOfCountermark 12
+ ,totalOfCountermarks 24
+ ,groupName "groupName"
+ ,validRegion
+ { viaStations {
+ route {
+ { stationNum 123455, border FALSE }
+ ,{ stationNum 123456, border FALSE }
+ ,{ alternativeRoutes {
+ { route { {stationNum 23455, border FALSE},{stationNum 23456, border FALSE }}, border FALSE }
+ ,{ route { {stationNum 3455, border FALSE },{stationNum 3456, border FALSE }}, border FALSE }
+ }
+ ,border FALSE
+ }
+ ,{ stationNum 123457, border FALSE }
+ }
+ ,border FALSE
+ ,seriesId 999
+ }
+ ,zones { zoneId {100,200}}
+ }
+ ,returnIncluded FALSE
+ ,classCode first
+ ,infoText "counterMark"
+ }
+ }
+ }
+ ,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 }
+ }
+ }
+
+Encoding to the file 'data.uper' using PER UNALIGNED encoding rule...
+UicRailTicketData SEQUENCE [root fieldcount (not encoded) = 5]
+ issuingDetail IssuingData SEQUENCE [root fieldcount (not encoded) = 8]
+ issuingYear INTEGER [length (not encoded) = 1.0]
+ 2018
+ issuingDay INTEGER [length (not encoded) = 1.1]
+ 1
+ issuingTime INTEGER [length (not encoded) = 1.3]
+ 600
+ specimen BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ securePaperTicket BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ activated BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ issuerPNR IA5String [length = 13.0]
+ "issuerTestPNR"
+ issuedOnLine INTEGER [length = 1.0]
+ 12
+ travelerDetail TravelerData SEQUENCE [root fieldcount (not encoded) = 2]
+ traveler SEQUENCE OF [count = 1]
+ TravelerType SEQUENCE [root fieldcount (not encoded) = 5]
+ firstName UTF8String [length = 4.0]
+ 0x4a6f686e
+ secondName UTF8String [length = 3.0]
+ 0x446f77
+ idCard IA5String [length = 5.0]
+ "12345"
+ ticketHolder BOOLEAN [length (not encoded) = 0.1]
+ TRUE
+ status SEQUENCE OF [count = 1]
+ CustomerStatusType SEQUENCE [fieldcount (not encoded) = 1]
+ customerStatusDescr IA5String [length = 6.0]
+ "senior"
+ groupName UTF8String [length = 7.0]
+ 0x6d7947726f7570
+ transportDocument SEQUENCE OF [count = 1]
+ DocumentData SEQUENCE [root fieldcount (not encoded) = 1]
+ ticket CHOICE [index = 6]
+ counterMark CountermarkData SEQUENCE [root fieldcount (not encoded) = 7]
+ numberOfCountermark INTEGER [length (not encoded) = 1.0]
+ 12
+ totalOfCountermarks INTEGER [length (not encoded) = 1.0]
+ 24
+ groupName UTF8String [length = 9.0]
+ 0x67726f75704e616d65
+ validRegion SEQUENCE OF [count = 2]
+ RegionalValidityType CHOICE [index = 1]
+ viaStations ViaStationType SEQUENCE [root fieldcount (not encoded) = 3]
+ route SEQUENCE OF [count = 4]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 123455
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 123456
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ alternativeRoutes SEQUENCE OF [count = 2]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ route SEQUENCE OF [count = 2]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 23455
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 23456
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ route SEQUENCE OF [count = 2]
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 3455
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 3456
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ViaStationType SEQUENCE [root fieldcount (not encoded) = 2]
+ stationNum INTEGER [length (not encoded) = 3.0]
+ 123457
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ border BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ seriesId INTEGER [length = 2.0]
+ 999
+ RegionalValidityType CHOICE [index = 2]
+ zones ZoneType SEQUENCE [root fieldcount (not encoded) = 1]
+ zoneId SEQUENCE OF [count = 2]
+ INTEGER [length = 1.0]
+ 100
+ INTEGER [length = 2.0]
+ 200
+ returnIncluded BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ classCode TravelClassType ENUMERATED [length (not encoded) = 0.4]
+ 1
+ infoText UTF8String [length = 11.0]
+ 0x636f756e7465724d61726b
+ controlDetail ControlData SEQUENCE [root fieldcount (not encoded) = 9]
+ identificationByCardReference SEQUENCE OF [count = 1]
+ CardReferenceType SEQUENCE [root fieldcount (not encoded) = 1]
+ trailingCardIdNum INTEGER [length = 1.0]
+ 100
+ identificationByIdCard BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ identificationByPassportId BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ passportValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ onlineValidationRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ ageCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ reductionCardCheckRequired BOOLEAN [length (not encoded) = 0.1]
+ FALSE
+ infoText UTF8String [length = 2.0]
+ 0x6364
+ includedTickets SEQUENCE OF [count = 1]
+ TicketLinkType SEQUENCE [root fieldcount (not encoded) = 6]
+ referenceIA5 IA5String [length = 11.0]
+ "UED12435867"
+ issuerName UTF8String [length = 4.0]
+ 0x4f454242
+ issuerPNR IA5String [length = 3.0]
+ "PNR"
+ productOwnerIA5 IA5String [length = 4.0]
+ "test"
+ ticketType TicketType ENUMERATED [length (not encoded) = 0.2]
+ 1
+ linkMode LinkMode ENUMERATED [length (not encoded) = 0.1]
+ 1
+ extension SEQUENCE OF [count = 2]
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "1"
+ extensionData OCTET STRING [length = 2.0]
+ 0x82da
+ ExtensionData SEQUENCE [fieldcount (not encoded) = 2]
+ extensionId IA5String [length = 1.0]
+ "2"
+ extensionData OCTET STRING [length = 2.0]
+ 0x83da
+Total encoded length = 187.0
+Encoded successfully in 187 bytes:
+78044040 04B14374 F3E7D72F 2A9979F4 A13A9008 6280B400 1044A6F6 86E03446
+F770562C 99B46B01 106E7977 69DFC81D B5E51DC9 BDD5C004 30000202 1058B84B
+3B937BAB 82730B6B 28108240 210000F1 1F080007 88FC1000 40800440 000B73C2
+00005B9F 01000880 00035F84 00001AFE 08000789 000203E7 20040201 640200C8
+042D8DBD D5B9D195 C93585C9 AD300802 01640009 8D90056E 17562C46 2C9A336A
+E1B37044 F4542420 3A13A902 74CBCFA1 40805881 416D00B2 0283DA
+
+ */
+
+
+
+ public static String getEncodingHex() {
+ return
+ "7804404004B14374F3E7D72F2A9979F4A13A90086280B4001044A6F686E03446" +
+ "F770562C99B46B01106E797769DFC81DB5E51DC9BDD5C004300002021058B84B" +
+ "3B937BAB82730B6B28108240210000F11F08000788FC100040800440000B73C2" +
+ "00005B9F0100088000035F8400001AFE08000789000203E720040201640200C8" +
+ "042D8DBDD5B9D195C93585C9AD300802016400098D90056E17562C462C9A336A" +
+ "E1B37044F45424203A13A90274CBCFA140805881416D00B20283DA";
+ }
+
+
+
+ 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();
+ addCounterMark(do1);
+ ds.add(do1);
+ ticket.setTransportDocument(ds);
+
+ SequenceOfExtensionData ed = new SequenceOfExtensionData();
+ populateExtensionSequence(ed);
+ ticket.setExtension(ed);
+
+ }
+
+
+ private static void addCounterMark(DocumentData dd) {
+
+ TicketDetailData tdd = new TicketDetailData();
+ CountermarkData otd = new CountermarkData();
+ otd.setInfoText("counterMark");
+ otd.setClassCode(TravelClassType.first);
+ otd.setReturnIncluded(false);
+
+ otd.setNumberOfCountermark(12L);
+ otd.setTotalOfCountermarks(24L);
+ otd.setGroupName("groupName");
+
+ otd.setValidRegion(getValidRegion());
+
+ tdd.setCounterMark(otd);
+ dd.setTicket(tdd);
+
+ }
+
+ private static SequenceOfRegionalValidityType getValidRegion() {
+ SequenceOfRegionalValidityType sr = new SequenceOfRegionalValidityType();
+ sr.add(getRegionalValidity());
+ sr.add(getZone());
+ return sr;
+ }
+
+ private static RegionalValidityType getRegionalValidity() {
+ RegionalValidityType r = new RegionalValidityType();
+ r.setViaStations(getRoute());
+ return r;
+ }
+
+ private static ViaStationType getRoute() {
+ ViaStationType m = new ViaStationType();
+ m.setRoute(getMainRoute());
+ m.setSeriesId(999L);
+ return m;
+ }
+
+
+
+ private static ViaStationType getAlternativeRoute() {
+ ViaStationType s = new ViaStationType();
+ s.setAlternativeRoutes(new SequenceOfViaStationType());
+ s.getAlternativeRoutes().add(getAltRoute1());
+ s.getAlternativeRoutes().add(getAltRoute2());
+ return s;
+ }
+
+ /*
+ * { route { {stationNum 23455, border FALSE},{stationNum 23456, border FALSE }}, border FALSE }
+ */
+ private static ViaStationType getAltRoute1() {
+ ViaStationType m = new ViaStationType();
+ m.setRoute(new SequenceOfViaStationType());
+ m.getRoute().add(getViaStation(23455L));
+ m.getRoute().add(getViaStation(23456L));
+ return m;
+ }
+
+ /*
+ * { route { {stationNum 3455, border FALSE },{stationNum 3456, border FALSE }}, border FALSE }
+ */
+
+
+ private static ViaStationType getAltRoute2() {
+ ViaStationType m = new ViaStationType();
+ m.setRoute(new SequenceOfViaStationType());
+ m.getRoute().add(getViaStation(3455L));
+ m.getRoute().add(getViaStation(3456L));
+ return m;
+ }
+
+ private static ViaStationType getViaStation(long i) {
+ ViaStationType s = new ViaStationType();
+ s.setStationNum(i);
+ return s;
+ }
+
+ private static SequenceOfViaStationType getMainRoute() {
+ SequenceOfViaStationType s = new SequenceOfViaStationType();
+ s.add(getViaStation(123455L));
+ s.add(getViaStation(123456L));
+ s.add(getAlternativeRoute());
+ s.add(getViaStation(123457L));
+ return s;
+ }
+
+ private static RegionalValidityType getZone() {
+ RegionalValidityType r = new RegionalValidityType();
+ ZoneType z = new ZoneType();
+ z.setZoneId(new SequenceOfUnrestrictedLong());
+ z.getZoneId().add(100L);
+ z.getZoneId().add(200L);
+ 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
+ issuingTime 600
+ specimen TRUE,
+ securePaperTicket FALSE,
+ activated TRUE,
+ issuerPNR "issuerTestPNR",
+ issuedOnLine 12
+ */
+ 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);
+ }
+
+ /*
+ *extension {
+ { extensionId "1", extensionData '82DA'H }
+ ,{ extensionId "2", extensionData '83DA'H }
+ }
+ */
+ private static void populateExtensionSequence(SequenceOfExtensionData ed) {
+ ExtensionData ed1 = new ExtensionData();
+ ed1.setExtensionId("1");
+ byte[] ba1 = { (byte) 0x82, (byte) 0xDA };
+ ed1.setExtensionData(ba1);
+ ExtensionData ed2 = new ExtensionData();
+ ed2.setExtensionId("2");
+ byte[] ba2 = { (byte) 0x83, (byte) 0xDA };
+ ed2.setExtensionData(ba2);
+ ed.add(ed1);
+ ed.add(ed2);
+ }
+
+
+ /*
+ *controlDetail {
+ identificationByCardReference {{ trailingCardIdNum 100 } }
+ ,identificationByIdCard FALSE
+ ,identificationByPassportId FALSE
+ ,passportValidationRequired FALSE
+ ,onlineValidationRequired FALSE
+ ,ageCheckRequired FALSE
+ ,reductionCardCheckRequired FALSE
+ ,infoText "cd"
+ }
+ }
+ */
+ 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);
+ }
+
+
+ /*
+ * includedTickets {
+ { referenceIA5 "UED12435867"
+ ,issuerName "OEBB"
+ ,issuerPNR "PNR"
+ ,productOwnerIA5 "test"
+ ,ticketType pass
+ ,linkMode onlyValidInCombination
+ }
+ */
+ private static void populateLinkedTickets(SequenceOfTicketLinkType sequenceOfTicketLinkType) {
+ TicketLinkType tlt = new TicketLinkType();
+ tlt.setProductOwnerIA5("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;
+ }
+
+ }
|