From d9b27b029870539fe2e3b6252efb791160fcd887 Mon Sep 17 00:00:00 2001 From: massifben <105049157+massifben@users.noreply.github.com> Date: Wed, 12 Jul 2023 12:17:53 +0200 Subject: [PATCH] feat(#295): add createPrivate for CompasTopo Signed-off-by: massifben <105049157+massifben@users.noreply.github.com> --- .../compas/sct/commons/scl/PrivateService.java | 15 +++++++++++++++ .../sct/commons/scl/PrivateServiceTest.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/PrivateService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/PrivateService.java index 5a12f3a25..68d4002ca 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/PrivateService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/PrivateService.java @@ -159,6 +159,21 @@ public static TPrivate createPrivate(TCompasSystemVersion compasSystemVersion) { return createPrivate(objectFactory.createSystemVersion(compasSystemVersion)); } + /** + * Create a single Private of type COMPAS-Topo + * containing all given TCompasTopo + * @param compasTopos list of TCompasTopo + * @return created Private + */ + public static TPrivate createPrivate(List compasTopos) { + TPrivate tPrivate = new TPrivate(); + tPrivate.setType(PrivateEnum.COMPAS_TOPO.getPrivateType()); + tPrivate.getContent().addAll( + compasTopos.stream().map(objectFactory::createTopo).toList() + ); + return tPrivate; + } + /** * Create Private of given type as parameter * @param jaxbElement content of Private to create diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java index 43b70fd52..73d82e4d4 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java @@ -579,4 +579,19 @@ private static TIED createTIED() { SCL sclFromFile = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); return sclFromFile.getIED().get(0); } + + @Test + void createPrivate_compas_Topo_should_succeed(){ + // Given + TCompasTopo tCompasTopo1 = new TCompasTopo(); + TCompasTopo tCompasTopo2 = new TCompasTopo(); + List compasTopos = List.of(tCompasTopo1, tCompasTopo2); + // When + TPrivate result = PrivateService.createPrivate(compasTopos); + // Then + assertThat(result.getContent()) + .map(JAXBElement.class::cast) + .map(JAXBElement::getValue) + .containsExactly(tCompasTopo1, tCompasTopo2); + } }