fix_bug: test transactional UnfinishedStubbingException
This commit is contained in:
parent
cd6e50312c
commit
262c09c394
@ -35,7 +35,7 @@ import org.junit.Rule;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -132,7 +132,8 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
||||
protected static final String DIFFERENT_CUSTOMER_USER_EMAIL = "testdifferentcustomer@thingsboard.org";
|
||||
private static final String DIFFERENT_CUSTOMER_USER_PASSWORD = "diffcustomer";
|
||||
|
||||
/** See {@link org.springframework.test.web.servlet.DefaultMvcResult#getAsyncResult(long)}
|
||||
/**
|
||||
* See {@link org.springframework.test.web.servlet.DefaultMvcResult#getAsyncResult(long)}
|
||||
* and {@link org.springframework.mock.web.MockAsyncContext#getTimeout()}
|
||||
*/
|
||||
private static final long DEFAULT_TIMEOUT = -1L;
|
||||
@ -732,23 +733,18 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
||||
|
||||
protected <T> void testEntityDaoWithRelationsTransactionalException(Dao<T> dao, EntityId entityIdFrom, EntityId entityTo,
|
||||
String urlDelete) throws Exception {
|
||||
entityDaoRemoveByIdWithException (dao);
|
||||
try {
|
||||
Mockito.doThrow(new ConstraintViolationException("mock message", new SQLException(), "MOCK_CONSTRAINT")).when(dao).removeById(any(), any());
|
||||
createEntityRelation(entityIdFrom, entityTo, "TEST_TRANSACTIONAL_TYPE");
|
||||
assertThat(findRelationsByTo(entityTo)).hasSize(1);
|
||||
|
||||
doDelete(urlDelete)
|
||||
.andExpect(status().isInternalServerError());
|
||||
|
||||
assertThat(findRelationsByTo(entityTo)).hasSize(1);
|
||||
} catch (Exception e) {
|
||||
log.error ("", e);
|
||||
} finally {
|
||||
Mockito.reset(dao);
|
||||
}
|
||||
|
||||
protected <T> void entityDaoRemoveByIdWithException (Dao<T> dao) throws Exception {
|
||||
BDDMockito.willThrow(new ConstraintViolationException("mock message", new SQLException(), "MOCK_CONSTRAINT"))
|
||||
.given(dao).removeById(any(), any());
|
||||
}
|
||||
|
||||
protected <T> void afterTestEntityDaoRemoveByIdWithException (Dao<T> dao) throws Exception {
|
||||
BDDMockito.willCallRealMethod().given(dao).removeById(any(), any());
|
||||
}
|
||||
|
||||
protected void createEntityRelation(EntityId entityIdFrom, EntityId entityIdTo, String typeRelation) throws Exception {
|
||||
@ -761,9 +757,13 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
||||
MvcResult mvcResult = doGet(url).andReturn();
|
||||
|
||||
switch (mvcResult.getResponse().getStatus()) {
|
||||
case 200: return readResponse(mvcResult, new TypeReference<>() {});
|
||||
case 404: return Collections.emptyList();
|
||||
case 200:
|
||||
return readResponse(mvcResult, new TypeReference<>() {
|
||||
});
|
||||
case 404:
|
||||
return Collections.emptyList();
|
||||
}
|
||||
throw new AssertionError("Unexpected status " + mvcResult.getResponse().getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,8 +22,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
@ -43,16 +47,24 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
@ContextConfiguration(classes = {BaseAlarmControllerTest.Config.class})
|
||||
public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
|
||||
public static final String TEST_ALARM_TYPE = "Test";
|
||||
|
||||
protected Device customerDevice;
|
||||
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private AlarmDao alarmDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public AlarmDao alarmDao(AlarmDao alarmDao) {
|
||||
return Mockito.mock(AlarmDao.class, AdditionalAnswers.delegatesTo(alarmDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
loginTenantAdmin();
|
||||
@ -72,8 +84,6 @@ public abstract class BaseAlarmControllerTest extends AbstractControllerTest {
|
||||
public void teardown() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (alarmDao);
|
||||
|
||||
deleteDifferentTenant();
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityView;
|
||||
@ -51,6 +55,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
||||
|
||||
@ContextConfiguration(classes = {BaseAssetControllerTest.Config.class})
|
||||
public abstract class BaseAssetControllerTest extends AbstractControllerTest {
|
||||
|
||||
private IdComparator<Asset> idComparator = new IdComparator<>();
|
||||
@ -58,9 +63,17 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
|
||||
private Tenant savedTenant;
|
||||
private User tenantAdmin;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private AssetDao assetDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public AssetDao assetDao(AssetDao assetDao) {
|
||||
return Mockito.mock(AssetDao.class, AdditionalAnswers.delegatesTo(assetDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
@ -84,8 +97,6 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
|
||||
public void afterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (assetDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@ -20,8 +20,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
@ -47,6 +51,7 @@ import java.util.stream.Collectors;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ContextConfiguration(classes = {BaseAssetProfileControllerTest.Config.class})
|
||||
public abstract class BaseAssetProfileControllerTest extends AbstractControllerTest {
|
||||
|
||||
private IdComparator<AssetProfile> idComparator = new IdComparator<>();
|
||||
@ -55,9 +60,17 @@ public abstract class BaseAssetProfileControllerTest extends AbstractControllerT
|
||||
private Tenant savedTenant;
|
||||
private User tenantAdmin;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private AssetProfileDao assetProfileDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public AssetProfileDao assetProfileDao(AssetProfileDao assetProfileDao) {
|
||||
return Mockito.mock(AssetProfileDao.class, AdditionalAnswers.delegatesTo(assetProfileDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
@ -81,8 +94,6 @@ public abstract class BaseAssetProfileControllerTest extends AbstractControllerT
|
||||
public void afterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (assetProfileDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@ -24,8 +24,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
@ -48,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ContextConfiguration(classes = {BaseCustomerControllerTest.Config.class})
|
||||
public abstract class BaseCustomerControllerTest extends AbstractControllerTest {
|
||||
static final TypeReference<PageData<Customer>> PAGE_DATA_CUSTOMER_TYPE_REFERENCE = new TypeReference<>() {
|
||||
};
|
||||
@ -57,9 +62,18 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
private Tenant savedTenant;
|
||||
private User tenantAdmin;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private CustomerDao customerDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public CustomerDao customerDao(CustomerDao customerDao) {
|
||||
return Mockito.mock(CustomerDao.class, AdditionalAnswers.delegatesTo(customerDao));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
executor = MoreExecutors.listeningDecorator(ThingsBoardExecutors.newWorkStealingPool(8, getClass()));
|
||||
@ -87,8 +101,6 @@ public abstract class BaseCustomerControllerTest extends AbstractControllerTest
|
||||
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (customerDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@ -21,8 +21,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.DashboardInfo;
|
||||
@ -46,6 +50,7 @@ import java.util.List;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ContextConfiguration(classes = {BaseDashboardControllerTest.Config.class})
|
||||
public abstract class BaseDashboardControllerTest extends AbstractControllerTest {
|
||||
|
||||
private IdComparator<DashboardInfo> idComparator = new IdComparator<>();
|
||||
@ -53,9 +58,17 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
||||
private Tenant savedTenant;
|
||||
private User tenantAdmin;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private DashboardDao dashboardDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public DashboardDao dashboardDao(DashboardDao dashboardDao) {
|
||||
return Mockito.mock(DashboardDao.class, AdditionalAnswers.delegatesTo(dashboardDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
@ -79,8 +92,6 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
||||
public void afterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (dashboardDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@ -25,8 +25,13 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -69,6 +74,7 @@ import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
||||
|
||||
@ContextConfiguration(classes = {BaseDeviceControllerTest.Config.class})
|
||||
public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
|
||||
static final TypeReference<PageData<Device>> PAGE_DATA_DEVICE_TYPE_REF = new TypeReference<>() {};
|
||||
|
||||
@ -83,9 +89,16 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
|
||||
@SpyBean
|
||||
private GatewayNotificationsService gatewayNotificationsService;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private DeviceDao deviceDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public DeviceDao deviceDao(DeviceDao deviceDao) {
|
||||
return Mockito.mock(DeviceDao.class, AdditionalAnswers.delegatesTo(deviceDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
@ -114,8 +127,6 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
|
||||
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (deviceDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@ -26,8 +26,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -69,6 +73,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
|
||||
|
||||
@ContextConfiguration(classes = {BaseDeviceProfileControllerTest.Config.class})
|
||||
public abstract class BaseDeviceProfileControllerTest extends AbstractControllerTest {
|
||||
|
||||
private IdComparator<DeviceProfile> idComparator = new IdComparator<>();
|
||||
@ -77,9 +82,17 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
||||
private Tenant savedTenant;
|
||||
private User tenantAdmin;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private DeviceProfileDao deviceProfileDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public DeviceProfileDao deviceProfileDao(DeviceProfileDao deviceProfileDao) {
|
||||
return Mockito.mock(DeviceProfileDao.class, AdditionalAnswers.delegatesTo(deviceProfileDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
@ -103,8 +116,6 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
||||
public void afterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (deviceProfileDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
@ -1149,4 +1160,5 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
||||
DeviceProfile deviceProfile = createDeviceProfile(name);
|
||||
return doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,8 +21,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -65,6 +69,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
||||
@TestPropertySource(properties = {
|
||||
"edges.enabled=true",
|
||||
})
|
||||
@ContextConfiguration(classes = {BaseEdgeControllerTest.Config.class})
|
||||
public abstract class BaseEdgeControllerTest extends AbstractControllerTest {
|
||||
|
||||
public static final String EDGE_HOST = "localhost";
|
||||
@ -76,9 +81,17 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest {
|
||||
private TenantId tenantId;
|
||||
private User tenantAdmin;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private EdgeDao edgeDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public EdgeDao edgeDao(EdgeDao edgeDao) {
|
||||
return Mockito.mock(EdgeDao.class, AdditionalAnswers.delegatesTo(edgeDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
@ -103,8 +116,6 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest {
|
||||
public void afterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (edgeDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@ -31,8 +31,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||
@ -84,6 +88,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
||||
"js.evaluator=mock",
|
||||
})
|
||||
@Slf4j
|
||||
@ContextConfiguration(classes = {BaseEntityViewControllerTest.Config.class})
|
||||
public abstract class BaseEntityViewControllerTest extends AbstractControllerTest {
|
||||
static final TypeReference<PageData<EntityView>> PAGE_DATA_ENTITY_VIEW_TYPE_REF = new TypeReference<>() {
|
||||
};
|
||||
@ -96,9 +101,17 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
|
||||
List<ListenableFuture<ResultActions>> deleteFutures = new ArrayList<>();
|
||||
ListeningExecutorService executor;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private EntityViewDao entityViewDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public EntityViewDao entityViewDao(EntityViewDao entityViewDao) {
|
||||
return Mockito.mock(EntityViewDao.class, AdditionalAnswers.delegatesTo(entityViewDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
executor = MoreExecutors.listeningDecorator(ThingsBoardExecutors.newWorkStealingPool(8, getClass()));
|
||||
@ -121,8 +134,6 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException (entityViewDao);
|
||||
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
|
||||
@ -20,8 +20,12 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
@ -43,6 +47,7 @@ import java.util.List;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ContextConfiguration(classes = {BaseRuleChainControllerTest.Config.class})
|
||||
public abstract class BaseRuleChainControllerTest extends AbstractControllerTest {
|
||||
|
||||
private IdComparator<RuleChain> idComparator = new IdComparator<>();
|
||||
@ -50,9 +55,17 @@ public abstract class BaseRuleChainControllerTest extends AbstractControllerTest
|
||||
private Tenant savedTenant;
|
||||
private User tenantAdmin;
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private RuleChainDao ruleChainDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public RuleChainDao ruleChainDao(RuleChainDao ruleChainDao) {
|
||||
return Mockito.mock(RuleChainDao.class, AdditionalAnswers.delegatesTo(ruleChainDao));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
@ -76,8 +89,6 @@ public abstract class BaseRuleChainControllerTest extends AbstractControllerTest
|
||||
public void afterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException(ruleChainDao);
|
||||
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@ -21,9 +21,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
@ -51,20 +55,27 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.SYSTEM_TENANT;
|
||||
|
||||
@ContextConfiguration(classes = {BaseUserControllerTest.Config.class})
|
||||
public abstract class BaseUserControllerTest extends AbstractControllerTest {
|
||||
|
||||
private IdComparator<User> idComparator = new IdComparator<>();
|
||||
|
||||
private CustomerId customerNUULId = (CustomerId) createEntityId_NULL_UUID(new Customer());
|
||||
|
||||
@SpyBean
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
static class Config {
|
||||
@Bean
|
||||
@Primary
|
||||
public UserDao userDao(UserDao userDao) {
|
||||
return Mockito.mock(UserDao.class, AdditionalAnswers.delegatesTo(userDao));
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
afterTestEntityDaoRemoveByIdWithException(userDao);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -42,8 +42,6 @@ import java.util.UUID;
|
||||
*/
|
||||
public interface AlarmDao extends Dao<Alarm> {
|
||||
|
||||
Boolean deleteAlarm(TenantId tenantId, Alarm alarm);
|
||||
|
||||
ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type);
|
||||
|
||||
ListenableFuture<Alarm> findAlarmByIdAsync(TenantId tenantId, UUID key);
|
||||
|
||||
@ -153,7 +153,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
||||
}
|
||||
AlarmOperationResult result = new AlarmOperationResult(alarm, true, new ArrayList<>(getPropagationEntityIds(alarm)));
|
||||
deleteEntityRelations(tenantId, alarm.getId());
|
||||
alarmDao.deleteAlarm(tenantId, alarm);
|
||||
alarmDao.removeById(tenantId, alarm.getUuidId());
|
||||
return result;
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@ -78,11 +78,6 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
|
||||
return alarmRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteAlarm(TenantId tenantId, Alarm alarm) {
|
||||
return removeById(tenantId, alarm.getUuidId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) {
|
||||
return service.submit(() -> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user