use of org.eclipse.leshan.tlv.Tlv in project leshan by eclipse.
the class CoapRequestBuilderTest method build_create_request__with_instance_id.
@Test
public void build_create_request__with_instance_id() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
CreateRequest request = new CreateRequest(12, new LwM2mObjectInstance(26, LwM2mSingleResource.newStringResource(0, "value")));
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.POST, coapRequest.getCode());
assertEquals("127.0.0.1", coapRequest.getDestinationContext().getPeerAddress().getAddress().getHostAddress());
assertEquals(12354, coapRequest.getDestinationContext().getPeerAddress().getPort());
assertEquals("coap://127.0.0.1:12354/12", coapRequest.getURI());
assertEquals(ContentFormat.TLV.getCode(), coapRequest.getOptions().getContentFormat());
assertNotNull(coapRequest.getPayload());
// assert it is encoded as array of instance TLV
Tlv[] tlvs = TlvDecoder.decode(ByteBuffer.wrap(coapRequest.getPayload()));
assertEquals(TlvType.OBJECT_INSTANCE, tlvs[0].getType());
assertEquals(26, tlvs[0].getIdentifier());
}
use of org.eclipse.leshan.tlv.Tlv in project leshan by eclipse.
the class CoapRequestBuilderTest method build_create_request__without_instance_id.
@Test
public void build_create_request__without_instance_id() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
CreateRequest request = new CreateRequest(12, LwM2mSingleResource.newStringResource(0, "value"));
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.POST, coapRequest.getCode());
assertEquals("127.0.0.1", coapRequest.getDestinationContext().getPeerAddress().getAddress().getHostAddress());
assertEquals(12354, coapRequest.getDestinationContext().getPeerAddress().getPort());
assertEquals("coap://127.0.0.1:12354/12", coapRequest.getURI());
assertEquals(ContentFormat.TLV.getCode(), coapRequest.getOptions().getContentFormat());
assertNotNull(coapRequest.getPayload());
// assert it is encoded as array of resources TLV
Tlv[] tlvs = TlvDecoder.decode(ByteBuffer.wrap(coapRequest.getPayload()));
assertEquals(TlvType.RESOURCE_VALUE, tlvs[0].getType());
}
use of org.eclipse.leshan.tlv.Tlv in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_unknown_object__missing_instance_tlv.
@Test
public void tlv_unknown_object__missing_instance_tlv() throws CodecException {
byte[] content = TlvEncoder.encode(new Tlv[] { new Tlv(TlvType.RESOURCE_VALUE, null, "value1".getBytes(), 1), new Tlv(TlvType.RESOURCE_VALUE, null, "value1".getBytes(), 2) }).array();
LwM2mObject obj = (LwM2mObject) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(10234), model);
assertEquals(1, obj.getInstances().size());
assertEquals(2, obj.getInstance(0).getResources().size());
}
use of org.eclipse.leshan.tlv.Tlv in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_empty_object.
@Test
public void tlv_empty_object() {
byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
LwM2mObject obj = (LwM2mObject) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2), model);
assertNotNull(obj);
assertEquals(2, obj.getId());
assertTrue(obj.getInstances().isEmpty());
}
use of org.eclipse.leshan.tlv.Tlv in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_multi_instance_object__missing_instance_tlv.
@Test(expected = CodecException.class)
public void tlv_multi_instance_object__missing_instance_tlv() throws CodecException {
byte[] content = TlvEncoder.encode(new Tlv[] { new Tlv(TlvType.RESOURCE_VALUE, null, TlvEncoder.encodeInteger(11), 1), new Tlv(TlvType.RESOURCE_VALUE, null, TlvEncoder.encodeInteger(10), 2) }).array();
decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2), model);
}
Aggregations