Skip to content

Commit

Permalink
Test java-coap in some of our integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 14, 2023
1 parent f3b1216 commit 87d3013
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 73 deletions.
4 changes: 4 additions & 0 deletions leshan-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Contributors:
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-cf</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-tl-javacoap-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-redis</artifactId>
Expand Down
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 @@ -69,7 +70,8 @@ public class DeleteTest {
static Stream<org.junit.jupiter.params.provider.Arguments> transports() {
return Stream.of(//
// ProtocolUsed - Client Endpoint Provider - Server Endpoint Provider
arguments(Protocol.COAP, "Californium", "Californium"));
arguments(Protocol.COAP, "Californium", "Californium"), //
arguments(Protocol.COAP, "Californium", "java-coap"));
}

/*---------------------------------/
Expand Down Expand Up @@ -116,15 +118,17 @@ public void delete_created_object_instance(Protocol givenProtocol, String givenC

// verify result
assertThat(response).hasCode(DELETED);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response).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 @@ -155,9 +159,7 @@ public void cannot_delete_unknown_object_instance(Protocol givenProtocol, String

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

@TestAllTransportLayer
Expand All @@ -168,9 +170,7 @@ public void cannot_delete_device_object_instance(Protocol givenProtocol, String

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

@TestAllTransportLayer
Expand All @@ -180,8 +180,6 @@ public void cannot_delete_security_object_instance(Protocol givenProtocol, Strin

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response).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 @@ -58,7 +56,8 @@ public class DiscoverTest {
static Stream<org.junit.jupiter.params.provider.Arguments> transports() {
return Stream.of(//
// ProtocolUsed - Client Endpoint Provider - Server Endpoint Provider
arguments(Protocol.COAP, "Californium", "Californium"));
arguments(Protocol.COAP, "Californium", "Californium"), //
arguments(Protocol.COAP, "Californium", "java-coap"));
}

/*---------------------------------/
Expand Down Expand Up @@ -101,9 +100,7 @@ public void can_discover_object(Protocol givenProtocol, String givenClientEndpoi

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

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>");
Expand All @@ -117,9 +114,7 @@ public void cant_discover_non_existent_object(Protocol givenProtocol, String giv

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

@TestAllTransportLayer
Expand All @@ -130,9 +125,7 @@ public void can_discover_object_instance(Protocol givenProtocol, String givenCli

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

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>");
Expand All @@ -146,9 +139,7 @@ public void cant_discover_non_existent_instance(Protocol givenProtocol, String g

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

@TestAllTransportLayer
Expand All @@ -159,9 +150,7 @@ public void can_discover_resource(Protocol givenProtocol, String givenClientEndp

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

assertThat(response.getObjectLinks()).isLikeLwM2mLinks("</3/0/0>");
}
Expand All @@ -174,9 +163,7 @@ public void cant_discover_resource_of_non_existent_object(Protocol givenProtocol

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

@TestAllTransportLayer
Expand All @@ -187,9 +174,7 @@ public void cant_discover_resource_of_non_existent_instance(Protocol givenProtoc

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

@TestAllTransportLayer
Expand All @@ -200,9 +185,7 @@ public void cant_discover_resource_of_non_existent_instance_and_resource(Protoco

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

@TestAllTransportLayer
Expand All @@ -213,8 +196,6 @@ public void cant_discover_resource_of_non_existent_resource(Protocol givenProtoc

// verify result
assertThat(response).hasCode(NOT_FOUND);
assertThat(response.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(response).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 @@ -61,7 +59,8 @@ public class ExecuteTest {
static Stream<org.junit.jupiter.params.provider.Arguments> transports() {
return Stream.of(//
// ProtocolUsed - Client Endpoint Provider - Server Endpoint Provider
arguments(Protocol.COAP, "Californium", "Californium"));
arguments(Protocol.COAP, "Californium", "Californium"), //
arguments(Protocol.COAP, "Californium", "java-coap"));
}

/*---------------------------------/
Expand Down Expand Up @@ -104,9 +103,7 @@ public void cannot_execute_read_only_resource(Protocol givenProtocol, String giv

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

@TestAllTransportLayer
Expand All @@ -117,9 +114,7 @@ public void cannot_execute_read_write_resource(Protocol givenProtocol, String gi

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

@TestAllTransportLayer
Expand All @@ -131,9 +126,7 @@ public void cannot_execute_nonexisting_resource_on_existing_object(Protocol give

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

@TestAllTransportLayer
Expand All @@ -144,9 +137,7 @@ public void cannot_execute_nonexisting_resource_on_non_existing_object(Protocol

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

@TestAllTransportLayer
Expand All @@ -156,9 +147,7 @@ public void cannot_execute_security_object(Protocol givenProtocol, String givenC

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

@TestAllTransportLayer
Expand All @@ -169,9 +158,7 @@ public void can_execute_resource(Protocol givenProtocol, String givenClientEndpo

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

@TestAllTransportLayer
Expand All @@ -182,9 +169,6 @@ public void can_execute_resource_with_parameters(Protocol givenProtocol, String

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

assertThat(response).hasValidUnderlyingResponseFor(givenServerEndpointProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class QueueModeTest {
static Stream<org.junit.jupiter.params.provider.Arguments> transports() {
return Stream.of(//
// ProtocolUsed - Client Endpoint Provider - Server Endpoint Provider
arguments(Protocol.COAP, "Californium", "Californium"));
arguments(Protocol.COAP, "Californium", "Californium"), //
arguments(Protocol.COAP, "Californium", "java-coap"));
}

/*---------------------------------/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.eclipse.leshan.integration.tests.util.assertion.Assertions.assertArg;
import static org.eclipse.leshan.integration.tests.util.assertion.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -97,7 +98,8 @@ public class RegistrationTest {
static Stream<org.junit.jupiter.params.provider.Arguments> transports() {
return Stream.of(//
// ProtocolUsed - Client Endpoint Provider - Server Endpoint Provider
arguments(Protocol.COAP, "Californium", "Californium"));
arguments(Protocol.COAP, "Californium", "Californium"), //
arguments(Protocol.COAP, "Californium", "java-coap"));
}

/*---------------------------------/
Expand Down Expand Up @@ -280,6 +282,11 @@ public void register_update_reregister(Protocol protocol, String clientEndpointP
@TestAllTransportLayer
public void register_observe_deregister_observe(Protocol protocol, String clientEndpointProvider,
String serverEndpointProvider) throws NonUniqueSecurityInfoException, InterruptedException {
// TODO java-coap does not raise expected SendFailedException at the end of this tests
// But not sure what should be the right behavior.
// Waiting for https://github.com/open-coap/java-coap/issues/36 before to move forward on this.
assumeTrue(serverEndpointProvider.equals("Californium"));

// Check client is not registered
client = givenClient.build();
assertThat(client).isNotRegisteredAt(server);
Expand All @@ -296,9 +303,7 @@ public void register_observe_deregister_observe(Protocol protocol, String client
// observe device timezone
ObserveResponse observeResponse = server.send(registration, new ObserveRequest(3, 0));
assertThat(observeResponse).hasCode(CONTENT);
assertThat(observeResponse.getCoapResponse())//
.isNotNull()//
.isInstanceOf(Response.class);
assertThat(observeResponse).hasValidUnderlyingResponseFor(serverEndpointProvider);

// check observation registry is not null
Set<Observation> observations = server.getObservationService().getObservations(registration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.eclipse.leshan.server.security.EditableSecurityStore;
import org.eclipse.leshan.server.security.SecurityStore;
import org.eclipse.leshan.server.security.ServerSecurityInfo;
import org.eclipse.leshan.transport.javacoap.endpoint.JavaCoapServerEndpointsProvider;

public class LeshanTestServerBuilder extends LeshanServerBuilder {

Expand Down Expand Up @@ -97,6 +98,10 @@ protected LeshanTestServer createServer(LwM2mServerEndpointsProvider endpointsPr
builder.addEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), protocolToUse);
endpointsProvider = builder.build();
break;
case "java-coap":
endpointsProvider = new JavaCoapServerEndpointsProvider(
new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
break;
default:
throw new IllegalStateException(
String.format("Unknown endpoint provider : [%s]", endpointProviderName));
Expand Down
Loading

0 comments on commit 87d3013

Please sign in to comment.