...
|
...
|
@@ -15,74 +15,79 @@ |
15
|
15
|
*/
|
16
|
16
|
package org.thingsboard.server.controller;
|
17
|
17
|
|
18
|
|
-import static org.hamcrest.Matchers.containsString;
|
19
|
|
-import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
20
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
21
|
|
-
|
22
|
|
-import java.util.ArrayList;
|
23
|
|
-import java.util.Collections;
|
24
|
|
-import java.util.List;
|
25
|
|
-
|
26
|
18
|
import com.datastax.driver.core.utils.UUIDs;
|
|
19
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
27
|
20
|
import org.apache.commons.lang3.RandomStringUtils;
|
28
|
|
-import org.thingsboard.server.common.data.*;
|
|
21
|
+import org.junit.After;
|
|
22
|
+import org.junit.Assert;
|
|
23
|
+import org.junit.Before;
|
|
24
|
+import org.junit.Test;
|
|
25
|
+import org.thingsboard.server.common.data.Customer;
|
|
26
|
+import org.thingsboard.server.common.data.Device;
|
|
27
|
+import org.thingsboard.server.common.data.EntitySubtype;
|
|
28
|
+import org.thingsboard.server.common.data.Tenant;
|
|
29
|
+import org.thingsboard.server.common.data.User;
|
29
|
30
|
import org.thingsboard.server.common.data.id.CustomerId;
|
30
|
31
|
import org.thingsboard.server.common.data.id.DeviceCredentialsId;
|
31
|
32
|
import org.thingsboard.server.common.data.id.DeviceId;
|
32
|
33
|
import org.thingsboard.server.common.data.page.TextPageData;
|
33
|
34
|
import org.thingsboard.server.common.data.page.TextPageLink;
|
|
35
|
+import org.thingsboard.server.common.data.relation.EntityRelation;
|
|
36
|
+import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
34
|
37
|
import org.thingsboard.server.common.data.security.Authority;
|
35
|
38
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
36
|
39
|
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
|
37
|
40
|
import org.thingsboard.server.dao.model.ModelConstants;
|
38
|
|
-import org.junit.After;
|
39
|
|
-import org.junit.Assert;
|
40
|
|
-import org.junit.Before;
|
41
|
|
-import org.junit.Test;
|
42
|
41
|
|
43
|
|
-import com.fasterxml.jackson.core.type.TypeReference;
|
|
42
|
+import java.util.ArrayList;
|
|
43
|
+import java.util.Collections;
|
|
44
|
+import java.util.List;
|
|
45
|
+
|
|
46
|
+import static org.hamcrest.Matchers.containsString;
|
|
47
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
48
|
+import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
44
|
49
|
|
45
|
50
|
public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
|
46
|
|
-
|
|
51
|
+
|
47
|
52
|
private IdComparator<Device> idComparator = new IdComparator<>();
|
48
|
|
-
|
|
53
|
+
|
49
|
54
|
private Tenant savedTenant;
|
50
|
55
|
private User tenantAdmin;
|
51
|
|
-
|
|
56
|
+
|
52
|
57
|
@Before
|
53
|
58
|
public void beforeTest() throws Exception {
|
54
|
59
|
loginSysAdmin();
|
55
|
|
-
|
|
60
|
+
|
56
|
61
|
Tenant tenant = new Tenant();
|
57
|
62
|
tenant.setTitle("My tenant");
|
58
|
63
|
savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
59
|
64
|
Assert.assertNotNull(savedTenant);
|
60
|
|
-
|
|
65
|
+
|
61
|
66
|
tenantAdmin = new User();
|
62
|
67
|
tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
|
63
|
68
|
tenantAdmin.setTenantId(savedTenant.getId());
|
64
|
69
|
tenantAdmin.setEmail("tenant2@thingsboard.org");
|
65
|
70
|
tenantAdmin.setFirstName("Joe");
|
66
|
71
|
tenantAdmin.setLastName("Downs");
|
67
|
|
-
|
|
72
|
+
|
68
|
73
|
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
|
69
|
74
|
}
|
70
|
|
-
|
|
75
|
+
|
71
|
76
|
@After
|
72
|
77
|
public void afterTest() throws Exception {
|
73
|
78
|
loginSysAdmin();
|
74
|
|
-
|
75
|
|
- doDelete("/api/tenant/"+savedTenant.getId().getId().toString())
|
76
|
|
- .andExpect(status().isOk());
|
|
79
|
+
|
|
80
|
+ doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
|
|
81
|
+ .andExpect(status().isOk());
|
77
|
82
|
}
|
78
|
|
-
|
|
83
|
+
|
79
|
84
|
@Test
|
80
|
85
|
public void testSaveDevice() throws Exception {
|
81
|
86
|
Device device = new Device();
|
82
|
87
|
device.setName("My device");
|
83
|
88
|
device.setType("default");
|
84
|
89
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
85
|
|
-
|
|
90
|
+
|
86
|
91
|
Assert.assertNotNull(savedDevice);
|
87
|
92
|
Assert.assertNotNull(savedDevice.getId());
|
88
|
93
|
Assert.assertTrue(savedDevice.getCreatedTime() > 0);
|
...
|
...
|
@@ -90,9 +95,9 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
90
|
95
|
Assert.assertNotNull(savedDevice.getCustomerId());
|
91
|
96
|
Assert.assertEquals(NULL_UUID, savedDevice.getCustomerId().getId());
|
92
|
97
|
Assert.assertEquals(device.getName(), savedDevice.getName());
|
93
|
|
-
|
94
|
|
- DeviceCredentials deviceCredentials =
|
95
|
|
- doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
|
98
|
+
|
|
99
|
+ DeviceCredentials deviceCredentials =
|
|
100
|
+ doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
96
|
101
|
|
97
|
102
|
Assert.assertNotNull(deviceCredentials);
|
98
|
103
|
Assert.assertNotNull(deviceCredentials.getId());
|
...
|
...
|
@@ -100,10 +105,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
100
|
105
|
Assert.assertEquals(DeviceCredentialsType.ACCESS_TOKEN, deviceCredentials.getCredentialsType());
|
101
|
106
|
Assert.assertNotNull(deviceCredentials.getCredentialsId());
|
102
|
107
|
Assert.assertEquals(20, deviceCredentials.getCredentialsId().length());
|
103
|
|
-
|
|
108
|
+
|
104
|
109
|
savedDevice.setName("My new device");
|
105
|
110
|
doPost("/api/device", savedDevice, Device.class);
|
106
|
|
-
|
|
111
|
+
|
107
|
112
|
Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class);
|
108
|
113
|
Assert.assertEquals(foundDevice.getName(), savedDevice.getName());
|
109
|
114
|
}
|
...
|
...
|
@@ -115,10 +120,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
115
|
120
|
device.setType("default");
|
116
|
121
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
117
|
122
|
loginDifferentTenant();
|
118
|
|
- doPost("/api/device", savedDevice, Device.class, status().isForbidden());
|
|
123
|
+ doPost("/api/device", savedDevice, Device.class, status().isNotFound());
|
119
|
124
|
deleteDifferentTenant();
|
120
|
125
|
}
|
121
|
|
-
|
|
126
|
+
|
122
|
127
|
@Test
|
123
|
128
|
public void testFindDeviceById() throws Exception {
|
124
|
129
|
Device device = new Device();
|
...
|
...
|
@@ -133,26 +138,27 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
133
|
138
|
@Test
|
134
|
139
|
public void testFindDeviceTypesByTenantId() throws Exception {
|
135
|
140
|
List<Device> devices = new ArrayList<>();
|
136
|
|
- for (int i=0;i<3;i++) {
|
|
141
|
+ for (int i = 0; i < 3; i++) {
|
137
|
142
|
Device device = new Device();
|
138
|
|
- device.setName("My device B"+i);
|
|
143
|
+ device.setName("My device B" + i);
|
139
|
144
|
device.setType("typeB");
|
140
|
145
|
devices.add(doPost("/api/device", device, Device.class));
|
141
|
146
|
}
|
142
|
|
- for (int i=0;i<7;i++) {
|
|
147
|
+ for (int i = 0; i < 7; i++) {
|
143
|
148
|
Device device = new Device();
|
144
|
|
- device.setName("My device C"+i);
|
|
149
|
+ device.setName("My device C" + i);
|
145
|
150
|
device.setType("typeC");
|
146
|
151
|
devices.add(doPost("/api/device", device, Device.class));
|
147
|
152
|
}
|
148
|
|
- for (int i=0;i<9;i++) {
|
|
153
|
+ for (int i = 0; i < 9; i++) {
|
149
|
154
|
Device device = new Device();
|
150
|
|
- device.setName("My device A"+i);
|
|
155
|
+ device.setName("My device A" + i);
|
151
|
156
|
device.setType("typeA");
|
152
|
157
|
devices.add(doPost("/api/device", device, Device.class));
|
153
|
158
|
}
|
154
|
159
|
List<EntitySubtype> deviceTypes = doGetTyped("/api/device/types",
|
155
|
|
- new TypeReference<List<EntitySubtype>>(){});
|
|
160
|
+ new TypeReference<List<EntitySubtype>>() {
|
|
161
|
+ });
|
156
|
162
|
|
157
|
163
|
Assert.assertNotNull(deviceTypes);
|
158
|
164
|
Assert.assertEquals(3, deviceTypes.size());
|
...
|
...
|
@@ -160,19 +166,19 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
160
|
166
|
Assert.assertEquals("typeB", deviceTypes.get(1).getType());
|
161
|
167
|
Assert.assertEquals("typeC", deviceTypes.get(2).getType());
|
162
|
168
|
}
|
163
|
|
-
|
|
169
|
+
|
164
|
170
|
@Test
|
165
|
171
|
public void testDeleteDevice() throws Exception {
|
166
|
172
|
Device device = new Device();
|
167
|
173
|
device.setName("My device");
|
168
|
174
|
device.setType("default");
|
169
|
175
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
170
|
|
-
|
171
|
|
- doDelete("/api/device/"+savedDevice.getId().getId().toString())
|
172
|
|
- .andExpect(status().isOk());
|
173
|
176
|
|
174
|
|
- doGet("/api/device/"+savedDevice.getId().getId().toString())
|
175
|
|
- .andExpect(status().isNotFound());
|
|
177
|
+ doDelete("/api/device/" + savedDevice.getId().getId().toString())
|
|
178
|
+ .andExpect(status().isOk());
|
|
179
|
+
|
|
180
|
+ doGet("/api/device/" + savedDevice.getId().getId().toString())
|
|
181
|
+ .andExpect(status().isNotFound());
|
176
|
182
|
}
|
177
|
183
|
|
178
|
184
|
@Test
|
...
|
...
|
@@ -189,52 +195,52 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
189
|
195
|
Device device = new Device();
|
190
|
196
|
device.setType("default");
|
191
|
197
|
doPost("/api/device", device)
|
192
|
|
- .andExpect(status().isBadRequest())
|
193
|
|
- .andExpect(statusReason(containsString("Device name should be specified")));
|
|
198
|
+ .andExpect(status().isBadRequest())
|
|
199
|
+ .andExpect(statusReason(containsString("Device name should be specified")));
|
194
|
200
|
}
|
195
|
|
-
|
|
201
|
+
|
196
|
202
|
@Test
|
197
|
203
|
public void testAssignUnassignDeviceToCustomer() throws Exception {
|
198
|
204
|
Device device = new Device();
|
199
|
205
|
device.setName("My device");
|
200
|
206
|
device.setType("default");
|
201
|
207
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
202
|
|
-
|
|
208
|
+
|
203
|
209
|
Customer customer = new Customer();
|
204
|
210
|
customer.setTitle("My customer");
|
205
|
211
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
|
206
|
|
-
|
207
|
|
- Device assignedDevice = doPost("/api/customer/" + savedCustomer.getId().getId().toString()
|
|
212
|
+
|
|
213
|
+ Device assignedDevice = doPost("/api/customer/" + savedCustomer.getId().getId().toString()
|
208
|
214
|
+ "/device/" + savedDevice.getId().getId().toString(), Device.class);
|
209
|
215
|
Assert.assertEquals(savedCustomer.getId(), assignedDevice.getCustomerId());
|
210
|
|
-
|
|
216
|
+
|
211
|
217
|
Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class);
|
212
|
218
|
Assert.assertEquals(savedCustomer.getId(), foundDevice.getCustomerId());
|
213
|
219
|
|
214
|
|
- Device unassignedDevice =
|
|
220
|
+ Device unassignedDevice =
|
215
|
221
|
doDelete("/api/customer/device/" + savedDevice.getId().getId().toString(), Device.class);
|
216
|
222
|
Assert.assertEquals(ModelConstants.NULL_UUID, unassignedDevice.getCustomerId().getId());
|
217
|
|
-
|
|
223
|
+
|
218
|
224
|
foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class);
|
219
|
225
|
Assert.assertEquals(ModelConstants.NULL_UUID, foundDevice.getCustomerId().getId());
|
220
|
226
|
}
|
221
|
|
-
|
|
227
|
+
|
222
|
228
|
@Test
|
223
|
229
|
public void testAssignDeviceToNonExistentCustomer() throws Exception {
|
224
|
230
|
Device device = new Device();
|
225
|
231
|
device.setName("My device");
|
226
|
232
|
device.setType("default");
|
227
|
233
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
228
|
|
-
|
|
234
|
+
|
229
|
235
|
doPost("/api/customer/" + UUIDs.timeBased().toString()
|
230
|
236
|
+ "/device/" + savedDevice.getId().getId().toString())
|
231
|
|
- .andExpect(status().isNotFound());
|
|
237
|
+ .andExpect(status().isNotFound());
|
232
|
238
|
}
|
233
|
|
-
|
|
239
|
+
|
234
|
240
|
@Test
|
235
|
241
|
public void testAssignDeviceToCustomerFromDifferentTenant() throws Exception {
|
236
|
242
|
loginSysAdmin();
|
237
|
|
-
|
|
243
|
+
|
238
|
244
|
Tenant tenant2 = new Tenant();
|
239
|
245
|
tenant2.setTitle("Different tenant");
|
240
|
246
|
Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class);
|
...
|
...
|
@@ -246,103 +252,103 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
246
|
252
|
tenantAdmin2.setEmail("tenant3@thingsboard.org");
|
247
|
253
|
tenantAdmin2.setFirstName("Joe");
|
248
|
254
|
tenantAdmin2.setLastName("Downs");
|
249
|
|
-
|
|
255
|
+
|
250
|
256
|
tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1");
|
251
|
|
-
|
|
257
|
+
|
252
|
258
|
Customer customer = new Customer();
|
253
|
259
|
customer.setTitle("Different customer");
|
254
|
260
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
|
255
|
261
|
|
256
|
262
|
login(tenantAdmin.getEmail(), "testPassword1");
|
257
|
|
-
|
|
263
|
+
|
258
|
264
|
Device device = new Device();
|
259
|
265
|
device.setName("My device");
|
260
|
266
|
device.setType("default");
|
261
|
267
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
262
|
|
-
|
|
268
|
+
|
263
|
269
|
doPost("/api/customer/" + savedCustomer.getId().getId().toString()
|
264
|
270
|
+ "/device/" + savedDevice.getId().getId().toString())
|
265
|
|
- .andExpect(status().isForbidden());
|
266
|
|
-
|
|
271
|
+ .andExpect(status().isForbidden());
|
|
272
|
+
|
267
|
273
|
loginSysAdmin();
|
268
|
|
-
|
269
|
|
- doDelete("/api/tenant/"+savedTenant2.getId().getId().toString())
|
270
|
|
- .andExpect(status().isOk());
|
|
274
|
+
|
|
275
|
+ doDelete("/api/tenant/" + savedTenant2.getId().getId().toString())
|
|
276
|
+ .andExpect(status().isOk());
|
271
|
277
|
}
|
272
|
|
-
|
|
278
|
+
|
273
|
279
|
@Test
|
274
|
280
|
public void testFindDeviceCredentialsByDeviceId() throws Exception {
|
275
|
281
|
Device device = new Device();
|
276
|
282
|
device.setName("My device");
|
277
|
283
|
device.setType("default");
|
278
|
284
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
279
|
|
- DeviceCredentials deviceCredentials =
|
280
|
|
- doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
|
285
|
+ DeviceCredentials deviceCredentials =
|
|
286
|
+ doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
281
|
287
|
Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
|
282
|
288
|
}
|
283
|
|
-
|
|
289
|
+
|
284
|
290
|
@Test
|
285
|
291
|
public void testSaveDeviceCredentials() throws Exception {
|
286
|
292
|
Device device = new Device();
|
287
|
293
|
device.setName("My device");
|
288
|
294
|
device.setType("default");
|
289
|
295
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
290
|
|
- DeviceCredentials deviceCredentials =
|
291
|
|
- doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
|
296
|
+ DeviceCredentials deviceCredentials =
|
|
297
|
+ doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
292
|
298
|
Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
|
293
|
299
|
deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
|
294
|
300
|
deviceCredentials.setCredentialsId("access_token");
|
295
|
301
|
doPost("/api/device/credentials", deviceCredentials)
|
296
|
|
- .andExpect(status().isOk());
|
297
|
|
-
|
298
|
|
- DeviceCredentials foundDeviceCredentials =
|
|
302
|
+ .andExpect(status().isOk());
|
|
303
|
+
|
|
304
|
+ DeviceCredentials foundDeviceCredentials =
|
299
|
305
|
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
300
|
|
-
|
|
306
|
+
|
301
|
307
|
Assert.assertEquals(deviceCredentials, foundDeviceCredentials);
|
302
|
308
|
}
|
303
|
|
-
|
|
309
|
+
|
304
|
310
|
@Test
|
305
|
311
|
public void testSaveDeviceCredentialsWithEmptyDevice() throws Exception {
|
306
|
312
|
DeviceCredentials deviceCredentials = new DeviceCredentials();
|
307
|
313
|
doPost("/api/device/credentials", deviceCredentials)
|
308
|
|
- .andExpect(status().isBadRequest());
|
|
314
|
+ .andExpect(status().isBadRequest());
|
309
|
315
|
}
|
310
|
|
-
|
|
316
|
+
|
311
|
317
|
@Test
|
312
|
318
|
public void testSaveDeviceCredentialsWithEmptyCredentialsType() throws Exception {
|
313
|
319
|
Device device = new Device();
|
314
|
320
|
device.setName("My device");
|
315
|
321
|
device.setType("default");
|
316
|
322
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
317
|
|
- DeviceCredentials deviceCredentials =
|
|
323
|
+ DeviceCredentials deviceCredentials =
|
318
|
324
|
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
319
|
325
|
deviceCredentials.setCredentialsType(null);
|
320
|
326
|
doPost("/api/device/credentials", deviceCredentials)
|
321
|
|
- .andExpect(status().isBadRequest())
|
322
|
|
- .andExpect(statusReason(containsString("Device credentials type should be specified")));
|
|
327
|
+ .andExpect(status().isBadRequest())
|
|
328
|
+ .andExpect(statusReason(containsString("Device credentials type should be specified")));
|
323
|
329
|
}
|
324
|
|
-
|
|
330
|
+
|
325
|
331
|
@Test
|
326
|
332
|
public void testSaveDeviceCredentialsWithEmptyCredentialsId() throws Exception {
|
327
|
333
|
Device device = new Device();
|
328
|
334
|
device.setName("My device");
|
329
|
335
|
device.setType("default");
|
330
|
336
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
331
|
|
- DeviceCredentials deviceCredentials =
|
|
337
|
+ DeviceCredentials deviceCredentials =
|
332
|
338
|
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
333
|
339
|
deviceCredentials.setCredentialsId(null);
|
334
|
340
|
doPost("/api/device/credentials", deviceCredentials)
|
335
|
|
- .andExpect(status().isBadRequest())
|
336
|
|
- .andExpect(statusReason(containsString("Device credentials id should be specified")));
|
|
341
|
+ .andExpect(status().isBadRequest())
|
|
342
|
+ .andExpect(statusReason(containsString("Device credentials id should be specified")));
|
337
|
343
|
}
|
338
|
|
-
|
|
344
|
+
|
339
|
345
|
@Test
|
340
|
346
|
public void testSaveNonExistentDeviceCredentials() throws Exception {
|
341
|
347
|
Device device = new Device();
|
342
|
348
|
device.setName("My device");
|
343
|
349
|
device.setType("default");
|
344
|
350
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
345
|
|
- DeviceCredentials deviceCredentials =
|
|
351
|
+ DeviceCredentials deviceCredentials =
|
346
|
352
|
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
347
|
353
|
DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(UUIDs.timeBased()));
|
348
|
354
|
newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime());
|
...
|
...
|
@@ -350,29 +356,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
350
|
356
|
newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType());
|
351
|
357
|
newDeviceCredentials.setCredentialsId(deviceCredentials.getCredentialsId());
|
352
|
358
|
doPost("/api/device/credentials", newDeviceCredentials)
|
353
|
|
- .andExpect(status().isBadRequest())
|
354
|
|
- .andExpect(statusReason(containsString("Unable to update non-existent device credentials")));
|
|
359
|
+ .andExpect(status().isBadRequest())
|
|
360
|
+ .andExpect(statusReason(containsString("Unable to update non-existent device credentials")));
|
355
|
361
|
}
|
356
|
|
-
|
|
362
|
+
|
357
|
363
|
@Test
|
358
|
364
|
public void testSaveDeviceCredentialsWithNonExistentDevice() throws Exception {
|
359
|
365
|
Device device = new Device();
|
360
|
366
|
device.setName("My device");
|
361
|
367
|
device.setType("default");
|
362
|
368
|
Device savedDevice = doPost("/api/device", device, Device.class);
|
363
|
|
- DeviceCredentials deviceCredentials =
|
|
369
|
+ DeviceCredentials deviceCredentials =
|
364
|
370
|
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
365
|
371
|
deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
|
366
|
372
|
doPost("/api/device/credentials", deviceCredentials)
|
367
|
|
- .andExpect(status().isNotFound());
|
|
373
|
+ .andExpect(status().isNotFound());
|
368
|
374
|
}
|
369
|
375
|
|
370
|
376
|
@Test
|
371
|
377
|
public void testFindTenantDevices() throws Exception {
|
372
|
378
|
List<Device> devices = new ArrayList<>();
|
373
|
|
- for (int i=0;i<178;i++) {
|
|
379
|
+ for (int i = 0; i < 178; i++) {
|
374
|
380
|
Device device = new Device();
|
375
|
|
- device.setName("Device"+i);
|
|
381
|
+ device.setName("Device" + i);
|
376
|
382
|
device.setType("default");
|
377
|
383
|
devices.add(doPost("/api/device", device, Device.class));
|
378
|
384
|
}
|
...
|
...
|
@@ -380,28 +386,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
380
|
386
|
TextPageLink pageLink = new TextPageLink(23);
|
381
|
387
|
TextPageData<Device> pageData = null;
|
382
|
388
|
do {
|
383
|
|
- pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
384
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
389
|
+ pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
|
390
|
+ new TypeReference<TextPageData<Device>>() {
|
|
391
|
+ }, pageLink);
|
385
|
392
|
loadedDevices.addAll(pageData.getData());
|
386
|
393
|
if (pageData.hasNext()) {
|
387
|
394
|
pageLink = pageData.getNextPageLink();
|
388
|
395
|
}
|
389
|
396
|
} while (pageData.hasNext());
|
390
|
|
-
|
|
397
|
+
|
391
|
398
|
Collections.sort(devices, idComparator);
|
392
|
399
|
Collections.sort(loadedDevices, idComparator);
|
393
|
|
-
|
|
400
|
+
|
394
|
401
|
Assert.assertEquals(devices, loadedDevices);
|
395
|
402
|
}
|
396
|
|
-
|
|
403
|
+
|
397
|
404
|
@Test
|
398
|
405
|
public void testFindTenantDevicesByName() throws Exception {
|
399
|
406
|
String title1 = "Device title 1";
|
400
|
407
|
List<Device> devicesTitle1 = new ArrayList<>();
|
401
|
|
- for (int i=0;i<143;i++) {
|
|
408
|
+ for (int i = 0; i < 143; i++) {
|
402
|
409
|
Device device = new Device();
|
403
|
410
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
404
|
|
- String name = title1+suffix;
|
|
411
|
+ String name = title1 + suffix;
|
405
|
412
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
406
|
413
|
device.setName(name);
|
407
|
414
|
device.setType("default");
|
...
|
...
|
@@ -409,38 +416,40 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
409
|
416
|
}
|
410
|
417
|
String title2 = "Device title 2";
|
411
|
418
|
List<Device> devicesTitle2 = new ArrayList<>();
|
412
|
|
- for (int i=0;i<75;i++) {
|
|
419
|
+ for (int i = 0; i < 75; i++) {
|
413
|
420
|
Device device = new Device();
|
414
|
421
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
415
|
|
- String name = title2+suffix;
|
|
422
|
+ String name = title2 + suffix;
|
416
|
423
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
417
|
424
|
device.setName(name);
|
418
|
425
|
device.setType("default");
|
419
|
426
|
devicesTitle2.add(doPost("/api/device", device, Device.class));
|
420
|
427
|
}
|
421
|
|
-
|
|
428
|
+
|
422
|
429
|
List<Device> loadedDevicesTitle1 = new ArrayList<>();
|
423
|
430
|
TextPageLink pageLink = new TextPageLink(15, title1);
|
424
|
431
|
TextPageData<Device> pageData = null;
|
425
|
432
|
do {
|
426
|
|
- pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
427
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
433
|
+ pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
|
434
|
+ new TypeReference<TextPageData<Device>>() {
|
|
435
|
+ }, pageLink);
|
428
|
436
|
loadedDevicesTitle1.addAll(pageData.getData());
|
429
|
437
|
if (pageData.hasNext()) {
|
430
|
438
|
pageLink = pageData.getNextPageLink();
|
431
|
439
|
}
|
432
|
440
|
} while (pageData.hasNext());
|
433
|
|
-
|
|
441
|
+
|
434
|
442
|
Collections.sort(devicesTitle1, idComparator);
|
435
|
443
|
Collections.sort(loadedDevicesTitle1, idComparator);
|
436
|
|
-
|
|
444
|
+
|
437
|
445
|
Assert.assertEquals(devicesTitle1, loadedDevicesTitle1);
|
438
|
|
-
|
|
446
|
+
|
439
|
447
|
List<Device> loadedDevicesTitle2 = new ArrayList<>();
|
440
|
448
|
pageLink = new TextPageLink(4, title2);
|
441
|
449
|
do {
|
442
|
|
- pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
443
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
450
|
+ pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
|
451
|
+ new TypeReference<TextPageData<Device>>() {
|
|
452
|
+ }, pageLink);
|
444
|
453
|
loadedDevicesTitle2.addAll(pageData.getData());
|
445
|
454
|
if (pageData.hasNext()) {
|
446
|
455
|
pageLink = pageData.getNextPageLink();
|
...
|
...
|
@@ -449,28 +458,30 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
449
|
458
|
|
450
|
459
|
Collections.sort(devicesTitle2, idComparator);
|
451
|
460
|
Collections.sort(loadedDevicesTitle2, idComparator);
|
452
|
|
-
|
|
461
|
+
|
453
|
462
|
Assert.assertEquals(devicesTitle2, loadedDevicesTitle2);
|
454
|
|
-
|
|
463
|
+
|
455
|
464
|
for (Device device : loadedDevicesTitle1) {
|
456
|
|
- doDelete("/api/device/"+device.getId().getId().toString())
|
457
|
|
- .andExpect(status().isOk());
|
|
465
|
+ doDelete("/api/device/" + device.getId().getId().toString())
|
|
466
|
+ .andExpect(status().isOk());
|
458
|
467
|
}
|
459
|
|
-
|
|
468
|
+
|
460
|
469
|
pageLink = new TextPageLink(4, title1);
|
461
|
|
- pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
462
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
470
|
+ pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
|
471
|
+ new TypeReference<TextPageData<Device>>() {
|
|
472
|
+ }, pageLink);
|
463
|
473
|
Assert.assertFalse(pageData.hasNext());
|
464
|
474
|
Assert.assertEquals(0, pageData.getData().size());
|
465
|
|
-
|
|
475
|
+
|
466
|
476
|
for (Device device : loadedDevicesTitle2) {
|
467
|
|
- doDelete("/api/device/"+device.getId().getId().toString())
|
468
|
|
- .andExpect(status().isOk());
|
|
477
|
+ doDelete("/api/device/" + device.getId().getId().toString())
|
|
478
|
+ .andExpect(status().isOk());
|
469
|
479
|
}
|
470
|
|
-
|
|
480
|
+
|
471
|
481
|
pageLink = new TextPageLink(4, title2);
|
472
|
|
- pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
473
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
482
|
+ pageData = doGetTypedWithPageLink("/api/tenant/devices?",
|
|
483
|
+ new TypeReference<TextPageData<Device>>() {
|
|
484
|
+ }, pageLink);
|
474
|
485
|
Assert.assertFalse(pageData.hasNext());
|
475
|
486
|
Assert.assertEquals(0, pageData.getData().size());
|
476
|
487
|
}
|
...
|
...
|
@@ -480,10 +491,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
480
|
491
|
String title1 = "Device title 1";
|
481
|
492
|
String type1 = "typeA";
|
482
|
493
|
List<Device> devicesType1 = new ArrayList<>();
|
483
|
|
- for (int i=0;i<143;i++) {
|
|
494
|
+ for (int i = 0; i < 143; i++) {
|
484
|
495
|
Device device = new Device();
|
485
|
496
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
486
|
|
- String name = title1+suffix;
|
|
497
|
+ String name = title1 + suffix;
|
487
|
498
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
488
|
499
|
device.setName(name);
|
489
|
500
|
device.setType(type1);
|
...
|
...
|
@@ -492,10 +503,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
492
|
503
|
String title2 = "Device title 2";
|
493
|
504
|
String type2 = "typeB";
|
494
|
505
|
List<Device> devicesType2 = new ArrayList<>();
|
495
|
|
- for (int i=0;i<75;i++) {
|
|
506
|
+ for (int i = 0; i < 75; i++) {
|
496
|
507
|
Device device = new Device();
|
497
|
508
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
498
|
|
- String name = title2+suffix;
|
|
509
|
+ String name = title2 + suffix;
|
499
|
510
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
500
|
511
|
device.setName(name);
|
501
|
512
|
device.setType(type2);
|
...
|
...
|
@@ -507,7 +518,8 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
507
|
518
|
TextPageData<Device> pageData = null;
|
508
|
519
|
do {
|
509
|
520
|
pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&",
|
510
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type1);
|
|
521
|
+ new TypeReference<TextPageData<Device>>() {
|
|
522
|
+ }, pageLink, type1);
|
511
|
523
|
loadedDevicesType1.addAll(pageData.getData());
|
512
|
524
|
if (pageData.hasNext()) {
|
513
|
525
|
pageLink = pageData.getNextPageLink();
|
...
|
...
|
@@ -523,7 +535,8 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
523
|
535
|
pageLink = new TextPageLink(4);
|
524
|
536
|
do {
|
525
|
537
|
pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&",
|
526
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type2);
|
|
538
|
+ new TypeReference<TextPageData<Device>>() {
|
|
539
|
+ }, pageLink, type2);
|
527
|
540
|
loadedDevicesType2.addAll(pageData.getData());
|
528
|
541
|
if (pageData.hasNext()) {
|
529
|
542
|
pageLink = pageData.getNextPageLink();
|
...
|
...
|
@@ -536,63 +549,66 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
536
|
549
|
Assert.assertEquals(devicesType2, loadedDevicesType2);
|
537
|
550
|
|
538
|
551
|
for (Device device : loadedDevicesType1) {
|
539
|
|
- doDelete("/api/device/"+device.getId().getId().toString())
|
|
552
|
+ doDelete("/api/device/" + device.getId().getId().toString())
|
540
|
553
|
.andExpect(status().isOk());
|
541
|
554
|
}
|
542
|
555
|
|
543
|
556
|
pageLink = new TextPageLink(4);
|
544
|
557
|
pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&",
|
545
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type1);
|
|
558
|
+ new TypeReference<TextPageData<Device>>() {
|
|
559
|
+ }, pageLink, type1);
|
546
|
560
|
Assert.assertFalse(pageData.hasNext());
|
547
|
561
|
Assert.assertEquals(0, pageData.getData().size());
|
548
|
562
|
|
549
|
563
|
for (Device device : loadedDevicesType2) {
|
550
|
|
- doDelete("/api/device/"+device.getId().getId().toString())
|
|
564
|
+ doDelete("/api/device/" + device.getId().getId().toString())
|
551
|
565
|
.andExpect(status().isOk());
|
552
|
566
|
}
|
553
|
567
|
|
554
|
568
|
pageLink = new TextPageLink(4);
|
555
|
569
|
pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&",
|
556
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type2);
|
|
570
|
+ new TypeReference<TextPageData<Device>>() {
|
|
571
|
+ }, pageLink, type2);
|
557
|
572
|
Assert.assertFalse(pageData.hasNext());
|
558
|
573
|
Assert.assertEquals(0, pageData.getData().size());
|
559
|
574
|
}
|
560
|
|
-
|
|
575
|
+
|
561
|
576
|
@Test
|
562
|
577
|
public void testFindCustomerDevices() throws Exception {
|
563
|
578
|
Customer customer = new Customer();
|
564
|
579
|
customer.setTitle("Test customer");
|
565
|
580
|
customer = doPost("/api/customer", customer, Customer.class);
|
566
|
581
|
CustomerId customerId = customer.getId();
|
567
|
|
-
|
|
582
|
+
|
568
|
583
|
List<Device> devices = new ArrayList<>();
|
569
|
|
- for (int i=0;i<128;i++) {
|
|
584
|
+ for (int i = 0; i < 128; i++) {
|
570
|
585
|
Device device = new Device();
|
571
|
|
- device.setName("Device"+i);
|
|
586
|
+ device.setName("Device" + i);
|
572
|
587
|
device.setType("default");
|
573
|
588
|
device = doPost("/api/device", device, Device.class);
|
574
|
|
- devices.add(doPost("/api/customer/" + customerId.getId().toString()
|
575
|
|
- + "/device/" + device.getId().getId().toString(), Device.class));
|
|
589
|
+ devices.add(doPost("/api/customer/" + customerId.getId().toString()
|
|
590
|
+ + "/device/" + device.getId().getId().toString(), Device.class));
|
576
|
591
|
}
|
577
|
|
-
|
|
592
|
+
|
578
|
593
|
List<Device> loadedDevices = new ArrayList<>();
|
579
|
594
|
TextPageLink pageLink = new TextPageLink(23);
|
580
|
595
|
TextPageData<Device> pageData = null;
|
581
|
596
|
do {
|
582
|
|
- pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
583
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
597
|
+ pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
|
598
|
+ new TypeReference<TextPageData<Device>>() {
|
|
599
|
+ }, pageLink);
|
584
|
600
|
loadedDevices.addAll(pageData.getData());
|
585
|
601
|
if (pageData.hasNext()) {
|
586
|
602
|
pageLink = pageData.getNextPageLink();
|
587
|
603
|
}
|
588
|
604
|
} while (pageData.hasNext());
|
589
|
|
-
|
|
605
|
+
|
590
|
606
|
Collections.sort(devices, idComparator);
|
591
|
607
|
Collections.sort(loadedDevices, idComparator);
|
592
|
|
-
|
|
608
|
+
|
593
|
609
|
Assert.assertEquals(devices, loadedDevices);
|
594
|
610
|
}
|
595
|
|
-
|
|
611
|
+
|
596
|
612
|
@Test
|
597
|
613
|
public void testFindCustomerDevicesByName() throws Exception {
|
598
|
614
|
Customer customer = new Customer();
|
...
|
...
|
@@ -602,53 +618,55 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
602
|
618
|
|
603
|
619
|
String title1 = "Device title 1";
|
604
|
620
|
List<Device> devicesTitle1 = new ArrayList<>();
|
605
|
|
- for (int i=0;i<125;i++) {
|
|
621
|
+ for (int i = 0; i < 125; i++) {
|
606
|
622
|
Device device = new Device();
|
607
|
623
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
608
|
|
- String name = title1+suffix;
|
|
624
|
+ String name = title1 + suffix;
|
609
|
625
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
610
|
626
|
device.setName(name);
|
611
|
627
|
device.setType("default");
|
612
|
628
|
device = doPost("/api/device", device, Device.class);
|
613
|
|
- devicesTitle1.add(doPost("/api/customer/" + customerId.getId().toString()
|
|
629
|
+ devicesTitle1.add(doPost("/api/customer/" + customerId.getId().toString()
|
614
|
630
|
+ "/device/" + device.getId().getId().toString(), Device.class));
|
615
|
631
|
}
|
616
|
632
|
String title2 = "Device title 2";
|
617
|
633
|
List<Device> devicesTitle2 = new ArrayList<>();
|
618
|
|
- for (int i=0;i<143;i++) {
|
|
634
|
+ for (int i = 0; i < 143; i++) {
|
619
|
635
|
Device device = new Device();
|
620
|
636
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
621
|
|
- String name = title2+suffix;
|
|
637
|
+ String name = title2 + suffix;
|
622
|
638
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
623
|
639
|
device.setName(name);
|
624
|
640
|
device.setType("default");
|
625
|
641
|
device = doPost("/api/device", device, Device.class);
|
626
|
|
- devicesTitle2.add(doPost("/api/customer/" + customerId.getId().toString()
|
|
642
|
+ devicesTitle2.add(doPost("/api/customer/" + customerId.getId().toString()
|
627
|
643
|
+ "/device/" + device.getId().getId().toString(), Device.class));
|
628
|
644
|
}
|
629
|
|
-
|
|
645
|
+
|
630
|
646
|
List<Device> loadedDevicesTitle1 = new ArrayList<>();
|
631
|
647
|
TextPageLink pageLink = new TextPageLink(15, title1);
|
632
|
648
|
TextPageData<Device> pageData = null;
|
633
|
649
|
do {
|
634
|
|
- pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
635
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
650
|
+ pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
|
651
|
+ new TypeReference<TextPageData<Device>>() {
|
|
652
|
+ }, pageLink);
|
636
|
653
|
loadedDevicesTitle1.addAll(pageData.getData());
|
637
|
654
|
if (pageData.hasNext()) {
|
638
|
655
|
pageLink = pageData.getNextPageLink();
|
639
|
656
|
}
|
640
|
657
|
} while (pageData.hasNext());
|
641
|
|
-
|
|
658
|
+
|
642
|
659
|
Collections.sort(devicesTitle1, idComparator);
|
643
|
660
|
Collections.sort(loadedDevicesTitle1, idComparator);
|
644
|
|
-
|
|
661
|
+
|
645
|
662
|
Assert.assertEquals(devicesTitle1, loadedDevicesTitle1);
|
646
|
|
-
|
|
663
|
+
|
647
|
664
|
List<Device> loadedDevicesTitle2 = new ArrayList<>();
|
648
|
665
|
pageLink = new TextPageLink(4, title2);
|
649
|
666
|
do {
|
650
|
|
- pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
651
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
667
|
+ pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
|
668
|
+ new TypeReference<TextPageData<Device>>() {
|
|
669
|
+ }, pageLink);
|
652
|
670
|
loadedDevicesTitle2.addAll(pageData.getData());
|
653
|
671
|
if (pageData.hasNext()) {
|
654
|
672
|
pageLink = pageData.getNextPageLink();
|
...
|
...
|
@@ -657,28 +675,30 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
657
|
675
|
|
658
|
676
|
Collections.sort(devicesTitle2, idComparator);
|
659
|
677
|
Collections.sort(loadedDevicesTitle2, idComparator);
|
660
|
|
-
|
|
678
|
+
|
661
|
679
|
Assert.assertEquals(devicesTitle2, loadedDevicesTitle2);
|
662
|
|
-
|
|
680
|
+
|
663
|
681
|
for (Device device : loadedDevicesTitle1) {
|
664
|
682
|
doDelete("/api/customer/device/" + device.getId().getId().toString())
|
665
|
|
- .andExpect(status().isOk());
|
|
683
|
+ .andExpect(status().isOk());
|
666
|
684
|
}
|
667
|
|
-
|
|
685
|
+
|
668
|
686
|
pageLink = new TextPageLink(4, title1);
|
669
|
|
- pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
670
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
687
|
+ pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
|
688
|
+ new TypeReference<TextPageData<Device>>() {
|
|
689
|
+ }, pageLink);
|
671
|
690
|
Assert.assertFalse(pageData.hasNext());
|
672
|
691
|
Assert.assertEquals(0, pageData.getData().size());
|
673
|
|
-
|
|
692
|
+
|
674
|
693
|
for (Device device : loadedDevicesTitle2) {
|
675
|
694
|
doDelete("/api/customer/device/" + device.getId().getId().toString())
|
676
|
|
- .andExpect(status().isOk());
|
|
695
|
+ .andExpect(status().isOk());
|
677
|
696
|
}
|
678
|
|
-
|
|
697
|
+
|
679
|
698
|
pageLink = new TextPageLink(4, title2);
|
680
|
|
- pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
681
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink);
|
|
699
|
+ pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
|
|
700
|
+ new TypeReference<TextPageData<Device>>() {
|
|
701
|
+ }, pageLink);
|
682
|
702
|
Assert.assertFalse(pageData.hasNext());
|
683
|
703
|
Assert.assertEquals(0, pageData.getData().size());
|
684
|
704
|
}
|
...
|
...
|
@@ -693,10 +713,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
693
|
713
|
String title1 = "Device title 1";
|
694
|
714
|
String type1 = "typeC";
|
695
|
715
|
List<Device> devicesType1 = new ArrayList<>();
|
696
|
|
- for (int i=0;i<125;i++) {
|
|
716
|
+ for (int i = 0; i < 125; i++) {
|
697
|
717
|
Device device = new Device();
|
698
|
718
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
699
|
|
- String name = title1+suffix;
|
|
719
|
+ String name = title1 + suffix;
|
700
|
720
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
701
|
721
|
device.setName(name);
|
702
|
722
|
device.setType(type1);
|
...
|
...
|
@@ -707,10 +727,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
707
|
727
|
String title2 = "Device title 2";
|
708
|
728
|
String type2 = "typeD";
|
709
|
729
|
List<Device> devicesType2 = new ArrayList<>();
|
710
|
|
- for (int i=0;i<143;i++) {
|
|
730
|
+ for (int i = 0; i < 143; i++) {
|
711
|
731
|
Device device = new Device();
|
712
|
732
|
String suffix = RandomStringUtils.randomAlphanumeric(15);
|
713
|
|
- String name = title2+suffix;
|
|
733
|
+ String name = title2 + suffix;
|
714
|
734
|
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
|
715
|
735
|
device.setName(name);
|
716
|
736
|
device.setType(type2);
|
...
|
...
|
@@ -724,7 +744,8 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
724
|
744
|
TextPageData<Device> pageData = null;
|
725
|
745
|
do {
|
726
|
746
|
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?type={type}&",
|
727
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type1);
|
|
747
|
+ new TypeReference<TextPageData<Device>>() {
|
|
748
|
+ }, pageLink, type1);
|
728
|
749
|
loadedDevicesType1.addAll(pageData.getData());
|
729
|
750
|
if (pageData.hasNext()) {
|
730
|
751
|
pageLink = pageData.getNextPageLink();
|
...
|
...
|
@@ -740,7 +761,8 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
740
|
761
|
pageLink = new TextPageLink(4);
|
741
|
762
|
do {
|
742
|
763
|
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?type={type}&",
|
743
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type2);
|
|
764
|
+ new TypeReference<TextPageData<Device>>() {
|
|
765
|
+ }, pageLink, type2);
|
744
|
766
|
loadedDevicesType2.addAll(pageData.getData());
|
745
|
767
|
if (pageData.hasNext()) {
|
746
|
768
|
pageLink = pageData.getNextPageLink();
|
...
|
...
|
@@ -759,7 +781,8 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
759
|
781
|
|
760
|
782
|
pageLink = new TextPageLink(4);
|
761
|
783
|
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?type={type}&",
|
762
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type1);
|
|
784
|
+ new TypeReference<TextPageData<Device>>() {
|
|
785
|
+ }, pageLink, type1);
|
763
|
786
|
Assert.assertFalse(pageData.hasNext());
|
764
|
787
|
Assert.assertEquals(0, pageData.getData().size());
|
765
|
788
|
|
...
|
...
|
@@ -770,9 +793,56 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
770
|
793
|
|
771
|
794
|
pageLink = new TextPageLink(4);
|
772
|
795
|
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?type={type}&",
|
773
|
|
- new TypeReference<TextPageData<Device>>(){}, pageLink, type2);
|
|
796
|
+ new TypeReference<TextPageData<Device>>() {
|
|
797
|
+ }, pageLink, type2);
|
774
|
798
|
Assert.assertFalse(pageData.hasNext());
|
775
|
799
|
Assert.assertEquals(0, pageData.getData().size());
|
776
|
800
|
}
|
777
|
801
|
|
|
802
|
+ @Test
|
|
803
|
+ public void testSwapDeviceFromOneTenantToAnother() throws Exception {
|
|
804
|
+ Device device = new Device();
|
|
805
|
+ device.setName("My device");
|
|
806
|
+ device.setType("default");
|
|
807
|
+ Device savedDevice = doPost("/api/device", device, Device.class);
|
|
808
|
+
|
|
809
|
+ Device anotherDevice = new Device();
|
|
810
|
+ anotherDevice.setName("My device1");
|
|
811
|
+ anotherDevice.setType("default");
|
|
812
|
+ Device savedAnotherDevice = doPost("/api/device", anotherDevice, Device.class);
|
|
813
|
+
|
|
814
|
+ EntityRelation relation = new EntityRelation();
|
|
815
|
+ relation.setFrom(savedDevice.getId());
|
|
816
|
+ relation.setTo(savedAnotherDevice.getId());
|
|
817
|
+ relation.setTypeGroup(RelationTypeGroup.COMMON);
|
|
818
|
+ relation.setType("Contains");
|
|
819
|
+ doPost("/api/relation", relation);
|
|
820
|
+
|
|
821
|
+ loginSysAdmin();
|
|
822
|
+ Tenant tenant = new Tenant();
|
|
823
|
+ tenant.setTitle("Different tenant");
|
|
824
|
+ Tenant savedDifferentTenant = doPost("/api/tenant", tenant, Tenant.class);
|
|
825
|
+ Assert.assertNotNull(savedDifferentTenant);
|
|
826
|
+
|
|
827
|
+ User user = new User();
|
|
828
|
+ user.setAuthority(Authority.TENANT_ADMIN);
|
|
829
|
+ user.setTenantId(savedDifferentTenant.getId());
|
|
830
|
+ user.setEmail("tenant9@thingsboard.org");
|
|
831
|
+ user.setFirstName("Sam");
|
|
832
|
+ user.setLastName("Downs");
|
|
833
|
+
|
|
834
|
+ createUserAndLogin(user, "testPassword1");
|
|
835
|
+
|
|
836
|
+ login("tenant2@thingsboard.org", "testPassword1");
|
|
837
|
+ Device swappedDevice = doPost("/api/tenant/" + savedDifferentTenant.getId().getId() + "/device/" + savedDevice.getId().getId(), Device.class);
|
|
838
|
+
|
|
839
|
+ doGet("/api/device/" + swappedDevice.getId().getId().toString(), Device.class, status().isNotFound());
|
|
840
|
+
|
|
841
|
+ login("tenant9@thingsboard.org", "testPassword1");
|
|
842
|
+
|
|
843
|
+ Device foundDevice1 = doGet("/api/device/" + swappedDevice.getId().getId().toString(), Device.class);
|
|
844
|
+ Assert.assertNotNull(foundDevice1);
|
|
845
|
+
|
|
846
|
+ doGet("/api/relation?fromId=" + savedDevice.getId().getId() + "&fromType=DEVICE&relationType=Contains&toId=" + savedAnotherDevice.getId().getId() + "&toType=DEVICE", EntityRelation.class, status().isNotFound());
|
|
847
|
+ }
|
778
|
848
|
} |
...
|
...
|
|