Skip to content

Commit

Permalink
Add a new Write Integration tests.
Browse files Browse the repository at this point in the history
Following discussion at : eclipse-wakaama/wakaama#674
  • Loading branch information
sbernard31 committed Nov 10, 2022
1 parent 76dc370 commit 07b7473
Showing 1 changed file with 64 additions and 0 deletions.
Expand Up @@ -207,6 +207,70 @@ public void can_write_multi_instance_objlnk_resource() throws InterruptedExcepti
assertEquals(((ObjectLink) resource.getValue(2)).getObjectInstanceId(), 3);
}

@Test
public void can_write_object_instance_with_empty_multi_resource() throws InterruptedException {

// =============== Try to write ==================
// /3442/0/1110 : { 0 = "string1", 1 = "string2" }
// /3442/0/1120 : { 1= 11, 1 = 22 }

// create initial value
Map<Integer, String> strings = new HashMap<>();
strings.put(0, "string1");
strings.put(1, "string2");
LwM2mMultipleResource stringMultiResource = LwM2mMultipleResource
.newStringResource(TestLwM2mId.MULTIPLE_STRING_VALUE, strings);

Map<Integer, Long> ints = new HashMap<>();
ints.put(0, 11l);
ints.put(1, 22l);
LwM2mMultipleResource intMultiResource = LwM2mMultipleResource
.newIntegerResource(TestLwM2mId.MULTIPLE_INTEGER_VALUE, ints);

// Write new instance
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(Mode.REPLACE,
contentFormat, TestLwM2mId.TEST_OBJECT, 0, stringMultiResource, intMultiResource));

// Verify Write result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

// Reading back the instance
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(),
new ReadRequest(TestLwM2mId.TEST_OBJECT, 0));
LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent();

// verify read value
assertEquals(stringMultiResource, instance.getResource(TestLwM2mId.MULTIPLE_STRING_VALUE));
assertEquals(intMultiResource, instance.getResource(TestLwM2mId.MULTIPLE_INTEGER_VALUE));

// =============== Now try to replace with ==================
// /3441/0/1110 : { 3 = "newString"}

// create initial value
strings = new HashMap<>();
strings.put(3, "newString");
stringMultiResource = LwM2mMultipleResource.newStringResource(TestLwM2mId.MULTIPLE_STRING_VALUE, strings);

// Write new instance
response = helper.server.send(helper.getCurrentRegistration(),
new WriteRequest(Mode.REPLACE, contentFormat, TestLwM2mId.TEST_OBJECT, 0, stringMultiResource));

// Verify Write result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

// Reading back the instance
readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(TestLwM2mId.TEST_OBJECT, 0));
instance = (LwM2mObjectInstance) readResponse.getContent();

// verify read value
assertEquals(stringMultiResource, instance.getResource(TestLwM2mId.MULTIPLE_STRING_VALUE));
assertNull(instance.getResource(TestLwM2mId.MULTIPLE_INTEGER_VALUE));
}

@Test
public void can_write_object_resource_instance() throws InterruptedException {

Expand Down

0 comments on commit 07b7473

Please sign in to comment.