Search in sources :

Example 16 with ReadRequest

use of org.eclipse.leshan.core.request.ReadRequest in project leshan by eclipse.

the class ReadTest method can_read_empty_object.

@Test
public void can_read_empty_object() throws InterruptedException {
    // read ACL object
    ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(2));
    // verify result
    assertEquals(CONTENT, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    LwM2mObject object = (LwM2mObject) response.getContent();
    assertEquals(2, object.getId());
    assertTrue(object.getInstances().isEmpty());
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) LwM2mObject(org.eclipse.leshan.core.node.LwM2mObject) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 17 with ReadRequest

use of org.eclipse.leshan.core.request.ReadRequest in project leshan by eclipse.

the class ReadTest method cannot_read_non_existent_instance.

@Test
public void cannot_read_non_existent_instance() throws InterruptedException {
    // read 2nd Device resource
    ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 1));
    // verify result
    assertEquals(NOT_FOUND, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 18 with ReadRequest

use of org.eclipse.leshan.core.request.ReadRequest in project leshan by eclipse.

the class ReadTest method cannot_read_non_readable_resource.

@Test
public void cannot_read_non_readable_resource() throws InterruptedException {
    // read device reboot resource
    ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 4));
    // verify result
    assertEquals(METHOD_NOT_ALLOWED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 19 with ReadRequest

use of org.eclipse.leshan.core.request.ReadRequest in project leshan by eclipse.

the class RegistrationTest method deregister_cancel_multiple_pending_request.

@Test
public void deregister_cancel_multiple_pending_request() throws InterruptedException {
    // Check client is not registered
    helper.assertClientNotRegisterered();
    // Start it and wait for registration
    helper.client.start();
    helper.waitForRegistration(1);
    // Check client is well registered
    helper.assertClientRegisterered();
    assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>".getBytes()), helper.getCurrentRegistration().getObjectLinks());
    // Stop client with out de-registration
    helper.client.stop(false);
    // Send multiple reads which should be retransmitted.
    List<Callback<ReadResponse>> callbacks = new ArrayList<>();
    for (int index = 0; index < 4; ++index) {
        Callback<ReadResponse> callback = new Callback<>();
        helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 1), callback, callback);
        callbacks.add(callback);
    }
    // Restart client (de-registration/re-registration)
    helper.client.start();
    // Check the request was cancelled.
    int index = 0;
    for (Callback<ReadResponse> callback : callbacks) {
        boolean timedout = !callback.waitForResponse(1000);
        assertFalse("Response or Error expected, no timeout, call " + index, timedout);
        assertTrue("Response or Error expected, call " + index, callback.isCalled().get());
        assertNull("No response expected, call " + index, callback.getResponse());
        assertNotNull("Exception expected, call " + index, callback.getException());
        ++index;
    }
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) ArrayList(java.util.ArrayList) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) Endpoint(org.eclipse.californium.core.network.Endpoint) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 20 with ReadRequest

use of org.eclipse.leshan.core.request.ReadRequest in project leshan by eclipse.

the class WriteTest method can_write_multi_instance_objlnk_resource_in_tlv.

@Test
public void can_write_multi_instance_objlnk_resource_in_tlv() throws InterruptedException {
    Map<Integer, ObjectLink> neighbourCellReport = new HashMap<>();
    neighbourCellReport.put(0, new ObjectLink(10245, 1));
    neighbourCellReport.put(1, new ObjectLink(10242, 2));
    neighbourCellReport.put(2, new ObjectLink(10244, 3));
    // Write objlnk resource in TLV format
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TLV, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_MULTI_INSTANCE_RESOURCE_ID, neighbourCellReport, Type.OBJLNK));
    // Verify Write result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    // Reading back the written OBJLNK value
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_MULTI_INSTANCE_RESOURCE_ID));
    LwM2mMultipleResource resource = (LwM2mMultipleResource) readResponse.getContent();
    // verify read value
    assertEquals(((ObjectLink) resource.getValue(0)).getObjectId(), 10245);
    assertEquals(((ObjectLink) resource.getValue(0)).getObjectInstanceId(), 1);
    assertEquals(((ObjectLink) resource.getValue(1)).getObjectId(), 10242);
    assertEquals(((ObjectLink) resource.getValue(1)).getObjectInstanceId(), 2);
    assertEquals(((ObjectLink) resource.getValue(2)).getObjectId(), 10244);
    assertEquals(((ObjectLink) resource.getValue(2)).getObjectInstanceId(), 3);
}
Also used : LwM2mMultipleResource(org.eclipse.leshan.core.node.LwM2mMultipleResource) HashMap(java.util.HashMap) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) WriteResponse(org.eclipse.leshan.core.response.WriteResponse) ObjectLink(org.eclipse.leshan.core.node.ObjectLink) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Aggregations

ReadRequest (org.eclipse.leshan.core.request.ReadRequest)43 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)34 Test (org.junit.Test)30 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)19 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)14 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)12 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)10 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)9 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)7 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)7 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)5 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)5 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)5 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)5 RegisterRequest (org.eclipse.leshan.core.request.RegisterRequest)4 TimeoutException (org.eclipse.leshan.core.request.exception.TimeoutException)4 JsonObject (com.eclipsesource.json.JsonObject)3 Request (org.eclipse.californium.core.coap.Request)3 ObjectLink (org.eclipse.leshan.core.node.ObjectLink)3 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)3