34 changed files with 1001 additions and 72 deletions
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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()); |
|||
} |
|||
|
|||
} |
|||
@ -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…
Reference in new issue