Add missing tests 39/35039/2
authorDenes Nemeth <denes.nemeth@nokia.com>
Sat, 10 Mar 2018 14:59:42 +0000 (15:59 +0100)
committerDenes Nemeth <denes.nemeth@nokia.com>
Sat, 10 Mar 2018 15:10:01 +0000 (16:10 +0100)
Change-Id: I6205fc147d0702c1f4242285f4414645a4e8a3de
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728

14 files changed:
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/MsbApiProvider.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/AdditionalParameters.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.cbam.yaml

index ec98e96..64a418d 100644 (file)
@@ -60,9 +60,7 @@ public class MsbApiProvider extends IpMappingProvider {
     public String getMicroServiceUrl(String name, String version) {
         MicroServiceFullInfo microServiceFullInfo = getMicroServiceInfo(name, version);
         String ipAnPort = getNodeIpAnPort(microServiceFullInfo);
-        //FIXME the enable_ssl field should be used, but it is not available in SDK
-        //depends on https://jira.onap.org/browse/MSB-151
-        String protocol = (ipAnPort.endsWith(":8443") || ipAnPort.endsWith(":443")) ? "https://" : "http://";
+        String protocol = microServiceFullInfo.isEnable_ssl() ? "https://" : "http://";
         //the field name in A&AI is misleading the URL is relative path postfixed to http(s)://ip:port
         return protocol + ipAnPort + microServiceFullInfo.getUrl();
     }
index 3fda619..a9e1165 100644 (file)
@@ -140,8 +140,7 @@ public class SelfRegistrationManager {
         microServiceInfo.setVisualRange(INTERNAL_SERVICE);
         microServiceInfo.setServiceName(SERVICE_NAME);
         microServiceInfo.setVersion(DRIVER_VERSION);
-        //FIXME set enable_ssl to false after the field has been added to MSB SDK https://jira.onap.org/browse/MSB-151
-        //currently defaults to false, which is good
+        microServiceInfo.setEnable_ssl(true);
         Node node = new Node();
         microServiceInfo.setNodes(new HashSet<>());
         microServiceInfo.getNodes().add(node);
index e628458..8d65831 100644 (file)
@@ -81,7 +81,7 @@ public class OnapVnfdBuilder {
                         body.append(buildEcp(node.getKey(), node.getValue(), nodeTemplates));
                         break;
                     default:
-                        //
+                        logger.warn("The {} type is not converted", type);
                 }
             }
             return buildHeader(topologyTemplate) + body.toString();
index 74ac6ea..7f63a1a 100644 (file)
@@ -28,6 +28,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.servlet.http.HttpServletResponse;
 
+import java.util.Optional;
+
+import static java.util.Optional.empty;
 import static org.apache.http.HttpStatus.SC_CREATED;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
 import static org.slf4j.LoggerFactory.getLogger;
@@ -146,6 +149,6 @@ public class LcmApi {
     @ResponseBody
     public JobInfo healVnf(@RequestBody VnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
         logger.info("REST: Heal VNF");
-        return lifecycleManager.healVnf(vnfmId, vnfInstanceId, request, httpResponse);
+        return lifecycleManager.healVnf(vnfmId, vnfInstanceId, request, empty(), httpResponse);
     }
 }
index 70cf11c..dfb7ada 100644 (file)
@@ -35,7 +35,7 @@ public class AdditionalParameters {
     private List<ExtVirtualLinkData> extVirtualLinks = new ArrayList<>();
     private Object additionalParams;
 
-    AdditionalParameters() {
+    public AdditionalParameters() {
         //only used through reflection (gson)
     }
 
index b78c13a..79e9487 100644 (file)
@@ -131,12 +131,10 @@ public class LifecycleManager {
      * @param csarId          the identifier of the VNF package
      * @param vnfName         the name of the VNF
      * @param description     the description of the VNF
-     * @param addtionalParams additional parameters for the VNF instantiation request
      * @return the VNF creation result
      */
-    public VnfCreationResult create(String vnfmId, String csarId, String vnfName, String description, AdditionalParameters addtionalParams) {
-        logOperationInput("not yet specified", "creation", addtionalParams);
-        validateVimType(addtionalParams.getVimType());
+    public VnfCreationResult create(String vnfmId, String csarId, String vnfName, String description) {
+        logOperationInput("not yet specified", "creation", csarId);
         try {
             CatalogAdapterVnfpackage cbamPackage = catalogManager.preparePackageInCbam(vnfmId, csarId);
             CreateVnfRequest vnfCreateRequest = new CreateVnfRequest();
@@ -206,7 +204,8 @@ public class LifecycleManager {
      */
     public VnfInstantiateResponse createAndInstantiate(String vnfmId, VnfInstantiateRequest request, HttpServletResponse httpResponse) {
         AdditionalParameters additionalParameters = convertInstantiationAdditionalParams(request.getVnfPackageId(), request.getAdditionalParam());
-        VnfCreationResult creationResult = create(vnfmId, request.getVnfDescriptorId(), request.getVnfInstanceName(), request.getVnfInstanceDescription(), additionalParameters);
+        validateVimType(additionalParameters.getVimType());
+        VnfCreationResult creationResult = create(vnfmId, request.getVnfDescriptorId(), request.getVnfInstanceName(), request.getVnfInstanceDescription());
         return instantiate(vnfmId, request, httpResponse, additionalParameters, creationResult.vnfInfo.getId(), creationResult.vnfdId);
     }
 
@@ -557,9 +556,10 @@ public class LifecycleManager {
      * @param vnfId        the identifier of the VNF
      * @param request      the heal request
      * @param httpResponse the HTTP response
+     * @param vnfcId the identifer of thr VNFC to be healed
      * @return the job for tracking the heal
      */
-    public JobInfo healVnf(String vnfmId, String vnfId, VnfHealRequest request, HttpServletResponse httpResponse) {
+    public JobInfo healVnf(String vnfmId, String vnfId, VnfHealRequest request, Optional<String> vnfcId, HttpServletResponse httpResponse) {
         logOperationInput(vnfId, "heal", request);
         return scheduleExecution(vnfId, httpResponse, "heal", job -> {
             HealVnfRequest cbamHealRequest = new HealVnfRequest();
@@ -567,6 +567,7 @@ public class LifecycleManager {
             additionalParams.put("vmName", request.getAffectedvm().getVmname());
             additionalParams.put("action", request.getAction());
             additionalParams.put("jobId", job.getJobId());
+            additionalParams.put("vnfcId", vnfcId.orElse("unknown"));
             cbamHealRequest.setAdditionalParams(additionalParams);
             com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION);
             String vimId = getVimIdFromInstantiationRequest(vnfmId, vnf);
@@ -621,15 +622,19 @@ public class LifecycleManager {
     @FunctionalInterface
     private interface AsynchronousExecution {
         void execute(JobInfo job) throws ApiException;
-    }
-
-    private static class VnfCreationResult {
-        private com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo;
-        private String vnfdId;
 
+    }
+    public static class VnfCreationResult {
+        private final com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo;
+        private final String vnfdId;
         VnfCreationResult(com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo, String vnfdId) {
             this.vnfInfo = vnfInfo;
             this.vnfdId = vnfdId;
         }
+
+        public com.nokia.cbam.lcm.v32.model.VnfInfo getVnfInfo() {
+            return vnfInfo;
+        }
+
     }
 }
index 47e441f..249e16c 100644 (file)
@@ -21,6 +21,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.*;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.event.ContextClosedEvent;
@@ -137,6 +138,16 @@ public class TestNokiaSvnfmApplication {
         verify(logger).error("Self de-registration failed", expectedException);
     }
 
+    /**
+     * Spring will instantiate using reflection
+     */
+    @Test
+    public void testUseStaticWay() throws Exception {
+        //verify
+        //the constructor is public even if has no private fields
+        new NokiaSvnfmApplication();
+    }
+
     /**
      * static entry point calling an other static entry point can not be tested
      */
index aefe63a..eb3674c 100644 (file)
@@ -121,16 +121,17 @@ public class TestMsbApiProvider extends TestBase {
 
 
     /**
-     * use HTTPS for known ports (443) should be removed if https://jira.onap.org/browse/MSB-151 is solved
+     * use HTTPS for known ports
      */
     @Test
-    public void testMsb151IssueHack() throws Exception {
+    public void testMsbServiceOverssl() throws Exception {
         NodeInfo nonDocker = new NodeInfo();
         nonDocker.setIp("173.1.2.3");
-        nonDocker.setPort("443");
+        nonDocker.setPort("123");
         microServiceInfo.setServiceName("serviceName");
         microServiceInfo.setVersion("v1");
         microServiceInfo.setUrl("/lead/nslcm/v1");
+        microServiceInfo.setEnable_ssl(true);
         when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("173.1.2.3->1.2.3.4");
         nodes.add(nonDocker);
         msbApiProvider = new MsbApiProvider(environment) {
@@ -142,32 +143,7 @@ public class TestMsbApiProvider extends TestBase {
         when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
         msbApiProvider.afterPropertiesSet();
         //when
-        assertEquals("https://1.2.3.4:443/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1"));
-    }
-
-    /**
-     * use HTTPS for known ports (443) should be removed if https://jira.onap.org/browse/MSB-151 is solved
-     */
-    @Test
-    public void testMsb151IssueHack2() throws Exception {
-        NodeInfo nonDocker = new NodeInfo();
-        nonDocker.setIp("173.1.2.3");
-        nonDocker.setPort("8443");
-        microServiceInfo.setServiceName("serviceName");
-        microServiceInfo.setVersion("v1");
-        microServiceInfo.setUrl("/lead/nslcm/v1");
-        when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("173.1.2.3->1.2.3.4");
-        nodes.add(nonDocker);
-        msbApiProvider = new MsbApiProvider(environment) {
-            @Override
-            public MSBServiceClient getMsbClient() {
-                return msbClient;
-            }
-        };
-        when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
-        msbApiProvider.afterPropertiesSet();
-        //when
-        assertEquals("https://1.2.3.4:8443/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1"));
+        assertEquals("https://1.2.3.4:123/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1"));
     }
 
     /**
index 5001eed..2cd0aa1 100644 (file)
@@ -63,14 +63,11 @@ public class TestOnapVnfdBuilder extends TestBase {
         verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp");
         verify(logger).warn("The {} ecp does not have an requirements section", "ecpWithIcpWithOutRequirements");
         verify(logger).warn("The {} internal connection point of the {} ecp does not have a VDU", "icpWithoutVdu", "myEcpWithoutIcpWithoutVdu");
-
         verify(logger).warn("The {} internal connection point of the {} ecp does not have a requirements section", "icpWithOutRequiements", "myEcpWithoutIcpWithoutIcpReq");
-
-
         verify(logger).warn("The {} internal connection point does not have a VDU", "icpWithOutVdu");
         verify(logger).warn("The {} internal connection point does not have a requirements section", "icpWithOutRequiements");
         verify(logger).warn("The {} internal connection point does not have a VL", "icpWithOutVl");
-
+        verify(logger).warn("The {} type is not converted", "tosca.nodes.nfv.Unknown");
     }
 
     /**
index 4d10fd5..6b04d69 100644 (file)
@@ -28,6 +28,7 @@ import org.onap.vnfmdriver.model.VnfInstantiateRequest;
 import org.onap.vnfmdriver.model.VnfScaleRequest;
 import org.onap.vnfmdriver.model.VnfTerminateRequest;
 
+import static java.util.Optional.empty;
 import static org.apache.http.HttpStatus.SC_CREATED;
 import static org.mockito.Mockito.verify;
 import static org.springframework.test.util.ReflectionTestUtils.setField;
@@ -70,7 +71,7 @@ public class TestLcmApi extends TestBase {
         //when
         lcmApi.healVnf(req, VNFM_ID, VNF_ID, httpResponse);
         //verify
-        verify(lifecycleManager).healVnf(VNFM_ID, VNF_ID, req, httpResponse);
+        verify(lifecycleManager).healVnf(VNFM_ID, VNF_ID, req, empty(), httpResponse);
         verify(logger).info("REST: Heal VNF");
     }
 
index f716cad..7a525b3 100644 (file)
@@ -21,6 +21,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
 import org.springframework.context.annotation.ConditionContext;
 import org.springframework.core.env.Environment;
 
@@ -63,4 +64,12 @@ public class TestConditions {
         TestCase.assertTrue(new Conditions.UseForDirect().matches(conditionContext, null));
     }
 
+    /**
+     * use class in a static way
+     */
+    @Test
+    public void useStaticway(){
+        TestUtil.coveragePrivateConstructorForClassesWithStaticMethodsOnly(Conditions.class);
+    }
+
 }
index 44ba0e5..4b35f2f 100644 (file)
@@ -45,6 +45,10 @@ import java.security.KeyStoreException;
 import java.util.ArrayList;
 import java.util.Base64;
 import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
 import static junit.framework.TestCase.*;
 import static org.mockito.Matchers.eq;
@@ -54,10 +58,10 @@ import static org.springframework.test.util.ReflectionTestUtils.setField;
 
 class HttpTestServer {
     Server _server;
-    List<String> requests = new ArrayList<>();
-    List<Integer> codes = new ArrayList<>();
-    List<String> respones = new ArrayList<>();
-
+    volatile List<String> requests = new ArrayList<>();
+    volatile List<Integer> codes = new ArrayList<>();
+    volatile List<String> respones = new ArrayList<>();
+    ExecutorService executorService = Executors.newCachedThreadPool();
     public void start() throws Exception {
         configureServer();
         startServer();
@@ -67,6 +71,18 @@ class HttpTestServer {
         requests.clear();
         codes.clear();
         _server.start();
+        Future<?> serverStarted = executorService.submit(() -> {
+            while(true){
+                try {
+                    Thread.sleep(10);
+                    if(_server.isStarted()){
+                        return;
+                    }
+                } catch (InterruptedException e) {
+                }
+            }
+        });
+        serverStarted.get(30, TimeUnit.SECONDS);
     }
 
     protected void configureServer() throws Exception {
@@ -119,6 +135,8 @@ public class TestCbamTokenProvider extends TestBase {
         testServer.start();
         URI uri = testServer._server.getURI();
         setField(cbamTokenProvider, "cbamKeyCloakBaseUrl", uri.toString());
+
+
     }
 
     private void addGoodTokenResponse() {
index c601f7e..c6e76ef 100644 (file)
@@ -49,6 +49,7 @@ import java.util.*;
 
 import static java.lang.Boolean.parseBoolean;
 import static java.nio.file.Files.readAllBytes;
+import static java.util.Optional.empty;
 import static junit.framework.TestCase.*;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.*;
@@ -1317,7 +1318,7 @@ public class TestLifecycleManager extends TestBase {
         String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
         when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams));
         //when
-        JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, restResponse);
+        JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(), restResponse);
         //verify
         waitForJobToFinishInJobManager(finished);
         assertEquals(1, actualHealRequest.getAllValues().size());
@@ -1366,7 +1367,7 @@ public class TestLifecycleManager extends TestBase {
             }
         });
         //when
-        JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, restResponse);
+        JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(),  restResponse);
         //verify
         waitForJobToFinishInJobManager(finished);
         assertEquals(100, expectedExceptions.size());
@@ -1389,7 +1390,7 @@ public class TestLifecycleManager extends TestBase {
         healRequest.setAffectedvm(affectedVm);
         when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
         //when
-        JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, restResponse);
+        JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest,  empty(), restResponse);
         //verify
         waitForJobToFinishInJobManager(finished);
         verify(logger).error("Unable to heal VNF with myVnfId identifier", expectedException);
index 4f8415e..985ab27 100644 (file)
@@ -20,6 +20,8 @@ topology_template:
         - virtual_storage: myStorage2
         - unhandled_type: unknown
 
+    unknownType:
+      type: tosca.nodes.nfv.Unknown
 
     myCompute:
       type: tosca.nodes.nfv.VirtualCompute