Ejemplo n.º 1
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));
   }
 }
Ejemplo n.º 2
0
 @Test
 public void testTemplating() {
   IsoMessage iso1 = mf.newMessage(0x200);
   IsoMessage iso2 = mf.newMessage(0x200);
   Assert.assertNotSame(iso1, iso2);
   Assert.assertEquals(iso1.getObjectValue(3), iso2.getObjectValue(3));
   Assert.assertNotSame(iso1.getField(3), iso2.getField(3));
   Assert.assertNotSame(iso1.getField(48), iso2.getField(48));
   CustomField48 cf48_1 = iso1.getObjectValue(48);
   int origv = cf48_1.getValue2();
   cf48_1.setValue2(origv + 1000);
   CustomField48 cf48_2 = iso2.getObjectValue(48);
   Assert.assertSame(cf48_1, cf48_2);
   Assert.assertEquals(cf48_2.getValue2(), origv + 1000);
 }
Ejemplo n.º 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));
     }
   }
 }
Ejemplo n.º 4
0
 @Test(expected = IllegalArgumentException.class)
 public void testSimpleFieldSetter() {
   IsoMessage iso = mf.newMessage(0x200);
   IsoValue<String> f3 = iso.getField(3);
   iso.updateValue(3, "999999");
   Assert.assertEquals("999999", iso.getObjectValue(3));
   IsoValue<String> nf3 = iso.getField(3);
   Assert.assertNotSame(f3, nf3);
   Assert.assertEquals(f3.getType(), nf3.getType());
   Assert.assertEquals(f3.getLength(), nf3.getLength());
   Assert.assertSame(f3.getEncoder(), nf3.getEncoder());
   iso.updateValue(4, "INVALID!");
   throw new RuntimeException("Update failed!");
 }