Exemple #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);
  }
Exemple #2
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));
     }
   }
 }