Search in sources :

Example 16 with LwM2mObjectInstance

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

Example 17 with LwM2mObjectInstance

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

Example 18 with LwM2mObjectInstance

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);
}
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 19 with LwM2mObjectInstance

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));
}
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 20 with LwM2mObjectInstance

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

Aggregations

LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)49 Test (org.junit.Test)30 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)25 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)13 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)13 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)11 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)10 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)9 ArrayList (java.util.ArrayList)8 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)8 TimestampedLwM2mNode (org.eclipse.leshan.core.node.TimestampedLwM2mNode)6 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)6 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)5 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)5 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)4 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)4 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)4 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)4 JsonObject (com.eclipsesource.json.JsonObject)3 Collection (java.util.Collection)3