|
|
@ -22,16 +22,19 @@ import org.junit.After; |
|
|
import org.junit.Assert; |
|
|
import org.junit.Assert; |
|
|
import org.junit.Before; |
|
|
import org.junit.Before; |
|
|
import org.junit.Test; |
|
|
import org.junit.Test; |
|
|
|
|
|
import org.mockito.Mockito; |
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
import org.thingsboard.server.common.data.Dashboard; |
|
|
import org.thingsboard.server.common.data.Dashboard; |
|
|
import org.thingsboard.server.common.data.DashboardInfo; |
|
|
import org.thingsboard.server.common.data.DashboardInfo; |
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
import org.thingsboard.server.common.data.User; |
|
|
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.edge.Edge; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Collections; |
|
|
import java.util.Collections; |
|
|
@ -41,54 +44,66 @@ import static org.hamcrest.Matchers.containsString; |
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
|
|
|
|
|
public abstract class BaseDashboardControllerTest extends AbstractControllerTest { |
|
|
public abstract class BaseDashboardControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
|
private IdComparator<DashboardInfo> idComparator = new IdComparator<>(); |
|
|
private IdComparator<DashboardInfo> idComparator = new IdComparator<>(); |
|
|
|
|
|
|
|
|
private Tenant savedTenant; |
|
|
private Tenant savedTenant; |
|
|
private User tenantAdmin; |
|
|
private User tenantAdmin; |
|
|
|
|
|
|
|
|
@Before |
|
|
@Before |
|
|
public void beforeTest() throws Exception { |
|
|
public void beforeTest() throws Exception { |
|
|
loginSysAdmin(); |
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
|
Tenant tenant = new Tenant(); |
|
|
Tenant tenant = new Tenant(); |
|
|
tenant.setTitle("My tenant"); |
|
|
tenant.setTitle("My tenant"); |
|
|
savedTenant = doPost("/api/tenant", tenant, Tenant.class); |
|
|
savedTenant = doPost("/api/tenant", tenant, Tenant.class); |
|
|
Assert.assertNotNull(savedTenant); |
|
|
Assert.assertNotNull(savedTenant); |
|
|
|
|
|
|
|
|
tenantAdmin = new User(); |
|
|
tenantAdmin = new User(); |
|
|
tenantAdmin.setAuthority(Authority.TENANT_ADMIN); |
|
|
tenantAdmin.setAuthority(Authority.TENANT_ADMIN); |
|
|
tenantAdmin.setTenantId(savedTenant.getId()); |
|
|
tenantAdmin.setTenantId(savedTenant.getId()); |
|
|
tenantAdmin.setEmail("tenant2@thingsboard.org"); |
|
|
tenantAdmin.setEmail("tenant2@thingsboard.org"); |
|
|
tenantAdmin.setFirstName("Joe"); |
|
|
tenantAdmin.setFirstName("Joe"); |
|
|
tenantAdmin.setLastName("Downs"); |
|
|
tenantAdmin.setLastName("Downs"); |
|
|
|
|
|
|
|
|
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); |
|
|
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@After |
|
|
@After |
|
|
public void afterTest() throws Exception { |
|
|
public void afterTest() throws Exception { |
|
|
loginSysAdmin(); |
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
|
doDelete("/api/tenant/"+savedTenant.getId().getId().toString()) |
|
|
doDelete("/api/tenant/" + savedTenant.getId().getId().toString()) |
|
|
.andExpect(status().isOk()); |
|
|
.andExpect(status().isOk()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testSaveDashboard() throws Exception { |
|
|
public void testSaveDashboard() throws Exception { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityOneTimeMsgToEdgeServiceNever(savedDashboard, savedDashboard.getId(), savedDashboard.getId(), savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED); |
|
|
|
|
|
|
|
|
Assert.assertNotNull(savedDashboard); |
|
|
Assert.assertNotNull(savedDashboard); |
|
|
Assert.assertNotNull(savedDashboard.getId()); |
|
|
Assert.assertNotNull(savedDashboard.getId()); |
|
|
Assert.assertTrue(savedDashboard.getCreatedTime() > 0); |
|
|
Assert.assertTrue(savedDashboard.getCreatedTime() > 0); |
|
|
Assert.assertEquals(savedTenant.getId(), savedDashboard.getTenantId()); |
|
|
Assert.assertEquals(savedTenant.getId(), savedDashboard.getTenantId()); |
|
|
Assert.assertEquals(dashboard.getTitle(), savedDashboard.getTitle()); |
|
|
Assert.assertEquals(dashboard.getTitle(), savedDashboard.getTitle()); |
|
|
|
|
|
|
|
|
savedDashboard.setTitle("My new dashboard"); |
|
|
savedDashboard.setTitle("My new dashboard"); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
doPost("/api/dashboard", savedDashboard, Dashboard.class); |
|
|
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); |
|
|
Dashboard foundDashboard = doGet("/api/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
Assert.assertEquals(foundDashboard.getTitle(), savedDashboard.getTitle()); |
|
|
Assert.assertEquals(foundDashboard.getTitle(), savedDashboard.getTitle()); |
|
|
} |
|
|
} |
|
|
@ -97,7 +112,16 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
public void testSaveDashboardInfoWithViolationOfValidation() throws Exception { |
|
|
public void testSaveDashboardInfoWithViolationOfValidation() throws Exception { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle(RandomStringUtils.randomAlphabetic(300)); |
|
|
dashboard.setTitle(RandomStringUtils.randomAlphabetic(300)); |
|
|
doPost("/api/dashboard", dashboard).andExpect(statusReason(containsString("length of title must be equal or less than 255"))); |
|
|
String msgError = "length of title must be equal or less than 255"; |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
doPost("/api/dashboard", dashboard).andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
|
|
|
|
dashboard.setTenantId(savedTenant.getId()); |
|
|
|
|
|
testNotifyEntityEqualsOneTimeError(dashboard, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError)); |
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -107,10 +131,16 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
|
|
|
|
|
loginDifferentTenant(); |
|
|
loginDifferentTenant(); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
doPost("/api/dashboard", savedDashboard, Dashboard.class, status().isForbidden()); |
|
|
doPost("/api/dashboard", savedDashboard, Dashboard.class, status().isForbidden()); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityNever(savedDashboard.getId(), savedDashboard); |
|
|
|
|
|
|
|
|
deleteDifferentTenant(); |
|
|
deleteDifferentTenant(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testFindDashboardById() throws Exception { |
|
|
public void testFindDashboardById() throws Exception { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
@ -120,48 +150,73 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
Assert.assertNotNull(foundDashboard); |
|
|
Assert.assertNotNull(foundDashboard); |
|
|
Assert.assertEquals(savedDashboard, foundDashboard); |
|
|
Assert.assertEquals(savedDashboard, foundDashboard); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testDeleteDashboard() throws Exception { |
|
|
public void testDeleteDashboard() throws Exception { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
|
|
|
|
|
doDelete("/api/dashboard/"+savedDashboard.getId().getId().toString()) |
|
|
|
|
|
.andExpect(status().isOk()); |
|
|
|
|
|
|
|
|
|
|
|
doGet("/api/dashboard/"+savedDashboard.getId().getId().toString()) |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
.andExpect(status().isNotFound()); |
|
|
|
|
|
|
|
|
doDelete("/api/dashboard/" + savedDashboard.getId().getId().toString()).andExpect(status().isOk()); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityOneTimeMsgToEdgeServiceNever(savedDashboard, savedDashboard.getId(), savedDashboard.getId(), |
|
|
|
|
|
savedDashboard.getTenantId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.DELETED, |
|
|
|
|
|
savedDashboard.getId().getId().toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doGet("/api/dashboard/" + savedDashboard.getId().getId().toString()) |
|
|
|
|
|
.andExpect(status().isNotFound()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testSaveDashboardWithEmptyTitle() throws Exception { |
|
|
public void testSaveDashboardWithEmptyTitle() throws Exception { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
|
|
String msgError = "Dashboard title should be specified"; |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
doPost("/api/dashboard", dashboard) |
|
|
doPost("/api/dashboard", dashboard) |
|
|
.andExpect(status().isBadRequest()) |
|
|
.andExpect(status().isBadRequest()) |
|
|
.andExpect(statusReason(containsString("Dashboard title should be specified"))); |
|
|
.andExpect(statusReason(containsString(msgError))); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityEqualsOneTimeError(dashboard, savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(msgError)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testAssignUnassignDashboardToCustomer() throws Exception { |
|
|
public void testAssignUnassignDashboardToCustomer() throws Exception { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
|
|
|
|
|
Customer customer = new Customer(); |
|
|
Customer customer = new Customer(); |
|
|
customer.setTitle("My customer"); |
|
|
customer.setTitle("My customer"); |
|
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
|
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
|
|
|
|
|
|
|
|
Dashboard assignedDashboard = doPost("/api/customer/" + savedCustomer.getId().getId().toString() |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
Dashboard assignedDashboard = doPost("/api/customer/" + savedCustomer.getId().getId().toString() |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
|
|
|
|
|
Assert.assertTrue(assignedDashboard.getAssignedCustomers().contains(savedCustomer.toShortCustomerInfo())); |
|
|
Assert.assertTrue(assignedDashboard.getAssignedCustomers().contains(savedCustomer.toShortCustomerInfo())); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityAllOneTimeLogEntityActionEntityEqClass(assignedDashboard, assignedDashboard.getId(), assignedDashboard.getId(), |
|
|
|
|
|
savedTenant.getId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ASSIGNED_TO_CUSTOMER, |
|
|
|
|
|
savedDashboard.getId().getId().toString(), savedCustomer.getId().getId().toString(), savedCustomer.getTitle()); |
|
|
|
|
|
|
|
|
Dashboard foundDashboard = doGet("/api/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
Dashboard foundDashboard = doGet("/api/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
Assert.assertTrue(foundDashboard.getAssignedCustomers().contains(savedCustomer.toShortCustomerInfo())); |
|
|
Assert.assertTrue(foundDashboard.getAssignedCustomers().contains(savedCustomer.toShortCustomerInfo())); |
|
|
|
|
|
|
|
|
Dashboard unassignedDashboard = |
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
doDelete("/api/customer/"+savedCustomer.getId().getId().toString()+"/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
|
|
|
|
|
Dashboard unassignedDashboard = |
|
|
|
|
|
doDelete("/api/customer/" + savedCustomer.getId().getId().toString() + "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityAllOneTimeLogEntityActionEntityEqClass(assignedDashboard, assignedDashboard.getId(), assignedDashboard.getId(), |
|
|
|
|
|
savedTenant.getId(), savedCustomer.getId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.UNASSIGNED_FROM_CUSTOMER, |
|
|
|
|
|
savedDashboard.getId().getId().toString(), savedCustomer.getId().getId().toString(), savedCustomer.getTitle()); |
|
|
|
|
|
|
|
|
Assert.assertTrue(unassignedDashboard.getAssignedCustomers() == null || unassignedDashboard.getAssignedCustomers().isEmpty()); |
|
|
Assert.assertTrue(unassignedDashboard.getAssignedCustomers() == null || unassignedDashboard.getAssignedCustomers().isEmpty()); |
|
|
|
|
|
|
|
|
@ -169,22 +224,25 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
|
Assert.assertTrue(foundDashboard.getAssignedCustomers() == null || foundDashboard.getAssignedCustomers().isEmpty()); |
|
|
Assert.assertTrue(foundDashboard.getAssignedCustomers() == null || foundDashboard.getAssignedCustomers().isEmpty()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testAssignDashboardToNonExistentCustomer() throws Exception { |
|
|
public void testAssignDashboardToNonExistentCustomer() throws Exception { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
|
|
|
|
|
doPost("/api/customer/" + Uuids.timeBased().toString() |
|
|
doPost("/api/customer/" + Uuids.timeBased().toString() |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString()) |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString()) |
|
|
.andExpect(status().isNotFound()); |
|
|
.andExpect(status().isNotFound()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
testNotifyEntityNever(savedDashboard.getId(), savedDashboard); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testAssignDashboardToCustomerFromDifferentTenant() throws Exception { |
|
|
public void testAssignDashboardToCustomerFromDifferentTenant() throws Exception { |
|
|
loginSysAdmin(); |
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
|
Tenant tenant2 = new Tenant(); |
|
|
Tenant tenant2 = new Tenant(); |
|
|
tenant2.setTitle("Different tenant"); |
|
|
tenant2.setTitle("Different tenant"); |
|
|
Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class); |
|
|
Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class); |
|
|
@ -196,100 +254,121 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
tenantAdmin2.setEmail("tenant3@thingsboard.org"); |
|
|
tenantAdmin2.setEmail("tenant3@thingsboard.org"); |
|
|
tenantAdmin2.setFirstName("Joe"); |
|
|
tenantAdmin2.setFirstName("Joe"); |
|
|
tenantAdmin2.setLastName("Downs"); |
|
|
tenantAdmin2.setLastName("Downs"); |
|
|
|
|
|
|
|
|
tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1"); |
|
|
createUserAndLogin(tenantAdmin2, "testPassword1"); |
|
|
|
|
|
|
|
|
Customer customer = new Customer(); |
|
|
Customer customer = new Customer(); |
|
|
customer.setTitle("Different customer"); |
|
|
customer.setTitle("Different customer"); |
|
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
|
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
|
|
|
|
|
|
|
|
login(tenantAdmin.getEmail(), "testPassword1"); |
|
|
login(tenantAdmin.getEmail(), "testPassword1"); |
|
|
|
|
|
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
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()) |
|
|
.andExpect(status().isForbidden()); |
|
|
.andExpect(status().isForbidden()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
testNotifyEntityNever(savedDashboard.getId(), savedDashboard); |
|
|
|
|
|
|
|
|
|
|
|
doDelete("/api/tenant/" + savedTenant2.getId().getId().toString()) |
|
|
|
|
|
.andExpect(status().isForbidden()); |
|
|
|
|
|
testNotifyEntityNever(savedDashboard.getId(), savedDashboard); |
|
|
|
|
|
|
|
|
loginSysAdmin(); |
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
|
doDelete("/api/tenant/"+savedTenant2.getId().getId().toString()) |
|
|
doDelete("/api/tenant/" + savedTenant2.getId().getId().toString()) |
|
|
.andExpect(status().isOk()); |
|
|
.andExpect(status().isOk()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testFindTenantDashboards() throws Exception { |
|
|
public void testFindTenantDashboards() throws Exception { |
|
|
List<DashboardInfo> dashboards = new ArrayList<>(); |
|
|
List<DashboardInfo> dashboards = new ArrayList<>(); |
|
|
for (int i=0;i<173;i++) { |
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
int cntEntity = 173; |
|
|
|
|
|
for (int i = 0; i < cntEntity; i++) { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle("Dashboard"+i); |
|
|
dashboard.setTitle("Dashboard" + i); |
|
|
dashboards.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class))); |
|
|
dashboards.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testNotifyManyEntityManyTimeMsgToEdgeServiceNever(new Dashboard(), new Dashboard(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.ADDED, cntEntity); |
|
|
|
|
|
|
|
|
List<DashboardInfo> loadedDashboards = new ArrayList<>(); |
|
|
List<DashboardInfo> loadedDashboards = new ArrayList<>(); |
|
|
PageLink pageLink = new PageLink(24); |
|
|
PageLink pageLink = new PageLink(24); |
|
|
PageData<DashboardInfo> pageData = null; |
|
|
PageData<DashboardInfo> pageData = null; |
|
|
do { |
|
|
do { |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
new TypeReference<PageData<DashboardInfo>>(){}, pageLink); |
|
|
new TypeReference<PageData<DashboardInfo>>() { |
|
|
|
|
|
}, pageLink); |
|
|
loadedDashboards.addAll(pageData.getData()); |
|
|
loadedDashboards.addAll(pageData.getData()); |
|
|
if (pageData.hasNext()) { |
|
|
if (pageData.hasNext()) { |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
} |
|
|
} |
|
|
} while (pageData.hasNext()); |
|
|
} while (pageData.hasNext()); |
|
|
|
|
|
|
|
|
Collections.sort(dashboards, idComparator); |
|
|
Collections.sort(dashboards, idComparator); |
|
|
Collections.sort(loadedDashboards, idComparator); |
|
|
Collections.sort(loadedDashboards, idComparator); |
|
|
|
|
|
|
|
|
Assert.assertEquals(dashboards, loadedDashboards); |
|
|
Assert.assertEquals(dashboards, loadedDashboards); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testFindTenantDashboardsByTitle() throws Exception { |
|
|
public void testFindTenantDashboardsByTitle() throws Exception { |
|
|
String title1 = "Dashboard title 1"; |
|
|
String title1 = "Dashboard title 1"; |
|
|
List<DashboardInfo> dashboardsTitle1 = new ArrayList<>(); |
|
|
List<DashboardInfo> dashboardsTitle1 = new ArrayList<>(); |
|
|
for (int i=0;i<134;i++) { |
|
|
int cntEntity = 134; |
|
|
|
|
|
for (int i = 0; i < cntEntity; i++) { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15)); |
|
|
String suffix = RandomStringUtils.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(); |
|
|
dashboard.setTitle(title); |
|
|
dashboard.setTitle(title); |
|
|
dashboardsTitle1.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class))); |
|
|
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(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15)); |
|
|
String suffix = RandomStringUtils.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(); |
|
|
dashboard.setTitle(title); |
|
|
dashboard.setTitle(title); |
|
|
dashboardsTitle2.add(new DashboardInfo(doPost("/api/dashboard", dashboard, Dashboard.class))); |
|
|
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); |
|
|
PageData<DashboardInfo> pageData = null; |
|
|
PageData<DashboardInfo> pageData = null; |
|
|
do { |
|
|
do { |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
new TypeReference<PageData<DashboardInfo>>(){}, pageLink); |
|
|
new TypeReference<PageData<DashboardInfo>>() { |
|
|
|
|
|
}, pageLink); |
|
|
loadedDashboardsTitle1.addAll(pageData.getData()); |
|
|
loadedDashboardsTitle1.addAll(pageData.getData()); |
|
|
if (pageData.hasNext()) { |
|
|
if (pageData.hasNext()) { |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
} |
|
|
} |
|
|
} while (pageData.hasNext()); |
|
|
} while (pageData.hasNext()); |
|
|
|
|
|
|
|
|
Collections.sort(dashboardsTitle1, idComparator); |
|
|
Collections.sort(dashboardsTitle1, idComparator); |
|
|
Collections.sort(loadedDashboardsTitle1, idComparator); |
|
|
Collections.sort(loadedDashboardsTitle1, idComparator); |
|
|
|
|
|
|
|
|
Assert.assertEquals(dashboardsTitle1, loadedDashboardsTitle1); |
|
|
Assert.assertEquals(dashboardsTitle1, loadedDashboardsTitle1); |
|
|
|
|
|
|
|
|
List<DashboardInfo> loadedDashboardsTitle2 = new ArrayList<>(); |
|
|
List<DashboardInfo> loadedDashboardsTitle2 = new ArrayList<>(); |
|
|
pageLink = new PageLink(4, 0, title2); |
|
|
pageLink = new PageLink(4, 0, title2); |
|
|
do { |
|
|
do { |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
new TypeReference<PageData<DashboardInfo>>(){}, pageLink); |
|
|
new TypeReference<PageData<DashboardInfo>>() { |
|
|
|
|
|
}, pageLink); |
|
|
loadedDashboardsTitle2.addAll(pageData.getData()); |
|
|
loadedDashboardsTitle2.addAll(pageData.getData()); |
|
|
if (pageData.hasNext()) { |
|
|
if (pageData.hasNext()) { |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
@ -298,63 +377,79 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
|
|
|
|
|
|
Collections.sort(dashboardsTitle2, idComparator); |
|
|
Collections.sort(dashboardsTitle2, idComparator); |
|
|
Collections.sort(loadedDashboardsTitle2, idComparator); |
|
|
Collections.sort(loadedDashboardsTitle2, idComparator); |
|
|
|
|
|
|
|
|
Assert.assertEquals(dashboardsTitle2, loadedDashboardsTitle2); |
|
|
Assert.assertEquals(dashboardsTitle2, loadedDashboardsTitle2); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
for (DashboardInfo dashboard : loadedDashboardsTitle1) { |
|
|
for (DashboardInfo dashboard : loadedDashboardsTitle1) { |
|
|
doDelete("/api/dashboard/"+dashboard.getId().getId().toString()) |
|
|
doDelete("/api/dashboard/" + dashboard.getId().getId().toString()) |
|
|
.andExpect(status().isOk()); |
|
|
.andExpect(status().isOk()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testNotifyManyEntityManyTimeMsgToEdgeServiceNeverAdditionalInfoAny(new Dashboard(), new Dashboard(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.DELETED, cntEntity, 1); |
|
|
|
|
|
|
|
|
pageLink = new PageLink(4, 0, title1); |
|
|
pageLink = new PageLink(4, 0, title1); |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
new TypeReference<PageData<DashboardInfo>>(){}, pageLink); |
|
|
new TypeReference<PageData<DashboardInfo>>() { |
|
|
|
|
|
}, pageLink); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertEquals(0, pageData.getData().size()); |
|
|
Assert.assertEquals(0, pageData.getData().size()); |
|
|
|
|
|
|
|
|
for (DashboardInfo dashboard : loadedDashboardsTitle2) { |
|
|
for (DashboardInfo dashboard : loadedDashboardsTitle2) { |
|
|
doDelete("/api/dashboard/"+dashboard.getId().getId().toString()) |
|
|
doDelete("/api/dashboard/" + dashboard.getId().getId().toString()) |
|
|
.andExpect(status().isOk()); |
|
|
.andExpect(status().isOk()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pageLink = new PageLink(4, 0, title2); |
|
|
pageLink = new PageLink(4, 0, title2); |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
pageData = doGetTypedWithPageLink("/api/tenant/dashboards?", |
|
|
new TypeReference<PageData<DashboardInfo>>(){}, pageLink); |
|
|
new TypeReference<PageData<DashboardInfo>>() { |
|
|
|
|
|
}, pageLink); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertFalse(pageData.hasNext()); |
|
|
Assert.assertEquals(0, pageData.getData().size()); |
|
|
Assert.assertEquals(0, pageData.getData().size()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testFindCustomerDashboards() throws Exception { |
|
|
public void testFindCustomerDashboards() throws Exception { |
|
|
Customer customer = new Customer(); |
|
|
Customer customer = new Customer(); |
|
|
customer.setTitle("Test customer"); |
|
|
customer.setTitle("Test customer"); |
|
|
customer = doPost("/api/customer", customer, Customer.class); |
|
|
customer = doPost("/api/customer", customer, Customer.class); |
|
|
CustomerId customerId = customer.getId(); |
|
|
CustomerId customerId = customer.getId(); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
int cntEntity = 173; |
|
|
List<DashboardInfo> dashboards = new ArrayList<>(); |
|
|
List<DashboardInfo> dashboards = new ArrayList<>(); |
|
|
for (int i=0;i<173;i++) { |
|
|
for (int i = 0; i < cntEntity; i++) { |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
Dashboard dashboard = new Dashboard(); |
|
|
dashboard.setTitle("Dashboard"+i); |
|
|
dashboard.setTitle("Dashboard" + i); |
|
|
dashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
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))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testNotifyManyEntityManyTimeMsgToEdgeServiceEntityEqAny(new Dashboard(), new Dashboard(), |
|
|
|
|
|
savedTenant.getId(), tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), |
|
|
|
|
|
ActionType.ADDED, ActionType.ASSIGNED_TO_CUSTOMER, cntEntity, cntEntity*2); |
|
|
|
|
|
|
|
|
List<DashboardInfo> loadedDashboards = new ArrayList<>(); |
|
|
List<DashboardInfo> loadedDashboards = new ArrayList<>(); |
|
|
PageLink pageLink = new PageLink(21); |
|
|
PageLink pageLink = new PageLink(21); |
|
|
PageData<DashboardInfo> pageData = null; |
|
|
PageData<DashboardInfo> pageData = null; |
|
|
do { |
|
|
do { |
|
|
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/dashboards?", |
|
|
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/dashboards?", |
|
|
new TypeReference<PageData<DashboardInfo>>(){}, pageLink); |
|
|
new TypeReference<PageData<DashboardInfo>>() { |
|
|
|
|
|
}, pageLink); |
|
|
loadedDashboards.addAll(pageData.getData()); |
|
|
loadedDashboards.addAll(pageData.getData()); |
|
|
if (pageData.hasNext()) { |
|
|
if (pageData.hasNext()) { |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
pageLink = pageLink.nextPageLink(); |
|
|
} |
|
|
} |
|
|
} while (pageData.hasNext()); |
|
|
} while (pageData.hasNext()); |
|
|
|
|
|
|
|
|
Collections.sort(dashboards, idComparator); |
|
|
Collections.sort(dashboards, idComparator); |
|
|
Collections.sort(loadedDashboards, idComparator); |
|
|
Collections.sort(loadedDashboards, idComparator); |
|
|
|
|
|
|
|
|
Assert.assertEquals(dashboards, loadedDashboards); |
|
|
Assert.assertEquals(dashboards, loadedDashboards); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -367,11 +462,18 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
dashboard.setTitle("My dashboard"); |
|
|
dashboard.setTitle("My dashboard"); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
doPost("/api/edge/" + savedEdge.getId().getId().toString() |
|
|
doPost("/api/edge/" + savedEdge.getId().getId().toString() |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
|
|
|
|
|
|
|
|
testNotifyEntityAllOneTime(savedDashboard, savedDashboard.getId(), savedDashboard.getId(), savedTenant.getId(), |
|
|
|
|
|
tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ASSIGNED_TO_EDGE, |
|
|
|
|
|
savedDashboard.getId().getId().toString(), savedEdge.getId().getId().toString(), savedEdge.getName()); |
|
|
|
|
|
|
|
|
PageData<Dashboard> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboards?", |
|
|
PageData<Dashboard> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboards?", |
|
|
new TypeReference<PageData<Dashboard>>() {}, new PageLink(100)); |
|
|
new TypeReference<PageData<Dashboard>>() { |
|
|
|
|
|
}, new PageLink(100)); |
|
|
|
|
|
|
|
|
Assert.assertEquals(1, pageData.getData().size()); |
|
|
Assert.assertEquals(1, pageData.getData().size()); |
|
|
|
|
|
|
|
|
@ -379,7 +481,8 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
|
|
|
|
|
pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboards?", |
|
|
pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboards?", |
|
|
new TypeReference<PageData<Dashboard>>() {}, new PageLink(100)); |
|
|
new TypeReference<PageData<Dashboard>>() { |
|
|
|
|
|
}, new PageLink(100)); |
|
|
|
|
|
|
|
|
Assert.assertEquals(0, pageData.getData().size()); |
|
|
Assert.assertEquals(0, pageData.getData().size()); |
|
|
} |
|
|
} |
|
|
|