DataValidator: validateName renamed to validateString
This commit is contained in:
parent
e69009c112
commit
e36231364d
@ -86,7 +86,7 @@ public abstract class DataValidator<D extends BaseData<?>> {
|
||||
public void validateDelete(TenantId tenantId, EntityId entityId) {
|
||||
}
|
||||
|
||||
public void validateName(String exceptionPrefix, String name) {
|
||||
public void validateString(String exceptionPrefix, String name) {
|
||||
if (StringUtils.isEmpty(name) || name.trim().length() == 0) {
|
||||
throw new DataValidationException(exceptionPrefix + " should be specified!");
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public class AdminSettingsDataValidator extends DataValidator<AdminSettings> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, AdminSettings adminSettings) {
|
||||
validateName("Key", adminSettings.getKey());
|
||||
validateString("Key", adminSettings.getKey());
|
||||
if (adminSettings.getJsonValue() == null) {
|
||||
throw new DataValidationException("Json value should be specified!");
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ public class AlarmDataValidator extends DataValidator<Alarm> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, Alarm alarm) {
|
||||
validateName("Alarm type", alarm.getType());
|
||||
validateString("Alarm type", alarm.getType());
|
||||
if (alarm.getOriginator() == null) {
|
||||
throw new DataValidationException("Alarm originator should be specified!");
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public class AssetDataValidator extends DataValidator<Asset> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, Asset asset) {
|
||||
validateName("Asset name", asset.getName());
|
||||
validateString("Asset name", asset.getName());
|
||||
if (asset.getTenantId() == null) {
|
||||
throw new DataValidationException("Asset should be assigned to tenant!");
|
||||
} else {
|
||||
|
||||
@ -53,7 +53,7 @@ public class AssetProfileDataValidator extends DataValidator<AssetProfile> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, AssetProfile assetProfile) {
|
||||
validateName("Asset profile name", assetProfile.getName());
|
||||
validateString("Asset profile name", assetProfile.getName());
|
||||
if (assetProfile.getTenantId() == null) {
|
||||
throw new DataValidationException("Asset profile should be assigned to tenant!");
|
||||
} else {
|
||||
|
||||
@ -41,7 +41,7 @@ public abstract class BaseOtaPackageDataValidator<D extends BaseData<?>> extends
|
||||
private DeviceProfileDao deviceProfileDao;
|
||||
|
||||
protected void validateImpl(OtaPackageInfo otaPackageInfo) {
|
||||
validateName("OtaPackage title", otaPackageInfo.getTitle());
|
||||
validateString("OtaPackage title", otaPackageInfo.getTitle());
|
||||
|
||||
if (otaPackageInfo.getTenantId() == null) {
|
||||
throw new DataValidationException("OtaPackage should be assigned to tenant!");
|
||||
|
||||
@ -27,7 +27,7 @@ public class ComponentDescriptorDataValidator extends DataValidator<ComponentDes
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, ComponentDescriptor plugin) {
|
||||
validateName("Component name", plugin.getName());
|
||||
validateString("Component name", plugin.getName());
|
||||
if (plugin.getType() == null) {
|
||||
throw new DataValidationException("Component type should be specified!");
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public class CustomerDataValidator extends DataValidator<Customer> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, Customer customer) {
|
||||
validateName("Customer title", customer.getTitle());
|
||||
validateString("Customer title", customer.getTitle());
|
||||
if (customer.getTitle().equals(CustomerServiceImpl.PUBLIC_CUSTOMER_TITLE)) {
|
||||
throw new DataValidationException("'Public' title for customer is system reserved!");
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public class DashboardDataValidator extends DataValidator<Dashboard> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, Dashboard dashboard) {
|
||||
validateName("Dashboard title", dashboard.getTitle());
|
||||
validateString("Dashboard title", dashboard.getTitle());
|
||||
if (dashboard.getTenantId() == null) {
|
||||
throw new DataValidationException("Dashboard should be assigned to tenant!");
|
||||
} else {
|
||||
|
||||
@ -60,7 +60,7 @@ public class DeviceDataValidator extends AbstractHasOtaPackageValidator<Device>
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, Device device) {
|
||||
validateName("Device name", device.getName());
|
||||
validateString("Device name", device.getName());
|
||||
if (device.getTenantId() == null) {
|
||||
throw new DataValidationException("Device should be assigned to tenant!");
|
||||
} else {
|
||||
|
||||
@ -103,7 +103,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, DeviceProfile deviceProfile) {
|
||||
validateName("Device profile name", deviceProfile.getName());
|
||||
validateString("Device profile name", deviceProfile.getName());
|
||||
if (deviceProfile.getType() == null) {
|
||||
throw new DataValidationException("Device profile type should be specified!");
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ public class EdgeDataValidator extends DataValidator<Edge> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, Edge edge) {
|
||||
validateName("Edge name", edge.getName());
|
||||
validateName("Edge type", edge.getType());
|
||||
validateString("Edge name", edge.getName());
|
||||
validateString("Edge type", edge.getType());
|
||||
if (StringUtils.isEmpty(edge.getSecret())) {
|
||||
throw new DataValidationException("Edge secret should be specified!");
|
||||
}
|
||||
|
||||
@ -58,8 +58,8 @@ public class EntityViewDataValidator extends DataValidator<EntityView> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, EntityView entityView) {
|
||||
validateName("Entity view name", entityView.getName());
|
||||
validateName("Entity view type", entityView.getType());
|
||||
validateString("Entity view name", entityView.getName());
|
||||
validateString("Entity view type", entityView.getType());
|
||||
if (entityView.getTenantId() == null) {
|
||||
throw new DataValidationException("Entity view should be assigned to tenant!");
|
||||
} else {
|
||||
|
||||
@ -66,7 +66,7 @@ public class ResourceDataValidator extends DataValidator<TbResource> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, TbResource resource) {
|
||||
validateName("Resource title", resource.getTitle());
|
||||
validateString("Resource title", resource.getTitle());
|
||||
if (resource.getResourceType() == null) {
|
||||
throw new DataValidationException("Resource type should be specified!");
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ public class RuleChainDataValidator extends DataValidator<RuleChain> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, RuleChain ruleChain) {
|
||||
validateName("Rule chain name", ruleChain.getName());
|
||||
validateString("Rule chain name", ruleChain.getName());
|
||||
if (ruleChain.getType() == null) {
|
||||
ruleChain.setType(RuleChainType.CORE);
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ public class TenantDataValidator extends DataValidator<Tenant> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, Tenant tenant) {
|
||||
validateName("Tenant title", tenant.getTitle());
|
||||
validateString("Tenant title", tenant.getTitle());
|
||||
if (!StringUtils.isEmpty(tenant.getEmail())) {
|
||||
validateEmail(tenant.getEmail());
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ public class TenantProfileDataValidator extends DataValidator<TenantProfile> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, TenantProfile tenantProfile) {
|
||||
validateName("Tenant profile name", tenantProfile.getName());
|
||||
validateString("Tenant profile name", tenantProfile.getName());
|
||||
if (tenantProfile.getProfileData() == null) {
|
||||
throw new DataValidationException("Tenant profile data should be specified!");
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public class WidgetTypeDataValidator extends DataValidator<WidgetTypeDetails> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, WidgetTypeDetails widgetTypeDetails) {
|
||||
validateName("Widgets type name", widgetTypeDetails.getName());
|
||||
validateString("Widgets type name", widgetTypeDetails.getName());
|
||||
if (widgetTypeDetails.getDescriptor() == null || widgetTypeDetails.getDescriptor().size() == 0) {
|
||||
throw new DataValidationException("Widgets type descriptor can't be empty!");
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ public class WidgetsBundleDataValidator extends DataValidator<WidgetsBundle> {
|
||||
|
||||
@Override
|
||||
protected void validateDataImpl(TenantId tenantId, WidgetsBundle widgetsBundle) {
|
||||
validateName("Widgets bundle title", widgetsBundle.getTitle());
|
||||
validateString("Widgets bundle title", widgetsBundle.getTitle());
|
||||
if (widgetsBundle.getTenantId() == null) {
|
||||
widgetsBundle.setTenantId(TenantId.fromUUID(ModelConstants.NULL_UUID));
|
||||
}
|
||||
|
||||
@ -41,12 +41,12 @@ public class DataValidatorTest {
|
||||
"Gdy Pomorze nie pomoże, to pomoże może morze, a gdy morze nie pomoże, to pomoże może Gdańsk",
|
||||
})
|
||||
void validateName_thenOK(final String name) {
|
||||
dataValidator.validateName("Device name", name);
|
||||
dataValidator.validateName("Asset name", name);
|
||||
dataValidator.validateName("Asset profile name", name);
|
||||
dataValidator.validateName("Alarm type", name);
|
||||
dataValidator.validateName("Customer name", name);
|
||||
dataValidator.validateName("Tenant name", name);
|
||||
dataValidator.validateString("Device name", name);
|
||||
dataValidator.validateString("Asset name", name);
|
||||
dataValidator.validateString("Asset profile name", name);
|
||||
dataValidator.validateString("Alarm type", name);
|
||||
dataValidator.validateString("Customer name", name);
|
||||
dataValidator.validateString("Tenant name", name);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -57,11 +57,11 @@ public class DataValidatorTest {
|
||||
})
|
||||
void validateName_thenDataValidationException(final String name) {
|
||||
DataValidationException exception;
|
||||
exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateName("Asset name", name));
|
||||
exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateString("Asset name", name));
|
||||
log.warn("Exception message Asset name: {}", exception.getMessage());
|
||||
assertThat(exception.getMessage()).as("message Asset name").containsPattern("Asset name .*");
|
||||
|
||||
exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateName("Device name", name));
|
||||
exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateString("Device name", name));
|
||||
log.warn("Exception message Device name: {}", exception.getMessage());
|
||||
assertThat(exception.getMessage()).as("message Device name").containsPattern("Device name .*");
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class AdminSettingsDataValidatorTest {
|
||||
adminSettings.setJsonValue(JacksonUtil.toJsonNode("{}"));
|
||||
|
||||
validator.validateDataImpl(tenantId, adminSettings);
|
||||
verify(validator).validateName("Key", adminSettings.getKey());
|
||||
verify(validator).validateString("Key", adminSettings.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
@ -55,7 +55,7 @@ class AlarmDataValidatorTest {
|
||||
alarm.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, alarm);
|
||||
verify(validator).validateName("Alarm type", alarm.getType());
|
||||
verify(validator).validateString("Alarm type", alarm.getType());
|
||||
}
|
||||
|
||||
}
|
||||
@ -65,7 +65,7 @@ class AssetProfileDataValidatorTest {
|
||||
assetProfile.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, assetProfile);
|
||||
verify(validator).validateName("Asset profile name", assetProfile.getName());
|
||||
verify(validator).validateString("Asset profile name", assetProfile.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@ -54,7 +54,7 @@ class BaseOtaPackageDataValidatorTest {
|
||||
otaPackageInfo.setTenantId(tenantId);
|
||||
|
||||
validator.validateImpl(otaPackageInfo);
|
||||
verify(validator).validateName("OtaPackage title", otaPackageInfo.getTitle());
|
||||
verify(validator).validateString("OtaPackage title", otaPackageInfo.getTitle());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -38,6 +38,6 @@ class ComponentDescriptorDataValidatorTest {
|
||||
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());
|
||||
verify(validator).validateString("Component name", plugin.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ class CustomerDataValidatorTest {
|
||||
customer.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, customer);
|
||||
verify(validator).validateName("Customer title", customer.getTitle());
|
||||
verify(validator).validateString("Customer title", customer.getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ class DashboardDataValidatorTest {
|
||||
dashboard.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, dashboard);
|
||||
verify(validator).validateName("Dashboard title", dashboard.getTitle());
|
||||
verify(validator).validateString("Dashboard title", dashboard.getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ class DeviceProfileDataValidatorTest {
|
||||
deviceProfile.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, deviceProfile);
|
||||
verify(validator).validateName("Device profile name", deviceProfile.getName());
|
||||
verify(validator).validateString("Device profile name", deviceProfile.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -59,8 +59,8 @@ class EdgeDataValidatorTest {
|
||||
edge.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, edge);
|
||||
verify(validator).validateName("Edge name", edge.getName());
|
||||
verify(validator).validateName("Edge type", edge.getType());
|
||||
verify(validator).validateString("Edge name", edge.getName());
|
||||
verify(validator).validateString("Edge type", edge.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -57,8 +57,8 @@ class EntityViewDataValidatorTest {
|
||||
entityView.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, entityView);
|
||||
verify(validator).validateName("Entity view name", entityView.getName());
|
||||
verify(validator).validateName("Entity view type", entityView.getType());
|
||||
verify(validator).validateString("Entity view name", entityView.getName());
|
||||
verify(validator).validateString("Entity view type", entityView.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ class ResourceDataValidatorTest {
|
||||
resource.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, resource);
|
||||
verify(validator).validateName("Resource title", resource.getTitle());
|
||||
verify(validator).validateString("Resource title", resource.getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ class RuleChainDataValidatorTest {
|
||||
ruleChain.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, ruleChain);
|
||||
verify(validator).validateName("Rule chain name", ruleChain.getName());
|
||||
verify(validator).validateString("Rule chain name", ruleChain.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class TenantDataValidatorTest {
|
||||
tenant.setEmail("support@thingsboard.io");
|
||||
|
||||
validator.validateDataImpl(tenantId, tenant);
|
||||
verify(validator).validateName("Tenant title", tenant.getTitle());
|
||||
verify(validator).validateString("Tenant title", tenant.getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ class TenantProfileDataValidatorTest {
|
||||
tenantProfile.setProfileData(tenantProfileData);
|
||||
|
||||
validator.validateDataImpl(tenantId, tenantProfile);
|
||||
verify(validator).validateName("Tenant profile name", tenantProfile.getName());
|
||||
verify(validator).validateString("Tenant profile name", tenantProfile.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ class WidgetTypeDataValidatorTest {
|
||||
widgetTypeDetails.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, widgetTypeDetails);
|
||||
verify(validator).validateName("Widgets type name", widgetTypeDetails.getName());
|
||||
verify(validator).validateString("Widgets type name", widgetTypeDetails.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ class WidgetsBundleDataValidatorTest {
|
||||
widgetsBundle.setTenantId(tenantId);
|
||||
|
||||
validator.validateDataImpl(tenantId, widgetsBundle);
|
||||
verify(validator).validateName("Widgets bundle title", widgetsBundle.getTitle());
|
||||
verify(validator).validateString("Widgets bundle title", widgetsBundle.getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user