예제 #1
0
 @BeforeClass
 public static void initClass() {
   FieldInfo fieldInfo1 =
       FieldInfo.newInstance(FieldInfo.class).addPlainEntry("05 field1 picture X(10)").build();
   fieldInfo1.setEncoding(ENCODING);
   FieldInfo fieldInfo2 =
       FieldInfo.newInstance(FieldInfo.class).addPlainEntry("05 field2 picture X").build();
   fieldInfo2.setEncoding(ENCODING);
   fieldInfo2.setDefaultValue("O");
   ROOT.addChildren(
       Field.newInstance(PictureField.class).addFieldInfo(fieldInfo1),
       Field.newInstance(PictureField.class).addFieldInfo(fieldInfo2));
 }
예제 #2
0
/** @author natiz */
public final class PlainPictureFieldTest {

  private static final ContainerField ROOT =
      Field.newInstance(CompositeField.class)
          .addFieldInfo(FieldInfo.newInstance(FieldInfo.class).addPlainEntry("01 ROOT").build());
  private static final String ENCODING = "ISO-8859-1";
  private static final Marshaller<Boolean> BOOLEAN_MARSHALLER =
      Marshaller.newInstance(BooleanMarshaller.class);

  @BeforeClass
  public static void initClass() {
    FieldInfo fieldInfo1 =
        FieldInfo.newInstance(FieldInfo.class).addPlainEntry("05 field1 picture X(10)").build();
    fieldInfo1.setEncoding(ENCODING);
    FieldInfo fieldInfo2 =
        FieldInfo.newInstance(FieldInfo.class).addPlainEntry("05 field2 picture X").build();
    fieldInfo2.setEncoding(ENCODING);
    fieldInfo2.setDefaultValue("O");
    ROOT.addChildren(
        Field.newInstance(PictureField.class).addFieldInfo(fieldInfo1),
        Field.newInstance(PictureField.class).addFieldInfo(fieldInfo2));
  }

  @Before
  public void initTest() {
    assertEquals(ROOT, ROOT.find("field1").getParent());
    assertEquals(ROOT, ROOT.find("field2").getParent());
    assertSame(ROOT.find("field1").getParent(), ROOT.find("field2").getParent());
    assertEquals(Integer.valueOf(10), ((PictureField) ROOT.find("field1")).getCardinal());
    assertEquals(Integer.valueOf(1), ((PictureField) ROOT.find("field2")).getCardinal());

    assertNull(((PictureField) ROOT.find("field1")).getScale());
    assertNull(((PictureField) ROOT.find("field2")).getScale());

    assertFalse(((PictureField) ROOT.find("field1")).isSigned());
  }

  @Test
  public void siblings() {
    assertEquals(Integer.valueOf(2), Integer.valueOf(ROOT.find("field1").getSiblings().size()));
    assertEquals(Integer.valueOf(2), Integer.valueOf(ROOT.find("field2").getSiblings().size()));

    assertEquals(ROOT.find("field1").getSiblings().get(0), ROOT.find("field1"));
    assertEquals(ROOT.find("field1").getSiblings().get(1), ROOT.find("field2"));

    assertEquals(ROOT.find("field2").getSiblings().get(0), ROOT.find("field1"));
    assertEquals(ROOT.find("field2").getSiblings().get(1), ROOT.find("field2"));
  }

  @Test
  public void cloneField() {
    assertEquals(ROOT.find("field1"), ROOT.find("field1").duplicate());
    assertEquals(ROOT.find("field2"), ROOT.find("field2").duplicate());
  }

  @Test
  public void buffer() throws Exception {
    // Exactly 10 letters as the field storage length (10)
    ROOT.find("field1").setStorage("0123456789".getBytes(ENCODING));
    assertEquals("0123456789", new String(ROOT.find("field1").getStorage(), ENCODING));

    // Exactly one letter as the field storage length (1). O equals
    // TRUE
    ROOT.find("field2").setStorage("O".getBytes(ENCODING));
    assertEquals(Boolean.TRUE, BOOLEAN_MARSHALLER.getValue((PictureField) ROOT.find("field2")));

    // Exactly one letter as the field storage length (1). N equals
    // FALSE
    ROOT.find("field2").setStorage("N".getBytes(ENCODING));
    assertEquals(Boolean.FALSE, BOOLEAN_MARSHALLER.getValue((PictureField) ROOT.find("field2")));

    // Exactly one letter as the field storage length (1). Other Value
    // equals FALSE too.
    ROOT.find("field2").setStorage("Y".getBytes(ENCODING));
    assertEquals(Boolean.FALSE, BOOLEAN_MARSHALLER.getValue((PictureField) ROOT.find("field2")));
  }

  @Test(expected = IllegalArgumentException.class, timeout = 1000)
  public void wrongBuffer() throws Exception {
    // Less letters than the 11 letters of the field storage length
    ROOT.find("field1").setStorage("An example".getBytes(ENCODING));

    // More letters than the 11 letters of the field storage length
    ROOT.find("field1").setStorage("The simple example".getBytes(ENCODING));

    // Less letters than the 1 letter of the field storage length
    ROOT.find("field2").setStorage("".getBytes(ENCODING));

    // More letters than the one letter of the field storage length
    ROOT.find("field2").setStorage("The simple example".getBytes(ENCODING));
  }
}