From c000ec257d115b5fa4855ddfacb81368dcb0016a Mon Sep 17 00:00:00 2001 From: leventecsanyi Date: Mon, 8 Dec 2025 12:39:37 +0100 Subject: [PATCH] Accept single-element FDN in the ProvMnS interface - removed extra validation to accept simple FDNs Issue-ID: CPS-3077 Change-Id: I67d19d45957e4cfa11b9776bdc42f5253b9593aa Signed-off-by: leventecsanyi --- .../org/onap/cps/ncmp/impl/provmns/ParameterMapper.java | 14 +++++++------- .../cps/ncmp/impl/provmns/ParameterMapperSpec.groovy | 17 ++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/provmns/ParameterMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/provmns/ParameterMapper.java index b58fe34852..1ce556c936 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/provmns/ParameterMapper.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/provmns/ParameterMapper.java @@ -41,23 +41,23 @@ public class ParameterMapper { public RequestPathParameters extractRequestParameters(final HttpServletRequest httpServletRequest) { final String uriPath = (String) httpServletRequest.getAttribute( "org.springframework.web.servlet.HandlerMapping.pathWithinHandlerMapping"); - final String[] pathVariables = uriPath.split(PROVMNS_BASE_PATH); final int lastSlashIndex = pathVariables[1].lastIndexOf('/'); + final RequestPathParameters requestPathParameters = new RequestPathParameters(); + final String classNameAndId; if (lastSlashIndex < 0) { - throw new ProvMnSException("not a valid path", String.format(INVALID_PATH_DETAILS_FORMAT, uriPath)); + requestPathParameters.setUriLdnFirstPart(""); + classNameAndId = pathVariables[1]; + } else { + requestPathParameters.setUriLdnFirstPart("/" + pathVariables[1].substring(0, lastSlashIndex)); + classNameAndId = pathVariables[1].substring(lastSlashIndex + 1); } - final RequestPathParameters requestPathParameters = new RequestPathParameters(); - requestPathParameters.setUriLdnFirstPart("/" + pathVariables[1].substring(0, lastSlashIndex)); - final String classNameAndId = pathVariables[1].substring(lastSlashIndex + 1); - final String[] splitClassNameId = classNameAndId.split("=", 2); if (splitClassNameId.length != 2) { throw new ProvMnSException("not a valid path", String.format(INVALID_PATH_DETAILS_FORMAT, uriPath)); } requestPathParameters.setClassName(splitClassNameId[0]); requestPathParameters.setId(splitClassNameId[1]); - return requestPathParameters; } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/provmns/ParameterMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/provmns/ParameterMapperSpec.groovy index 9acd4bc802..3f9faa6d67 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/provmns/ParameterMapperSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/provmns/ParameterMapperSpec.groovy @@ -33,19 +33,20 @@ class ParameterMapperSpec extends Specification { def 'Extract request parameters with url first part is a FDN with #scenario.'() { given: 'a http request with all the required parts' - mockHttpServletRequest.getAttribute(uriPathAttributeName) >> (String) "ProvMnS/v1/${fdnPrefix}/myClass=myId" + mockHttpServletRequest.getAttribute(uriPathAttributeName) >> path when: 'the request parameters are extracted' def result = objectUnderTest.extractRequestParameters(mockHttpServletRequest) - then: 'the Uri LDN first part is the fdnPrefix preceded with an extra "/"' - assert result.uriLdnFirstPart == '/' + fdnPrefix + then: 'the Uri LDN first part is as expected' + assert result.uriLdnFirstPart == expectedUriLdnFirstPart and: 'the class name and id are mapped correctly' assert result.className == 'myClass' assert result.id == 'myId' where: 'The following FDN prefixes are used' - scenario | fdnPrefix - '1 segment' | 'somePrefix' - 'multiple segments' | 'some/prefix' - 'empty segment' | '' + scenario | path || expectedUriLdnFirstPart + '1 segment' | 'ProvMnS/v1/segment1/myClass=myId' || '/segment1' + '2 segments' | 'ProvMnS/v1/segment1/segment2/myClass=myId' || '/segment1/segment2' + 'multiple segments' | 'ProvMnS/v1/segment1/segment2/segment3/segment4/myClass=myId' || '/segment1/segment2/segment3/segment4' + 'no slash' | 'ProvMnS/v1/myClass=myId' || '' } def 'Attempt to extract request parameters with #scenario.'() { @@ -60,8 +61,6 @@ class ParameterMapperSpec extends Specification { assert thrown.details.contains(path) where: 'the following paths are used' scenario | path - 'No / in URI first part' | 'ProvMnS/v1/myClass=myId' 'No = After (last) class name' | 'ProvMnS/v1/someOtherClass=someId/myClass' } - } -- 2.16.6