Search in sources :

Example 26 with LwM2mResource

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

the class WriteTest method write_string_resource.

private void write_string_resource(ContentFormat format) throws InterruptedException {
    // write resource
    String expectedvalue = "stringvalue";
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_ID, expectedvalue));
    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    // read resource to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(TEST_OBJECT_ID, 0, STRING_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertEquals(expectedvalue, resource.getValue());
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) WriteResponse(org.eclipse.leshan.core.response.WriteResponse) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) ReadRequest(org.eclipse.leshan.core.request.ReadRequest)

Example 27 with LwM2mResource

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

the class DeleteTest method cannot_delete_resource_of_created_object_instance.

@Test
public void cannot_delete_resource_of_created_object_instance() throws InterruptedException {
    // create ACL instance
    helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2, new LwM2mObjectInstance(0, Arrays.asList(new LwM2mResource[] { LwM2mSingleResource.newIntegerResource(0, 123) }))));
    // try to delete this instance
    DeleteResponse response = helper.server.send(helper.getCurrentRegistration(), new DeleteRequest("/2/0/0"));
    // verify result
    assertEquals(ResponseCode.METHOD_NOT_ALLOWED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Test(org.junit.Test)

Example 28 with LwM2mResource

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

the class DeleteTest method delete_created_object_instance.

@Test
public void delete_created_object_instance() throws InterruptedException {
    // create ACL instance
    helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2, new LwM2mObjectInstance(0, Arrays.asList(new LwM2mResource[] { LwM2mSingleResource.newIntegerResource(0, 123) }))));
    // try to delete this instance
    DeleteResponse response = helper.server.send(helper.getCurrentRegistration(), new DeleteRequest(2, 0));
    // verify result
    assertEquals(ResponseCode.DELETED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Test(org.junit.Test)

Example 29 with LwM2mResource

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

the class LwM2mNodeDecoderTest method tlv_empty_multi_resource.

@Test
public void tlv_empty_multi_resource() {
    byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
    LwM2mResource resource = (LwM2mResource) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 6), model);
    assertNotNull(resource);
    assertTrue(resource instanceof LwM2mMultipleResource);
    assertEquals(6, resource.getId());
    assertTrue(resource.getValues().isEmpty());
}
Also used : LwM2mMultipleResource(org.eclipse.leshan.core.node.LwM2mMultipleResource) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 30 with LwM2mResource

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

the class LwM2mNodeDecoderTest method tlv_power_source__multiple_resource.

@Test
public void tlv_power_source__multiple_resource() throws CodecException {
    // this content (a single TLV of type 'multiple_resource' containing the values)
    // is probably not compliant with the spec but it should be supported by the server
    byte[] content = new byte[] { -122, 6, 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)

Aggregations

LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)33 Test (org.junit.Test)15 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)14 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)13 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)13 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)11 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)10 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)10 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)9 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)5 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)5 JsonObject (com.eclipsesource.json.JsonObject)4 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)4 JsonArray (com.eclipsesource.json.JsonArray)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JsonValue (com.eclipsesource.json.JsonValue)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2