Search in sources :

Example 26 with LwM2mPath

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

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

the class LwM2mNodeDecoderTest method tlv_empty_object.

@Test
public void tlv_empty_object() {
    byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
    LwM2mObject obj = (LwM2mObject) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2), model);
    assertNotNull(obj);
    assertEquals(2, obj.getId());
    assertTrue(obj.getInstances().isEmpty());
}
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 28 with LwM2mPath

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

the class LwM2mNodeDecoderTest method tlv_multi_instance_object__missing_instance_tlv.

@Test(expected = CodecException.class)
public void tlv_multi_instance_object__missing_instance_tlv() throws CodecException {
    byte[] content = TlvEncoder.encode(new Tlv[] { new Tlv(TlvType.RESOURCE_VALUE, null, TlvEncoder.encodeInteger(11), 1), new Tlv(TlvType.RESOURCE_VALUE, null, TlvEncoder.encodeInteger(10), 2) }).array();
    decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2), model);
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 29 with LwM2mPath

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

the class LwM2mNodeDecoderTest method tlv_power_source__array_values.

@Test
public void tlv_power_source__array_values() throws CodecException {
    byte[] content = new byte[] { 65, 0, 1, 65, 1, 5 };
    LwM2mResource resource = (LwM2mResource) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 6), model);
    assertEquals(6, resource.getId());
    assertEquals(2, resource.getValues().size());
    assertEquals(1L, resource.getValue(0));
    assertEquals(5L, resource.getValue(1));
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Test(org.junit.Test)

Example 30 with LwM2mPath

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

the class LwM2mNodeDecoderTest method tlv_invalid_multi_resource_2_instance_with_the_same_id.

@Test(expected = CodecException.class)
public void tlv_invalid_multi_resource_2_instance_with_the_same_id() {
    Tlv resInstance1 = new Tlv(TlvType.RESOURCE_INSTANCE, null, TlvEncoder.encodeObjlnk(new ObjectLink(100, 1)), 0);
    Tlv resInstance2 = new Tlv(TlvType.RESOURCE_INSTANCE, null, TlvEncoder.encodeObjlnk(new ObjectLink(101, 2)), 0);
    Tlv multiResource = new Tlv(TlvType.MULTIPLE_RESOURCE, new Tlv[] { resInstance1, resInstance2 }, null, 22);
    byte[] content = TlvEncoder.encode(new Tlv[] { multiResource }).array();
    decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 22), model);
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) ObjectLink(org.eclipse.leshan.core.node.ObjectLink) Tlv(org.eclipse.leshan.tlv.Tlv) 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