Closed loop operation guarantee for ccvpn
[policy/models.git] / models-interactions / model-simulators / src / test / java / org / onap / policy / simulators / SoSimulatorTest.java
index e35e11d..31b7627 100644 (file)
@@ -2,8 +2,10 @@
  * ============LICENSE_START=======================================================
  * simulators
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 Wipro Limited.
+ * Modifications Copyright (C) 2022 CTC, Inc. and others.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.simulators;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.HashMap;
 import java.util.UUID;
+import org.apache.commons.lang3.tuple.Pair;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
 import org.onap.policy.so.SoCloudConfiguration;
 import org.onap.policy.so.SoModelInfo;
 import org.onap.policy.so.SoRelatedInstance;
 import org.onap.policy.so.SoRelatedInstanceListElement;
 import org.onap.policy.so.SoRequest;
+import org.onap.policy.so.SoRequest3gpp;
+import org.onap.policy.so.SoRequestCll;
 import org.onap.policy.so.SoRequestDetails;
 import org.onap.policy.so.SoRequestInfo;
 import org.onap.policy.so.SoRequestParameters;
-import org.onap.policy.so.SoResponse;
 import org.onap.policy.so.util.Serialization;
 
 public class SoSimulatorTest {
@@ -59,7 +65,8 @@ public class SoSimulatorTest {
 
     @AfterClass
     public static void tearDownSimulator() {
-        HttpServletServer.factory.destroy();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+        SoSimulatorJaxRs.setRequirePolling(false);
     }
 
     /**
@@ -134,14 +141,152 @@ public class SoSimulatorTest {
     }
 
     @Test
-    public void testResponse() {
-        final String request = Serialization.gsonPretty.toJson(this.createTestRequest());
-        final Pair<Integer, String> httpDetails = new RestManager().post(
+    public void testPost() {
+        SoSimulatorJaxRs.setRequirePolling(false);
+        String request = Serialization.gsonPretty.toJson(this.createTestRequest());
+        Pair<Integer, String> httpDetails = new RestManager().post(
                         "http://localhost:6667/serviceInstantiation/v7/serviceInstances/12345/vnfs/12345/vfModules/scaleOut",
                         "username",
                         "password", new HashMap<>(), "application/json", request);
         assertNotNull(httpDetails);
-        final SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
+        assertThat(httpDetails.getRight()).contains("\"COMPLETE\"").contains("requestSelfLink");
+
+        /*
+         * Repeat, but set the flag indicating that the request should yield incomplete.
+         */
+        SoSimulatorJaxRs.setRequirePolling(true);
+
+        request = Serialization.gsonPretty.toJson(this.createTestRequest());
+        httpDetails = new RestManager().post(
+                        "http://localhost:6667/serviceInstantiation/v7/serviceInstances/12345/vnfs/12345/vfModules/scaleOut",
+                        "username",
+                        "password", new HashMap<>(), "application/json", request);
+        assertNotNull(httpDetails);
+        assertThat(httpDetails.getRight()).contains("requestSelfLink").doesNotContain("\"COMPLETE\"");
+
+        // now poll for the response
+        String uri = extractUri(httpDetails.getRight());
+        httpDetails = new RestManager().get(
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
+                        "username",
+                        "password", new HashMap<>());
+        assertNotNull(httpDetails);
+        assertThat(httpDetails.getRight()).contains("\"IN_PROGRESS\"").doesNotContain("requestSelfLink");
+
+        // poll again
+        httpDetails = new RestManager().get(
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
+                        "username",
+                        "password", new HashMap<>());
+        assertNotNull(httpDetails);
+        assertThat(httpDetails.getRight()).contains("\"COMPLETE\"").doesNotContain("requestSelfLink");
+    }
+
+    @Test
+    public void testDelete() {
+        SoSimulatorJaxRs.setRequirePolling(false);
+        String request = Serialization.gsonPretty.toJson(this.createTestRequest());
+        Pair<Integer, String> httpDetails = new RestManager().delete(
+                        "http://localhost:6667/serviceInstances/v7/12345/vnfs/12345/vfModules/12345",
+                        "username",
+                        "password", new HashMap<>(), "application/json", request);
+        assertNotNull(httpDetails);
+        assertThat(httpDetails.getRight()).contains("\"COMPLETE\"").contains("requestSelfLink");
+
+        /*
+         * Repeat, but set the flag indicating that the request should yield incomplete.
+         */
+        SoSimulatorJaxRs.setRequirePolling(true);
+
+        request = Serialization.gsonPretty.toJson(this.createTestRequest());
+        httpDetails = new RestManager().delete(
+                        "http://localhost:6667/serviceInstances/v7/12345/vnfs/12345/vfModules/12345",
+                        "username",
+                        "password", new HashMap<>(), "application/json", request);
+        assertNotNull(httpDetails);
+        assertThat(httpDetails.getRight()).contains("requestSelfLink").doesNotContain("\"COMPLETE\"");
+
+        // now poll for the response
+        String uri = extractUri(httpDetails.getRight());
+        httpDetails = new RestManager().get(
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
+                        "username",
+                        "password", new HashMap<>());
+        assertNotNull(httpDetails);
+        assertThat(httpDetails.getRight()).contains("\"IN_PROGRESS\"").doesNotContain("requestSelfLink");
+
+        // poll again
+        httpDetails = new RestManager().get(
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
+                        "username",
+                        "password", new HashMap<>());
+        assertNotNull(httpDetails);
+        assertThat(httpDetails.getRight()).contains("\"COMPLETE\"").doesNotContain("requestSelfLink");
+    }
+
+    @Test
+    public void testModifyNssi() {
+        SoSimulatorJaxRs.setRequirePolling(false);
+        String request = Serialization.gsonPretty.toJson(this.createNssiRequest());
+        Pair<Integer, String> httpDetails = new RestManager().put(
+                "http://localhost:6667/3gppservices/v7/modify",
+                "username",
+                "password", new HashMap<>(), "application/json", request);
+        assertNotNull(httpDetails);
+        assertEquals(200, httpDetails.getLeft().intValue());
+        assertThat(httpDetails.getRight()).contains("jobId").contains("status");
+    }
+
+    private SoRequest3gpp createNssiRequest() {
+        SoRequest3gpp request = new SoRequest3gpp();
+
+        request.setName("URLLC_core1");
+        request.setServiceInstanceId("ff67a209-dc69-4a1a-b89a-c1f55c2a8842");
+        request.setGlobalSubscriberId("5G Customer");
+        request.setSubscriptionServiceType("5G");
+        request.setNetworkType("an");
+        request.setAdditionalProperties(new HashMap<String, Object>());
+
+        return request;
+    }
+
+    @Test
+    public void testModifyCll() {
+        SoSimulatorJaxRs.setRequirePolling(false);
+        String request = Serialization.gsonPretty.toJson(this.createCllRequest());
+        Pair<Integer, String> httpDetails = new RestManager().put(
+                "http://localhost:6667/infra/serviceIntent/v1/modify",
+                "username",
+                "password", new HashMap<>(), "application/json", request);
+        assertNotNull(httpDetails);
+        assertEquals(200, httpDetails.getLeft().intValue());
+        assertThat(httpDetails.getRight()).contains("jobId").contains("status");
+    }
+
+    private SoRequestCll createCllRequest() {
+        SoRequestCll request = new SoRequestCll();
+
+        request.setName("cloud-leased-line-101");
+        request.setServiceInstanceId("cll-instance-01");
+        request.setGlobalSubscriberId("IBNCustomer");
+        request.setSubscriptionServiceType("ibn");
+        request.setServiceType("CLL");
+        request.setAdditionalProperties(new HashMap<String, Object>());
+
+        return request;
+    }
+
+    private String extractUri(String response) {
+        final String prefix = "\"requestId\": \"";
+
+        int start = response.indexOf(prefix);
+        assertTrue(start >= 0);
+
+        start += prefix.length();
+
+        int end = response.indexOf('"', start);
+        assertTrue(end >= 0);
+
+        return response.substring(start, end);
     }
 }