Merge "[SO] create generic pnf healthcheck workflow"
authorByung-Woo Jun <byung-woo.jun@est.tech>
Fri, 31 Jul 2020 01:13:18 +0000 (01:13 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 31 Jul 2020 01:13:18 +0000 (01:13 +0000)
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java

index c806e9f..fec512a 100644 (file)
@@ -163,12 +163,14 @@ public abstract class AbstractRestHandler {
         try {
             URL aUrl = new URL(url);
             String aPath = aUrl.getPath();
-            if (aPath.indexOf("/v") == -1) {
-                version = aPath.substring(aPath.indexOf("/V"), aPath.indexOf("/V") + 4);
-            } else {
-                version = aPath.substring(aPath.indexOf("/v"), aPath.indexOf("/v") + 4);
-            }
-            String selfLinkPath = Constants.ORCHESTRATION_REQUESTS_PATH.concat(version).concat(requestId);
+            int indexOfVersion = Math.max(aPath.indexOf("/V"), aPath.indexOf("/v"));
+            version = aPath.substring(indexOfVersion, indexOfVersion + 4);
+
+            String pathWithSOAction = aPath.substring(0, indexOfVersion);
+            String pathWithoutSOAction = pathWithSOAction.substring(0, pathWithSOAction.lastIndexOf("/"));
+
+            String selfLinkPath =
+                    pathWithoutSOAction.concat(Constants.ORCHESTRATION_REQUESTS_PATH).concat(version).concat(requestId);
             selfLinkUrl = Optional.of(new URL(aUrl.getProtocol(), aUrl.getHost(), aUrl.getPort(), selfLinkPath));
         } catch (Exception e) {
             selfLinkUrl = Optional.empty(); // ignore
index 5da16f4..0ca9888 100644 (file)
@@ -70,6 +70,10 @@ public abstract class BaseTest {
         return "http://localhost:" + port + uri;
     }
 
+    protected String createURLWithPort(String uri, String orchestrationPath) {
+        return "http://localhost:" + port + orchestrationPath + uri;
+    }
+
     protected String createURLWithPort(String uri, int iPort) {
         return "http://localhost:" + iPort + uri;
     }
index 33ed5fa..7b2e502 100644 (file)
@@ -71,6 +71,7 @@ public class InstanceManagementTest extends BaseTest {
     private String wiremockPort;
 
     private final String instanceManagementUri = "/onap/so/infra/instanceManagement/";
+    private final String orchestration_path = "/onap/so/infra";
 
     private String uri;
     private URL selfLink;
@@ -92,7 +93,7 @@ public class InstanceManagementTest extends BaseTest {
         headers.set(ONAP_PARTNER_NAME, "VID");
         headers.set(REQUESTOR_ID, "xxxxxx");
         try { // generate one-time port number to avoid RANDOM port number later.
-            initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH));
+            initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH, orchestration_path));
             initialPort = initialUrl.getPort();
         } catch (MalformedURLException e) {
             e.printStackTrace();
index b3151db..33d86a2 100644 (file)
@@ -97,6 +97,8 @@ public class ServiceInstancesTest extends BaseTest {
 
     private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/";
     private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/";
+    private final String orchestration_path = "/onap/so/infra";
+
     private String uri;
     private URL selfLink;
     private URL initialUrl;
@@ -115,7 +117,7 @@ public class ServiceInstancesTest extends BaseTest {
         headers.set(ONAP_PARTNER_NAME, "VID");
         headers.set(REQUESTOR_ID, "xxxxxx");
         try { // generate one-time port number to avoid RANDOM port number later.
-            initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH));
+            initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH, orchestration_path));
             initialPort = initialUrl.getPort();
         } catch (MalformedURLException e) {
             e.printStackTrace();
index d39192c..6c643c7 100644 (file)
@@ -61,4 +61,15 @@ public class AbstractRestHandlerTest {
                 restHandler.createResponse("instanceId", "requestId", mockRequestContext);
         assertThat(actualResponse, sameBeanAs(expectedResponse));
     }
+
+    @Test
+    public void test_buildSelfLinkUrl() throws MalformedURLException {
+        String initialLink = "http://some.domain.com:30277/onap/so/infra/serviceInstantiation/v7/serviceInstances";
+        String requestId = "4d0437c3-ee48-4361-a4f7-e1613c82493a";
+        Optional<URL> expectedLink = Optional.of(new URL(
+                "http://some.domain.com:30277/onap/so/infra/orchestrationRequests/v7/4d0437c3-ee48-4361-a4f7-e1613c82493a"));
+        Optional<URL> resultURL = restHandler.buildSelfLinkUrl(initialLink, requestId);
+
+        assertThat(resultURL, sameBeanAs(expectedLink));
+    }
 }