Skip to content

Commit

Permalink
Fix some WriteSingleValueTest about on object link
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Dec 12, 2023
1 parent 004344d commit c520c83
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.node.LwM2mResourceInstance;
import org.eclipse.leshan.core.node.LwM2mSingleResource;
import org.eclipse.leshan.core.node.ObjectLink;
import org.eclipse.leshan.core.node.codec.CodecException;
import org.eclipse.leshan.core.request.ContentFormat;
Expand Down Expand Up @@ -303,6 +302,26 @@ public void write_unsigned_integer_resource(ContentFormat contentFormat, Protoco
assertThat(resource.getValue()).isEqualTo(expectedValue);
}

@TestAllCases
public void write_objlnk_resource(ContentFormat contentFormat, Protocol givenProtocol,
String givenClientEndpointProvider, String givenServerEndpointProvider) throws InterruptedException {
// write resource
ObjectLink expectedValue = new ObjectLink(10245, 1);
WriteResponse response = server.send(currentRegistration,
new WriteRequest(contentFormat, TestLwM2mId.TEST_OBJECT, 0, TestLwM2mId.OBJLINK_VALUE, expectedValue));

// verify result
assertThat(response) //
.hasCode(CHANGED) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);

// read resource to check the value changed
ReadResponse readResponse = server.send(currentRegistration,
new ReadRequest(TestLwM2mId.TEST_OBJECT, 0, TestLwM2mId.OBJLINK_VALUE));
LwM2mResource resource = (LwM2mResource) readResponse.getContent();
assertThat(resource.getValue()).isEqualTo(expectedValue);
}

@TestAllCases
public void can_write_single_instance_objlnk_resource(ContentFormat contentFormat, Protocol givenProtocol,
String givenClientEndpointProvider, String givenServerEndpointProvider) throws InterruptedException {
Expand All @@ -311,7 +330,7 @@ public void can_write_single_instance_objlnk_resource(ContentFormat contentForma

// Write objlnk resource
WriteResponse response = server.send(currentRegistration, new WriteRequest(contentFormat,
TestLwM2mId.TEST_OBJECT, 0, TestLwM2mId.MULTIPLE_OBJLINK_VALUE, expectedValue));
TestLwM2mId.TEST_OBJECT, 0, TestLwM2mId.MULTIPLE_OBJLINK_VALUE, 0, expectedValue, Type.OBJLNK));

// Verify Write result
assertThat(response) //
Expand All @@ -320,8 +339,8 @@ public void can_write_single_instance_objlnk_resource(ContentFormat contentForma

// Reading back the written OBJLNK value
ReadResponse readResponse = server.send(currentRegistration,
new ReadRequest(TestLwM2mId.TEST_OBJECT, 0, TestLwM2mId.MULTIPLE_OBJLINK_VALUE));
LwM2mSingleResource resource = (LwM2mSingleResource) readResponse.getContent();
new ReadRequest(TestLwM2mId.TEST_OBJECT, 0, TestLwM2mId.MULTIPLE_OBJLINK_VALUE, 0));
LwM2mResourceInstance resource = (LwM2mResourceInstance) readResponse.getContent();
assertThat(resource.getValue()).isEqualTo(expectedValue);
}

Expand Down

0 comments on commit c520c83

Please sign in to comment.