Browse Source

Adapt entity view tests to the owner model and existing source entities

pull/16844/head
Viacheslav Klimov 3 weeks ago
parent
commit
a23e60f7cf
Failed to extract signature
  1. 14
      application/src/test/java/org/thingsboard/server/controller/EntityViewControllerTest.java
  2. 2
      application/src/test/java/org/thingsboard/server/edge/EntityViewEdgeTest.java
  3. 9
      application/src/test/java/org/thingsboard/server/service/entitiy/EntityServiceTest.java

14
application/src/test/java/org/thingsboard/server/controller/EntityViewControllerTest.java

@ -371,15 +371,15 @@ public class EntityViewControllerTest extends AbstractControllerTest {
@Test
public void testUpdateEntityViewByCustomerUserToEntityNotAssignedToCustomer() throws Exception {
EntityView savedView = getNewSavedEntityView("Customer entity view");
doPost("/api/customer/" + customerId.getId() + "/entityView/" + savedView.getId().getId(), EntityView.class);
doPost("/api/customer/" + customerId.getId() + "/device/" + testDevice.getId().getId(), Device.class);
doPost("/api/owner/CUSTOMER/" + customerId.getId() + "/ENTITY_VIEW/" + savedView.getId().getId()).andExpect(status().isOk());
doPost("/api/owner/CUSTOMER/" + customerId.getId() + "/DEVICE/" + testDevice.getId().getId()).andExpect(status().isOk());
Device otherDevice = new Device();
otherDevice.setName("Device not assigned to customer");
otherDevice.setType("default");
otherDevice = doPost("/api/device", otherDevice, Device.class);
loginCustomerUser();
loginCustomerAdminUser();
EntityView customerView = doGet("/api/entityView/" + savedView.getId().getId(), EntityView.class);
customerView.setEntityId(otherDevice.getId());
@ -393,9 +393,9 @@ public class EntityViewControllerTest extends AbstractControllerTest {
@Test
public void testUpdateEntityViewByCustomerUserKeepingEntity() throws Exception {
EntityView savedView = getNewSavedEntityView("Customer entity view");
doPost("/api/customer/" + customerId.getId() + "/entityView/" + savedView.getId().getId(), EntityView.class);
doPost("/api/owner/CUSTOMER/" + customerId.getId() + "/ENTITY_VIEW/" + savedView.getId().getId()).andExpect(status().isOk());
loginCustomerUser();
loginCustomerAdminUser();
EntityView customerView = doGet("/api/entityView/" + savedView.getId().getId(), EntityView.class);
customerView.setName("Customer entity view renamed");
@ -408,9 +408,9 @@ public class EntityViewControllerTest extends AbstractControllerTest {
@Test
public void testUpdateEntityViewKeysByCustomerUserWithEntityNotAssignedToCustomer() throws Exception {
EntityView savedView = getNewSavedEntityView("Customer entity view");
doPost("/api/customer/" + customerId.getId() + "/entityView/" + savedView.getId().getId(), EntityView.class);
doPost("/api/owner/CUSTOMER/" + customerId.getId() + "/ENTITY_VIEW/" + savedView.getId().getId()).andExpect(status().isOk());
loginCustomerUser();
loginCustomerAdminUser();
EntityView customerView = doGet("/api/entityView/" + savedView.getId().getId(), EntityView.class);
customerView.setKeys(new TelemetryEntityView(List.of("tsKey1"), new AttributesEntityView()));

2
application/src/test/java/org/thingsboard/server/edge/EntityViewEdgeTest.java

@ -248,6 +248,8 @@ public class EntityViewEdgeTest extends AbstractEdgeTest {
Assert.assertEquals(differentTenantId, storedView.getTenantId());
Assert.assertEquals("Other tenant EntityView", storedView.getName());
Assert.assertEquals(otherTenantDevice.getId(), storedView.getEntityId());
Assert.assertEquals(otherTenantView.getCustomerId(), storedView.getCustomerId());
Assert.assertEquals(otherTenantView.getOwnerId(), storedView.getOwnerId());
loginTenantAdmin();
}

9
application/src/test/java/org/thingsboard/server/service/entitiy/EntityServiceTest.java

@ -2105,6 +2105,7 @@ public class EntityServiceTest extends AbstractControllerTest {
entityView.setCustomerId(customerId);
entityView.setName("test");
entityView.setType("default");
entityView.setEntityId(deviceId);
customerEntityIds.add(entityViewService.saveEntityView(entityView).getId());
EntityGroup entityGroup = new EntityGroup();
@ -3876,12 +3877,18 @@ public class EntityServiceTest extends AbstractControllerTest {
@Test
public void testEntityViewEntityMapping() {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("Device for entity view");
device.setType("default");
device = deviceService.saveDevice(device);
EntityView entityView = new EntityView();
entityView.setTenantId(tenantId);
entityView.setCustomerId(customerId);
entityView.setName("test");
entityView.setType("default");
entityView.setEntityId(new DeviceId(UUID.randomUUID()));
entityView.setEntityId(device.getId());
entityView.setKeys(new TelemetryEntityView(List.of("test"), null));
entityView.setStartTimeMs(124);
entityView.setEndTimeMs(256);

Loading…
Cancel
Save