diff --git a/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/MaintainableArtefactReference.java b/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/MaintainableArtefactReference.java index d38d95a..e55be49 100644 --- a/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/MaintainableArtefactReference.java +++ b/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/MaintainableArtefactReference.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; @Data @NoArgsConstructor @@ -34,11 +35,12 @@ public MaintainableArtefactReference(String id, String organisationId, String ve } public MaintainableArtefactReference(String urn) { - final UrnComponents urnComponents = SdmxUrn.getUrnComponents(urn); + final String trimmedUrn = StringUtils.trim(urn); + final UrnComponents urnComponents = SdmxUrn.getUrnComponents(trimmedUrn); this.organisationId = urnComponents.getAgency(); this.id = urnComponents.getId(); this.version = VersionReference.createFromString(urnComponents.getVersion()); - this.structureClass = getType(urn); + this.structureClass = getType(trimmedUrn); } public MaintainableArtefactReference(ArtefactReference from) { diff --git a/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/SdmxUrn.java b/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/SdmxUrn.java index c9979dc..9da143a 100644 --- a/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/SdmxUrn.java +++ b/sdmx30-infomodel/src/main/java/com/epam/jsdmx/infomodel/sdmx30/SdmxUrn.java @@ -44,12 +44,13 @@ public static boolean isUrn(String candidate) { } public static UrnComponents getUrnComponents(String urn) { - final Matcher fullUrnMatcher = FULL_URN_PATTERN.matcher(urn); + final String trimmedUrn = StringUtils.trim(urn); + final Matcher fullUrnMatcher = FULL_URN_PATTERN.matcher(trimmedUrn); if (fullUrnMatcher.matches()) { return buildFromFullUrn(fullUrnMatcher); } - final Matcher shortUrnMatcher = SHORT_URN_PATTERN.matcher(urn); + final Matcher shortUrnMatcher = SHORT_URN_PATTERN.matcher(trimmedUrn); if (shortUrnMatcher.matches()) { return buildFromShortUrn(shortUrnMatcher); } diff --git a/sdmx30-infomodel/src/test/java/com/epam/jsdmx/infomodel/sdmx30/MaintainableArtefactReferenceTest.java b/sdmx30-infomodel/src/test/java/com/epam/jsdmx/infomodel/sdmx30/MaintainableArtefactReferenceTest.java new file mode 100644 index 0000000..03223ff --- /dev/null +++ b/sdmx30-infomodel/src/test/java/com/epam/jsdmx/infomodel/sdmx30/MaintainableArtefactReferenceTest.java @@ -0,0 +1,31 @@ +package com.epam.jsdmx.infomodel.sdmx30; + + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class MaintainableArtefactReferenceTest { + + @ParameterizedTest + @MethodSource + void shouldTrimUrnOnInit(String urn) { + var res = new MaintainableArtefactReference("\nurn:sdmx:org.sdmx.infomodel.codelist.Codelist=EPM:CL(1.0)"); + assertThat(res).isNotNull(); + } + + private static Stream shouldTrimUrnOnInit() { + return Stream.of( + Arguments.of("\nurn:sdmx:org.sdmx.infomodel.codelist.Codelist=EPM:CL(1.0)"), + Arguments.of("\n urn:sdmx:org.sdmx.infomodel.codelist.Codelist=EPM:CL(1.0)"), + Arguments.of("\nurn:sdmx:org.sdmx.infomodel.codelist.Codelist=EPM:CL(1.0) "), + Arguments.of("\n urn:sdmx:org.sdmx.infomodel.codelist.Codelist=EPM:CL(1.0) "), + Arguments.of("\n urn:sdmx:org.sdmx.infomodel.codelist.Codelist=EPM:CL(1.0)\n ") + ); + } + +} \ No newline at end of file