add tests

This commit is contained in:
desoliture 2021-12-01 14:49:50 +02:00
parent 046ca0b264
commit d070d83458

View File

@ -352,7 +352,9 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
Assert.assertEquals("typeB", deviceTypes.get(1).getType()); Assert.assertEquals("typeB", deviceTypes.get(1).getType());
Assert.assertEquals("typeC", deviceTypes.get(2).getType()); Assert.assertEquals("typeC", deviceTypes.get(2).getType());
} finally { } finally {
devices.forEach((device) -> { deviceService.deleteDevice(tenantId, device.getId()); }); devices.forEach((device) -> {
deviceService.deleteDevice(tenantId, device.getId());
});
} }
} }
@ -818,4 +820,157 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
Assert.assertNull("Can't find device by name in cache if it was renamed", renamedDevice); Assert.assertNull("Can't find device by name in cache if it was renamed", renamedDevice);
deviceService.deleteDevice(tenantId, savedDevice.getId()); deviceService.deleteDevice(tenantId, savedDevice.getId());
} }
@Test
public void testFindDeviceInfoByTenantId() {
Customer customer = new Customer();
customer.setTitle("Customer X");
customer.setTenantId(tenantId);
Customer savedCustomer = customerService.saveCustomer(customer);
Device device = new Device();
device.setTenantId(tenantId);
device.setName("default");
device.setType("default");
device.setLabel("label");
device.setCustomerId(savedCustomer.getId());
Device savedDevice = deviceService.saveDevice(device);
PageLink pageLinkWithLabel = new PageLink(100, 0, "label");
List<DeviceInfo> deviceInfosWithLabel = deviceService
.findDeviceInfosByTenantId(tenantId, pageLinkWithLabel).getData();
Assert.assertFalse(deviceInfosWithLabel.isEmpty());
Assert.assertTrue(
deviceInfosWithLabel.stream()
.anyMatch(
d -> d.getId().equals(savedDevice.getId())
&& d.getTenantId().equals(tenantId)
&& d.getLabel().equals(savedDevice.getLabel())
)
);
PageLink pageLinkWithCustomer = new PageLink(100, 0, savedCustomer.getSearchText());
List<DeviceInfo> deviceInfosWithCustomer = deviceService
.findDeviceInfosByTenantId(tenantId, pageLinkWithCustomer).getData();
Assert.assertFalse(deviceInfosWithCustomer.isEmpty());
Assert.assertTrue(
deviceInfosWithCustomer.stream()
.anyMatch(
d -> d.getId().equals(savedDevice.getId())
&& d.getTenantId().equals(tenantId)
&& d.getCustomerId().equals(savedCustomer.getId())
&& d.getCustomerTitle().equals(savedCustomer.getTitle())
)
);
PageLink pageLinkWithType = new PageLink(100, 0, device.getType());
List<DeviceInfo> deviceInfosWithType = deviceService
.findDeviceInfosByTenantId(tenantId, pageLinkWithType).getData();
Assert.assertFalse(deviceInfosWithType.isEmpty());
Assert.assertTrue(
deviceInfosWithType.stream()
.anyMatch(
d -> d.getId().equals(savedDevice.getId())
&& d.getTenantId().equals(tenantId)
&& d.getType().equals(device.getType())
)
);
}
@Test
public void testFindDeviceInfoByTenantIdAndType() {
Customer customer = new Customer();
customer.setTitle("Customer X");
customer.setTenantId(tenantId);
Customer savedCustomer = customerService.saveCustomer(customer);
Device device = new Device();
device.setTenantId(tenantId);
device.setName("default");
device.setType("default");
device.setLabel("label");
device.setCustomerId(savedCustomer.getId());
Device savedDevice = deviceService.saveDevice(device);
PageLink pageLinkWithLabel = new PageLink(100, 0, "label");
List<DeviceInfo> deviceInfosWithLabel = deviceService
.findDeviceInfosByTenantIdAndType(tenantId, device.getType(), pageLinkWithLabel).getData();
Assert.assertFalse(deviceInfosWithLabel.isEmpty());
Assert.assertTrue(
deviceInfosWithLabel.stream()
.anyMatch(
d -> d.getId().equals(savedDevice.getId())
&& d.getTenantId().equals(tenantId)
&& d.getDeviceProfileName().equals(savedDevice.getType())
&& d.getLabel().equals(savedDevice.getLabel())
)
);
PageLink pageLinkWithCustomer = new PageLink(100, 0, savedCustomer.getSearchText());
List<DeviceInfo> deviceInfosWithCustomer = deviceService
.findDeviceInfosByTenantIdAndType(tenantId, device.getType(), pageLinkWithCustomer).getData();
Assert.assertFalse(deviceInfosWithCustomer.isEmpty());
Assert.assertTrue(
deviceInfosWithCustomer.stream()
.anyMatch(
d -> d.getId().equals(savedDevice.getId())
&& d.getTenantId().equals(tenantId)
&& d.getDeviceProfileName().equals(savedDevice.getType())
&& d.getCustomerId().equals(savedCustomer.getId())
&& d.getCustomerTitle().equals(savedCustomer.getTitle())
)
);
}
@Test
public void testFindDeviceInfoByTenantIdAndDeviceProfileId() {
Customer customer = new Customer();
customer.setTitle("Customer X");
customer.setTenantId(tenantId);
Customer savedCustomer = customerService.saveCustomer(customer);
Device device = new Device();
device.setTenantId(tenantId);
device.setName("default");
device.setLabel("label");
device.setCustomerId(savedCustomer.getId());
Device savedDevice = deviceService.saveDevice(device);
PageLink pageLinkWithLabel = new PageLink(100, 0, "label");
List<DeviceInfo> deviceInfosWithLabel = deviceService
.findDeviceInfosByTenantIdAndDeviceProfileId(tenantId, savedDevice.getDeviceProfileId(), pageLinkWithLabel).getData();
Assert.assertFalse(deviceInfosWithLabel.isEmpty());
Assert.assertTrue(
deviceInfosWithLabel.stream()
.anyMatch(
d -> d.getId().equals(savedDevice.getId())
&& d.getTenantId().equals(tenantId)
&& d.getDeviceProfileId().equals(savedDevice.getDeviceProfileId())
&& d.getLabel().equals(savedDevice.getLabel())
)
);
PageLink pageLinkWithCustomer = new PageLink(100, 0, savedCustomer.getSearchText());
List<DeviceInfo> deviceInfosWithCustomer = deviceService
.findDeviceInfosByTenantIdAndDeviceProfileId(tenantId, savedDevice.getDeviceProfileId(), pageLinkWithCustomer).getData();
Assert.assertFalse(deviceInfosWithCustomer.isEmpty());
Assert.assertTrue(
deviceInfosWithCustomer.stream()
.anyMatch(
d -> d.getId().equals(savedDevice.getId())
&& d.getTenantId().equals(tenantId)
&& d.getDeviceProfileId().equals(savedDevice.getDeviceProfileId())
&& d.getCustomerId().equals(savedCustomer.getId())
&& d.getCustomerTitle().equals(savedCustomer.getTitle())
)
);
}
} }