Merge pull request #6900 from thingsboard/refactoring_test_19
[3.4] Refactoring test 19
This commit is contained in:
commit
d1e830d59e
@ -381,8 +381,8 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void testBroadcastEntityStateChangeEventTime(EntityId entityId, TenantId tenantId, int cntTime) {
|
protected void testBroadcastEntityStateChangeEventTime(EntityId entityId, TenantId tenantId, int cntTime) {
|
||||||
ArgumentMatcher<TenantId> matcherTenantIdId = cntTime == 1 ? argument -> argument.equals(tenantId) :
|
ArgumentMatcher<TenantId> matcherTenantIdId = cntTime > 1 || tenantId == null ? argument -> argument.getClass().equals(TenantId.class) :
|
||||||
argument -> argument.getClass().equals(TenantId.class);
|
argument -> argument.equals(tenantId) ;
|
||||||
Mockito.verify(tbClusterService, times(cntTime)).broadcastEntityStateChangeEvent(Mockito.argThat(matcherTenantIdId),
|
Mockito.verify(tbClusterService, times(cntTime)).broadcastEntityStateChangeEvent(Mockito.argThat(matcherTenantIdId),
|
||||||
Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class));
|
Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,7 +93,7 @@ public abstract class BaseTenantControllerTest extends AbstractControllerTest {
|
|||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
tenant.setTitle("My tenant");
|
tenant.setTitle("My tenant");
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
||||||
Assert.assertNotNull(savedTenant);
|
Assert.assertNotNull(savedTenant);
|
||||||
@ -122,7 +122,7 @@ public abstract class BaseTenantControllerTest extends AbstractControllerTest {
|
|||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
tenant.setTitle(RandomStringUtils.randomAlphanumeric(300));
|
tenant.setTitle(RandomStringUtils.randomAlphanumeric(300));
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
doPost("/api/tenant", tenant)
|
doPost("/api/tenant", tenant)
|
||||||
.andExpect(status().isBadRequest())
|
.andExpect(status().isBadRequest())
|
||||||
@ -161,7 +161,7 @@ public abstract class BaseTenantControllerTest extends AbstractControllerTest {
|
|||||||
public void testSaveTenantWithEmptyTitle() throws Exception {
|
public void testSaveTenantWithEmptyTitle() throws Exception {
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
doPost("/api/tenant", tenant)
|
doPost("/api/tenant", tenant)
|
||||||
@ -175,7 +175,7 @@ public abstract class BaseTenantControllerTest extends AbstractControllerTest {
|
|||||||
public void testSaveTenantWithInvalidEmail() throws Exception {
|
public void testSaveTenantWithInvalidEmail() throws Exception {
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
tenant.setTitle("My tenant");
|
tenant.setTitle("My tenant");
|
||||||
@ -212,7 +212,7 @@ public abstract class BaseTenantControllerTest extends AbstractControllerTest {
|
|||||||
Assert.assertEquals(1, pageData.getData().size());
|
Assert.assertEquals(1, pageData.getData().size());
|
||||||
tenants.addAll(pageData.getData());
|
tenants.addAll(pageData.getData());
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
int cntEntity = 56;
|
int cntEntity = 56;
|
||||||
List<ListenableFuture<Tenant>> createFutures = new ArrayList<>(56);
|
List<ListenableFuture<Tenant>> createFutures = new ArrayList<>(56);
|
||||||
@ -578,13 +578,13 @@ public abstract class BaseTenantControllerTest extends AbstractControllerTest {
|
|||||||
}
|
}
|
||||||
TenantId tenantId = cntTime == 1 ? tenant.getId() : (TenantId) createEntityId_NULL_UUID(tenant);
|
TenantId tenantId = cntTime == 1 ? tenant.getId() : (TenantId) createEntityId_NULL_UUID(tenant);
|
||||||
testBroadcastEntityStateChangeEventTime(tenantId, tenantId, cntTime);
|
testBroadcastEntityStateChangeEventTime(tenantId, tenantId, cntTime);
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testBroadcastEntityStateChangeEventNeverTenant() {
|
private void testBroadcastEntityStateChangeEventNeverTenant() {
|
||||||
Mockito.verify(tbClusterService, never()).onTenantChange(Mockito.any(Tenant.class),
|
Mockito.verify(tbClusterService, never()).onTenantChange(Mockito.any(Tenant.class),
|
||||||
Mockito.isNull());
|
Mockito.isNull());
|
||||||
testBroadcastEntityStateChangeEventNever(createEntityId_NULL_UUID(new Tenant()));
|
testBroadcastEntityStateChangeEventNever(createEntityId_NULL_UUID(new Tenant()));
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,24 +17,24 @@ package org.thingsboard.server.controller;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.mockito.ArgumentMatcher;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.thingsboard.server.common.data.EntityInfo;
|
import org.thingsboard.server.common.data.EntityInfo;
|
||||||
import org.thingsboard.server.common.data.Tenant;
|
import org.thingsboard.server.common.data.Tenant;
|
||||||
import org.thingsboard.server.common.data.TenantProfile;
|
import org.thingsboard.server.common.data.TenantProfile;
|
||||||
|
import org.thingsboard.server.common.data.id.TenantProfileId;
|
||||||
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
|
import org.thingsboard.server.common.data.page.PageLink;
|
||||||
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
||||||
import org.thingsboard.server.common.data.queue.ProcessingStrategy;
|
import org.thingsboard.server.common.data.queue.ProcessingStrategy;
|
||||||
import org.thingsboard.server.common.data.queue.ProcessingStrategyType;
|
import org.thingsboard.server.common.data.queue.ProcessingStrategyType;
|
||||||
import org.thingsboard.server.common.data.queue.SubmitStrategy;
|
import org.thingsboard.server.common.data.queue.SubmitStrategy;
|
||||||
import org.thingsboard.server.common.data.queue.SubmitStrategyType;
|
import org.thingsboard.server.common.data.queue.SubmitStrategyType;
|
||||||
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.common.data.id.TenantId;
|
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
|
||||||
import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration;
|
import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration;
|
||||||
import org.thingsboard.server.dao.tenant.TenantProfileService;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -42,6 +42,8 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
public abstract class BaseTenantProfileControllerTest extends AbstractControllerTest {
|
public abstract class BaseTenantProfileControllerTest extends AbstractControllerTest {
|
||||||
@ -52,6 +54,9 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
@Test
|
@Test
|
||||||
public void testSaveTenantProfile() throws Exception {
|
public void testSaveTenantProfile() throws Exception {
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
||||||
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
||||||
Assert.assertNotNull(savedTenantProfile);
|
Assert.assertNotNull(savedTenantProfile);
|
||||||
@ -64,17 +69,28 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
Assert.assertEquals(tenantProfile.isIsolatedTbCore(), savedTenantProfile.isIsolatedTbCore());
|
Assert.assertEquals(tenantProfile.isIsolatedTbCore(), savedTenantProfile.isIsolatedTbCore());
|
||||||
Assert.assertEquals(tenantProfile.isIsolatedTbRuleEngine(), savedTenantProfile.isIsolatedTbRuleEngine());
|
Assert.assertEquals(tenantProfile.isIsolatedTbRuleEngine(), savedTenantProfile.isIsolatedTbRuleEngine());
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventTimeManyTimeTenantProfile(savedTenantProfile, ComponentLifecycleEvent.CREATED, 1);
|
||||||
|
|
||||||
savedTenantProfile.setName("New tenant profile");
|
savedTenantProfile.setName("New tenant profile");
|
||||||
doPost("/api/tenantProfile", savedTenantProfile, TenantProfile.class);
|
doPost("/api/tenantProfile", savedTenantProfile, TenantProfile.class);
|
||||||
TenantProfile foundTenantProfile = doGet("/api/tenantProfile/"+savedTenantProfile.getId().getId().toString(), TenantProfile.class);
|
TenantProfile foundTenantProfile = doGet("/api/tenantProfile/"+savedTenantProfile.getId().getId().toString(), TenantProfile.class);
|
||||||
Assert.assertEquals(foundTenantProfile.getName(), savedTenantProfile.getName());
|
Assert.assertEquals(foundTenantProfile.getName(), savedTenantProfile.getName());
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventTimeManyTimeTenantProfile(savedTenantProfile, ComponentLifecycleEvent.UPDATED, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveTenantProfileWithViolationOfLengthValidation() throws Exception {
|
public void testSaveTenantProfileWithViolationOfLengthValidation() throws Exception {
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
TenantProfile tenantProfile = this.createTenantProfile(RandomStringUtils.randomAlphabetic(300));
|
TenantProfile tenantProfile = this.createTenantProfile(RandomStringUtils.randomAlphabetic(300));
|
||||||
doPost("/api/tenantProfile", tenantProfile).andExpect(statusReason(containsString("length of name must be equal or less than 255")));
|
doPost("/api/tenantProfile", tenantProfile)
|
||||||
|
.andExpect(status().isBadRequest())
|
||||||
|
.andExpect(statusReason(containsString(msgErrorFieldLength("name"))));
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventNeverTenantProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -122,9 +138,15 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
@Test
|
@Test
|
||||||
public void testSaveTenantProfileWithEmptyName() throws Exception {
|
public void testSaveTenantProfileWithEmptyName() throws Exception {
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
TenantProfile tenantProfile = new TenantProfile();
|
TenantProfile tenantProfile = new TenantProfile();
|
||||||
doPost("/api/tenantProfile", tenantProfile).andExpect(status().isBadRequest())
|
doPost("/api/tenantProfile", tenantProfile).andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString("Tenant profile name should be specified")));
|
.andExpect(status().isBadRequest())
|
||||||
|
.andExpect(statusReason(containsString("Tenant profile name " + msgErrorShouldBeSpecified)));
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventNeverTenantProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -132,9 +154,15 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
||||||
doPost("/api/tenantProfile", tenantProfile).andExpect(status().isOk());
|
doPost("/api/tenantProfile", tenantProfile).andExpect(status().isOk());
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
TenantProfile tenantProfile2 = this.createTenantProfile("Tenant Profile");
|
TenantProfile tenantProfile2 = this.createTenantProfile("Tenant Profile");
|
||||||
doPost("/api/tenantProfile", tenantProfile2).andExpect(status().isBadRequest())
|
doPost("/api/tenantProfile", tenantProfile2)
|
||||||
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString("Tenant profile with such name already exists")));
|
.andExpect(statusReason(containsString("Tenant profile with such name already exists")));
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventNeverTenantProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -144,8 +172,14 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
||||||
savedTenantProfile.setIsolatedTbRuleEngine(true);
|
savedTenantProfile.setIsolatedTbRuleEngine(true);
|
||||||
addMainQueueConfig(savedTenantProfile);
|
addMainQueueConfig(savedTenantProfile);
|
||||||
doPost("/api/tenantProfile", savedTenantProfile).andExpect(status().isBadRequest())
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
|
doPost("/api/tenantProfile", savedTenantProfile)
|
||||||
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString("Can't update isolatedTbRuleEngine property")));
|
.andExpect(statusReason(containsString("Can't update isolatedTbRuleEngine property")));
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventNeverTenantProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -153,9 +187,15 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
||||||
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
savedTenantProfile.setIsolatedTbCore(true);
|
savedTenantProfile.setIsolatedTbCore(true);
|
||||||
doPost("/api/tenantProfile", savedTenantProfile).andExpect(status().isBadRequest())
|
doPost("/api/tenantProfile", savedTenantProfile)
|
||||||
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString("Can't update isolatedTbCore property")));
|
.andExpect(statusReason(containsString("Can't update isolatedTbCore property")));
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventNeverTenantProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -169,10 +209,14 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
tenant.setTenantProfileId(savedTenantProfile.getId());
|
tenant.setTenantProfileId(savedTenantProfile.getId());
|
||||||
Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
doDelete("/api/tenantProfile/" + savedTenantProfile.getId().getId().toString())
|
doDelete("/api/tenantProfile/" + savedTenantProfile.getId().getId().toString())
|
||||||
.andExpect(status().isBadRequest())
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString("The tenant profile referenced by the tenants cannot be deleted")));
|
.andExpect(statusReason(containsString("The tenant profile referenced by the tenants cannot be deleted")));
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventNeverTenantProfile();
|
||||||
|
|
||||||
doDelete("/api/tenant/"+savedTenant.getId().getId().toString())
|
doDelete("/api/tenant/"+savedTenant.getId().getId().toString())
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
@ -183,11 +227,16 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
|
||||||
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
doDelete("/api/tenantProfile/" + savedTenantProfile.getId().getId().toString())
|
doDelete("/api/tenantProfile/" + savedTenantProfile.getId().getId().toString())
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventTimeManyTimeTenantProfile(savedTenantProfile, ComponentLifecycleEvent.DELETED, 1);
|
||||||
|
|
||||||
doGet("/api/tenantProfile/" + savedTenantProfile.getId().getId().toString())
|
doGet("/api/tenantProfile/" + savedTenantProfile.getId().getId().toString())
|
||||||
.andExpect(status().isNotFound());
|
.andExpect(status().isNotFound())
|
||||||
|
.andExpect(statusReason(containsString(msgErrorNoFound("Tenant profile", savedTenantProfile.getId().getId().toString()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -196,21 +245,26 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
List<TenantProfile> tenantProfiles = new ArrayList<>();
|
List<TenantProfile> tenantProfiles = new ArrayList<>();
|
||||||
PageLink pageLink = new PageLink(17);
|
PageLink pageLink = new PageLink(17);
|
||||||
PageData<TenantProfile> pageData = doGetTypedWithPageLink("/api/tenantProfiles?",
|
PageData<TenantProfile> pageData = doGetTypedWithPageLink("/api/tenantProfiles?",
|
||||||
new TypeReference<PageData<TenantProfile>>(){}, pageLink);
|
new TypeReference<>(){}, pageLink);
|
||||||
Assert.assertFalse(pageData.hasNext());
|
Assert.assertFalse(pageData.hasNext());
|
||||||
Assert.assertEquals(1, pageData.getTotalElements());
|
Assert.assertEquals(1, pageData.getTotalElements());
|
||||||
tenantProfiles.addAll(pageData.getData());
|
tenantProfiles.addAll(pageData.getData());
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
|
int cntEntity = 28;
|
||||||
for (int i=0;i<28;i++) {
|
for (int i=0;i<28;i++) {
|
||||||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"+i);
|
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"+i);
|
||||||
tenantProfiles.add(doPost("/api/tenantProfile", tenantProfile, TenantProfile.class));
|
tenantProfiles.add(doPost("/api/tenantProfile", tenantProfile, TenantProfile.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventTimeManyTimeTenantProfile(new TenantProfile(), ComponentLifecycleEvent.CREATED, cntEntity);
|
||||||
|
|
||||||
List<TenantProfile> loadedTenantProfiles = new ArrayList<>();
|
List<TenantProfile> loadedTenantProfiles = new ArrayList<>();
|
||||||
pageLink = new PageLink(17);
|
pageLink = new PageLink(17);
|
||||||
do {
|
do {
|
||||||
pageData = doGetTypedWithPageLink("/api/tenantProfiles?",
|
pageData = doGetTypedWithPageLink("/api/tenantProfiles?",
|
||||||
new TypeReference<PageData<TenantProfile>>(){}, pageLink);
|
new TypeReference<>(){}, pageLink);
|
||||||
loadedTenantProfiles.addAll(pageData.getData());
|
loadedTenantProfiles.addAll(pageData.getData());
|
||||||
if (pageData.hasNext()) {
|
if (pageData.hasNext()) {
|
||||||
pageLink = pageLink.nextPageLink();
|
pageLink = pageLink.nextPageLink();
|
||||||
@ -222,6 +276,8 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
|
|
||||||
Assert.assertEquals(tenantProfiles, loadedTenantProfiles);
|
Assert.assertEquals(tenantProfiles, loadedTenantProfiles);
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
|
||||||
for (TenantProfile tenantProfile : loadedTenantProfiles) {
|
for (TenantProfile tenantProfile : loadedTenantProfiles) {
|
||||||
if (!tenantProfile.isDefault()) {
|
if (!tenantProfile.isDefault()) {
|
||||||
doDelete("/api/tenantProfile/" + tenantProfile.getId().getId().toString())
|
doDelete("/api/tenantProfile/" + tenantProfile.getId().getId().toString())
|
||||||
@ -234,6 +290,8 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
new TypeReference<PageData<TenantProfile>>(){}, pageLink);
|
new TypeReference<PageData<TenantProfile>>(){}, pageLink);
|
||||||
Assert.assertFalse(pageData.hasNext());
|
Assert.assertFalse(pageData.hasNext());
|
||||||
Assert.assertEquals(1, pageData.getTotalElements());
|
Assert.assertEquals(1, pageData.getTotalElements());
|
||||||
|
|
||||||
|
testBroadcastEntityStateChangeEventTimeManyTimeTenantProfile(new TenantProfile(), ComponentLifecycleEvent.DELETED, cntEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -242,7 +300,7 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
List<TenantProfile> tenantProfiles = new ArrayList<>();
|
List<TenantProfile> tenantProfiles = new ArrayList<>();
|
||||||
PageLink pageLink = new PageLink(17);
|
PageLink pageLink = new PageLink(17);
|
||||||
PageData<TenantProfile> tenantProfilePageData = doGetTypedWithPageLink("/api/tenantProfiles?",
|
PageData<TenantProfile> tenantProfilePageData = doGetTypedWithPageLink("/api/tenantProfiles?",
|
||||||
new TypeReference<PageData<TenantProfile>>(){}, pageLink);
|
new TypeReference<>(){}, pageLink);
|
||||||
Assert.assertFalse(tenantProfilePageData.hasNext());
|
Assert.assertFalse(tenantProfilePageData.hasNext());
|
||||||
Assert.assertEquals(1, tenantProfilePageData.getTotalElements());
|
Assert.assertEquals(1, tenantProfilePageData.getTotalElements());
|
||||||
tenantProfiles.addAll(tenantProfilePageData.getData());
|
tenantProfiles.addAll(tenantProfilePageData.getData());
|
||||||
@ -322,4 +380,28 @@ public abstract class BaseTenantProfileControllerTest extends AbstractController
|
|||||||
profileData.setQueueConfiguration(Collections.singletonList(mainQueueConfiguration));
|
profileData.setQueueConfiguration(Collections.singletonList(mainQueueConfiguration));
|
||||||
tenantProfile.setProfileData(profileData);
|
tenantProfile.setProfileData(profileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void testBroadcastEntityStateChangeEventTimeManyTimeTenantProfile(TenantProfile tenantProfile, ComponentLifecycleEvent event, int cntTime) {
|
||||||
|
ArgumentMatcher<TenantProfile> matcherTenantProfile = cntTime == 1 ? argument -> argument.equals(tenantProfile) :
|
||||||
|
argument -> argument.getClass().equals(TenantProfile.class);
|
||||||
|
if (ComponentLifecycleEvent.DELETED.equals(event)) {
|
||||||
|
Mockito.verify(tbClusterService, times( cntTime)).onTenantProfileDelete(Mockito.argThat( matcherTenantProfile),
|
||||||
|
Mockito.isNull());
|
||||||
|
testBroadcastEntityStateChangeEventNever(createEntityId_NULL_UUID(new Tenant()));
|
||||||
|
} else {
|
||||||
|
Mockito.verify(tbClusterService, times( cntTime)).onTenantProfileChange(Mockito.argThat(matcherTenantProfile),
|
||||||
|
Mockito.isNull());
|
||||||
|
TenantProfileId tenantProfileIdId = cntTime == 1 ? tenantProfile.getId() : (TenantProfileId) createEntityId_NULL_UUID(tenantProfile);
|
||||||
|
testBroadcastEntityStateChangeEventTime(tenantProfileIdId, null, cntTime);
|
||||||
|
}
|
||||||
|
Mockito.reset(tbClusterService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testBroadcastEntityStateChangeEventNeverTenantProfile() {
|
||||||
|
Mockito.verify(tbClusterService, never()).onTenantProfileChange(Mockito.any(TenantProfile.class),
|
||||||
|
Mockito.isNull());
|
||||||
|
testBroadcastEntityStateChangeEventNever(createEntityId_NULL_UUID(new Tenant()));
|
||||||
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user