Browse Source
[3.5.2] Device Asset name - Validate contains0x00 to prevent PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00pull/9198/head
committed by
GitHub
44 changed files with 1340 additions and 126 deletions
@ -0,0 +1,40 @@ |
|||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.ValueSource; |
||||
|
|
||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
|
||||
|
class StringUtilsTest { |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@ValueSource(strings = { |
||||
|
"\000", "\u0000", " \000", " \000 ", "\000 ", "\000\000", "\000 \000", |
||||
|
"世\000界", "F0929906\000\000\000\000\000\000\000\000\000", |
||||
|
}) |
||||
|
void testContains0x00_thenTrue(String sample) { |
||||
|
assertThat(StringUtils.contains0x00(sample)).isTrue(); |
||||
|
} |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@ValueSource(strings = {"", " ", "abc", "世界", "\001", "\uD83D\uDC0C"}) |
||||
|
void testContains0x00_thenFalse(String sample) { |
||||
|
assertThat(StringUtils.contains0x00(sample)).isFalse(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Key", adminSettings.getKey()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Alarm type", alarm.getType()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
/** |
||||
|
* 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 lombok.extern.slf4j.Slf4j; |
||||
|
import org.junit.jupiter.api.Assertions; |
||||
|
import org.junit.jupiter.api.BeforeEach; |
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.ValueSource; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||
|
import org.thingsboard.server.common.data.asset.Asset; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.dao.asset.AssetDao; |
||||
|
import org.thingsboard.server.dao.customer.CustomerDao; |
||||
|
import org.thingsboard.server.dao.exception.DataValidationException; |
||||
|
import org.thingsboard.server.dao.tenant.TenantService; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
import static org.mockito.BDDMockito.willReturn; |
||||
|
|
||||
|
@SpringBootTest(classes = AssetDataValidator.class) |
||||
|
@Slf4j |
||||
|
class AssetDataValidatorTest { |
||||
|
|
||||
|
@MockBean |
||||
|
AssetDao assetDao; |
||||
|
@MockBean |
||||
|
TenantService tenantService; |
||||
|
@MockBean |
||||
|
CustomerDao customerDao; |
||||
|
@Autowired |
||||
|
AssetDataValidator validator; |
||||
|
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da")); |
||||
|
|
||||
|
@BeforeEach |
||||
|
void setUp() { |
||||
|
willReturn(true).given(tenantService).tenantExists(tenantId); |
||||
|
} |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@ValueSource(strings = { |
||||
|
"coffee", "1", "big box", "世界", "!", "--", "~!@#$%^&*()_+=-/|\\[]{};:'`\"?<>,.", "\uD83D\uDC0C", "\041", |
||||
|
"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 testAssetName_thenOK(final String name) { |
||||
|
Asset asset = new Asset(); |
||||
|
asset.setTenantId(tenantId); |
||||
|
asset.setName(name); |
||||
|
validator.validateDataImpl(tenantId, asset); |
||||
|
} |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@ValueSource(strings = { |
||||
|
"", " ", " ", "\n", "\r\n", "\t", "\000", "\000\000", "\001", "\002", "\040", "\u0000", "\u0000\u0000", |
||||
|
"F0929906\000\000\000\000\000\000\000\000\000", "\000\000\000F0929906", |
||||
|
"\u0000F0929906", "F092\u00009906", "F0929906\u0000" |
||||
|
}) |
||||
|
void testAssetName_thenDataValidationException(final String name) { |
||||
|
Asset asset = new Asset(); |
||||
|
asset.setTenantId(tenantId); |
||||
|
asset.setName(name); |
||||
|
|
||||
|
DataValidationException exception = Assertions.assertThrows(DataValidationException.class, () -> validator.validateDataImpl(tenantId, asset)); |
||||
|
log.warn("Exception message: {}", exception.getMessage()); |
||||
|
assertThat(exception.getMessage()).as("message Asset name").containsPattern("Asset name .*"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Asset profile name", assetProfile.getName()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("OtaPackage title", otaPackageInfo.getTitle()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -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).validateString("Component name", plugin.getName()); |
||||
|
} |
||||
|
} |
||||
@ -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).validateString("Customer title", customer.getTitle()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Dashboard title", dashboard.getTitle()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
/** |
||||
|
* 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 lombok.extern.slf4j.Slf4j; |
||||
|
import org.junit.jupiter.api.Assertions; |
||||
|
import org.junit.jupiter.api.BeforeEach; |
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.ValueSource; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||
|
import org.thingsboard.server.common.data.Device; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.dao.customer.CustomerDao; |
||||
|
import org.thingsboard.server.dao.device.DeviceDao; |
||||
|
import org.thingsboard.server.dao.exception.DataValidationException; |
||||
|
import org.thingsboard.server.dao.tenant.TenantService; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
import static org.mockito.BDDMockito.willReturn; |
||||
|
|
||||
|
@SpringBootTest(classes = DeviceDataValidator.class) |
||||
|
@Slf4j |
||||
|
class DeviceDataValidatorTest { |
||||
|
|
||||
|
@MockBean |
||||
|
DeviceDao deviceDao; |
||||
|
@MockBean |
||||
|
TenantService tenantService; |
||||
|
@MockBean |
||||
|
CustomerDao customerDao; |
||||
|
@Autowired |
||||
|
DeviceDataValidator validator; |
||||
|
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da")); |
||||
|
|
||||
|
@BeforeEach |
||||
|
void setUp() { |
||||
|
willReturn(true).given(tenantService).tenantExists(tenantId); |
||||
|
} |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@ValueSource(strings = { |
||||
|
"coffee", "1", "big box", "世界", "!", "--", "~!@#$%^&*()_+=-/|\\[]{};:'`\"?<>,.", "\uD83D\uDC0C", "\041", |
||||
|
"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 testDeviceName_thenOK(final String name) { |
||||
|
Device device = new Device(); |
||||
|
device.setTenantId(tenantId); |
||||
|
device.setName(name); |
||||
|
validator.validateDataImpl(tenantId, device); |
||||
|
} |
||||
|
|
||||
|
@ParameterizedTest |
||||
|
@ValueSource(strings = { |
||||
|
"", " ", " ", "\n", "\r\n", "\t", "\000", "\000\000", "\001", "\002", "\040", "\u0000", "\u0000\u0000", |
||||
|
"F0929906\000\000\000\000\000\000\000\000\000", "\000\000\000F0929906", |
||||
|
"\u0000F0929906", "F092\u00009906", "F0929906\u0000" |
||||
|
}) |
||||
|
void testDeviceName_thenDataValidationException(final String name) { |
||||
|
Device device = new Device(); |
||||
|
device.setTenantId(tenantId); |
||||
|
device.setName(name); |
||||
|
|
||||
|
DataValidationException exception = Assertions.assertThrows(DataValidationException.class, () -> validator.validateDataImpl(tenantId, device)); |
||||
|
log.warn("Exception message: {}", exception.getMessage()); |
||||
|
assertThat(exception.getMessage()).as("message Device name").containsPattern("Device name .*"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Device profile name", deviceProfile.getName()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Edge name", edge.getName()); |
||||
|
verify(validator).validateString("Edge type", edge.getType()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Entity view name", entityView.getName()); |
||||
|
verify(validator).validateString("Entity view type", entityView.getType()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Resource title", resource.getTitle()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Rule chain name", ruleChain.getName()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Tenant title", tenant.getTitle()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Tenant profile name", tenantProfile.getName()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
/** |
||||
|
* 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.setDescriptor(JacksonUtil.toJsonNode("{\"content\":\"empty\"}")); |
||||
|
widgetTypeDetails.setTenantId(tenantId); |
||||
|
|
||||
|
validator.validateDataImpl(tenantId, widgetTypeDetails); |
||||
|
verify(validator).validateString("Widgets type name", widgetTypeDetails.getName()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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).validateString("Widgets bundle title", widgetsBundle.getTitle()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue