use of org.eclipse.leshan.core.node.LwM2mObjectInstance in project leshan by eclipse.
the class LwM2mNodeEncoderTest method json_encode_device_object_instance.
@Test
public void json_encode_device_object_instance() {
LwM2mObjectInstance oInstance = new LwM2mObjectInstance(0, getDeviceResources());
byte[] encoded = encoder.encode(oInstance, ContentFormat.JSON, new LwM2mPath("/3/0"), model);
StringBuilder b = new StringBuilder();
b.append("{\"bn\":\"/3/0\",\"e\":[");
b.append("{\"n\":\"0\",\"sv\":\"Open Mobile Alliance\"},");
b.append("{\"n\":\"1\",\"sv\":\"Lightweight M2M Client\"},");
b.append("{\"n\":\"2\",\"sv\":\"345000123\"},");
b.append("{\"n\":\"3\",\"sv\":\"1.0\"},");
b.append("{\"n\":\"6/0\",\"v\":1},");
b.append("{\"n\":\"6/1\",\"v\":5},");
b.append("{\"n\":\"7/0\",\"v\":3800},");
b.append("{\"n\":\"7/1\",\"v\":5000},");
b.append("{\"n\":\"8/0\",\"v\":125},");
b.append("{\"n\":\"8/1\",\"v\":900},");
b.append("{\"n\":\"9\",\"v\":100},");
b.append("{\"n\":\"10\",\"v\":15},");
b.append("{\"n\":\"11/0\",\"v\":0},");
b.append("{\"n\":\"13\",\"v\":1.367491215E9},");
b.append("{\"n\":\"14\",\"sv\":\"+02:00\"},");
b.append("{\"n\":\"16\",\"sv\":\"U\"}]}");
String expected = b.toString();
Assert.assertEquals(expected, new String(encoded));
}
use of org.eclipse.leshan.core.node.LwM2mObjectInstance 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);
}
use of org.eclipse.leshan.core.node.LwM2mObjectInstance 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);
}
use of org.eclipse.leshan.core.node.LwM2mObjectInstance 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));
}
use of org.eclipse.leshan.core.node.LwM2mObjectInstance 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);
}
Aggregations