lwm2m: refactoring tests
This commit is contained in:
parent
549e68e4b8
commit
8763e85e3f
@ -21,7 +21,6 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.californium.elements.config.Configuration;
|
||||
import org.eclipse.leshan.client.LeshanClient;
|
||||
import org.eclipse.leshan.client.object.Security;
|
||||
import org.eclipse.leshan.core.ResponseCode;
|
||||
@ -86,8 +85,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.eclipse.californium.core.config.CoapConfig.COAP_PORT;
|
||||
import static org.eclipse.californium.core.config.CoapConfig.COAP_SECURE_PORT;
|
||||
import static org.eclipse.leshan.client.object.Security.noSec;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -135,8 +132,6 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
|
||||
public static final String SECURE_URI = COAPS + host + ":" + securityPort;
|
||||
public static final String URI_BS = COAP + hostBs + ":" + portBs;
|
||||
public static final String SECURE_URI_BS = COAPS + hostBs + ":" + securityPortBs;
|
||||
public static final Configuration COAP_CONFIG = new Configuration().set(COAP_PORT, port).set(COAP_SECURE_PORT, securityPort);
|
||||
public static Configuration COAP_CONFIG_BS = new Configuration().set(COAP_PORT, portBs).set(COAP_SECURE_PORT, securityPortBs);
|
||||
public static final Security SECURITY_NO_SEC = noSec(URI, shortServerId);
|
||||
|
||||
protected final String OBSERVE_ATTRIBUTES_WITHOUT_PARAMS =
|
||||
@ -219,7 +214,6 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
|
||||
|
||||
public void basicTestConnectionObserveTelemetry(Security security,
|
||||
LwM2MDeviceCredentials deviceCredentials,
|
||||
Configuration coapConfig,
|
||||
String endpoint,
|
||||
boolean queueMode) throws Exception {
|
||||
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE));
|
||||
@ -238,7 +232,7 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
|
||||
getWsClient().waitForReply();
|
||||
|
||||
getWsClient().registerWaitForUpdate();
|
||||
createNewClient(security, null, coapConfig, false, endpoint, null, queueMode);
|
||||
createNewClient(security, null, false, endpoint, null, queueMode);
|
||||
deviceId = device.getId().getId().toString();
|
||||
awaitObserveReadAll(0, deviceId);
|
||||
String msg = getWsClient().waitForUpdate();
|
||||
@ -306,24 +300,24 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
public void createNewClient(Security security, Security securityBs, Configuration coapConfig, boolean isRpc,
|
||||
public void createNewClient(Security security, Security securityBs, boolean isRpc,
|
||||
String endpoint) throws Exception {
|
||||
this.createNewClient(security, securityBs, coapConfig, isRpc, endpoint, null, false);
|
||||
this.createNewClient(security, securityBs, isRpc, endpoint, null, false);
|
||||
}
|
||||
|
||||
public void createNewClient(Security security, Security securityBs, Configuration coapConfig, boolean isRpc,
|
||||
public void createNewClient(Security security, Security securityBs, boolean isRpc,
|
||||
String endpoint, Integer clientDtlsCidLength) throws Exception {
|
||||
this.createNewClient(security, securityBs, coapConfig, isRpc, endpoint, clientDtlsCidLength, false);
|
||||
this.createNewClient(security, securityBs, isRpc, endpoint, clientDtlsCidLength, false);
|
||||
}
|
||||
|
||||
public void createNewClient(Security security, Security securityBs, Configuration coapConfig, boolean isRpc,
|
||||
public void createNewClient(Security security, Security securityBs, boolean isRpc,
|
||||
String endpoint, Integer clientDtlsCidLength, boolean queueMode) throws Exception {
|
||||
this.clientDestroy();
|
||||
lwM2MTestClient = new LwM2MTestClient(this.executor, endpoint);
|
||||
|
||||
try (ServerSocket socket = new ServerSocket(0)) {
|
||||
int clientPort = socket.getLocalPort();
|
||||
lwM2MTestClient.init(security, securityBs, coapConfig, clientPort, isRpc,
|
||||
lwM2MTestClient.init(security, securityBs, clientPort, isRpc,
|
||||
this.defaultLwM2mUplinkMsgHandlerTest, this.clientContextTest, isWriteAttribute
|
||||
, clientDtlsCidLength, queueMode);
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ public class LwM2MTestClient {
|
||||
private LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest;
|
||||
private LwM2mClientContext clientContext;
|
||||
|
||||
public void init(Security security, Security securityBs,Configuration coapConfig, int port, boolean isRpc,
|
||||
public void init(Security security, Security securityBs, int port, boolean isRpc,
|
||||
LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandler,
|
||||
LwM2mClientContext clientContext, boolean isWriteAttribute, Integer cIdLength, boolean queueMode) throws InvalidDDFFileException, IOException {
|
||||
Assert.assertNull("client already initialized", leshanClient);
|
||||
@ -218,7 +218,6 @@ public class LwM2MTestClient {
|
||||
|
||||
// Create Californium Configuration
|
||||
Configuration clientCoapConfig = endpointsBuilder.createDefaultConfiguration();
|
||||
DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(coapConfig);
|
||||
|
||||
// Set some DTLS stuff
|
||||
// These configuration values are always overwritten by CLI therefore set them to transient.
|
||||
|
||||
@ -59,7 +59,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
|
||||
createDeviceProfile(transportConfiguration);
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO));
|
||||
final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
|
||||
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
|
||||
createNewClient(SECURITY_NO_SEC, null, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
|
||||
awaitObserveReadAll(0, device.getId().getId().toString());
|
||||
|
||||
device.setFirmwareId(createFirmware().getId());
|
||||
@ -84,7 +84,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
|
||||
createDeviceProfile(transportConfiguration);
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5));
|
||||
final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA5);
|
||||
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA5);
|
||||
createNewClient(SECURITY_NO_SEC, null, false, this.CLIENT_ENDPOINT_OTA5);
|
||||
awaitObserveReadAll(9, device.getId().getId().toString());
|
||||
|
||||
device.setFirmwareId(createFirmware().getId());
|
||||
@ -114,7 +114,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
|
||||
createDeviceProfile(transportConfiguration);
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA9));
|
||||
final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA9);
|
||||
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA9);
|
||||
createNewClient(SECURITY_NO_SEC, null, false, this.CLIENT_ENDPOINT_OTA9);
|
||||
awaitObserveReadAll(9, device.getId().getId().toString());
|
||||
|
||||
device.setSoftwareId(createSoftware().getId());
|
||||
|
||||
@ -91,7 +91,7 @@ public abstract class AbstractRpcLwM2MIntegrationTest extends AbstractLwM2MInteg
|
||||
|
||||
private void initRpc () throws Exception {
|
||||
String endpoint = DEVICE_ENDPOINT_RPC_PREF + endpointSequence.incrementAndGet();
|
||||
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, true, endpoint);
|
||||
createNewClient(SECURITY_NO_SEC, null, true, endpoint);
|
||||
expectedObjects = ConcurrentHashMap.newKeySet();
|
||||
expectedObjectIdVers = ConcurrentHashMap.newKeySet();
|
||||
expectedInstances = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@ -18,7 +18,6 @@ package org.thingsboard.server.transport.lwm2m.security;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.eclipse.californium.elements.config.Configuration;
|
||||
import org.eclipse.leshan.client.object.Security;
|
||||
import org.eclipse.leshan.core.ResponseCode;
|
||||
import org.eclipse.leshan.core.util.Hex;
|
||||
@ -186,7 +185,6 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint));
|
||||
this.basicTestConnection(null , SECURITY_NO_SEC_BS,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG_BS,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
awaitAlias,
|
||||
@ -198,7 +196,6 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
|
||||
protected void basicTestConnection(Security security, Security securityBs,
|
||||
LwM2MDeviceCredentials deviceCredentials,
|
||||
Configuration coapConfig,
|
||||
String endpoint,
|
||||
Lwm2mDeviceProfileTransportConfiguration transportConfiguration,
|
||||
String awaitAlias,
|
||||
@ -208,7 +205,7 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
boolean isStartLw) throws Exception {
|
||||
createDeviceProfile(transportConfiguration);
|
||||
final Device device = createDevice(deviceCredentials, endpoint);
|
||||
createNewClient(security, securityBs, coapConfig, true, endpoint);
|
||||
createNewClient(security, securityBs, true, endpoint);
|
||||
lwM2MTestClient.start(isStartLw);
|
||||
if (isAwaitObserveReadAll) {
|
||||
awaitObserveReadAll(0, device.getId().getId().toString());
|
||||
@ -236,7 +233,6 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
SECURITY_NO_SEC,
|
||||
SECURITY_NO_SEC_BS,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
awaitAlias,
|
||||
@ -246,7 +242,6 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
|
||||
private void basicTestConnectionBootstrapRequestTrigger(Security security, Security securityBs,
|
||||
LwM2MDeviceCredentials deviceCredentials,
|
||||
Configuration coapConfig,
|
||||
String endpoint,
|
||||
Lwm2mDeviceProfileTransportConfiguration transportConfiguration,
|
||||
String awaitAlias,
|
||||
@ -256,7 +251,7 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
createDeviceProfile(transportConfiguration);
|
||||
final Device device = createDevice(deviceCredentials, endpoint);
|
||||
String deviceIdStr = device.getId().getId().toString();
|
||||
createNewClient(security, securityBs, coapConfig, true, endpoint);
|
||||
createNewClient(security, securityBs, true, endpoint);
|
||||
lwM2MTestClient.start(true);
|
||||
awaitObserveReadAll(0, deviceIdStr);
|
||||
await(awaitAlias)
|
||||
|
||||
@ -52,7 +52,7 @@ public abstract class AbstractSecurityLwM2MIntegrationDtlsCidLengthTest extends
|
||||
createDeviceProfile(transportConfiguration);
|
||||
final Device device = createDevice(deviceCredentials, clientEndpoint);
|
||||
device.getId().getId().toString();
|
||||
createNewClient(security, null, COAP_CONFIG, true, clientEndpoint, clientDtlsCidLength);
|
||||
createNewClient(security, null, true, clientEndpoint, clientDtlsCidLength);
|
||||
lwM2MTestClient.start(true);
|
||||
await(awaitAlias)
|
||||
.atMost(40, TimeUnit.SECONDS)
|
||||
|
||||
@ -52,7 +52,7 @@ public abstract class AbstractLwM2MIntegrationDiffPortTest extends AbstractSecur
|
||||
|
||||
createDeviceProfile(transportConfiguration);
|
||||
createDevice(deviceCredentials, clientEndpoint);
|
||||
createNewClient(security, null, COAP_CONFIG, true, clientEndpoint);
|
||||
createNewClient(security, null, true, clientEndpoint);
|
||||
lwM2MTestClient.start(true);
|
||||
await(awaitAlias)
|
||||
.atMost(40, TimeUnit.SECONDS)
|
||||
|
||||
@ -32,13 +32,13 @@ public class NoSecLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationT
|
||||
public void testWithNoSecConnectLwm2mSuccessAndObserveTelemetry() throws Exception {
|
||||
String clientEndpoint = CLIENT_ENDPOINT_NO_SEC;
|
||||
LwM2MDeviceCredentials clientCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint));
|
||||
super.basicTestConnectionObserveTelemetry(SECURITY_NO_SEC, clientCredentials, COAP_CONFIG, clientEndpoint, false);
|
||||
super.basicTestConnectionObserveTelemetry(SECURITY_NO_SEC, clientCredentials, clientEndpoint, false);
|
||||
}
|
||||
@Test
|
||||
public void testWithNoSecQueueModeConnectLwm2mSuccessAndObserveTelemetry() throws Exception {
|
||||
String clientEndpoint = CLIENT_ENDPOINT_NO_SEC + "_QueueMode";
|
||||
LwM2MDeviceCredentials clientCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint));
|
||||
super.basicTestConnectionObserveTelemetry(SECURITY_NO_SEC, clientCredentials, COAP_CONFIG, clientEndpoint, true);
|
||||
super.basicTestConnectionObserveTelemetry(SECURITY_NO_SEC, clientCredentials, clientEndpoint, true);
|
||||
}
|
||||
|
||||
// Bootstrap + Lwm2m
|
||||
|
||||
@ -57,7 +57,6 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes
|
||||
this.basicTestConnection(security,
|
||||
null,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (Psk_Lwm2m)",
|
||||
@ -103,7 +102,6 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false);
|
||||
this.basicTestConnection(null, securityBs,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG_BS,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (PskBS two section)",
|
||||
|
||||
@ -58,7 +58,6 @@ public class RpkLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationTes
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, RPK, false);
|
||||
this.basicTestConnection(security, null,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (Rpk_Lwm2m)",
|
||||
@ -119,7 +118,6 @@ public class RpkLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationTes
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, clientPrivateKeyFromCertTrust, certificate, RPK, false);
|
||||
this.basicTestConnection(null, securityBs,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG_BS,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (RpkBS two section)",
|
||||
|
||||
@ -59,7 +59,6 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg
|
||||
this.basicTestConnection(security,
|
||||
null,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (X509_Trust_Lwm2m)",
|
||||
@ -121,7 +120,6 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg
|
||||
this.basicTestConnection(security,
|
||||
null,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG_BS,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (X509NoTrust two section)",
|
||||
|
||||
@ -53,7 +53,6 @@ public class X509_TrustLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegra
|
||||
this.basicTestConnection(security,
|
||||
null,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (X509_Trust_Lwm2m)",
|
||||
@ -81,7 +80,6 @@ public class X509_TrustLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegra
|
||||
this.basicTestConnection(security,
|
||||
null,
|
||||
deviceCredentials,
|
||||
COAP_CONFIG_BS,
|
||||
clientEndpoint,
|
||||
transportConfiguration,
|
||||
"await on client state (X509Trust two section)",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user