Tests added for JpaDeviceDao and DeviceService
This commit is contained in:
parent
22c9aa3776
commit
f621c10260
@ -283,6 +283,17 @@ public class DeviceServiceTest extends AbstractServiceTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDeviceWithNameContains0x00_thenDataValidationException() {
|
||||
Device device = new Device();
|
||||
device.setType("default");
|
||||
device.setTenantId(tenantId);
|
||||
device.setName("F0929906\000\000\000\000\000\000\000\000\000");
|
||||
Assertions.assertThrows(DataValidationException.class, () -> {
|
||||
deviceService.saveDevice(device);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDeviceWithInvalidTenant() {
|
||||
Device device = new Device();
|
||||
|
||||
@ -45,6 +45,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@ -101,6 +102,12 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDeviceName0x00_thenSomeDatabaseException() {
|
||||
Device device = getDevice(tenantId1, customerId1, "\u0000");
|
||||
assertThatThrownBy(() -> deviceIds.add(deviceDao.save(TenantId.fromUUID(tenantId1), device).getUuidId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindDevicesByTenantId() {
|
||||
PageLink pageLink = new PageLink(15, 0, PREFIX_FOR_DEVICE_NAME);
|
||||
@ -155,16 +162,16 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
|
||||
return savedDevicesUUID;
|
||||
}
|
||||
|
||||
private Device getDevice(UUID tenantId, UUID customerID, int number) {
|
||||
return getDevice(tenantId, customerID, Uuids.timeBased(), number);
|
||||
private Device getDevice(UUID tenantId, UUID customerID, Object nameSuffix) {
|
||||
return getDevice(tenantId, customerID, Uuids.timeBased(), nameSuffix);
|
||||
}
|
||||
|
||||
private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId, int number) {
|
||||
private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId, Object nameSuffix) {
|
||||
Device device = new Device();
|
||||
device.setId(new DeviceId(deviceId));
|
||||
device.setTenantId(TenantId.fromUUID(tenantId));
|
||||
device.setCustomerId(new CustomerId(customerID));
|
||||
device.setName(PREFIX_FOR_DEVICE_NAME + number);
|
||||
device.setName(PREFIX_FOR_DEVICE_NAME + nameSuffix);
|
||||
device.setDeviceProfileId(savedDeviceProfile.getId());
|
||||
return device;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user