Пример #1
0
  /** Parses a message from a file and checks the fields. */
  @Test
  public void testParsing() throws IOException, ParseException {
    InputStream ins = getClass().getResourceAsStream("/parse1.txt");
    final byte[] buf = new byte[400];
    int pos = 0;
    while (ins.available() > 0) {
      buf[pos++] = (byte) ins.read();
    }
    ins.close();
    IsoMessage iso = mf.parseMessage(buf, mf.getIsoHeader(0x210).length());
    Assert.assertEquals(0x210, iso.getType());
    byte[] b2 = iso.writeData();

    // Remove leftover newline and stuff from the original buffer
    byte[] b3 = new byte[b2.length];
    System.arraycopy(buf, 0, b3, 0, b3.length);
    Assert.assertArrayEquals(b3, b2);

    // Test it contains the correct fields
    final List<Integer> fields =
        Arrays.asList(
            3, 4, 7, 11, 12, 13, 15, 17, 32, 35, 37, 38, 39, 41, 43, 49, 60, 61, 100, 102, 126);
    testFields(iso, fields);
    // Again, but now with forced encoding
    mf.setForceStringEncoding(true);
    iso = mf.parseMessage(buf, mf.getIsoHeader(0x210).length());
    Assert.assertEquals(0x210, iso.getType());
    testFields(iso, fields);
  }
Пример #2
0
 /** Creates a new message and checks that it has all the fields included in the config. */
 @Test
 public void testCreation() {
   IsoMessage iso = mf.newMessage(0x200);
   Assert.assertEquals(0x200, iso.getType());
   Assert.assertTrue(iso.hasEveryField(3, 32, 35, 43, 48, 49, 60, 61, 100, 102));
   Assert.assertEquals(IsoType.NUMERIC, iso.getField(3).getType());
   Assert.assertEquals("650000", iso.getObjectValue(3));
   Assert.assertEquals(IsoType.LLVAR, iso.getField(32).getType());
   Assert.assertEquals(IsoType.LLVAR, iso.getField(35).getType());
   Assert.assertEquals(IsoType.ALPHA, iso.getField(43).getType());
   Assert.assertEquals(40, ((String) iso.getObjectValue(43)).length());
   Assert.assertEquals(IsoType.LLLVAR, iso.getField(48).getType());
   Assert.assertTrue(iso.getObjectValue(48) instanceof CustomField48);
   Assert.assertEquals(IsoType.ALPHA, iso.getField(49).getType());
   Assert.assertEquals(IsoType.LLLVAR, iso.getField(60).getType());
   Assert.assertEquals(IsoType.LLLVAR, iso.getField(61).getType());
   Assert.assertEquals(IsoType.LLVAR, iso.getField(100).getType());
   Assert.assertEquals(IsoType.LLVAR, iso.getField(102).getType());
   for (int i = 4; i < 32; i++) {
     Assert.assertFalse("ISO should not contain " + i, iso.hasField(i));
   }
   for (int i = 36; i < 43; i++) {
     Assert.assertFalse("ISO should not contain " + i, iso.hasField(i));
   }
   for (int i = 50; i < 60; i++) {
     Assert.assertFalse("ISO should not contain " + i, iso.hasField(i));
   }
   for (int i = 62; i < 100; i++) {
     Assert.assertFalse("ISO should not contain " + i, iso.hasField(i));
   }
   for (int i = 103; i < 128; i++) {
     Assert.assertFalse("ISO should not contain " + i, iso.hasField(i));
   }
 }
Пример #3
0
 @Test
 public void testEncoding() throws Exception {
   IsoMessage m1 = mf.newMessage(0x200);
   byte[] buf = m1.writeData();
   IsoMessage m2 = mf.parseMessage(buf, mf.getIsoHeader(0x200).length());
   Assert.assertEquals(m2.getType(), m1.getType());
   for (int i = 2; i < 128; i++) {
     // Either both have the field or neither have it
     if (m1.hasField(i) && m2.hasField(i)) {
       Assert.assertEquals(m1.getField(i).getType(), m2.getField(i).getType());
       Assert.assertEquals(m1.getObjectValue(i), m2.getObjectValue(i));
     } else {
       Assert.assertFalse(m1.hasField(i));
       Assert.assertFalse(m2.hasField(i));
     }
   }
 }