Merge remote-tracking branch 'upstream/develop/3.5' into feature/test_dependency_refactor
# Conflicts: # dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceServiceTest.java # dao/src/test/java/org/thingsboard/server/dao/service/BaseOtaPackageServiceTest.java
This commit is contained in:
commit
c73fc3e0fc
@ -690,7 +690,7 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
|
||||
edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
||||
Assert.assertTrue(edgeImitator.waitForResponses());
|
||||
|
||||
Assert.assertTrue(onUpdateCallback.getSubscribeLatch().await(5, TimeUnit.SECONDS));
|
||||
Assert.assertTrue(onUpdateCallback.getSubscribeLatch().await(30, TimeUnit.SECONDS));
|
||||
|
||||
Assert.assertEquals(JacksonUtil.OBJECT_MAPPER.createObjectNode().put(attrKey, attrValue),
|
||||
JacksonUtil.fromBytes(onUpdateCallback.getPayloadBytes()));
|
||||
|
||||
@ -19,10 +19,8 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.server.common.data.EntityInfo;
|
||||
import org.thingsboard.server.common.data.ResourceType;
|
||||
@ -46,6 +44,7 @@ import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@DaoSqlTest
|
||||
@ -116,10 +115,6 @@ public class BaseTbResourceServiceTest extends AbstractControllerTest {
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testSaveResourceWithMaxSumDataSizeOutOfLimit() throws Exception {
|
||||
loginSysAdmin();
|
||||
@ -138,9 +133,9 @@ public class BaseTbResourceServiceTest extends AbstractControllerTest {
|
||||
Assert.assertEquals(1, resourceService.sumDataSizeByTenantId(tenantId));
|
||||
|
||||
try {
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage(String.format("Failed to create the tb resource, files size limit is exhausted %d bytes!", limit));
|
||||
createResource("test1", 1 + DEFAULT_FILE_NAME);
|
||||
assertThatThrownBy(() -> createResource("test1", 1 + DEFAULT_FILE_NAME))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Failed to create the tb resource, files size limit is exhausted %d bytes!", limit);
|
||||
} finally {
|
||||
defaultTenantProfile.getProfileData().setConfiguration(DefaultTenantProfileConfiguration.builder().maxResourcesInBytes(0).build());
|
||||
loginSysAdmin();
|
||||
|
||||
@ -70,7 +70,7 @@ import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
|
||||
import org.thingsboard.server.transport.AbstractTransportIntegrationTest;
|
||||
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
|
||||
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
@ -108,7 +108,7 @@ import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfil
|
||||
public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportIntegrationTest {
|
||||
|
||||
@SpyBean
|
||||
DefaultLwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest;
|
||||
LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest;
|
||||
|
||||
@Autowired
|
||||
private LwM2mClientContext clientContextTest;
|
||||
|
||||
@ -45,7 +45,7 @@ import org.junit.Assert;
|
||||
import org.mockito.Mockito;
|
||||
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
|
||||
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -109,12 +109,12 @@ public class LwM2MTestClient {
|
||||
private LwM2MLocationParams locationParams;
|
||||
private LwM2mTemperatureSensor lwM2MTemperatureSensor;
|
||||
private Set<LwM2MClientState> clientStates;
|
||||
private DefaultLwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest;
|
||||
private LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest;
|
||||
private LwM2mClientContext clientContext;
|
||||
|
||||
public void init(Security security, Configuration coapConfig, int port, boolean isRpc, boolean isBootstrap,
|
||||
int shortServerId, int shortServerIdBs, Security securityBs,
|
||||
DefaultLwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandler,
|
||||
LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandler,
|
||||
LwM2mClientContext clientContext) throws InvalidDDFFileException, IOException {
|
||||
Assert.assertNull("client already initialized", leshanClient);
|
||||
this.defaultLwM2mUplinkMsgHandlerTest = defaultLwM2mUplinkMsgHandler;
|
||||
|
||||
@ -21,6 +21,13 @@
|
||||
<!-- mute TelemetryEdgeSqlTest that causes a lot of randomly generated errors -->
|
||||
<logger name="org.thingsboard.server.service.edge.rpc.EdgeGrpcSession" level="OFF"/>
|
||||
|
||||
<!-- LwM2m lifecycle debug for the test scope -->
|
||||
<logger name="org.thingsboard.server.transport.lwm2m.server.downlink.DefaultLwM2mDownlinkMsgHandler" level="TRACE"/>
|
||||
<logger name="org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler" level="TRACE"/>
|
||||
<logger name="org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService" level="TRACE"/>
|
||||
<logger name="org.thingsboard.server.transport.lwm2m.server" level="INFO"/>
|
||||
<logger name="org.eclipse.californium.core" level="INFO"/>
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
@ -25,6 +25,7 @@ import org.eclipse.leshan.core.node.codec.DefaultLwM2mEncoder;
|
||||
import org.eclipse.leshan.server.californium.LeshanServer;
|
||||
import org.eclipse.leshan.server.californium.LeshanServerBuilder;
|
||||
import org.eclipse.leshan.server.californium.registration.CaliforniumRegistrationStore;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.cache.ota.OtaPackageDataCache;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
@ -35,7 +36,7 @@ import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
|
||||
import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MAuthorizer;
|
||||
import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MDtlsCertificateVerifier;
|
||||
import org.thingsboard.server.transport.lwm2m.server.store.TbSecurityStore;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
@ -56,6 +57,7 @@ import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaU
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@DependsOn({"lwM2mDownlinkMsgHandler", "lwM2mUplinkMsgHandler"})
|
||||
@TbLwM2mTransportComponent
|
||||
@RequiredArgsConstructor
|
||||
public class DefaultLwM2mTransportService implements LwM2MTransportService {
|
||||
@ -66,7 +68,7 @@ public class DefaultLwM2mTransportService implements LwM2MTransportService {
|
||||
private final LwM2mTransportContext context;
|
||||
private final LwM2MTransportServerConfig config;
|
||||
private final OtaPackageDataCache otaPackageDataCache;
|
||||
private final DefaultLwM2mUplinkMsgHandler handler;
|
||||
private final LwM2mUplinkMsgHandler handler;
|
||||
private final CaliforniumRegistrationStore registrationStore;
|
||||
private final TbSecurityStore securityStore;
|
||||
private final TbLwM2MDtlsCertificateVerifier certificateVerifier;
|
||||
|
||||
@ -42,7 +42,7 @@ import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService;
|
||||
import org.thingsboard.server.transport.lwm2m.server.session.LwM2MSessionManager;
|
||||
import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MClientStore;
|
||||
import org.thingsboard.server.transport.lwm2m.server.store.TbMainSecurityStore;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -75,7 +75,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private DefaultLwM2mUplinkMsgHandler defaultLwM2MUplinkMsgHandler;
|
||||
private LwM2mUplinkMsgHandler defaultLwM2MUplinkMsgHandler;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private LwM2MOtaUpdateService otaUpdateService;
|
||||
|
||||
@ -85,6 +85,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
@ -103,7 +104,7 @@ import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.ge
|
||||
import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.validateVersionedId;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Service("lwM2mDownlinkMsgHandler")
|
||||
@TbLwM2mTransportComponent
|
||||
@RequiredArgsConstructor
|
||||
public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService implements LwM2mDownlinkMsgHandler {
|
||||
@ -124,6 +125,7 @@ public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService im
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
log.trace("Destroying {}", getClass().getSimpleName());
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@ -521,16 +523,22 @@ public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService im
|
||||
|
||||
private <R extends DownlinkRequest<T>, T extends LwM2mResponse> void handleDownlinkError(LwM2mClient client, R request, DownlinkRequestCallback<R, T> callback, Exception e) {
|
||||
log.trace("[{}] Received downlink error: {}.", client.getEndpoint(), e);
|
||||
client.updateLastUplinkTime();
|
||||
executor.submit(() -> {
|
||||
if (e instanceof TimeoutException || e instanceof ClientSleepingException) {
|
||||
log.trace("[{}] Received {}, client is probably sleeping", client.getEndpoint(), e.getClass().getSimpleName());
|
||||
clientContext.asleep(client);
|
||||
} else {
|
||||
log.trace("[{}] Received {}", client.getEndpoint(), e.getClass().getSimpleName());
|
||||
}
|
||||
callback.onError(toString(request), e);
|
||||
});
|
||||
try {
|
||||
client.updateLastUplinkTime();
|
||||
executor.submit(() -> {
|
||||
if (e instanceof TimeoutException || e instanceof ClientSleepingException) {
|
||||
log.trace("[{}] Received {}, client is probably sleeping", client.getEndpoint(), e.getClass().getSimpleName());
|
||||
clientContext.asleep(client);
|
||||
} else {
|
||||
log.trace("[{}] Received {}", client.getEndpoint(), e.getClass().getSimpleName());
|
||||
}
|
||||
callback.onError(toString(request), e);
|
||||
});
|
||||
} catch (RejectedExecutionException ree) {
|
||||
log.warn("[{}] Can not handle downlink error. Executor already down", client.getEndpoint(), ree);
|
||||
} catch (Exception exception) {
|
||||
log.warn("[{}] Can not handle downlink error", client.getEndpoint(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
private WriteRequest getWriteRequestSingleResource(ResourceModel.Type type, ContentFormat contentFormat, int objectId, int instanceId, int resourceId, Object value) {
|
||||
|
||||
@ -146,6 +146,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
log.trace("Destroying {}", getClass().getSimpleName());
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,8 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.leshan.core.ResponseCode;
|
||||
import org.eclipse.leshan.core.model.ObjectModel;
|
||||
@ -32,6 +34,7 @@ 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.codec.LwM2mValueConverter;
|
||||
import org.eclipse.leshan.core.observation.Observation;
|
||||
import org.eclipse.leshan.core.request.*;
|
||||
import org.eclipse.leshan.core.request.WriteRequest.Mode;
|
||||
@ -122,69 +125,41 @@ import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.fr
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Service("lwM2mUplinkMsgHandler")
|
||||
@TbLwM2mTransportComponent
|
||||
@RequiredArgsConstructor
|
||||
public class DefaultLwM2mUplinkMsgHandler extends LwM2MExecutorAwareService implements LwM2mUplinkMsgHandler {
|
||||
|
||||
public LwM2mValueConverterImpl converter;
|
||||
@Getter
|
||||
private final LwM2mValueConverter converter = LwM2mValueConverterImpl.getInstance();;
|
||||
|
||||
private final TransportService transportService;
|
||||
private final LwM2mTransportContext context;
|
||||
@Lazy
|
||||
private final LwM2MAttributesService attributesService;
|
||||
private final LwM2MSessionManager sessionManager;
|
||||
@Lazy
|
||||
private final LwM2MOtaUpdateService otaService;
|
||||
private final LwM2MTransportServerConfig config;
|
||||
private final LwM2MTelemetryLogService logService;
|
||||
private final LwM2mTransportServerHelper helper;
|
||||
private final TbLwM2MDtlsSessionStore sessionStore;
|
||||
private final LwM2mClientContext clientContext;
|
||||
private final LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler;
|
||||
private final LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler; //Do not use Lazy because we need live executor to handle msgs
|
||||
private final LwM2mVersionedModelProvider modelProvider;
|
||||
private final RegistrationStore registrationStore;
|
||||
private final TbLwM2mSecurityStore securityStore;
|
||||
private final LwM2MModelConfigService modelConfigService;
|
||||
|
||||
public DefaultLwM2mUplinkMsgHandler(TransportService transportService,
|
||||
LwM2MTransportServerConfig config,
|
||||
LwM2mTransportServerHelper helper,
|
||||
LwM2mClientContext clientContext,
|
||||
LwM2MTelemetryLogService logService,
|
||||
LwM2MSessionManager sessionManager,
|
||||
@Lazy LwM2MOtaUpdateService otaService,
|
||||
@Lazy LwM2MAttributesService attributesService,
|
||||
@Lazy LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler,
|
||||
LwM2mTransportContext context,
|
||||
TbLwM2MDtlsSessionStore sessionStore,
|
||||
LwM2mVersionedModelProvider modelProvider,
|
||||
RegistrationStore registrationStore,
|
||||
TbLwM2mSecurityStore securityStore,
|
||||
LwM2MModelConfigService modelConfigService) {
|
||||
this.transportService = transportService;
|
||||
this.sessionManager = sessionManager;
|
||||
this.attributesService = attributesService;
|
||||
this.otaService = otaService;
|
||||
this.config = config;
|
||||
this.helper = helper;
|
||||
this.clientContext = clientContext;
|
||||
this.logService = logService;
|
||||
this.defaultLwM2MDownlinkMsgHandler = defaultLwM2MDownlinkMsgHandler;
|
||||
this.context = context;
|
||||
this.sessionStore = sessionStore;
|
||||
this.modelProvider = modelProvider;
|
||||
this.registrationStore = registrationStore;
|
||||
this.securityStore = securityStore;
|
||||
this.modelConfigService = modelConfigService;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
super.init();
|
||||
this.context.getScheduler().scheduleAtFixedRate(this::reportActivity, new Random().nextInt((int) config.getSessionReportTimeout()), config.getSessionReportTimeout(), TimeUnit.MILLISECONDS);
|
||||
this.converter = LwM2mValueConverterImpl.getInstance();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
log.trace("Destroying {}", getClass().getSimpleName());
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@ -955,6 +930,7 @@ public class DefaultLwM2mUplinkMsgHandler extends LwM2MExecutorAwareService impl
|
||||
*
|
||||
* @param lwM2MClient - LwM2M Client
|
||||
*/
|
||||
@Override
|
||||
public void initAttributes(LwM2mClient lwM2MClient, boolean logFailedUpdateOfNonChangedValue) {
|
||||
Map<String, String> keyNamesMap = this.getNamesFromProfileForSharedAttributes(lwM2MClient);
|
||||
if (!keyNamesMap.isEmpty()) {
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.lwm2m.server.uplink;
|
||||
|
||||
import org.eclipse.leshan.core.node.codec.LwM2mValueConverter;
|
||||
import org.eclipse.leshan.core.observation.Observation;
|
||||
import org.eclipse.leshan.core.request.CreateRequest;
|
||||
import org.eclipse.leshan.core.request.SendRequest;
|
||||
@ -69,5 +70,10 @@ public interface LwM2mUplinkMsgHandler {
|
||||
|
||||
void onToTransportUpdateCredentials(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.ToTransportUpdateCredentialsProto updateCredentials);
|
||||
|
||||
void initAttributes(LwM2mClient lwM2MClient, boolean logFailedUpdateOfNonChangedValue);
|
||||
|
||||
LwM2MTransportServerConfig getConfig();
|
||||
|
||||
LwM2mValueConverter getConverter();
|
||||
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdate
|
||||
import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState;
|
||||
import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult;
|
||||
import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler;
|
||||
import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -289,12 +289,12 @@ public class LwM2MTransportUtil {
|
||||
* Attribute pmax = new Attribute(MAXIMUM_PERIOD, "60");
|
||||
* Attribute [] attrs = {gt, st};
|
||||
*/
|
||||
public static SimpleDownlinkRequest createWriteAttributeRequest(String target, Object params, DefaultLwM2mUplinkMsgHandler serviceImpl) {
|
||||
public static SimpleDownlinkRequest createWriteAttributeRequest(String target, Object params, LwM2mUplinkMsgHandler serviceImpl) {
|
||||
AttributeSet attrSet = new AttributeSet(createWriteAttributes(params, serviceImpl, target));
|
||||
return attrSet.getAttributes().size() > 0 ? new WriteAttributesRequest(target, attrSet) : null;
|
||||
}
|
||||
|
||||
private static Attribute[] createWriteAttributes(Object params, DefaultLwM2mUplinkMsgHandler serviceImpl, String target) {
|
||||
private static Attribute[] createWriteAttributes(Object params, LwM2mUplinkMsgHandler serviceImpl, String target) {
|
||||
List<Attribute> attributeLists = new ArrayList<>();
|
||||
Map<String, Object> map = JacksonUtil.convertValue(params, new TypeReference<>() {
|
||||
});
|
||||
@ -366,19 +366,19 @@ public class LwM2MTransportUtil {
|
||||
return newValues;
|
||||
}
|
||||
|
||||
public static Object convertWriteAttributes(String type, Object value, DefaultLwM2mUplinkMsgHandler serviceImpl, String target) {
|
||||
public static Object convertWriteAttributes(String type, Object value, LwM2mUplinkMsgHandler serviceImpl, String target) {
|
||||
switch (type) {
|
||||
/** Integer [0:255]; */
|
||||
case DIMENSION:
|
||||
Long dim = (Long) serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target));
|
||||
Long dim = (Long) serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target));
|
||||
return dim >= 0 && dim <= 255 ? dim : null;
|
||||
/**String;*/
|
||||
case OBJECT_VERSION:
|
||||
return serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), STRING, new LwM2mPath(target));
|
||||
return serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), STRING, new LwM2mPath(target));
|
||||
/**INTEGER */
|
||||
case MINIMUM_PERIOD:
|
||||
case MAXIMUM_PERIOD:
|
||||
return serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target));
|
||||
return serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target));
|
||||
/**Float; */
|
||||
case GREATER_THAN:
|
||||
case LESSER_THAN:
|
||||
@ -386,7 +386,7 @@ public class LwM2MTransportUtil {
|
||||
if (value.getClass().getSimpleName().equals("String")) {
|
||||
value = Double.valueOf((String) value);
|
||||
}
|
||||
return serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), FLOAT, new LwM2mPath(target));
|
||||
return serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), FLOAT, new LwM2mPath(target));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -19,10 +19,8 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -54,6 +52,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
||||
|
||||
@ -89,10 +88,6 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
|
||||
tenantProfileService.deleteTenantProfiles(anotherTenantId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testSaveDevicesWithoutMaxDeviceLimit() {
|
||||
Device device = this.saveDevice(tenantId, "My device");
|
||||
@ -261,9 +256,9 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
|
||||
|
||||
savedDevice.setFirmwareId(savedFirmware.getId());
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("Can't assign firmware with different deviceProfile!");
|
||||
deviceService.saveDevice(savedDevice);
|
||||
assertThatThrownBy(() -> deviceService.saveDevice(savedDevice))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Can't assign firmware with different deviceProfile!");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -19,9 +19,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -48,6 +46,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
|
||||
|
||||
public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
@ -83,10 +82,6 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
deviceProfileId = savedDeviceProfile.getId();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
tenantService.deleteTenant(tenantId);
|
||||
@ -104,9 +99,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
createAndSaveFirmware(tenantId, "1");
|
||||
Assert.assertEquals(1, otaPackageService.sumDataSizeByTenantId(tenantId));
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage(String.format("Failed to create the ota package, files size limit is exhausted %d bytes!", DATA_SIZE));
|
||||
createAndSaveFirmware(tenantId, "2");
|
||||
assertThatThrownBy(() -> createAndSaveFirmware(tenantId, "2"))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Failed to create the ota package, files size limit is exhausted %d bytes!", DATA_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -248,9 +243,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage should be assigned to tenant!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage should be assigned to tenant!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -266,9 +261,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("Type should be specified!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Type should be specified!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -284,9 +279,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage title should be specified!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage title should be specified!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -302,9 +297,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage file name should be specified!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage file name should be specified!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -320,9 +315,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage content type should be specified!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage content type should be specified!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -338,9 +333,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM);
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage data should be specified!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage data should be specified!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -357,9 +352,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage is referencing to non-existent tenant!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage is referencing to non-existent tenant!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -376,9 +371,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksum(CHECKSUM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage is referencing to non-existent device profile!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage is referencing to non-existent device profile!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -394,9 +389,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM);
|
||||
firmware.setData(DATA);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage checksum should be specified!");
|
||||
otaPackageService.saveOtaPackage(firmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage checksum should be specified!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -416,17 +411,17 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
newFirmwareInfo.setTitle(TITLE);
|
||||
newFirmwareInfo.setVersion(VERSION);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage with such title and version already exists!");
|
||||
otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage with such title and version already exists!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveFirmwareWithExistingTitleAndVersion() {
|
||||
createAndSaveFirmware(tenantId, VERSION);
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("OtaPackage with such title and version already exists!");
|
||||
createAndSaveFirmware(tenantId, VERSION);
|
||||
assertThatThrownBy(() -> createAndSaveFirmware(tenantId, VERSION))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("OtaPackage with such title and version already exists!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -441,9 +436,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
Device savedDevice = deviceService.saveDevice(device);
|
||||
|
||||
try {
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("The otaPackage referenced by the devices cannot be deleted!");
|
||||
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
|
||||
assertThatThrownBy(() -> otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("The otaPackage referenced by the devices cannot be deleted!");
|
||||
} finally {
|
||||
deviceService.deleteDevice(tenantId, savedDevice.getId());
|
||||
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
|
||||
@ -453,12 +448,12 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
@Test
|
||||
public void testUpdateDeviceProfileId() {
|
||||
OtaPackage savedFirmware = createAndSaveFirmware(tenantId, VERSION);
|
||||
savedFirmware.setDeviceProfileId(null);
|
||||
|
||||
try {
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("Updating otaPackage deviceProfile is prohibited!");
|
||||
savedFirmware.setDeviceProfileId(null);
|
||||
otaPackageService.saveOtaPackage(savedFirmware);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(savedFirmware))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Updating otaPackage deviceProfile is prohibited!");
|
||||
} finally {
|
||||
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
|
||||
}
|
||||
@ -487,9 +482,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
deviceProfileService.saveDeviceProfile(savedDeviceProfile);
|
||||
|
||||
try {
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("The otaPackage referenced by the device profile cannot be deleted!");
|
||||
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
|
||||
assertThatThrownBy(() -> otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("The otaPackage referenced by the device profile cannot be deleted!");
|
||||
} finally {
|
||||
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId());
|
||||
}
|
||||
@ -641,12 +636,18 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmwareInfo.setType(FIRMWARE);
|
||||
firmwareInfo.setTitle(TITLE);
|
||||
firmwareInfo.setVersion(VERSION);
|
||||
|
||||
firmwareInfo.setUrl(" ");
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("Ota package URL should be specified!");
|
||||
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
|
||||
.as("firmwareInfo url set whitespaces")
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Ota package URL should be specified!");
|
||||
|
||||
firmwareInfo.setUrl("");
|
||||
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
|
||||
.as("firmwareInfo url is empty")
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Ota package URL should be specified!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -660,12 +661,10 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmwareInfo.setTenantId(tenantId);
|
||||
|
||||
OtaPackageInfo savedFirmwareInfo = otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("Updating otaPackage URL is prohibited!");
|
||||
|
||||
savedFirmwareInfo.setUrl("https://newurl.com");
|
||||
otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("Updating otaPackage URL is prohibited!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -678,10 +677,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmwareInfo.setUrl(URL);
|
||||
firmwareInfo.setTenantId(tenantId);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("title length must be equal or less than 255");
|
||||
|
||||
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("title length must be equal or less than 255");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -692,11 +690,11 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
firmwareInfo.setUrl(URL);
|
||||
firmwareInfo.setTenantId(tenantId);
|
||||
firmwareInfo.setTitle(TITLE);
|
||||
|
||||
firmwareInfo.setVersion(StringUtils.random(257));
|
||||
thrown.expectMessage("version length must be equal or less than 255");
|
||||
|
||||
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
|
||||
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
|
||||
.isInstanceOf(DataValidationException.class)
|
||||
.hasMessageContaining("version length must be equal or less than 255");
|
||||
}
|
||||
|
||||
private OtaPackage createAndSaveFirmware(TenantId tenantId, String version) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user