Skip to content

Commit

Permalink
Add empty opaque test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Dec 31, 2019
1 parent bb159bf commit 346bf6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.leshan.client.resource.DummyInstanceEnabler;
import org.eclipse.leshan.client.resource.LwM2mObjectEnabler;
import org.eclipse.leshan.client.resource.ObjectsInitializer;
import org.eclipse.leshan.client.resource.SimpleInstanceEnabler;
import org.eclipse.leshan.core.model.ObjectLoader;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.model.ResourceModel;
Expand Down Expand Up @@ -106,7 +107,7 @@ protected List<ObjectModel> createObjectModels() {
false, Type.OBJLNK, null, null, null);
ResourceModel objlnkSinglefield = new ResourceModel(OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, "objlnk", Operations.RW,
false, false, Type.OBJLNK, null, null, null);
objectModels.add(new ObjectModel(TEST_OBJECT_ID, "testobject", null, ObjectModel.DEFAULT_VERSION, false, false,
objectModels.add(new ObjectModel(TEST_OBJECT_ID, "testobject", null, ObjectModel.DEFAULT_VERSION, true, false,
stringfield, booleanfield, integerfield, floatfield, timefield, opaquefield, objlnkfield,
objlnkSinglefield));

Expand Down Expand Up @@ -154,7 +155,8 @@ public void createClient(Map<String, String> additionalAttributes) {
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
initializer.setInstancesForObject(LwM2mId.DEVICE, new TestDevice("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
initializer.setClassForObject(LwM2mId.ACCESS_CONTROL, DummyInstanceEnabler.class);
initializer.setDummyInstancesForObject(2000);
initializer.setInstancesForObject(TEST_OBJECT_ID, new DummyInstanceEnabler(0),
new SimpleInstanceEnabler(1, OPAQUE_RESOURCE_ID, new byte[0]));
List<LwM2mObjectEnabler> objects = initializer.createAll();

// Build Client
Expand Down
Expand Up @@ -19,14 +19,17 @@
package org.eclipse.leshan.integration.tests;

import static org.eclipse.leshan.ResponseCode.*;
import static org.eclipse.leshan.integration.tests.IntegrationTestHelper.*;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.*;

import org.eclipse.californium.core.coap.Response;
import org.eclipse.leshan.core.model.ResourceModel.Type;
import org.eclipse.leshan.core.node.LwM2mObject;
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.request.ReadRequest;
import org.eclipse.leshan.core.response.ReadResponse;
import org.junit.After;
Expand Down Expand Up @@ -115,6 +118,22 @@ public void can_read_resource() throws InterruptedException {
assertEquals(IntegrationTestHelper.MODEL_NUMBER, resource.getValue());
}

@Test
public void can_read_empty_opaque_resource() throws InterruptedException {
// read device model number
ReadResponse response = helper.server.send(helper.getCurrentRegistration(),
new ReadRequest(ContentFormat.OPAQUE, TEST_OBJECT_ID, 1, OPAQUE_RESOURCE_ID));

// verify result
assertEquals(CONTENT, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

LwM2mResource resource = (LwM2mResource) response.getContent();
assertEquals(Type.OPAQUE, resource.getType());
assertEquals(0, ((byte[]) resource.getValue()).length);
}

@Test
public void cannot_read_non_readable_resource() throws InterruptedException {
// read device reboot resource
Expand Down
Expand Up @@ -85,7 +85,7 @@ public void register_update_deregister() {

// Check client is well registered
helper.assertClientRegisterered();
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>".getBytes()),
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>,</2000/1>".getBytes()),
helper.getCurrentRegistration().getObjectLinks());

// Check for update
Expand All @@ -109,7 +109,7 @@ public void deregister_cancel_multiple_pending_request() throws InterruptedExcep

// Check client is well registered
helper.assertClientRegisterered();
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>".getBytes()),
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>,</2000/1>".getBytes()),
helper.getCurrentRegistration().getObjectLinks());

// Stop client with out de-registration
Expand Down Expand Up @@ -271,7 +271,7 @@ public void register_with_additional_attributes() throws InterruptedException {
helper.assertClientRegisterered();
assertNotNull(helper.getLastRegistration());
assertEquals(additionalAttributes, helper.getLastRegistration().getAdditionalRegistrationAttributes());
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>".getBytes()),
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>,</2000/1>".getBytes()),
helper.getCurrentRegistration().getObjectLinks());
}

Expand Down

0 comments on commit 346bf6c

Please sign in to comment.