Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment new design for integration tests. #1399

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions leshan-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Contributors:
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-cf</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-tl-javacoap-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-redis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2023 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.integration.tests;

import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder;
import org.eclipse.leshan.server.redis.RedisRegistrationStore;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.util.Pool;

public class RedisRegistrationTest2 extends RegistrationTest2 {

@Override
protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) {
LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol);

// Create redis store
Pool<Jedis> jedis = createJedisPool();
builder.setRegistrationStore(new RedisRegistrationStore(jedis));

return builder;
}

private Pool<Jedis> createJedisPool() {
String redisURI = System.getenv("REDIS_URI");
if (redisURI != null && !redisURI.isEmpty()) {
return new JedisPool(redisURI);
} else {
return new JedisPool();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2023 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.integration.tests;

import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder;
import org.eclipse.leshan.server.redis.RedisRegistrationStore;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.util.Pool;

public abstract class RedisRegistrationTest3 extends RegistrationTest3 {

public RedisRegistrationTest3(Protocol protocol, String serverProvider, String clientProvider) {
super(protocol, serverProvider, clientProvider);
}

public static class CoAPCaliforniumCalifornium extends RedisRegistrationTest3 {
public CoAPCaliforniumCalifornium() {
super(Protocol.COAP, "Californium", "Californium");
}
}

public static class CoAPCaliforniumJavaCoap extends RedisRegistrationTest3 {
public CoAPCaliforniumJavaCoap() {
super(Protocol.COAP, "Californium", "java-coap");
}
}

@Override
protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) {
LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol);

// Create redis store
Pool<Jedis> jedis = createJedisPool();
builder.setRegistrationStore(new RedisRegistrationStore(jedis));

return builder;
}

private Pool<Jedis> createJedisPool() {
String redisURI = System.getenv("REDIS_URI");
if (redisURI != null && !redisURI.isEmpty()) {
return new JedisPool(redisURI);
} else {
return new JedisPool();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2023 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.integration.tests;

import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder;
import org.eclipse.leshan.server.redis.RedisRegistrationStore;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.util.Pool;

public abstract class RedisRegistrationTest4 extends RegistrationTest3 {

public RedisRegistrationTest4(Protocol protocol, String serverProvider, String clientProvider) {
super(protocol, serverProvider, clientProvider);
}

public static class CoAPCaliforniumCalifornium extends RedisRegistrationTest4 {
public CoAPCaliforniumCalifornium() {
super(Protocol.COAP, "Californium", "Californium");
}
}

public static class CoAPCaliforniumJavaCoap extends RedisRegistrationTest4 {
public CoAPCaliforniumJavaCoap() {
super(Protocol.COAP, "Californium", "java-coap");
}
}

@Override
protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) {
LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol);

// Create redis store
Pool<Jedis> jedis = createJedisPool();
builder.setRegistrationStore(new RedisRegistrationStore(jedis));

return builder;
}

private Pool<Jedis> createJedisPool() {
String redisURI = System.getenv("REDIS_URI");
if (redisURI != null && !redisURI.isEmpty()) {
return new JedisPool(redisURI);
} else {
return new JedisPool();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*******************************************************************************
* Copyright (c) 2013-2015 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Zebra Technologies - initial API and implementation
* Achim Kraus (Bosch Software Innovations GmbH) - replace close() with destroy()
* Michał Wadowski (Orange) - Improved compliance with rfc6690
*******************************************************************************/

package org.eclipse.leshan.integration.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.leshan.integration.tests.util.IntegrationTestHelper.LIFETIME;
import static org.eclipse.leshan.integration.tests.util.IntegrationTestHelper.linkParser;
import static org.eclipse.leshan.integration.tests.util.LeshanTestClientBuilder.givenClientUsing;
import static org.eclipse.leshan.integration.tests.util.assertion.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.link.LinkParseException;
import org.eclipse.leshan.integration.tests.util.LeshanTestClient;
import org.eclipse.leshan.integration.tests.util.LeshanTestClientBuilder;
import org.eclipse.leshan.integration.tests.util.LeshanTestServer;
import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder;
import org.eclipse.leshan.integration.tests.util.junit5.extensions.BeforeEachParameterizedResolver;
import org.eclipse.leshan.server.registration.Registration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@ExtendWith(BeforeEachParameterizedResolver.class)
public class RegistrationTest2 {

/*---------------------------------/
* Parameterized Tests
* -------------------------------*/
@ParameterizedTest(name = "{0} - Client using {1} - Server using {2}")
@MethodSource("transports")
@Retention(RetentionPolicy.RUNTIME)
private @interface TestAllTransportLayer {
}

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", "java-coap") //
);
}

/*---------------------------------/
* Set-up and Tear-down Tests
* -------------------------------*/

LeshanTestServer server;
LeshanTestClientBuilder givenClient;
LeshanTestClient client;

@BeforeEach
public void start(Protocol givenProtocol, String givenClientEndpointProvider, String givenServerEndpointProvider) {
server = givenServerUsing(givenProtocol).with(givenServerEndpointProvider).build();
server.start();
givenClient = givenClientUsing(givenProtocol).with(givenClientEndpointProvider).connectingTo(server);
}

@AfterEach
public void stop() throws InterruptedException {
if (client != null)
client.destroy(false);
if (server != null)
server.destroy();
}

protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) {
return new LeshanTestServerBuilder(givenProtocol);
}

/*---------------------------------/
* Tests
* -------------------------------*/
@TestAllTransportLayer
public void register_update_deregister(Protocol protocol, String clientEndpointProvider,
String serverEndpointProvider) throws LinkParseException {

// Check client is not registered
client = givenClient.build();
assertThat(client).isNotRegisteredAt(server);

// Start it and wait for registration
client.start();
server.waitForNewRegistrationOf(client);
client.waitForRegistrationTo(server);

// Check client is well registered
assertThat(client).isRegisteredAt(server);
Registration registration = server.getRegistrationFor(client);
assertThat(registration.getObjectLinks()) //
.isEqualTo(linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1>;ver=1.1,</1/0>,</2>,</3>;ver=1.1,</3/0>,</3442/0>"
.getBytes()));

// Check for update
client.waitForUpdateTo(server, LIFETIME, TimeUnit.SECONDS);
server.waitForUpdateOf(registration);
assertThat(client).isRegisteredAt(server);

// Check deregistration
client.stop(true);
server.waitForDeregistrationOf(registration);
assertThat(client).isNotRegisteredAt(server);
}
}
Loading