Search in sources :

Example 31 with LwM2mPath

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

the class LwM2mNodeDecoderTest method tlv_manufacturer_resource.

@Test
public void tlv_manufacturer_resource() throws CodecException {
    String value = "MyManufacturer";
    byte[] content = TlvEncoder.encode(new Tlv[] { new Tlv(TlvType.RESOURCE_VALUE, null, value.getBytes(), 0) }).array();
    LwM2mSingleResource resource = (LwM2mSingleResource) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 0), model);
    assertEquals(0, resource.getId());
    assertFalse(resource.isMultiInstances());
    assertEquals(value, resource.getValue());
}
Also used : LwM2mSingleResource(org.eclipse.leshan.core.node.LwM2mSingleResource) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 32 with LwM2mPath

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

the class LwM2mNodeDecoderTest method text_manufacturer_resource.

@Test
public void text_manufacturer_resource() throws CodecException {
    String value = "MyManufacturer";
    LwM2mSingleResource resource = (LwM2mSingleResource) decoder.decode(value.getBytes(StandardCharsets.UTF_8), ContentFormat.TEXT, new LwM2mPath(3, 0, 0), model);
    assertEquals(0, resource.getId());
    assertFalse(resource.isMultiInstances());
    assertEquals(Type.STRING, resource.getType());
    assertEquals(value, resource.getValue());
}
Also used : LwM2mSingleResource(org.eclipse.leshan.core.node.LwM2mSingleResource) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 33 with LwM2mPath

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

the class LwM2mNodeDecoderTest method json_custom_object_instance.

@Test
public void json_custom_object_instance() throws CodecException {
    // json content for instance 0 of device object
    StringBuilder b = new StringBuilder();
    b.append("{\"e\":[");
    b.append("{\"n\":\"0\",\"sv\":\"a string\"},");
    b.append("{\"n\":\"1\",\"v\":10.5},");
    b.append("{\"n\":\"2\",\"bv\":true}]}");
    LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(1024, 0), model);
    assertEquals(0, oInstance.getId());
    assertEquals("a string", oInstance.getResource(0).getValue());
    assertEquals(10.5, oInstance.getResource(1).getValue());
    assertEquals(true, oInstance.getResource(2).getValue());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 34 with LwM2mPath

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

the class LwM2mNodeDecoderTest method json_empty_single_resource.

@Test(expected = CodecException.class)
public void json_empty_single_resource() {
    StringBuilder b = new StringBuilder();
    b.append("{}");
    decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0, 0), model);
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 35 with LwM2mPath

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

the class LwM2mNodeDecoderTest method json_empty_object.

@Test
public void json_empty_object() {
    // Completely empty
    StringBuilder b = new StringBuilder();
    b.append("{}");
    LwM2mObject obj = (LwM2mObject) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2), model);
    assertNotNull(obj);
    assertEquals(2, obj.getId());
    assertTrue(obj.getInstances().isEmpty());
    // with empty resource list
    b = new StringBuilder();
    b.append("{\"e\":[]}");
    obj = (LwM2mObject) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2), model);
    assertNotNull(obj);
    assertEquals(2, obj.getId());
    assertTrue(obj.getInstances().isEmpty());
    // with empty resources list and base name
    b = new StringBuilder();
    b.append("{\"bn\":\"2\", \"e\":[]}");
    obj = (LwM2mObject) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, 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) 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