summaryrefslogtreecommitdiffstats
path: root/src/org/uic/barcode/test/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/uic/barcode/test/utils')
-rw-r--r--src/org/uic/barcode/test/utils/Level2TestDataFactory.java20
-rw-r--r--src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java80
-rw-r--r--src/org/uic/barcode/test/utils/SimpleTestTicketLayout.java33
-rw-r--r--src/org/uic/barcode/test/utils/SimpleUICTestTicket.java254
-rw-r--r--src/org/uic/barcode/test/utils/TestUtils.java38
5 files changed, 425 insertions, 0 deletions
diff --git a/src/org/uic/barcode/test/utils/Level2TestDataFactory.java b/src/org/uic/barcode/test/utils/Level2TestDataFactory.java
new file mode 100644
index 0000000..a361561
--- /dev/null
+++ b/src/org/uic/barcode/test/utils/Level2TestDataFactory.java
@@ -0,0 +1,20 @@
+package org.uic.barcode.test.utils;
+
+import org.uic.barcode.dynamicFrame.DataType;
+
+import net.gcdc.asn1.datatypesimpl.OctetString;
+
+public class Level2TestDataFactory {
+
+ public static DataType getLevel2SimpleTestData() {
+
+ String testContent = "2020.10.01T12:12.20";
+
+ DataType level2Data = new DataType();
+ level2Data.setFormat("TEST");
+ level2Data.setData(new OctetString(testContent.getBytes()));
+
+ return level2Data;
+ }
+
+}
diff --git a/src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java b/src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java
new file mode 100644
index 0000000..1782ca6
--- /dev/null
+++ b/src/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java
@@ -0,0 +1,80 @@
+package org.uic.barcode.test.utils;
+
+import java.security.KeyPair;
+
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.DataType;
+import org.uic.barcode.dynamicFrame.DynamicFrame;
+import org.uic.barcode.dynamicFrame.Level1DataType;
+import org.uic.barcode.dynamicFrame.Level2DataType;
+import org.uic.barcode.dynamicFrame.SequenceOfDataType;
+import org.uic.ticket.EncodingFormatException;
+import org.uic.ticket.api.asn.omv1.UicRailTicketData;
+import org.uic.ticket.api.test.SimpleUicTestTicket;
+
+
+public class SimpleDynamicFrameTestBarcode {
+
+ public static DynamicFrame getSimpleDynamicHeaderBarcode(String algorithm, KeyPair keyPair) {
+
+
+
+ DynamicFrame barcode = null;
+
+
+
+ try {
+ barcode = new DynamicFrame();
+ barcode.setFormat(Constants.DYNAMIC_BARCODE_FORMAT_DEFAULT);
+ Level2DataType level2Data = new Level2DataType();
+ barcode.setLevel2SignedData(level2Data);
+
+ Level1DataType level1Data = new Level1DataType();
+ level2Data.setLevel1Data(level1Data);
+
+ level1Data.setSecurityProvider("1080");
+ level1Data.setKeyId(1L);
+
+ level1Data.setLevel1SigningAlg(Constants.ECDSA_SHA256);
+
+ DataType data = new DataType();
+ UicRailTicketData ticket = SimpleUicTestTicket.getUicTestTicket();
+ byte[] ticketData = ticket.encode();
+ data.setByteData(ticketData);
+ data.setFormat(Constants.DATA_TYPE_FCB_VERSION_1);
+ SequenceOfDataType dataSequence = new SequenceOfDataType();
+ level1Data.setData(dataSequence);
+ level1Data.getData().add(data);
+
+ try {
+ level2Data.signLevel1(keyPair.getPrivate());
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ } catch (EncodingFormatException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ return barcode;
+ }
+
+
+ public static void compareFrame(DynamicFrame frame1, DynamicFrame frame2) {
+
+ assert(frame1.getLevel2SignedData().getLevel1Data().getKeyId() == frame2.getLevel2SignedData().getLevel1Data().getKeyId());
+
+ assert(frame1.getLevel2SignedData().getLevel1Data().getLevel1SigningAlg().equals(frame2.getLevel2SignedData().getLevel1Data().level1SigningAlg));
+
+ assert(frame1.getLevel2SignedData().getLevel1Data().getSecurityProvider().equals(frame2.getLevel2SignedData().getLevel1Data().getSecurityProvider()));
+
+ DataType data1 = frame1.getLevel2SignedData().getLevel1Data().getData().get(0);
+ DataType data2 = frame2.getLevel2SignedData().getLevel1Data().getData().get(0);
+
+ assert(data1.getFormat().equals(data2.getFormat()));
+
+ }
+
+}
diff --git a/src/org/uic/barcode/test/utils/SimpleTestTicketLayout.java b/src/org/uic/barcode/test/utils/SimpleTestTicketLayout.java
new file mode 100644
index 0000000..24cbf50
--- /dev/null
+++ b/src/org/uic/barcode/test/utils/SimpleTestTicketLayout.java
@@ -0,0 +1,33 @@
+package org.uic.barcode.test.utils;
+
+import org.uic.barcode.staticHeader.ticketLayoutBarcode.LayoutElement;
+import org.uic.barcode.staticHeader.ticketLayoutBarcode.TicketLayout;
+
+public class SimpleTestTicketLayout {
+
+
+ public static TicketLayout getSimpleTestTicketLayout() {
+
+ TicketLayout layout = new TicketLayout();
+
+ layout.setLayoutStandard("RCT2");
+
+ LayoutElement element = new LayoutElement();
+ element.setColumn(1);
+ element.setLine(1);
+ element.setHeight(1);
+ element.setWidth(20);
+ element.setText("Müller");
+ layout.addLayoutElement(element);
+
+ return layout;
+
+ }
+
+ public static void compare(TicketLayout layout1, TicketLayout layout2) {
+
+ assert(layout1.getLayoutStandard().equals(layout2.getLayoutStandard()));
+
+ }
+
+}
diff --git a/src/org/uic/barcode/test/utils/SimpleUICTestTicket.java b/src/org/uic/barcode/test/utils/SimpleUICTestTicket.java
new file mode 100644
index 0000000..3f38515
--- /dev/null
+++ b/src/org/uic/barcode/test/utils/SimpleUICTestTicket.java
@@ -0,0 +1,254 @@
+package org.uic.barcode.test.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.uic.ticket.api.impl.SimpleCardReference;
+import org.uic.ticket.api.impl.SimpleControlDetail;
+import org.uic.ticket.api.impl.SimpleCustomerStatusDescription;
+import org.uic.ticket.api.impl.SimpleExtension;
+import org.uic.ticket.api.impl.SimpleIssuingDetail;
+import org.uic.ticket.api.impl.SimpleOpenTicket;
+import org.uic.ticket.api.impl.SimpleStationPassage;
+import org.uic.ticket.api.impl.SimpleTicketLink;
+import org.uic.ticket.api.impl.SimpleToken;
+import org.uic.ticket.api.impl.SimpleTraveler;
+import org.uic.ticket.api.impl.SimpleTravelerDetail;
+import org.uic.ticket.api.impl.SimpleUicRailTicket;
+import org.uic.ticket.api.spec.ICardReference;
+import org.uic.ticket.api.spec.IControlDetail;
+import org.uic.ticket.api.spec.ICustomerStatusDescription;
+import org.uic.ticket.api.spec.IExtension;
+import org.uic.ticket.api.spec.IIssuingDetail;
+import org.uic.ticket.api.spec.ILinkMode;
+import org.uic.ticket.api.spec.IOpenTicket;
+import org.uic.ticket.api.spec.IStationPassage;
+import org.uic.ticket.api.spec.ITicketLink;
+import org.uic.ticket.api.spec.IToken;
+import org.uic.ticket.api.spec.ITraveler;
+import org.uic.ticket.api.spec.IUicRailTicket;
+
+public class SimpleUICTestTicket {
+
+
+ public static IUicRailTicket getUicTestTicket() {
+ IUicRailTicket ticket = new SimpleUicRailTicket();
+ populateTicket(ticket);
+ return ticket;
+ }
+
+
+ private static void populateTicket(IUicRailTicket ticket) {
+
+ ticket.setControlDetails(new SimpleControlDetail());
+ populate(ticket.getControlDetails());
+
+
+ ticket.setIssuerDetails(new SimpleIssuingDetail());
+ populateIssuingData(ticket.getIssuerDetails());
+
+ SimpleTravelerDetail td = new SimpleTravelerDetail();
+ populateTravelerData(td);
+ ticket.setTravelerDetails(td);
+
+
+ //OpenTicket
+ IOpenTicket do1 = new SimpleOpenTicket();
+ populate(do1);
+ ticket.addOpenTicket(do1);
+
+ //StationPassage
+ IStationPassage do2 = new SimpleStationPassage();
+ populateStationPassage(do2);
+ ticket.addStationPassage(do2);
+
+ //token
+ IToken to = new SimpleToken();
+ to.setTokenProvider("VDV");
+ byte[] ba = { (byte) 0x82, (byte) 0xDA };
+ to.setToken(ba);
+
+
+ ticket.addExtension(populateExtension());
+
+ }
+
+ /*
+ ticket stationPassage : {
+ productName "passage"
+ ,station {8312345}
+ ,stationNameUTF8 { "Amsterdam" }
+ ,validFromDay 0
+ ,validUntilDay 4
+ }
+ */
+ private static void populateStationPassage(IStationPassage sp) {
+ sp.setProductName("passage");
+
+ try {
+ Date date = new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2018");
+ sp.setValidFrom(date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ try {
+ Date date = new SimpleDateFormat("dd/MM/yyyy").parse("04/01/2018");
+ sp.setValidUntil(date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ sp.addStation("8312345");
+ sp.addStationName("Amsterdam");
+
+ }
+
+ /*
+ {
+ token {tokenProviderIA5 "VDV", token '82DA'H }
+ ,ticket openTicket : {
+ returnIncluded FALSE
+ infoText "openTicketInfo"
+ }
+ }
+ */
+
+ private static void populate(IOpenTicket otd) {
+ otd.setInfoText("openTicketInfo");
+ otd.setReturnIncluded(false);
+ }
+
+
+ /*
+ ,travelerDetail{
+ traveler {
+ {
+ firstName "John"
+ ,secondName "Dow"
+ ,idCard "12345"
+ ,ticketHolder TRUE
+ ,status {{customerStatusDescr "senior" }}
+ }
+ }
+ ,groupName "myGroup"
+ }
+ */
+
+ private static void populateTravelerData(SimpleTravelerDetail td) {
+ td.setGroupName("myGroup");
+ ITraveler tr = new SimpleTraveler();
+ tr.setIdCard("12345");
+ tr.setFirstName("John");
+ tr.setSecondName("Dow");
+ tr.setTicketHolder(true);
+ ICustomerStatusDescription cst = new SimpleCustomerStatusDescription();
+ tr.addStatusDescription(cst);
+ cst.setDescription("senior");
+ td.addTraveler(tr);
+ }
+
+ /*
+ ,issuingDetail {
+ issuerNum 1080
+ issuingYear 2018
+ issuingDay 1
+ specimen TRUE,
+ securePaperTicket FALSE,
+ activated TRUE,
+ issuerPNR "issuerTestPNR",
+ issuedOnLine 12
+ }
+ */
+ private static void populateIssuingData(IIssuingDetail iIssuingDetail) {
+
+ try {
+ Date date = new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2018");
+ iIssuingDetail.setIssuer("1080");
+ iIssuingDetail.setIssuingDate(date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+
+ iIssuingDetail.setIssuerPNR("issuerTestPNR");
+ iIssuingDetail.setSpecimen(true);
+ iIssuingDetail.setSecurePaperTicket(false);
+ iIssuingDetail.setActivated(true);
+ iIssuingDetail.setIssuedOnLine(12);
+ }
+
+ /*
+ ,extension {
+ { extensionId "1", extensionData '82DA'H }
+ ,{ extensionId "2", extensionData '83DA'H }
+ }
+ */
+ private static IExtension populateExtension() {
+ IExtension ed1 = new SimpleExtension();
+ ed1.setId("1");
+ byte[] ba1 = { (byte) 0x82, (byte) 0xDA };
+ ed1.setBinarydata(ba1);
+ return ed1;
+ }
+
+ /*
+ ,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(IControlDetail iControlDetail) {
+ iControlDetail.setInfoText("cd");
+ iControlDetail.setAgeCheckRequired(false);
+ iControlDetail.setIdentificationByIdCard(false);
+ iControlDetail.setIdentificationByPassportId(false);
+ iControlDetail.setOnlineValidationRequired(false);
+ iControlDetail.setPassportValidationRequired(false);
+ iControlDetail.setReductionCardCheckRequired(false);
+ iControlDetail.getIdentificationByCardReference().add(populateCardRefrence());
+ iControlDetail.addLinkedTicket(populateLinkedTicket());
+ }
+
+
+ /*
+ *
+ */
+ private static ITicketLink populateLinkedTicket() {
+ ITicketLink it = new SimpleTicketLink();
+ it.setProductOwner("test");
+ it.setLinkMode(ILinkMode.issuedTogether);
+ return it;
+ }
+
+ /*
+ {
+ trailingCardIdNum 100
+ }
+ */
+ private static ICardReference populateCardRefrence() {
+ ICardReference cr = new SimpleCardReference();
+ cr.setTrailingCardId("100");
+ return cr;
+ }
+
+
+ public static void compare(IUicRailTicket ticket1, IUicRailTicket ticket2) {
+
+ assert(ticket1.getIssuerDetails().getIssuer().equals(ticket2.getIssuerDetails().getIssuer()));
+
+ }
+
+
+}
diff --git a/src/org/uic/barcode/test/utils/TestUtils.java b/src/org/uic/barcode/test/utils/TestUtils.java
new file mode 100644
index 0000000..7311ae4
--- /dev/null
+++ b/src/org/uic/barcode/test/utils/TestUtils.java
@@ -0,0 +1,38 @@
+package org.uic.barcode.test.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class TestUtils {
+
+ final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
+
+ public static String hexStringFromBytes(byte[] bytes) {
+ char[] hexChars = new char[bytes.length * 2];
+ for (int j = 0; j < bytes.length; j++) {
+ int v = bytes[j] & 0xFF;
+ hexChars[j * 2] = hexArray[v >>> 4];
+ hexChars[j * 2 + 1] = hexArray[v & 0x0F];
+ }
+ return new String(hexChars);
+ }
+
+
+ public static Date parseDate (String source){
+
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+
+ try {
+ return formatter.parse(source);
+ } catch (ParseException e) {
+ try {
+ return formatter.parse("2001-01-01");
+ } catch (ParseException e1) {
+ return null;
+ }
+ }
+
+ }
+
+}