From fbbc6349283bc8958cad51534da9cb82c46210c9 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:37:37 +0100 Subject: api layer for dynamic content --- .../barcode/test/AsnLevelDynamicContentTest.java | 112 +++++++++++++++++++ .../uic/barcode/test/DynamicContentCoderTest.java | 118 +++++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java create mode 100644 src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java (limited to 'src/test/java/org/uic') diff --git a/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java b/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java new file mode 100644 index 0000000..955066d --- /dev/null +++ b/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java @@ -0,0 +1,112 @@ +package org.uic.barcode.test; + +import org.junit.Before; +import org.junit.Test; +import org.uic.barcode.asn1.uper.UperEncoder; +import org.uic.barcode.dynamicContent.fdc1.ExtensionData; +import org.uic.barcode.dynamicContent.fdc1.TimeStamp; +import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1; +import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType; + +public class AsnLevelDynamicContentTest { + + UicDynamicContentDataFDC1 asn = null; + + @Before public void initialize() { + + + asn = new UicDynamicContentDataFDC1(); + + asn.setAppId("appID"); + + asn.setChallengeString("challenge string"); + + ExtensionData asnE1 = new ExtensionData(); + asnE1.setExtensionData(UperEncoder.bytesFromHexString("82DA")); + asnE1.setExtensionId("challenge_extension_id1"); + asn.setDynamicContentExtension(asnE1); + + + asn.getExtensions().add(asnE1); + + ExtensionData asnE2 = new ExtensionData(); + asnE2.setExtensionData(UperEncoder.bytesFromHexString("83DA")); + asnE2.setExtensionId("phone"); + asn.getExtensions().add(asnE2); + + ExtensionData asnE3 = new ExtensionData(); + asnE3.setExtensionData(UperEncoder.bytesFromHexString("84DA")); + asnE3.setExtensionId("pass"); + asn.getExtensions().add(asnE3); + + + + asn.setGeoCoordinate(new GeoCoordinateType()); + asn.getGeoCoordinate().setLongitude( 12345L); + asn.getGeoCoordinate().setLatitude( 56789L); + + TimeStamp t = new TimeStamp(); + t.setTime(100L); + t.setDay(20L); + asn.setTimeStamp(t); + + + + } + + @Test public void testDynamicContentEncoding() { + + byte[] encodedBytes = UperEncoder.encode(asn); + + String encoding = UperEncoder.hexStringFromBytes(encodedBytes); + + String expectedEncoding = "7C170F0E126204C00C800230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA"; + + assert(expectedEncoding.equals(encoding)); + + } + + @Test public void testDynamicContentDecoding() { + + String encoding = "7C170F0E126204C00C800230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA"; + + UicDynamicContentDataFDC1 asn = UperEncoder.decode(UperEncoder.bytesFromHexString(encoding), UicDynamicContentDataFDC1.class); + + + assert("appID".equals(asn.getAppId())); + + assert("challenge string".equals(asn.getChallengeString())); + + ExtensionData asnE1 = asn.getDynamicContentExtension(); + assert(UperEncoder.hexStringFromBytes(asnE1.getExtensionData()).equals("82DA")); + assert(asnE1.getExtensionId().equals("challenge_extension_id1")); + + + assert(asn.getExtensions().size() == 4); + + assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(0).getExtensionData()).equals("6368616C6C656E676520737472696E67")); + assert(asn.getExtensions().get(0).getExtensionId().equals("=")); + + assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(1).getExtensionData()).equals("82DA")); + assert(asn.getExtensions().get(1).getExtensionId().equals("challenge_extension_id1")); + + assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(2).getExtensionData()).equals("83DA")); + assert(asn.getExtensions().get(2).getExtensionId().equals("phone")); + + assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(3).getExtensionData()).equals("84DA")); + assert(asn.getExtensions().get(3).getExtensionId().equals("pass")); + + + assert(asn.getGeoCoordinate() != null); + assert(asn.getGeoCoordinate().getLongitude() == 12345L); + assert(asn.getGeoCoordinate().getLatitude() == 56789L); + + assert(asn.getTimeStamp() != null); + assert(asn.getTimeStamp().getDay() == 20L); + assert(asn.getTimeStamp().getTime() == 100L); + + } + + + +} diff --git a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java new file mode 100644 index 0000000..10963c5 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java @@ -0,0 +1,118 @@ +package org.uic.barcode.test; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import org.junit.Before; +import org.junit.Test; +import org.uic.barcode.asn1.uper.UperEncoder; +import org.uic.barcode.dynamicContent.api.DynamicContentCoder; +import org.uic.barcode.dynamicContent.api.IUicDynamicContent; +import org.uic.barcode.dynamicContent.api.SimpleUicDynamicContent; +import org.uic.barcode.ticket.EncodingFormatException; +import org.uic.barcode.ticket.api.impl.SimpleExtension; +import org.uic.barcode.ticket.api.impl.SimpleGeoCoordinate; +import org.uic.barcode.ticket.api.spec.IExtension; +import org.uic.barcode.ticket.api.spec.IGeoCoordinate; + +public class DynamicContentCoderTest { + + IUicDynamicContent content = null; + + @Before public void initialize() { + + content = new SimpleUicDynamicContent(); + + content.setAppId("appID"); + + content.setChallengeString("challenge string"); + + IExtension e = new SimpleExtension(); + e.setId("challenge_extension_id1"); + e.setBinarydata(UperEncoder.bytesFromHexString("82DA")); + content.setExtension(e); + + IExtension e1 = new SimpleExtension(); + e1.setId("challenge_extension_id1"); + e1.setBinarydata(UperEncoder.bytesFromHexString("82DA")); + content.addDynamicContentResponse(e1); + + content.setPhoneIdHash(UperEncoder.bytesFromHexString("83DA")); + + content.setPassIdHash(UperEncoder.bytesFromHexString("84DA")); + + IGeoCoordinate g = new SimpleGeoCoordinate(); + g.setLongitude( 12345L); + g.setLatitude( 56789L); + content.setGeoCoordinate(g); + + try { + content.setTimeStamp(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" )); + } catch (ParseException e2) { + // + } + + } + + @Test public void testDynamicContentEncoding() { + + + byte[] encodedBytes = null; + try { + encodedBytes = DynamicContentCoder.encode(content, null); + } catch (EncodingFormatException e) { + assert(false); + } + + String encoding = UperEncoder.hexStringFromBytes(encodedBytes); + + String expectedEncoding = "7C170F0E12620F9437000230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA"; + + assert(expectedEncoding.equals(encoding)); + + } + + @Test public void testDynamicContentDecoding() { + + String encoding = "7C170F0E12620F9437000230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA"; + + IUicDynamicContent content = DynamicContentCoder.decode(UperEncoder.bytesFromHexString(encoding)); + + + assert("appID".equals(content.getAppId())); + + assert("challenge string".equals(content.getChallengeString())); + + IExtension e1 = content.getExtension(); + assert(UperEncoder.hexStringFromBytes(e1.getBinarydata()).equals("82DA")); + assert(e1.getId().equals("challenge_extension_id1")); + + + assert(content.getChallengeString().equals("challenge string")); + + byte[] ce = null; + for (IExtension e : content.getDynamicContentResponseList()) { + if (e.getId().equals("challenge_extension_id1")) { + ce = e.getBinarydata(); + } + } + assert(UperEncoder.hexStringFromBytes(ce).equals("82DA")); + + assert(UperEncoder.hexStringFromBytes(content.getPhoneIdHash()).equals("83DA")); + + assert(UperEncoder.hexStringFromBytes(content.getPassIdHash()).equals("84DA")); + + assert(content.getGeoCoordinate() != null); + assert(content.getGeoCoordinate().getLongitude() == 12345L); + assert(content.getGeoCoordinate().getLatitude() == 56789L); + + assert(content.getTimeStamp() != null); + + assert(content.getTimeStamp().toString().equals("Wed Dec 15 12:30:00 CET 2021" )); + + + } + + + +} -- cgit v1.2.3