|
|
@ -16,29 +16,35 @@ |
|
|
package org.thingsboard.server.dao.service.validator; |
|
|
package org.thingsboard.server.dao.service.validator; |
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
|
|
import org.junit.jupiter.params.provider.ValueSource; |
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
import org.springframework.boot.test.mock.mockito.MockBean; |
|
|
import org.springframework.test.context.bean.override.mockito.MockitoBean; |
|
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
|
|
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; |
|
|
import org.thingsboard.server.common.data.TenantProfile; |
|
|
import org.thingsboard.server.common.data.TenantProfile; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
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.DefaultTenantProfileConfiguration; |
|
|
import org.thingsboard.server.common.data.tenant.profile.TenantProfileData; |
|
|
import org.thingsboard.server.common.data.tenant.profile.TenantProfileData; |
|
|
import org.thingsboard.server.dao.tenant.TenantProfileDao; |
|
|
import org.thingsboard.server.dao.tenant.TenantProfileDao; |
|
|
import org.thingsboard.server.dao.tenant.TenantProfileService; |
|
|
import org.thingsboard.server.dao.tenant.TenantProfileService; |
|
|
|
|
|
import org.thingsboard.server.exception.DataValidationException; |
|
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatCode; |
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
import static org.mockito.Mockito.verify; |
|
|
import static org.mockito.Mockito.verify; |
|
|
|
|
|
|
|
|
@SpringBootTest(classes = TenantProfileDataValidator.class) |
|
|
@SpringBootTest(classes = TenantProfileDataValidator.class) |
|
|
class TenantProfileDataValidatorTest { |
|
|
class TenantProfileDataValidatorTest { |
|
|
|
|
|
|
|
|
@MockBean |
|
|
@MockitoBean |
|
|
TenantProfileDao tenantProfileDao; |
|
|
TenantProfileDao tenantProfileDao; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
TenantProfileService tenantProfileService; |
|
|
TenantProfileService tenantProfileService; |
|
|
@SpyBean |
|
|
@MockitoSpyBean |
|
|
TenantProfileDataValidator validator; |
|
|
TenantProfileDataValidator validator; |
|
|
|
|
|
|
|
|
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da")); |
|
|
TenantId tenantId = TenantId.fromUUID(UUID.fromString("9ef79cdf-37a8-4119-b682-2e7ed4e018da")); |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -53,4 +59,44 @@ class TenantProfileDataValidatorTest { |
|
|
verify(validator).validateString("Tenant profile name", tenantProfile.getName()); |
|
|
verify(validator).validateString("Tenant profile name", tenantProfile.getName()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
|
|
@ValueSource(ints = {-1, -100, Integer.MIN_VALUE}) |
|
|
|
|
|
void minAllowedScheduledUpdateIntervalInSecForCF_shouldRejectNegativeValues(int value) { |
|
|
|
|
|
// GIVEN
|
|
|
|
|
|
var config = new DefaultTenantProfileConfiguration(); |
|
|
|
|
|
config.setMinAllowedScheduledUpdateIntervalInSecForCF(value); |
|
|
|
|
|
|
|
|
|
|
|
var tenantProfileData = new TenantProfileData(); |
|
|
|
|
|
tenantProfileData.setConfiguration(config); |
|
|
|
|
|
|
|
|
|
|
|
var tenantProfile = new TenantProfile(); |
|
|
|
|
|
tenantProfile.setName("Test"); |
|
|
|
|
|
tenantProfile.setProfileData(tenantProfileData); |
|
|
|
|
|
|
|
|
|
|
|
// WHEN/THEN
|
|
|
|
|
|
assertThatThrownBy(() -> validator.validate(tenantProfile, __ -> TenantId.SYS_TENANT_ID)) |
|
|
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
|
|
.hasMessageContaining("minAllowedScheduledUpdateIntervalInSecForCF") |
|
|
|
|
|
.hasMessageContaining("must be greater than or equal to 0"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
|
|
@ValueSource(ints = {0, 1, 60, Integer.MAX_VALUE}) |
|
|
|
|
|
void minAllowedScheduledUpdateIntervalInSecForCF_shouldAcceptValidValues(int value) { |
|
|
|
|
|
// GIVEN
|
|
|
|
|
|
var config = new DefaultTenantProfileConfiguration(); |
|
|
|
|
|
config.setMinAllowedScheduledUpdateIntervalInSecForCF(value); |
|
|
|
|
|
|
|
|
|
|
|
var tenantProfileData = new TenantProfileData(); |
|
|
|
|
|
tenantProfileData.setConfiguration(config); |
|
|
|
|
|
|
|
|
|
|
|
var tenantProfile = new TenantProfile(); |
|
|
|
|
|
tenantProfile.setName("Test"); |
|
|
|
|
|
tenantProfile.setProfileData(tenantProfileData); |
|
|
|
|
|
|
|
|
|
|
|
// WHEN/THEN
|
|
|
|
|
|
assertThatCode(() -> validator.validate(tenantProfile, __ -> TenantId.SYS_TENANT_ID)) |
|
|
|
|
|
.doesNotThrowAnyException(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|