Showing
1 changed file
with
23 additions
and
16 deletions
... | ... | @@ -24,7 +24,6 @@ import org.junit.Before; |
24 | 24 | import org.junit.Test; |
25 | 25 | import org.thingsboard.server.common.data.*; |
26 | 26 | import org.thingsboard.server.common.data.id.CustomerId; |
27 | -import org.thingsboard.server.common.data.id.TenantId; | |
28 | 27 | import org.thingsboard.server.common.data.objects.AttributesEntityView; |
29 | 28 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; |
30 | 29 | import org.thingsboard.server.common.data.page.TextPageData; |
... | ... | @@ -33,11 +32,9 @@ import org.thingsboard.server.common.data.security.Authority; |
33 | 32 | import org.thingsboard.server.dao.model.ModelConstants; |
34 | 33 | |
35 | 34 | import java.util.*; |
36 | -import java.util.stream.Stream; | |
37 | 35 | |
38 | 36 | import static org.hamcrest.Matchers.containsString; |
39 | 37 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
40 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; | |
41 | 38 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
42 | 39 | |
43 | 40 | public abstract class BaseEntityViewControllerTest extends AbstractControllerTest { |
... | ... | @@ -54,9 +51,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
54 | 51 | |
55 | 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 | 55 | Assert.assertNotNull(savedTenant); |
61 | 56 | |
62 | 57 | tenantAdmin = new User(); |
... | ... | @@ -119,29 +114,38 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
119 | 114 | |
120 | 115 | @Test |
121 | 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 | 122 | doDelete("/api/entityView/" + savedView.getId().getId().toString()) |
124 | 123 | .andExpect(status().isOk()); |
124 | + | |
125 | 125 | doGet("/api/entityView/" + savedView.getId().getId().toString()) |
126 | 126 | .andExpect(status().isNotFound()); |
127 | 127 | } |
128 | 128 | |
129 | 129 | @Test |
130 | 130 | public void testSaveEntityViewWithEmptyName() throws Exception { |
131 | - doPost("/api/entityView", getNewEntityView("")) | |
131 | + doPost("/api/entityView", new EntityView()) | |
132 | 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 | 136 | @Test |
137 | 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 | 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 | 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 | 149 | Assert.assertEquals(savedCustomer.getId(), foundView.getCustomerId()); |
146 | 150 | |
147 | 151 | EntityView unAssignedView = doDelete("/api/customer/entityView/" + savedView.getId().getId().toString(), EntityView.class); |
... | ... | @@ -172,7 +176,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
172 | 176 | tenantAdmin2.setEmail("tenant3@thingsboard.org"); |
173 | 177 | tenantAdmin2.setFirstName("Joe"); |
174 | 178 | tenantAdmin2.setLastName("Downs"); |
175 | - tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1"); | |
179 | + createUserAndLogin(tenantAdmin2, "testPassword1"); | |
176 | 180 | |
177 | 181 | Customer customer = getNewCustomer("Different customer"); |
178 | 182 | Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
... | ... | @@ -298,9 +302,9 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
298 | 302 | |
299 | 303 | private EntityView getNewEntityView(String name) throws Exception { |
300 | 304 | EntityView view = new EntityView(); |
301 | - view.setName(name); | |
302 | 305 | view.setEntityId(testDevice.getId()); |
303 | 306 | view.setTenantId(savedTenant.getId()); |
307 | + view.setName(name); | |
304 | 308 | view.setKeys(new TelemetryEntityView(obj)); |
305 | 309 | return doPost("/api/entityView", view, EntityView.class); |
306 | 310 | } |
... | ... | @@ -330,7 +334,10 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
330 | 334 | for (int i = 0; i < limit; i++) { |
331 | 335 | String fullName = partOfName + ' ' + RandomStringUtils.randomAlphanumeric(15); |
332 | 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 | 342 | return viewNames; |
336 | 343 | } | ... | ... |