Пример #1
0
  @Test
  public void shouldMarshalNumberWithColour() throws Exception {
    NumberWithColour nwc = new NumberWithColour();
    nwc.setI1(99);
    nwc.setC(Colour.GREEN);
    Marshaller marshaller = dadlContext.createMarshaller();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    marshaller.marshal(nwc, os);
    assertThat(os.toByteArray().length, is(2));

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readByte(), is((byte) 99));
    assertThat(reader.readByte(), is((byte) 17));
    reader.close();
  }
Пример #2
0
  @Test
  public void shouldUnmarshalNumberWithColour() throws Exception {
    ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter();
    writer.writeByte(22);
    writer.writeByte(14);
    writer.close();
    byte[] bytes = writer.toByteArray();
    assertThat(bytes.length, is(2));

    Unmarshaller parser = dadlContext.createUnmarshaller();
    NumberWithColour nwc = parser.unmarshal(bytes, NumberWithColour.class);
    assertThat(nwc, is(notNullValue()));
    assertThat(nwc.getI1(), is(22));
    assertThat(nwc.getC(), is(Colour.YELLOW));
  }
Пример #3
0
  @Test
  public void shouldMarshalTaggedString() throws Exception {
    NumberWithColour nwc = new NumberWithColour();
    nwc.setI1(22);
    nwc.setC(Colour.GREEN);
    String text = "Hello DADL!";
    TaggedString taggedString = new TaggedString();
    taggedString.setNwc(nwc);
    taggedString.setText(text);

    Marshaller marshaller = dadlContext.createMarshaller();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    marshaller.marshal(taggedString, os);

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readByte(), is((byte) 0x0A));
    assertThat(reader.readByte(), is((byte) (2 + text.length())));
    assertThat(reader.readByte(), is((byte) 22));
    assertThat(reader.readByte(), is((byte) 17));
    byte[] bytes = new byte[11];
    reader.read(bytes);
    assertThat(new String(bytes, StandardCharsets.UTF_8), is(text));
    reader.close();
  }