|
|
|
@ -22,6 +22,7 @@ import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.Dashboard; |
|
|
|
import org.thingsboard.server.common.data.DashboardInfo; |
|
|
|
@ -31,9 +32,11 @@ import org.thingsboard.server.common.data.User; |
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.DashboardId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
|
import org.thingsboard.server.dao.dashboard.DashboardDao; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -50,6 +53,9 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
private Tenant savedTenant; |
|
|
|
private User tenantAdmin; |
|
|
|
|
|
|
|
@SpyBean |
|
|
|
private DashboardDao dashboardDao; |
|
|
|
|
|
|
|
@Before |
|
|
|
public void beforeTest() throws Exception { |
|
|
|
loginSysAdmin(); |
|
|
|
@ -73,18 +79,18 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
public void afterTest() throws Exception { |
|
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
afterTestEntityDaoRemoveByIdWithException (dashboardDao); |
|
|
|
|
|
|
|
doDelete("/api/tenant/" + savedTenant.getId().getId().toString()) |
|
|
|
.andExpect(status().isOk()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveDashboard() throws Exception { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
String title = "My dashboard"; |
|
|
|
Dashboard savedDashboard = createDashboard(title); |
|
|
|
|
|
|
|
testNotifyEntityOneTimeMsgToEdgeServiceNever(savedDashboard, savedDashboard.getId(), savedDashboard.getId(), savedTenant.getId(), |
|
|
|
tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED); |
|
|
|
@ -93,7 +99,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
Assert.assertNotNull(savedDashboard.getId()); |
|
|
|
Assert.assertTrue(savedDashboard.getCreatedTime() > 0); |
|
|
|
Assert.assertEquals(savedTenant.getId(), savedDashboard.getTenantId()); |
|
|
|
Assert.assertEquals(dashboard.getTitle(), savedDashboard.getTitle()); |
|
|
|
Assert.assertEquals(title, savedDashboard.getTitle()); |
|
|
|
|
|
|
|
savedDashboard.setTitle("My new dashboard"); |
|
|
|
|
|
|
|
@ -120,7 +126,6 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
.andExpect(status().isBadRequest()) |
|
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
dashboard.setTenantId(savedTenant.getId()); |
|
|
|
testNotifyEntityEqualsOneTimeServiceNeverError(dashboard, savedTenant.getId(), |
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError)); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
@ -128,9 +133,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateDashboardFromDifferentTenant() throws Exception { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard savedDashboard = createDashboard(); |
|
|
|
|
|
|
|
loginDifferentTenant(); |
|
|
|
|
|
|
|
@ -145,9 +148,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFindDashboardById() throws Exception { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard savedDashboard = createDashboard(); |
|
|
|
Dashboard foundDashboard = doGet("/api/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
Assert.assertNotNull(foundDashboard); |
|
|
|
Assert.assertEquals(savedDashboard, foundDashboard); |
|
|
|
@ -155,9 +156,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteDashboard() throws Exception { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard savedDashboard = createDashboard(); |
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
@ -190,9 +189,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAssignUnassignDashboardToCustomer() throws Exception { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard savedDashboard = createDashboard(); |
|
|
|
|
|
|
|
Customer customer = new Customer(); |
|
|
|
customer.setTitle("My customer"); |
|
|
|
@ -230,9 +227,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAssignDashboardToNonExistentCustomer() throws Exception { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard savedDashboard = createDashboard(); |
|
|
|
|
|
|
|
String customerIdStr = Uuids.timeBased().toString(); |
|
|
|
doPost("/api/customer/" + customerIdStr |
|
|
|
@ -268,9 +263,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
login(tenantAdmin.getEmail(), "testPassword1"); |
|
|
|
|
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard savedDashboard = createDashboard(); |
|
|
|
|
|
|
|
doPost("/api/customer/" + savedCustomer.getId().getId().toString() |
|
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString()) |
|
|
|
@ -300,9 +293,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
int cntEntity = 173; |
|
|
|
for (int i = 0; i < cntEntity; i++) { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("Dashboard" + i); |
|
|
|
dashboards.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class))); |
|
|
|
dashboards.add(new DashboardInfo(createDashboard("Dashboard" + i))); |
|
|
|
} |
|
|
|
|
|
|
|
testNotifyManyEntityManyTimeMsgToEdgeServiceNever(new Dashboard(), new Dashboard(), |
|
|
|
@ -334,24 +325,19 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
List<DashboardInfo> dashboardsTitle1 = new ArrayList<>(); |
|
|
|
int cntEntity = 134; |
|
|
|
for (int i = 0; i < cntEntity; i++) { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
String suffix = StringUtils.randomAlphanumeric((int) (Math.random() * 15)); |
|
|
|
String title = title1 + suffix; |
|
|
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); |
|
|
|
dashboard.setTitle(title); |
|
|
|
dashboardsTitle1.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class))); |
|
|
|
} |
|
|
|
dashboardsTitle1.add(new DashboardInfo(createDashboard(title))); |
|
|
|
} |
|
|
|
String title2 = "Dashboard title 2"; |
|
|
|
List<DashboardInfo> dashboardsTitle2 = new ArrayList<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < 112; i++) { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
String suffix = StringUtils.randomAlphanumeric((int) (Math.random() * 15)); |
|
|
|
String title = title2 + suffix; |
|
|
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); |
|
|
|
dashboard.setTitle(title); |
|
|
|
dashboardsTitle2.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class))); |
|
|
|
} |
|
|
|
dashboardsTitle2.add(new DashboardInfo(createDashboard(title))); } |
|
|
|
|
|
|
|
List<DashboardInfo> loadedDashboardsTitle1 = new ArrayList<>(); |
|
|
|
PageLink pageLink = new PageLink(15, 0, title1); |
|
|
|
@ -431,9 +417,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
int cntEntity = 173; |
|
|
|
List<DashboardInfo> dashboards = new ArrayList<>(); |
|
|
|
for (int i = 0; i < cntEntity; i++) { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("Dashboard" + i); |
|
|
|
dashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard dashboard = createDashboard("Dashboard" + i); |
|
|
|
dashboards.add(new DashboardInfo(doPost("/api/customer/" + customerId.getId().toString() |
|
|
|
+ "/dashboard/" + dashboard.getId().getId().toString(), Dashboard.class))); |
|
|
|
} |
|
|
|
@ -466,9 +450,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
Edge edge = constructEdge("My edge", "default"); |
|
|
|
Edge savedEdge = doPost("/api/edge", edge, Edge.class); |
|
|
|
|
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
Dashboard savedDashboard = createDashboard(); |
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
@ -495,4 +477,28 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
Assert.assertEquals(0, pageData.getData().size()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteDashboardWithRelationsOk() throws Exception { |
|
|
|
DashboardId dashboardId = createDashboard().getId(); |
|
|
|
tesEntityDaoWithRelationsOk(savedTenant.getId(), dashboardId, "/api/dashboard/" + dashboardId); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteDashboardWithRelationsTransactionalException() throws Exception { |
|
|
|
DashboardId dashboardId = createDashboard().getId(); |
|
|
|
tesEntityDaoWithRelationsTransactionalException(dashboardDao, savedTenant.getId(), dashboardId, "/api/dashboard/" + dashboardId); |
|
|
|
} |
|
|
|
|
|
|
|
private Dashboard createDashboard(String title) { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle(title); |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|