fix_bug: Entity delete with delete relations, Dashboard delete refactoring
This commit is contained in:
parent
c6535a128e
commit
2bb2429bcf
@ -711,25 +711,25 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
|||||||
return Futures.allAsList(futures);
|
return Futures.allAsList(futures);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tesEntityDaoWithRelationsOk(EntityId entityIdFrom, EntityId entityTo, String urlDelete) throws Exception {
|
protected void testEntityDaoWithRelationsOk(EntityId entityIdFrom, EntityId entityTo, String urlDelete) throws Exception {
|
||||||
createEntityRelation(entityIdFrom, entityTo, "TEST_TYPE");
|
createEntityRelation(entityIdFrom, entityTo, "TEST_TYPE");
|
||||||
assertThat(getRelationsTo(entityTo)).hasSize(1);
|
assertThat(findRelationsByTo(entityTo)).hasSize(1);
|
||||||
|
|
||||||
doDelete(urlDelete).andExpect(status().isOk());
|
doDelete(urlDelete).andExpect(status().isOk());
|
||||||
|
|
||||||
assertThat(getRelationsTo(entityTo)).hasSize(0);
|
assertThat(findRelationsByTo(entityTo)).hasSize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> void tesEntityDaoWithRelationsTransactionalException(Dao<T> dao, EntityId entityIdFrom, EntityId entityTo,
|
protected <T> void testEntityDaoWithRelationsTransactionalException(Dao<T> dao, EntityId entityIdFrom, EntityId entityTo,
|
||||||
String urlDelete) throws Exception {
|
String urlDelete) throws Exception {
|
||||||
entityDaoRemoveByIdWithException (dao);
|
entityDaoRemoveByIdWithException (dao);
|
||||||
createEntityRelation(entityIdFrom, entityTo, "TEST_TRANSACTIONAL_TYPE");
|
createEntityRelation(entityIdFrom, entityTo, "TEST_TRANSACTIONAL_TYPE");
|
||||||
assertThat(getRelationsTo(entityTo)).hasSize(1);
|
assertThat(findRelationsByTo(entityTo)).hasSize(1);
|
||||||
|
|
||||||
doDelete(urlDelete)
|
doDelete(urlDelete)
|
||||||
.andExpect(status().isInternalServerError());
|
.andExpect(status().isInternalServerError());
|
||||||
|
|
||||||
assertThat(getRelationsTo(entityTo)).hasSize(1);
|
assertThat(findRelationsByTo(entityTo)).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> void entityDaoRemoveByIdWithException (Dao<T> dao) {
|
protected <T> void entityDaoRemoveByIdWithException (Dao<T> dao) {
|
||||||
@ -746,7 +746,7 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
|
|||||||
doPost("/api/relation", relation);
|
doPost("/api/relation", relation);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<EntityRelation> getRelationsTo(EntityId entityId) throws Exception {
|
protected List<EntityRelation> findRelationsByTo(EntityId entityId) throws Exception {
|
||||||
String url = String.format("/api/relations?toId=%s&toType=%s", entityId.getId(), entityId.getEntityType().name());
|
String url = String.format("/api/relations?toId=%s&toType=%s", entityId.getId(), entityId.getEntityType().name());
|
||||||
MvcResult mvcResult = doGet(url).andReturn();
|
MvcResult mvcResult = doGet(url).andReturn();
|
||||||
|
|
||||||
|
|||||||
@ -85,35 +85,6 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSaveDashboard() throws Exception {
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
|
||||||
|
|
||||||
String title = "My dashboard";
|
|
||||||
Dashboard savedDashboard = createDashboard(title);
|
|
||||||
|
|
||||||
testNotifyEntityOneTimeMsgToEdgeServiceNever(savedDashboard, savedDashboard.getId(), savedDashboard.getId(), savedTenant.getId(),
|
|
||||||
tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED);
|
|
||||||
|
|
||||||
Assert.assertNotNull(savedDashboard);
|
|
||||||
Assert.assertNotNull(savedDashboard.getId());
|
|
||||||
Assert.assertTrue(savedDashboard.getCreatedTime() > 0);
|
|
||||||
Assert.assertEquals(savedTenant.getId(), savedDashboard.getTenantId());
|
|
||||||
Assert.assertEquals(title, savedDashboard.getTitle());
|
|
||||||
|
|
||||||
savedDashboard.setTitle("My new dashboard");
|
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
|
||||||
|
|
||||||
doPost("/api/dashboard", savedDashboard, Dashboard.class);
|
|
||||||
|
|
||||||
testNotifyEntityAllOneTime(savedDashboard, savedDashboard.getId(), savedDashboard.getId(), savedTenant.getId(),
|
|
||||||
tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.UPDATED);
|
|
||||||
|
|
||||||
Dashboard foundDashboard = doGet("/api/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class);
|
|
||||||
Assert.assertEquals(foundDashboard.getTitle(), savedDashboard.getTitle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveDashboardInfoWithViolationOfValidation() throws Exception {
|
public void testSaveDashboardInfoWithViolationOfValidation() throws Exception {
|
||||||
Dashboard dashboard = new Dashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
@ -126,6 +97,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
.andExpect(status().isBadRequest())
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(statusReason(containsString(msgError)));
|
.andExpect(statusReason(containsString(msgError)));
|
||||||
|
|
||||||
|
dashboard.setTenantId(savedTenant.getId());
|
||||||
testNotifyEntityEqualsOneTimeServiceNeverError(dashboard, savedTenant.getId(),
|
testNotifyEntityEqualsOneTimeServiceNeverError(dashboard, savedTenant.getId(),
|
||||||
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError));
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
@ -133,7 +105,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateDashboardFromDifferentTenant() throws Exception {
|
public void testUpdateDashboardFromDifferentTenant() throws Exception {
|
||||||
Dashboard savedDashboard = createDashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("My dashboard");
|
||||||
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
|
|
||||||
loginDifferentTenant();
|
loginDifferentTenant();
|
||||||
|
|
||||||
@ -148,7 +122,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindDashboardById() throws Exception {
|
public void testFindDashboardById() throws Exception {
|
||||||
Dashboard savedDashboard = createDashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("My dashboard");
|
||||||
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
Dashboard foundDashboard = doGet("/api/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class);
|
Dashboard foundDashboard = doGet("/api/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class);
|
||||||
Assert.assertNotNull(foundDashboard);
|
Assert.assertNotNull(foundDashboard);
|
||||||
Assert.assertEquals(savedDashboard, foundDashboard);
|
Assert.assertEquals(savedDashboard, foundDashboard);
|
||||||
@ -156,7 +132,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteDashboard() throws Exception {
|
public void testDeleteDashboard() throws Exception {
|
||||||
Dashboard savedDashboard = createDashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("My dashboard");
|
||||||
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
|
|
||||||
@ -189,7 +167,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAssignUnassignDashboardToCustomer() throws Exception {
|
public void testAssignUnassignDashboardToCustomer() throws Exception {
|
||||||
Dashboard savedDashboard = createDashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("My dashboard");
|
||||||
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
|
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTitle("My customer");
|
customer.setTitle("My customer");
|
||||||
@ -227,7 +207,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAssignDashboardToNonExistentCustomer() throws Exception {
|
public void testAssignDashboardToNonExistentCustomer() throws Exception {
|
||||||
Dashboard savedDashboard = createDashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("My dashboard");
|
||||||
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
|
|
||||||
String customerIdStr = Uuids.timeBased().toString();
|
String customerIdStr = Uuids.timeBased().toString();
|
||||||
doPost("/api/customer/" + customerIdStr
|
doPost("/api/customer/" + customerIdStr
|
||||||
@ -263,7 +245,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
login(tenantAdmin.getEmail(), "testPassword1");
|
login(tenantAdmin.getEmail(), "testPassword1");
|
||||||
|
|
||||||
Dashboard savedDashboard = createDashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("My dashboard");
|
||||||
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
|
|
||||||
doPost("/api/customer/" + savedCustomer.getId().getId().toString()
|
doPost("/api/customer/" + savedCustomer.getId().getId().toString()
|
||||||
+ "/dashboard/" + savedDashboard.getId().getId().toString())
|
+ "/dashboard/" + savedDashboard.getId().getId().toString())
|
||||||
@ -293,7 +277,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
int cntEntity = 173;
|
int cntEntity = 173;
|
||||||
for (int i = 0; i < cntEntity; i++) {
|
for (int i = 0; i < cntEntity; i++) {
|
||||||
dashboards.add(new DashboardInfo(createDashboard("Dashboard" + i)));
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("Dashboard" + i);
|
||||||
|
dashboards.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
testNotifyManyEntityManyTimeMsgToEdgeServiceNever(new Dashboard(), new Dashboard(),
|
testNotifyManyEntityManyTimeMsgToEdgeServiceNever(new Dashboard(), new Dashboard(),
|
||||||
@ -325,19 +311,24 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
List<DashboardInfo> dashboardsTitle1 = new ArrayList<>();
|
List<DashboardInfo> dashboardsTitle1 = new ArrayList<>();
|
||||||
int cntEntity = 134;
|
int cntEntity = 134;
|
||||||
for (int i = 0; i < cntEntity; i++) {
|
for (int i = 0; i < cntEntity; i++) {
|
||||||
|
Dashboard dashboard = new Dashboard();
|
||||||
String suffix = StringUtils.randomAlphanumeric((int) (Math.random() * 15));
|
String suffix = StringUtils.randomAlphanumeric((int) (Math.random() * 15));
|
||||||
String title = title1 + suffix;
|
String title = title1 + suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
dashboardsTitle1.add(new DashboardInfo(createDashboard(title)));
|
dashboard.setTitle(title);
|
||||||
}
|
dashboardsTitle1.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class)));
|
||||||
|
}
|
||||||
String title2 = "Dashboard title 2";
|
String title2 = "Dashboard title 2";
|
||||||
List<DashboardInfo> dashboardsTitle2 = new ArrayList<>();
|
List<DashboardInfo> dashboardsTitle2 = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < 112; i++) {
|
for (int i = 0; i < 112; i++) {
|
||||||
|
Dashboard dashboard = new Dashboard();
|
||||||
String suffix = StringUtils.randomAlphanumeric((int) (Math.random() * 15));
|
String suffix = StringUtils.randomAlphanumeric((int) (Math.random() * 15));
|
||||||
String title = title2 + suffix;
|
String title = title2 + suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
dashboardsTitle2.add(new DashboardInfo(createDashboard(title))); }
|
dashboard.setTitle(title);
|
||||||
|
dashboardsTitle2.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class)));
|
||||||
|
}
|
||||||
|
|
||||||
List<DashboardInfo> loadedDashboardsTitle1 = new ArrayList<>();
|
List<DashboardInfo> loadedDashboardsTitle1 = new ArrayList<>();
|
||||||
PageLink pageLink = new PageLink(15, 0, title1);
|
PageLink pageLink = new PageLink(15, 0, title1);
|
||||||
@ -417,7 +408,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
int cntEntity = 173;
|
int cntEntity = 173;
|
||||||
List<DashboardInfo> dashboards = new ArrayList<>();
|
List<DashboardInfo> dashboards = new ArrayList<>();
|
||||||
for (int i = 0; i < cntEntity; i++) {
|
for (int i = 0; i < cntEntity; i++) {
|
||||||
Dashboard dashboard = createDashboard("Dashboard" + i);
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("Dashboard" + i);
|
||||||
|
dashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
dashboards.add(new DashboardInfo(doPost("/api/customer/" + customerId.getId().toString()
|
dashboards.add(new DashboardInfo(doPost("/api/customer/" + customerId.getId().toString()
|
||||||
+ "/dashboard/" + dashboard.getId().getId().toString(), Dashboard.class)));
|
+ "/dashboard/" + dashboard.getId().getId().toString(), Dashboard.class)));
|
||||||
}
|
}
|
||||||
@ -450,7 +443,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
Edge edge = constructEdge("My edge", "default");
|
Edge edge = constructEdge("My edge", "default");
|
||||||
Edge savedEdge = doPost("/api/edge", edge, Edge.class);
|
Edge savedEdge = doPost("/api/edge", edge, Edge.class);
|
||||||
|
|
||||||
Dashboard savedDashboard = createDashboard();
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setTitle("My dashboard");
|
||||||
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
|
|
||||||
Mockito.reset(tbClusterService, auditLogService);
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
|
|
||||||
@ -479,14 +474,14 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteDashboardWithRelationsOk() throws Exception {
|
public void testDeleteDashboardWithRelationsOk() throws Exception {
|
||||||
DashboardId dashboardId = createDashboard().getId();
|
DashboardId dashboardId = createDashboard("Dashboard for Test WithRelationsOk").getId();
|
||||||
tesEntityDaoWithRelationsOk(savedTenant.getId(), dashboardId, "/api/dashboard/" + dashboardId);
|
testEntityDaoWithRelationsOk(savedTenant.getId(), dashboardId, "/api/dashboard/" + dashboardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteDashboardWithRelationsTransactionalException() throws Exception {
|
public void testDeleteDashboardWithRelationsTransactionalException() throws Exception {
|
||||||
DashboardId dashboardId = createDashboard().getId();
|
DashboardId dashboardId = createDashboard("Dashboard for Test WithRelations Transactional Exception").getId();
|
||||||
tesEntityDaoWithRelationsTransactionalException(dashboardDao, savedTenant.getId(), dashboardId, "/api/dashboard/" + dashboardId);
|
testEntityDaoWithRelationsTransactionalException(dashboardDao, savedTenant.getId(), dashboardId, "/api/dashboard/" + dashboardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dashboard createDashboard(String title) {
|
private Dashboard createDashboard(String title) {
|
||||||
@ -494,11 +489,4 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
|
|||||||
dashboard.setTitle(title);
|
dashboard.setTitle(title);
|
||||||
return doPost("/api/dashboard", dashboard, Dashboard.class);
|
return doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dashboard createDashboard() {
|
|
||||||
String title = "My dashboard";
|
|
||||||
Dashboard dashboard = new Dashboard();
|
|
||||||
dashboard.setTitle(title);
|
|
||||||
return doPost("/api/dashboard", dashboard, Dashboard.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user