Encoding path segments on reduced custom query 69/96169/1
authorAmichai Hemli <amichai.hemli@intl.att.com>
Mon, 23 Sep 2019 18:45:26 +0000 (21:45 +0300)
committerAmichai Hemli <amichai.hemli@intl.att.com>
Tue, 24 Sep 2019 09:39:45 +0000 (12:39 +0300)
Need to URL-encode the path segments when sending URL in the custom queries to A&AI
Issue-ID: VID-596

Signed-off-by: Amichai Hemli <amichai.hemli@intl.att.com>
Change-Id: Ie551cccfc1a8c627984185324a59c18f13200e91

vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java

index 644309d..7e96c93 100644 (file)
@@ -315,13 +315,13 @@ public class AaiClient implements AaiClientInterface {
             if (cloudRegion != null){
                 return ImmutableMap.of(
                     "start", ImmutableList
-                        .of("/business/customers/customer/" + subscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances"),
+                        .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
                     "query",  "query/vnfs-fromServiceInstance-filterByCloudRegion?nfRole=" + nfRole + "&cloudRegionID=" + cloudRegion + ""
                 );
             }else {
                 return ImmutableMap.of(
                     "start", ImmutableList
-                        .of("/business/customers/customer/" + subscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances"),
+                        .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
                     "query",  "query/vnfs-fromServiceInstance-filter?nfRole=" + nfRole + ""
                 );
             }
@@ -330,14 +330,14 @@ public class AaiClient implements AaiClientInterface {
         if (cloudRegion != null){
             return ImmutableMap.of(
                 "start", ImmutableList
-                    .of("/business/customers/customer/" + subscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances"),
+                    .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
                 "query",  "query/vnfs-fromServiceInstance-filterByCloudRegion?cloudRegionID=" + cloudRegion + ""
             );
         }
 
         return ImmutableMap.of(
             "start", ImmutableList
-                .of("/business/customers/customer/" + subscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances"),
+                .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
             "query", "query/vnfs-fromServiceInstance-filter"
         );
     }
index 8cb3a50..cfebe1a 100644 (file)
@@ -141,6 +141,7 @@ public class AaiClientTest {
     private static String nfRoleAndCloudRegion = "{\"start\":[\"/business/customers/customer/globalCustomerId1-360-as988q/service-subscriptions/service-subscription/TEST1-360/service-instances\"],\"query\":\"query/vnfs-fromServiceInstance-filterByCloudRegion?nfRole=test360&cloudRegionID=cloudRegion-1\"}";
     private static String cloudRegionOnly = "{\"start\":[\"/business/customers/customer/globalCustomerId1-360-as988q/service-subscriptions/service-subscription/TEST1-360/service-instances\"],\"query\":\"query/vnfs-fromServiceInstance-filterByCloudRegion?cloudRegionID=cloudRegion-1\"}";
     private static String withoutNfroleAndCloudRegion = "{\"start\":[\"/business/customers/customer/globalCustomerId1-360-as988q/service-subscriptions/service-subscription/TEST1-360/service-instances\"],\"query\":\"query/vnfs-fromServiceInstance-filter\"}";
+    private static String withoutNfroleAndCloudRegionWithSpace = "{\"start\":[\"/business/customers/customer/globalCustomerId1with%20space%20360-as988q/service-subscriptions/service-subscription/TEST1%20360/service-instances\"],\"query\":\"query/vnfs-fromServiceInstance-filter\"}";
 
     private static String responseJsonNfRole = "/payload_jsons/changeManagement/vnfs-fromServiceInstance-filterNfRole.json";
     private static String responseJsonCloudRegion ="/payload_jsons/changeManagement/vnfs-fromServiceInstance-filterByCloudRegion.json";
@@ -153,7 +154,8 @@ public class AaiClientTest {
             {"globalCustomerId1-360-as988q", "TEST1-360", null, "cloudRegion-1", cloudRegionOnly, responseJsonCloudRegion, "1165906024", 200},
             {"globalCustomerId1-360-as988q", "TEST1-360", "test360", "cloudRegion-1", nfRoleAndCloudRegion,
                 responseJsonCloudRegion, "1165906024", 200},
-            {"globalCustomerId1-360-as988q", "TEST1-360", null, null, withoutNfroleAndCloudRegion, responseJsonNfRole, "908419144", 200},
+            {"globalCustomerId1with space 360-as988q", "TEST1 360", null, null, withoutNfroleAndCloudRegionWithSpace, responseJsonNfRole, "908419144", 200},
+                {"globalCustomerId1-360-as988q", "TEST1-360", null, null, withoutNfroleAndCloudRegion, responseJsonNfRole, "908419144", 200},
         };
     }