Skip to content

Commit

Permalink
[to be squashed] More refactoring after testing with java-coap.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 19, 2023
1 parent c702f0e commit 97827bb
Show file tree
Hide file tree
Showing 29 changed files with 841 additions and 919 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.eclipse.leshan.integration.tests.util.LeshanTestClientBuilder.givenClientUsing;
import static org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder.givenServerUsing;
import static org.eclipse.leshan.integration.tests.util.assertion.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.lang.annotation.Retention;
Expand Down Expand Up @@ -115,16 +116,19 @@ public void delete_created_object_instance(Protocol givenProtocol, String givenC
DeleteResponse response = server.send(currentRegistration, new DeleteRequest(2, 0));

// verify result
assertThat(response).hasCode(DELETED);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(DELETED) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

// TODO should maybe moved as it only tests client
@TestAllTransportLayer
public void cannot_delete_resource(Protocol givenProtocol, String givenClientEndpointProvider,
String givenServerEndpointProvider) throws InterruptedException {

// TODO should maybe moved as it only tests client
assumeTrue(givenServerEndpointProvider.equals("Californium"));

// create ACL instance
server.send(currentRegistration,
new CreateRequest(2, new LwM2mObjectInstance(0, LwM2mSingleResource.newIntegerResource(0, 123))));
Expand Down Expand Up @@ -154,10 +158,9 @@ public void cannot_delete_unknown_object_instance(Protocol givenProtocol, String
DeleteResponse response = server.send(currentRegistration, new DeleteRequest(2, 0));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -167,10 +170,9 @@ public void cannot_delete_device_object_instance(Protocol givenProtocol, String
DeleteResponse response = server.send(currentRegistration, new DeleteRequest(3, 0));

// verify result
assertThat(response).hasCode(METHOD_NOT_ALLOWED);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(METHOD_NOT_ALLOWED) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -179,9 +181,8 @@ public void cannot_delete_security_object_instance(Protocol givenProtocol, Strin
DeleteResponse response = server.send(currentRegistration, new DeleteRequest(0, 0));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.eclipse.leshan.integration.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.leshan.core.ResponseCode.CONTENT;
import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND;
import static org.eclipse.leshan.integration.tests.util.LeshanTestClientBuilder.givenClientUsing;
Expand All @@ -29,7 +28,6 @@
import java.lang.annotation.RetentionPolicy;
import java.util.stream.Stream;

import org.eclipse.californium.core.coap.Response;
import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.request.DiscoverRequest;
import org.eclipse.leshan.core.response.DiscoverResponse;
Expand Down Expand Up @@ -100,13 +98,12 @@ public void can_discover_object(Protocol givenProtocol, String givenClientEndpoi
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(3));

// verify result
assertThat(response).hasCode(CONTENT);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(CONTENT) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider) // */
.hasObjectLinksLike(
"</3>;ver=1.1,</3/0>,</3/0/0>,</3/0/1>,</3/0/2>,</3/0/11>,</3/0/14>,</3/0/15>,</3/0/16>");

assertThat(response.getObjectLinks()).isLikeLwM2mLinks(
"</3>;ver=1.1,</3/0>,</3/0/0>,</3/0/1>,</3/0/2>,</3/0/11>,</3/0/14>,</3/0/15>,</3/0/16>");
}

@TestAllTransportLayer
Expand All @@ -116,10 +113,9 @@ public void cant_discover_non_existent_object(Protocol givenProtocol, String giv
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(4));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -129,13 +125,10 @@ public void can_discover_object_instance(Protocol givenProtocol, String givenCli
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(3, 0));

// verify result
assertThat(response).hasCode(CONTENT);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);

assertThat(response.getObjectLinks())
.isLikeLwM2mLinks("</3/0>,</3/0/0>,</3/0/1>,</3/0/2>,</3/0/11>,</3/0/14>,</3/0/15>,</3/0/16>");
assertThat(response) //
.hasCode(CONTENT) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider) //
.hasObjectLinksLike("</3/0>,</3/0/0>,</3/0/1>,</3/0/2>,</3/0/11>,</3/0/14>,</3/0/15>,</3/0/16>");
}

@TestAllTransportLayer
Expand All @@ -145,10 +138,9 @@ public void cant_discover_non_existent_instance(Protocol givenProtocol, String g
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(3, 1));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -158,10 +150,10 @@ public void can_discover_resource(Protocol givenProtocol, String givenClientEndp
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(3, 0, 0));

// verify result
assertThat(response).hasCode(CONTENT);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(CONTENT) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider) //
.hasObjectLinksLike("</3/0/0>");

assertThat(response.getObjectLinks()).isLikeLwM2mLinks("</3/0/0>");
}
Expand All @@ -173,10 +165,9 @@ public void cant_discover_resource_of_non_existent_object(Protocol givenProtocol
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(4, 0, 0));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -186,10 +177,9 @@ public void cant_discover_resource_of_non_existent_instance(Protocol givenProtoc
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(3, 1, 0));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -199,10 +189,9 @@ public void cant_discover_resource_of_non_existent_instance_and_resource(Protoco
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(3, 1, 20));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -212,9 +201,8 @@ public void cant_discover_resource_of_non_existent_resource(Protocol givenProtoc
DiscoverResponse response = server.send(currentRegistration, new DiscoverRequest(3, 0, 42));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.eclipse.leshan.integration.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.leshan.core.ResponseCode.CHANGED;
import static org.eclipse.leshan.core.ResponseCode.METHOD_NOT_ALLOWED;
import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND;
Expand All @@ -32,7 +31,6 @@
import java.lang.annotation.RetentionPolicy;
import java.util.stream.Stream;

import org.eclipse.californium.core.coap.Response;
import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.request.ExecuteRequest;
import org.eclipse.leshan.core.response.ExecuteResponse;
Expand Down Expand Up @@ -103,10 +101,9 @@ public void cannot_execute_read_only_resource(Protocol givenProtocol, String giv
ExecuteResponse response = server.send(currentRegistration, new ExecuteRequest(3, 0, 0));

// verify result
assertThat(response).hasCode(METHOD_NOT_ALLOWED);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(METHOD_NOT_ALLOWED) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -116,10 +113,9 @@ public void cannot_execute_read_write_resource(Protocol givenProtocol, String gi
ExecuteResponse response = server.send(currentRegistration, new ExecuteRequest(3, 0, 13));

// verify result
assertThat(response).hasCode(METHOD_NOT_ALLOWED);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(METHOD_NOT_ALLOWED) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -130,10 +126,9 @@ public void cannot_execute_nonexisting_resource_on_existing_object(Protocol give
ExecuteResponse response = server.send(currentRegistration, new ExecuteRequest(3, 0, nonExistingResourceId));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -143,10 +138,9 @@ public void cannot_execute_nonexisting_resource_on_non_existing_object(Protocol
ExecuteResponse response = server.send(currentRegistration, new ExecuteRequest(nonExistingObjectId, 0, 0));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -155,10 +149,9 @@ public void cannot_execute_security_object(Protocol givenProtocol, String givenC
ExecuteResponse response = server.send(currentRegistration, new ExecuteRequest(0, 0, 0));

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(NOT_FOUND) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -168,10 +161,9 @@ public void can_execute_resource(Protocol givenProtocol, String givenClientEndpo
ExecuteResponse response = server.send(currentRegistration, new ExecuteRequest(3, 0, 4));

// verify result
assertThat(response).hasCode(CHANGED);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response) //
.hasCode(CHANGED) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}

@TestAllTransportLayer
Expand All @@ -181,10 +173,8 @@ public void can_execute_resource_with_parameters(Protocol givenProtocol, String
ExecuteResponse response = server.send(currentRegistration, new ExecuteRequest(3, 0, 4, "6"));

// verify result
assertThat(response).hasCode(CHANGED);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);

assertThat(response) //
.hasCode(CHANGED) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}
}

This file was deleted.

Loading

0 comments on commit 97827bb

Please sign in to comment.