CardCommandTemplate { @Nonnull public CardCommandAPDU evaluate(@Nonnull Map<String, Object> context) throws APDUTemplateException { byte[] head = evalTemplate(template.getHeaderTemplate(), context); byte[] data = evalTemplate(template.getDataTemplate(), context); BigInteger length = template.getExpectedLength(); if (head.length != 4) { throw new APDUTemplateException("The computed command APDU header is not valid."); } CardCommandAPDU apdu = new CardCommandAPDU(); apdu.setCLA(head[0]); apdu.setINS(head[1]); apdu.setP1(head[2]); apdu.setP2(head[3]); if (data.length > 0) { apdu.setData(data); } if (length != null) { apdu.setLE(length.intValue()); } return apdu; } CardCommandTemplate(@Nonnull CardCallTemplateType apduTemplate); @Nonnull CardCommandAPDU evaluate(@Nonnull Map<String, Object> context);  }
@Test public void testNoExp() throws APDUTemplateException { CardCallTemplateType templateType = new CardCallTemplateType(); templateType.setHeaderTemplate("00a4020c"); CardCommandTemplate t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(EMPTY_CTX).toHexString(), "00A4020C"); templateType.setDataTemplate("00ff"); t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(EMPTY_CTX).toHexString(), "00A4020C0200FF"); templateType.setExpectedLength(BigInteger.valueOf(0xff)); t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(EMPTY_CTX).toHexString(), "00A4020C0200FFFF"); }
@Test public void testSymbolExp() throws APDUTemplateException { CardCallTemplateType templateType = new CardCallTemplateType(); templateType.setHeaderTemplate("00a4020c"); templateType.setDataTemplate("{val1}"); CardCommandTemplate t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(CTX).toHexString(), "00A4020C0200FF"); templateType.setDataTemplate("ab{val1}"); t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(CTX).toHexString(), "00A4020C03AB00FF"); templateType.setDataTemplate("{val1}ab"); t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(CTX).toHexString(), "00A4020C0300FFAB"); templateType.setDataTemplate("ba{val1}ab"); t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(CTX).toHexString(), "00A4020C04BA00FFAB"); templateType.setDataTemplate("ba{val1}ab{val2}cd"); t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(CTX).toHexString(), "00A4020C07BA00FFAB1234CD"); templateType.setDataTemplate("ba{val1}{val2}cd"); t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(CTX).toHexString(), "00A4020C06BA00FF1234CD"); }
@Test public void testSymbolFun() throws APDUTemplateException { CardCallTemplateType templateType = new CardCallTemplateType(); templateType.setHeaderTemplate("00a4020c"); templateType.setDataTemplate("{tlv 0x01 val1}"); CardCommandTemplate t = new CardCommandTemplate(templateType); assertEquals(t.evaluate(CTX).toHexString(), "00A4020C04010200FF"); }