Search in sources :

Example 31 with ReadRequest

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

the class ReadTest method can_read_object_instance.

@Test
public void can_read_object_instance() throws InterruptedException {
    // read device single instance
    ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0));
    // verify result
    assertEquals(CONTENT, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    LwM2mObjectInstance instance = (LwM2mObjectInstance) response.getContent();
    assertEquals(0, instance.getId());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 32 with ReadRequest

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

the class ReadTest method can_read_resource.

@Test
public void can_read_resource() throws InterruptedException {
    // read device model number
    ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 1));
    // verify result
    assertEquals(CONTENT, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    LwM2mResource resource = (LwM2mResource) response.getContent();
    assertEquals(1, resource.getId());
    assertEquals(IntegrationTestHelper.MODEL_NUMBER, resource.getValue());
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 33 with ReadRequest

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

the class ReadTest method cannot_read_security_resource.

@Test
public void cannot_read_security_resource() throws InterruptedException {
    // read device 50 resource
    ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(0, 0, 0));
    // 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 34 with ReadRequest

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

the class WriteTest method write_opaque_resource.

private void write_opaque_resource(ContentFormat format) throws InterruptedException {
    // write resource
    byte[] expectedvalue = new byte[] { 1, 2, 3 };
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, OPAQUE_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, OPAQUE_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertArrayEquals(expectedvalue, (byte[]) 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 35 with ReadRequest

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

the class WriteTest method can_write_single_instance_objlnk_resource_in_tlv.

@Test
public void can_write_single_instance_objlnk_resource_in_tlv() throws InterruptedException {
    ObjectLink data = new ObjectLink(10245, 1);
    // Write objlnk resource in TLV format
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TLV, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, data));
    // 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_SINGLE_INSTANCE_RESOURCE_ID));
    LwM2mSingleResource resource = (LwM2mSingleResource) readResponse.getContent();
    // verify read value
    assertEquals(((ObjectLink) resource.getValue()).getObjectId(), 10245);
    assertEquals(((ObjectLink) resource.getValue()).getObjectInstanceId(), 1);
}
Also used : LwM2mSingleResource(org.eclipse.leshan.core.node.LwM2mSingleResource) 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