Search in sources :

Example 21 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__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 22 with LwM2mObjectInstance

use of org.eclipse.leshan.core.node.LwM2mObjectInstance 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 23 with LwM2mObjectInstance

use of org.eclipse.leshan.core.node.LwM2mObjectInstance 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)

Example 24 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method json_device_object_instance0_with_root_basename.

@Test
public void json_device_object_instance0_with_root_basename() throws CodecException {
    // json content for instance 0 of device object
    StringBuilder b = new StringBuilder();
    b.append("{\"bn\":\"/\",");
    b.append("\"e\":[");
    b.append("{\"n\":\"3/0/0\",\"sv\":\"Open Mobile Alliance\"},");
    b.append("{\"n\":\"3/0/1\",\"sv\":\"Lightweight M2M Client\"},");
    b.append("{\"n\":\"3/0/2\",\"sv\":\"345000123\"},");
    b.append("{\"n\":\"3/0/3\",\"sv\":\"1.0\"},");
    b.append("{\"n\":\"3/0/6/0\",\"v\":1},");
    b.append("{\"n\":\"3/0/6/1\",\"v\":5},");
    b.append("{\"n\":\"3/0/7/0\",\"v\":3800},");
    b.append("{\"n\":\"3/0/7/1\",\"v\":5000},");
    b.append("{\"n\":\"3/0/8/0\",\"v\":125},");
    b.append("{\"n\":\"3/0/8/1\",\"v\":900},");
    b.append("{\"n\":\"3/0/9\",\"v\":100},");
    b.append("{\"n\":\"3/0/10\",\"v\":15},");
    b.append("{\"n\":\"3/0/11/0\",\"v\":0},");
    b.append("{\"n\":\"3/0/13\",\"v\":1367491215},");
    b.append("{\"n\":\"3/0/14\",\"sv\":\"+02:00\"},");
    b.append("{\"n\":\"3/0/16\",\"sv\":\"U\"}]}");
    LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, 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 25 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method assertAclInstances.

private void assertAclInstances(LwM2mObject oObject) {
    assertEquals(2, oObject.getId());
    assertEquals(2, oObject.getInstances().size());
    // instance 1
    LwM2mObjectInstance oInstance0 = oObject.getInstance(0);
    assertEquals(1L, oInstance0.getResource(0).getValue());
    assertEquals(0L, oInstance0.getResource(1).getValue());
    assertEquals(1, oInstance0.getResource(2).getValues().size());
    assertEquals(7L, oInstance0.getResource(2).getValue(127));
    assertEquals(127L, oInstance0.getResource(3).getValue());
    // instance 2
    LwM2mObjectInstance oInstance2 = oObject.getInstance(2);
    assertEquals(3L, oInstance2.getResource(0).getValue());
    assertEquals(0L, oInstance2.getResource(1).getValue());
    assertEquals(2, oInstance2.getResource(2).getValues().size());
    assertEquals(7L, oInstance2.getResource(2).getValue(127));
    assertEquals(1L, oInstance2.getResource(2).getValue(310));
    assertEquals(127L, oInstance2.getResource(3).getValue());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance)

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