use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class EMVTagSequenceTest method testPacking.
@Test
public void testPacking() throws ISOException, FileNotFoundException, UnknownTagNumberException {
ISOMsg msg = new ISOMsg("0100");
EMVTagSequence tagValueSequence = new EMVTagSequence();
tagValueSequence.add(new LiteralEMVTag(EMVStandardTagType.APPLICATION_PRIMARY_ACCOUNT_NUMBER_0x5A, "999999123456789"));
tagValueSequence.add(new LiteralEMVTag(EMVStandardTagType.APPLICATION_PREFERRED_NAME_0x9F12, "JPOS"));
tagValueSequence.add(new LiteralEMVTag(EMVStandardTagType.APPLICATION_LABEL_0x50, "Q2"));
tagValueSequence.add(new LiteralEMVTag(EMVStandardTagType.TRANSACTION_CURRENCY_CODE_0x5F2A, "840"));
ISOMsg field48 = new ISOMsg(48);
tagValueSequence.writeTo(field48);
msg.set(field48);
msg.recalcBitMap();
GenericPackager packager = new GenericPackager(new FileInputStream("build/resources/test/org/jpos/tlv/emv-tlv-packager.xml"));
msg.setPackager(packager);
byte[] packed = packager.pack(msg);
// 30313030
// 00 00 00 00 00 01 00 00
// 30 32 30
// 50 02 51 32
// 5a 07 19 96 09 30 00 00 00
// 9f 12 04 4a 50 4f 53
System.out.println("Packed: " + ISOUtil.byte2hex(packed));
// skip 4 byte MTI and 8 byte Primary BitMap
byte[] field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 29, field48Packed.length);
Assert.assertEquals("Pack error", "3032365a08999999123456789f9f12044a504f53500251325f2a020840", ISOUtil.byte2hex(field48Packed));
msg = new ISOMsg();
packager.unpack(msg, packed);
msg.recalcBitMap();
tagValueSequence = new EMVTagSequence();
tagValueSequence.readFrom((ISOMsg) msg.getComponent(48));
Assert.assertEquals("Unpack error", 4, tagValueSequence.getAll().size());
String tag1 = EMVStandardTagType.APPLICATION_PRIMARY_ACCOUNT_NUMBER_0x5A.getTagNumberHex();
LiteralEMVTag pan = (LiteralEMVTag) tagValueSequence.getFirst(tag1);
Assert.assertEquals("Unpack error", "999999123456789", pan.getValue());
String tag2 = EMVStandardTagType.APPLICATION_PREFERRED_NAME_0x9F12.getTagNumberHex();
LiteralEMVTag name = (LiteralEMVTag) tagValueSequence.getFirst(tag2);
Assert.assertEquals("Unpack error", "JPOS", name.getValue());
String tag3 = EMVStandardTagType.APPLICATION_LABEL_0x50.getTagNumberHex();
LiteralEMVTag label = (LiteralEMVTag) tagValueSequence.getFirst(tag3);
Assert.assertEquals("Unpack error", "Q2", label.getValue());
String tag4 = EMVStandardTagType.TRANSACTION_CURRENCY_CODE_0x5F2A.getTagNumberHex();
LiteralEMVTag currency = (LiteralEMVTag) tagValueSequence.getFirst(tag4);
Assert.assertEquals("Unpack error", "840", currency.getValue());
packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 29, field48Packed.length);
Assert.assertEquals("Pack error", "3032365a08999999123456789f9f12044a504f53500251325f2a020840", ISOUtil.byte2hex(field48Packed));
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class ISOTaggedSequenceTest method testPackingSpanningMultipleFields.
@Test
public void testPackingSpanningMultipleFields() throws ISOException, FileNotFoundException {
ISOMsg msg = new ISOMsg("0100");
GenericTagSequence tagValueSequence = new GenericTagSequence();
tagValueSequence.add(new LiteralTagValue("0012", "19960930000000"));
tagValueSequence.add(new LiteralTagValue("0165", "M"));
tagValueSequence.add(new LiteralTagValue("0023", "CT2"));
tagValueSequence.add(new LiteralTagValue("0170", "1-800-555-1212"));
ISOMsg field48 = new ISOMsg(48);
tagValueSequence.writeTo(field48);
ISOMsgRef isoMsgRef = new ISOMsgRef(field48);
msg.set(isoMsgRef.reference(48));
msg.set(isoMsgRef.reference(62));
msg.recalcBitMap();
GenericPackager packager = new GenericPackager(new FileInputStream("build/resources/test/org/jpos/tlv/tagged-sequence-packager.xml"));
msg.setPackager(packager);
byte[] packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
byte[] field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 66, field48Packed.length);
Assert.assertEquals("Pack error", "0390012014199609300000000165001M0023003CT202101700141-800-555-1212", new String(field48Packed));
msg = new ISOMsg();
packager.unpack(msg, packed);
tagValueSequence = new GenericTagSequence();
tagValueSequence.readFrom((ISOMsg) msg.getComponent(48));
tagValueSequence.readFrom((ISOMsg) msg.getComponent(62));
Assert.assertEquals("Unpack error", 4, tagValueSequence.getAll().size());
msg.recalcBitMap();
packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 66, field48Packed.length);
Assert.assertEquals("Pack error", "0390012014199609300000000165001M0023003CT202101700141-800-555-1212", new String(field48Packed));
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class ISOTaggedSequenceTest method testPacking.
@Test
public void testPacking() throws ISOException, FileNotFoundException {
ISOMsg msg = new ISOMsg("0100");
GenericTagSequence tagValueSequence = new GenericTagSequence();
tagValueSequence.add(new LiteralTagValue("0012", "19960930000000"));
tagValueSequence.add(new LiteralTagValue("0165", "M"));
tagValueSequence.add(new LiteralTagValue("0023", "CT2"));
ISOMsg field48 = new ISOMsg(48);
tagValueSequence.writeTo(field48);
msg.set(field48);
msg.recalcBitMap();
GenericPackager packager = new GenericPackager(new FileInputStream("build/resources/test/org/jpos/tlv/tagged-sequence-packager.xml"));
msg.setPackager(packager);
byte[] packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
byte[] field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 42, field48Packed.length);
Assert.assertEquals("Pack error", "0390012014199609300000000165001M0023003CT2", new String(field48Packed));
msg = new ISOMsg();
packager.unpack(msg, packed);
msg.recalcBitMap();
packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 42, field48Packed.length);
Assert.assertEquals("Pack error", "0390012014199609300000000165001M0023003CT2", new String(field48Packed));
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class ISOTaggedSequenceTest method testPackingWithISOField.
@Test
public void testPackingWithISOField() throws ISOException, FileNotFoundException {
ISOMsg msg = new ISOMsg("0100");
GenericTagSequence tagValueSequence = new GenericTagSequence();
ISOMsg field48 = new ISOMsg(48);
field48.set("12", "19960930000000");
field48.set("0165", "M");
field48.set("23", "CT2");
tagValueSequence.writeTo(field48);
msg.set(field48);
msg.recalcBitMap();
GenericPackager packager = new GenericPackager(new FileInputStream("build/resources/test/org/jpos/tlv/tagged-sequence-packager.xml"));
msg.setPackager(packager);
byte[] packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
byte[] field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 42, field48Packed.length);
Assert.assertEquals("Pack error", "0390012014199609300000000023003CT20165001M", new String(field48Packed));
msg = new ISOMsg();
packager.unpack(msg, packed);
msg.recalcBitMap();
packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 42, field48Packed.length);
Assert.assertEquals("Pack error", "0390012014199609300000000023003CT20165001M", new String(field48Packed));
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class CheckFieldsTest method testMidAndTidWithSpaces.
@Test
public void testMidAndTidWithSpaces() {
Context ctx = new Context();
ISOMsg m = new ISOMsg();
m.set(41, "0001 ");
m.set(42, "0000000001 ");
ctx.put(ContextConstants.REQUEST.toString(), m);
cfg.put("mandatory", "MID, TID");
int action = cf.prepare(1L, ctx);
assertEquals(PREPARED | NO_JOIN | READONLY, action);
Result rc = ctx.getResult();
assertFalse(rc.hasFailures());
}
Aggregations