|
|
@ -21,10 +21,15 @@ import org.junit.Assert; |
|
|
import org.junit.Test; |
|
|
import org.junit.Test; |
|
|
import org.junit.jupiter.api.Assertions; |
|
|
import org.junit.jupiter.api.Assertions; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
import org.thingsboard.server.common.data.AdminSettings; |
|
|
import org.thingsboard.server.common.data.AdminSettings; |
|
|
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.settings.AdminSettingsService; |
|
|
import org.thingsboard.server.dao.settings.AdminSettingsService; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
|
|
|
|
|
|
|
|
public abstract class BaseAdminSettingsServiceTest extends AbstractServiceTest { |
|
|
public abstract class BaseAdminSettingsServiceTest extends AbstractServiceTest { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
@ -77,4 +82,33 @@ public abstract class BaseAdminSettingsServiceTest extends AbstractServiceTest { |
|
|
adminSettingsService.saveAdminSettings(SYSTEM_TENANT_ID, adminSettings); |
|
|
adminSettingsService.saveAdminSettings(SYSTEM_TENANT_ID, adminSettings); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void whenSavingAdminSettingsWithAlreadyExistingKey_thenReturnError() { |
|
|
|
|
|
String key = "mySettings"; |
|
|
|
|
|
ObjectNode value = JacksonUtil.newObjectNode().put("test", "test"); |
|
|
|
|
|
|
|
|
|
|
|
AdminSettings systemSettings = new AdminSettings(); |
|
|
|
|
|
systemSettings.setTenantId(TenantId.SYS_TENANT_ID); |
|
|
|
|
|
systemSettings.setKey(key); |
|
|
|
|
|
systemSettings.setJsonValue(value); |
|
|
|
|
|
adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, systemSettings); |
|
|
|
|
|
|
|
|
|
|
|
assertThatThrownBy(() -> { |
|
|
|
|
|
adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, systemSettings); |
|
|
|
|
|
}).hasMessageContaining("already exists"); |
|
|
|
|
|
|
|
|
|
|
|
AdminSettings tenantSettings = new AdminSettings(); |
|
|
|
|
|
tenantSettings.setTenantId(tenantId); |
|
|
|
|
|
tenantSettings.setKey(key); |
|
|
|
|
|
tenantSettings.setJsonValue(value); |
|
|
|
|
|
assertDoesNotThrow(() -> { |
|
|
|
|
|
adminSettingsService.saveAdminSettings(tenantId, tenantSettings); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
assertThatThrownBy(() -> { |
|
|
|
|
|
adminSettingsService.saveAdminSettings(tenantId, tenantSettings); |
|
|
|
|
|
}).hasMessageContaining("already exists"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|