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 #29

Merged
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
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.2.0</version>
<version>6.3.0</version>

<name>5gLa FIWARE integration layer</name>
<url>https://github.com/vitrum-connect/5gla-fiware-integration-layer</url>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/de/app/fivegla/fiware/api/FiwareIdGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.app.fivegla.fiware.api;

import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

/**
* This class provides methods for generating FIWARE IDs.
* FIWARE IDs are used to uniquely identify entities in the FIWARE ecosystem.
*/
@Slf4j
public final class FiwareIdGenerator {

private FiwareIdGenerator() {
// private constructor to prevent instantiation
}

/**
* Generates a unique identifier with the given prefix.
* The generated identifier is a combination of the prefix and two parts of a randomly generated UUID string.
* If the length of the generated identifier exceeds 62 characters, a FiwareIntegrationLayerException will be thrown.
*
* @param prefix the prefix to be appended to the randomly generated UUID parts
* @return a unique identifier generated by combining the prefix and two parts of a randomly generated UUID string
* @throws FiwareIntegrationLayerException if the length of the generated identifier exceeds 62 characters
*/
public static String id(String prefix) {
var randomUUIDParts = UUID.randomUUID().toString().split("-");
var fiwareId = prefix + randomUUIDParts[0] + randomUUIDParts[1];
if (fiwareId.length() > 62) {
throw new FiwareIntegrationLayerException("The generated id is too long. Please choose a shorter prefix.");
} else {
log.debug("Generated id: " + fiwareId);
return fiwareId;
}
}

/**
* Generates a unique ID.
*
* @return a unique ID string
*/
public static String id() {
return id("");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.app.fivegla.fiware;

import de.app.fivegla.fiware.api.FiwareIdGenerator;
import de.app.fivegla.fiware.api.enums.DeviceCategoryValues;
import de.app.fivegla.fiware.model.Device;
import de.app.fivegla.fiware.model.DeviceCategory;
Expand All @@ -8,16 +9,15 @@
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.UUID;

class DeviceIntegrationServiceBasedOnTenantIT extends AbstractIT {

@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var fiwareIntegrationServiceForFoo = new DeviceIntegrationService(contextBrokerUrl, "foo");
var fiwareIntegrationServiceForBar = new DeviceIntegrationService(contextBrokerUrl, "bar");
var manufacturerSpecificIdForFoo = UUID.randomUUID().toString();
var manufacturerSpecificIdForBar = UUID.randomUUID().toString();
var manufacturerSpecificIdForFoo = FiwareIdGenerator.id();
var manufacturerSpecificIdForBar = FiwareIdGenerator.id();

var deviceForFoo = Device.builder()
.id("integration-test:" + manufacturerSpecificIdForFoo)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.app.fivegla.fiware;

import de.app.fivegla.fiware.api.FiwareIdGenerator;
import de.app.fivegla.fiware.api.FiwareIntegrationLayerException;
import de.app.fivegla.fiware.api.enums.DeviceCategoryValues;
import de.app.fivegla.fiware.model.Device;
Expand All @@ -9,14 +10,13 @@
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.UUID;

class DeviceIntegrationServiceIT extends AbstractIT {

@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
Expand All @@ -35,7 +35,7 @@ void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnT
@Test
void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnException() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
Expand All @@ -56,7 +56,7 @@ void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnE
@Test
void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheValuesForTheDevice() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
Expand Down Expand Up @@ -85,7 +85,7 @@ void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheVal
@Test
void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
Expand All @@ -105,7 +105,7 @@ void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTr
@Test
void givenExistingDeviceWhenDeletingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var id = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.app.fivegla.fiware;

import de.app.fivegla.fiware.api.FiwareIdGenerator;
import de.app.fivegla.fiware.api.enums.DeviceCategoryValues;
import de.app.fivegla.fiware.model.Device;
import de.app.fivegla.fiware.model.DeviceCategory;
Expand All @@ -16,7 +17,7 @@ class DeviceMeasurementIntegrationServiceIT extends AbstractIT {
@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand All @@ -37,7 +38,7 @@ void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnT
@Test
void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnException() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand All @@ -61,7 +62,7 @@ void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnE
@Test
void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheValuesForTheDevice() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand Down Expand Up @@ -95,7 +96,7 @@ void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheVal
@Test
void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var deviceMeasurementIntegrationService = new DeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.app.fivegla.fiware;

import de.app.fivegla.fiware.api.FiwareIdGenerator;
import de.app.fivegla.fiware.api.enums.DeviceCategoryValues;
import de.app.fivegla.fiware.model.*;
import org.junit.jupiter.api.Assertions;
Expand All @@ -13,7 +14,7 @@ class DroneDeviceMeasurementIntegrationServiceIT extends AbstractIT {
@Test
void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnTheCurrentVersion() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand All @@ -35,7 +36,7 @@ void givenExistingPackagePropertiesWhenFetchingTheVersionTheServiceShouldReturnT
@Test
void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnException() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand All @@ -61,7 +62,7 @@ void givenAlreadyExistingDeviceWhenCreatingNewDevicesTheServiceShouldNotThrowAnE
@Test
void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheValuesForTheDevice() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand Down Expand Up @@ -93,7 +94,7 @@ void givenAlreadyExistingDeviceWhenUpdatingTheDeviceTheServiceShouldUpdateTheVal
@Test
void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var deviceMeasurementIntegrationService = new DroneDeviceMeasurementIntegrationService(contextBrokerUrl, tenant);
var manufacturerSpecificId = UUID.randomUUID().toString();
var manufacturerSpecificId = FiwareIdGenerator.id();
var deviceId = "integration-test:" + manufacturerSpecificId;
var device = Device.builder()
.id(deviceId)
Expand Down