junit5: BaseTenantServiceTest annotation exceptions refactoring, testSaveTenantWithIsolatedProfileInMonolithSetup issue
This commit is contained in:
parent
99b60dff4e
commit
25e046dc79
@ -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);
|
||||
|
||||
@ -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<TenantId, Boolean> 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user