diff --git a/sct-commons/src/main/java/org/lfenergy/compas/scl2007b4/model/package-info.java b/sct-commons/src/main/java/org/lfenergy/compas/scl2007b4/model/package-info.java new file mode 100644 index 000000000..956fc92ac --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/scl2007b4/model/package-info.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +@XmlSchema( + namespace = "http://www.iec.ch/61850/2003/SCL", + xmlns = { + @XmlNs(namespaceURI = "http://www.iec.ch/61850/2003/SCL", prefix = ""), + @XmlNs(namespaceURI = "https://www.lfenergy.org/compas/extension/v1", prefix = "compas") + }, + elementFormDefault = XmlNsForm.QUALIFIED) + + +package org.lfenergy.compas.scl2007b4.model; + +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlNsForm; +import javax.xml.bind.annotation.XmlSchema; + +/* This file is used by the Marshaller to set prefix "compas" for Compas Privates when marshalling JAXB objects */ diff --git a/sct-commons/src/test/java/org/lfenergy/compas/scl2007b4/model/NamespaceConfigurationTest.java b/sct-commons/src/test/java/org/lfenergy/compas/scl2007b4/model/NamespaceConfigurationTest.java new file mode 100644 index 000000000..a4b413b91 --- /dev/null +++ b/sct-commons/src/test/java/org/lfenergy/compas/scl2007b4/model/NamespaceConfigurationTest.java @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.scl2007b4.model; + +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.sct.commons.scl.PrivateService; +import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; + +import static org.assertj.core.api.Assertions.assertThat; + +class NamespaceConfigurationTest { + + @Test + void marshalling_SCL_and_Compas_Privates_should_set_correct_prefix() { + // Given + SCL scl = createValidScl(); + TPrivate aCompasPrivate = PrivateService.createPrivate(TCompasSclFileType.SCD); + scl.getPrivate().add(aCompasPrivate); + // When + String result = MarshallerWrapper.marshall(scl); + // Then + assertThat(result) + .containsPattern("(?s)]* xmlns=\"http://www\\.iec\\.ch/61850/2003/SCL\"") + .containsPattern("(?s)]* xmlns:compas=\"https://www\\.lfenergy\\.org/compas/extension/v1\""); + } + + private static SCL createValidScl() { + SCL scl = new SCL(); + scl.setVersion("2007"); + scl.setRevision("B"); + scl.setRelease((short) 4); + THeader tHeader = new THeader(); + tHeader.setId("headerId"); + scl.setHeader(tHeader); + return scl; + } +}