Search in sources :

Example 41 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method json_device_object_instance0.

@Test
public void json_device_object_instance0() throws CodecException {
    // json content for instance 0 of device object
    StringBuilder b = new StringBuilder();
    b.append("{\"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\":1367491215},");
    b.append("{\"n\":\"14\",\"sv\":\"+02:00\"},");
    b.append("{\"n\":\"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 42 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method assertObj66Instance.

private void assertObj66Instance(LwM2mObject oObject) {
    assertEquals(66, oObject.getId());
    assertEquals(2, oObject.getInstances().size());
    // instance 1
    LwM2mObjectInstance oInstance0 = oObject.getInstance(0);
    assertEquals("myService 1", oInstance0.getResource(0).getValue());
    assertEquals("Internet.15.234", oInstance0.getResource(1).getValue());
    assertEquals(new ObjectLink(67, 0), oInstance0.getResource(2).getValue());
    // instance 2
    LwM2mObjectInstance oInstance2 = oObject.getInstance(1);
    assertEquals("myService 2", oInstance2.getResource(0).getValue());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) ObjectLink(org.eclipse.leshan.core.node.ObjectLink)

Example 43 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method tlv_empty_instance.

@Test
public void tlv_empty_instance() {
    byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
    LwM2mObjectInstance instance = (LwM2mObjectInstance) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2, 0), model);
    assertNotNull(instance);
    assertEquals(0, instance.getId());
    assertTrue(instance.getResources().isEmpty());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 44 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method json_empty_instance.

@Test
public void json_empty_instance() {
    // Completely empty
    StringBuilder b = new StringBuilder();
    b.append("{}");
    LwM2mObjectInstance instance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0), model);
    assertNotNull(instance);
    assertEquals(0, instance.getId());
    assertTrue(instance.getResources().isEmpty());
    // with empty resource list
    b = new StringBuilder();
    b.append("{\"e\":[]}");
    instance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0), model);
    assertNotNull(instance);
    assertEquals(0, instance.getId());
    assertTrue(instance.getResources().isEmpty());
    // with empty resources list and base name
    b = new StringBuilder();
    b.append("{\"bn\":\"2/0\", \"e\":[]}");
    instance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0), model);
    assertNotNull(instance);
    assertEquals(0, instance.getId());
    assertTrue(instance.getResources().isEmpty());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 45 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method tlv_device_object_instance0_from_resources_tlv__instance_expected.

@Test
public void tlv_device_object_instance0_from_resources_tlv__instance_expected() throws CodecException {
    LwM2mObjectInstance oInstance = decoder.decode(ENCODED_DEVICE_WITHOUT_INSTANCE, ContentFormat.TLV, new LwM2mPath(3), model, LwM2mObjectInstance.class);
    assertDeviceInstance(oInstance);
}
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