Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Add manufacturerSpecificId to Device model and tests #27

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/de/app/fivegla/fiware/model/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class Device implements Validatable {
*/
private String id;

/**
* The manufacturer ID of the device.
*/
private String manufacturerSpecificId;

/**
* The category of the device.
*/
Expand All @@ -44,6 +49,9 @@ public void validate() {
if (StringUtils.isBlank(id)) {
throw new IllegalArgumentException("The id of the device must not be null.");
}
if (StringUtils.isBlank(manufacturerSpecificId)) {
throw new IllegalArgumentException("The manufacturer specific id of the device must not be null.");
}
if (deviceCategory == null) {
throw new IllegalArgumentException("The device category of the device must not be null.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.app.fivegla.fiware.api.enums.DeviceCategoryValues;
import de.app.fivegla.fiware.model.Device;
import de.app.fivegla.fiware.model.DeviceCategory;
import de.app.fivegla.fiware.model.Location;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -15,9 +16,29 @@ class DeviceIntegrationServiceBasedOnTenantIT extends AbstractIT {
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var fiwareIntegrationServiceForFoo = new DeviceIntegrationService(contextBrokerUrl, "foo");
var fiwareIntegrationServiceForBar = new DeviceIntegrationService(contextBrokerUrl, "bar");

var deviceForFoo = Device.builder().id("integration-test:" + UUID.randomUUID()).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var deviceForBar = Device.builder().id("integration-test:" + UUID.randomUUID()).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.Farm21Sensor.getKey())).build()).build();
var manufacturerSpecificIdForFoo = UUID.randomUUID().toString();
var manufacturerSpecificIdForBar = UUID.randomUUID().toString();

var deviceForFoo = Device.builder()
.id("integration-test:" + manufacturerSpecificIdForFoo)
.manufacturerSpecificId(manufacturerSpecificIdForFoo)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var deviceForBar = Device.builder()
.id("integration-test:" + manufacturerSpecificIdForBar)
.manufacturerSpecificId(manufacturerSpecificIdForBar)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.Farm21Sensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();

fiwareIntegrationServiceForFoo.persist(deviceForFoo);
fiwareIntegrationServiceForBar.persist(deviceForBar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class DeviceIntegrationServiceIT extends AbstractIT {
@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id("integration-test:" + UUID.randomUUID())
.id(id)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
Expand All @@ -32,9 +35,11 @@ void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnT
@Test
void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnException() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var manufacturerSpecificId = UUID.randomUUID().toString();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
Expand All @@ -51,9 +56,11 @@ void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnE
@Test
void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheValuesForTheDevice() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var manufacturerSpecificId = UUID.randomUUID().toString();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
Expand All @@ -78,9 +85,11 @@ void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheVal
@Test
void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var manufacturerSpecificId = UUID.randomUUID().toString();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
Expand All @@ -96,9 +105,11 @@ void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTr
@Test
void givenExistingDeviceWhenDeletingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var manufacturerSpecificId = UUID.randomUUID().toString();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ class DeviceMeasurementIntegrationServiceIT extends AbstractIT {
@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var device = Device.builder().id("integration-test:" + UUID.randomUUID()).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
var deviceMeasurement = DeviceMeasurement.builder().id("integration-test:" + UUID.randomUUID()).refDevice(device.getId()).numValue(2.4).location(location).build();
deviceMeasurementIntegrationService.persist(deviceMeasurement);
Expand All @@ -26,8 +37,18 @@ void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnT
@Test
void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnException() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
String deviceId = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(deviceId).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
String deviceMeasurementId = "integration-test:" + UUID.randomUUID();
var deviceMeasurement = DeviceMeasurement.builder().id(deviceMeasurementId).refDevice(device.getId()).numValue(2.4).location(location).build();
Expand All @@ -40,8 +61,18 @@ void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnE
@Test
void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheValuesForTheDevice() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
String deviceId = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(deviceId).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
String deviceMeasurementId = "integration-test:" + UUID.randomUUID();
var deviceMeasurement = DeviceMeasurement.builder().id(deviceMeasurementId).refDevice(device.getId()).numValue(2.4).location(location).build();
Expand All @@ -64,8 +95,18 @@ void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheVal
@Test
void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
String deviceId = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(deviceId).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
String deviceMeasurementId = "integration-test:" + UUID.randomUUID();
var deviceMeasurement = DeviceMeasurement.builder().id(deviceMeasurementId).refDevice(device.getId()).numValue(2.4).location(location).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ class DroneDeviceMeasurementIntegrationServiceIT extends AbstractIT {
@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var device = Device.builder().id("integration-test:" + UUID.randomUUID()).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
var deviceMeasurement = DeviceMeasurement.builder().id("integration-test:" + UUID.randomUUID()).refDevice(device.getId()).numValue(2.4).location(location).build();
var droneDeviceMeasurement = DroneDeviceMeasurement.builder().id("integration-test:" + UUID.randomUUID()).deviceMeasurement(deviceMeasurement).channel("red").imagePath("http://localhost:8080/images/" + UUID.randomUUID()).build();
Expand All @@ -24,8 +35,18 @@ void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnT
@Test
void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnException() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var deviceId = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(deviceId).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
var deviceMeasurementId = "integration-test:" + UUID.randomUUID();
var droneDeviceMeasurementId = "integration-test:" + UUID.randomUUID();
Expand All @@ -40,8 +61,18 @@ void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnE
@Test
void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheValuesForTheDevice() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var deviceId = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(deviceId).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
var deviceMeasurementId = "integration-test:" + UUID.randomUUID();
var droneDeviceMeasurementId = "integration-test:" + UUID.randomUUID();
Expand All @@ -62,8 +93,18 @@ void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheVal
@Test
void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
String deviceId = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(deviceId).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var manufacturerSpecificId = UUID.randomUUID().toString();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
.manufacturerSpecificId(manufacturerSpecificId)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
var location = Location.builder().coordinates(List.of(1.0, 2.0)).build();
String deviceMeasurementId = "integration-test:" + UUID.randomUUID();
var droneDeviceMeasurementId = "integration-test:" + UUID.randomUUID();
Expand Down