Skip to content
Snippets Groups Projects
Commit 91b8c2c6 authored by Fotis Soldatos's avatar Fotis Soldatos
Browse files

refactor(automation): implement builder pattern for EndPoint

parent 0315e6b7
No related branches found
No related tags found
1 merge request!54Release 2.0.0
...@@ -24,6 +24,7 @@ import context.ContextOuterClass.ConfigRule_Custom; ...@@ -24,6 +24,7 @@ import context.ContextOuterClass.ConfigRule_Custom;
import context.ContextOuterClass.ContextId; import context.ContextOuterClass.ContextId;
import context.ContextOuterClass.DeviceId; import context.ContextOuterClass.DeviceId;
import context.ContextOuterClass.DeviceOperationalStatusEnum; import context.ContextOuterClass.DeviceOperationalStatusEnum;
import context.ContextOuterClass.Location.LocationCase;
import context.ContextOuterClass.Uuid; import context.ContextOuterClass.Uuid;
import eu.teraflow.automation.acl.AclAction; import eu.teraflow.automation.acl.AclAction;
import eu.teraflow.automation.acl.AclEntry; import eu.teraflow.automation.acl.AclEntry;
...@@ -833,12 +834,14 @@ public class Serializer { ...@@ -833,12 +834,14 @@ public class Serializer {
final var serializedEndPointId = serialize(endPointId); final var serializedEndPointId = serialize(endPointId);
final var serializedKpiSampleTypes = final var serializedKpiSampleTypes =
kpiSampleTypes.stream().map(this::serialize).collect(Collectors.toList()); 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.setEndpointId(serializedEndPointId);
builder.setEndpointType(endPointType); builder.setEndpointType(endPointType);
builder.addAllKpiSampleTypes(serializedKpiSampleTypes); builder.addAllKpiSampleTypes(serializedKpiSampleTypes);
builder.setEndpointLocation(serializedEndPointLocation);
return builder.build(); return builder.build();
} }
...@@ -852,9 +855,15 @@ public class Serializer { ...@@ -852,9 +855,15 @@ public class Serializer {
final var endPointId = deserialize(serializedEndPointId); final var endPointId = deserialize(serializedEndPointId);
final var kpiSampleTypes = final var kpiSampleTypes =
serializedKpiSampleTypes.stream().map(this::deserialize).collect(Collectors.toList()); 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) { public ContextOuterClass.Device serialize(Device device) {
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
package eu.teraflow.automation.acl; package eu.teraflow.automation.acl;
import eu.teraflow.automation.common.Util;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class AclRuleSet { public class AclRuleSet {
...@@ -64,10 +64,11 @@ public class AclRuleSet { ...@@ -64,10 +64,11 @@ public class AclRuleSet {
public String toString() { public String toString() {
return String.format( return String.format(
"%s:{name:\"%s\", type:\"%s\", description:\"%s\", userId:\"%s\", [%s]}", "%s:{name:\"%s\", type:\"%s\", description:\"%s\", userId:\"%s\", [%s]}",
getClass().getSimpleName(), name, type.toString(), description, userId, toString(entries)); getClass().getSimpleName(),
} name,
type.toString(),
private static <T> String toString(List<T> list) { description,
return list.stream().map(T::toString).collect(Collectors.joining(", ")); userId,
Util.toString(entries));
} }
} }
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
package eu.teraflow.automation.context.model; package eu.teraflow.automation.context.model;
import eu.teraflow.automation.common.Util;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class Device { public class Device {
...@@ -102,11 +102,7 @@ public class Device { ...@@ -102,11 +102,7 @@ public class Device {
deviceType, deviceType,
deviceConfig, deviceConfig,
deviceOperationalStatus.toString(), deviceOperationalStatus.toString(),
toString(deviceDrivers), Util.toString(deviceDrivers),
toString(endPoints)); Util.toString(endPoints));
}
private static <T> String toString(List<T> list) {
return list.stream().map(T::toString).collect(Collectors.joining(", "));
} }
} }
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
package eu.teraflow.automation.context.model; package eu.teraflow.automation.context.model;
import eu.teraflow.automation.common.Util;
import eu.teraflow.automation.kpi_sample_types.model.KpiSampleType; import eu.teraflow.automation.kpi_sample_types.model.KpiSampleType;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class EndPoint { public class EndPoint {
private final EndPointId endPointId; private final EndPointId endPointId;
...@@ -26,15 +26,11 @@ public class EndPoint { ...@@ -26,15 +26,11 @@ public class EndPoint {
private final List<KpiSampleType> kpiSampleTypes; private final List<KpiSampleType> kpiSampleTypes;
private final Location endPointLocation; private final Location endPointLocation;
public EndPoint( EndPoint(EndPointBuilder builder) {
EndPointId endPointId, this.endPointId = builder.endPointId;
String endPointType, this.endPointType = builder.endPointType;
List<KpiSampleType> kpiSampleTypes, this.kpiSampleTypes = builder.kpiSampleTypes;
Location endPointLocation) { this.endPointLocation = builder.endPointLocation;
this.endPointId = endPointId;
this.endPointType = endPointType;
this.kpiSampleTypes = kpiSampleTypes;
this.endPointLocation = endPointLocation;
} }
public EndPointId getEndPointId() { public EndPointId getEndPointId() {
...@@ -60,11 +56,50 @@ public class EndPoint { ...@@ -60,11 +56,50 @@ public class EndPoint {
getClass().getSimpleName(), getClass().getSimpleName(),
endPointId, endPointId,
endPointType, endPointType,
toString(kpiSampleTypes), Util.toString(kpiSampleTypes),
endPointLocation); endPointLocation);
} }
private static <T> String toString(List<T> list) { public static class EndPointBuilder {
return list.stream().map(T::toString).collect(Collectors.joining(", ")); 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");
}
}
} }
} }
...@@ -29,7 +29,7 @@ import eu.teraflow.automation.context.model.Device; ...@@ -29,7 +29,7 @@ import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceConfig; import eu.teraflow.automation.context.model.DeviceConfig;
import eu.teraflow.automation.context.model.DeviceDriverEnum; import eu.teraflow.automation.context.model.DeviceDriverEnum;
import eu.teraflow.automation.context.model.DeviceOperationalStatus; 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.EndPointId;
import eu.teraflow.automation.context.model.Location; import eu.teraflow.automation.context.model.Location;
import eu.teraflow.automation.context.model.LocationTypeRegion; import eu.teraflow.automation.context.model.LocationTypeRegion;
...@@ -109,7 +109,10 @@ class AutomationFunctionalServiceTest { ...@@ -109,7 +109,10 @@ class AutomationFunctionalServiceTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationTypeRegionA = new LocationTypeRegion("ATH");
final var locationA = new Location(locationTypeRegionA); 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 topologyIdB = new TopologyId("contextIdB", "idB");
final var deviceIdB = "deviceIdB"; final var deviceIdB = "deviceIdB";
...@@ -120,7 +123,10 @@ class AutomationFunctionalServiceTest { ...@@ -120,7 +123,10 @@ class AutomationFunctionalServiceTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationTypeRegionB = new LocationTypeRegion("ATH");
final var locationB = new Location(locationTypeRegionB); 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); final var endPoints = List.of(endPointA, endPointB);
...@@ -217,7 +223,10 @@ class AutomationFunctionalServiceTest { ...@@ -217,7 +223,10 @@ class AutomationFunctionalServiceTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationTypeRegionA = new LocationTypeRegion("ATH");
final var locationA = new Location(locationTypeRegionA); 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 topologyIdB = new TopologyId("contextIdB", "idB");
final var deviceIdB = "deviceIdB"; final var deviceIdB = "deviceIdB";
...@@ -228,7 +237,10 @@ class AutomationFunctionalServiceTest { ...@@ -228,7 +237,10 @@ class AutomationFunctionalServiceTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationTypeRegionB = new LocationTypeRegion("ATH");
final var locationB = new Location(locationTypeRegionB); 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); final var endPoints = List.of(endPointA, endPointB);
......
...@@ -30,7 +30,7 @@ import eu.teraflow.automation.context.model.Device; ...@@ -30,7 +30,7 @@ import eu.teraflow.automation.context.model.Device;
import eu.teraflow.automation.context.model.DeviceConfig; import eu.teraflow.automation.context.model.DeviceConfig;
import eu.teraflow.automation.context.model.DeviceDriverEnum; import eu.teraflow.automation.context.model.DeviceDriverEnum;
import eu.teraflow.automation.context.model.DeviceOperationalStatus; 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.EndPointId;
import eu.teraflow.automation.context.model.Location; import eu.teraflow.automation.context.model.Location;
import eu.teraflow.automation.context.model.LocationTypeRegion; import eu.teraflow.automation.context.model.LocationTypeRegion;
...@@ -88,7 +88,10 @@ class AutomationServiceTest { ...@@ -88,7 +88,10 @@ class AutomationServiceTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationTypeRegionA = new LocationTypeRegion("ATH");
final var locationA = new Location(locationTypeRegionA); 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 topologyIdB = new TopologyId("contextIdB", "idB");
final var deviceIdB = "deviceIdB"; final var deviceIdB = "deviceIdB";
...@@ -99,7 +102,10 @@ class AutomationServiceTest { ...@@ -99,7 +102,10 @@ class AutomationServiceTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationTypeRegionB = new LocationTypeRegion("ATH");
final var locationB = new Location(locationTypeRegionB); 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); final var endPoints = List.of(endPointA, endPointB);
......
/*
* 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);
}
}
...@@ -43,7 +43,7 @@ import eu.teraflow.automation.context.model.DeviceConfig; ...@@ -43,7 +43,7 @@ import eu.teraflow.automation.context.model.DeviceConfig;
import eu.teraflow.automation.context.model.DeviceDriverEnum; import eu.teraflow.automation.context.model.DeviceDriverEnum;
import eu.teraflow.automation.context.model.DeviceEvent; import eu.teraflow.automation.context.model.DeviceEvent;
import eu.teraflow.automation.context.model.DeviceOperationalStatus; 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.EndPointId;
import eu.teraflow.automation.context.model.Event; import eu.teraflow.automation.context.model.Event;
import eu.teraflow.automation.context.model.EventTypeEnum; import eu.teraflow.automation.context.model.EventTypeEnum;
...@@ -1279,6 +1279,133 @@ class SerializerTest { ...@@ -1279,6 +1279,133 @@ class SerializerTest {
.isThrownBy(() -> serializer.deserialize(serializedLocation)); .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 @Test
void shouldSerializeDevice() { void shouldSerializeDevice() {
final var expectedConfigRuleCustomA = final var expectedConfigRuleCustomA =
...@@ -1310,7 +1437,10 @@ class SerializerTest { ...@@ -1310,7 +1437,10 @@ class SerializerTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationTypeRegionA = new LocationTypeRegion("ATH");
final var locationA = new Location(locationTypeRegionA); 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 expectedTopologyIdB = new TopologyId("contextIdB", "idB");
final var expectedDeviceIdB = "expectedDeviceIdB"; final var expectedDeviceIdB = "expectedDeviceIdB";
...@@ -1322,7 +1452,10 @@ class SerializerTest { ...@@ -1322,7 +1452,10 @@ class SerializerTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationTypeRegionB = new LocationTypeRegion("ATH");
final var locationB = new Location(locationTypeRegionB); 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); final var endPoints = List.of(endPointA, endPointB);
...@@ -1389,7 +1522,10 @@ class SerializerTest { ...@@ -1389,7 +1522,10 @@ class SerializerTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionA = new LocationTypeRegion("ATH"); final var locationTypeRegionA = new LocationTypeRegion("ATH");
final var locationA = new Location(locationTypeRegionA); 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 expectedTopologyIdB = new TopologyId("contextIdB", "idB");
final var expectedDeviceIdB = "expectedDeviceIdB"; final var expectedDeviceIdB = "expectedDeviceIdB";
...@@ -1401,7 +1537,10 @@ class SerializerTest { ...@@ -1401,7 +1537,10 @@ class SerializerTest {
List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED); List.of(KpiSampleType.BYTES_RECEIVED, KpiSampleType.BYTES_TRANSMITTED);
final var locationTypeRegionB = new LocationTypeRegion("ATH"); final var locationTypeRegionB = new LocationTypeRegion("ATH");
final var locationB = new Location(locationTypeRegionB); 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); final var endPoints = List.of(endPointA, endPointB);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment