|
|
|
@ -22,9 +22,12 @@ import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.test.web.servlet.ResultActions; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.Dashboard; |
|
|
|
import org.thingsboard.server.common.data.DataConstants; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
@ -33,6 +36,7 @@ import org.thingsboard.server.common.data.Tenant; |
|
|
|
import org.thingsboard.server.common.data.User; |
|
|
|
import org.thingsboard.server.common.data.alarm.Alarm; |
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
@ -76,6 +80,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. |
|
|
|
@DaoSqlTest |
|
|
|
public class EntityQueryControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
private static final String CUSTOMER_USER_EMAIL = "entityQueryCustomer@thingsboard.org"; |
|
|
|
private static final String TENANT_PASSWORD = "testPassword1"; |
|
|
|
private static final String CUSTOMER_USER_PASSWORD = "customer"; |
|
|
|
private static final String TENANT_EMAIL = "entityQueryTenant@thingsboard.org"; |
|
|
|
|
|
|
|
private Tenant savedTenant; |
|
|
|
private User tenantAdmin; |
|
|
|
|
|
|
|
@ -94,11 +103,11 @@ public class EntityQueryControllerTest extends AbstractControllerTest { |
|
|
|
tenantAdmin = new User(); |
|
|
|
tenantAdmin.setAuthority(Authority.TENANT_ADMIN); |
|
|
|
tenantAdmin.setTenantId(savedTenant.getId()); |
|
|
|
tenantAdmin.setEmail("tenant2@thingsboard.org"); |
|
|
|
tenantAdmin.setEmail(TENANT_EMAIL); |
|
|
|
tenantAdmin.setFirstName("Joe"); |
|
|
|
tenantAdmin.setLastName("Downs"); |
|
|
|
|
|
|
|
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); |
|
|
|
tenantAdmin = createUserAndLogin(tenantAdmin, TENANT_PASSWORD); |
|
|
|
} |
|
|
|
|
|
|
|
@After |
|
|
|
@ -807,6 +816,61 @@ public class EntityQueryControllerTest extends AbstractControllerTest { |
|
|
|
checkEntitiesByQuery(customerEntitiesQuery, 0, null, null); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFindCustomerDashboards() throws Exception { |
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
dashboard.setTitle("My dashboard"); |
|
|
|
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
|
|
|
|
|
|
|
Customer customer = new Customer(); |
|
|
|
customer.setTitle("My customer"); |
|
|
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
|
|
|
|
|
|
|
//assign dashboard
|
|
|
|
doPost("/api/customer/" + savedCustomer.getId().getId().toString() |
|
|
|
+ "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
|
|
|
|
// check entity data query by customer
|
|
|
|
User customerUser = new User(); |
|
|
|
customerUser.setAuthority(Authority.CUSTOMER_USER); |
|
|
|
customerUser.setTenantId(savedTenant.getId()); |
|
|
|
customerUser.setCustomerId(savedCustomer.getId()); |
|
|
|
customerUser.setEmail(CUSTOMER_USER_EMAIL); |
|
|
|
|
|
|
|
createUserAndLogin(customerUser, CUSTOMER_USER_PASSWORD); |
|
|
|
|
|
|
|
EntityTypeFilter filter = new EntityTypeFilter(); |
|
|
|
filter.setEntityType(EntityType.DASHBOARD); |
|
|
|
|
|
|
|
EntityDataSortOrder sortOrder = new EntityDataSortOrder( |
|
|
|
new EntityKey(EntityKeyType.ENTITY_FIELD, "createdTime"), EntityDataSortOrder.Direction.ASC); |
|
|
|
EntityDataPageLink pageLink = new EntityDataPageLink(10, 0, null, sortOrder); |
|
|
|
List<EntityKey> entityFields = Collections.singletonList(new EntityKey(EntityKeyType.ENTITY_FIELD, "name")); |
|
|
|
|
|
|
|
EntityDataQuery query = new EntityDataQuery(filter, pageLink, entityFields, null, null); |
|
|
|
|
|
|
|
PageData<EntityData> data = |
|
|
|
doPostWithTypedResponse("/api/entitiesQuery/find", query, new TypeReference<PageData<EntityData>>() { |
|
|
|
}); |
|
|
|
|
|
|
|
Assert.assertEquals(1, data.getTotalElements()); |
|
|
|
Assert.assertEquals(1, data.getTotalPages()); |
|
|
|
Assert.assertEquals(1, data.getData().size()); |
|
|
|
|
|
|
|
// unnassign dashboard
|
|
|
|
login(TENANT_EMAIL, TENANT_PASSWORD); |
|
|
|
doDelete("/api/customer/" + savedCustomer.getId().getId().toString() + "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class); |
|
|
|
|
|
|
|
login(CUSTOMER_USER_EMAIL, CUSTOMER_USER_PASSWORD); |
|
|
|
PageData<EntityData> dataAfterUnassign = |
|
|
|
doPostWithTypedResponse("/api/entitiesQuery/find", query, new TypeReference<PageData<EntityData>>() { |
|
|
|
}); |
|
|
|
|
|
|
|
Assert.assertEquals(0, dataAfterUnassign.getTotalElements()); |
|
|
|
Assert.assertEquals(0, dataAfterUnassign.getTotalPages()); |
|
|
|
Assert.assertEquals(0, dataAfterUnassign.getData().size()); |
|
|
|
} |
|
|
|
|
|
|
|
private void checkEntitiesByQuery(EntityDataQuery query, int expectedNumOfDevices, String expectedOwnerName, String expectedOwnerType) throws Exception { |
|
|
|
Awaitility.await() |
|
|
|
.alias("data by query") |
|
|
|
|