Search in sources :

Example 16 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_instance.

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

Example 17 with LwM2mPath

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

the class LwM2mNodeEncoderTest method tlv_encode_device_object.

@Test
public void tlv_encode_device_object() {
    LwM2mObject object = new LwM2mObject(3, new LwM2mObjectInstance(0, getDeviceResources()));
    byte[] encoded = encoder.encode(object, ContentFormat.TLV, new LwM2mPath("/3"), model);
    // encoded as an array of resource TLVs
    Assert.assertArrayEquals(ENCODED_DEVICE_WITH_INSTANCE, encoded);
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) LwM2mObject(org.eclipse.leshan.core.node.LwM2mObject) Test(org.junit.Test)

Example 18 with LwM2mPath

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

the class LwM2mNodeEncoderTest method json_encode_timestamped_Object.

@Test
public void json_encode_timestamped_Object() throws CodecException {
    List<TimestampedLwM2mNode> data = new ArrayList<>();
    LwM2mObject objectAt210 = new LwM2mObject(1204, new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 22.9)));
    LwM2mObject objectAt220 = new LwM2mObject(1204, new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 22.4), LwM2mSingleResource.newStringResource(0, "a string")), new LwM2mObjectInstance(1, LwM2mSingleResource.newFloatResource(1, 23)));
    LwM2mObject objetAt230 = new LwM2mObject(1204, new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 24.1)));
    data.add(new TimestampedLwM2mNode(210L, objectAt210));
    data.add(new TimestampedLwM2mNode(220L, objectAt220));
    data.add(new TimestampedLwM2mNode(230L, objetAt230));
    byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024), model);
    StringBuilder b = new StringBuilder();
    b.append("{\"bn\":\"/1024\",\"e\":[");
    b.append("{\"n\":\"0/1\",\"v\":22.9,\"t\":210},");
    b.append("{\"n\":\"0/0\",\"sv\":\"a string\",\"t\":220},");
    b.append("{\"n\":\"0/1\",\"v\":22.4,\"t\":220},");
    b.append("{\"n\":\"1/1\",\"v\":23,\"t\":220},");
    b.append("{\"n\":\"0/1\",\"v\":24.1,\"t\":230}]}");
    String expected = b.toString();
    Assert.assertEquals(expected, new String(encoded));
}
Also used : TimestampedLwM2mNode(org.eclipse.leshan.core.node.TimestampedLwM2mNode) LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) ArrayList(java.util.ArrayList) LwM2mObject(org.eclipse.leshan.core.node.LwM2mObject) Test(org.junit.Test)

Example 19 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.

@Test
public void tlv_encode_device_object_instance_as_resources_array() {
    LwM2mObjectInstance oInstance = new LwM2mObjectInstance(0, getDeviceResources());
    byte[] encoded = encoder.encode(oInstance, ContentFormat.TLV, new LwM2mPath("/3/0"), 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 20 with LwM2mPath

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

the class LwM2mNodeEncoderTest method json_encode_timestamped_resources.

@Test
public void json_encode_timestamped_resources() throws CodecException {
    List<TimestampedLwM2mNode> data = new ArrayList<>();
    data.add(new TimestampedLwM2mNode(500L, LwM2mSingleResource.newFloatResource(1, 22.9)));
    data.add(new TimestampedLwM2mNode(510L, LwM2mSingleResource.newFloatResource(1, 22.4)));
    data.add(new TimestampedLwM2mNode(520L, LwM2mSingleResource.newFloatResource(1, 24.1)));
    byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024, 0, 1), model);
    StringBuilder b = new StringBuilder();
    b.append("{\"bn\":\"/1024/0/1\",\"e\":[");
    b.append("{\"n\":\"\",\"v\":22.9,\"t\":500},");
    b.append("{\"n\":\"\",\"v\":22.4,\"t\":510},");
    b.append("{\"n\":\"\",\"v\":24.1,\"t\":520}]}");
    String expected = b.toString();
    Assert.assertEquals(expected, new String(encoded));
}
Also used : TimestampedLwM2mNode(org.eclipse.leshan.core.node.TimestampedLwM2mNode) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) ArrayList(java.util.ArrayList) 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