Search in sources :

Example 16 with ReadResponse

use of org.eclipse.leshan.core.response.ReadResponse 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 17 with ReadResponse

use of org.eclipse.leshan.core.response.ReadResponse 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 18 with ReadResponse

use of org.eclipse.leshan.core.response.ReadResponse 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 19 with ReadResponse

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

Example 20 with ReadResponse

use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.

the class WriteTest method write_boolean_resource.

private void write_boolean_resource(ContentFormat format) throws InterruptedException {
    // write resource
    boolean expectedvalue = true;
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, BOOLEAN_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, BOOLEAN_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)

Aggregations

ReadResponse (org.eclipse.leshan.core.response.ReadResponse)37 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)34 Test (org.junit.Test)25 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)14 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)14 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)11 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)7 DiscoverResponse (org.eclipse.leshan.core.response.DiscoverResponse)5 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)5 RegisterRequest (org.eclipse.leshan.core.request.RegisterRequest)4 TimeoutException (org.eclipse.leshan.core.request.exception.TimeoutException)4 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)4 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)3 ObjectLink (org.eclipse.leshan.core.node.ObjectLink)3 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)3 JsonObject (com.eclipsesource.json.JsonObject)2 ArrayList (java.util.ArrayList)2 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)2 LwM2mSingleResource (org.eclipse.leshan.core.node.LwM2mSingleResource)2 Observation (org.eclipse.leshan.core.observation.Observation)2