Add missing tests 85/48485/1
authorDenes Nemeth <denes.nemeth@nokia.com>
Tue, 22 May 2018 12:29:51 +0000 (14:29 +0200)
committerDenes Nemeth <denes.nemeth@nokia.com>
Tue, 22 May 2018 12:29:51 +0000 (14:29 +0200)
Change-Id: I980aec0ec492a4cd77b12e7475c70965d5c9877e
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728

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/onap/direct/notification/GenericVnfManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManagerForVfc.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestSelfRegistrationManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestConstants.java [new file with mode: 0644]

index 17060d6..123f263 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
 import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
@@ -110,6 +111,7 @@ public class SelfRegistrationManager {
      *
      * @param vnfmId the identifier of the VNFM
      */
+    @VisibleForTesting
     public void assureSubscription(String vnfmId) {
         if (!vnfmIdToSubscriptionId.containsKey(vnfmId)) {
             subscribeToLcn(vnfmId);
index d0df8a8..164d3a2 100644 (file)
@@ -101,6 +101,9 @@ public class GenericVnfManager extends AbstractManager {
         if (nsId.isPresent()) {
             addSingletonRelation(vnf.getRelationshipList(), linkToNs(nsId.get()));
         }
+        else{
+            logger.warn("Not linking VNF with {} identifier to any NS", vnfId);
+        }
         aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf).blockingFirst();
     }
 
index d237885..1bda9a3 100644 (file)
@@ -17,7 +17,6 @@
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
 
 
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.GrantlessGrantManager;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcExternalSystemInfoProvider;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcGrantManager;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManagerForVfc;
index 88c1e00..4829d29 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Optional;
 import java.util.Set;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.OperationMustBeAborted;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
index d1e2dea..b082dbd 100644 (file)
@@ -234,6 +234,7 @@ public class TestSelfRegistrationManager extends TestBase {
             return buildObservable(subscription);
         });
         selfRegistrationManager.assureSubscription(VNFM_ID);
+        selfRegistrationManager.assureSubscription(VNFM_ID);
         when(jobManager.hasOngoingJobs()).thenReturn(false);
         when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
         VoidObservable MSB_DELETE = new VoidObservable();
index 912a220..fd5f112 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
 
 import java.util.ArrayList;
+import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -24,6 +25,7 @@ import org.onap.aai.api.ExternalSystemApi;
 import org.onap.aai.model.CloudRegion;
 import org.onap.aai.model.EsrSystemInfo;
 import org.onap.aai.model.EsrVnfm;
+import org.onap.aai.model.EsrVnfmList;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
 import org.onap.vnfmdriver.model.VimInfo;
 import org.onap.vnfmdriver.model.VnfmInfo;
@@ -195,4 +197,21 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
             assertEquals(expectedException, e.getCause());
         }
     }
+
+    /**
+     * the list of VNFMs is retrieved from AAI
+     */
+    @Test
+    public void testQueryAAIExternaSystemProvider() throws Exception{
+        EsrVnfmList e = new EsrVnfmList();
+        EsrVnfm esrVnfmItem = new EsrVnfm();
+        esrVnfmItem.setVnfmId(VNFM_ID);
+        e.addEsrVnfmItem(esrVnfmItem);
+        when(externalSystemApi.getExternalSystemEsrVnfmList()).thenReturn(buildObservable(e));
+        //when
+        Set<String> vnfms = aaiExternalSystemInfoProvider.getVnfms();
+        //verify
+        assertEquals(1, vnfms.size());
+        assertEquals(VNFM_ID, vnfms.iterator().next());
+    }
 }
\ No newline at end of file
index 5ade389..b4783b4 100644 (file)
@@ -17,10 +17,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
 
 import com.nokia.cbam.lcm.v32.model.VnfInfo;
 import io.reactivex.Observable;
-import java.util.HashSet;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicLong;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,6 +36,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
 
 import static java.lang.Boolean.TRUE;
+import static java.util.Optional.empty;
 import static java.util.Optional.of;
 
 import static junit.framework.TestCase.assertEquals;
@@ -140,8 +138,10 @@ public class TestGenericVnfManager extends TestBase {
         when(cbamRestApiProviderForSo.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
         when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         vnfInfo.setName("vnfName");
+        vnfInAaai.setRelationshipList(new ArrayList<>());
+        vnfInAaai.getRelationshipList().add(new Relationship());
         //when
-        genericVnfManager.createOrUpdate(VNF_ID, true, VNFM_ID, of("nsId"));
+        genericVnfManager.createOrUpdate(VNF_ID, true, VNFM_ID, empty());
         //verify
         GenericVnf vnfSentToAai = payload.getValue();
         assertEquals(VNF_ID, vnfSentToAai.getVnfId());
@@ -152,6 +152,7 @@ public class TestGenericVnfManager extends TestBase {
         assertEquals("vnfName", vnfSentToAai.getVnfName());
         verify(systemFunctions, never()).sleep(anyLong());
         VOID_OBSERVABLE.assertCalled();
+        assertEquals(1, vnfInAaai.getRelationshipList().size());
         verify(networkApi, times(1)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
     }
 
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestConstants.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestConstants.java
new file mode 100644 (file)
index 0000000..58afb9b
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
+
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
+
+public class TestConstants {
+
+    @Test
+    public void useInStaticWay(){
+        TestUtil.coveragePrivateConstructorForClassesWithStaticMethodsOnly(Constants.class);
+    }
+}
\ No newline at end of file