diff --git a/src/automation/src/main/java/eu/teraflow/automation/Serializer.java b/src/automation/src/main/java/eu/teraflow/automation/Serializer.java index 4dd09b55dc7a67287a84daafaaf4feb0ae190c6e..2b163fdff1a29c26f98380a0c3b19666a86749fe 100644 --- a/src/automation/src/main/java/eu/teraflow/automation/Serializer.java +++ b/src/automation/src/main/java/eu/teraflow/automation/Serializer.java @@ -24,6 +24,7 @@ import context.ContextOuterClass.ConfigRule_Custom; import context.ContextOuterClass.ContextId; import context.ContextOuterClass.DeviceId; import context.ContextOuterClass.DeviceOperationalStatusEnum; +import context.ContextOuterClass.Location.LocationCase; import context.ContextOuterClass.Uuid; import eu.teraflow.automation.acl.AclAction; import eu.teraflow.automation.acl.AclEntry; @@ -833,12 +834,14 @@ public class Serializer { final var serializedEndPointId = serialize(endPointId); final var serializedKpiSampleTypes = kpiSampleTypes.stream().map(this::serialize).collect(Collectors.toList()); - final var serializedEndPointLocation = serialize(endPointLocation); + if (endPointLocation != null) { + final var serializedEndPointLocation = serialize(endPointLocation); + builder.setEndpointLocation(serializedEndPointLocation); + } builder.setEndpointId(serializedEndPointId); builder.setEndpointType(endPointType); builder.addAllKpiSampleTypes(serializedKpiSampleTypes); - builder.setEndpointLocation(serializedEndPointLocation); return builder.build(); } @@ -852,9 +855,15 @@ public class Serializer { final var endPointId = deserialize(serializedEndPointId); final var kpiSampleTypes = serializedKpiSampleTypes.stream().map(this::deserialize).collect(Collectors.toList()); - final var endPointLocation = deserialize(serializedEndPointLocation); - return new EndPoint(endPointId, endPointType, kpiSampleTypes, endPointLocation); + if (serializedEndPointLocation.getLocationCase() != LocationCase.LOCATION_NOT_SET) { + final var endPointLocation = deserialize(serializedEndPointLocation); + return new EndPoint.EndPointBuilder(endPointId, endPointType, kpiSampleTypes) + .location(endPointLocation) + .build(); + } + + return new EndPoint.EndPointBuilder(endPointId, endPointType, kpiSampleTypes).build(); } public ContextOuterClass.Device serialize(Device device) { diff --git a/src/automation/src/main/java/eu/teraflow/automation/acl/AclRuleSet.java b/src/automation/src/main/java/eu/teraflow/automation/acl/AclRuleSet.java index 4a919a6842774b1dcdb8f6cfad3215f54bb0e4f6..6dacab0480647609b85c9b45504341e6b47600fa 100644 --- a/src/automation/src/main/java/eu/teraflow/automation/acl/AclRuleSet.java +++ b/src/automation/src/main/java/eu/teraflow/automation/acl/AclRuleSet.java @@ -16,8 +16,8 @@ package eu.teraflow.automation.acl; +import eu.teraflow.automation.common.Util; import java.util.List; -import java.util.stream.Collectors; public class AclRuleSet { @@ -64,10 +64,11 @@ public class AclRuleSet { public String toString() { return String.format( "%s:{name:\"%s\", type:\"%s\", description:\"%s\", userId:\"%s\", [%s]}", - getClass().getSimpleName(), name, type.toString(), description, userId, toString(entries)); - } - - private static <T> String toString(List<T> list) { - return list.stream().map(T::toString).collect(Collectors.joining(", ")); + getClass().getSimpleName(), + name, + type.toString(), + description, + userId, + Util.toString(entries)); } } diff --git a/src/automation/src/main/java/eu/teraflow/automation/context/model/Device.java b/src/automation/src/main/java/eu/teraflow/automation/context/model/Device.java index 1b286f57173c48787460828ba6bfc2c43588d4db..77bd3ca5c861713b43faf178c6450e35e6032b3c 100644 --- a/src/automation/src/main/java/eu/teraflow/automation/context/model/Device.java +++ b/src/automation/src/main/java/eu/teraflow/automation/context/model/Device.java @@ -16,8 +16,8 @@ package eu.teraflow.automation.context.model; +import eu.teraflow.automation.common.Util; import java.util.List; -import java.util.stream.Collectors; public class Device { @@ -102,11 +102,7 @@ public class Device { deviceType, deviceConfig, deviceOperationalStatus.toString(), - toString(deviceDrivers), - toString(endPoints)); - } - - private static <T> String toString(List<T> list) { - return list.stream().map(T::toString).collect(Collectors.joining(", ")); + Util.toString(deviceDrivers), + Util.toString(endPoints)); } } diff --git a/src/automation/src/main/java/eu/teraflow/automation/context/model/EndPoint.java b/src/automation/src/main/java/eu/teraflow/automation/context/model/EndPoint.java index f9fb8bf0d8406db4ee4fb07783eaf20bfd88e2b0..25b3864c5d367b7767dc8afb52e9edc04bb31817 100644 --- a/src/automation/src/main/java/eu/teraflow/automation/context/model/EndPoint.java +++ b/src/automation/src/main/java/eu/teraflow/automation/context/model/EndPoint.java @@ -16,9 +16,9 @@ package eu.teraflow.automation.context.model; +import eu.teraflow.automation.common.Util; import eu.teraflow.automation.kpi_sample_types.model.KpiSampleType; import java.util.List; -import java.util.stream.Collectors; public class EndPoint { private final EndPointId endPointId; @@ -26,15 +26,11 @@ public class EndPoint { private final List<KpiSampleType> kpiSampleTypes; private final Location endPointLocation; - public EndPoint( - EndPointId endPointId, - String endPointType, - List<KpiSampleType> kpiSampleTypes, - Location endPointLocation) { - this.endPointId = endPointId; - this.endPointType = endPointType; - this.kpiSampleTypes = kpiSampleTypes; - this.endPointLocation = endPointLocation; + EndPoint(EndPointBuilder builder) { + this.endPointId = builder.endPointId; + this.endPointType = builder.endPointType; + this.kpiSampleTypes = builder.kpiSampleTypes; + this.endPointLocation = builder.endPointLocation; } public EndPointId getEndPointId() { @@ -60,11 +56,50 @@ public class EndPoint { getClass().getSimpleName(), endPointId, endPointType, - toString(kpiSampleTypes), + Util.toString(kpiSampleTypes), endPointLocation); } - private static <T> String toString(List<T> list) { - return list.stream().map(T::toString).collect(Collectors.joining(", ")); + public static class EndPointBuilder { + private final EndPointId endPointId; + private final String endPointType; + private final List<KpiSampleType> kpiSampleTypes; + private Location endPointLocation; + + public EndPointBuilder( + EndPointId endPointId, String endPointType, List<KpiSampleType> kpiSampleTypes) { + this.endPointId = endPointId; + this.endPointType = endPointType; + this.kpiSampleTypes = kpiSampleTypes; + } + + public EndPointBuilder location(Location endPointLocation) { + this.endPointLocation = endPointLocation; + return this; + } + + public EndPoint build() { + EndPoint endPoint = new EndPoint(this); + validateEndPointObject(endPoint); + return endPoint; + } + + private void validateEndPointObject(EndPoint endPoint) { + final var validatedEndPointId = endPoint.getEndPointId(); + final var validatedEndPointType = endPoint.getEndPointType(); + final var validatedKpiSampleTypes = endPoint.getKpiSampleTypes(); + + if (validatedEndPointId == null) { + throw new IllegalStateException("EndPoint ID cannot be null"); + } + + if (validatedEndPointType == null) { + throw new IllegalStateException("EndPoint type cannot be null"); + } + + if (validatedKpiSampleTypes == null) { + throw new IllegalStateException("Kpi sample types cannot be null"); + } + } } } diff --git a/src/automation/src/test/java/eu/teraflow/automation/AutomationFunctionalServiceTest.java b/src/automation/src/test/java/eu/teraflow/automation/AutomationFunctionalServiceTest.java index d697569123484d1f8022a79794cf0367440cbbab..e250a905c8379c01383c149cc944fdd4a55a81b4 100644 --- a/src/automation/src/test/java/eu/teraflow/automation/AutomationFunctionalServiceTest.java +++ b/src/automation/src/test/java/eu/teraflow/automation/AutomationFunctionalServiceTest.java @@ -29,7 +29,7 @@ import eu.teraflow.automation.context.model.Device; import eu.teraflow.automation.context.model.DeviceConfig; import eu.teraflow.automation.context.model.DeviceDriverEnum; import eu.teraflow.automation.context.model.DeviceOperationalStatus; -import eu.teraflow.automation.context.model.EndPoint; +import eu.teraflow.automation.context.model.EndPoint.EndPointBuilder; import eu.teraflow.automation.context.model.EndPointId; import eu.teraflow.automation.context.model.Location; import eu.teraflow.automation.context.model.LocationTypeRegion; @@ -109,7 +109,10 @@ class AutomationFunctionalServiceTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationA = new Location(locationTypeRegionA); - final var endPointA = new EndPoint(endPointIdA, endPointTypeA, kpiSampleTypesA, locationA); + final var endPointA = + new EndPointBuilder(endPointIdA, endPointTypeA, kpiSampleTypesA) + .location(locationA) + .build(); final var topologyIdB = new TopologyId("contextIdB", "idB"); final var deviceIdB = "deviceIdB"; @@ -120,7 +123,10 @@ class AutomationFunctionalServiceTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationB = new Location(locationTypeRegionB); - final var endPointB = new EndPoint(endPointIdB, endPointTypeB, kpiSampleTypesB, locationB); + final var endPointB = + new EndPointBuilder(endPointIdB, endPointTypeB, kpiSampleTypesB) + .location(locationB) + .build(); final var endPoints = List.of(endPointA, endPointB); @@ -217,7 +223,10 @@ class AutomationFunctionalServiceTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationA = new Location(locationTypeRegionA); - final var endPointA = new EndPoint(endPointIdA, endPointTypeA, kpiSampleTypesA, locationA); + final var endPointA = + new EndPointBuilder(endPointIdA, endPointTypeA, kpiSampleTypesA) + .location(locationA) + .build(); final var topologyIdB = new TopologyId("contextIdB", "idB"); final var deviceIdB = "deviceIdB"; @@ -228,7 +237,10 @@ class AutomationFunctionalServiceTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationB = new Location(locationTypeRegionB); - final var endPointB = new EndPoint(endPointIdB, endPointTypeB, kpiSampleTypesB, locationB); + final var endPointB = + new EndPointBuilder(endPointIdB, endPointTypeB, kpiSampleTypesB) + .location(locationB) + .build(); final var endPoints = List.of(endPointA, endPointB); diff --git a/src/automation/src/test/java/eu/teraflow/automation/AutomationServiceTest.java b/src/automation/src/test/java/eu/teraflow/automation/AutomationServiceTest.java index bd69616bcb8331919faf3ed90b6612f01a7321b9..b1a70a7e0f0933d9d8aa6049c53d75a40ebf14d8 100644 --- a/src/automation/src/test/java/eu/teraflow/automation/AutomationServiceTest.java +++ b/src/automation/src/test/java/eu/teraflow/automation/AutomationServiceTest.java @@ -30,7 +30,7 @@ import eu.teraflow.automation.context.model.Device; import eu.teraflow.automation.context.model.DeviceConfig; import eu.teraflow.automation.context.model.DeviceDriverEnum; import eu.teraflow.automation.context.model.DeviceOperationalStatus; -import eu.teraflow.automation.context.model.EndPoint; +import eu.teraflow.automation.context.model.EndPoint.EndPointBuilder; import eu.teraflow.automation.context.model.EndPointId; import eu.teraflow.automation.context.model.Location; import eu.teraflow.automation.context.model.LocationTypeRegion; @@ -88,7 +88,10 @@ class AutomationServiceTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationA = new Location(locationTypeRegionA); - final var endPointA = new EndPoint(endPointIdA, endPointTypeA, kpiSampleTypesA, locationA); + final var endPointA = + new EndPointBuilder(endPointIdA, endPointTypeA, kpiSampleTypesA) + .location(locationA) + .build(); final var topologyIdB = new TopologyId("contextIdB", "idB"); final var deviceIdB = "deviceIdB"; @@ -99,7 +102,10 @@ class AutomationServiceTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationB = new Location(locationTypeRegionB); - final var endPointB = new EndPoint(endPointIdB, endPointTypeB, kpiSampleTypesB, locationB); + final var endPointB = + new EndPointBuilder(endPointIdB, endPointTypeB, kpiSampleTypesB) + .location(locationB) + .build(); final var endPoints = List.of(endPointA, endPointB); diff --git a/src/automation/src/test/java/eu/teraflow/automation/EndPointCreationTest.java b/src/automation/src/test/java/eu/teraflow/automation/EndPointCreationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d2094efaf48338c710121eddffc4b5fb1edd3790 --- /dev/null +++ b/src/automation/src/test/java/eu/teraflow/automation/EndPointCreationTest.java @@ -0,0 +1,124 @@ +/* +* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package eu.teraflow.automation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import eu.teraflow.automation.context.model.EndPoint; +import eu.teraflow.automation.context.model.EndPointId; +import eu.teraflow.automation.context.model.Location; +import eu.teraflow.automation.context.model.LocationTypeRegion; +import eu.teraflow.automation.context.model.TopologyId; +import eu.teraflow.automation.kpi_sample_types.model.KpiSampleType; +import io.quarkus.test.junit.QuarkusTest; +import java.util.List; +import org.junit.jupiter.api.Test; + +@QuarkusTest +class EndPointCreationTest { + + @Test + void shouldCreateEndPointObjectGivenAllAvailableFields() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + + final var expectedEndPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + final var expectedEndPointType = "expectedEndPointType"; + final var expectedKpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + + final var expectedLocationType = new LocationTypeRegion("ATH"); + final var expectedEndPointLocation = new Location(expectedLocationType); + + final var expectedEndPoint = + new EndPoint.EndPointBuilder( + expectedEndPointId, expectedEndPointType, expectedKpiSampleTypes) + .location(expectedEndPointLocation) + .build(); + + assertThat(expectedEndPoint.getEndPointId()).isEqualTo(expectedEndPointId); + assertThat(expectedEndPoint.getEndPointType()).isEqualTo(expectedEndPointType); + assertThat(expectedEndPoint.getKpiSampleTypes()).isEqualTo(expectedKpiSampleTypes); + assertThat(expectedEndPoint.getEndPointLocation()).isEqualTo(expectedEndPointLocation); + } + + @Test + void shouldCreateEndPointObjectGivenAllFieldsExceptFromLocation() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + + final var expectedEndPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + final var expectedEndPointType = "expectedEndPointType"; + final var expectedKpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + + final var expectedEndPoint = + new EndPoint.EndPointBuilder( + expectedEndPointId, expectedEndPointType, expectedKpiSampleTypes) + .build(); + + assertThat(expectedEndPoint.getEndPointId()).isEqualTo(expectedEndPointId); + assertThat(expectedEndPoint.getEndPointType()).isEqualTo(expectedEndPointType); + assertThat(expectedEndPoint.getKpiSampleTypes()).isEqualTo(expectedKpiSampleTypes); + } + + @Test + void shouldThrowIllegalStateExceptionDuringCreationOfEndPointObjectUponMissingEndPointId() { + final var expectedEndPointType = "expectedEndPointType"; + final var expectedKpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + + final var endPoint = + new EndPoint.EndPointBuilder(null, expectedEndPointType, expectedKpiSampleTypes); + + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(endPoint::build); + } + + @Test + void shouldThrowIllegalStateExceptionDuringCreationOfEndPointObjectUponMissingEndPointType() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + + final var expectedEndPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + final var expectedKpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + + final var endPoint = + new EndPoint.EndPointBuilder(expectedEndPointId, null, expectedKpiSampleTypes); + + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(endPoint::build); + } + + @Test + void shouldThrowIllegalStateExceptionDuringCreationOfEndPointObjectUponMissingKpiSampleTypes() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + + final var expectedEndPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + final var expectedEndPointType = "expectedEndPointType"; + + final var endPoint = + new EndPoint.EndPointBuilder(expectedEndPointId, expectedEndPointType, null); + + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(endPoint::build); + } +} diff --git a/src/automation/src/test/java/eu/teraflow/automation/SerializerTest.java b/src/automation/src/test/java/eu/teraflow/automation/SerializerTest.java index 35074b1dd4a62f0accf49db3ec87c32942de6183..74f8f301ca7d4db904d9092e8f860fc4dc171a51 100644 --- a/src/automation/src/test/java/eu/teraflow/automation/SerializerTest.java +++ b/src/automation/src/test/java/eu/teraflow/automation/SerializerTest.java @@ -43,7 +43,7 @@ import eu.teraflow.automation.context.model.DeviceConfig; import eu.teraflow.automation.context.model.DeviceDriverEnum; import eu.teraflow.automation.context.model.DeviceEvent; import eu.teraflow.automation.context.model.DeviceOperationalStatus; -import eu.teraflow.automation.context.model.EndPoint; +import eu.teraflow.automation.context.model.EndPoint.EndPointBuilder; import eu.teraflow.automation.context.model.EndPointId; import eu.teraflow.automation.context.model.Event; import eu.teraflow.automation.context.model.EventTypeEnum; @@ -1279,6 +1279,133 @@ class SerializerTest { .isThrownBy(() -> serializer.deserialize(serializedLocation)); } + @Test + void shouldSerializeEndPointWithAllAvailableFields() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + final var endPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + + final var endPointType = "endPointType"; + final var kpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + final var locationTypeRegion = new LocationTypeRegion("ATH"); + final var location = new Location(locationTypeRegion); + + final var endPoint = + new EndPointBuilder(endPointId, endPointType, kpiSampleTypes).location(location).build(); + + final var serializedEndPointId = serializer.serialize(endPointId); + final var serializedKpiSampleTypes = + kpiSampleTypes.stream().map(serializer::serialize).collect(Collectors.toList()); + final var serializedEndPointLocation = serializer.serialize(location); + + final var expectedEndPoint = + ContextOuterClass.EndPoint.newBuilder() + .setEndpointId(serializedEndPointId) + .setEndpointType(endPointType) + .addAllKpiSampleTypes(serializedKpiSampleTypes) + .setEndpointLocation(serializedEndPointLocation) + .build(); + + final var serializedEndPoint = serializer.serialize(endPoint); + + assertThat(serializedEndPoint).isEqualTo(expectedEndPoint); + } + + @Test + void shouldDeserializeEndPointWithAllAvailableFields() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + final var endPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + + final var endPointType = "endPointType"; + final var kpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + final var locationTypeRegion = new LocationTypeRegion("ATH"); + final var location = new Location(locationTypeRegion); + + final var expectedEndPoint = + new EndPointBuilder(endPointId, endPointType, kpiSampleTypes).location(location).build(); + + final var serializedEndPointId = serializer.serialize(endPointId); + final var serializedKpiSampleTypes = + kpiSampleTypes.stream().map(serializer::serialize).collect(Collectors.toList()); + final var serializedEndPointLocation = serializer.serialize(location); + + final var serializedEndPoint = + ContextOuterClass.EndPoint.newBuilder() + .setEndpointId(serializedEndPointId) + .setEndpointType(endPointType) + .addAllKpiSampleTypes(serializedKpiSampleTypes) + .setEndpointLocation(serializedEndPointLocation) + .build(); + + final var endPoint = serializer.deserialize(serializedEndPoint); + + assertThat(endPoint).usingRecursiveComparison().isEqualTo(expectedEndPoint); + } + + @Test + void shouldSerializeEndPointWithAllAvailableFieldsMissingLocation() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + final var endPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + + final var endPointType = "endPointType"; + final var kpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + + final var endPoint = new EndPointBuilder(endPointId, endPointType, kpiSampleTypes).build(); + + final var serializedEndPointId = serializer.serialize(endPointId); + final var serializedKpiSampleTypes = + kpiSampleTypes.stream().map(serializer::serialize).collect(Collectors.toList()); + + final var expectedEndPoint = + ContextOuterClass.EndPoint.newBuilder() + .setEndpointId(serializedEndPointId) + .setEndpointType(endPointType) + .addAllKpiSampleTypes(serializedKpiSampleTypes) + .build(); + + final var serializedEndPoint = serializer.serialize(endPoint); + + assertThat(serializedEndPoint).isEqualTo(expectedEndPoint); + } + + @Test + void shouldDeserializeEndPointWithAllAvailableFieldsMissingLocation() { + final var expectedTopologyId = new TopologyId("contextId", "id"); + final var expectedDeviceId = "expectedDeviceId"; + final var expectedId = "expectedId"; + final var endPointId = new EndPointId(expectedTopologyId, expectedDeviceId, expectedId); + + final var endPointType = "endPointType"; + final var kpiSampleTypes = + List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); + + final var expectedEndPoint = + new EndPointBuilder(endPointId, endPointType, kpiSampleTypes).build(); + + final var serializedEndPointId = serializer.serialize(endPointId); + final var serializedKpiSampleTypes = + kpiSampleTypes.stream().map(serializer::serialize).collect(Collectors.toList()); + + final var serializedEndPoint = + ContextOuterClass.EndPoint.newBuilder() + .setEndpointId(serializedEndPointId) + .setEndpointType(endPointType) + .addAllKpiSampleTypes(serializedKpiSampleTypes) + .build(); + + final var endPoint = serializer.deserialize(serializedEndPoint); + + assertThat(endPoint).usingRecursiveComparison().isEqualTo(expectedEndPoint); + } + @Test void shouldSerializeDevice() { final var expectedConfigRuleCustomA = @@ -1310,7 +1437,10 @@ class SerializerTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationA = new Location(locationTypeRegionA); - final var endPointA = new EndPoint(endPointIdA, endPointTypeA, kpiSampleTypesA, locationA); + final var endPointA = + new EndPointBuilder(endPointIdA, endPointTypeA, kpiSampleTypesA) + .location(locationA) + .build(); final var expectedTopologyIdB = new TopologyId("contextIdB", "idB"); final var expectedDeviceIdB = "expectedDeviceIdB"; @@ -1322,7 +1452,10 @@ class SerializerTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationB = new Location(locationTypeRegionB); - final var endPointB = new EndPoint(endPointIdB, endPointTypeB, kpiSampleTypesB, locationB); + final var endPointB = + new EndPointBuilder(endPointIdB, endPointTypeB, kpiSampleTypesB) + .location(locationB) + .build(); final var endPoints = List.of(endPointA, endPointB); @@ -1389,7 +1522,10 @@ class SerializerTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationA = new Location(locationTypeRegionA); - final var endPointA = new EndPoint(endPointIdA, endPointTypeA, kpiSampleTypesA, locationA); + final var endPointA = + new EndPointBuilder(endPointIdA, endPointTypeA, kpiSampleTypesA) + .location(locationA) + .build(); final var expectedTopologyIdB = new TopologyId("contextIdB", "idB"); final var expectedDeviceIdB = "expectedDeviceIdB"; @@ -1401,7 +1537,10 @@ class SerializerTest { List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationB = new Location(locationTypeRegionB); - final var endPointB = new EndPoint(endPointIdB, endPointTypeB, kpiSampleTypesB, locationB); + final var endPointB = + new EndPointBuilder(endPointIdB, endPointTypeB, kpiSampleTypesB) + .location(locationB) + .build(); final var endPoints = List.of(endPointA, endPointB);