Skip to content

Commit

Permalink
Merge pull request #288 from com-pas/fix/287_invalid_prefix_for_compa…
Browse files Browse the repository at this point in the history
…s_privates_when_marshalling

fix(#287): fix invalid prefix for Compas Privates when marshalling
  • Loading branch information
massifben authored Jun 9, 2023
2 parents c4d0729 + f3d3392 commit d0e9a95
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 */
Original file line number Diff line number Diff line change
@@ -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)<SCL[^>]* xmlns=\"http://www\\.iec\\.ch/61850/2003/SCL\"")
.containsPattern("(?s)<SCL[^>]* 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;
}
}

0 comments on commit d0e9a95

Please sign in to comment.