diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantProfileServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantProfileServiceTest.java index a21a8e5845..68f703b63d 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantProfileServiceTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantProfileServiceTest.java @@ -294,7 +294,7 @@ public abstract class BaseTenantProfileServiceTest extends AbstractServiceTest { return tenantProfile; } - private void addMainQueueConfig(TenantProfile tenantProfile) { + public static void addMainQueueConfig(TenantProfile tenantProfile) { TenantProfileQueueConfiguration mainQueueConfiguration = new TenantProfileQueueConfiguration(); mainQueueConfiguration.setName(DataConstants.MAIN_QUEUE_NAME); mainQueueConfiguration.setTopic(DataConstants.MAIN_QUEUE_TOPIC); diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantServiceTest.java index 4e4fc44c56..e899d85655 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantServiceTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantServiceTest.java @@ -15,8 +15,10 @@ */ package org.thingsboard.server.dao.service; +import org.junit.After; import org.junit.Assert; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.SpyBean; @@ -54,6 +56,7 @@ import org.thingsboard.server.common.data.rule.RuleChainType; import org.thingsboard.server.common.data.security.Authority; 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.TenantProfileQueueConfiguration; import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.tenant.TenantDao; @@ -81,6 +84,19 @@ public abstract class BaseTenantServiceTest extends AbstractServiceTest { @Autowired protected TbTransactionalCache existsTenantCache; + Tenant savedTenant; + TenantProfile savedTenantProfile; + + @After + public void tearDown() throws Exception { + if (savedTenant != null) { + tenantService.deleteTenant(savedTenant.getId()); + } + if (savedTenantProfile != null) { + tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); + } + } + @Test public void testSaveTenant() { Tenant tenant = new Tenant(); @@ -121,18 +137,22 @@ public abstract class BaseTenantServiceTest extends AbstractServiceTest { tenantService.deleteTenant(savedTenant.getId()); } - @Test(expected = DataValidationException.class) + @Test public void testSaveTenantWithEmptyTitle() { Tenant tenant = new Tenant(); - tenantService.saveTenant(tenant); + Assertions.assertThrows(DataValidationException.class, () -> { + tenantService.saveTenant(tenant); + }); } - @Test(expected = DataValidationException.class) + @Test public void testSaveTenantWithInvalidEmail() { Tenant tenant = new Tenant(); tenant.setTitle("My tenant"); tenant.setEmail("invalid@mail"); - tenantService.saveTenant(tenant); + Assertions.assertThrows(DataValidationException.class, () -> { + tenantService.saveTenant(tenant); + }); } @Test @@ -301,7 +321,7 @@ public abstract class BaseTenantServiceTest extends AbstractServiceTest { } - @Test(expected = DataValidationException.class) + @Test public void testSaveTenantWithIsolatedProfileInMonolithSetup() { TenantProfile tenantProfile = new TenantProfile(); tenantProfile.setName("Isolated Tenant Profile"); @@ -310,12 +330,15 @@ public abstract class BaseTenantServiceTest extends AbstractServiceTest { tenantProfile.setProfileData(profileData); tenantProfile.setDefault(false); tenantProfile.setIsolatedTbRuleEngine(true); - TenantProfile isolatedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); + BaseTenantProfileServiceTest.addMainQueueConfig(tenantProfile); + this.savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); Tenant tenant = new Tenant(); - tenant.setTitle("Tenant"); - tenant.setTenantProfileId(isolatedTenantProfile.getId()); - tenantService.saveTenant(tenant); + tenant.setTitle("Tenant with isolated profile"); + tenant.setTenantProfileId(savedTenantProfile.getId()); + Assertions.assertThrows(DataValidationException.class, () -> { + this.savedTenant = tenantService.saveTenant(tenant); + }); } @Test