75 changed files with 3640 additions and 1610 deletions
@ -0,0 +1,144 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.controller; |
||||
|
|
||||
|
import com.fasterxml.jackson.core.type.TypeReference; |
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import com.google.common.util.concurrent.ListeningExecutorService; |
||||
|
import com.google.common.util.concurrent.MoreExecutors; |
||||
|
import org.junit.After; |
||||
|
import org.junit.Assert; |
||||
|
import org.junit.Before; |
||||
|
import org.junit.Test; |
||||
|
import org.mockito.AdditionalAnswers; |
||||
|
import org.mockito.Mockito; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Primary; |
||||
|
import org.springframework.test.annotation.DirtiesContext; |
||||
|
import org.springframework.test.context.ContextConfiguration; |
||||
|
import org.springframework.test.context.TestPropertySource; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.common.util.ThingsBoardExecutors; |
||||
|
import org.thingsboard.server.common.data.Device; |
||||
|
import org.thingsboard.server.common.data.DeviceProfile; |
||||
|
import org.thingsboard.server.common.data.DeviceProfileType; |
||||
|
import org.thingsboard.server.common.data.DeviceTransportType; |
||||
|
import org.thingsboard.server.common.data.Tenant; |
||||
|
import org.thingsboard.server.common.data.User; |
||||
|
import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; |
||||
|
import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; |
||||
|
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration; |
||||
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
||||
|
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; |
||||
|
import org.thingsboard.server.common.data.id.DeviceProfileId; |
||||
|
import org.thingsboard.server.common.data.security.Authority; |
||||
|
import org.thingsboard.server.common.data.security.DeviceCredentials; |
||||
|
import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
||||
|
import org.thingsboard.server.dao.device.DeviceDao; |
||||
|
import org.thingsboard.server.dao.service.DaoSqlTest; |
||||
|
|
||||
|
import java.nio.file.Files; |
||||
|
import java.nio.file.Path; |
||||
|
|
||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.COAP; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.COAPS; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.DOCKER; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.HTTP; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.HTTPS; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.MQTT; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.MQTTS; |
||||
|
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.PEM_CERT_FILE_NAME; |
||||
|
|
||||
|
@TestPropertySource(properties = { |
||||
|
"device.connectivity.https.enabled=true", |
||||
|
"device.connectivity.http.port=80", |
||||
|
"device.connectivity.mqtt.enabled=false", |
||||
|
"device.connectivity.mqtts.enabled=false", |
||||
|
"device.connectivity.coap.enabled=false", |
||||
|
"device.connectivity.coaps.enabled=false", |
||||
|
}) |
||||
|
@ContextConfiguration(classes = {DeviceConnectivityControllerWithDefaultPortTest.Config.class}) |
||||
|
@DaoSqlTest |
||||
|
public class DeviceConnectivityControllerWithDefaultPortTest extends AbstractControllerTest { |
||||
|
|
||||
|
ListeningExecutorService executor; |
||||
|
|
||||
|
private Tenant savedTenant; |
||||
|
|
||||
|
static class Config { |
||||
|
@Bean |
||||
|
@Primary |
||||
|
public DeviceDao deviceDao(DeviceDao deviceDao) { |
||||
|
return Mockito.mock(DeviceDao.class, AdditionalAnswers.delegatesTo(deviceDao)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Before |
||||
|
public void beforeTest() throws Exception { |
||||
|
executor = MoreExecutors.listeningDecorator(ThingsBoardExecutors.newWorkStealingPool(8, getClass())); |
||||
|
|
||||
|
loginSysAdmin(); |
||||
|
|
||||
|
Tenant tenant = new Tenant(); |
||||
|
tenant.setTitle("My tenant"); |
||||
|
savedTenant = doPost("/api/tenant", tenant, Tenant.class); |
||||
|
Assert.assertNotNull(savedTenant); |
||||
|
|
||||
|
User tenantAdmin = new User(); |
||||
|
tenantAdmin.setAuthority(Authority.TENANT_ADMIN); |
||||
|
tenantAdmin.setTenantId(savedTenant.getId()); |
||||
|
tenantAdmin.setEmail("tenant2@thingsboard.org"); |
||||
|
tenantAdmin.setFirstName("Joe"); |
||||
|
tenantAdmin.setLastName("Downs"); |
||||
|
|
||||
|
createUserAndLogin(tenantAdmin, "testPassword1"); |
||||
|
} |
||||
|
|
||||
|
@After |
||||
|
public void afterTest() throws Exception { |
||||
|
executor.shutdownNow(); |
||||
|
|
||||
|
loginSysAdmin(); |
||||
|
|
||||
|
doDelete("/api/tenant/" + savedTenant.getId().getId()) |
||||
|
.andExpect(status().isOk()); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testFetchPublishTelemetryCommandsForDefaultDevice() throws Exception { |
||||
|
Device device = new Device(); |
||||
|
device.setName("My device"); |
||||
|
device.setType("default"); |
||||
|
Device savedDevice = doPost("/api/device", device, Device.class); |
||||
|
JsonNode commands = |
||||
|
doGetTyped("/api/device-connectivity/" + savedDevice.getId().getId(), new TypeReference<>() { |
||||
|
}); |
||||
|
|
||||
|
DeviceCredentials credentials = |
||||
|
doGet("/api/device/" + savedDevice.getId().getId() + "/credentials", DeviceCredentials.class); |
||||
|
|
||||
|
assertThat(commands).hasSize(1); |
||||
|
JsonNode httpCommands = commands.get(HTTP); |
||||
|
assertThat(httpCommands.get(HTTP).asText()).isEqualTo(String.format("curl -v -X POST http://localhost/api/v1/%s/telemetry " + |
||||
|
"--header Content-Type:application/json --data \"{temperature:25}\"", |
||||
|
credentials.getCredentialsId())); |
||||
|
assertThat(httpCommands.get(HTTPS).asText()).isEqualTo(String.format("curl -v -X POST https://localhost/api/v1/%s/telemetry " + |
||||
|
"--header Content-Type:application/json --data \"{temperature:25}\"", |
||||
|
credentials.getCredentialsId())); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,306 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge.rpc.processor; |
||||
|
|
||||
|
import org.junit.jupiter.params.provider.Arguments; |
||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.springframework.context.annotation.Lazy; |
||||
|
import org.thingsboard.server.cluster.TbClusterService; |
||||
|
import org.thingsboard.server.common.data.Dashboard; |
||||
|
import org.thingsboard.server.common.data.Device; |
||||
|
import org.thingsboard.server.common.data.DeviceProfile; |
||||
|
import org.thingsboard.server.common.data.EntityView; |
||||
|
import org.thingsboard.server.common.data.asset.Asset; |
||||
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEvent; |
||||
|
import org.thingsboard.server.common.data.id.DashboardId; |
||||
|
import org.thingsboard.server.common.data.id.EdgeId; |
||||
|
import org.thingsboard.server.common.data.id.RuleChainId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.dao.alarm.AlarmService; |
||||
|
import org.thingsboard.server.dao.asset.AssetProfileService; |
||||
|
import org.thingsboard.server.dao.asset.AssetService; |
||||
|
import org.thingsboard.server.dao.attributes.AttributesService; |
||||
|
import org.thingsboard.server.dao.customer.CustomerService; |
||||
|
import org.thingsboard.server.dao.dashboard.DashboardService; |
||||
|
import org.thingsboard.server.dao.device.DeviceCredentialsService; |
||||
|
import org.thingsboard.server.dao.device.DeviceProfileService; |
||||
|
import org.thingsboard.server.dao.device.DeviceService; |
||||
|
import org.thingsboard.server.dao.edge.EdgeEventService; |
||||
|
import org.thingsboard.server.dao.edge.EdgeService; |
||||
|
import org.thingsboard.server.dao.edge.EdgeSynchronizationManager; |
||||
|
import org.thingsboard.server.dao.entityview.EntityViewService; |
||||
|
import org.thingsboard.server.dao.ota.OtaPackageService; |
||||
|
import org.thingsboard.server.dao.queue.QueueService; |
||||
|
import org.thingsboard.server.dao.relation.RelationService; |
||||
|
import org.thingsboard.server.dao.rule.RuleChainService; |
||||
|
import org.thingsboard.server.dao.service.DataValidator; |
||||
|
import org.thingsboard.server.dao.tenant.TenantProfileService; |
||||
|
import org.thingsboard.server.dao.tenant.TenantService; |
||||
|
import org.thingsboard.server.dao.user.UserService; |
||||
|
import org.thingsboard.server.dao.widget.WidgetTypeService; |
||||
|
import org.thingsboard.server.dao.widget.WidgetsBundleService; |
||||
|
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
||||
|
import org.thingsboard.server.queue.discovery.PartitionService; |
||||
|
import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
||||
|
import org.thingsboard.server.queue.util.DataDecodingEncodingService; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.AdminSettingsMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.AlarmMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.AssetMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.AssetProfileMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.CustomerMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.DashboardMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.DeviceMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.DeviceProfileMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.EdgeMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.EntityDataMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.EntityViewMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.OtaPackageMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.QueueMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.RelationMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.RuleChainMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.TenantMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.TenantProfileMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.UserMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.WidgetTypeMsgConstructor; |
||||
|
import org.thingsboard.server.service.edge.rpc.constructor.WidgetsBundleMsgConstructor; |
||||
|
import org.thingsboard.server.service.entitiy.TbNotificationEntityService; |
||||
|
import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
||||
|
import org.thingsboard.server.service.profile.TbAssetProfileCache; |
||||
|
import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
||||
|
import org.thingsboard.server.service.state.DeviceStateService; |
||||
|
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
import java.util.stream.Stream; |
||||
|
|
||||
|
public abstract class BaseEdgeProcessorTest { |
||||
|
|
||||
|
@MockBean |
||||
|
protected TelemetrySubscriptionService tsSubService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TbNotificationEntityService notificationEntityService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected RuleChainService ruleChainService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected AlarmService alarmService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DeviceService deviceService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TbDeviceProfileCache deviceProfileCache; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TbAssetProfileCache assetProfileCache; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DashboardService dashboardService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected AssetService assetService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected EntityViewService entityViewService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TenantService tenantService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TenantProfileService tenantProfileService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected EdgeService edgeService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected CustomerService customerService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected UserService userService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DeviceProfileService deviceProfileService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected AssetProfileService assetProfileService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected RelationService relationService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DeviceCredentialsService deviceCredentialsService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected AttributesService attributesService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TbClusterService tbClusterService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DeviceStateService deviceStateService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected EdgeEventService edgeEventService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected WidgetsBundleService widgetsBundleService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected WidgetTypeService widgetTypeService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected OtaPackageService otaPackageService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected QueueService queueService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected PartitionService partitionService; |
||||
|
|
||||
|
@MockBean |
||||
|
@Lazy |
||||
|
protected TbQueueProducerProvider producerProvider; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DataValidator<Device> deviceValidator; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DataValidator<DeviceProfile> deviceProfileValidator; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DataValidator<Asset> assetValidator; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DataValidator<AssetProfile> assetProfileValidator; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DataValidator<Dashboard> dashboardValidator; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DataValidator<EntityView> entityViewValidator; |
||||
|
|
||||
|
@MockBean |
||||
|
protected EdgeMsgConstructor edgeMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected EntityDataMsgConstructor entityDataMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected RuleChainMsgConstructor ruleChainMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected AlarmMsgConstructor alarmMsgConstructor; |
||||
|
|
||||
|
@SpyBean |
||||
|
protected DeviceMsgConstructor deviceMsgConstructor; |
||||
|
|
||||
|
@SpyBean |
||||
|
protected AssetMsgConstructor assetMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected EntityViewMsgConstructor entityViewMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DashboardMsgConstructor dashboardMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected RelationMsgConstructor relationMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected UserMsgConstructor userMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected CustomerMsgConstructor customerMsgConstructor; |
||||
|
|
||||
|
@SpyBean |
||||
|
protected DeviceProfileMsgConstructor deviceProfileMsgConstructor; |
||||
|
|
||||
|
@SpyBean |
||||
|
protected AssetProfileMsgConstructor assetProfileMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TenantMsgConstructor tenantMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected TenantProfileMsgConstructor tenantProfileMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected WidgetsBundleMsgConstructor widgetsBundleMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected WidgetTypeMsgConstructor widgetTypeMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected AdminSettingsMsgConstructor adminSettingsMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected OtaPackageMsgConstructor otaPackageMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected QueueMsgConstructor queueMsgConstructor; |
||||
|
|
||||
|
@MockBean |
||||
|
protected EdgeSynchronizationManager edgeSynchronizationManager; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DbCallbackExecutorService dbCallbackExecutorService; |
||||
|
|
||||
|
@MockBean |
||||
|
protected DataDecodingEncodingService dataDecodingEncodingService; |
||||
|
|
||||
|
protected EdgeId edgeId; |
||||
|
protected TenantId tenantId; |
||||
|
protected EdgeEvent edgeEvent; |
||||
|
|
||||
|
protected DashboardId getDashboardId(long expectedDashboardIdMSB, long expectedDashboardIdLSB) { |
||||
|
DashboardId dashboardId; |
||||
|
if (expectedDashboardIdMSB != 0 && expectedDashboardIdLSB != 0) { |
||||
|
dashboardId = new DashboardId(new UUID(expectedDashboardIdMSB, expectedDashboardIdLSB)); |
||||
|
} else { |
||||
|
dashboardId = new DashboardId(UUID.randomUUID()); |
||||
|
} |
||||
|
return dashboardId; |
||||
|
} |
||||
|
|
||||
|
protected RuleChainId getRuleChainId(long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
RuleChainId ruleChainId; |
||||
|
if (expectedRuleChainIdMSB != 0 && expectedRuleChainIdLSB != 0) { |
||||
|
ruleChainId = new RuleChainId(new UUID(expectedRuleChainIdMSB, expectedRuleChainIdLSB)); |
||||
|
} else { |
||||
|
ruleChainId = new RuleChainId(UUID.randomUUID()); |
||||
|
} |
||||
|
return ruleChainId; |
||||
|
} |
||||
|
|
||||
|
protected static Stream<Arguments> provideParameters() { |
||||
|
UUID dashoboardUUID = UUID.randomUUID(); |
||||
|
UUID ruleChaindUUID = UUID.randomUUID(); |
||||
|
return Stream.of( |
||||
|
Arguments.of(EdgeVersion.V_3_3_0, 0, 0, 0, 0), |
||||
|
Arguments.of(EdgeVersion.V_3_3_3, 0, 0, 0, 0), |
||||
|
Arguments.of(EdgeVersion.V_3_4_0, 0, 0, 0, 0), |
||||
|
Arguments.of(EdgeVersion.V_3_6_0, |
||||
|
dashoboardUUID.getMostSignificantBits(), |
||||
|
dashoboardUUID.getLeastSignificantBits(), |
||||
|
ruleChaindUUID.getMostSignificantBits(), |
||||
|
ruleChaindUUID.getLeastSignificantBits()) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge.rpc.processor.asset; |
||||
|
|
||||
|
import org.assertj.core.api.Assertions; |
||||
|
import org.junit.jupiter.api.BeforeEach; |
||||
|
import org.thingsboard.server.common.data.asset.Asset; |
||||
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEvent; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
||||
|
import org.thingsboard.server.common.data.id.AssetId; |
||||
|
import org.thingsboard.server.common.data.id.AssetProfileId; |
||||
|
import org.thingsboard.server.common.data.id.DashboardId; |
||||
|
import org.thingsboard.server.common.data.id.EdgeId; |
||||
|
import org.thingsboard.server.common.data.id.RuleChainId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
||||
|
import org.thingsboard.server.service.edge.rpc.processor.BaseEdgeProcessorTest; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||
|
import static org.mockito.BDDMockito.willReturn; |
||||
|
|
||||
|
public abstract class AbstractAssetProcessorTest extends BaseEdgeProcessorTest { |
||||
|
|
||||
|
|
||||
|
protected AssetId assetId; |
||||
|
protected AssetProfileId assetProfileId; |
||||
|
protected AssetProfile assetProfile; |
||||
|
|
||||
|
@BeforeEach |
||||
|
public void setUp() { |
||||
|
edgeId = new EdgeId(UUID.randomUUID()); |
||||
|
tenantId = new TenantId(UUID.randomUUID()); |
||||
|
assetId = new AssetId(UUID.randomUUID()); |
||||
|
assetProfileId = new AssetProfileId(UUID.randomUUID()); |
||||
|
|
||||
|
assetProfile = new AssetProfile(); |
||||
|
assetProfile.setId(assetProfileId); |
||||
|
assetProfile.setName("AssetProfile"); |
||||
|
assetProfile.setDefault(true); |
||||
|
|
||||
|
Asset asset = new Asset(); |
||||
|
asset.setAssetProfileId(assetProfileId); |
||||
|
asset.setId(assetId); |
||||
|
asset.setName("Asset"); |
||||
|
asset.setType(assetProfile.getName()); |
||||
|
|
||||
|
edgeEvent = new EdgeEvent(); |
||||
|
edgeEvent.setTenantId(tenantId); |
||||
|
edgeEvent.setAction(EdgeEventActionType.ADDED); |
||||
|
|
||||
|
|
||||
|
willReturn(asset).given(assetService).findAssetById(tenantId, assetId); |
||||
|
willReturn(assetProfile).given(assetProfileService).findAssetProfileById(tenantId, assetProfileId); |
||||
|
} |
||||
|
|
||||
|
protected void updateAssetProfileDefaultFields(long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
DashboardId dashboardId = getDashboardId(expectedDashboardIdMSB, expectedDashboardIdLSB); |
||||
|
RuleChainId ruleChainId = getRuleChainId(expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
|
||||
|
assetProfile.setDefaultDashboardId(dashboardId); |
||||
|
assetProfile.setDefaultEdgeRuleChainId(ruleChainId); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
protected void verify(DownlinkMsg downlinkMsg, long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
AssetProfileUpdateMsg assetProfileUpdateMsg = downlinkMsg.getAssetProfileUpdateMsgList().get(0); |
||||
|
assertNotNull(assetProfileUpdateMsg); |
||||
|
Assertions.assertThat(assetProfileUpdateMsg.getDefaultDashboardIdMSB()).isEqualTo(expectedDashboardIdMSB); |
||||
|
Assertions.assertThat(assetProfileUpdateMsg.getDefaultDashboardIdLSB()).isEqualTo(expectedDashboardIdLSB); |
||||
|
Assertions.assertThat(assetProfileUpdateMsg.getDefaultRuleChainIdMSB()).isEqualTo(expectedRuleChainIdMSB); |
||||
|
Assertions.assertThat(assetProfileUpdateMsg.getDefaultRuleChainIdLSB()).isEqualTo(expectedRuleChainIdLSB); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge.rpc.processor.asset; |
||||
|
|
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.MethodSource; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
||||
|
|
||||
|
@SpringBootTest(classes = {AssetEdgeProcessor.class}) |
||||
|
class AssetEdgeProcessorTest extends AbstractAssetProcessorTest { |
||||
|
|
||||
|
@SpyBean |
||||
|
AssetEdgeProcessor assetEdgeProcessor; |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@MethodSource("provideParameters") |
||||
|
public void testAssetProfileDefaultFields_notSendToEdgeOlder3_6_0IfNotAssigned(EdgeVersion edgeVersion, long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
updateAssetProfileDefaultFields(expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
|
||||
|
edgeEvent.setEntityId(assetId.getId()); |
||||
|
|
||||
|
DownlinkMsg downlinkMsg = assetEdgeProcessor.convertAssetEventToDownlink(edgeEvent, edgeId, edgeVersion); |
||||
|
|
||||
|
verify(downlinkMsg, expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge.rpc.processor.asset; |
||||
|
|
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.MethodSource; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
||||
|
|
||||
|
@SpringBootTest(classes = {AssetProfileEdgeProcessor.class}) |
||||
|
class AssetProfileEdgeProcessorTest extends AbstractAssetProcessorTest{ |
||||
|
@SpyBean |
||||
|
AssetProfileEdgeProcessor assetProfileEdgeProcessor; |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@MethodSource("provideParameters") |
||||
|
public void testAssetProfileDefaultFields_notSendToEdgeOlder3_6_0IfNotAssigned(EdgeVersion edgeVersion, long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
|
||||
|
updateAssetProfileDefaultFields(expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
|
||||
|
edgeEvent.setEntityId(assetProfileId.getId()); |
||||
|
|
||||
|
DownlinkMsg downlinkMsg = assetProfileEdgeProcessor.convertAssetProfileEventToDownlink(edgeEvent, edgeId, edgeVersion); |
||||
|
|
||||
|
verify(downlinkMsg, expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,100 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge.rpc.processor.device; |
||||
|
|
||||
|
import org.assertj.core.api.Assertions; |
||||
|
import org.junit.jupiter.api.BeforeEach; |
||||
|
import org.thingsboard.server.common.data.Device; |
||||
|
import org.thingsboard.server.common.data.DeviceProfile; |
||||
|
import org.thingsboard.server.common.data.DeviceProfileType; |
||||
|
import org.thingsboard.server.common.data.DeviceTransportType; |
||||
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEvent; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
||||
|
import org.thingsboard.server.common.data.id.DashboardId; |
||||
|
import org.thingsboard.server.common.data.id.DeviceId; |
||||
|
import org.thingsboard.server.common.data.id.DeviceProfileId; |
||||
|
import org.thingsboard.server.common.data.id.EdgeId; |
||||
|
import org.thingsboard.server.common.data.id.RuleChainId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
||||
|
import org.thingsboard.server.service.edge.rpc.processor.BaseEdgeProcessorTest; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||
|
import static org.mockito.BDDMockito.willReturn; |
||||
|
|
||||
|
public abstract class AbstractDeviceProcessorTest extends BaseEdgeProcessorTest { |
||||
|
|
||||
|
protected DeviceId deviceId; |
||||
|
protected DeviceProfileId deviceProfileId; |
||||
|
protected DeviceProfile deviceProfile; |
||||
|
|
||||
|
@BeforeEach |
||||
|
public void setUp() { |
||||
|
edgeId = new EdgeId(UUID.randomUUID()); |
||||
|
tenantId = new TenantId(UUID.randomUUID()); |
||||
|
deviceId = new DeviceId(UUID.randomUUID()); |
||||
|
deviceProfileId = new DeviceProfileId(UUID.randomUUID()); |
||||
|
|
||||
|
deviceProfile = new DeviceProfile(); |
||||
|
deviceProfile.setId(deviceProfileId); |
||||
|
deviceProfile.setName("DeviceProfile"); |
||||
|
deviceProfile.setDefault(true); |
||||
|
deviceProfile.setType(DeviceProfileType.DEFAULT); |
||||
|
DeviceProfileData deviceProfileData = new DeviceProfileData(); |
||||
|
deviceProfile.setProfileData(deviceProfileData); |
||||
|
deviceProfile.setTransportType(DeviceTransportType.DEFAULT); |
||||
|
|
||||
|
Device device = new Device(); |
||||
|
device.setDeviceProfileId(deviceProfileId); |
||||
|
device.setId(deviceId); |
||||
|
device.setName("Device"); |
||||
|
device.setType(deviceProfile.getName()); |
||||
|
|
||||
|
edgeEvent = new EdgeEvent(); |
||||
|
edgeEvent.setTenantId(tenantId); |
||||
|
edgeEvent.setAction(EdgeEventActionType.ADDED); |
||||
|
|
||||
|
|
||||
|
willReturn(device).given(deviceService).findDeviceById(tenantId, deviceId); |
||||
|
willReturn(deviceProfile).given(deviceProfileService).findDeviceProfileById(tenantId, deviceProfileId); |
||||
|
willReturn(new byte[]{0x00}).given(dataDecodingEncodingService).encode(deviceProfileData); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
protected void updateDeviceProfileDefaultFields(long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
DashboardId dashboardId = getDashboardId(expectedDashboardIdMSB, expectedDashboardIdLSB); |
||||
|
RuleChainId ruleChainId = getRuleChainId(expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
|
||||
|
deviceProfile.setDefaultDashboardId(dashboardId); |
||||
|
deviceProfile.setDefaultEdgeRuleChainId(ruleChainId); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
protected void verify(DownlinkMsg downlinkMsg, long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
DeviceProfileUpdateMsg deviceProfileUpdateMsg = downlinkMsg.getDeviceProfileUpdateMsgList().get(0); |
||||
|
assertNotNull(deviceProfileUpdateMsg); |
||||
|
Assertions.assertThat(deviceProfileUpdateMsg.getDefaultDashboardIdMSB()).isEqualTo(expectedDashboardIdMSB); |
||||
|
Assertions.assertThat(deviceProfileUpdateMsg.getDefaultDashboardIdLSB()).isEqualTo(expectedDashboardIdLSB); |
||||
|
Assertions.assertThat(deviceProfileUpdateMsg.getDefaultRuleChainIdMSB()).isEqualTo(expectedRuleChainIdMSB); |
||||
|
Assertions.assertThat(deviceProfileUpdateMsg.getDefaultRuleChainIdLSB()).isEqualTo(expectedRuleChainIdLSB); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge.rpc.processor.device; |
||||
|
|
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.MethodSource; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
||||
|
|
||||
|
@SpringBootTest(classes = {DeviceEdgeProcessor.class}) |
||||
|
class DeviceEdgeProcessorTest extends AbstractDeviceProcessorTest { |
||||
|
|
||||
|
@SpyBean |
||||
|
DeviceEdgeProcessor deviceEdgeProcessor; |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@MethodSource("provideParameters") |
||||
|
public void testDeviceProfileDefaultFields_notSendToEdgeOlder3_6_0IfNotAssigned(EdgeVersion edgeVersion, long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
updateDeviceProfileDefaultFields(expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
edgeEvent.setEntityId(deviceId.getId()); |
||||
|
|
||||
|
DownlinkMsg downlinkMsg = deviceEdgeProcessor.convertDeviceEventToDownlink(edgeEvent, edgeId, edgeVersion); |
||||
|
|
||||
|
verify(downlinkMsg, expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge.rpc.processor.device; |
||||
|
|
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.MethodSource; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
||||
|
|
||||
|
|
||||
|
@SpringBootTest(classes = {DeviceProfileEdgeProcessor.class}) |
||||
|
class DeviceProfileEdgeProcessorTest extends AbstractDeviceProcessorTest { |
||||
|
|
||||
|
@SpyBean |
||||
|
DeviceProfileEdgeProcessor deviceProfileEdgeProcessor; |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@MethodSource("provideParameters") |
||||
|
public void testDeviceProfileDefaultFields_notSendToEdgeOlder3_6_0IfNotAssigned(EdgeVersion edgeVersion, long expectedDashboardIdMSB, long expectedDashboardIdLSB, |
||||
|
long expectedRuleChainIdMSB, long expectedRuleChainIdLSB) { |
||||
|
updateDeviceProfileDefaultFields(expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
|
||||
|
edgeEvent.setEntityId(deviceProfileId.getId()); |
||||
|
|
||||
|
DownlinkMsg downlinkMsg = deviceProfileEdgeProcessor.convertDeviceProfileEventToDownlink(edgeEvent, edgeId, edgeVersion); |
||||
|
|
||||
|
verify(downlinkMsg, expectedDashboardIdMSB, expectedDashboardIdLSB, expectedRuleChainIdMSB, expectedRuleChainIdLSB); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,119 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.junit.jupiter.api.BeforeEach; |
||||
|
import org.junit.jupiter.api.Test; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.common.data.id.RuleChainId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.rule.RuleChain; |
||||
|
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
||||
|
import org.thingsboard.server.dao.dashboard.DashboardService; |
||||
|
import org.thingsboard.server.dao.oauth2.OAuth2ConfigTemplateService; |
||||
|
import org.thingsboard.server.dao.resource.ResourceService; |
||||
|
import org.thingsboard.server.dao.rule.RuleChainService; |
||||
|
import org.thingsboard.server.dao.service.validator.RuleChainDataValidator; |
||||
|
import org.thingsboard.server.dao.tenant.TenantService; |
||||
|
import org.thingsboard.server.dao.usagerecord.ApiLimitService; |
||||
|
import org.thingsboard.server.dao.widget.WidgetTypeService; |
||||
|
import org.thingsboard.server.dao.widget.WidgetsBundleService; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.nio.file.Path; |
||||
|
import java.util.Collections; |
||||
|
import java.util.List; |
||||
|
import java.util.UUID; |
||||
|
|
||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
import static org.mockito.ArgumentMatchers.any; |
||||
|
import static org.mockito.BDDMockito.willReturn; |
||||
|
|
||||
|
@Slf4j |
||||
|
@SpringBootTest(classes = {InstallScripts.class, RuleChainDataValidator.class}) |
||||
|
class InstallScriptsTest { |
||||
|
|
||||
|
@MockBean |
||||
|
RuleChainService ruleChainService; |
||||
|
@MockBean |
||||
|
DashboardService dashboardService; |
||||
|
@MockBean |
||||
|
WidgetTypeService widgetTypeService; |
||||
|
@MockBean |
||||
|
WidgetsBundleService widgetsBundleService; |
||||
|
@MockBean |
||||
|
OAuth2ConfigTemplateService oAuth2TemplateService; |
||||
|
@MockBean |
||||
|
ResourceService resourceService; |
||||
|
@SpyBean |
||||
|
InstallScripts installScripts; |
||||
|
|
||||
|
@MockBean |
||||
|
TenantService tenantService; |
||||
|
@MockBean |
||||
|
ApiLimitService apiLimitService; |
||||
|
@SpyBean |
||||
|
RuleChainDataValidator ruleChainValidator; |
||||
|
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da")); |
||||
|
|
||||
|
@BeforeEach |
||||
|
void setUp() { |
||||
|
willReturn(true).given(tenantService).tenantExists(tenantId); |
||||
|
willReturn(true).given(apiLimitService).checkEntitiesLimit(any(), any()); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
void testDefaultRuleChainsTemplates() throws IOException { |
||||
|
Path dir = installScripts.getTenantRuleChainsDir(); |
||||
|
installScripts.findRuleChainsFromPath(dir) |
||||
|
.forEach(this::validateRuleChainTemplate); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
void testDefaultEdgeRuleChainsTemplates() throws IOException { |
||||
|
Path dir = installScripts.getEdgeRuleChainsDir(); |
||||
|
installScripts.findRuleChainsFromPath(dir) |
||||
|
.forEach(this::validateRuleChainTemplate); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
void testDeviceProfileDefaultRuleChainTemplate() { |
||||
|
validateRuleChainTemplate(installScripts.getDeviceProfileDefaultRuleChainTemplateFilePath()); |
||||
|
} |
||||
|
|
||||
|
private void validateRuleChainTemplate(Path templateFilePath) { |
||||
|
log.warn("validateRuleChainTemplate {}", templateFilePath); |
||||
|
JsonNode ruleChainJson = JacksonUtil.toJsonNode(templateFilePath.toFile()); |
||||
|
|
||||
|
RuleChain ruleChain = JacksonUtil.treeToValue(ruleChainJson.get("ruleChain"), RuleChain.class); |
||||
|
ruleChain.setTenantId(tenantId); |
||||
|
ruleChainValidator.validate(ruleChain, RuleChain::getTenantId); |
||||
|
ruleChain.setId(new RuleChainId(UUID.randomUUID())); |
||||
|
|
||||
|
RuleChainMetaData ruleChainMetaData = JacksonUtil.treeToValue(ruleChainJson.get("metadata"), RuleChainMetaData.class); |
||||
|
ruleChainMetaData.setRuleChainId(ruleChain.getId()); |
||||
|
List<Throwable> throwables = RuleChainDataValidator.validateMetaData(ruleChainMetaData); |
||||
|
|
||||
|
assertThat(throwables).as("templateFilePath " + templateFilePath) |
||||
|
.containsExactlyInAnyOrderElementsOf(Collections.emptyList()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.transport.snmp.config; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.transport.snmp.SnmpCommunicationSpec; |
||||
|
|
||||
|
public class ToServerRpcRequestSnmpCommunicationConfig extends MultipleMappingsSnmpCommunicationConfig { |
||||
|
|
||||
|
private static final long serialVersionUID = 4851028734093214L; |
||||
|
|
||||
|
@Override |
||||
|
public SnmpCommunicationSpec getSpec() { |
||||
|
return SnmpCommunicationSpec.TO_SERVER_RPC_REQUEST; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
package org.thingsboard.script.api.tbel; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import org.thingsboard.server.common.data.StringUtils; |
||||
|
|
||||
|
import java.time.format.FormatStyle; |
||||
|
import java.util.TimeZone; |
||||
|
|
||||
|
@NoArgsConstructor |
||||
|
@Data |
||||
|
class DateFormattingOptions { |
||||
|
private static final TimeZone DEFAULT_TZ = TimeZone.getDefault(); |
||||
|
|
||||
|
private String timeZone; |
||||
|
private String dateStyle; |
||||
|
private String timeStyle; |
||||
|
@Getter |
||||
|
private String pattern; |
||||
|
|
||||
|
public DateFormattingOptions(String timeZone) { |
||||
|
this.timeZone = timeZone; |
||||
|
} |
||||
|
|
||||
|
TimeZone getTimeZone() { |
||||
|
return StringUtils.isNotEmpty(timeZone) ? TimeZone.getTimeZone(timeZone) : TimeZone.getDefault(); |
||||
|
} |
||||
|
|
||||
|
FormatStyle getDateStyle() { |
||||
|
return getFormatStyle(dateStyle, FormatStyle.SHORT); |
||||
|
} |
||||
|
|
||||
|
FormatStyle getTimeStyle() { |
||||
|
return getFormatStyle(timeStyle, FormatStyle.MEDIUM); |
||||
|
} |
||||
|
|
||||
|
private static FormatStyle getFormatStyle(String style, FormatStyle defaultStyle) { |
||||
|
if (StringUtils.isNotEmpty(style)) { |
||||
|
try { |
||||
|
return FormatStyle.valueOf(style.toUpperCase()); |
||||
|
} catch (IllegalArgumentException e) { |
||||
|
return defaultStyle; |
||||
|
} |
||||
|
} else { |
||||
|
return defaultStyle; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
File diff suppressed because it is too large
Loading…
Reference in new issue