@Test
  public void testCborSerialize() throws Exception {
    CBORAccessRequestMac instance = new CBORAccessRequestMac(this.publisherId, this.ifMapTimestamp);

    CborBuilder cb = new CborBuilder();
    ArrayBuilder ab = cb.addArray();

    instance.cborSerialize(ab);

    ab.end();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CborEncoder ce = new CborEncoder(bos);
    ce.encode(cb.build());

    log.info("CBOR serialize:");
    log.info(DatatypeConverter.printHexBinary(bos.toByteArray()));

    byte[] expResult =
        DatatypeConverter.parseHexBinary(
            "847839687474703A2F2F7777772E74727573746564636F6D707574696E6767726F75702E6F72672F32303130"
                + "2F49464D41504D455441444154412F32726163636573732D726571756573742D6D6163887269666D61702D7075626C69736865722D69646F6D792D7075626C6973"
                + "6865722D69646F69666D61702D74696D657374616D70C11A4ED9E8B2781869666D61702D74696D657374616D702D6672616374696F6EC482281A075BCA00716966"
                + "6D61702D63617264696E616C6974796B73696E676C6556616C756580");

    assertTrue(Arrays.equals(expResult, bos.toByteArray()));
  }
Ejemplo n.º 2
0
 @Test
 public void shouldAddDouble() {
   CborBuilder builder = new CborBuilder();
   List<DataItem> dataItems = builder.addArray().add(1.0d).end().build();
   assertEquals(1, dataItems.size());
   assertTrue(dataItems.get(0) instanceof Array);
   Array array = (Array) dataItems.get(0);
   assertEquals(1, array.getDataItems().size());
   assertTrue(array.getDataItems().get(0) instanceof DoublePrecisionFloat);
 }
Ejemplo n.º 3
0
 @Test
 public void shouldAddByteArray() {
   CborBuilder builder = new CborBuilder();
   List<DataItem> dataItems = builder.addArray().add(new byte[] {0x0}).end().build();
   assertEquals(1, dataItems.size());
   assertTrue(dataItems.get(0) instanceof Array);
   Array array = (Array) dataItems.get(0);
   assertEquals(1, array.getDataItems().size());
   assertTrue(array.getDataItems().get(0) instanceof ByteString);
 }
Ejemplo n.º 4
0
 @Test
 public void shouldAddBoolean() {
   CborBuilder builder = new CborBuilder();
   List<DataItem> dataItems = builder.addArray().add(true).add(false).end().build();
   assertEquals(1, dataItems.size());
   assertTrue(dataItems.get(0) instanceof Array);
   Array array = (Array) dataItems.get(0);
   assertEquals(2, array.getDataItems().size());
   assertTrue(array.getDataItems().get(0) instanceof SimpleValue);
   assertTrue(array.getDataItems().get(1) instanceof SimpleValue);
 }