summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-14 09:51:50 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-14 14:53:54 +0100
commit876a4acf6f2e8264bb82e960e9aa886799c4bdb1 (patch)
treee929d22a832b73a2345b8c8f7f8c4a06721e4731 /nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm
parent626ebae46807adeab6d0b9d5568515f457c7ece3 (diff)
Fix some security vulnerabilities
Change-Id: Ib1c08c4f73df8cfe42b2857ee674f102ec09c253 Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm')
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java27
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestCbamRestApiProvider.java235
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java11
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java1
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcExternalSystemInfoProvider.java12
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java22
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java12
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java15
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcRestApiProvider.java41
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java14
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java2
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java91
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java35
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java65
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java257
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java327
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java272
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java48
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java276
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java22
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java28
23 files changed, 1041 insertions, 778 deletions
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java
index 4ed4bf27..f0b24762 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java
@@ -17,10 +17,14 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestCbamRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestGenericExternalSystemInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestIpMappingProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestMsbApiProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestAAIExternalSystemInfoProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestAAIRestApiProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestGrantlessGrantManager;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestSdcPackageProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.*;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.*;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestCbamVnfPackageBuilder;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestCbamVnfdBuilder;
@@ -37,14 +41,27 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestProcessed
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedAffectedConnectionPoints;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedAffectedCp;
+//import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestCbamRestApiProvider;
+
@RunWith(Suite.class)
@Suite.SuiteClasses({
-
- TestCbamRestApiProvider.class,
TestGenericExternalSystemInfoProvider.class,
TestIpMappingProvider.class,
TestMsbApiProvider.class,
+ TestAAINotificationProcessor.class,
+ TestAbstractManager.class,
+ TestGenericVnfManager.class,
+ TestL3NetworkManager.class,
+ TestLInterfaceManager.class,
+ TestVnfcManager.class,
+ TestVserverManager.class,
+
+ TestAAIExternalSystemInfoProvider.class,
+ TestAAIRestApiProvider.class,
+ TestGrantlessGrantManager.class,
+ TestSdcPackageProvider.class,
+
TestVfcExternalSystemInfoProvider.class,
TestVfcGrantManager.class,
TestVfcPackageProvider.class,
@@ -79,6 +96,8 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedA
TestAdditionalParams.class,
TestCbamCatalogManager.class,
+ TestCbamRestApiProvider.class,
+ TestCbamSecurityProvider.class,
TestCbamTokenProvider.class,
TestDriverProperties.class,
TestJobManager.class,
@@ -101,5 +120,3 @@ public class FullUnitTestSuite {
-
-
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java
index 249e16c9..92e19a3c 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java
@@ -16,13 +16,12 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia;
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
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.slf4j.Logger;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.test.util.ReflectionTestUtils;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestCbamRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestCbamRestApiProvider.java
deleted file mode 100644
index 0d036a63..00000000
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestCbamRestApiProvider.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * 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.onap.core;
-
-import com.nokia.cbam.catalog.v1.api.DefaultApi;
-import com.nokia.cbam.lcm.v32.ApiClient;
-import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
-import com.nokia.cbam.lcm.v32.api.VnfsApi;
-import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.NodeInfo;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamTokenProvider;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import org.onap.vnfmdriver.model.VnfmInfo;
-import org.springframework.core.env.Environment;
-
-import java.util.Base64;
-import java.util.HashSet;
-import java.util.Set;
-
-import static junit.framework.TestCase.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.springframework.test.util.ReflectionTestUtils.setField;
-
-public class TestCbamRestApiProvider extends TestBase {
- @Mock
- private Environment environment;
- @Mock
- private CbamTokenProvider cbamTokenProvider;
- private MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
- private Set<NodeInfo> nodes = new HashSet<>();
-
- private CbamRestApiProvider cbamRestApiProvider;
-
- @Before
- public void init() {
- microServiceInfo.setNodes(nodes);
- CbamRestApiProvider real = new CbamRestApiProvider(driverProperties, cbamTokenProvider, vnfmInfoProvider);
- setField(real, "trustedCertificates", "mytrustedCertificates");
- setField(real, "skipCertificateVerification", true);
- cbamRestApiProvider = spy(real);
- when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("");
- when(environment.getProperty(GenericExternalSystemInfoProvider.VNFM_INFO_CACHE_EVICTION_IN_MS, Long.class, Long.valueOf(10 * 60 * 1000))).thenReturn(10 * 60 * 1000L);
- }
-
- /**
- * test CBAM LCM API retrieval without SSL verification
- */
- @Test
- public void testCbamLcmApi() throws Exception {
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- expectedVnfmInfo.setUrl("https://cbamUrl:123/d");
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- //when
- VnfsApi cbamLcmApi = cbamRestApiProvider.getCbamLcmApi(VNFM_ID);
- //verify
- ApiClient apiClient = cbamLcmApi.getApiClient();
- assertEquals("https://cbamUrl:123/d", apiClient.getBasePath());
- assertNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.lcm.v32.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamLcmApi.getApiClient().getAuthentications().size());
- assertTrue(!cbamLcmApi.getApiClient().isVerifyingSsl());
- }
-
- /**
- * test CBAM LCM API retrieval with SSL verification
- */
- @Test
- public void testCbamLcmApiWithSslVerfy() throws Exception {
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- expectedVnfmInfo.setUrl("https://cbamUrl:123/d");
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- setField(cbamRestApiProvider, "skipCertificateVerification", false);
- setField(cbamRestApiProvider, "trustedCertificates", Base64.getEncoder().encodeToString(TestUtil.loadFile("unittests/sample.cert.pem")));
- //when
- VnfsApi cbamLcmApi = cbamRestApiProvider.getCbamLcmApi(VNFM_ID);
- //verify
- ApiClient apiClient = cbamLcmApi.getApiClient();
- assertEquals("https://cbamUrl:123/d", apiClient.getBasePath());
- assertNotNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.lcm.v32.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamLcmApi.getApiClient().getAuthentications().size());
- assertTrue(cbamLcmApi.getApiClient().isVerifyingSsl());
- }
-
- /**
- * test CBAM Catalog API retrieval without SSL verification
- */
- @Test
- public void testCbamCatalogApi() throws Exception {
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- when(driverProperties.getCbamCatalogUrl()).thenReturn("https://1.2.3.4/path");
- //when
- DefaultApi cbamCatalogApi = cbamRestApiProvider.getCbamCatalogApi(VNFM_ID);
- //verify
- com.nokia.cbam.catalog.v1.ApiClient apiClient = cbamCatalogApi.getApiClient();
- assertEquals("https://1.2.3.4/path", apiClient.getBasePath());
- assertNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.catalog.v1.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamCatalogApi.getApiClient().getAuthentications().size());
- assertTrue(!cbamCatalogApi.getApiClient().isVerifyingSsl());
- }
-
- /**
- * test CBAM Catalog API retrieval with SSL verification
- */
- @Test
- public void testCbamCatalogApiWithSslVerfy() throws Exception {
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- when(driverProperties.getCbamCatalogUrl()).thenReturn("https://1.2.3.4/path");
- setField(cbamRestApiProvider, "skipCertificateVerification", false);
- setField(cbamRestApiProvider, "trustedCertificates", Base64.getEncoder().encodeToString(TestUtil.loadFile("unittests/sample.cert.pem")));
- //when
- DefaultApi cbamLcmApi = cbamRestApiProvider.getCbamCatalogApi(VNFM_ID);
- //verify
- com.nokia.cbam.catalog.v1.ApiClient apiClient = cbamLcmApi.getApiClient();
- assertEquals("https://1.2.3.4/path", apiClient.getBasePath());
- assertNotNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.catalog.v1.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamLcmApi.getApiClient().getAuthentications().size());
- assertTrue(cbamLcmApi.getApiClient().isVerifyingSsl());
- }
-
- /**
- * test CBAM Lcn API retrieval without SSL verification
- */
- @Test
- public void testCbamLcnApi() throws Exception {
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- when(driverProperties.getCbamLcnUrl()).thenReturn("https://1.2.3.4/path");
- //when
- SubscriptionsApi cbamLcnApi = cbamRestApiProvider.getCbamLcnApi(VNFM_ID);
- //verify
- com.nokia.cbam.lcn.v32.ApiClient apiClient = cbamLcnApi.getApiClient();
- assertEquals("https://1.2.3.4/path", apiClient.getBasePath());
- assertNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.lcn.v32.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamLcnApi.getApiClient().getAuthentications().size());
- assertTrue(!cbamLcnApi.getApiClient().isVerifyingSsl());
- }
-
- /**
- * test CBAM Lcn API retrieval with SSL verification
- */
- @Test
- public void testCbamLcnApiWithSslVerfy() throws Exception {
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- when(driverProperties.getCbamLcnUrl()).thenReturn("https://1.2.3.4/path");
- setField(cbamRestApiProvider, "skipCertificateVerification", false);
- setField(cbamRestApiProvider, "trustedCertificates", Base64.getEncoder().encodeToString(TestUtil.loadFile("unittests/sample.cert.pem")));
- //when
- SubscriptionsApi cbamLcnApi = cbamRestApiProvider.getCbamLcnApi(VNFM_ID);
- //verify
- com.nokia.cbam.lcn.v32.ApiClient apiClient = cbamLcnApi.getApiClient();
- assertEquals("https://1.2.3.4/path", apiClient.getBasePath());
- assertNotNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.lcn.v32.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamLcnApi.getApiClient().getAuthentications().size());
- assertTrue(cbamLcnApi.getApiClient().isVerifyingSsl());
- }
-
- /**
- * test CBAM operation exeution API retrieval without SSL verification
- */
- @Test
- public void testCbamOpexApi() throws Exception {
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- expectedVnfmInfo.setUrl("https://cbamUrl:123/d");
- //when
- OperationExecutionsApi cbamLcnApi = cbamRestApiProvider.getCbamOperationExecutionApi(VNFM_ID);
- //verify
- ApiClient apiClient = cbamLcnApi.getApiClient();
- assertEquals("https://cbamUrl:123/d", apiClient.getBasePath());
- assertNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.lcm.v32.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamLcnApi.getApiClient().getAuthentications().size());
- assertTrue(!cbamLcnApi.getApiClient().isVerifyingSsl());
- }
-
- /**
- * test CBAM operation execution API retrieval with SSL verification
- */
- @Test
- public void testCbamOpexApiWithSslVerfy() throws Exception {
- when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn("myToken");
- setField(cbamRestApiProvider, "skipCertificateVerification", false);
- setField(cbamRestApiProvider, "trustedCertificates", Base64.getEncoder().encodeToString(TestUtil.loadFile("unittests/sample.cert.pem")));
- VnfmInfo expectedVnfmInfo = new VnfmInfo();
- when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- expectedVnfmInfo.setUrl("https://cbamUrl:123/d");
- when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
- //when
- OperationExecutionsApi cbamLcnApi = cbamRestApiProvider.getCbamOperationExecutionApi(VNFM_ID);
- //verify
- ApiClient apiClient = cbamLcnApi.getApiClient();
- assertEquals("https://cbamUrl:123/d", apiClient.getBasePath());
- assertNotNull(apiClient.getSslCaCert());
- assertEquals("myToken", ((com.nokia.cbam.lcm.v32.auth.OAuth) apiClient.getAuthentication("OauthClient")).getAccessToken());
- assertEquals(2, cbamLcnApi.getApiClient().getAuthentications().size());
- assertTrue(cbamLcnApi.getApiClient().isVerifyingSsl());
- }
-}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java
index bc8f7835..7bc7df7a 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java
@@ -17,7 +17,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.*;
-import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
@@ -203,7 +202,6 @@ public class TestAAINotificationProcessor extends TestBase {
}
-
/**
* if changes connection points are not present a warning is logged
*/
@@ -219,7 +217,6 @@ public class TestAAINotificationProcessor extends TestBase {
verify(logger).warn("The changed connection points are not present in VNF with {} identifier", VNF_ID);
}
- @NotNull
private ReportedAffectedCp buildCp() {
ReportedAffectedCp cp = new ReportedAffectedCp();
cp.setServerProviderId(UUID.randomUUID().toString());
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
index 861966f3..7cddb50e 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
@@ -15,7 +15,6 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
import org.junit.Before;
import org.junit.Test;
@@ -113,7 +112,7 @@ public class TestGenericVnfManager extends TestBase {
}
return vnfs.iterator().next();
});
- when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
vnfs.add(vnfInAaai);
return null;
@@ -141,7 +140,7 @@ public class TestGenericVnfManager extends TestBase {
GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
vnfInAaai.setResourceVersion("v1");
when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
- when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenReturn(null);
vnfInfo.setName("vnfName");
//when
@@ -166,7 +165,7 @@ public class TestGenericVnfManager extends TestBase {
GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
vnfInAaai.setResourceVersion("v1");
when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
vnfInAaai.setResourceVersion("v2");
@@ -198,7 +197,7 @@ public class TestGenericVnfManager extends TestBase {
}
throw new NoSuchElementException();
});
- when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
RuntimeException runtimeException = new RuntimeException();
when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
GenericVnf vnfSentToAAi = (GenericVnf) invocation.getArguments()[3];
@@ -221,7 +220,7 @@ public class TestGenericVnfManager extends TestBase {
assertEquals("v3", vnfSentToAai.getResourceVersion());
verify(systemFunctions, times(10)).sleep(3000);
verify(aaiRestApiProvider, times(11)).get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class);
- verify(aaiRestApiProvider, times(2)).put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), anyString(), eq(Void.class));
+ verify(aaiRestApiProvider, times(2)).put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), any(), eq(Void.class));
verify(logger).warn(eq("The VNF with myVnfId identifier did not appear in time"), any(NoSuchElementException.class));
verify(logger).warn("The VNF with myVnfId identifier has been created since after the maximal wait for VNF to appear timeout", runtimeException);
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
index 159d6e63..373c5dd0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
@@ -119,6 +119,7 @@ public class TestL3NetworkManager extends TestBase {
assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
}
+
/**
* test L3 network deletion
*/
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcExternalSystemInfoProvider.java
index 537093c3..5f1ecc85 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcExternalSystemInfoProvider.java
@@ -19,10 +19,10 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import org.onap.vnfmdriver.ApiException;
import org.onap.vnfmdriver.model.VimInfo;
import org.onap.vnfmdriver.model.VnfmInfo;
import org.springframework.test.util.ReflectionTestUtils;
+import retrofit2.Call;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
@@ -44,7 +44,8 @@ public class TestVfcExternalSystemInfoProvider extends TestBase {
@Test
public void testVimRetrieval() throws Exception {
VimInfo expectedVimInfo = new VimInfo();
- when(nsLcmApi.queryVIMInfo(VIM_ID)).thenReturn(expectedVimInfo);
+ Call<VimInfo> vimInfoCall = buildCall(expectedVimInfo);
+ when(nsLcmApi.queryVIMInfo(VIM_ID)).thenReturn(vimInfoCall);
//when
VimInfo vimInfo = vfcExternalSystemInfoProvider.getVimInfo(VIM_ID);
//verify
@@ -56,7 +57,7 @@ public class TestVfcExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testUnableToQueryVim() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(nsLcmApi.queryVIMInfo(VIM_ID)).thenThrow(expectedException);
//when
try {
@@ -74,7 +75,8 @@ public class TestVfcExternalSystemInfoProvider extends TestBase {
@Test
public void testVnfmRetrieval() throws Exception {
VnfmInfo expectedVimInfo = new VnfmInfo();
- when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenReturn(expectedVimInfo);
+ Call<VnfmInfo> vnfmInfoCall = buildCall(expectedVimInfo);
+ when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenReturn(vnfmInfoCall);
//when
VnfmInfo vimInfo = vfcExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
//verify
@@ -86,7 +88,7 @@ public class TestVfcExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testUnableToQueryVnfm() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenThrow(expectedException);
//when
try {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
index 4bbf0764..53e8f8d7 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
@@ -20,6 +20,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.*;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
+import io.reactivex.Observable;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -29,9 +30,9 @@ import org.mockito.Mockito;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import org.onap.vnfmdriver.ApiException;
import org.onap.vnfmdriver.model.*;
import org.onap.vnfmdriver.model.ScaleDirection;
+import retrofit2.Call;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -57,7 +58,8 @@ public class TestVfcGrantManager extends TestBase {
@Before
public void initMocks() throws Exception {
setField(VfcGrantManager.class, "logger", logger);
- when(nsLcmApi.grantvnf(grantRequest.capture())).thenReturn(grantResponse);
+ Call<GrantVNFResponse> grantVNFResponseCall = buildCall(grantResponse);
+ when(nsLcmApi.grantvnf(grantRequest.capture())).thenReturn(grantVNFResponseCall);
grantResponse.setVim(vim);
}
@@ -101,7 +103,7 @@ public class TestVfcGrantManager extends TestBase {
@Test
public void testFailureDuringGrantRequest() throws Exception {
String cbamVnfdContent = new String(readAllBytes(Paths.get(TestVfcGrantManager.class.getResource("/unittests/vnfd.instantiation.yaml").toURI())));
- ApiException expectedException = new ApiException("a");
+ RuntimeException expectedException = new RuntimeException("a");
when(nsLcmApi.grantvnf(Mockito.any())).thenThrow(expectedException);
//when
try {
@@ -224,7 +226,7 @@ public class TestVfcGrantManager extends TestBase {
prop.setValue(ONAP_CSAR_ID);
vnf.setVnfConfigurableProperties(new ArrayList<>());
vnf.getVnfConfigurableProperties().add(prop);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(nsLcmApi.grantvnf(Mockito.any())).thenThrow(expectedException);
//when
try {
@@ -246,7 +248,7 @@ public class TestVfcGrantManager extends TestBase {
scaleRequest.setType(ScaleDirection.OUT);
scaleRequest.setAspectId("aspect1");
scaleRequest.setNumberOfSteps("2");
- com.nokia.cbam.lcm.v32.ApiException expectedException = new com.nokia.cbam.lcm.v32.ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
@@ -270,7 +272,8 @@ public class TestVfcGrantManager extends TestBase {
scaleRequest.setAspectId("aspect1");
scaleRequest.setNumberOfSteps("2");
VnfInfo vnf = new VnfInfo();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ Observable<VnfInfo> vnfInfoObservable = buildObservable(vnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfoObservable);
vnf.setVnfdId(CBAM_VNFD_ID);
when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent);
//when
@@ -295,7 +298,8 @@ public class TestVfcGrantManager extends TestBase {
scaleRequest.setAspectId("aspectWithOutVdu");
scaleRequest.setNumberOfSteps("2");
VnfInfo vnf = new VnfInfo();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ Observable<VnfInfo> vnfInfoObservable = buildObservable(vnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfoObservable);
vnf.setVnfdId(CBAM_VNFD_ID);
when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent);
//when
@@ -320,7 +324,7 @@ public class TestVfcGrantManager extends TestBase {
scaleRequest.setAspectId("emptyAspect");
scaleRequest.setNumberOfSteps("2");
VnfInfo vnf = new VnfInfo();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnf));
vnf.setVnfdId(CBAM_VNFD_ID);
when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent);
//when
@@ -343,7 +347,7 @@ public class TestVfcGrantManager extends TestBase {
scaleRequest.setAspectId("aspect1");
scaleRequest.setNumberOfSteps("2");
VnfInfo vnf = new VnfInfo();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnf));
vnf.setVnfdId(CBAM_VNFD_ID);
when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent);
//when
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
index d28e224f..4fbae45f 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
@@ -30,11 +30,9 @@ import com.nokia.cbam.lcm.v32.model.ScaleDirection;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
-import org.onap.vnfmdriver.ApiException;
import org.onap.vnfmdriver.model.*;
import org.threeten.bp.OffsetDateTime;
@@ -66,7 +64,7 @@ public class TestVfcNotificationSender extends TestBase {
public void init() throws Exception {
vfcNotificationSender = new VfcNotificationSender(driverProperties, vfcRestApiProvider);
setField(VfcNotificationSender.class, "logger", logger);
- Mockito.doNothing().when(nsLcmApi).vNFLCMNotification(eq(VNFM_ID), eq(VNF_ID), sentLcnToVfc.capture());
+ when(nsLcmApi.vNFLCMNotification(eq(VNFM_ID), eq(VNF_ID), sentLcnToVfc.capture())).thenReturn(VOID_CALL);
instantiationOperation.setId("instantiationOperationExecutionId");
instantiationOperation.setStartTime(OffsetDateTime.now());
instantiationOperation.setOperationType(OperationType.INSTANTIATE);
@@ -79,7 +77,7 @@ public class TestVfcNotificationSender extends TestBase {
healOperation.setId("healOperaitonExecutionId");
healOperation.setOperationType(OperationType.HEAL);
healOperation.setStartTime(OffsetDateTime.now().plusDays(1));
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(operationExecutions);
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecutions));
prepOperation(instantiationOperation);
prepOperation(scaleOperation);
prepOperation(healOperation);
@@ -87,7 +85,7 @@ public class TestVfcNotificationSender extends TestBase {
recievedLcn.setVnfInstanceId(VNF_ID);
}
- private void prepOperation(OperationExecution operationExecution) throws com.nokia.cbam.lcm.v32.ApiException {
+ private void prepOperation(OperationExecution operationExecution) {
addEmptyModifiedConnectionPoints(operationExecution);
JsonElement root = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + JOB_ID + "\"}}");
operationExecution.setOperationParams(root);
@@ -95,7 +93,7 @@ public class TestVfcNotificationSender extends TestBase {
case TERMINATE:
root.getAsJsonObject().addProperty("terminationType", "GRACEFULL");
}
- when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(operationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationExecution);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(operationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecution));
operationExecutions.add(operationExecution);
}
@@ -842,7 +840,7 @@ public class TestVfcNotificationSender extends TestBase {
*/
@Test
public void testUnableToSendNotificationToVfc() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
doThrow(expectedException).when(nsLcmApi).vNFLCMNotification(any(), any(), any());
recievedLcn.setStatus(OperationStatus.STARTED);
recievedLcn.setOperation(OperationType.INSTANTIATE);
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java
index b027ccad..b09a11b1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java
@@ -25,9 +25,9 @@ import org.mockito.Mockito;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.IpMappingProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import org.onap.vfccatalog.ApiException;
import org.onap.vfccatalog.model.VnfPkgDetailInfo;
import org.onap.vfccatalog.model.VnfPkgInfo;
+import retrofit2.Call;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -65,7 +65,8 @@ public class TestVfcPackageProvider extends TestBase {
vnfPackageDetails.setPackageInfo(new VnfPkgInfo());
vnfPackageDetails.getPackageInfo().setVnfdModel("{ \"metadata\" : { \"resourceVendorModelNumber\" : \"" + CBAM_VNFD_ID + "\" }}");
vnfPackageDetails.getPackageInfo().setDownloadUrl("http://127.0.0.1/a.csar");
- when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenReturn(vnfPackageDetails);
+ Call<VnfPkgDetailInfo> vnfPkgDetailInfoCall = buildCall(vnfPackageDetails);
+ when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenReturn(vnfPkgDetailInfoCall);
//when
String cbamVnfdId = vfcPackageProvider.getCbamVnfdId(CSAR_ID);
//verify
@@ -82,7 +83,8 @@ public class TestVfcPackageProvider extends TestBase {
vnfPackageDetails.setPackageInfo(new VnfPkgInfo());
vnfPackageDetails.getPackageInfo().setVnfdModel("{ \"metadata\" : { \"resourceVendorModelNumber\" : \"" + CBAM_VNFD_ID + "\" }}");
vnfPackageDetails.getPackageInfo().setDownloadUrl("http://127.0.0.1/a.csar");
- when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenReturn(vnfPackageDetails);
+ Call<VnfPkgDetailInfo> vnfPkgDetailInfoCall = buildCall(vnfPackageDetails);
+ when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenReturn(vnfPkgDetailInfoCall);
byte[] onapPackageContent = TestUtil.loadFile("unittests/TestCbamCatalogManager.sample.csar");
when(ipMappingProvider.mapPrivateIpToPublicIp("127.0.0.1")).thenReturn("1.2.3.4");
when(entity.getContent()).thenReturn(new ByteArrayInputStream(onapPackageContent));
@@ -100,7 +102,7 @@ public class TestVfcPackageProvider extends TestBase {
*/
@Test
public void unableToGetCbamVnfdFromCatalog() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenThrow(expectedException);
//when
try {
@@ -122,7 +124,8 @@ public class TestVfcPackageProvider extends TestBase {
vnfPackageDetails.setPackageInfo(new VnfPkgInfo());
vnfPackageDetails.getPackageInfo().setVnfdModel("{ \"metadata\" : { \"resourceVendorModelNumber\" : \"" + CBAM_VNFD_ID + "\" }}");
vnfPackageDetails.getPackageInfo().setDownloadUrl("http://127.0.0.1/a.csar");
- when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenReturn(vnfPackageDetails);
+ Call<VnfPkgDetailInfo> vnfPkgDetailInfoCall = buildCall(vnfPackageDetails);
+ when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenReturn(vnfPkgDetailInfoCall);
byte[] onapPackageContent = TestUtil.loadFile("unittests/TestCbamCatalogManager.sample.csar");
when(ipMappingProvider.mapPrivateIpToPublicIp("127.0.0.1")).thenReturn("1.2.3.4");
IOException expectedException = new IOException();
@@ -142,7 +145,7 @@ public class TestVfcPackageProvider extends TestBase {
*/
@Test
public void unableToQueryPackageForDownloadFromCatalog() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vfcCatalogApi.queryVnfPackage(CSAR_ID)).thenThrow(expectedException);
//when
try {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcRestApiProvider.java
index a527b568..9881749e 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcRestApiProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcRestApiProvider.java
@@ -19,11 +19,11 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+import org.onap.vfccatalog.ApiClient;
import org.onap.vfccatalog.api.VnfpackageApi;
-import org.onap.vnfmdriver.api.NslcmApi;
import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertNull;
+import static junit.framework.TestCase.assertNotNull;
import static org.mockito.Mockito.when;
public class TestVfcRestApiProvider extends TestBase {
@@ -35,30 +35,43 @@ public class TestVfcRestApiProvider extends TestBase {
}
/**
- * test VF-C NSLCM API retrieval
+ * the base URL of the LCM API is set
*/
@Test
public void testNsLcmApi() throws Exception {
- when(msbApiProvider.getMicroServiceUrl(VfcRestApiProvider.NSLCM_API_SERVICE_NAME, VfcRestApiProvider.NSLCM_API_VERION)).thenReturn("http://1.2.3.4:1234/nslcm/v1/lead");
+ when(msbApiProvider.getMicroServiceUrl(VfcRestApiProvider.NSLCM_API_SERVICE_NAME, VfcRestApiProvider.NSLCM_API_VERION)).thenReturn("http://1.2.3.4:1234/nslcm/v1/lead/");
//when
- NslcmApi nsLcmApi = vfcRestApiProvider.getNsLcmApi();
+ org.onap.vnfmdriver.ApiClient apiClient = vfcRestApiProvider.buildNslcmApiClient();
//verify
- assertEquals("http://1.2.3.4:1234/lead", nsLcmApi.getApiClient().getBasePath());
- assertNull(nsLcmApi.getApiClient().getSslCaCert());
- assertEquals(0, nsLcmApi.getApiClient().getAuthentications().size());
+ assertEquals("http://1.2.3.4:1234/lead/", apiClient.getAdapterBuilder().build().baseUrl().toString());
}
/**
- * test VF-C catalog API retrieval
+ * the base URL of the Catalog API is set
*/
@Test
public void testNsCatalogApi() throws Exception {
- when(msbApiProvider.getMicroServiceUrl(VfcRestApiProvider.NSCATALOG_SERVICE_NAME, VfcRestApiProvider.NSCATALOG_API_VERSION)).thenReturn("http://1.2.3.4:1234/lead");
+ when(msbApiProvider.getMicroServiceUrl(VfcRestApiProvider.NSCATALOG_SERVICE_NAME, VfcRestApiProvider.NSCATALOG_API_VERSION)).thenReturn("http://1.2.3.4:1234/lead/");
//when
- VnfpackageApi nsCatalogApi = vfcRestApiProvider.getOnapCatalogApi();
+ ApiClient apiClient = vfcRestApiProvider.buildCatalogApiClient();
//verify
- assertEquals("http://1.2.3.4:1234/lead", nsCatalogApi.getApiClient().getBasePath());
- assertNull(nsCatalogApi.getApiClient().getSslCaCert());
- assertEquals(0, nsCatalogApi.getApiClient().getAuthentications().size());
+ assertEquals("http://1.2.3.4:1234/lead/", apiClient.getAdapterBuilder().build().baseUrl().toString());
+ }
+
+ @Test
+ public void testNsLcm() {
+ when(msbApiProvider.getMicroServiceUrl(VfcRestApiProvider.NSLCM_API_SERVICE_NAME, VfcRestApiProvider.NSLCM_API_VERION)).thenReturn("http://1.2.3.4:1234/nslcm/v1/lead/");
+ //when
+ //verify
+ assertNotNull(vfcRestApiProvider.getNsLcmApi());
+ }
+
+ @Test
+ public void testNsCatalog() {
+ when(msbApiProvider.getMicroServiceUrl(VfcRestApiProvider.NSCATALOG_SERVICE_NAME, VfcRestApiProvider.NSCATALOG_API_VERSION)).thenReturn("http://1.2.3.4:1234/lead/");
+ //when
+ VnfpackageApi catalogApi = vfcRestApiProvider.getVfcCatalogApi();
+ //verify
+ assertNotNull(catalogApi);
}
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
index eeb79be8..6096802a 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
@@ -18,6 +18,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Sets;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import junit.framework.TestCase;
@@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.reflect.Method;
import java.util.HashSet;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
@@ -43,11 +45,11 @@ public class TestSwaggerDefinitionConsistency extends TestBase {
JsonObject root = new JsonParser().parse(new String(loadFile("self.swagger.json"))).getAsJsonObject();
String basePath = root.get("basePath").getAsString();
HashMultimap<String, RequestMethod> expectedPaths = HashMultimap.create();
- for (String pathName : child(root, "paths").keySet()) {
- JsonObject path = child(child(root, "paths"), pathName);
- for (String method : path.keySet()) {
- locate(basePath + pathName);
- expectedPaths.put(basePath + pathName, RequestMethod.valueOf(method.toUpperCase()));
+ for (Map.Entry<String, JsonElement> pathName : child(root, "paths").entrySet()) {
+ JsonObject path = child(child(root, "paths"), pathName.getKey());
+ for (Map.Entry<String, JsonElement> method : path.entrySet()) {
+ locate(basePath + pathName.getKey());
+ expectedPaths.put(basePath + pathName.getKey(), RequestMethod.valueOf(method.getKey().toUpperCase()));
}
}
@@ -60,7 +62,7 @@ public class TestSwaggerDefinitionConsistency extends TestBase {
RequestMethod restMethod = methodMapping.method()[0];
Set<RequestMethod> currentMethods = expectedPaths.get(fPath);
if (!currentMethods.contains(restMethod)) {
- TestCase.fail("Not documented REST API" + fPath + " " + restMethod + " current " + currentMethods);
+ TestCase.fail("Not documented REST API " + fPath + " " + restMethod + " current " + currentMethods);
}
}
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java
index 7a525b37..671764ae 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java
@@ -68,7 +68,7 @@ public class TestConditions {
* use class in a static way
*/
@Test
- public void useStaticway(){
+ public void useStaticway() {
TestUtil.coveragePrivateConstructorForClassesWithStaticMethodsOnly(Conditions.class);
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java
new file mode 100644
index 00000000..9b032824
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java
@@ -0,0 +1,91 @@
+/*
+ * 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 com.google.common.io.ByteStreams;
+import org.eclipse.jetty.server.NetworkTrafficServerConnector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+public class HttpTestServer {
+ public Server _server;
+ public volatile List<String> requests = new ArrayList<>();
+ public volatile List<Integer> codes = new ArrayList<>();
+ public volatile List<String> respones = new ArrayList<>();
+ ExecutorService executorService = Executors.newCachedThreadPool();
+
+ public void start() throws Exception {
+ configureServer();
+ startServer();
+ }
+
+ private void startServer() throws Exception {
+ 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 {
+ Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.jks").toURI());
+ String path = jksPath.normalize().toAbsolutePath().toUri().toString();
+ _server = new Server();
+ SslContextFactory factory = new SslContextFactory(path);
+ factory.setKeyStorePassword("changeit");
+ NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(_server, factory);
+ connector.setHost("127.0.0.1");
+ _server.addConnector(connector);
+ _server.setHandler(new AbstractHandler() {
+ @Override
+ public void handle(String target, org.eclipse.jetty.server.Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
+ requests.add(new String(ByteStreams.toByteArray(request.getInputStream())));
+ httpServletResponse.getWriter().write(respones.remove(0));
+ httpServletResponse.setStatus(codes.remove(0));
+ request.setHandled(true);
+ }
+ });
+ }
+
+ public void stop() throws Exception {
+ _server.stop();
+ }
+}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java
index 7a1bf7f2..2489d3c2 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java
@@ -21,6 +21,9 @@ import com.nokia.cbam.catalog.v1.api.DefaultApi;
import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
import com.nokia.cbam.lcm.v32.api.VnfsApi;
import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
+import io.reactivex.Observable;
+import okhttp3.RequestBody;
+import okio.Buffer;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -31,6 +34,7 @@ import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
@@ -45,6 +49,8 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.test.util.ReflectionTestUtils;
+import retrofit2.Call;
+import retrofit2.Response;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
@@ -69,6 +75,7 @@ public class TestBase {
public static final String VIM_ID = "myCloudOwnerId_myRegionName";
public static final String JOB_ID = "myJobId";
public static final String CBAM_VNFD_ID = "cbamVnfdId";
+ protected static Call<Void> VOID_CALL = buildCall(null);
@Mock
protected CbamRestApiProvider cbamRestApiProvider;
@Mock
@@ -113,6 +120,20 @@ public class TestBase {
@Mock
protected Environment environment;
+ protected static <T> Call<T> buildCall(T response) {
+ Call<T> call = Mockito.mock(Call.class);
+ try {
+ when(call.execute()).thenReturn(Response.success(response));
+ } catch (Exception e) {
+ throw new RuntimeException();
+ }
+ return call;
+ }
+
+ protected static <T> Observable<T> buildObservable(T response) {
+ return Observable.just(response);
+ }
+
@Before
public void genericSetup() throws Exception {
MockitoAnnotations.initMocks(this);
@@ -123,7 +144,7 @@ public class TestBase {
when(cbamRestApiProvider.getCbamCatalogApi(VNFM_ID)).thenReturn(cbamCatalogApi);
when(msbApiProvider.getMsbClient()).thenReturn(msbClient);
when(vfcRestApiProvider.getNsLcmApi()).thenReturn(nsLcmApi);
- when(vfcRestApiProvider.getOnapCatalogApi()).thenReturn(vfcCatalogApi);
+ when(vfcRestApiProvider.getVfcCatalogApi()).thenReturn(vfcCatalogApi);
when(systemFunctions.getHttpClient()).thenReturn(httpClient);
when(httpClient.execute(request.capture())).thenReturn(response);
when(response.getEntity()).thenReturn(entity);
@@ -148,6 +169,18 @@ public class TestBase {
assertEquals(build(expected), build(actual));
}
+ byte[] getContent(RequestBody requestBody) {
+ try {
+ Buffer buffer = new Buffer();
+ requestBody.writeTo(buffer);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ buffer.copyTo(byteArrayOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
private Map<String, List<Byte>> build(byte[] zip) throws Exception {
Map<String, List<Byte>> files = new HashMap<>();
ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(zip));
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java
index f38758f0..1425d97c 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java
@@ -16,6 +16,12 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
+import okhttp3.Headers;
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
+import okhttp3.internal.http.RealResponseBody;
+import okio.Buffer;
+import okio.BufferedSource;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -25,15 +31,13 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IPackageProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
+import retrofit2.Call;
import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.UUID;
import static junit.framework.TestCase.*;
import static org.junit.Assert.assertArrayEquals;
@@ -50,12 +54,13 @@ public class TestCbamCatalogManager extends TestBase {
private IPackageProvider packageProvider;
private List<CatalogAdapterVnfpackage> existingVnfPackages = new ArrayList<>();
- private ArgumentCaptor<File> uploadedFile = ArgumentCaptor.forClass(File.class);
+ private ArgumentCaptor<RequestBody> uploadedFile = ArgumentCaptor.forClass(RequestBody.class);
@Before
public void initMocks() throws Exception {
setField(CatalogManager.class, "logger", logger);
- when(cbamCatalogApi.list()).thenReturn(existingVnfPackages);
+ Call<List<CatalogAdapterVnfpackage>> value = buildCall(existingVnfPackages);
+ when(cbamCatalogApi.list()).thenReturn(value);
cbamCatalogManager = new CatalogManager(cbamRestApiProvider, packageProvider);
}
@@ -69,19 +74,15 @@ public class TestCbamCatalogManager extends TestBase {
existingVnfPackages.add(existingPackage);
CatalogAdapterVnfpackage createdPackage = new CatalogAdapterVnfpackage();
createdPackage.setVnfdId(CBAM_VNFD_ID);
- when(cbamCatalogApi.create(uploadedFile.capture())).thenAnswer(new Answer<CatalogAdapterVnfpackage>() {
- @Override
- public CatalogAdapterVnfpackage answer(InvocationOnMock invocationOnMock) throws Throwable {
- return createdPackage;
- }
- });
+ Call<CatalogAdapterVnfpackage> catalogAdapterVnfpackageCall = buildCall(createdPackage);
+ when(cbamCatalogApi.create(uploadedFile.capture())).thenReturn(catalogAdapterVnfpackageCall);
byte[] onapPackageContent = TestUtil.loadFile("unittests/TestCbamCatalogManager.sample.csar");
when(packageProvider.getPackage(CSAR_ID)).thenReturn(onapPackageContent);
when(packageProvider.getCbamVnfdId(CSAR_ID)).thenReturn(CBAM_VNFD_ID);
//when
CatalogAdapterVnfpackage cbamPackage = cbamCatalogManager.preparePackageInCbam(VNFM_ID, CSAR_ID);
//verify
- byte[] a2 = Files.readAllBytes(uploadedFile.getValue().toPath());
+ byte[] a2 = getContent(uploadedFile.getValue());
assertArrayEquals(getFileInZip(new ByteArrayInputStream(onapPackageContent), "Artifacts/Deployment/OTHER/cbam.package.zip").toByteArray(), a2);
assertEquals(createdPackage, cbamPackage);
}
@@ -106,7 +107,8 @@ public class TestCbamCatalogManager extends TestBase {
public CatalogAdapterVnfpackage answer(InvocationOnMock invocationOnMock) throws Throwable {
//this is done by an other thread
existingVnfPackages.add(createdPackage);
- when(cbamCatalogApi.getById(CBAM_VNFD_ID)).thenReturn(createdPackage);
+ Call<CatalogAdapterVnfpackage> catalogAdapterVnfpackageCall = buildCall(createdPackage);
+ when(cbamCatalogApi.getById(CBAM_VNFD_ID)).thenReturn(catalogAdapterVnfpackageCall);
throw can_not_upload_package;
}
});
@@ -115,7 +117,7 @@ public class TestCbamCatalogManager extends TestBase {
//verify
//the correct portion of the package is extracted and uploaded to CBAM
byte[] expectedContentToUpload = getFileInZip(new ByteArrayInputStream(onapPackageContent), "Artifacts/Deployment/OTHER/cbam.package.zip").toByteArray();
- assertTrue(Arrays.equals(expectedContentToUpload, Files.readAllBytes(uploadedFile.getValue().toPath())));
+ assertTrue(Arrays.equals(expectedContentToUpload, getContent(uploadedFile.getValue())));
assertEquals(createdPackage, cbamPackage);
verify(logger).debug("Probably concurrent package uploads", can_not_upload_package);
}
@@ -137,7 +139,8 @@ public class TestCbamCatalogManager extends TestBase {
CatalogAdapterVnfpackage existingPackage = new CatalogAdapterVnfpackage();
existingPackage.setVnfdId(CBAM_VNFD_ID);
existingVnfPackages.add(existingPackage);
- when(cbamCatalogApi.getById(CBAM_VNFD_ID)).thenReturn(existingPackage);
+ Call<CatalogAdapterVnfpackage> catalogAdapterVnfpackageCall = buildCall(existingPackage);
+ when(cbamCatalogApi.getById(CBAM_VNFD_ID)).thenReturn(catalogAdapterVnfpackageCall);
//when
CatalogAdapterVnfpackage cbamPackage = cbamCatalogManager.preparePackageInCbam(VNFM_ID, CSAR_ID);
//verify
@@ -152,7 +155,7 @@ public class TestCbamCatalogManager extends TestBase {
@Test
public void testFailureToListVnfPackagesInCbam() throws Exception {
when(packageProvider.getCbamVnfdId(CSAR_ID)).thenReturn(CBAM_VNFD_ID);
- com.nokia.cbam.catalog.v1.ApiException expectedException = new com.nokia.cbam.catalog.v1.ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(cbamCatalogApi.list()).thenThrow(expectedException);
//when
try {
@@ -173,7 +176,7 @@ public class TestCbamCatalogManager extends TestBase {
CatalogAdapterVnfpackage existingPackage = new CatalogAdapterVnfpackage();
existingPackage.setVnfdId(CBAM_VNFD_ID);
existingVnfPackages.add(existingPackage);
- com.nokia.cbam.catalog.v1.ApiException expectedException = new com.nokia.cbam.catalog.v1.ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(cbamCatalogApi.getById(CBAM_VNFD_ID)).thenThrow(expectedException);
//when
try {
@@ -196,7 +199,7 @@ public class TestCbamCatalogManager extends TestBase {
when(packageProvider.getCbamVnfdId(CSAR_ID)).thenReturn(CBAM_VNFD_ID);
byte[] onapPackageContent = TestUtil.loadFile("unittests/TestCbamCatalogManager.sample.csar");
when(packageProvider.getPackage(CSAR_ID)).thenReturn(onapPackageContent);
- com.nokia.cbam.catalog.v1.ApiException expectedException = new com.nokia.cbam.catalog.v1.ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(cbamCatalogApi.create(Mockito.any())).thenThrow(expectedException);
try {
cbamCatalogManager.preparePackageInCbam(VNFM_ID, CSAR_ID);
@@ -212,9 +215,8 @@ public class TestCbamCatalogManager extends TestBase {
*/
@Test
public void testExtractVnfdFromPackage() throws Exception {
- Path csar = Files.createTempFile(UUID.randomUUID().toString(), "csar");
- Files.write(csar, TestUtil.loadFile("unittests/cbam.package.zip"));
- when(cbamCatalogApi.content(CBAM_VNFD_ID)).thenReturn(csar.toFile());
+ Call<ResponseBody> responseBodyCall = buildCall(buildResponse(TestUtil.loadFile("unittests/cbam.package.zip")));
+ when(cbamCatalogApi.content(CBAM_VNFD_ID)).thenReturn(responseBodyCall);
//when
String content = cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID);
//verify
@@ -226,9 +228,8 @@ public class TestCbamCatalogManager extends TestBase {
*/
@Test
public void testEmptyCbamPackage() throws Exception {
- Path csar = Files.createTempFile(UUID.randomUUID().toString(), "csar");
- Files.write(csar, TestUtil.loadFile("unittests/empty.zip"));
- when(cbamCatalogApi.content(CBAM_VNFD_ID)).thenReturn(csar.toFile());
+ Call<ResponseBody> responseBodyCall = buildCall(buildResponse(TestUtil.loadFile("unittests/empty.zip")));
+ when(cbamCatalogApi.content(CBAM_VNFD_ID)).thenReturn(responseBodyCall);
//when
try {
cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID);
@@ -244,9 +245,9 @@ public class TestCbamCatalogManager extends TestBase {
*/
@Test
public void testMissingVnfdCbamPackage() throws Exception {
- Path csar = Files.createTempFile(UUID.randomUUID().toString(), "csar");
- Files.write(csar, TestUtil.loadFile("unittests/missing.vnfd.zip"));
- when(cbamCatalogApi.content(CBAM_VNFD_ID)).thenReturn(csar.toFile());
+ byte[] bytes = TestUtil.loadFile("unittests/missing.vnfd.zip");
+ Call<ResponseBody> response = buildCall(buildResponse(bytes));
+ when(cbamCatalogApi.content(CBAM_VNFD_ID)).thenReturn(response);
//when
try {
cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID);
@@ -258,4 +259,12 @@ public class TestCbamCatalogManager extends TestBase {
);
}
}
+
+ private ResponseBody buildResponse(byte[] content) throws IOException {
+ Headers headers = new Headers.Builder().build();
+ Buffer buffer = new Buffer();
+ buffer.write(content);
+ BufferedSource response = buffer;
+ return new RealResponseBody(headers, response);
+ }
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java
new file mode 100644
index 00000000..cb541278
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java
@@ -0,0 +1,257 @@
+/*
+ * 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 com.nokia.cbam.catalog.v1.api.DefaultApi;
+import com.nokia.cbam.lcm.v32.ApiClient;
+import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
+import com.nokia.cbam.lcm.v32.api.VnfsApi;
+import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
+import okhttp3.Interceptor;
+import okhttp3.OakExtractor;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
+import org.onap.msb.sdk.discovery.entity.NodeInfo;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.IpMappingProvider;
+import org.onap.vnfmdriver.model.VnfmInfo;
+import org.springframework.core.env.Environment;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertNotNull;
+import static org.mockito.Mockito.*;
+import static org.springframework.test.util.ReflectionTestUtils.setField;
+
+class ResultCaptor<T> implements Answer {
+ private T result = null;
+
+ public T getResult() {
+ return result;
+ }
+
+ @Override
+ public T answer(InvocationOnMock invocationOnMock) throws Throwable {
+ result = (T) invocationOnMock.callRealMethod();
+ return result;
+ }
+}
+
+public class TestCbamRestApiProvider extends TestBase {
+ @Mock
+ private Environment environment;
+ @Mock
+ private CbamTokenProvider cbamTokenProvider;
+ @Mock
+ private MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+ @Mock
+ private Interceptor interceptor;
+ @Mock
+ private HostnameVerifier hostnameVerifier;
+ private Set<NodeInfo> nodes = new HashSet<>();
+
+ private CbamRestApiProvider cbamRestApiProvider;
+ private CbamSecurityProvider cbamSecurityProvider = spy(new CbamSecurityProvider());
+
+ @Before
+ public void init() {
+ microServiceInfo.setNodes(nodes);
+ setField(cbamSecurityProvider, "skipCertificateVerification", true);
+ setField(cbamSecurityProvider, "skipHostnameVerification", true);
+ cbamRestApiProvider = new CbamRestApiProvider(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider);
+ when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("");
+ when(environment.getProperty(GenericExternalSystemInfoProvider.VNFM_INFO_CACHE_EVICTION_IN_MS, Long.class, Long.valueOf(10 * 60 * 1000))).thenReturn(10 * 60 * 1000L);
+ }
+
+ /**
+ * test CBAM LCM API
+ */
+ @Test
+ public void testCbamLcmApi() throws Exception {
+ VnfmInfo expectedVnfmInfo = new VnfmInfo();
+ when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo);
+ expectedVnfmInfo.setUrl("https://cbamurl:123/d/");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(cbamSecurityProvider).buildSSLSocketFactory();
+ when(cbamSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
+ when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn(interceptor);
+ //when
+ ApiClient cbamLcmApi = cbamRestApiProvider.buildLcmApiClient(VNFM_ID);
+ //verify
+ String actual = cbamLcmApi.getAdapterBuilder().build().baseUrl().toString();
+ assertEquals("https://cbamurl:123/d/", actual);
+ assertEquals(sslSocketFactoryResultCaptor.getResult(), cbamLcmApi.getOkBuilder().build().sslSocketFactory());
+ Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
+ assertEquals(1, apiAuthorizations.size());
+ assertEquals(interceptor, apiAuthorizations.values().iterator().next());
+ assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ }
+
+ /**
+ * test CBAM catalog API
+ */
+ @Test
+ public void testCbamCatalogApi() throws Exception {
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(cbamSecurityProvider).buildSSLSocketFactory();
+ when(cbamSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
+ when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn(interceptor);
+ when(driverProperties.getCbamCatalogUrl()).thenReturn("https://cbamurl:123/d/");
+ //when
+ com.nokia.cbam.catalog.v1.ApiClient cbamLcmApi = cbamRestApiProvider.buildCatalogApiClient(VNFM_ID);
+ //verify
+ String actual = cbamLcmApi.getAdapterBuilder().build().baseUrl().toString();
+ assertEquals("https://cbamurl:123/d/", actual);
+ assertEquals(sslSocketFactoryResultCaptor.getResult(), cbamLcmApi.getOkBuilder().build().sslSocketFactory());
+ Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
+ assertEquals(1, apiAuthorizations.size());
+ assertEquals(interceptor, apiAuthorizations.values().iterator().next());
+ assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ }
+
+ /**
+ * test CBAM LCN API
+ */
+ @Test
+ public void testCbamLcnApi() throws Exception {
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(cbamSecurityProvider).buildSSLSocketFactory();
+ when(cbamSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
+ when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn(interceptor);
+ when(driverProperties.getCbamLcnUrl()).thenReturn("https://cbamurl:123/d/");
+ //when
+ com.nokia.cbam.lcn.v32.ApiClient cbamLcmApi = cbamRestApiProvider.buildLcnApiClient(VNFM_ID);
+ //verify
+ String actual = cbamLcmApi.getAdapterBuilder().build().baseUrl().toString();
+ assertEquals("https://cbamurl:123/d/", actual);
+ assertEquals(sslSocketFactoryResultCaptor.getResult(), cbamLcmApi.getOkBuilder().build().sslSocketFactory());
+ Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
+ assertEquals(1, apiAuthorizations.size());
+ assertEquals(interceptor, apiAuthorizations.values().iterator().next());
+ assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ }
+
+ /**
+ * Test API wrapping for Catalog
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
+ */
+ @Test
+ public void testCatalogAPiWrapping() {
+ com.nokia.cbam.catalog.v1.ApiClient c = Mockito.mock(com.nokia.cbam.catalog.v1.ApiClient.class);
+ class TestClasss extends CbamRestApiProvider {
+ public TestClasss() {
+ super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider);
+ }
+
+ @Override
+ com.nokia.cbam.catalog.v1.ApiClient buildCatalogApiClient(String vnfmId) {
+ return c;
+ }
+ }
+ DefaultApi defaultApi = Mockito.mock(DefaultApi.class);
+ when(c.createService(DefaultApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertNotNull(testInstnace.getCbamCatalogApi(VNFM_ID));
+ assertEquals(defaultApi, testInstnace.getCbamCatalogApi(VNFM_ID));
+ }
+
+ /**
+ * Test API wrapping for LCN
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
+ */
+ @Test
+ public void testLcmAPiWrapping() {
+ com.nokia.cbam.lcn.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcn.v32.ApiClient.class);
+ class TestClasss extends CbamRestApiProvider {
+ public TestClasss() {
+ super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider);
+ }
+
+ @Override
+ com.nokia.cbam.lcn.v32.ApiClient buildLcnApiClient(String vnfmId) {
+ return c;
+ }
+ }
+ SubscriptionsApi defaultApi = Mockito.mock(SubscriptionsApi.class);
+ when(c.createService(SubscriptionsApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertNotNull(testInstnace.getCbamLcnApi(VNFM_ID));
+ assertEquals(defaultApi, testInstnace.getCbamLcnApi(VNFM_ID));
+ }
+
+ /**
+ * Test API wrapping for LCM
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
+ */
+ @Test
+ public void testLcnAPiWrapping() {
+ com.nokia.cbam.lcm.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcm.v32.ApiClient.class);
+ class TestClasss extends CbamRestApiProvider {
+ public TestClasss() {
+ super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider);
+ }
+
+ @Override
+ ApiClient buildLcmApiClient(String vnfmId) {
+ return c;
+ }
+ }
+ VnfsApi defaultApi = Mockito.mock(VnfsApi.class);
+ when(c.createService(VnfsApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertNotNull(testInstnace.getCbamLcmApi(VNFM_ID));
+ assertEquals(defaultApi, testInstnace.getCbamLcmApi(VNFM_ID));
+ }
+
+ /**
+ * Test API wrapping for LCM
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
+ */
+ @Test
+ public void testOperationExecutionsApiAPiWrapping() {
+ com.nokia.cbam.lcm.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcm.v32.ApiClient.class);
+ class TestClasss extends CbamRestApiProvider {
+ public TestClasss() {
+ super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider);
+ }
+
+ @Override
+ ApiClient buildLcmApiClient(String vnfmId) {
+ return c;
+ }
+ }
+ OperationExecutionsApi defaultApi = Mockito.mock(OperationExecutionsApi.class);
+ when(c.createService(OperationExecutionsApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertNotNull(testInstnace.getCbamOperationExecutionApi(VNFM_ID));
+ assertEquals(defaultApi, testInstnace.getCbamOperationExecutionApi(VNFM_ID));
+ }
+}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java
new file mode 100644
index 00000000..17c68e41
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java
@@ -0,0 +1,327 @@
+/*
+ * 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 com.google.gson.Gson;
+import com.google.gson.JsonParseException;
+import com.google.gson.annotations.SerializedName;
+import com.nokia.cbam.lcn.v32.JSON;
+import io.reactivex.Observable;
+import okhttp3.OkHttpClient;
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import retrofit2.Converter;
+import retrofit2.Retrofit;
+import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
+import retrofit2.converter.gson.GsonConverterFactory;
+import retrofit2.http.GET;
+import retrofit2.http.Headers;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Base64;
+
+import static junit.framework.TestCase.*;
+import static org.springframework.test.util.ReflectionTestUtils.setField;
+
+interface TestService {
+ @Headers({
+ "Content-Type:application/json"
+ })
+ @GET("subscriptions")
+ Observable<TestResource> subscriptionsGet();
+}
+
+@XmlRootElement(name = "Subscription")
+@XmlAccessorType(XmlAccessType.FIELD)
+class TestResource {
+ @XmlElement(name = "id")
+ @SerializedName("id")
+ public String id = null;
+}
+
+class GsonCustomConverterFactory extends Converter.Factory {
+ private final Gson gson;
+ private final GsonConverterFactory gsonConverterFactory;
+
+ private GsonCustomConverterFactory(Gson gson) {
+ if (gson == null)
+ throw new NullPointerException("gson == null");
+ this.gson = gson;
+ this.gsonConverterFactory = GsonConverterFactory.create(gson);
+ }
+
+ public static GsonCustomConverterFactory create(Gson gson) {
+ return new GsonCustomConverterFactory(gson);
+ }
+
+ @Override
+ public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
+ if (type.equals(String.class))
+ return new GsonResponseBodyConverterToString<Object>(gson, type);
+ else
+ return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
+ }
+
+ @Override
+ public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
+ return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
+ }
+}
+
+class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T> {
+ private final Gson gson;
+ private final Type type;
+
+ GsonResponseBodyConverterToString(Gson gson, Type type) {
+ this.gson = gson;
+ this.type = type;
+ }
+
+ @Override
+ public T convert(ResponseBody value) throws IOException {
+ String returned = value.string();
+ try {
+ return gson.fromJson(returned, type);
+ } catch (JsonParseException e) {
+ return (T) returned;
+ }
+ }
+}
+
+public class TestCbamSecurityProvider extends TestBase {
+ CbamSecurityProvider securityProvider = new CbamSecurityProvider() {
+ };
+
+ HttpTestServer testServer = new HttpTestServer();
+ String url;
+
+ @Before
+ public void init() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", true);
+ testServer = new HttpTestServer();
+ testServer.start();
+ url = testServer._server.getURI().toString();
+ }
+
+ @After
+ public void testServer() throws Exception {
+ testServer.stop();
+ }
+
+ /**
+ * test skipping certificate and skipping hostname verification
+ */
+ @Test
+ public void testSkipHostAndSkipCertifiacateVerification() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", true);
+ //when
+ TestResource testResource = fireRequest();
+ //verify
+ assertEquals("1234", testResource.id);
+ //when
+ securityProvider.buildTrustManager().checkClientTrusted(null, null);
+ //verify
+ //no security exception is thrown
+ }
+
+ /**
+ * test skipping certificate and doing hostname verification
+ */
+ @Test
+ public void testHostAndSkipCertifiacateVerification() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", false);
+ url = url.replace("127.0.0.1", "localhost");
+ TestResource testResource = fireRequest();
+ assertEquals("1234", testResource.id);
+ }
+
+ /**
+ * test skipping certificate and doing hostname verification
+ * (if hostname is invalid exception is propagated)
+ */
+ @Test
+ public void testHostAndSkipCertifiacateVerificationNegativeCase() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", false);
+ //url = url.replace("127.0.0.1", "localhost");
+ try {
+ fireRequest();
+ fail();
+ } catch (Exception e) {
+ assertEquals(javax.net.ssl.SSLPeerUnverifiedException.class, e.getCause().getClass());
+ assertTrue(e.getCause().getMessage().contains("Hostname 127.0.0.1 not verified"));
+ }
+ }
+
+ /**
+ * test certificate and hostname verification
+ */
+ @Test
+ public void testHostAndCertifiacateVerification() throws Exception {
+ Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
+ String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
+ setField(securityProvider, "trustedCertificates", cert);
+ setField(securityProvider, "skipCertificateVerification", false);
+ setField(securityProvider, "skipHostnameVerification", false);
+ url = url.replace("127.0.0.1", "localhost");
+ TestResource testResource = fireRequest();
+ assertEquals("1234", testResource.id);
+ }
+
+ /**
+ * test certificate and hostname verification
+ * (not trusted certificate)
+ */
+ @Test
+ public void testHostAndCertifiacateVerificationNegative() throws Exception {
+ Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/sample.cert.pem").toURI());
+ String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
+ setField(securityProvider, "trustedCertificates", cert);
+ setField(securityProvider, "skipCertificateVerification", false);
+ setField(securityProvider, "skipHostnameVerification", false);
+ url = url.replace("127.0.0.1", "localhost");
+ try {
+ fireRequest();
+ fail();
+ } catch (Exception e) {
+ assertEquals(javax.net.ssl.SSLHandshakeException.class, e.getCause().getClass());
+ assertTrue(e.getCause().getMessage().contains("unable to find valid certification path to requested target"));
+ }
+ }
+
+ /**
+ * test certificate and hostname verification
+ */
+ @Test
+ public void testSkipHostAndCertifiacateVerification() throws Exception {
+ Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
+ String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
+ setField(securityProvider, "trustedCertificates", cert);
+ setField(securityProvider, "skipCertificateVerification", false);
+ setField(securityProvider, "skipHostnameVerification", true);
+ //url = url.replace("127.0.0.1", "localhost");
+ TestResource testResource = fireRequest();
+ assertEquals("1234", testResource.id);
+ }
+
+ /**
+ * empty trusted pem results in error if verification is required
+ */
+ @Test
+ public void testEmptyTrustStoreWhenCheckingIsRequired() throws Exception {
+ setField(securityProvider, "trustedCertificates", "");
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty", e.getMessage());
+ }
+ }
+
+ /**
+ * invalid PEM results in fast fail error
+ */
+ @Test
+ public void testInvalidPem() throws Exception {
+ setField(securityProvider, "trustedCertificates", "______");
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("The trustedCertificates must be a base64 encoded collection of PEM certificates", e.getMessage());
+ }
+ }
+
+ /**
+ * invalid PEM results in fast fail error
+ */
+ @Test
+ public void testEmptyInvalidPem() throws Exception {
+ setField(securityProvider, "trustedCertificates", "a3VrdQo=");
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("No certificate can be extracted from kuku\n", e.getMessage());
+ }
+ }
+
+ /**
+ * bad certificate content results in fast fail error
+ */
+ @Test
+ public void testEmptyInvalidPemContent() throws Exception {
+ String badCert = "-----BEGIN CERTIFICATE-----\nXXXXXX\n-----END CERTIFICATE-----";
+ setField(securityProvider, "trustedCertificates", Base64.getEncoder().encodeToString(badCert.getBytes()));
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("Unable to create keystore", e.getMessage());
+ }
+ }
+
+ /**
+ * bad certificate content results in fast fail error for SSL socket factory
+ */
+ @Test
+ public void testEmptyInvalidPemContentSSl() throws Exception {
+ String badCert = "-----BEGIN CERTIFICATE-----\nXXXXXX\n-----END CERTIFICATE-----";
+ setField(securityProvider, "trustedCertificates", Base64.getEncoder().encodeToString(badCert.getBytes()));
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildSSLSocketFactory();
+ fail();
+ } catch (Exception e) {
+ assertEquals("Unable to create SSL socket factory", e.getMessage());
+ }
+ }
+
+ private TestResource fireRequest() {
+ OkHttpClient client =
+ new OkHttpClient.Builder()
+ .sslSocketFactory(securityProvider.buildSSLSocketFactory(), securityProvider.buildTrustManager())
+ .hostnameVerifier(securityProvider.buildHostnameVerifier()).build();
+ TestService test1 = new Retrofit.Builder().baseUrl(url).client(client)
+ .addConverterFactory(GsonCustomConverterFactory.create(new JSON().getGson()))
+ .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build().create(TestService.class);
+ testServer.respones.add("{ \"id\" : \"1234\" } ");
+ testServer.codes.add(200);
+ TestService test = test1;
+ return test.subscriptionsGet().blockingFirst();
+ }
+
+}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java
index 4b35f2ff..699a5900 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java
@@ -16,39 +16,19 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
-import com.google.common.io.ByteStreams;
-import org.eclipse.jetty.server.NetworkTrafficServerConnector;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
+import okhttp3.Interceptor;
+import okhttp3.Request;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
import org.onap.vnfmdriver.model.VnfmInfo;
import org.springframework.http.HttpStatus;
-import javax.net.ssl.*;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.security.GeneralSecurityException;
-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;
@@ -56,70 +36,24 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;
-class HttpTestServer {
- Server _server;
- 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();
- }
-
- private void startServer() throws Exception {
- 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 {
- Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.jks").toURI());
- String path = jksPath.normalize().toAbsolutePath().toUri().toString();
- _server = new Server();
- SslContextFactory factory = new SslContextFactory(path);
- factory.setKeyStorePassword("changeit");
- NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(_server, factory);
- connector.setHost("127.0.0.1");
- _server.addConnector(connector);
- _server.setHandler(new AbstractHandler() {
- @Override
- public void handle(String target, org.eclipse.jetty.server.Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
- requests.add(new String(ByteStreams.toByteArray(request.getInputStream())));
- httpServletResponse.getWriter().write(respones.remove(0));
- httpServletResponse.setStatus(codes.remove(0));
- request.setHandled(true);
- }
- });
- }
-
- public void stop() throws Exception {
- _server.stop();
- }
-}
-
public class TestCbamTokenProvider extends TestBase {
private static String GOOD_RESPONSE = "{ \"access_token\" : \"myToken\", \"expires_in\" : 1000 }";
@InjectMocks
private CbamTokenProvider cbamTokenProvider;
private VnfmInfo vnfmInfo = new VnfmInfo();
- private ArgumentCaptor<SSLSocketFactory> sslSocketFactory = ArgumentCaptor.forClass(SSLSocketFactory.class);
- private ArgumentCaptor<HostnameVerifier> hostnameVerifier = ArgumentCaptor.forClass(HostnameVerifier.class);
private HttpTestServer testServer;
+ public static String extractToken(Interceptor token) throws IOException {
+ Interceptor.Chain chain = Mockito.mock(Interceptor.Chain.class);
+ Request request = new Request.Builder().url("http://127.0.0.0/").build();
+ when(chain.request()).thenReturn(request);
+ ArgumentCaptor<Request> re = ArgumentCaptor.forClass(Request.class);
+ when(chain.proceed(re.capture())).thenReturn(null);
+ token.intercept(chain);
+ return re.getValue().header("Authorization").replaceFirst("Bearer ", "");
+ }
+
@Before
public void initMocks() throws Exception {
setField(CbamTokenProvider.class, "logger", logger);
@@ -135,8 +69,6 @@ public class TestCbamTokenProvider extends TestBase {
testServer.start();
URI uri = testServer._server.getURI();
setField(cbamTokenProvider, "cbamKeyCloakBaseUrl", uri.toString());
-
-
}
private void addGoodTokenResponse() {
@@ -157,7 +89,7 @@ public class TestCbamTokenProvider extends TestBase {
//given
addGoodTokenResponse();
//when
- String token = cbamTokenProvider.getToken(VNFM_ID);
+ String token = extractToken(cbamTokenProvider.getToken(VNFM_ID));
//verify
assertEquals(1, testServer.requests.size());
assertTokenRequest(testServer.requests.get(0));
@@ -172,12 +104,12 @@ public class TestCbamTokenProvider extends TestBase {
public void testTokenIsRequestedIfPreviousExpired() throws Exception {
//given
addGoodTokenResponse();
- String firstToken = cbamTokenProvider.getToken(VNFM_ID);
+ String firstToken = extractToken(cbamTokenProvider.getToken(VNFM_ID));
testServer.respones.add("{ \"access_token\" : \"myToken2\", \"expires_in\" : 2000 }");
testServer.codes.add(HttpStatus.OK.value());
when(systemFunctions.currentTimeMillis()).thenReturn(500L * 1000 + 1L);
//when
- String token = cbamTokenProvider.getToken(VNFM_ID);
+ String token = extractToken(cbamTokenProvider.getToken(VNFM_ID));
//verify
assertEquals(2, testServer.requests.size());
assertTokenRequest(testServer.requests.get(0));
@@ -192,12 +124,12 @@ public class TestCbamTokenProvider extends TestBase {
public void testTokenIsNotRequestedIfPreviousHasNotExpired() throws Exception {
//given
addGoodTokenResponse();
- String firstToken = cbamTokenProvider.getToken(VNFM_ID);
+ String firstToken = extractToken(cbamTokenProvider.getToken(VNFM_ID));
testServer.respones.add("{ \"access_token\" : \"myToken2\", \"expires_in\" : 2000 }");
testServer.codes.add(HttpStatus.OK.value());
when(systemFunctions.currentTimeMillis()).thenReturn(500L * 1000);
//when
- String token = cbamTokenProvider.getToken(VNFM_ID);
+ String token = extractToken(cbamTokenProvider.getToken(VNFM_ID));
//verify
assertEquals(1, testServer.requests.size());
assertTokenRequest(testServer.requests.get(0));
@@ -217,7 +149,7 @@ public class TestCbamTokenProvider extends TestBase {
addGoodTokenResponse();
//cbamTokenProvider.failOnRequestNumber = 5;
//when
- String token = cbamTokenProvider.getToken(VNFM_ID);
+ String token = extractToken(cbamTokenProvider.getToken(VNFM_ID));
//verify
assertEquals(5, testServer.requests.size());
assertTokenRequest(testServer.requests.get(0));
@@ -269,174 +201,6 @@ public class TestCbamTokenProvider extends TestBase {
testServer.respones.add(new String());
}
- /**
- * the SSL connection is established without certificate & hostname verification
- */
- @Test
- public void noSslVerification() throws Exception {
- //given
- //the default settings is no SSL & hostname check
- addGoodTokenResponse();
- //when
- cbamTokenProvider.getToken(VNFM_ID);
- //verify
- //no exception is thrown
- }
-
- /**
- * if SSL is verified the certificates must be defined
- */
- @Test
- public void testInvalidCombinationOfSettings() throws Exception {
- //given
- setField(cbamTokenProvider, "skipCertificateVerification", false);
- //when
- try {
- cbamTokenProvider.getToken(VNFM_ID);
- //verify
- fail();
- } catch (RuntimeException e) {
- assertEquals("If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty", e.getMessage());
- }
- }
-
- /**
- * if SSL is verified the certificates must be defined
- */
- @Test
- public void testInvalidCombinationOfSettings2() throws Exception {
- //given
- setField(cbamTokenProvider, "skipCertificateVerification", false);
- setField(cbamTokenProvider, "trustedCertificates", "xx\nxx");
- //when
- try {
- cbamTokenProvider.getToken(VNFM_ID);
- //verify
- fail();
- } catch (RuntimeException e) {
- assertEquals("The trustedCertificates must be a base64 encoded collection of PEM certificates", e.getMessage());
- assertNotNull(e.getCause());
- }
- }
-
- /**
- * the SSL connection is established without certificate & hostname verification
- */
- @Test
- public void testNotTrustedSslConnection() throws Exception {
- //given
- setField(cbamTokenProvider, "skipCertificateVerification", false);
- Path caPem = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/sample.cert.pem").toURI());
- setField(cbamTokenProvider, "trustedCertificates", Base64.getEncoder().encodeToString(Files.readAllBytes(caPem)));
- addGoodTokenResponse();
- //when
- try {
- cbamTokenProvider.getToken(VNFM_ID);
- //verify
- fail();
- } catch (RuntimeException e) {
- assertTrue(e.getCause().getCause().getMessage().contains("unable to find valid certification path"));
- assertTrue(e.getCause() instanceof SSLHandshakeException);
- }
- }
-
- /**
- * the SSL connection is established with certificate & hostname verification
- */
- @Test
- public void testHostnameVerificationSucceeds() throws Exception {
- //given
- setField(cbamTokenProvider, "skipCertificateVerification", false);
- Path caPem = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
- setField(cbamTokenProvider, "trustedCertificates", Base64.getEncoder().encodeToString(Files.readAllBytes(caPem)));
- setField(cbamTokenProvider, "cbamKeyCloakBaseUrl", testServer._server.getURI().toString().replace("127.0.0.1", "localhost"));
- setField(cbamTokenProvider, "skipHostnameVerification", false);
- addGoodTokenResponse();
- //when
- cbamTokenProvider.getToken(VNFM_ID);
- //verify
- //no seception is thrown
- }
-
- /**
- * the SSL connection is dropped with certificate & hostname verification due to invalid hostname
- */
- @Test
- public void testHostnameverifcationfail() throws Exception {
- //given
- setField(cbamTokenProvider, "skipCertificateVerification", false);
- Path caPem = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
- setField(cbamTokenProvider, "trustedCertificates", Base64.getEncoder().encodeToString(Files.readAllBytes(caPem)));
- setField(cbamTokenProvider, "skipHostnameVerification", false);
- addGoodTokenResponse();
- //when
- try {
- cbamTokenProvider.getToken(VNFM_ID);
- //verify
- fail();
- } catch (RuntimeException e) {
- assertTrue(e.getCause().getMessage().contains("Hostname 127.0.0.1 not verified"));
- assertTrue(e.getCause() instanceof SSLPeerUnverifiedException);
- }
- }
-
- /**
- * invalid certificate content
- */
- @Test
- public void testInvalidCerificateContent() throws Exception {
- //given
- setField(cbamTokenProvider, "skipCertificateVerification", false);
- setField(cbamTokenProvider, "trustedCertificates", Base64.getEncoder().encodeToString("-----BEGIN CERTIFICATE-----\nkuku\n-----END CERTIFICATE-----\n".getBytes()));
- setField(cbamTokenProvider, "skipHostnameVerification", false);
- addGoodTokenResponse();
- //when
- try {
- cbamTokenProvider.getToken(VNFM_ID);
- //verify
- fail();
- } catch (RuntimeException e) {
- assertEquals("Unable to load certificates", e.getMessage());
- assertTrue(e.getCause() instanceof GeneralSecurityException);
- }
- }
-
- /**
- * Verify client certificates are not verified
- * \
- */
- @Test
- public void testClientCertificates() throws Exception {
- //when
- new CbamTokenProvider.AllTrustedTrustManager().checkClientTrusted(null, null);
- //verify
- //no security exception is thrown
- }
-
- /**
- * Exception during keystore creation is logged (semi-useless)
- */
- @Test
- public void testKeystoreCreationFailure() {
- KeyStoreException expectedException = new KeyStoreException();
- class X extends CbamTokenProvider {
- X(VnfmInfoProvider vnfmInfoProvider) {
- super(vnfmInfoProvider);
- }
-
- @Override
- TrustManager[] buildTrustManager() throws KeyStoreException {
- throw expectedException;
- }
- }
- try {
- new X(null).buildSSLSocketFactory();
- fail();
- } catch (RuntimeException e) {
- assertEquals(expectedException, e.getCause());
- verify(logger).error("Unable to create SSL socket factory", expectedException);
- }
- }
private void assertTokenRequest(String body) {
assertContains(body, "grant_type", "password");
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
index 4b59eeb3..ee206537 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
@@ -18,8 +18,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.model.*;
+import io.reactivex.Observable;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -62,7 +62,7 @@ public class TestJobManager extends TestBase {
@Before
public void initMocks() throws Exception {
ReflectionTestUtils.setField(JobManager.class, "logger", logger);
- when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenReturn(vnfs);
+ when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfs));
when(selfRegistrationManager.isReady()).thenReturn(true);
}
@@ -179,7 +179,7 @@ public class TestJobManager extends TestBase {
vnfs.add(vnf);
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
//verify
assertResult(jobId, job, STARTED, "50", "Operation started");
@@ -198,7 +198,7 @@ public class TestJobManager extends TestBase {
vnfs.add(vnf);
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
jobManager.jobFinished(jobId);
JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
//verify
@@ -218,7 +218,7 @@ public class TestJobManager extends TestBase {
vnfs.add(vnf);
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
OperationExecution operation = new OperationExecution();
operation.setId(UUID.randomUUID().toString());
operation.setStartTime(OffsetDateTime.now());
@@ -226,7 +226,7 @@ public class TestJobManager extends TestBase {
detailedVnf.setOperationExecutions(new ArrayList<>());
detailedVnf.getOperationExecutions().add(operation);
JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationParams);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationParams));
JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
//verify
assertResult(jobId, job, STARTED, "50", "Operation started");
@@ -246,11 +246,11 @@ public class TestJobManager extends TestBase {
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
List<Integer> vnfQueryCallCounter = new ArrayList<>();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(new Answer<VnfInfo>() {
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(new Answer<Observable<VnfInfo>>() {
@Override
- public VnfInfo answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<VnfInfo> answer(InvocationOnMock invocation) throws Throwable {
vnfs.clear();
- return detailedVnf;
+ return buildObservable(detailedVnf);
}
});
@@ -265,7 +265,7 @@ public class TestJobManager extends TestBase {
detailedVnf.getOperationExecutions().add(operation);
JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationParams);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationParams));
//when
JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
//verify
@@ -285,7 +285,7 @@ public class TestJobManager extends TestBase {
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
List<Integer> vnfCounter = new ArrayList<>();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
OperationExecution operation = new OperationExecution();
operation.setId(UUID.randomUUID().toString());
operation.setStartTime(OffsetDateTime.now());
@@ -297,7 +297,7 @@ public class TestJobManager extends TestBase {
detailedVnf.setOperationExecutions(new ArrayList<>());
detailedVnf.getOperationExecutions().add(operation);
JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationParams);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationParams));
//when
JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
//verify
@@ -350,7 +350,7 @@ public class TestJobManager extends TestBase {
vnfs.add(vnf);
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
OperationExecution operation = new OperationExecution();
operation.setId(UUID.randomUUID().toString());
operation.setStartTime(OffsetDateTime.now());
@@ -359,7 +359,7 @@ public class TestJobManager extends TestBase {
detailedVnf.setOperationExecutions(new ArrayList<>());
detailedVnf.getOperationExecutions().add(operation);
JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationParams);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationParams));
JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
//verify
assertResult(jobId, job, JobStatus.FINISHED, "100", "Operation finished");
@@ -379,7 +379,7 @@ public class TestJobManager extends TestBase {
vnfs.add(vnf);
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
OperationExecution operation = new OperationExecution();
operation.setId(UUID.randomUUID().toString());
operation.setStartTime(OffsetDateTime.now());
@@ -388,7 +388,7 @@ public class TestJobManager extends TestBase {
detailedVnf.setOperationExecutions(new ArrayList<>());
detailedVnf.getOperationExecutions().add(operation);
JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationParams);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationParams));
JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
//verify
assertResult(jobId, job, STARTED, "50", "Operation started");
@@ -412,12 +412,12 @@ public class TestJobManager extends TestBase {
vnfs.add(vnf);
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
OperationExecution operation = new OperationExecution();
operation.setId(UUID.randomUUID().toString());
detailedVnf.setOperationExecutions(new ArrayList<>());
detailedVnf.getOperationExecutions().add(operation);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operation.getId(), NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//verify
try {
@@ -439,7 +439,7 @@ public class TestJobManager extends TestBase {
VnfInfo vnf = new VnfInfo();
vnf.setId(VNF_ID);
vnfs.add(vnf);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//verify
try {
@@ -464,7 +464,7 @@ public class TestJobManager extends TestBase {
vnfs.add(vnf);
VnfInfo detailedVnf = new VnfInfo();
detailedVnf.setId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(detailedVnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
OperationExecution olderOperation = new OperationExecution();
olderOperation.setId(UUID.randomUUID().toString());
olderOperation.setStartTime(OffsetDateTime.now());
@@ -481,14 +481,14 @@ public class TestJobManager extends TestBase {
JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
List<String> queriedOperaionsInOrder = new ArrayList<>();
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(Mockito.anyString(), Mockito.eq(NOKIA_LCM_API_VERSION)))
- .then(new Answer<Object>() {
+ .then(new Answer<Observable<Object>>() {
@Override
- public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
+ public Observable<Object> answer(InvocationOnMock invocationOnMock) throws Throwable {
queriedOperaionsInOrder.add(invocationOnMock.getArguments()[0].toString());
if (invocationOnMock.getArguments()[0].equals(olderOperation.getId())) {
- return new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
+ return buildObservable(new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}"));
} else {
- return new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + "nonMatching" + "\"}}");
+ return buildObservable(new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + "nonMatching" + "\"}}"));
}
}
});
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
index c6e76ef6..1a622151 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
@@ -20,11 +20,11 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.model.*;
import com.nokia.cbam.lcm.v32.model.OperationType;
import com.nokia.cbam.lcm.v32.model.VimInfo;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
+import io.reactivex.Observable;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -128,7 +128,7 @@ public class TestLifecycleManager extends TestBase {
instantiationOperationExecution.setId(OPERATION_EXECUTION_ID);
instantiationOperationExecution.setOperationType(OperationType.INSTANTIATE);
instantiationOperationExecution.setStartTime(OffsetDateTime.now());
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(operationExecutions);
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecutions));
operationExecutions.add(modifyPropertyoperationExecution);
modifyPropertyoperationExecution.setStartTime(OffsetDateTime.now());
modifyPropertyoperationExecution.setOperationType(OperationType.MODIFY_INFO);
@@ -138,7 +138,7 @@ public class TestLifecycleManager extends TestBase {
modifyPropertyoperationExecution.setId(UUID.randomUUID().toString());
scaleOperationExecution.setId(UUID.randomUUID().toString());
healOperationExecution.setId(UUID.randomUUID().toString());
- when(vnfApi.vnfsVnfInstanceIdPatch(eq(VNF_ID), actualVnfModifyRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(modifyPropertyoperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdPatch(eq(VNF_ID), actualVnfModifyRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(modifyPropertyoperationExecution));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
@@ -146,18 +146,18 @@ public class TestLifecycleManager extends TestBase {
return null;
}
}).when(jobManager).jobFinished(JOB_ID);
- when(vnfApi.vnfsVnfInstanceIdScalePost(eq(VNF_ID), actualScaleRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
+ when(vnfApi.vnfsVnfInstanceIdScalePost(eq(VNF_ID), actualScaleRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<Observable<OperationExecution>>() {
@Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
operationExecutions.add(scaleOperationExecution);
- return scaleOperationExecution;
+ return buildObservable(scaleOperationExecution);
}
});
- when(vnfApi.vnfsVnfInstanceIdHealPost(eq(VNF_ID), actualHealRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
+ when(vnfApi.vnfsVnfInstanceIdHealPost(eq(VNF_ID), actualHealRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<Observable<OperationExecution>>() {
@Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
operationExecutions.add(healOperationExecution);
- return healOperationExecution;
+ return buildObservable(healOperationExecution);
}
});
}
@@ -170,7 +170,7 @@ public class TestLifecycleManager extends TestBase {
//given
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -178,7 +178,7 @@ public class TestLifecycleManager extends TestBase {
accessInfo.setTenant(TENANT);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -264,7 +264,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationWithInvalidVimType() throws Exception {
//given
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OTHER_VIM_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
when(logger.isInfoEnabled()).thenReturn(false);
//when
try {
@@ -287,7 +287,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationV2WithSsl() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -298,7 +298,7 @@ public class TestLifecycleManager extends TestBase {
vimInfo.setSslCacert(caCert);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
JsonObject inputs = child((JsonObject) instantiationRequest.getAdditionalParam(), "inputs");
JsonObject vnfs = child(child(inputs, "vnfs"), ONAP_CSAR_ID);
vnfs.remove("additionalParams");
@@ -321,7 +321,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationV2WithoutSsl() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -330,7 +330,7 @@ public class TestLifecycleManager extends TestBase {
vimInfo.setSslInsecure(null);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -348,7 +348,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationV3() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -356,7 +356,7 @@ public class TestLifecycleManager extends TestBase {
accessInfo.setTenant(TENANT);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -384,7 +384,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationV3WithSsl() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -395,7 +395,7 @@ public class TestLifecycleManager extends TestBase {
vimInfo.setSslCacert(caCert);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -424,7 +424,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationV3WithNonSpecifiedSsl() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -433,7 +433,7 @@ public class TestLifecycleManager extends TestBase {
vimInfo.setSslInsecure(null);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -460,7 +460,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationVcloud() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -468,7 +468,7 @@ public class TestLifecycleManager extends TestBase {
accessInfo.setTenant(TENANT);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -494,7 +494,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationVcloudWithSsl() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -505,7 +505,7 @@ public class TestLifecycleManager extends TestBase {
vimInfo.setSslCacert(caCert);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -532,7 +532,7 @@ public class TestLifecycleManager extends TestBase {
public void testInstantiationVcloudWithNonSecifedSSl() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -541,7 +541,7 @@ public class TestLifecycleManager extends TestBase {
vimInfo.setSslInsecure(null);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -565,7 +565,7 @@ public class TestLifecycleManager extends TestBase {
@Test
public void testFailureInTheInstantiationRequest() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -573,7 +573,7 @@ public class TestLifecycleManager extends TestBase {
accessInfo.setTenant(TENANT);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenThrow(expectedException);
//when
@@ -592,7 +592,7 @@ public class TestLifecycleManager extends TestBase {
public void testVfcFailsToSendVimId() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
//grantResponse.setVimId(VIM_ID);
@@ -603,7 +603,7 @@ public class TestLifecycleManager extends TestBase {
vimInfo.setSslCacert(caCert);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -619,7 +619,7 @@ public class TestLifecycleManager extends TestBase {
@Test
public void testFailureInTheOperationExecutionPollingDuringInstantiationRequest() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@@ -627,18 +627,17 @@ public class TestLifecycleManager extends TestBase {
accessInfo.setTenant(TENANT);
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
- ApiException expectedException = new ApiException();
- List<ApiException> polling = new ArrayList<>();
- when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).then(new Answer<List<OperationExecution>>() {
+ List<RuntimeException> polling = new ArrayList<>();
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).then(new Answer<Observable<List<OperationExecution>>>() {
@Override
- public List<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<List<OperationExecution>> answer(InvocationOnMock invocation) throws Throwable {
if (polling.size() > 2) {
- return operationExecutions;
+ return buildObservable(operationExecutions);
}
- ApiException apiException = new ApiException();
- polling.add(apiException);
- throw apiException;
+ RuntimeException runtimeException = new RuntimeException();
+ polling.add(runtimeException);
+ throw runtimeException;
}
});
//when
@@ -648,7 +647,7 @@ public class TestLifecycleManager extends TestBase {
assertEquals(VNF_ID, response.getVnfInstanceId());
assertEquals(JOB_ID, response.getJobId());
assertEquals(3, polling.size());
- for (ApiException e : polling) {
+ for (RuntimeException e : polling) {
verify(logger).warn("Unable to retrieve operations details", e);
}
verify(systemFunctions, Mockito.times(3)).sleep(5000);
@@ -662,7 +661,7 @@ public class TestLifecycleManager extends TestBase {
//given
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenThrow(expectedException);
//when
try {
@@ -683,8 +682,8 @@ public class TestLifecycleManager extends TestBase {
//given
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- ApiException expectedException = new ApiException();
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ RuntimeException expectedException = new RuntimeException();
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
when(vnfApi.vnfsVnfInstanceIdPatch(eq(VNF_ID), actualVnfModifyRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenThrow(expectedException);
//when
@@ -705,7 +704,7 @@ public class TestLifecycleManager extends TestBase {
@Test
public void testFailureInQueryVimInfo() throws Exception {
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
- when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
GrantVNFResponseVimAccessInfo accessInfo = new GrantVNFResponseVimAccessInfo();
@@ -728,7 +727,7 @@ public class TestLifecycleManager extends TestBase {
public void testTermination() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
vnfInfo.setInstantiationState(InstantiationState.INSTANTIATED);
vnfInfo.setOperationExecutions(operationExecutions);
VnfProperty vnfdId = new VnfProperty();
@@ -736,18 +735,18 @@ public class TestLifecycleManager extends TestBase {
vnfdId.setValue(ONAP_CSAR_ID);
vnfInfo.getExtensions().add(vnfdId);
ArgumentCaptor<TerminateVnfRequest> actualTerminationRequest = ArgumentCaptor.forClass(TerminateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
+ when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<Observable<OperationExecution>>() {
@Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
OperationExecution terminationOperation = new OperationExecution();
terminationOperation.setId("terminationId");
operationExecutions.add(terminationOperation);
terminationOperation.setStatus(OperationStatus.FINISHED);
- return terminationOperation;
+ return buildObservable(terminationOperation);
}
});
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
@@ -770,7 +769,7 @@ public class TestLifecycleManager extends TestBase {
public void testTerminationOfNonInstantiated() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
vnfInfo.setInstantiationState(InstantiationState.NOT_INSTANTIATED);
vnfInfo.setOperationExecutions(operationExecutions);
VnfProperty vnfdId = new VnfProperty();
@@ -778,7 +777,7 @@ public class TestLifecycleManager extends TestBase {
vnfdId.setValue(ONAP_CSAR_ID);
vnfInfo.getExtensions().add(vnfdId);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
@@ -802,7 +801,7 @@ public class TestLifecycleManager extends TestBase {
public void testTerminationOperationIsOutwaited() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
vnfInfo.setInstantiationState(InstantiationState.INSTANTIATED);
vnfInfo.setOperationExecutions(operationExecutions);
VnfProperty vnfdId = new VnfProperty();
@@ -811,27 +810,21 @@ public class TestLifecycleManager extends TestBase {
vnfInfo.getExtensions().add(vnfdId);
ArgumentCaptor<TerminateVnfRequest> actualTerminationRequest = ArgumentCaptor.forClass(TerminateVnfRequest.class);
OperationExecution terminationOperation = new OperationExecution();
- when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
- @Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
- terminationOperation.setId("terminationId");
- operationExecutions.add(terminationOperation);
- terminationOperation.setStatus(OperationStatus.STARTED);
- return terminationOperation;
- }
+ when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(invocation -> {
+ terminationOperation.setId("terminationId");
+ operationExecutions.add(terminationOperation);
+ terminationOperation.setStatus(OperationStatus.STARTED);
+ return buildObservable(terminationOperation);
});
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
Set<Integer> calls = new HashSet<>();
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(new Answer<List<OperationExecution>>() {
- @Override
- public List<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
- if (calls.size() == 1000) {
- terminationOperation.setStatus(OperationStatus.FINISHED);
- }
- calls.add(calls.size());
- return operationExecutions;
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(invocation -> {
+ if (calls.size() == 1000) {
+ terminationOperation.setStatus(OperationStatus.FINISHED);
}
+ calls.add(calls.size());
+ return buildObservable(operationExecutions);
});
//when
JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
@@ -849,7 +842,7 @@ public class TestLifecycleManager extends TestBase {
public void testTerminationOperationIsOutwaitedWithErrors() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
vnfInfo.setInstantiationState(InstantiationState.INSTANTIATED);
vnfInfo.setOperationExecutions(operationExecutions);
VnfProperty vnfdId = new VnfProperty();
@@ -858,30 +851,30 @@ public class TestLifecycleManager extends TestBase {
vnfInfo.getExtensions().add(vnfdId);
ArgumentCaptor<TerminateVnfRequest> actualTerminationRequest = ArgumentCaptor.forClass(TerminateVnfRequest.class);
OperationExecution terminationOperation = new OperationExecution();
- when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
+ when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<Observable<OperationExecution>>() {
@Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
terminationOperation.setId("terminationId");
operationExecutions.add(terminationOperation);
terminationOperation.setStatus(OperationStatus.STARTED);
- return terminationOperation;
+ return buildObservable(terminationOperation);
}
});
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
Set<Integer> calls = new HashSet<>();
- List<ApiException> expectedExceptions = new ArrayList<>();
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(new Answer<List<OperationExecution>>() {
+ List<RuntimeException> expectedExceptions = new ArrayList<>();
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(new Answer<Observable<List<OperationExecution>>>() {
@Override
- public List<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<List<OperationExecution>> answer(InvocationOnMock invocation) throws Throwable {
if (calls.size() >= 100) {
terminationOperation.setStatus(OperationStatus.FINISHED);
- return operationExecutions;
+ return buildObservable(operationExecutions);
}
calls.add(calls.size());
- ApiException apiException = new ApiException();
- expectedExceptions.add(apiException);
- throw apiException;
+ RuntimeException RuntimeException = new RuntimeException();
+ expectedExceptions.add(RuntimeException);
+ throw RuntimeException;
}
});
//when
@@ -890,7 +883,7 @@ public class TestLifecycleManager extends TestBase {
waitForJobToFinishInJobManager(finished);
verify(vnfApi, times(101)).vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION);
verify(systemFunctions, times(100)).sleep(5000);
- for (ApiException expectedException : expectedExceptions) {
+ for (RuntimeException expectedException : expectedExceptions) {
verify(logger).warn("Unable to retrieve operations details", expectedException);
}
}
@@ -902,7 +895,7 @@ public class TestLifecycleManager extends TestBase {
public void testGracefullTermination() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
terminationRequest.setTerminationType(VnfTerminationType.GRACEFUL);
terminationRequest.setGracefulTerminationTimeout("1234");
vnfInfo.setInstantiationState(InstantiationState.INSTANTIATED);
@@ -912,14 +905,14 @@ public class TestLifecycleManager extends TestBase {
vnfdId.setValue(ONAP_CSAR_ID);
vnfInfo.getExtensions().add(vnfdId);
ArgumentCaptor<TerminateVnfRequest> actualTerminationRequest = ArgumentCaptor.forClass(TerminateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
+ when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<Observable<OperationExecution>>() {
@Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
OperationExecution terminationOperation = new OperationExecution();
terminationOperation.setId("terminationId");
operationExecutions.add(terminationOperation);
terminationOperation.setStatus(OperationStatus.FINISHED);
- return terminationOperation;
+ return buildObservable(terminationOperation);
}
});
doAnswer(invocation -> {
@@ -927,7 +920,7 @@ public class TestLifecycleManager extends TestBase {
return null;
}).when(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
@@ -967,7 +960,7 @@ public class TestLifecycleManager extends TestBase {
public void testExplicitForcefulTermination() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
terminationRequest.setTerminationType(VnfTerminationType.FORCEFUL);
terminationRequest.setGracefulTerminationTimeout("1234");
vnfInfo.setInstantiationState(InstantiationState.INSTANTIATED);
@@ -977,22 +970,19 @@ public class TestLifecycleManager extends TestBase {
vnfdId.setValue(ONAP_CSAR_ID);
vnfInfo.getExtensions().add(vnfdId);
ArgumentCaptor<TerminateVnfRequest> actualTerminationRequest = ArgumentCaptor.forClass(TerminateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
- @Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
- OperationExecution terminationOperation = new OperationExecution();
- terminationOperation.setId("terminationId");
- operationExecutions.add(terminationOperation);
- terminationOperation.setStatus(OperationStatus.FINISHED);
- return terminationOperation;
- }
+ when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(invocation -> {
+ OperationExecution terminationOperation = new OperationExecution();
+ terminationOperation.setId("terminationId");
+ operationExecutions.add(terminationOperation);
+ terminationOperation.setStatus(OperationStatus.FINISHED);
+ return buildObservable(terminationOperation);
});
doAnswer(invocation -> {
verify(jobManager, Mockito.never()).jobFinished(JOB_ID);
return null;
}).when(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
@@ -1013,7 +1003,7 @@ public class TestLifecycleManager extends TestBase {
public void testFailureInTheTerminationFinishesTheManagedJob() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
terminationRequest.setTerminationType(VnfTerminationType.FORCEFUL);
terminationRequest.setGracefulTerminationTimeout("1234");
vnfInfo.setInstantiationState(InstantiationState.INSTANTIATED);
@@ -1033,10 +1023,10 @@ public class TestLifecycleManager extends TestBase {
return terminationOperation;
}
});
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
@@ -1052,7 +1042,7 @@ public class TestLifecycleManager extends TestBase {
public void testFailedTerminationAbortsTerminationWorkflow() throws Exception {
//given
VnfTerminateRequest terminationRequest = new VnfTerminateRequest();
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
vnfInfo.setInstantiationState(InstantiationState.INSTANTIATED);
vnfInfo.setOperationExecutions(operationExecutions);
VnfProperty vnfdId = new VnfProperty();
@@ -1060,18 +1050,18 @@ public class TestLifecycleManager extends TestBase {
vnfdId.setValue(ONAP_CSAR_ID);
vnfInfo.getExtensions().add(vnfdId);
ArgumentCaptor<TerminateVnfRequest> actualTerminationRequest = ArgumentCaptor.forClass(TerminateVnfRequest.class);
- when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<OperationExecution>() {
+ when(vnfApi.vnfsVnfInstanceIdTerminatePost(eq(VNF_ID), actualTerminationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenAnswer(new Answer<Observable<OperationExecution>>() {
@Override
- public OperationExecution answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
OperationExecution terminationOperation = new OperationExecution();
terminationOperation.setId("terminationId");
operationExecutions.add(terminationOperation);
terminationOperation.setStatus(OperationStatus.FAILED);
- return terminationOperation;
+ return buildObservable(terminationOperation);
}
});
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(instantiationParameters);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
@@ -1092,7 +1082,7 @@ public class TestLifecycleManager extends TestBase {
vnfInfo.setName("myName");
vnfInfo.setVnfSoftwareVersion("vnfSoftwareVersion");
vnfInfo.setVnfProvider("myProvider");
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
VnfProperty prop = new VnfProperty();
prop.setName(LifecycleManager.ONAP_CSAR_ID);
prop.setValue(ONAP_CSAR_ID);
@@ -1119,7 +1109,7 @@ public class TestLifecycleManager extends TestBase {
@Test
public void testQueryForNonExistingVnf() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
@@ -1143,14 +1133,14 @@ public class TestLifecycleManager extends TestBase {
scaleRequest.setType(ScaleDirection.IN);
scaleRequest.setAdditionalParam(new JsonParser().parse("{ \"a\" : \"b\", \"c\" : \"d\" }"));
scaleOperationExecution.setStatus(OperationStatus.FINISHED);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
VnfProperty prop = new VnfProperty();
prop.setValue(ONAP_CSAR_ID);
prop.setName(LifecycleManager.ONAP_CSAR_ID);
vnfInfo.getExtensions().add(prop);
vnfInfo.getOperationExecutions().add(instantiationOperationExecution);
String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams));
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new JsonParser().parse(instantiationParams)));
//when
JobInfo job = lifecycleManager.scaleVnf(VNFM_ID, VNF_ID, scaleRequest, restResponse);
//verify
@@ -1180,14 +1170,14 @@ public class TestLifecycleManager extends TestBase {
scaleRequest.setType(ScaleDirection.IN);
scaleRequest.setAdditionalParam(null);
scaleOperationExecution.setStatus(OperationStatus.FINISHED);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
VnfProperty prop = new VnfProperty();
prop.setValue(ONAP_CSAR_ID);
prop.setName(LifecycleManager.ONAP_CSAR_ID);
vnfInfo.getExtensions().add(prop);
vnfInfo.getOperationExecutions().add(instantiationOperationExecution);
String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams));
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new JsonParser().parse(instantiationParams)));
//when
JobInfo job = lifecycleManager.scaleVnf(VNFM_ID, VNF_ID, scaleRequest, restResponse);
//verify
@@ -1215,14 +1205,14 @@ public class TestLifecycleManager extends TestBase {
scaleRequest.setType(ScaleDirection.OUT);
scaleRequest.setAdditionalParam(new JsonParser().parse("{ \"a\" : \"b\" }"));
scaleOperationExecution.setStatus(OperationStatus.FINISHED);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
VnfProperty prop = new VnfProperty();
prop.setValue(ONAP_CSAR_ID);
prop.setName(LifecycleManager.ONAP_CSAR_ID);
vnfInfo.getExtensions().add(prop);
vnfInfo.getOperationExecutions().add(instantiationOperationExecution);
String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams));
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new JsonParser().parse(instantiationParams)));
//when
JobInfo job = lifecycleManager.scaleVnf(VNFM_ID, VNF_ID, scaleRequest, restResponse);
//verify
@@ -1249,24 +1239,24 @@ public class TestLifecycleManager extends TestBase {
scaleRequest.setType(ScaleDirection.IN);
scaleRequest.setAdditionalParam(new JsonParser().parse("{ \"a\" : \"b\" }"));
scaleOperationExecution.setStatus(OperationStatus.STARTED);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
VnfProperty prop = new VnfProperty();
prop.setValue(ONAP_CSAR_ID);
prop.setName(LifecycleManager.ONAP_CSAR_ID);
vnfInfo.getExtensions().add(prop);
vnfInfo.getOperationExecutions().add(instantiationOperationExecution);
String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams));
- List<ApiException> expectedExceptions = new ArrayList<>();
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer((Answer<List<OperationExecution>>) invocation -> {
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new JsonParser().parse(instantiationParams)));
+ List<RuntimeException> expectedExceptions = new ArrayList<>();
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer((Answer<Observable<List<OperationExecution>>>) invocation -> {
if (expectedExceptions.size() >= 100) {
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(scaleOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(scaleOperationExecution));
scaleOperationExecution.setStatus(OperationStatus.FINISHED);
- return operationExecutions;
+ return buildObservable(operationExecutions);
}
- ApiException apiException = new ApiException();
- expectedExceptions.add(apiException);
- // when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(scaleOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(scaleOperationExecution);
- throw apiException;
+ RuntimeException RuntimeException = new RuntimeException();
+ expectedExceptions.add(RuntimeException);
+ throw RuntimeException;
});
//when
@@ -1274,7 +1264,7 @@ public class TestLifecycleManager extends TestBase {
//verify
waitForJobToFinishInJobManager(finished);
assertEquals(100, expectedExceptions.size());
- for (ApiException expectedException : expectedExceptions) {
+ for (RuntimeException expectedException : expectedExceptions) {
verify(logger).warn("Unable to retrieve operations details", expectedException);
}
verify(systemFunctions, times(100)).sleep(5000);
@@ -1285,7 +1275,7 @@ public class TestLifecycleManager extends TestBase {
*/
@Test
public void testScaleFailurePropagation() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
VnfScaleRequest scaleRequest = new VnfScaleRequest();
scaleRequest.setNumberOfSteps("2");
scaleRequest.setAspectId("myAspect");
@@ -1309,14 +1299,14 @@ public class TestLifecycleManager extends TestBase {
affectedVm.setVmname("vmName");
healRequest.setAffectedvm(affectedVm);
healOperationExecution.setStatus(OperationStatus.FINISHED);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
VnfProperty prop = new VnfProperty();
prop.setValue(ONAP_CSAR_ID);
prop.setName(LifecycleManager.ONAP_CSAR_ID);
vnfInfo.getExtensions().add(prop);
vnfInfo.getOperationExecutions().add(instantiationOperationExecution);
String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams));
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new JsonParser().parse(instantiationParams)));
//when
JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(), restResponse);
//verify
@@ -1345,33 +1335,33 @@ public class TestLifecycleManager extends TestBase {
affectedVm.setVmname("vmName");
healRequest.setAffectedvm(affectedVm);
healOperationExecution.setStatus(OperationStatus.FINISHED);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
VnfProperty prop = new VnfProperty();
prop.setValue(ONAP_CSAR_ID);
prop.setName(LifecycleManager.ONAP_CSAR_ID);
vnfInfo.getExtensions().add(prop);
vnfInfo.getOperationExecutions().add(instantiationOperationExecution);
String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams));
- List<ApiException> expectedExceptions = new ArrayList<>();
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(new Answer<List<OperationExecution>>() {
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new JsonParser().parse(instantiationParams)));
+ List<RuntimeException> expectedExceptions = new ArrayList<>();
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenAnswer(new Answer<Observable<List<OperationExecution>>>() {
@Override
- public List<OperationExecution> answer(InvocationOnMock invocation) throws Throwable {
+ public Observable<List<OperationExecution>> answer(InvocationOnMock invocation) throws Throwable {
if (expectedExceptions.size() >= 100) {
scaleOperationExecution.setStatus(OperationStatus.FINISHED);
- return operationExecutions;
+ return buildObservable(operationExecutions);
}
- ApiException apiException = new ApiException();
- expectedExceptions.add(apiException);
- throw apiException;
+ RuntimeException RuntimeException = new RuntimeException();
+ expectedExceptions.add(RuntimeException);
+ throw RuntimeException;
}
});
//when
- JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(), restResponse);
+ JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(), restResponse);
//verify
waitForJobToFinishInJobManager(finished);
assertEquals(100, expectedExceptions.size());
- for (ApiException expectedException : expectedExceptions) {
+ for (RuntimeException expectedException : expectedExceptions) {
verify(logger).warn("Unable to retrieve operations details", expectedException);
}
verify(systemFunctions, times(100)).sleep(5000);
@@ -1382,7 +1372,7 @@ public class TestLifecycleManager extends TestBase {
*/
@Test
public void testHealFailurePropagation() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
VnfHealRequest healRequest = new VnfHealRequest();
healRequest.setAction("myAction");
VnfHealRequestAffectedvm affectedVm = new VnfHealRequestAffectedvm();
@@ -1390,7 +1380,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, empty(), 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);
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java
index 79ec1a83..e4960b2b 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java
@@ -16,7 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.collect.Lists;
-import com.nokia.cbam.lcn.v32.ApiException;
import com.nokia.cbam.lcn.v32.model.CreateSubscriptionRequest;
import com.nokia.cbam.lcn.v32.model.Subscription;
import com.nokia.cbam.lcn.v32.model.SubscriptionAuthentication;
@@ -58,7 +57,7 @@ public class TestSelfRegistrationManager extends TestBase {
@Before
public void initMocks() throws Exception {
setField(SelfRegistrationManager.class, "logger", logger);
- when(lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION)).thenReturn(subscriptions);
+ when(lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION)).thenReturn(buildObservable(subscriptions));
when(driverProperties.getVnfmId()).thenReturn(VNFM_ID);
setField(selfRegistrationManager, "driverMsbExternalIp", "1.2.3.4");
setField(selfRegistrationManager, "driverVnfmExternalIp", "5.6.7.8");
@@ -78,7 +77,7 @@ public class TestSelfRegistrationManager extends TestBase {
public void testRegistration() throws Exception {
//given
Subscription subscription = new Subscription();
- when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenReturn(subscription);
+ when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenReturn(buildObservable(subscription));
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
when(msbClient.registerMicroServiceInfo(registeredMicroservice.capture())).thenReturn(returnedMicroService);
//when
@@ -158,7 +157,7 @@ public class TestSelfRegistrationManager extends TestBase {
@Test
public void testFailedLcnSubscription() throws Exception {
//given
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(lcnApi.subscriptionsPost(any(), any())).thenThrow(expectedException);
//when
try {
@@ -180,14 +179,11 @@ public class TestSelfRegistrationManager extends TestBase {
public void testFailedMsbPublish() throws Exception {
//given
Subscription subscription = new Subscription();
- when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenAnswer(new Answer<Subscription>() {
- @Override
- public Subscription answer(InvocationOnMock invocationOnMock) throws Throwable {
- subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
- subscription.setId(UUID.randomUUID().toString());
- subscriptions.add(subscription);
- return subscription;
- }
+ when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenAnswer(invocationOnMock -> {
+ subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
+ subscription.setId(UUID.randomUUID().toString());
+ subscriptions.add(subscription);
+ return buildObservable(subscription);
});
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
RouteException expectedException = new RouteException();
@@ -302,7 +298,7 @@ public class TestSelfRegistrationManager extends TestBase {
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
when(jobManager.hasOngoingJobs()).thenReturn(false);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
doThrow(expectedException).when(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
//when
try {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
index 7121bea6..bf85dedd 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
@@ -16,9 +16,7 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification;
import com.google.gson.*;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.model.*;
-import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -42,8 +40,6 @@ import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestLifecycleChangeNotificationManager extends TestBase {
- public static final String OPERATION_EXECUTION_ID = "myOperationExecutionId";
-
@InjectMocks
private LifecycleChangeNotificationManager lifecycleChangeNotificationManager;
private VnfLifecycleChangeNotification recievedLcn = new VnfLifecycleChangeNotification();
@@ -76,7 +72,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
recievedLcn.setLifecycleOperationOccurrenceId("instantiationOperationExecutionId");
healOperation.setStartTime(OffsetDateTime.now().plusDays(1));
recievedLcn.setVnfInstanceId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(operationExecutions);
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecutions));
prepOperation(instantiationOperation);
prepOperation(scaleOperation);
prepOperation(healOperation);
@@ -86,8 +82,8 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
VimInfo vimInfo = new VimInfo();
vimInfo.setId(VIM_ID);
instantiateVnfRequest.getVims().add(vimInfo);
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new Gson().toJsonTree(instantiateVnfRequest));
- when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenReturn(vnfs);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new Gson().toJsonTree(instantiateVnfRequest)));
+ when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfs));
vnfs.add(vnf);
vnf.setId(VNF_ID);
VnfProperty prop = new VnfProperty();
@@ -95,10 +91,10 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
prop.setValue(VNFM_ID);
vnf.setExtensions(new ArrayList<>());
vnf.getExtensions().add(prop);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnf));
}
- private void prepOperation(OperationExecution operationExecution) throws ApiException {
+ private void prepOperation(OperationExecution operationExecution) {
addEmptyModifiedConnectionPoints(operationExecution);
JsonElement root = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + JOB_ID + "\"}}");
operationExecution.setOperationParams(root);
@@ -106,7 +102,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
case TERMINATE:
root.getAsJsonObject().addProperty("terminationType", "GRACEFULL");
}
- when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(operationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationExecution);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(operationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecution));
operationExecutions.add(operationExecution);
}
@@ -141,7 +137,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
*/
@Test
public void testInstantiationSufficesTheLastInstantiation() {
- DateTime baseTime = DateTime.now();
+ OffsetDateTime baseTime = OffsetDateTime.now();
List<OperationExecution> operations = new ArrayList<>();
OperationExecution operation = buildOperation(OffsetDateTime.now(), INSTANTIATE);
@@ -159,7 +155,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
*/
@Test
public void testNoInstantiation() {
- DateTime baseTime = DateTime.now();
+ OffsetDateTime baseTime = OffsetDateTime.now();
List<OperationExecution> operations = new ArrayList<>();
OperationExecution operation = buildOperation(OffsetDateTime.now(), TERMINATE);
@@ -195,7 +191,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
*/
@Test
public void testUnableToListVnfs() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
@@ -212,7 +208,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
*/
@Test
public void testUnableToQueryVnf() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
@@ -304,7 +300,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
public void testUnableToQueryCurrentOperation() throws Exception {
recievedLcn.setOperation(OperationType.TERMINATE);
recievedLcn.setStatus(OperationStatus.FINISHED);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
@@ -313,7 +309,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
} catch (Exception e) {
//verify
assertEquals(expectedException, e.getCause());
- verify(logger).error("Unable to retrieve the current VNF myVnfId", e.getCause());
+ verify(logger).error("Unable to retrieve the operation executions for the VNF myVnfId", e.getCause());
}
}