Browse Source

WidgetTypeDataValidator resolver merge conflicts

pull/9163/head
Sergey Matvienko 3 years ago
parent
commit
71434dbb46
  1. 6
      dao/src/main/java/org/thingsboard/server/dao/service/validator/AdminSettingsDataValidator.java
  2. 5
      dao/src/main/java/org/thingsboard/server/dao/service/validator/AlarmDataValidator.java
  3. 1
      dao/src/main/java/org/thingsboard/server/dao/service/validator/AssetDataValidator.java
  4. 4
      dao/src/main/java/org/thingsboard/server/dao/service/validator/AssetProfileDataValidator.java
  5. 13
      dao/src/main/java/org/thingsboard/server/dao/service/validator/BaseOtaPackageDataValidator.java
  6. 4
      dao/src/main/java/org/thingsboard/server/dao/service/validator/ComponentDescriptorDataValidator.java
  7. 4
      dao/src/main/java/org/thingsboard/server/dao/service/validator/CustomerDataValidator.java
  8. 9
      dao/src/main/java/org/thingsboard/server/dao/service/validator/DashboardDataValidator.java
  9. 1
      dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceDataValidator.java
  10. 4
      dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java
  11. 8
      dao/src/main/java/org/thingsboard/server/dao/service/validator/EdgeDataValidator.java
  12. 9
      dao/src/main/java/org/thingsboard/server/dao/service/validator/EntityViewDataValidator.java
  13. 4
      dao/src/main/java/org/thingsboard/server/dao/service/validator/ResourceDataValidator.java
  14. 5
      dao/src/main/java/org/thingsboard/server/dao/service/validator/RuleChainDataValidator.java
  15. 4
      dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantDataValidator.java
  16. 5
      dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java
  17. 6
      dao/src/main/java/org/thingsboard/server/dao/service/validator/WidgetTypeDataValidator.java
  18. 5
      dao/src/main/java/org/thingsboard/server/dao/service/validator/WidgetsBundleDataValidator.java
  19. 50
      dao/src/test/java/org/thingsboard/server/dao/service/validator/AdminSettingsDataValidatorTest.java
  20. 61
      dao/src/test/java/org/thingsboard/server/dao/service/validator/AlarmDataValidatorTest.java
  21. 71
      dao/src/test/java/org/thingsboard/server/dao/service/validator/AssetProfileDataValidatorTest.java
  22. 61
      dao/src/test/java/org/thingsboard/server/dao/service/validator/BaseOtaPackageDataValidatorTest.java
  23. 43
      dao/src/test/java/org/thingsboard/server/dao/service/validator/ComponentDescriptorDataValidatorTest.java
  24. 59
      dao/src/test/java/org/thingsboard/server/dao/service/validator/CustomerDataValidatorTest.java
  25. 56
      dao/src/test/java/org/thingsboard/server/dao/service/validator/DashboardDataValidatorTest.java
  26. 83
      dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java
  27. 66
      dao/src/test/java/org/thingsboard/server/dao/service/validator/EdgeDataValidatorTest.java
  28. 64
      dao/src/test/java/org/thingsboard/server/dao/service/validator/EntityViewDataValidatorTest.java
  29. 69
      dao/src/test/java/org/thingsboard/server/dao/service/validator/ResourceDataValidatorTest.java
  30. 64
      dao/src/test/java/org/thingsboard/server/dao/service/validator/RuleChainDataValidatorTest.java
  31. 49
      dao/src/test/java/org/thingsboard/server/dao/service/validator/TenantDataValidatorTest.java
  32. 56
      dao/src/test/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidatorTest.java
  33. 65
      dao/src/test/java/org/thingsboard/server/dao/service/validator/WidgetTypeDataValidatorTest.java
  34. 59
      dao/src/test/java/org/thingsboard/server/dao/service/validator/WidgetsBundleDataValidatorTest.java

6
dao/src/main/java/org/thingsboard/server/dao/service/validator/AdminSettingsDataValidator.java

@ -18,7 +18,6 @@ package org.thingsboard.server.dao.service.validator;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.service.DataValidator;
@ -49,12 +48,9 @@ public class AdminSettingsDataValidator extends DataValidator<AdminSettings> {
return existentAdminSettings;
}
@Override
protected void validateDataImpl(TenantId tenantId, AdminSettings adminSettings) {
if (StringUtils.isEmpty(adminSettings.getKey())) {
throw new DataValidationException("Key should be specified!");
}
validateName("Key", adminSettings.getKey());
if (adminSettings.getJsonValue() == null) {
throw new DataValidationException("Json value should be specified!");
}

5
dao/src/main/java/org/thingsboard/server/dao/service/validator/AlarmDataValidator.java

@ -17,7 +17,6 @@ package org.thingsboard.server.dao.service.validator;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.exception.DataValidationException;
@ -32,9 +31,7 @@ public class AlarmDataValidator extends DataValidator<Alarm> {
@Override
protected void validateDataImpl(TenantId tenantId, Alarm alarm) {
if (StringUtils.isEmpty(alarm.getType())) {
throw new DataValidationException("Alarm type should be specified!");
}
validateName("Alarm type", alarm.getType());
if (alarm.getOriginator() == null) {
throw new DataValidationException("Alarm originator should be specified!");
}

1
dao/src/main/java/org/thingsboard/server/dao/service/validator/AssetDataValidator.java

@ -20,7 +20,6 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;

4
dao/src/main/java/org/thingsboard/server/dao/service/validator/AssetProfileDataValidator.java

@ -53,9 +53,7 @@ public class AssetProfileDataValidator extends DataValidator<AssetProfile> {
@Override
protected void validateDataImpl(TenantId tenantId, AssetProfile assetProfile) {
if (StringUtils.isEmpty(assetProfile.getName())) {
throw new DataValidationException("Asset profile name should be specified!");
}
validateName("Asset profile name", assetProfile.getName());
if (assetProfile.getTenantId() == null) {
throw new DataValidationException("Asset profile should be assigned to tenant!");
} else {

13
dao/src/main/java/org/thingsboard/server/dao/service/validator/BaseOtaPackageDataValidator.java

@ -15,6 +15,7 @@
*/
package org.thingsboard.server.dao.service.validator;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.thingsboard.server.common.data.BaseData;
@ -31,23 +32,27 @@ import java.util.Objects;
public abstract class BaseOtaPackageDataValidator<D extends BaseData<?>> extends DataValidator<D> {
@Autowired
@Getter
@Lazy
private TenantService tenantService;
@Autowired
@Getter
private DeviceProfileDao deviceProfileDao;
protected void validateImpl(OtaPackageInfo otaPackageInfo) {
validateName("OtaPackage title", otaPackageInfo.getTitle());
if (otaPackageInfo.getTenantId() == null) {
throw new DataValidationException("OtaPackage should be assigned to tenant!");
} else {
if (!tenantService.tenantExists(otaPackageInfo.getTenantId())) {
if (!getTenantService().tenantExists(otaPackageInfo.getTenantId())) {
throw new DataValidationException("OtaPackage is referencing to non-existent tenant!");
}
}
if (otaPackageInfo.getDeviceProfileId() != null) {
DeviceProfile deviceProfile = deviceProfileDao.findById(otaPackageInfo.getTenantId(), otaPackageInfo.getDeviceProfileId().getId());
DeviceProfile deviceProfile = getDeviceProfileDao().findById(otaPackageInfo.getTenantId(), otaPackageInfo.getDeviceProfileId().getId());
if (deviceProfile == null) {
throw new DataValidationException("OtaPackage is referencing to non-existent device profile!");
}
@ -57,10 +62,6 @@ public abstract class BaseOtaPackageDataValidator<D extends BaseData<?>> extends
throw new DataValidationException("Type should be specified!");
}
if (StringUtils.isEmpty(otaPackageInfo.getTitle())) {
throw new DataValidationException("OtaPackage title should be specified!");
}
if (StringUtils.isEmpty(otaPackageInfo.getVersion())) {
throw new DataValidationException("OtaPackage version should be specified!");
}

4
dao/src/main/java/org/thingsboard/server/dao/service/validator/ComponentDescriptorDataValidator.java

@ -27,15 +27,13 @@ public class ComponentDescriptorDataValidator extends DataValidator<ComponentDes
@Override
protected void validateDataImpl(TenantId tenantId, ComponentDescriptor plugin) {
validateName("Component name", plugin.getName());
if (plugin.getType() == null) {
throw new DataValidationException("Component type should be specified!");
}
if (plugin.getScope() == null) {
throw new DataValidationException("Component scope should be specified!");
}
if (StringUtils.isEmpty(plugin.getName())) {
throw new DataValidationException("Component name should be specified!");
}
if (StringUtils.isEmpty(plugin.getClazz())) {
throw new DataValidationException("Component clazz should be specified!");
}

4
dao/src/main/java/org/thingsboard/server/dao/service/validator/CustomerDataValidator.java

@ -63,9 +63,7 @@ public class CustomerDataValidator extends DataValidator<Customer> {
@Override
protected void validateDataImpl(TenantId tenantId, Customer customer) {
if (StringUtils.isEmpty(customer.getTitle())) {
throw new DataValidationException("Customer title should be specified!");
}
validateName("Customer title", customer.getTitle());
if (customer.getTitle().equals(CustomerServiceImpl.PUBLIC_CUSTOMER_TITLE)) {
throw new DataValidationException("'Public' title for customer is system reserved!");
}

9
dao/src/main/java/org/thingsboard/server/dao/service/validator/DashboardDataValidator.java

@ -19,9 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.dashboard.DashboardDao;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.tenant.TenantService;
@ -29,9 +27,6 @@ import org.thingsboard.server.dao.tenant.TenantService;
@Component
public class DashboardDataValidator extends DataValidator<Dashboard> {
@Autowired
private DashboardDao dashboardDao;
@Autowired
private TenantService tenantService;
@ -42,9 +37,7 @@ public class DashboardDataValidator extends DataValidator<Dashboard> {
@Override
protected void validateDataImpl(TenantId tenantId, Dashboard dashboard) {
if (StringUtils.isEmpty(dashboard.getTitle())) {
throw new DataValidationException("Dashboard title should be specified!");
}
validateName("Dashboard title", dashboard.getTitle());
if (dashboard.getTenantId() == null) {
throw new DataValidationException("Dashboard should be assigned to tenant!");
} else {

1
dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceDataValidator.java

@ -20,7 +20,6 @@ import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.device.data.DeviceTransportConfiguration;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;

4
dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java

@ -103,9 +103,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
@Override
protected void validateDataImpl(TenantId tenantId, DeviceProfile deviceProfile) {
if (StringUtils.isEmpty(deviceProfile.getName())) {
throw new DataValidationException("Device profile name should be specified!");
}
validateName("Device profile name", deviceProfile.getName());
if (deviceProfile.getType() == null) {
throw new DataValidationException("Device profile type should be specified!");
}

8
dao/src/main/java/org/thingsboard/server/dao/service/validator/EdgeDataValidator.java

@ -49,12 +49,8 @@ public class EdgeDataValidator extends DataValidator<Edge> {
@Override
protected void validateDataImpl(TenantId tenantId, Edge edge) {
if (StringUtils.isEmpty(edge.getType())) {
throw new DataValidationException("Edge type should be specified!");
}
if (StringUtils.isEmpty(edge.getName())) {
throw new DataValidationException("Edge name should be specified!");
}
validateName("Edge name", edge.getName());
validateName("Edge type", edge.getType());
if (StringUtils.isEmpty(edge.getSecret())) {
throw new DataValidationException("Edge secret should be specified!");
}

9
dao/src/main/java/org/thingsboard/server/dao/service/validator/EntityViewDataValidator.java

@ -19,7 +19,6 @@ import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.customer.CustomerDao;
@ -59,12 +58,8 @@ public class EntityViewDataValidator extends DataValidator<EntityView> {
@Override
protected void validateDataImpl(TenantId tenantId, EntityView entityView) {
if (StringUtils.isEmpty(entityView.getType())) {
throw new DataValidationException("Entity View type should be specified!");
}
if (StringUtils.isEmpty(entityView.getName())) {
throw new DataValidationException("Entity view name should be specified!");
}
validateName("Entity view name", entityView.getName());
validateName("Entity view type", entityView.getType());
if (entityView.getTenantId() == null) {
throw new DataValidationException("Entity view should be assigned to tenant!");
} else {

4
dao/src/main/java/org/thingsboard/server/dao/service/validator/ResourceDataValidator.java

@ -66,9 +66,7 @@ public class ResourceDataValidator extends DataValidator<TbResource> {
@Override
protected void validateDataImpl(TenantId tenantId, TbResource resource) {
if (StringUtils.isEmpty(resource.getTitle())) {
throw new DataValidationException("Resource title should be specified!");
}
validateName("Resource title", resource.getTitle());
if (resource.getResourceType() == null) {
throw new DataValidationException("Resource type should be specified!");
}

5
dao/src/main/java/org/thingsboard/server/dao/service/validator/RuleChainDataValidator.java

@ -23,7 +23,6 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.rule.NodeConnectionInfo;
import org.thingsboard.server.common.data.rule.RuleChain;
@ -65,9 +64,7 @@ public class RuleChainDataValidator extends DataValidator<RuleChain> {
@Override
protected void validateDataImpl(TenantId tenantId, RuleChain ruleChain) {
if (StringUtils.isEmpty(ruleChain.getName())) {
throw new DataValidationException("Rule chain name should be specified!");
}
validateName("Rule chain name", ruleChain.getName());
if (ruleChain.getType() == null) {
ruleChain.setType(RuleChainType.CORE);
}

4
dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantDataValidator.java

@ -32,9 +32,7 @@ public class TenantDataValidator extends DataValidator<Tenant> {
@Override
protected void validateDataImpl(TenantId tenantId, Tenant tenant) {
if (StringUtils.isEmpty(tenant.getTitle())) {
throw new DataValidationException("Tenant title should be specified!");
}
validateName("Tenant title", tenant.getTitle());
if (!StringUtils.isEmpty(tenant.getEmail())) {
validateEmail(tenant.getEmail());
}

5
dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java

@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.TenantProfile;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.queue.ProcessingStrategy;
@ -48,9 +47,7 @@ public class TenantProfileDataValidator extends DataValidator<TenantProfile> {
@Override
protected void validateDataImpl(TenantId tenantId, TenantProfile tenantProfile) {
if (StringUtils.isEmpty(tenantProfile.getName())) {
throw new DataValidationException("Tenant profile name should be specified!");
}
validateName("Tenant profile name", tenantProfile.getName());
if (tenantProfile.getProfileData() == null) {
throw new DataValidationException("Tenant profile data should be specified!");
}

6
dao/src/main/java/org/thingsboard/server/dao/service/validator/WidgetTypeDataValidator.java

@ -17,7 +17,6 @@ package org.thingsboard.server.dao.service.validator;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
@ -39,9 +38,8 @@ public class WidgetTypeDataValidator extends DataValidator<WidgetTypeDetails> {
@Override
protected void validateDataImpl(TenantId tenantId, WidgetTypeDetails widgetTypeDetails) {
if (StringUtils.isEmpty(widgetTypeDetails.getName())) {
throw new DataValidationException("Widgets type name should be specified!");
}
validateName("Widgets type name", widgetTypeDetails.getName());
validateName("Widgets type bundle alias", widgetTypeDetails.getBundleAlias());
if (widgetTypeDetails.getDescriptor() == null || widgetTypeDetails.getDescriptor().size() == 0) {
throw new DataValidationException("Widgets type descriptor can't be empty!");
}

5
dao/src/main/java/org/thingsboard/server/dao/service/validator/WidgetsBundleDataValidator.java

@ -17,7 +17,6 @@ package org.thingsboard.server.dao.service.validator;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.exception.DataValidationException;
@ -35,9 +34,7 @@ public class WidgetsBundleDataValidator extends DataValidator<WidgetsBundle> {
@Override
protected void validateDataImpl(TenantId tenantId, WidgetsBundle widgetsBundle) {
if (StringUtils.isEmpty(widgetsBundle.getTitle())) {
throw new DataValidationException("Widgets bundle title should be specified!");
}
validateName("Widgets bundle title", widgetsBundle.getTitle());
if (widgetsBundle.getTenantId() == null) {
widgetsBundle.setTenantId(TenantId.fromUUID(ModelConstants.NULL_UUID));
}

50
dao/src/test/java/org/thingsboard/server/dao/service/validator/AdminSettingsDataValidatorTest.java

@ -0,0 +1,50 @@
/**
* 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.dao.service.validator;
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.AdminSettings;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.settings.AdminSettingsService;
import java.util.UUID;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = AdminSettingsDataValidator.class)
class AdminSettingsDataValidatorTest {
@MockBean
AdminSettingsService adminSettingsService;
@SpyBean
AdminSettingsDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@Test
void testValidateNameInvocation() {
AdminSettings adminSettings = new AdminSettings();
adminSettings.setKey("jwt");
adminSettings.setJsonValue(JacksonUtil.toJsonNode("{}"));
validator.validateDataImpl(tenantId, adminSettings);
verify(validator).validateName("Key", adminSettings.getKey());
}
}

61
dao/src/test/java/org/thingsboard/server/dao/service/validator/AlarmDataValidatorTest.java

@ -0,0 +1,61 @@
/**
* 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.dao.service.validator;
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.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmSeverity;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = AlarmDataValidator.class)
class AlarmDataValidatorTest {
@MockBean
TenantService tenantService;
@SpyBean
AlarmDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
Alarm alarm = new Alarm();
alarm.setType("overheating");
alarm.setOriginator(tenantId);
alarm.setSeverity(AlarmSeverity.CRITICAL);
alarm.setCleared(false);
alarm.setAcknowledged(false);
alarm.setTenantId(tenantId);
validator.validateDataImpl(tenantId, alarm);
verify(validator).validateName("Alarm type", alarm.getType());
}
}

71
dao/src/test/java/org/thingsboard/server/dao/service/validator/AssetProfileDataValidatorTest.java

@ -0,0 +1,71 @@
/**
* 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.dao.service.validator;
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.server.common.data.asset.AssetProfile;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.asset.AssetProfileDao;
import org.thingsboard.server.dao.asset.AssetProfileService;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = AssetProfileDataValidator.class)
class AssetProfileDataValidatorTest {
@MockBean
AssetProfileDao assetProfileDao;
@MockBean
AssetProfileService assetProfileService;
@MockBean
TenantService tenantService;
@MockBean
QueueService queueService;
@MockBean
RuleChainService ruleChainService;
@MockBean
DashboardService dashboardService;
@SpyBean
AssetProfileDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
AssetProfile assetProfile = new AssetProfile();
assetProfile.setName("prod");
assetProfile.setTenantId(tenantId);
validator.validateDataImpl(tenantId, assetProfile);
verify(validator).validateName("Asset profile name", assetProfile.getName());
}
}

61
dao/src/test/java/org/thingsboard/server/dao/service/validator/BaseOtaPackageDataValidatorTest.java

@ -0,0 +1,61 @@
/**
* 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.dao.service.validator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.thingsboard.server.common.data.OtaPackageInfo;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.ota.OtaPackageType;
import org.thingsboard.server.dao.device.DeviceProfileDao;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
class BaseOtaPackageDataValidatorTest {
DeviceProfileDao deviceProfileDao = mock(DeviceProfileDao.class);
TenantService tenantService = mock(TenantService.class);
BaseOtaPackageDataValidator<?> validator = spy(BaseOtaPackageDataValidator.class);
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
willReturn(tenantService).given(validator).getTenantService();
willReturn(deviceProfileDao).given(validator).getDeviceProfileDao();
}
@Test
void testValidateNameInvocation() {
OtaPackageInfo otaPackageInfo = new OtaPackageInfo();
otaPackageInfo.setTitle("fw");
otaPackageInfo.setVersion("1.0");
otaPackageInfo.setType(OtaPackageType.FIRMWARE);
otaPackageInfo.setTenantId(tenantId);
validator.validateImpl(otaPackageInfo);
verify(validator).validateName("OtaPackage title", otaPackageInfo.getTitle());
}
}

43
dao/src/test/java/org/thingsboard/server/dao/service/validator/ComponentDescriptorDataValidatorTest.java

@ -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.dao.service.validator;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
import org.thingsboard.server.common.data.plugin.ComponentScope;
import org.thingsboard.server.common.data.plugin.ComponentType;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = ComponentDescriptorDataValidator.class)
class ComponentDescriptorDataValidatorTest {
@SpyBean
ComponentDescriptorDataValidator validator;
@Test
void testValidateNameInvocation() {
ComponentDescriptor plugin = new ComponentDescriptor();
plugin.setType(ComponentType.ENRICHMENT);
plugin.setScope(ComponentScope.SYSTEM);
plugin.setName("originator attributes");
plugin.setClazz("org.thingsboard.rule.engine.metadata.TbGetAttributesNode");
validator.validateDataImpl(TenantId.SYS_TENANT_ID, plugin);
verify(validator).validateName("Component name", plugin.getName());
}
}

59
dao/src/test/java/org/thingsboard/server/dao/service/validator/CustomerDataValidatorTest.java

@ -0,0 +1,59 @@
/**
* 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.dao.service.validator;
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.server.common.data.Customer;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.customer.CustomerDao;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = CustomerDataValidator.class)
class CustomerDataValidatorTest {
@MockBean
CustomerDao customerDao;
@MockBean
TenantService tenantService;
@SpyBean
CustomerDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
Customer customer = new Customer();
customer.setTitle("Customer A");
customer.setTenantId(tenantId);
validator.validateDataImpl(tenantId, customer);
verify(validator).validateName("Customer title", customer.getTitle());
}
}

56
dao/src/test/java/org/thingsboard/server/dao/service/validator/DashboardDataValidatorTest.java

@ -0,0 +1,56 @@
/**
* 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.dao.service.validator;
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.server.common.data.Dashboard;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = DashboardDataValidator.class)
class DashboardDataValidatorTest {
@MockBean
TenantService tenantService;
@SpyBean
DashboardDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
Dashboard dashboard = new Dashboard();
dashboard.setTitle("flight control");
dashboard.setTenantId(tenantId);
validator.validateDataImpl(tenantId, dashboard);
verify(validator).validateName("Dashboard title", dashboard.getTitle());
}
}

83
dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java

@ -0,0 +1,83 @@
/**
* 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.dao.service.validator;
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.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.DefaultDeviceProfileTransportConfiguration;
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceDao;
import org.thingsboard.server.dao.device.DeviceProfileDao;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = DeviceProfileDataValidator.class)
class DeviceProfileDataValidatorTest {
@MockBean
DeviceProfileDao deviceProfileDao;
@MockBean
DeviceProfileService deviceProfileService;
@MockBean
DeviceDao deviceDao;
@MockBean
TenantService tenantService;
@MockBean
QueueService queueService;
@MockBean
RuleChainService ruleChainService;
@MockBean
DashboardService dashboardService;
@SpyBean
DeviceProfileDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
DeviceProfile deviceProfile = new DeviceProfile();
deviceProfile.setName("default");
deviceProfile.setType(DeviceProfileType.DEFAULT);
deviceProfile.setTransportType(DeviceTransportType.DEFAULT);
DeviceProfileData data = new DeviceProfileData();
data.setTransportConfiguration(new DefaultDeviceProfileTransportConfiguration());
deviceProfile.setProfileData(data);
deviceProfile.setTenantId(tenantId);
validator.validateDataImpl(tenantId, deviceProfile);
verify(validator).validateName("Device profile name", deviceProfile.getName());
}
}

66
dao/src/test/java/org/thingsboard/server/dao/service/validator/EdgeDataValidatorTest.java

@ -0,0 +1,66 @@
/**
* 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.dao.service.validator;
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.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.customer.CustomerDao;
import org.thingsboard.server.dao.edge.EdgeDao;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = EdgeDataValidator.class)
class EdgeDataValidatorTest {
@MockBean
EdgeDao edgeDao;
@MockBean
TenantService tenantService;
@MockBean
CustomerDao customerDao;
@SpyBean
EdgeDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
Edge edge = new Edge();
edge.setName("Edge 007");
edge.setType("Silos");
edge.setSecret("secret");
edge.setRoutingKey("53c56104-d302-4d6e-97f5-a7a99c7effdc");
edge.setTenantId(tenantId);
validator.validateDataImpl(tenantId, edge);
verify(validator).validateName("Edge name", edge.getName());
verify(validator).validateName("Edge type", edge.getType());
}
}

64
dao/src/test/java/org/thingsboard/server/dao/service/validator/EntityViewDataValidatorTest.java

@ -0,0 +1,64 @@
/**
* 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.dao.service.validator;
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.server.common.data.EntityView;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.customer.CustomerDao;
import org.thingsboard.server.dao.entityview.EntityViewDao;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = EntityViewDataValidator.class)
class EntityViewDataValidatorTest {
@MockBean
EntityViewDao entityViewDao;
@MockBean
TenantService tenantService;
@MockBean
CustomerDao customerDao;
@SpyBean
EntityViewDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
EntityView entityView = new EntityView();
entityView.setName("view");
entityView.setType("default");
entityView.setTenantId(tenantId);
validator.validateDataImpl(tenantId, entityView);
verify(validator).validateName("Entity view name", entityView.getName());
verify(validator).validateName("Entity view type", entityView.getType());
}
}

69
dao/src/test/java/org/thingsboard/server/dao/service/validator/ResourceDataValidatorTest.java

@ -0,0 +1,69 @@
/**
* 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.dao.service.validator;
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.server.common.data.ResourceType;
import org.thingsboard.server.common.data.TbResource;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.resource.TbResourceDao;
import org.thingsboard.server.dao.tenant.TbTenantProfileCache;
import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.widget.WidgetTypeDao;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = ResourceDataValidator.class)
class ResourceDataValidatorTest {
@MockBean
TbResourceDao resourceDao;
@MockBean
WidgetTypeDao widgetTypeDao;
@MockBean
TenantService tenantService;
@MockBean
TbTenantProfileCache tenantProfileCache;
@SpyBean
ResourceDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
TbResource resource = new TbResource();
resource.setTitle("rss");
resource.setResourceType(ResourceType.PKCS_12);
resource.setFileName("cert.pem");
resource.setResourceKey("19_1.0");
resource.setTenantId(tenantId);
validator.validateDataImpl(tenantId, resource);
verify(validator).validateName("Resource title", resource.getTitle());
}
}

64
dao/src/test/java/org/thingsboard/server/dao/service/validator/RuleChainDataValidatorTest.java

@ -0,0 +1,64 @@
/**
* 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.dao.service.validator;
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.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.dao.rule.RuleChainDao;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.tenant.TenantService;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = RuleChainDataValidator.class)
class RuleChainDataValidatorTest {
@MockBean
RuleChainDao ruleChainDao;
@MockBean
RuleChainService ruleChainService;
@MockBean
TenantService tenantService;
@SpyBean
RuleChainDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
RuleChain ruleChain = new RuleChain();
ruleChain.setName("generate daily report");
ruleChain.setType(RuleChainType.CORE);
ruleChain.setTenantId(tenantId);
validator.validateDataImpl(tenantId, ruleChain);
verify(validator).validateName("Rule chain name", ruleChain.getName());
}
}

49
dao/src/test/java/org/thingsboard/server/dao/service/validator/TenantDataValidatorTest.java

@ -0,0 +1,49 @@
/**
* 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.dao.service.validator;
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.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.tenant.TenantDao;
import java.util.UUID;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = TenantDataValidator.class)
class TenantDataValidatorTest {
@MockBean
TenantDao tenantDao;
@SpyBean
TenantDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@Test
void testValidateNameInvocation() {
Tenant tenant = new Tenant();
tenant.setTitle("Monster corporation ©");
tenant.setEmail("support@thingsboard.io");
validator.validateDataImpl(tenantId, tenant);
verify(validator).validateName("Tenant title", tenant.getTitle());
}
}

56
dao/src/test/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidatorTest.java

@ -0,0 +1,56 @@
/**
* 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.dao.service.validator;
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.server.common.data.TenantProfile;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
import org.thingsboard.server.common.data.tenant.profile.TenantProfileData;
import org.thingsboard.server.dao.tenant.TenantProfileDao;
import org.thingsboard.server.dao.tenant.TenantProfileService;
import java.util.UUID;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = TenantProfileDataValidator.class)
class TenantProfileDataValidatorTest {
@MockBean
TenantProfileDao tenantProfileDao;
@MockBean
TenantProfileService tenantProfileService;
@SpyBean
TenantProfileDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@Test
void testValidateNameInvocation() {
TenantProfile tenantProfile = new TenantProfile();
tenantProfile.setName("Sandbox");
TenantProfileData tenantProfileData = new TenantProfileData();
tenantProfileData.setConfiguration(new DefaultTenantProfileConfiguration());
tenantProfile.setProfileData(tenantProfileData);
validator.validateDataImpl(tenantId, tenantProfile);
verify(validator).validateName("Tenant profile name", tenantProfile.getName());
}
}

65
dao/src/test/java/org/thingsboard/server/dao/service/validator/WidgetTypeDataValidatorTest.java

@ -0,0 +1,65 @@
/**
* 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.dao.service.validator;
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.TenantId;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.widget.WidgetTypeDao;
import org.thingsboard.server.dao.widget.WidgetsBundleDao;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = WidgetTypeDataValidator.class)
class WidgetTypeDataValidatorTest {
@MockBean
WidgetTypeDao widgetTypeDao;
@MockBean
WidgetsBundleDao widgetsBundleDao;
@MockBean
TenantService tenantService;
@SpyBean
WidgetTypeDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
WidgetTypeDetails widgetTypeDetails = new WidgetTypeDetails();
widgetTypeDetails.setName("widget type gas");
widgetTypeDetails.setBundleAlias("Widget bundle fuel");
widgetTypeDetails.setDescriptor(JacksonUtil.toJsonNode("{\"content\":\"empty\"}"));
widgetTypeDetails.setTenantId(tenantId);
validator.validateDataImpl(tenantId, widgetTypeDetails);
verify(validator).validateName("Widgets type name", widgetTypeDetails.getName());
verify(validator).validateName("Widgets type bundle alias", widgetTypeDetails.getBundleAlias());
}
}

59
dao/src/test/java/org/thingsboard/server/dao/service/validator/WidgetsBundleDataValidatorTest.java

@ -0,0 +1,59 @@
/**
* 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.dao.service.validator;
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.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.widget.WidgetsBundleDao;
import java.util.UUID;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
@SpringBootTest(classes = WidgetsBundleDataValidator.class)
class WidgetsBundleDataValidatorTest {
@MockBean
WidgetsBundleDao widgetsBundleDao;
@MockBean
TenantService tenantService;
@SpyBean
WidgetsBundleDataValidator validator;
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da"));
@BeforeEach
void setUp() {
willReturn(true).given(tenantService).tenantExists(tenantId);
}
@Test
void testValidateNameInvocation() {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTitle("my fancy WB");
widgetsBundle.setTenantId(tenantId);
validator.validateDataImpl(tenantId, widgetsBundle);
verify(validator).validateName("Widgets bundle title", widgetsBundle.getTitle());
}
}
Loading…
Cancel
Save