Closed loop operation guarantee for ccvpn
[policy/models.git] / models-interactions / model-simulators / src / test / java / org / onap / policy / simulators / SoSimulatorTest.java
index c5f9973..31b7627 100644 (file)
@@ -3,7 +3,9 @@
  * simulators
  * ================================================================================
  * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * 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.assertNull;
+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.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 {
@@ -62,7 +66,7 @@ public class SoSimulatorTest {
     @AfterClass
     public static void tearDownSimulator() {
         HttpServletServerFactoryInstance.getServerFactory().destroy();
-        SoSimulatorJaxRs.setYieldIncomplete(false);
+        SoSimulatorJaxRs.setRequirePolling(false);
     }
 
     /**
@@ -138,23 +142,19 @@ public class SoSimulatorTest {
 
     @Test
     public void testPost() {
-        SoSimulatorJaxRs.setYieldIncomplete(false);
+        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);
-        SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNotNull(response.getRequestReferences());
-        assertNotNull(response.getRequestReferences().getRequestId());
-        assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+        assertThat(httpDetails.getRight()).contains("\"COMPLETE\"").contains("requestSelfLink");
 
         /*
          * Repeat, but set the flag indicating that the request should yield incomplete.
          */
-        SoSimulatorJaxRs.setYieldIncomplete(true);
+        SoSimulatorJaxRs.setRequirePolling(true);
 
         request = Serialization.gsonPretty.toJson(this.createTestRequest());
         httpDetails = new RestManager().post(
@@ -162,55 +162,41 @@ public class SoSimulatorTest {
                         "username",
                         "password", new HashMap<>(), "application/json", request);
         assertNotNull(httpDetails);
-        response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNotNull(response.getRequestReferences());
-        assertNotNull(response.getRequestReferences().getRequestId());
-        assertEquals("INCOMPLETE", response.getRequest().getRequestStatus().getRequestState());
+        assertThat(httpDetails.getRight()).contains("requestSelfLink").doesNotContain("\"COMPLETE\"");
 
         // now poll for the response
-        String reqid = response.getRequestReferences().getRequestId();
+        String uri = extractUri(httpDetails.getRight());
         httpDetails = new RestManager().get(
-                        "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
                         "username",
                         "password", new HashMap<>());
         assertNotNull(httpDetails);
-        response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNull(response.getRequest());
+        assertThat(httpDetails.getRight()).contains("\"IN_PROGRESS\"").doesNotContain("requestSelfLink");
 
         // poll again
         httpDetails = new RestManager().get(
-                        "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
                         "username",
                         "password", new HashMap<>());
         assertNotNull(httpDetails);
-        response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNotNull(response.getRequest());
-        assertNotNull(response.getRequest().getRequestStatus());
-        assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+        assertThat(httpDetails.getRight()).contains("\"COMPLETE\"").doesNotContain("requestSelfLink");
     }
 
     @Test
     public void testDelete() {
-        SoSimulatorJaxRs.setYieldIncomplete(false);
+        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);
-        SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNotNull(response.getRequestReferences());
-        assertNotNull(response.getRequestReferences().getRequestId());
-        assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+        assertThat(httpDetails.getRight()).contains("\"COMPLETE\"").contains("requestSelfLink");
 
         /*
          * Repeat, but set the flag indicating that the request should yield incomplete.
          */
-        SoSimulatorJaxRs.setYieldIncomplete(true);
+        SoSimulatorJaxRs.setRequirePolling(true);
 
         request = Serialization.gsonPretty.toJson(this.createTestRequest());
         httpDetails = new RestManager().delete(
@@ -218,33 +204,89 @@ public class SoSimulatorTest {
                         "username",
                         "password", new HashMap<>(), "application/json", request);
         assertNotNull(httpDetails);
-        response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNotNull(response.getRequestReferences());
-        assertNotNull(response.getRequestReferences().getRequestId());
-        assertEquals("INCOMPLETE", response.getRequest().getRequestStatus().getRequestState());
+        assertThat(httpDetails.getRight()).contains("requestSelfLink").doesNotContain("\"COMPLETE\"");
 
         // now poll for the response
-        String reqid = response.getRequestReferences().getRequestId();
+        String uri = extractUri(httpDetails.getRight());
         httpDetails = new RestManager().get(
-                        "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
                         "username",
                         "password", new HashMap<>());
         assertNotNull(httpDetails);
-        response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNull(response.getRequest());
+        assertThat(httpDetails.getRight()).contains("\"IN_PROGRESS\"").doesNotContain("requestSelfLink");
 
         // poll again
         httpDetails = new RestManager().get(
-                        "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+                        "http://localhost:6667/orchestrationRequests/v5/" + uri,
                         "username",
                         "password", new HashMap<>());
         assertNotNull(httpDetails);
-        response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
-        assertNotNull(response);
-        assertNotNull(response.getRequest());
-        assertNotNull(response.getRequest().getRequestStatus());
-        assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+        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);
     }
 }