Search in sources :

Example 21 with LwM2mPath

use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.

the class LwM2mNodeEncoderTest method text_encode_single_resource.

@Test
public void text_encode_single_resource() {
    byte[] encoded = encoder.encode(LwM2mSingleResource.newFloatResource(15, 56.4D), ContentFormat.TEXT, new LwM2mPath("/323/0/15"), model);
    Assert.assertEquals("56.4", new String(encoded, StandardCharsets.UTF_8));
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 22 with LwM2mPath

use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.

the class LwM2mNodeEncoderTest method tlv_encode_device_object_instance_as_resources_array__undefined_instance_id.

@Test
public void tlv_encode_device_object_instance_as_resources_array__undefined_instance_id() {
    LwM2mObjectInstance oInstance = new LwM2mObjectInstance(LwM2mObjectInstance.UNDEFINED, getDeviceResources());
    byte[] encoded = encoder.encode(oInstance, ContentFormat.TLV, new LwM2mPath("/3"), model);
    Assert.assertArrayEquals(ENCODED_DEVICE_WITHOUT_INSTANCE, encoded);
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 23 with LwM2mPath

use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.

the class LwM2mNodeDecoderTest method tlv_device_object_instance0_from_instance_tlv.

@Test
public void tlv_device_object_instance0_from_instance_tlv() throws CodecException {
    LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(ENCODED_DEVICE_WITH_INSTANCE, ContentFormat.TLV, new LwM2mPath(3, 0), model);
    assertDeviceInstance(oInstance);
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 24 with LwM2mPath

use of org.eclipse.leshan.core.node.LwM2mPath 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());
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) LwM2mObject(org.eclipse.leshan.core.node.LwM2mObject) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 25 with LwM2mPath

use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.

the class LwM2mNodeDecoderTest method json_timestamped_instances.

@Test
public void json_timestamped_instances() throws CodecException {
    // json content for instance 0 of device object
    StringBuilder b = new StringBuilder();
    b.append("{\"e\":[");
    b.append("{\"n\":\"1\",\"v\":22.9,\"t\":-30},");
    b.append("{\"n\":\"1\",\"v\":22.4,\"t\":-5},");
    b.append("{\"n\":\"0\",\"sv\":\"a string\",\"t\":-5},");
    b.append("{\"n\":\"1\",\"v\":24.1,\"t\":-50}],");
    b.append("\"bt\":25462634}");
    List<TimestampedLwM2mNode> timestampedResources = decoder.decodeTimestampedData(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(1024, 0), model);
    assertEquals(3, timestampedResources.size());
    assertEquals(Long.valueOf(25462634L - 5), timestampedResources.get(0).getTimestamp());
    assertEquals("a string", ((LwM2mObjectInstance) timestampedResources.get(0).getNode()).getResource(0).getValue());
    assertEquals(22.4d, ((LwM2mObjectInstance) timestampedResources.get(0).getNode()).getResource(1).getValue());
    assertEquals(Long.valueOf(25462634L - 30), timestampedResources.get(1).getTimestamp());
    assertEquals(22.9d, ((LwM2mObjectInstance) timestampedResources.get(1).getNode()).getResource(1).getValue());
    assertEquals(Long.valueOf(25462634 - 50), timestampedResources.get(2).getTimestamp());
    assertEquals(24.1d, ((LwM2mObjectInstance) timestampedResources.get(2).getNode()).getResource(1).getValue());
}
Also used : TimestampedLwM2mNode(org.eclipse.leshan.core.node.TimestampedLwM2mNode) LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Aggregations

LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)70 Test (org.junit.Test)51 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)25 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)13 Observation (org.eclipse.leshan.core.observation.Observation)11 ArrayList (java.util.ArrayList)10 TimestampedLwM2mNode (org.eclipse.leshan.core.node.TimestampedLwM2mNode)10 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)9 Tlv (org.eclipse.leshan.tlv.Tlv)8 LwM2mModel (org.eclipse.leshan.core.model.LwM2mModel)7 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)6 CodecException (org.eclipse.leshan.core.node.codec.CodecException)6 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)6 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)6 BootstrapWriteRequest (org.eclipse.leshan.core.request.BootstrapWriteRequest)5 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)5 HashMap (java.util.HashMap)4 Response (org.eclipse.californium.core.coap.Response)4 ResourceModel (org.eclipse.leshan.core.model.ResourceModel)4 DefaultLwM2mValueConverter (org.eclipse.leshan.core.node.codec.DefaultLwM2mValueConverter)4