Showing
1 changed file
with
23 additions
and
16 deletions
@@ -24,7 +24,6 @@ import org.junit.Before; | @@ -24,7 +24,6 @@ import org.junit.Before; | ||
24 | import org.junit.Test; | 24 | import org.junit.Test; |
25 | import org.thingsboard.server.common.data.*; | 25 | import org.thingsboard.server.common.data.*; |
26 | import org.thingsboard.server.common.data.id.CustomerId; | 26 | import org.thingsboard.server.common.data.id.CustomerId; |
27 | -import org.thingsboard.server.common.data.id.TenantId; | ||
28 | import org.thingsboard.server.common.data.objects.AttributesEntityView; | 27 | import org.thingsboard.server.common.data.objects.AttributesEntityView; |
29 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; | 28 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; |
30 | import org.thingsboard.server.common.data.page.TextPageData; | 29 | import org.thingsboard.server.common.data.page.TextPageData; |
@@ -33,11 +32,9 @@ import org.thingsboard.server.common.data.security.Authority; | @@ -33,11 +32,9 @@ import org.thingsboard.server.common.data.security.Authority; | ||
33 | import org.thingsboard.server.dao.model.ModelConstants; | 32 | import org.thingsboard.server.dao.model.ModelConstants; |
34 | 33 | ||
35 | import java.util.*; | 34 | import java.util.*; |
36 | -import java.util.stream.Stream; | ||
37 | 35 | ||
38 | import static org.hamcrest.Matchers.containsString; | 36 | import static org.hamcrest.Matchers.containsString; |
39 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | 37 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
40 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; | ||
41 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 38 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
42 | 39 | ||
43 | public abstract class BaseEntityViewControllerTest extends AbstractControllerTest { | 40 | public abstract class BaseEntityViewControllerTest extends AbstractControllerTest { |
@@ -54,9 +51,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -54,9 +51,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
54 | 51 | ||
55 | idComparator = new IdComparator<>(); | 52 | idComparator = new IdComparator<>(); |
56 | 53 | ||
57 | - Tenant tenant = new Tenant(); | ||
58 | - tenant.setTitle("My tenant"); | ||
59 | - savedTenant = doPost("/api/tenant", tenant, Tenant.class); | 54 | + savedTenant = doPost("/api/tenant", getNewTenant("My tenant"), Tenant.class); |
60 | Assert.assertNotNull(savedTenant); | 55 | Assert.assertNotNull(savedTenant); |
61 | 56 | ||
62 | tenantAdmin = new User(); | 57 | tenantAdmin = new User(); |
@@ -119,29 +114,38 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -119,29 +114,38 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
119 | 114 | ||
120 | @Test | 115 | @Test |
121 | public void testDeleteEntityView() throws Exception { | 116 | public void testDeleteEntityView() throws Exception { |
122 | - EntityView savedView = doPost("/api/entityView", getNewEntityView("Test entity view"), EntityView.class); | 117 | + EntityView view = getNewEntityView("Test entity view"); |
118 | + Customer customer = doPost("/api/customer", getNewCustomer("My customer"), Customer.class); | ||
119 | + view.setCustomerId(customer.getId()); | ||
120 | + EntityView savedView = doPost("/api/entityView", view, EntityView.class); | ||
121 | + | ||
123 | doDelete("/api/entityView/" + savedView.getId().getId().toString()) | 122 | doDelete("/api/entityView/" + savedView.getId().getId().toString()) |
124 | .andExpect(status().isOk()); | 123 | .andExpect(status().isOk()); |
124 | + | ||
125 | doGet("/api/entityView/" + savedView.getId().getId().toString()) | 125 | doGet("/api/entityView/" + savedView.getId().getId().toString()) |
126 | .andExpect(status().isNotFound()); | 126 | .andExpect(status().isNotFound()); |
127 | } | 127 | } |
128 | 128 | ||
129 | @Test | 129 | @Test |
130 | public void testSaveEntityViewWithEmptyName() throws Exception { | 130 | public void testSaveEntityViewWithEmptyName() throws Exception { |
131 | - doPost("/api/entityView", getNewEntityView("")) | 131 | + doPost("/api/entityView", new EntityView()) |
132 | .andExpect(status().isBadRequest()) | 132 | .andExpect(status().isBadRequest()) |
133 | - .andExpect(statusReason(containsString("Entity-view name should be specified"))); | 133 | + .andExpect(statusReason(containsString("Entity view name should be specified!"))); |
134 | } | 134 | } |
135 | 135 | ||
136 | @Test | 136 | @Test |
137 | public void testAssignAndUnAssignedEntityViewToCustomer() throws Exception { | 137 | public void testAssignAndUnAssignedEntityViewToCustomer() throws Exception { |
138 | - EntityView savedView = doPost("/api/entityView", getNewEntityView("Test entity view"), EntityView.class); | 138 | + EntityView view = getNewEntityView("Test entity view"); |
139 | Customer savedCustomer = doPost("/api/customer", getNewCustomer("My customer"), Customer.class); | 139 | Customer savedCustomer = doPost("/api/customer", getNewCustomer("My customer"), Customer.class); |
140 | - EntityView assignedView = doPost("/api/customer/" + savedCustomer.getId().getId().toString() | ||
141 | - + "/entityView/" + savedView.getId().getId().toString(), EntityView.class); | 140 | + view.setCustomerId(savedCustomer.getId()); |
141 | + EntityView savedView = doPost("/api/entityView", view, EntityView.class); | ||
142 | + | ||
143 | + EntityView assignedView = doPost( | ||
144 | + "/api/customer/" + savedCustomer.getId().getId().toString() + "/entityView/" + savedView.getId().getId().toString(), | ||
145 | + EntityView.class); | ||
142 | Assert.assertEquals(savedCustomer.getId(), assignedView.getCustomerId()); | 146 | Assert.assertEquals(savedCustomer.getId(), assignedView.getCustomerId()); |
143 | 147 | ||
144 | - EntityView foundView = doGet("/api/entityView" + savedView.getId().getId().toString(), EntityView.class); | 148 | + EntityView foundView = doGet("/api/entityView/" + savedView.getId().getId().toString(), EntityView.class); |
145 | Assert.assertEquals(savedCustomer.getId(), foundView.getCustomerId()); | 149 | Assert.assertEquals(savedCustomer.getId(), foundView.getCustomerId()); |
146 | 150 | ||
147 | EntityView unAssignedView = doDelete("/api/customer/entityView/" + savedView.getId().getId().toString(), EntityView.class); | 151 | EntityView unAssignedView = doDelete("/api/customer/entityView/" + savedView.getId().getId().toString(), EntityView.class); |
@@ -172,7 +176,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -172,7 +176,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
172 | tenantAdmin2.setEmail("tenant3@thingsboard.org"); | 176 | tenantAdmin2.setEmail("tenant3@thingsboard.org"); |
173 | tenantAdmin2.setFirstName("Joe"); | 177 | tenantAdmin2.setFirstName("Joe"); |
174 | tenantAdmin2.setLastName("Downs"); | 178 | tenantAdmin2.setLastName("Downs"); |
175 | - tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1"); | 179 | + createUserAndLogin(tenantAdmin2, "testPassword1"); |
176 | 180 | ||
177 | Customer customer = getNewCustomer("Different customer"); | 181 | Customer customer = getNewCustomer("Different customer"); |
178 | Customer savedCustomer = doPost("/api/customer", customer, Customer.class); | 182 | Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
@@ -298,9 +302,9 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -298,9 +302,9 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
298 | 302 | ||
299 | private EntityView getNewEntityView(String name) throws Exception { | 303 | private EntityView getNewEntityView(String name) throws Exception { |
300 | EntityView view = new EntityView(); | 304 | EntityView view = new EntityView(); |
301 | - view.setName(name); | ||
302 | view.setEntityId(testDevice.getId()); | 305 | view.setEntityId(testDevice.getId()); |
303 | view.setTenantId(savedTenant.getId()); | 306 | view.setTenantId(savedTenant.getId()); |
307 | + view.setName(name); | ||
304 | view.setKeys(new TelemetryEntityView(obj)); | 308 | view.setKeys(new TelemetryEntityView(obj)); |
305 | return doPost("/api/entityView", view, EntityView.class); | 309 | return doPost("/api/entityView", view, EntityView.class); |
306 | } | 310 | } |
@@ -330,7 +334,10 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -330,7 +334,10 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
330 | for (int i = 0; i < limit; i++) { | 334 | for (int i = 0; i < limit; i++) { |
331 | String fullName = partOfName + ' ' + RandomStringUtils.randomAlphanumeric(15); | 335 | String fullName = partOfName + ' ' + RandomStringUtils.randomAlphanumeric(15); |
332 | fullName = i % 2 == 0 ? fullName.toLowerCase() : fullName.toUpperCase(); | 336 | fullName = i % 2 == 0 ? fullName.toLowerCase() : fullName.toUpperCase(); |
333 | - viewNames.add(doPost("/api/entityView", getNewEntityView(fullName), EntityView.class)); | 337 | + EntityView view = getNewEntityView(fullName); |
338 | + Customer customer = getNewCustomer("Test customer " + String.valueOf(Math.random())); | ||
339 | + view.setCustomerId(doPost("/api/customer", customer, Customer.class).getId()); | ||
340 | + viewNames.add(doPost("/api/entityView", view, EntityView.class)); | ||
334 | } | 341 | } |
335 | return viewNames; | 342 | return viewNames; |
336 | } | 343 | } |