From d58e0cb39096a5ecb4eaf1f17ed6b9d7d83d829d Mon Sep 17 00:00:00 2001 From: Samir Romdhani Date: Tue, 9 Aug 2022 14:41:22 +0200 Subject: [PATCH] fix error marshalling SCL after automatic scd creation call (#127) [#126] fix importSTDElementsInSCD when copying Compas ICDHeader and add assertIsMarshallable to tests Signed-off-by: samirromdhani Signed-off-by: massifben <105049157+massifben@users.noreply.github.com> Co-authored-by: samirromdhani Co-authored-by: massifben <105049157+massifben@users.noreply.github.com> --- .../SclAutomationServiceTest.java | 19 ++++++- .../compas/sct/commons/scl/SclService.java | 31 ++++++------ .../sct/commons/scl/SclRootAdapterTest.java | 11 ++-- .../sct/commons/scl/SclServiceTest.java | 50 +++++++++++-------- .../sct/commons/scl/ied/IEDAdapterTest.java | 8 +-- .../testhelpers/SclTestMarshaller.java | 7 +++ 6 files changed, 78 insertions(+), 48 deletions(-) diff --git a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java index 6aecfd219..84e413104 100644 --- a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java +++ b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java @@ -17,6 +17,7 @@ import java.util.Set; import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; class SclAutomationServiceTest { @@ -30,20 +31,25 @@ void init(){ } @Test - void createSCD() throws Exception { + void createSCD_should_return_generatedSCD() throws Exception { + // Given SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml"); SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); + // When SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std)); + // Then assertNotNull(expectedSCD.getCurrentElem().getHeader().getId()); assertNull(expectedSCD.getCurrentElem().getHeader().getHistory()); assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size()); assertEquals(1, expectedSCD.getCurrentElem().getIED().size()); assertNotNull(expectedSCD.getCurrentElem().getDataTypeTemplates()); assertEquals(2, expectedSCD.getCurrentElem().getCommunication().getSubNetwork().size()); + assertIsMarshallable(expectedSCD.getCurrentElem()); } @Test void createSCD_With_HItem() throws Exception { + // Given HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem(); historyItem.setWhat("what"); historyItem.setWho("me"); @@ -53,14 +59,18 @@ void createSCD_With_HItem() throws Exception { SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml"); SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml"); SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml"); + // When SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std1, std2, std3)); + // Then assertNotNull(expectedSCD.getCurrentElem().getHeader().getId()); assertEquals(1 ,expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size()); assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size()); + assertIsMarshallable(expectedSCD.getCurrentElem()); } @Test void createSCD_With_HItems() throws Exception { + // Given HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem(); historyItem.setWhat("what"); historyItem.setWho("me"); @@ -74,17 +84,22 @@ void createSCD_With_HItems() throws Exception { SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml"); SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml"); SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml"); + // When SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO,Set.of(std1, std2, std3)); + // Then assertNotNull(expectedSCD.getCurrentElem().getHeader().getId()); assertEquals(1, expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size()); assertEquals("what", expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().get(0).getWhat()); + assertIsMarshallable(expectedSCD.getCurrentElem()); } @Test void createSCD_SSD_Without_Substation() throws Exception { + // Given SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml"); + // When & Then assertThrows(ScdException.class, () -> SclAutomationService.createSCD(ssd, headerDTO, new HashSet<>()) ); } -} \ No newline at end of file +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java index f352ec16b..bcd2cb5b6 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java @@ -412,7 +412,7 @@ public static SclRootAdapter importSTDElementsInSCD(@NonNull SclRootAdapter scdR for (Map.Entry entry : mapIEDNameAndPrivate.entrySet()) { String iedName = entry.getKey(); TPrivate tPrivate = entry.getValue(); - String icdSysVerUuid = getCompasICDHeader(tPrivate).map(TCompasICDHeader::getICDSystemVersionUUID).orElseThrow( + String icdSysVerUuid = getCompasICDHeaderValue(tPrivate).map(TCompasICDHeader::getICDSystemVersionUUID).orElseThrow( () -> new ScdException(ICD_SYSTEM_VERSION_UUID + " is not present in COMPAS-ICDHeader in LNode") ); @@ -446,10 +446,10 @@ private static void checkSTDCorrespondanceWithLNodeCompasICDHeader(Map new ScdException(CommonConstants.COMPAS_ICDHEADER + "not found in LNode Private ")); return iedCompasICDHeader.getIEDType().equals(scdCompasICDHeader.getIEDType()) && iedCompasICDHeader.getICDSystemVersionUUID().equals(scdCompasICDHeader.getICDSystemVersionUUID()) @@ -495,20 +495,21 @@ private static boolean comparePrivateCompasICDHeaders(TPrivate iedPrivate, TPriv } private static void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate(TPrivate stdPrivate, TPrivate lNodePrivate) throws ScdException { - TCompasICDHeader lNodeCompasICDHeader = getCompasICDHeader(lNodePrivate).orElseThrow( + JAXBElement lNodeCompasICDHeader = getCompasICDHeader(lNodePrivate).orElseThrow( () -> new ScdException(CommonConstants.COMPAS_ICDHEADER + "not found in LNode Private ")); stdPrivate.getContent().clear(); stdPrivate.getContent().add(lNodeCompasICDHeader); - } - private static Optional getCompasICDHeader(TPrivate tPrivate) { - Optional> tCompasICDHeader = !tPrivate.getType().equals(CommonConstants.COMPAS_ICDHEADER) ? Optional.empty() : + private static Optional> getCompasICDHeader(TPrivate tPrivate) { + return !tPrivate.getType().equals(CommonConstants.COMPAS_ICDHEADER) ? Optional.empty() : tPrivate.getContent().stream() .filter(JAXBElement.class::isInstance) .map(o -> (JAXBElement) o) .findFirst(); - return tCompasICDHeader.map(JAXBElement::getValue); + } + private static Optional getCompasICDHeaderValue(TPrivate tPrivate) { + return getCompasICDHeader(tPrivate).map(JAXBElement::getValue); } public static void removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(final SCL scl) { diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java index c35d252e1..f83ab071b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java @@ -9,12 +9,12 @@ import org.lfenergy.compas.scl2007b4.model.SCL; import org.lfenergy.compas.scl2007b4.model.TPrivate; import org.lfenergy.compas.sct.commons.exception.ScdException; -import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import java.util.concurrent.atomic.AtomicReference; import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; @Slf4j class SclRootAdapterTest { @@ -34,6 +34,7 @@ void testConstruction() { assertEquals(SclRootAdapter.RELEASE,sclRootAdapter.get().getSclRelease()); assertEquals(SclRootAdapter.VERSION,sclRootAdapter.get().getSclVersion()); assertEquals(SclRootAdapter.REVISION,sclRootAdapter.get().getSclRevision()); + assertIsMarshallable(sclRootAdapter.get().getCurrentElem()); assertThrows(IllegalArgumentException.class, () -> new SclRootAdapter(new SCL())); } @@ -50,10 +51,7 @@ void addIED() throws Exception { assertDoesNotThrow(() -> sclRootAdapter.addIED(icd1, "IED_NAME1")); assertThrows(ScdException.class, () -> sclRootAdapter.addIED(icd1, "IED_NAME1")); assertDoesNotThrow(() -> sclRootAdapter.addIED(icd2, "IED_NAME2")); - - MarshallerWrapper marshallerWrapper = SclTestMarshaller.createWrapper(); - System.out.println(marshallerWrapper.marshall(sclRootAdapter.getCurrentElem())); - + assertIsMarshallable(scd); } @Test @@ -66,5 +64,6 @@ void addPrivate() throws Exception { assertTrue(sclRootAdapter.getCurrentElem().getPrivate().isEmpty()); sclRootAdapter.addPrivate(tPrivate); assertEquals(1, sclRootAdapter.getCurrentElem().getPrivate().size()); + assertIsMarshallable(scd); } -} \ No newline at end of file +} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java index 6c437dfc9..ce5dc93e9 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java @@ -13,7 +13,6 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.ied.*; -import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import java.util.*; @@ -23,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.createDa; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.createDo; +import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; class SclServiceTest { @@ -43,6 +43,7 @@ void testAddHistoryItem() throws ScdException { assertEquals("why", tHitem.getWhy()); assertEquals(SclRootAdapter.REVISION, tHitem.getRevision()); assertEquals(SclRootAdapter.VERSION, tHitem.getVersion()); + assertIsMarshallable(scd); } @Test @@ -57,8 +58,7 @@ void testAddIED() throws Exception { assertEquals("IED_NAME1", iedAdapter.getName()); assertNotNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates()); - MarshallerWrapper marshallerWrapper = SclTestMarshaller.createWrapper(); - System.out.println(marshallerWrapper.marshall(scd)); + assertIsMarshallable(scd); } @Test @@ -79,8 +79,7 @@ void testAddSubnetworks() throws Exception { subNetworkDTO.addConnectedAP(connectedApDTO); assertDoesNotThrow(() -> SclService.addSubnetworks(scd, Set.of(subNetworkDTO), Optional.of(icd)).get()); - MarshallerWrapper marshallerWrapper = SclTestMarshaller.createWrapper(); - System.out.println(marshallerWrapper.marshall(scd)); + assertIsMarshallable(scd); } @Test @@ -93,8 +92,7 @@ void testAddSubnetworksWithoutCommunicationTagInIcd() throws Exception { assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd)); assertDoesNotThrow(() -> SclService.addSubnetworks(scd, new HashSet<>(), Optional.of(icd))); - MarshallerWrapper marshallerWrapper = SclTestMarshaller.createWrapper(); - String marshalledScd = marshallerWrapper.marshall(scd); + String marshalledScd = assertIsMarshallable(scd); assertThat(marshalledScd).doesNotContain(" subNetworkDTOSet = new HashSet<>(SclService.getSubnetwork(icd)); assertDoesNotThrow(() -> SclService.addSubnetworks(scd, subNetworkDTOSet, Optional.of(icd)).get()); - MarshallerWrapper marshallerWrapper = SclTestMarshaller.createWrapper(); - String marshalledScd = marshallerWrapper.marshall(scd); + String marshalledScd = assertIsMarshallable(scd); assertThat(marshalledScd).contains("
", "PhysConn"); } @@ -127,8 +124,7 @@ void testAddSubnetworksWithoutImportingIcdAddressAndPhysConn() throws Exception Set subNetworkDTOSet = new HashSet<>(SclService.getSubnetwork(icd)); assertDoesNotThrow(() -> SclService.addSubnetworks(scd, subNetworkDTOSet, Optional.empty()).get()); - MarshallerWrapper marshallerWrapper = SclTestMarshaller.createWrapper(); - String marshalledScd = marshallerWrapper.marshall(scd); + String marshalledScd = assertIsMarshallable(scd); assertThat(marshalledScd).doesNotContain("
", "PhysConn"); } @@ -240,6 +236,7 @@ void testUpdateExtRefBinders() throws Exception { ScdException.class, () -> SclService.updateExtRefBinders(scd, extRefInfo) ); + assertIsMarshallable(scd); } @Test @@ -509,17 +506,19 @@ void getDAI_should_filter_updatable_DA_with_sGroup_Val_without_ConfSg() throws E @Test void testInitScl() { - assertDoesNotThrow( - () -> SclService.initScl(Optional.empty(), "hVersion", "hRevision") + SclRootAdapter sclRootAdapter = assertDoesNotThrow( + () -> SclService.initScl(Optional.empty(), "hVersion", "hRevision") ); + assertIsMarshallable(sclRootAdapter.getCurrentElem()); } @Test void testInitScl_With_hId_shouldNotThrowError() { UUID hid = UUID.randomUUID(); - assertDoesNotThrow( - () -> SclService.initScl(Optional.of(hid), "hVersion", "hRevision") + SclRootAdapter sclRootAdapter = assertDoesNotThrow( + () -> SclService.initScl(Optional.of(hid), "hVersion", "hRevision") ); + assertIsMarshallable(sclRootAdapter.getCurrentElem()); } @Test @@ -530,6 +529,7 @@ void testInitScl_Create_Private_SCL_FILETYPE() { ); assertThat(rootAdapter.getCurrentElem().getPrivate()).isNotEmpty(); assertThat(rootAdapter.getCurrentElem().getPrivate().get(0).getType()).isEqualTo(CommonConstants.COMPAS_SCL_FILE_TYPE); + assertIsMarshallable(rootAdapter.getCurrentElem()); } @Test @@ -541,8 +541,7 @@ void testUpdateHeader() { UUID hId = UUID.fromString(sclRootAdapter.getHeaderAdapter().getHeaderId()); HeaderDTO headerDTO = DTO.createHeaderDTO(hId); SclService.updateHeader(sclRootAdapter.getCurrentElem(), headerDTO); - SclService.updateHeader(sclRootAdapter.getCurrentElem(), headerDTO); - + assertIsMarshallable(sclRootAdapter.getCurrentElem()); } @Test @@ -564,7 +563,7 @@ void testUpdateDAI() throws Exception { tVal.setValue("newValue"); rDtt.setDaiValues(List.of(tVal)); assertDoesNotThrow(() -> SclService.updateDAI(scd, "IED_NAME", "LD_INS1", rDtt)); - + assertIsMarshallable(scd); } @Test @@ -586,6 +585,7 @@ void testAddSubstation_Check_SSD_Validity(String ssdFileName) throws Exception { assertThrows(ScdException.class, () -> SclService.addSubstation(scd, ssd)); + assertIsMarshallable(scd); } @Test @@ -598,6 +598,7 @@ void testAddSubstation_SCD_Without_Substation() throws Exception { assertNotEquals(scdRootAdapter, expectedScdAdapter); assertEquals(expectedScdAdapter.getCurrentElem().getSubstation(), ssdRootAdapter.getCurrentElem().getSubstation()); + assertIsMarshallable(scd); } @Test @@ -607,6 +608,7 @@ void testAddSubstation_SCD_With_Different_Substation_Name() throws Exception { assertThrows(ScdException.class, () -> SclService.addSubstation(scd, ssd)); + assertIsMarshallable(scd); } @Test @@ -622,6 +624,7 @@ void testAddSubstation_SCD_With_Substation() throws Exception { assertNotEquals(scdRootAdapter, expectedScdAdapter); assertEquals(expectedTSubstation.getName(), tSubstation.getName()); assertEquals(expectedTSubstation.getVoltageLevel().size(), tSubstation.getVoltageLevel().size()); + assertIsMarshallable(scd); } @Test @@ -635,6 +638,7 @@ void testImportSTDElementsInSCD() throws Exception { assertThat(expectedScdAdapter.getCurrentElem().getIED()).hasSize(1); assertThat(expectedScdAdapter.getCurrentElem().getDataTypeTemplates()).hasNoNullFieldsOrProperties(); assertThat(expectedScdAdapter.getCurrentElem().getCommunication().getSubNetwork()).hasSize(2); + assertIsMarshallable(scd); } @Test @@ -652,6 +656,7 @@ void testImportSTDElementsInSCD_with_Multiple_STD() throws Exception { assertThat(expectedScdAdapter.getCurrentElem().getCommunication().getSubNetwork()).hasSize(2); assertThat(expectedScdAdapter.getCurrentElem().getCommunication().getSubNetwork().get(0).getConnectedAP()).hasSizeBetween(1,3); assertThat(expectedScdAdapter.getCurrentElem().getCommunication().getSubNetwork().get(1).getConnectedAP()).hasSizeBetween(1,3); + assertIsMarshallable(scd); } @Test @@ -662,7 +667,7 @@ void testImportSTDElementsInSCD_Several_STD_Match_Compas_ICDHeader() throws Exce SclRootAdapter scdRootAdapter = new SclRootAdapter(scd); assertThrows(ScdException.class, () -> SclService.importSTDElementsInSCD(scdRootAdapter, Set.of(std, std1), DTO.comMap)); - + assertIsMarshallable(scd); } @Test @@ -672,7 +677,7 @@ void testImportSTDElementsInSCD_Compas_ICDHeader_Not_Match() throws Exception { SclRootAdapter scdRootAdapter = new SclRootAdapter(scd); assertThrows(ScdException.class, ()-> SclService.importSTDElementsInSCD(scdRootAdapter, Set.of(std), DTO.comMap)); - + assertIsMarshallable(scd); } @Test @@ -681,7 +686,7 @@ void testImportSTDElementsInSCD_No_STD_Match() throws Exception { SclRootAdapter scdRootAdapter = new SclRootAdapter(scd); assertThrows(ScdException.class, ()-> SclService.importSTDElementsInSCD(scdRootAdapter, new HashSet<>(), DTO.comMap)); - + assertIsMarshallable(scd); } @Test @@ -702,6 +707,7 @@ void removeControlBlocksAndDatasetAndExtRefSrc_should_remove_controlBlocks_and_D .noneMatch(TAnyLN::isSetReportControl) .noneMatch(LN0::isSetGSEControl) .noneMatch(LN0::isSetSampledValueControl); + assertIsMarshallable(scl); } @Test @@ -721,6 +727,7 @@ void removeControlBlocksAndDatasetAndExtRefSrc_should_remove_controlBlocks_and_D .noneMatch(TAnyLN::isSetDataSet) .noneMatch(TAnyLN::isSetLogControl) .noneMatch(TAnyLN::isSetReportControl); + assertIsMarshallable(scl); } @Test @@ -744,6 +751,7 @@ void removeControlBlocksAndDatasetAndExtRefSrc_should_remove_srcXXX_attributes_o .noneMatch(TExtRef::isSetSrcLNInst) .noneMatch(TExtRef::isSetSrcCBName) .noneMatch(TExtRef::isSetSrcLNClass); + assertIsMarshallable(scl); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java index 320ad9886..b75e19ff6 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java @@ -13,7 +13,6 @@ import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.ObjectReference; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.mockito.Mockito; @@ -22,6 +21,7 @@ import java.util.Map; import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; class IEDAdapterTest { @@ -155,8 +155,7 @@ void testCreateDataSet() throws Exception { dataSetInfo.setHolderLnClass(TLLN0Enum.LLN_0.value()); assertDoesNotThrow(() -> iAdapter.createDataSet(dataSetInfo)); - MarshallerWrapper marshallerWrapper = SclTestMarshaller.createWrapper(); - System.out.println(marshallerWrapper.marshall(scd)); + assertIsMarshallable(scd); } @Test @@ -227,6 +226,7 @@ void createControlBlock() throws Exception { controlBlock.setHolderIEDName("IED_NAME"); controlBlock.setHolderIEDName("IED_NAME"); controlBlock.setHolderIEDName("IED_NAME"); + assertIsMarshallable(scd); } @Test @@ -244,4 +244,4 @@ void addPrivate() { iAdapter.addPrivate(tPrivate); assertEquals(1, iAdapter.getCurrentElem().getPrivate().size()); } -} \ No newline at end of file +} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclTestMarshaller.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclTestMarshaller.java index c0fc4850d..98594458b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclTestMarshaller.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclTestMarshaller.java @@ -7,6 +7,8 @@ import org.apache.commons.io.IOUtils; import org.lfenergy.compas.scl2007b4.model.SCL; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + public class SclTestMarshaller { public static SCL getSCLFromFile(String filename) throws Exception { @@ -15,6 +17,11 @@ public static SCL getSCLFromFile(String filename) throws Exception { return marshallerWrapper.unmarshall(rawXml,SCL.class); } + public static String assertIsMarshallable(SCL scl) { + MarshallerWrapper marshallerWrapper = createWrapper(); + return assertDoesNotThrow(() -> marshallerWrapper.marshall(scl)); + } + public static MarshallerWrapper createWrapper() { return MarshallerWrapper.builder() .withProperties("classpath:scl_schema.yml")