Search in sources :

Example 51 with LwM2mPath

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

the class LwM2mNodeEncoderTest method text_encode_multiple_instances.

@Test(expected = CodecException.class)
public void text_encode_multiple_instances() {
    Map<Integer, Long> values = new HashMap<>();
    values.put(0, 1L);
    values.put(1, 5L);
    encoder.encode(LwM2mMultipleResource.newIntegerResource(6, values), ContentFormat.TEXT, new LwM2mPath("/3/0/6"), model);
}
Also used : HashMap(java.util.HashMap) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 52 with LwM2mPath

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

the class LwM2mNodeEncoderTest method text_encode_date_as_iso_string.

@Test
public void text_encode_date_as_iso_string() {
    byte[] encoded = encoder.encode(LwM2mSingleResource.newIntegerResource(13, 1367491215000L), ContentFormat.TEXT, new LwM2mPath("/3/0/13"), model);
    Assert.assertEquals("1367491215", new String(encoded, StandardCharsets.UTF_8));
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Example 53 with LwM2mPath

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

the class LwM2mNodeDecoderTest method tlv_empty_single_resource.

@Test(expected = CodecException.class)
public void tlv_empty_single_resource() {
    byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
    decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2, 0, 0), model);
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 54 with LwM2mPath

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

the class LwM2mNodeDecoderTest method tlv_device_object_instance0_from_resources_tlv.

@Test
public void tlv_device_object_instance0_from_resources_tlv() throws CodecException {
    LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(ENCODED_DEVICE_WITHOUT_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 55 with LwM2mPath

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

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