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

Commit

Permalink
Feature/assure that locations are validated (#26)
Browse files Browse the repository at this point in the history
* Add null validation for device category and location

Enhanced the Device class by adding null validation checks for the device category and location fields. These checks ensure the completeness and integrity of data before it is further processed or stored. Now, an exception will be thrown if the device category or location is not specified, ensuring that we maintain robust and reliable device data.

* Update pom.xml version to 6.2.0

Bumped up the application version in pom.xml from 6.1.0 to 6.2.0. This new version includes added null validation checks for device category and location fields in the Device class. This ensures completeness and integrity of device data.

* Add location data in DeviceIntegrationService tests

Modified the DeviceIntegrationService integration tests to include the location data in Device builder. This change ensures that the tests alignments with the latest version of the Device model that includes the 'location' field.
  • Loading branch information
saschadoemer committed Oct 27, 2023
1 parent 81b0165 commit 398edb1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.app.5gla</groupId>
<artifactId>fiware-integration-layer</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>

<name>5gLa FIWARE integration layer</name>
<url>https://github.com/vitrum-connect/5gla-fiware-integration-layer</url>
Expand Down
7 changes: 7 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 @@ -44,5 +44,12 @@ public void validate() {
if (StringUtils.isBlank(id)) {
throw new IllegalArgumentException("The id of the device must not be null.");
}
if (deviceCategory == null) {
throw new IllegalArgumentException("The device category of the device must not be null.");
}
if (location == null) {
throw new IllegalArgumentException("The location of the device must not be null.");
}
location.validate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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,7 +16,15 @@ class DeviceIntegrationServiceIT extends AbstractIT {
@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var device = Device.builder().id("integration-test:" + UUID.randomUUID()).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var device = Device.builder()
.id("integration-test:" + UUID.randomUUID())
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
fiwareIntegrationService.persist(device);
Assertions.assertTrue(fiwareIntegrationService.exists(device.getId()));
}
Expand All @@ -24,7 +33,15 @@ void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnT
void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnException() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(id).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var device = Device.builder()
.id(id)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
fiwareIntegrationService.persist(device);
Assertions.assertTrue(fiwareIntegrationService.exists(id));
fiwareIntegrationService.persist(device);
Expand All @@ -35,7 +52,15 @@ void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnE
void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheValuesForTheDevice() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(id).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var device = Device.builder()
.id(id)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
fiwareIntegrationService.persist(device);
Assertions.assertTrue(fiwareIntegrationService.exists(id));
var persistedDevice = fiwareIntegrationService.read(id);
Expand All @@ -54,7 +79,15 @@ void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheVal
void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(id).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var device = Device.builder()
.id(id)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
fiwareIntegrationService.persist(device);
Assertions.assertTrue(fiwareIntegrationService.exists(id));
Assertions.assertFalse(fiwareIntegrationService.exists("integration-test:does-not-exist"));
Expand All @@ -64,7 +97,15 @@ void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTr
void givenExistingDeviceWhenDeletingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(id).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
var device = Device.builder()
.id(id)
.deviceCategory(DeviceCategory.builder()
.value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey()))
.build())
.location(Location.builder()
.coordinates(List.of(2.0, 4.0))
.build())
.build();
fiwareIntegrationService.persist(device);
Assertions.assertTrue(fiwareIntegrationService.exists(id));
Assertions.assertTrue(fiwareIntegrationService.delete(id));
Expand Down

0 comments on commit 398edb1

Please sign in to comment.