summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nokiav2/deployment/src/main/resources/application.properties6
-rw-r--r--nokiav2/driver/pom.xml18
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java6
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java9
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java6
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java5
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java3
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcExternalSystemInfoProvider.java9
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java35
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java13
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcRestApiProvider.java31
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java2
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java6
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java31
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java76
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java117
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java93
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java12
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java95
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java35
-rw-r--r--nokiav2/driver/src/test/java/okhttp3/OakExtractor.java28
-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
-rw-r--r--nokiav2/driverwar/pom.xml7
-rw-r--r--nokiav2/generatedapis/pom.xml100
-rw-r--r--nokiav2/generatedapis/src/test/java/TestInhertence.java97
-rw-r--r--nokiav2/pom.xml41
-rw-r--r--pom.xml2
49 files changed, 1556 insertions, 1146 deletions
diff --git a/nokiav2/deployment/src/main/resources/application.properties b/nokiav2/deployment/src/main/resources/application.properties
index c9c86a02..c467e765 100644
--- a/nokiav2/deployment/src/main/resources/application.properties
+++ b/nokiav2/deployment/src/main/resources/application.properties
@@ -29,11 +29,11 @@ driverVnfmExternalIp=127.0.0.1
# the IP address of the message bus
messageBusIp=127.0.0.1
# the URL of the CBAM catalog service
-cbamCatalogUrl=https://127.0.0.1:443/api/catalog/adapter
+cbamCatalogUrl=https://127.0.0.1:443/api/catalog/adapter/
# the URL of the CBAM LCN service
-cbamLcnUrl=https://127.0.0.1:443/vnfm/lcn/v3
+cbamLcnUrl=https://127.0.0.1:443/vnfm/lcn/v3/
# the URL of the CBAM authentication service
-cbamKeyCloakBaseUrl=https://127.0.0.1:443/auth
+cbamKeyCloakBaseUrl=https://127.0.0.1:443/auth/
# the username to be used for requesing a token on CBAM authorization interface
cbamUsername=kukuUser
# the password to be used for requesing a token on CBAM authorization interface
diff --git a/nokiav2/driver/pom.xml b/nokiav2/driver/pom.xml
index 46dfe936..a06b4166 100644
--- a/nokiav2/driver/pom.xml
+++ b/nokiav2/driver/pom.xml
@@ -40,13 +40,13 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
- <version>1.5.10.RELEASE</version>
+ <version>${spring.boot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
- <version>1.5.10.RELEASE</version>
+ <version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -60,12 +60,11 @@
<artifactId>snakeyaml</artifactId>
<version>1.19</version>
</dependency>
+ <!-- this version must be in sync with the dependency comming from spring boot -->
<dependency>
- <!-- this does not have a compile time dependency, but is required to be able to deserialize the date to joda time -->
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
- <!-- this version must be in sync with the dependency comming from spring boot -->
- <version>2.8.10</version>
+ <version>2.9.3</version>
</dependency>
<!-- access MSB during registration -->
<dependency>
@@ -85,11 +84,13 @@
<version>9.4.8.v20171121</version>
<scope>test</scope>
</dependency>
+<!--
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
- <version>RELEASE</version>
+ <version>16.0.1</version>
</dependency>
+-->
<dependency>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-schema</artifactId>
@@ -100,13 +101,14 @@
<artifactId>rest-client</artifactId>
<version>1.2.0</version>
</dependency>
- </dependencies>
+
+ </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.5</version>
+ <version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java
index e75159f6..6296d4b2 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java
@@ -16,9 +16,9 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia;
-import org.apache.log4j.Logger;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
+import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -28,12 +28,14 @@ import org.springframework.context.annotation.Profile;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;
+import static org.slf4j.LoggerFactory.getLogger;
+
/**
* Represents the spring boot application
*/
@SpringBootApplication
public class NokiaSvnfmApplication {
- private static Logger logger = Logger.getLogger(NokiaSvnfmApplication.class);
+ private static Logger logger = getLogger(NokiaSvnfmApplication.class);
/**
* Entry point for the Spring boot application
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
index a9e11653..6d569e2a 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
@@ -16,7 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
-import com.nokia.cbam.lcn.v32.ApiException;
import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
import com.nokia.cbam.lcn.v32.model.*;
import org.onap.msb.sdk.discovery.common.RouteException;
@@ -121,12 +120,12 @@ public class SelfRegistrationManager {
SubscriptionsApi lcnApi = cbamRestApiProvider.getCbamLcnApi(vnfmId);
try {
String callbackUrl = getDriverVnfmUrl() + DriverProperties.LCN_URL;
- for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION)) {
+ for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) {
if (subscription.getCallbackUrl().equals(callbackUrl)) {
lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
}
}
- } catch (ApiException e) {
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to delete CBAM LCN subscription", e);
}
}
@@ -159,7 +158,7 @@ public class SelfRegistrationManager {
logger.info("Subscribing to CBAM LCN {} with callback to {}", driverProperties.getCbamLcnUrl(), callbackUrl);
SubscriptionsApi lcnApi = cbamRestApiProvider.getCbamLcnApi(vnfmId);
try {
- for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION)) {
+ for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) {
if (subscription.getCallbackUrl().equals(callbackUrl)) {
return;
}
@@ -177,7 +176,7 @@ public class SelfRegistrationManager {
subscriptionAuthentication.setType(NONE);
request.setAuthentication(subscriptionAuthentication);
lcnApi.subscriptionsPost(request, NOKIA_LCN_API_VERSION);
- } catch (ApiException e) {
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to subscribe to CBAM LCN", e);
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java
index ff2bde8a..aad90eac 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java
@@ -97,13 +97,11 @@ public class AAINotificationProcessor implements INotificationSender {
for (ReportedAffectedCp affectedCp : affectedConnectionPoints.get().getPost()) {
if (!isEmpty(affectedCp.getServerProviderId())) {
lInterfaceManager.update(receivedNotification.getVnfInstanceId(), vimId, affectedCp, inMaintenance);
- }
- else{
+ } else {
logger.warn("The changed {} connection point is not linked to any server", affectedCp.getCpId());
}
}
- }
- else{
+ } else {
logger.warn("The changed connection points are not present in VNF with {} identifier", receivedNotification.getVnfInstanceId());
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java
index 959177c1..2b9b3882 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.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.onap.aai.domain.yang.v11.GenericVnf;
import org.onap.aai.domain.yang.v11.Relationship;
@@ -84,9 +83,9 @@ class GenericVnfManager extends AbstractManager {
private void updateFields(GenericVnf vnf, String vnfId, boolean inMaintenance) {
try {
- VnfInfo vnfInfo = cbamRestApiProvider.getCbamLcmApi(driverProperties.getVnfmId()).vnfsVnfInstanceIdGet(vnfId, CbamRestApiProvider.NOKIA_LCM_API_VERSION);
+ VnfInfo vnfInfo = cbamRestApiProvider.getCbamLcmApi(driverProperties.getVnfmId()).vnfsVnfInstanceIdGet(vnfId, CbamRestApiProvider.NOKIA_LCM_API_VERSION).blockingFirst();
vnf.setVnfName(vnfInfo.getName());
- } catch (ApiException e) {
+ } catch (RuntimeException e) {
throw buildFatalFailure(logger, "Unable to query VNF with " + vnfId + " identifier from CBAM", e);
}
vnf.setVnfId(vnfId);
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java
index 976e283d..8a4dbdd1 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java
@@ -16,7 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.common.base.Splitter;
-import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
import org.onap.aai.domain.yang.v11.RelationshipList;
import org.onap.aai.domain.yang.v11.Vnfc;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
@@ -50,7 +49,7 @@ public class VnfcManager extends AbstractManager {
return format("/vnfcs/vnfc/%s", buildId(vnfId, cbamVnfcId));
}
- public static String getCbamVnfcId(String vnfcId){
+ public static String getCbamVnfcId(String vnfcId) {
String vnfId = Splitter.on(CbamUtils.SEPARATOR).split(vnfcId).iterator().next();
return vnfcId.replaceFirst(vnfId + SEPARATOR, "");
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcExternalSystemInfoProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcExternalSystemInfoProvider.java
index 416367d7..83b10872 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcExternalSystemInfoProvider.java
@@ -17,7 +17,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
-import org.onap.vnfmdriver.ApiException;
import org.onap.vnfmdriver.model.VimInfo;
import org.onap.vnfmdriver.model.VnfmInfo;
import org.slf4j.Logger;
@@ -47,8 +46,8 @@ public class VfcExternalSystemInfoProvider extends GenericExternalSystemInfoProv
@Override
public VnfmInfo queryVnfmInfoFromSource(String vnfmId) {
try {
- return vfcRestApiProvider.getNsLcmApi().queryVnfmInfo(vnfmId);
- } catch (ApiException e) {
+ return vfcRestApiProvider.getNsLcmApi().queryVnfmInfo(vnfmId).execute().body();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VNFM from VF-C with " + vnfmId + " identifier", e);
}
}
@@ -56,8 +55,8 @@ public class VfcExternalSystemInfoProvider extends GenericExternalSystemInfoProv
@Override
public VimInfo getVimInfo(String vimId) {
try {
- return vfcRestApiProvider.getNsLcmApi().queryVIMInfo(vimId);
- } catch (org.onap.vnfmdriver.ApiException e) {
+ return vfcRestApiProvider.getNsLcmApi().queryVIMInfo(vimId).execute().body();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VIM from VF-C with " + vimId + " identifier", e);
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java
index 1d9ef8dc..03169612 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java
@@ -21,7 +21,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
import com.nokia.cbam.lcm.v32.model.VnfcResourceInfo;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IGrantManager;
@@ -77,23 +76,25 @@ public class VfcGrantManager implements IGrantManager {
@Override
public void requestGrantForScale(String vnfmId, String vnfId, String vimId, String onapCsarId, VnfScaleRequest request, String jobId) {
+ String cbamVnfdId;
try {
- OperationType operationType = ScaleDirection.IN.equals(request.getType()) ? OperationType.SCALEIN : OperationType.SCALEOUT;
- GrantVNFRequest grantRequest = buildGrantRequest(vnfmId, vimId, onapCsarId, jobId, operationType);
- com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION);
- String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, vnf.getVnfdId());
- Set<ResourceChange> resourceChanges = calculateResourceChangeDuringScaling(vnfdContent, request.getAspectId(), Integer.parseInt(request.getNumberOfSteps()));
- if (request.getType() == ScaleDirection.IN) {
- grantRequest.getRemoveResource().addAll(resourceChanges);
-
- } else {
- grantRequest.getAddResource().addAll(resourceChanges);
- }
- grantRequest.setVnfInstanceId(vnfId);
- requestGrant(grantRequest);
- } catch (ApiException e) {
+ com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
+ cbamVnfdId = vnf.getVnfdId();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VNF " + vnfId, e);
}
+ OperationType operationType = ScaleDirection.IN.equals(request.getType()) ? OperationType.SCALEIN : OperationType.SCALEOUT;
+ GrantVNFRequest grantRequest = buildGrantRequest(vnfmId, vimId, onapCsarId, jobId, operationType);
+ String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, cbamVnfdId);
+ Set<ResourceChange> resourceChanges = calculateResourceChangeDuringScaling(vnfdContent, request.getAspectId(), Integer.parseInt(request.getNumberOfSteps()));
+ if (request.getType() == ScaleDirection.IN) {
+ grantRequest.getRemoveResource().addAll(resourceChanges);
+
+ } else {
+ grantRequest.getAddResource().addAll(resourceChanges);
+ }
+ grantRequest.setVnfInstanceId(vnfId);
+ requestGrant(grantRequest);
}
@Override
@@ -157,8 +158,8 @@ public class VfcGrantManager implements IGrantManager {
private GrantVNFResponseVim requestGrant(GrantVNFRequest grantRequest) {
try {
- return vfcRestApiProvider.getNsLcmApi().grantvnf(grantRequest).getVim();
- } catch (org.onap.vnfmdriver.ApiException e) {
+ return vfcRestApiProvider.getNsLcmApi().grantvnf(grantRequest).execute().body().getVim();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to request grant", e);
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java
index 71880d0b..5a3e960f 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java
@@ -60,22 +60,23 @@ public class VfcPackageProvider implements IPackageProvider {
@Override
public String getCbamVnfdId(String csarId) {
+ VnfPkgDetailInfo vnfPackageDetails;
try {
- VnfpackageApi onapCatalogApi = restApiProvider.getOnapCatalogApi();
- VnfPkgDetailInfo vnfPackageDetails = onapCatalogApi.queryVnfPackage(csarId);
- JsonElement vnfdModel = new JsonParser().parse(vnfPackageDetails.getPackageInfo().getVnfdModel());
- return vnfdModel.getAsJsonObject().get("metadata").getAsJsonObject().get("resourceVendorModelNumber").getAsString();
+ VnfpackageApi onapCatalogApi = restApiProvider.getVfcCatalogApi();
+ vnfPackageDetails = onapCatalogApi.queryVnfPackage(csarId).execute().body();
} catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VNF package with " + csarId, e);
}
+ JsonElement vnfdModel = new JsonParser().parse(vnfPackageDetails.getPackageInfo().getVnfdModel());
+ return vnfdModel.getAsJsonObject().get("metadata").getAsJsonObject().get("resourceVendorModelNumber").getAsString();
}
@Override
public byte[] getPackage(String csarId) {
String downloadUrl;
try {
- VnfpackageApi onapCatalogApi = restApiProvider.getOnapCatalogApi();
- VnfPkgDetailInfo vnfPackageDetails = onapCatalogApi.queryVnfPackage(csarId);
+ VnfpackageApi onapCatalogApi = restApiProvider.getVfcCatalogApi();
+ VnfPkgDetailInfo vnfPackageDetails = onapCatalogApi.queryVnfPackage(csarId).execute().body();
String urlFromVfc = vnfPackageDetails.getPackageInfo().getDownloadUrl();
String host = new URL(urlFromVfc).getHost();
downloadUrl = urlFromVfc.replaceFirst("://" + host, "://" + ipMappingProvider.mapPrivateIpToPublicIp(host));
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcRestApiProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcRestApiProvider.java
index baa61f75..c2473aae 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcRestApiProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcRestApiProvider.java
@@ -15,9 +15,11 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
+import com.google.common.annotations.VisibleForTesting;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.MsbApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
import org.onap.vfccatalog.api.VnfpackageApi;
+import org.onap.vnfmdriver.ApiClient;
import org.onap.vnfmdriver.api.NslcmApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
@@ -44,19 +46,36 @@ public class VfcRestApiProvider {
* @return API to access VF-C for granting & LCN API
*/
public NslcmApi getNsLcmApi() {
- org.onap.vnfmdriver.ApiClient apiClient = new org.onap.vnfmdriver.ApiClient();
+ return buildNslcmApiClient().createService(NslcmApi.class);
+ }
+
+ @VisibleForTesting
+ ApiClient buildNslcmApiClient() {
+ ApiClient apiClient = new ApiClient();
String correctedUrl = fixIncorrectUrl();
- apiClient.setBasePath(correctedUrl);
- return new NslcmApi(apiClient);
+ if (!correctedUrl.endsWith("/")) {
+ correctedUrl = correctedUrl + "/";
+ }
+ apiClient.setAdapterBuilder(apiClient.getAdapterBuilder().baseUrl(correctedUrl));
+ return apiClient;
}
/**
* @return API to access VF-C catalog API
*/
- public VnfpackageApi getOnapCatalogApi() {
+ public VnfpackageApi getVfcCatalogApi() {
+ return buildCatalogApiClient().createService(VnfpackageApi.class);
+ }
+
+ @VisibleForTesting
+ org.onap.vfccatalog.ApiClient buildCatalogApiClient() {
org.onap.vfccatalog.ApiClient vfcApiClient = new org.onap.vfccatalog.ApiClient();
- vfcApiClient.setBasePath(msbApiProvider.getMicroServiceUrl(NSCATALOG_SERVICE_NAME, NSCATALOG_API_VERSION));
- return new VnfpackageApi(vfcApiClient);
+ String microServiceUrl = msbApiProvider.getMicroServiceUrl(NSCATALOG_SERVICE_NAME, NSCATALOG_API_VERSION);
+ if (!microServiceUrl.endsWith("/")) {
+ microServiceUrl = microServiceUrl + "/";
+ }
+ vfcApiClient.setAdapterBuilder(vfcApiClient.getAdapterBuilder().baseUrl(microServiceUrl));
+ return vfcApiClient;
}
/**
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java
index 7f63a1a4..5a7bd749 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java
@@ -28,8 +28,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
-import java.util.Optional;
-
import static java.util.Optional.empty;
import static org.apache.http.HttpStatus.SC_CREATED;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java
index 26a3156f..3ed94c94 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java
@@ -15,9 +15,7 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
-import com.nokia.cbam.lcm.v32.ApiClient;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
@@ -38,11 +36,11 @@ public class RealConfig {
*
* @return the message converter
*/
- @Bean
+ //FIXME? @Bean
public HttpMessageConverters customConverters() {
Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
- gsonHttpMessageConverter.setGson(new ApiClient().getJSON().getGson());
+ //FIXME gsonHttpMessageConverter.setGson(new ApiClient().getAdapterBuilder().build()..getJSON().getGson());
messageConverters.add(gsonHttpMessageConverter);
return new HttpMessageConverters(true, messageConverters);
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java
index 6a35d8e2..a7cabd52 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java
@@ -17,7 +17,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.io.ByteStreams;
-import com.nokia.cbam.catalog.v1.ApiException;
import com.nokia.cbam.catalog.v1.api.DefaultApi;
import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IPackageProvider;
@@ -25,8 +24,10 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.io.*;
-import java.nio.file.Path;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;
@@ -35,8 +36,9 @@ import java.util.zip.ZipInputStream;
import static com.google.common.base.Splitter.on;
import static com.google.common.collect.Iterables.filter;
-import static java.nio.file.Files.createTempFile;
-import static java.nio.file.Files.write;
+import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
+import static okhttp3.MediaType.parse;
+import static okhttp3.RequestBody.create;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
@@ -113,11 +115,8 @@ public class CatalogManager {
DefaultApi cbamCatalogApi = cbamRestApiProvider.getCbamCatalogApi(vnfmId);
if (!isPackageReplicated(cbamVnfdId, cbamCatalogApi)) {
try {
- Path tempFile = createTempFile("cbam", "zip");
ByteArrayOutputStream cbamPackage = getFileInZip(new ByteArrayInputStream(packageProvider.getPackage(csarId)), CBAM_PACKAGE_NAME_IN_ZIP);
- write(tempFile, cbamPackage.toByteArray());
- //FIXME delete file
- return cbamCatalogApi.create(tempFile.toFile());
+ return cbamCatalogApi.create(create(parse(APPLICATION_OCTET_STREAM), cbamPackage.toByteArray())).execute().body();
} catch (Exception e) {
logger.debug("Probably concurrent package uploads", e);
//retest if the VNF package exists in CBAM. It might happen that an other operation
@@ -142,9 +141,9 @@ public class CatalogManager {
*/
public String getCbamVnfdContent(String vnfmId, String vnfdId) {
try {
- File content = cbamRestApiProvider.getCbamCatalogApi(vnfmId).content(vnfdId);
- String vnfdPath = getVnfdLocation(new FileInputStream(content));
- return new String(getFileInZip(new FileInputStream(content), vnfdPath).toByteArray());
+ byte[] vnfdContent = cbamRestApiProvider.getCbamCatalogApi(vnfmId).content(vnfdId).execute().body().bytes();
+ String vnfdPath = getVnfdLocation(new ByteArrayInputStream(vnfdContent));
+ return new String(getFileInZip(new ByteArrayInputStream(vnfdContent), vnfdPath).toByteArray());
} catch (Exception e) {
throw buildFatalFailure(logger, "Unable to get package with (" + vnfdId + ")", e);
}
@@ -160,14 +159,14 @@ public class CatalogManager {
private CatalogAdapterVnfpackage queryPackageFromCBAM(String cbamVnfdId, DefaultApi cbamCatalogApi) {
try {
- return cbamCatalogApi.getById(cbamVnfdId);
- } catch (ApiException e) {
+ return cbamCatalogApi.getById(cbamVnfdId).execute().body();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VNF package with " + cbamVnfdId + " from CBAM", e);
}
}
- private boolean isPackageReplicatedToCbam(String cbamVnfdId, DefaultApi cbamCatalogApi) throws ApiException {
- for (CatalogAdapterVnfpackage vnfPackage : cbamCatalogApi.list()) {
+ private boolean isPackageReplicatedToCbam(String cbamVnfdId, DefaultApi cbamCatalogApi) throws IOException {
+ for (CatalogAdapterVnfpackage vnfPackage : cbamCatalogApi.list().execute().body()) {
if (vnfPackage.getVnfdId().equals(cbamVnfdId)) {
return true;
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java
index 5fdc919a..de850da6 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java
@@ -15,7 +15,7 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
-import com.google.common.io.BaseEncoding;
+import com.google.common.annotations.VisibleForTesting;
import com.nokia.cbam.catalog.v1.api.DefaultApi;
import com.nokia.cbam.lcm.v32.ApiClient;
import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
@@ -27,8 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import java.io.ByteArrayInputStream;
-
/**
* Responsible for providing client to access CBAM REST API
*/
@@ -36,20 +34,24 @@ import java.io.ByteArrayInputStream;
public class CbamRestApiProvider {
public static final String NOKIA_LCN_API_VERSION = "3.2";
public static final String NOKIA_LCM_API_VERSION = "3.2";
+ public static final String AUTH_NAME = "test";
private final DriverProperties driverProperties;
private final CbamTokenProvider tokenProvider;
private final VnfmInfoProvider vnfmInfoProvider;
-
- @Value("${trustedCertificates}")
- private String trustedCertificates;
- @Value("${skipCertificateVerification}")
- private boolean skipCertificateVerification;
+ private final CbamSecurityProvider cbamSecurityProvider;
+ @Value("${cbamKeyCloakBaseUrl}")
+ private String cbamKeyCloakBaseUrl;
+ @Value("${cbamUsername}")
+ private String username;
+ @Value("${cbamPassword}")
+ private String password;
@Autowired
- public CbamRestApiProvider(DriverProperties driverProperties, CbamTokenProvider cbamTokenProvider, VnfmInfoProvider vnfmInfoProvider) {
+ public CbamRestApiProvider(DriverProperties driverProperties, CbamTokenProvider cbamTokenProvider, VnfmInfoProvider vnfmInfoProvider, CbamSecurityProvider cbamSecurityProvider) {
this.driverProperties = driverProperties;
this.tokenProvider = cbamTokenProvider;
this.vnfmInfoProvider = vnfmInfoProvider;
+ this.cbamSecurityProvider = cbamSecurityProvider;
}
/**
@@ -57,7 +59,7 @@ public class CbamRestApiProvider {
* @return API to access CBAM LCM API
*/
public VnfsApi getCbamLcmApi(String vnfmId) {
- return new VnfsApi(getLcmApiClient(vnfmId));
+ return buildLcmApiClient(vnfmId).createService(VnfsApi.class);
}
/**
@@ -65,7 +67,7 @@ public class CbamRestApiProvider {
* @return API to access the operation executions
*/
public OperationExecutionsApi getCbamOperationExecutionApi(String vnfmId) {
- return new OperationExecutionsApi(getLcmApiClient(vnfmId));
+ return buildLcmApiClient(vnfmId).createService(OperationExecutionsApi.class);
}
/**
@@ -73,15 +75,7 @@ public class CbamRestApiProvider {
* @return API to access CBAM LCN subscription API
*/
public SubscriptionsApi getCbamLcnApi(String vnfmId) {
- com.nokia.cbam.lcn.v32.ApiClient apiClient = new com.nokia.cbam.lcn.v32.ApiClient();
- if (!skipCertificateVerification) {
- apiClient.setSslCaCert(new ByteArrayInputStream(BaseEncoding.base64().decode(trustedCertificates)));
- } else {
- apiClient.setVerifyingSsl(false);
- }
- apiClient.setBasePath(driverProperties.getCbamLcnUrl());
- apiClient.setAccessToken(tokenProvider.getToken(vnfmId));
- return new SubscriptionsApi(apiClient);
+ return buildLcnApiClient(vnfmId).createService(SubscriptionsApi.class);
}
/**
@@ -89,27 +83,37 @@ public class CbamRestApiProvider {
* @return API to access CBAM catalog API
*/
public DefaultApi getCbamCatalogApi(String vnfmId) {
+ return buildCatalogApiClient(vnfmId).createService(DefaultApi.class);
+ }
+
+ @VisibleForTesting
+ com.nokia.cbam.lcn.v32.ApiClient buildLcnApiClient(String vnfmId) {
+ com.nokia.cbam.lcn.v32.ApiClient apiClient = new com.nokia.cbam.lcn.v32.ApiClient();
+ apiClient.getOkBuilder().sslSocketFactory(cbamSecurityProvider.buildSSLSocketFactory(), cbamSecurityProvider.buildTrustManager());
+ apiClient.getOkBuilder().hostnameVerifier(cbamSecurityProvider.buildHostnameVerifier());
+ apiClient.addAuthorization(AUTH_NAME, tokenProvider.getToken(vnfmId));
+ apiClient.setAdapterBuilder(apiClient.getAdapterBuilder().baseUrl(driverProperties.getCbamLcnUrl()));
+ return apiClient;
+ }
+
+ @VisibleForTesting
+ com.nokia.cbam.catalog.v1.ApiClient buildCatalogApiClient(String vnfmId) {
com.nokia.cbam.catalog.v1.ApiClient apiClient = new com.nokia.cbam.catalog.v1.ApiClient();
- if (!skipCertificateVerification) {
- apiClient.setSslCaCert(new ByteArrayInputStream(BaseEncoding.base64().decode(trustedCertificates)));
- } else {
- apiClient.setVerifyingSsl(false);
- }
- apiClient.setBasePath(driverProperties.getCbamCatalogUrl());
- apiClient.setAccessToken(tokenProvider.getToken(vnfmId));
- return new DefaultApi(apiClient);
+ apiClient.getOkBuilder().sslSocketFactory(cbamSecurityProvider.buildSSLSocketFactory(), cbamSecurityProvider.buildTrustManager());
+ apiClient.getOkBuilder().hostnameVerifier(cbamSecurityProvider.buildHostnameVerifier());
+ apiClient.addAuthorization(AUTH_NAME, tokenProvider.getToken(vnfmId));
+ apiClient.setAdapterBuilder(apiClient.getAdapterBuilder().baseUrl(driverProperties.getCbamCatalogUrl()));
+ return apiClient;
}
- private ApiClient getLcmApiClient(String vnfmId) {
+ @VisibleForTesting
+ ApiClient buildLcmApiClient(String vnfmId) {
VnfmInfo vnfmInfo = vnfmInfoProvider.getVnfmInfo(vnfmId);
ApiClient apiClient = new ApiClient();
- if (!skipCertificateVerification) {
- apiClient.setSslCaCert(new ByteArrayInputStream(BaseEncoding.base64().decode(trustedCertificates)));
- } else {
- apiClient.setVerifyingSsl(false);
- }
- apiClient.setAccessToken(tokenProvider.getToken(vnfmId));
- apiClient.setBasePath(vnfmInfo.getUrl());
+ apiClient.getOkBuilder().sslSocketFactory(cbamSecurityProvider.buildSSLSocketFactory(), cbamSecurityProvider.buildTrustManager());
+ apiClient.getOkBuilder().hostnameVerifier(cbamSecurityProvider.buildHostnameVerifier());
+ apiClient.addAuthorization(AUTH_NAME, tokenProvider.getToken(vnfmId));
+ apiClient.setAdapterBuilder(apiClient.getAdapterBuilder().baseUrl(vnfmInfo.getUrl()));
return apiClient;
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java
new file mode 100644
index 00000000..c2358cf1
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java
@@ -0,0 +1,117 @@
+/*
+ * 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.base.Joiner;
+import com.google.common.io.BaseEncoding;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.StoreLoader;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import javax.net.ssl.*;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.Set;
+
+import static java.util.UUID.randomUUID;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Responsible for providing a token to access CBAM APIs
+ */
+@Component
+public class CbamSecurityProvider {
+ private static Logger logger = getLogger(CbamSecurityProvider.class);
+ @Value("${trustedCertificates}")
+ private String trustedCertificates;
+ @Value("${skipCertificateVerification}")
+ private boolean skipCertificateVerification;
+ @Value("${skipHostnameVerification}")
+ private boolean skipHostnameVerification;
+
+ protected HostnameVerifier buildHostnameVerifier() {
+ if (skipHostnameVerification) {
+ return (hostname, session) -> true;
+ } else {
+ return new DefaultHostnameVerifier();
+ }
+ }
+
+ protected SSLSocketFactory buildSSLSocketFactory() {
+ try {
+ TrustManager[] trustManagers = new X509TrustManager[]{buildTrustManager()};
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(null, trustManagers, new SecureRandom());
+ return sslContext.getSocketFactory();
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to create SSL socket factory", e);
+ }
+ }
+
+ protected X509TrustManager buildTrustManager() {
+ if (skipCertificateVerification) {
+ return new AllTrustedTrustManager();
+ } else {
+ if (StringUtils.isEmpty(trustedCertificates)) {
+ throw buildFatalFailure(logger, "If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty");
+ }
+ Set<String> trustedPems;
+ String content;
+ try {
+ content = new String(BaseEncoding.base64().decode(trustedCertificates), StandardCharsets.UTF_8);
+ trustedPems = StoreLoader.getCertifacates(content);
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "The trustedCertificates must be a base64 encoded collection of PEM certificates", e);
+ }
+ if (trustedPems.size() == 0) {
+ throw buildFatalFailure(logger, "No certificate can be extracted from " + content);
+ }
+ try {
+ KeyStore keyStore = StoreLoader.loadStore(Joiner.on("\n").join(trustedPems), randomUUID().toString(), randomUUID().toString());
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ trustManagerFactory.init(keyStore);
+ return (X509TrustManager) trustManagerFactory.getTrustManagers()[0];
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to create keystore", e);
+ }
+ }
+ }
+
+ private static class AllTrustedTrustManager implements X509TrustManager {
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ //no need to check certificates if everything is trusted
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ //no need to check certificates if everything is trusted
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[0];
+ }
+ }
+
+}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java
index a8c7ca04..837a25e5 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java
@@ -16,32 +16,21 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Joiner;
-import com.google.common.io.BaseEncoding;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import okhttp3.*;
-import org.apache.http.conn.ssl.DefaultHostnameVerifier;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.StoreLoader;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.UserVisibleError;
import org.onap.vnfmdriver.model.VnfmInfo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
-import javax.net.ssl.*;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.security.*;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.util.Set;
-import static java.util.UUID.randomUUID;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
@@ -54,11 +43,11 @@ import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VAL
//even if the value for grant type an user password is the same they do not mean the same thing
//the duplication of this is intentional
@SuppressWarnings("squid:S1192")
-public class CbamTokenProvider {
+public class CbamTokenProvider extends CbamSecurityProvider {
public static final int MAX_RETRY_COUNT = 5;
public static final String GRANT_TYPE = "password";
public static final String CLIENT_SECRET = "password";
- private static final String CBAM_TOKEN_URL = "/realms/cbam/protocol/openid-connect/token";
+ private static final String CBAM_TOKEN_URL = "realms/cbam/protocol/openid-connect/token";
private static Logger logger = getLogger(CbamTokenProvider.class);
private final VnfmInfoProvider vnfmInfoProvider;
@Value("${cbamKeyCloakBaseUrl}")
@@ -67,12 +56,6 @@ public class CbamTokenProvider {
private String username;
@Value("${cbamPassword}")
private String password;
- @Value("${trustedCertificates}")
- private String trustedCertificates;
- @Value("${skipCertificateVerification}")
- private boolean skipCertificateVerification;
- @Value("${skipHostnameVerification}")
- private boolean skipHostnameVerification;
private volatile CurrentToken token;
@Autowired
@@ -83,9 +66,9 @@ public class CbamTokenProvider {
/**
* @return the token to access CBAM APIs (ex. 123456)
*/
- public String getToken(String vnfmId) {
+ public Interceptor getToken(String vnfmId) {
VnfmInfo vnfmInfo = vnfmInfoProvider.getVnfmInfo(vnfmId);
- return getToken(vnfmInfo.getUserName(), vnfmInfo.getPassword());
+ return new OauthInterceptor(getToken(vnfmInfo.getUserName(), vnfmInfo.getPassword()));
}
private String getToken(String clientId, String clientSecret) {
@@ -155,45 +138,20 @@ public class CbamTokenProvider {
return SystemFunctions.systemFunctions().currentTimeMillis() + token.expiresIn * (1000 / 2);
}
- private HostnameVerifier buildHostnameVerifier() {
- if (skipHostnameVerification) {
- return (hostname, session) -> true;
- } else {
- return new DefaultHostnameVerifier();
- }
- }
+ private static class OauthInterceptor implements Interceptor {
+ private final String token;
- @VisibleForTesting
- SSLSocketFactory buildSSLSocketFactory() {
- try {
- TrustManager[] trustManagers = buildTrustManager();
- SSLContext sslContext = SSLContext.getInstance("TLS");
- sslContext.init(null, trustManagers, new SecureRandom());
- return sslContext.getSocketFactory();
- } catch (GeneralSecurityException e) {
- throw buildFatalFailure(logger, "Unable to create SSL socket factory", e);
+ OauthInterceptor(String token) {
+ this.token = token;
}
- }
-
- @VisibleForTesting
- TrustManager[] buildTrustManager() throws KeyStoreException, NoSuchAlgorithmException {
- if (skipCertificateVerification) {
- return new TrustManager[]{new AllTrustedTrustManager()};
- } else {
- if (StringUtils.isEmpty(trustedCertificates)) {
- throw new IllegalArgumentException("If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty");
- }
- Set<String> trustedPems;
- try {
- trustedPems = StoreLoader.getCertifacates(new String(BaseEncoding.base64().decode(trustedCertificates), StandardCharsets.UTF_8));
- } catch (Exception e) {
- throw new UserVisibleError("The trustedCertificates must be a base64 encoded collection of PEM certificates", e);
- }
- KeyStore keyStore = StoreLoader.loadStore(Joiner.on("\n").join(trustedPems), randomUUID().toString(), randomUUID().toString());
- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- trustManagerFactory.init(keyStore);
- return trustManagerFactory.getTrustManagers();
+ @Override
+ public Response intercept(Chain chain) throws IOException {
+ Request request = chain.request();
+ Request.Builder builder = request.newBuilder();
+ builder.addHeader("Authorization", "Bearer " + token);
+ Request request1 = builder.build();
+ return chain.proceed(request1);
}
}
@@ -207,23 +165,6 @@ public class CbamTokenProvider {
}
}
- static class AllTrustedTrustManager implements X509TrustManager {
- @Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- //no need to check certificates if everything is trusted
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- //no need to check certificates if everything is trusted
- }
-
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return new X509Certificate[0];
- }
- }
-
/**
* Represents the token received from CBAM
*/
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
index 94cb404c..085231f6 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
@@ -19,7 +19,6 @@ import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
import com.nokia.cbam.lcm.v32.api.VnfsApi;
import com.nokia.cbam.lcm.v32.model.OperationExecution;
@@ -285,12 +284,13 @@ public class JobManager {
}
private boolean isCurrentOperationTriggeredByJob(String jobId, OperationExecutionsApi cbamOperationExecutionApi, OperationExecution operationExecution) {
+
try {
- Object operationParams = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operationExecution.getId(), NOKIA_LCM_API_VERSION);
+ Object operationParams = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operationExecution.getId(), NOKIA_LCM_API_VERSION).blockingFirst();
if (extractOnapJobId(operationParams).equals(jobId)) {
return true;
}
- } catch (ApiException e) {
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to retrieve operation parameters", e);
}
return false;
@@ -301,7 +301,7 @@ public class JobManager {
//test if the VNF exists (required to be able to distingush between failed request )
VnfsApi cbamLcmApi = cbamRestApiProvider.getCbamLcmApi(vnfmId);
logger.debug("Listing VNFs");
- List<VnfInfo> vnfs = cbamLcmApi.vnfsGet(NOKIA_LCM_API_VERSION);
+ List<VnfInfo> vnfs = cbamLcmApi.vnfsGet(NOKIA_LCM_API_VERSION).blockingSingle();
com.google.common.base.Optional<VnfInfo> vnf = tryFind(vnfs, vnfInfo -> vnfId.equals(vnfInfo.getId()));
if (!vnf.isPresent()) {
logger.debug("VNF with {} identifier is missing", vnfId);
@@ -309,9 +309,9 @@ public class JobManager {
} else {
logger.debug("VNF with {} identifier still exists", vnfId);
//query the VNF again to get operation execution result
- return of(cbamLcmApi.vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION));
+ return of(cbamLcmApi.vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst());
}
- } catch (ApiException e) {
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to retrieve VNF", e);
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
index 79e9487d..d543f3ce 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
@@ -21,7 +21,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
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.ScaleDirection;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IGrantManager;
@@ -127,10 +126,10 @@ public class LifecycleManager {
* <li>terminate & delete VNF if error occurs after instantiation</li>
* </ul>
*
- * @param vnfmId the identifier of the VNFM
- * @param csarId the identifier of the VNF package
- * @param vnfName the name of the VNF
- * @param description the description of the VNF
+ * @param vnfmId the identifier of the VNFM
+ * @param csarId the identifier of the VNF package
+ * @param vnfName the name of the VNF
+ * @param description the description of the VNF
* @return the VNF creation result
*/
public VnfCreationResult create(String vnfmId, String csarId, String vnfName, String description) {
@@ -141,7 +140,7 @@ public class LifecycleManager {
vnfCreateRequest.setVnfdId(cbamPackage.getVnfdId());
vnfCreateRequest.setName(vnfName);
vnfCreateRequest.setDescription(description);
- com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsPost(vnfCreateRequest, NOKIA_LCM_API_VERSION);
+ com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsPost(vnfCreateRequest, NOKIA_LCM_API_VERSION).blockingFirst();
addVnfdIdToVnfModifyableAttributeExtensions(vnfmId, vnfInfo.getId(), csarId);
return new VnfCreationResult(vnfInfo, cbamPackage.getVnfdId());
} catch (Exception e) {
@@ -209,7 +208,7 @@ public class LifecycleManager {
return instantiate(vnfmId, request, httpResponse, additionalParameters, creationResult.vnfInfo.getId(), creationResult.vnfdId);
}
- private void instantiateVnf(String vnfmId, VnfInstantiateRequest request, AdditionalParameters additionalParameters, String vnfdId, String vnfId, String vimId, JobInfo jobInfo) throws ApiException {
+ private void instantiateVnf(String vnfmId, VnfInstantiateRequest request, AdditionalParameters additionalParameters, String vnfdId, String vnfId, String vimId, JobInfo jobInfo) {
String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, vnfdId);
GrantVNFResponseVim vim = grantManager.requestGrantForInstantiate(vnfmId, vnfId, vimId, request.getVnfPackageId(), additionalParameters.getInstantiationLevel(), vnfdContent, jobInfo.getJobId());
if (vim.getVimId() == null) {
@@ -238,7 +237,7 @@ public class LifecycleManager {
logger.warn("No additional parameters were specified for the operation");
}
instantiationRequest.setAdditionalParams(root);
- OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdInstantiatePost(vnfId, instantiationRequest, NOKIA_LCM_API_VERSION);
+ OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdInstantiatePost(vnfId, instantiationRequest, NOKIA_LCM_API_VERSION).blockingFirst();
waitForOperationToFinish(vnfmId, vnfId, operationExecution.getId());
}
@@ -281,11 +280,11 @@ public class LifecycleManager {
return childElement(deploymentFlavorProperties, "flavour_id").getAsString();
}
- private Set<String> getAcceptableOperationParameters(String vnfdContent, String categroryOfOperation, String operationName) {
+ private Set<Map.Entry<String, JsonElement>> getAcceptableOperationParameters(String vnfdContent, String categroryOfOperation, String operationName) {
JsonObject root = new Gson().toJsonTree(new Yaml().load(vnfdContent)).getAsJsonObject();
JsonObject interfaces = child(child(child(root, "topology_template"), "substitution_mappings"), "interfaces");
JsonObject additionalParameters = child(child(child(child(interfaces, categroryOfOperation), operationName), "inputs"), "additional_parameters");
- return additionalParameters.keySet();
+ return additionalParameters.entrySet();
}
private void addExternalLinksToRequest(List<ExtVirtualLinkInfo> extVirtualLinks, AdditionalParameters additionalParameters, InstantiateVnfRequest instantiationRequest, String vimId) {
@@ -316,9 +315,9 @@ public class LifecycleManager {
request.getExtensions().add(externalVnfmIdProperty);
request.setVnfConfigurableProperties(null);
try {
- OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdPatch(vnfId, request, NOKIA_LCM_API_VERSION);
+ OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdPatch(vnfId, request, NOKIA_LCM_API_VERSION).blockingFirst();
waitForOperationToFinish(vnfmId, vnfId, operationExecution.getId());
- } catch (ApiException e) {
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to set the " + ONAP_CSAR_ID + " property on the VNF", e);
}
}
@@ -428,7 +427,7 @@ public class LifecycleManager {
logOperationInput(vnfId, "termination", request);
return scheduleExecution(vnfId, httpResponse, "terminate", jobInfo -> {
TerminateVnfRequest cbamRequest = new TerminateVnfRequest();
- cbamRequest.setAdditionalParams(jobInfo);
+ //cbamRequest.setAdditionalParams(jobInfo);
if (request.getTerminationType() == null) {
cbamRequest.setTerminationType(TerminationType.FORCEFUL);
} else {
@@ -439,7 +438,7 @@ public class LifecycleManager {
cbamRequest.setTerminationType(TerminationType.FORCEFUL);
}
}
- com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION);
+ com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
if (vnf.getInstantiationState() == INSTANTIATED) {
terminateVnf(vnfmId, vnfId, jobInfo, cbamRequest, vnf);
} else {
@@ -448,10 +447,10 @@ public class LifecycleManager {
});
}
- private void terminateVnf(String vnfmId, String vnfId, JobInfo jobInfo, TerminateVnfRequest cbamRequest, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) throws ApiException {
+ private void terminateVnf(String vnfmId, String vnfId, JobInfo jobInfo, TerminateVnfRequest cbamRequest, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
String vimId = getVimIdFromInstantiationRequest(vnfmId, vnf);
grantManager.requestGrantForTerminate(vnfmId, vnfId, vimId, getVnfdIdFromModifyableAttributes(vnf), vnf, jobInfo.getJobId());
- OperationExecution terminationOperation = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdTerminatePost(vnfId, cbamRequest, NOKIA_LCM_API_VERSION);
+ OperationExecution terminationOperation = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdTerminatePost(vnfId, cbamRequest, NOKIA_LCM_API_VERSION).blockingFirst();
OperationExecution finishedOperation = waitForOperationToFinish(vnfmId, vnfId, terminationOperation.getId());
if (finishedOperation.getStatus() == FINISHED) {
notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId());
@@ -464,9 +463,9 @@ public class LifecycleManager {
}
}
- private String getVimIdFromInstantiationRequest(String vnfmId, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) throws ApiException {
+ private String getVimIdFromInstantiationRequest(String vnfmId, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
OperationExecution lastInstantiation = findLastInstantiation(vnf.getOperationExecutions());
- Object operationParameters = cbamRestApiProvider.getCbamOperationExecutionApi(vnfmId).operationExecutionsOperationExecutionIdOperationParamsGet(lastInstantiation.getId(), NOKIA_LCM_API_VERSION);
+ Object operationParameters = cbamRestApiProvider.getCbamOperationExecutionApi(vnfmId).operationExecutionsOperationExecutionIdOperationParamsGet(lastInstantiation.getId(), NOKIA_LCM_API_VERSION).blockingFirst();
JsonObject root = new Gson().toJsonTree(operationParameters).getAsJsonObject();
return childElement(childElement(root, "vims").getAsJsonArray().get(0).getAsJsonObject(), "id").getAsString();
}
@@ -482,7 +481,7 @@ public class LifecycleManager {
*/
public VnfInfo queryVnf(String vnfmId, String vnfId) {
try {
- com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION);
+ com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
VnfInfo vnfInfo = new VnfInfo();
vnfInfo.setVersion(cbamVnfInfo.getVnfSoftwareVersion());
vnfInfo.setVnfInstanceId(vnfId);
@@ -495,7 +494,7 @@ public class LifecycleManager {
vnfInfo.setVnfStatus("ACTIVE");
vnfInfo.setVnfType("Kuku");
return vnfInfo;
- } catch (ApiException e) {
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VNF (" + vnfId + ")", e);
}
}
@@ -519,28 +518,37 @@ public class LifecycleManager {
*/
public JobInfo scaleVnf(String vnfmId, String vnfId, VnfScaleRequest request, HttpServletResponse httpResponse) {
logOperationInput(vnfId, SCALE_OPERATION_NAME, request);
- return scheduleExecution(vnfId, httpResponse, SCALE_OPERATION_NAME, jobInfo -> {
- ScaleVnfRequest cbamRequest = new ScaleVnfRequest();
- cbamRequest.setAspectId(request.getAspectId());
- cbamRequest.setNumberOfSteps(Integer.valueOf(request.getNumberOfSteps()));
- cbamRequest.setType(convert(request.getType()));
- com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION);
- JsonObject root = new Gson().toJsonTree(jobInfo).getAsJsonObject();
- com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION);
- String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, cbamVnfInfo.getVnfdId());
- Set<String> acceptableOperationParameters = getAcceptableOperationParameters(vnfdContent, "Basic", SCALE_OPERATION_NAME);
- buildAdditionalParameters(request, root, acceptableOperationParameters);
- cbamRequest.setAdditionalParams(root);
- grantManager.requestGrantForScale(vnfmId, vnfId, getVimIdFromInstantiationRequest(vnfmId, vnf), getVnfdIdFromModifyableAttributes(vnf), request, jobInfo.getJobId());
- OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdScalePost(vnfId, cbamRequest, NOKIA_LCM_API_VERSION);
- waitForOperationToFinish(vnfmId, vnfId, operationExecution.getId());
+ return scheduleExecution(vnfId, httpResponse, SCALE_OPERATION_NAME, new AsynchronousExecution() {
+ @Override
+ public void execute(JobInfo jobInfo) {
+ ScaleVnfRequest cbamRequest = new ScaleVnfRequest();
+ cbamRequest.setAspectId(request.getAspectId());
+ cbamRequest.setNumberOfSteps(Integer.valueOf(request.getNumberOfSteps()));
+ cbamRequest.setType(convert(request.getType()));
+ com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
+ JsonObject root = new Gson().toJsonTree(jobInfo).getAsJsonObject();
+ com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
+ String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, cbamVnfInfo.getVnfdId());
+ Set<Map.Entry<String, JsonElement>> acceptableOperationParameters = getAcceptableOperationParameters(vnfdContent, "Basic", SCALE_OPERATION_NAME);
+ buildAdditionalParameters(request, root, acceptableOperationParameters);
+ cbamRequest.setAdditionalParams(root);
+ grantManager.requestGrantForScale(vnfmId, vnfId, getVimIdFromInstantiationRequest(vnfmId, vnf), getVnfdIdFromModifyableAttributes(vnf), request, jobInfo.getJobId());
+ OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdScalePost(vnfId, cbamRequest, NOKIA_LCM_API_VERSION).blockingFirst();
+ waitForOperationToFinish(vnfmId, vnfId, operationExecution.getId());
+ }
});
}
- private void buildAdditionalParameters(VnfScaleRequest request, JsonObject root, Set<String> acceptableOperationParameters) {
+ private void buildAdditionalParameters(VnfScaleRequest request, JsonObject root, Set<Map.Entry<String, JsonElement>> acceptableOperationParameters) {
if (request.getAdditionalParam() != null) {
for (Map.Entry<String, JsonElement> item : new Gson().toJsonTree(request.getAdditionalParam()).getAsJsonObject().entrySet()) {
- if (acceptableOperationParameters.contains(item.getKey())) {
+ boolean found = false;
+ for (Map.Entry<String, JsonElement> acceptableOperationParameter : acceptableOperationParameters) {
+ if (acceptableOperationParameter.getKey().equals(item.getKey())) {
+ found = true;
+ }
+ }
+ if (found) {
root.add(item.getKey(), item.getValue());
}
}
@@ -556,7 +564,7 @@ public class LifecycleManager {
* @param vnfId the identifier of the VNF
* @param request the heal request
* @param httpResponse the HTTP response
- * @param vnfcId the identifer of thr VNFC to be healed
+ * @param vnfcId the identifer of thr VNFC to be healed
* @return the job for tracking the heal
*/
public JobInfo healVnf(String vnfmId, String vnfId, VnfHealRequest request, Optional<String> vnfcId, HttpServletResponse httpResponse) {
@@ -569,10 +577,10 @@ public class LifecycleManager {
additionalParams.put("jobId", job.getJobId());
additionalParams.put("vnfcId", vnfcId.orElse("unknown"));
cbamHealRequest.setAdditionalParams(additionalParams);
- com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION);
+ com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
String vimId = getVimIdFromInstantiationRequest(vnfmId, vnf);
grantManager.requestGrantForHeal(vnfmId, vnfId, vimId, getVnfdIdFromModifyableAttributes(vnf), request, job.getJobId());
- OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdHealPost(vnfId, cbamHealRequest, NOKIA_LCM_API_VERSION);
+ OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdHealPost(vnfId, cbamHealRequest, NOKIA_LCM_API_VERSION).blockingFirst();
waitForOperationToFinish(vnfmId, vnfId, operationExecution.getId());
});
}
@@ -602,7 +610,7 @@ public class LifecycleManager {
private OperationExecution waitForOperationToFinish(String vnfmId, String vnfId, String operationExecutionId) {
while (true) {
try {
- OperationExecution operationExecution = find(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdOperationExecutionsGet(vnfId, NOKIA_LCM_API_VERSION), opEx -> operationExecutionId.equals(opEx.getId()));
+ OperationExecution operationExecution = find(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdOperationExecutionsGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst(), opEx -> operationExecutionId.equals(opEx.getId()));
if (hasOperationFinished(operationExecution)) {
logger.debug("Operation finished with " + operationExecution.getId());
return operationExecution;
@@ -621,12 +629,13 @@ public class LifecycleManager {
@FunctionalInterface
private interface AsynchronousExecution {
- void execute(JobInfo job) throws ApiException;
-
+ void execute(JobInfo job);
}
+
public static class VnfCreationResult {
private final com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo;
private final String vnfdId;
+
VnfCreationResult(com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo, String vnfdId) {
this.vnfInfo = vnfInfo;
this.vnfdId = vnfdId;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
index 6a31e833..d6fbd33f 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
@@ -20,7 +20,6 @@ import com.google.common.collect.Ordering;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
import com.nokia.cbam.lcm.v32.api.VnfsApi;
import com.nokia.cbam.lcm.v32.model.*;
@@ -118,7 +117,7 @@ public class LifecycleChangeNotificationManager implements ILifecycleChangeNotif
}
VnfsApi cbamLcmApi = restApiProvider.getCbamLcmApi(driverProperties.getVnfmId());
try {
- List<VnfInfo> vnfs = cbamLcmApi.vnfsGet(NOKIA_LCM_API_VERSION);
+ List<VnfInfo> vnfs = cbamLcmApi.vnfsGet(NOKIA_LCM_API_VERSION).blockingFirst();
com.google.common.base.Optional<VnfInfo> currentVnf = tryFind(vnfs, vnf -> vnf.getId().equals(receivedNotification.getVnfInstanceId()));
String vnfHeader = "The VNF with " + receivedNotification.getVnfInstanceId() + " identifier";
if (!currentVnf.isPresent()) {
@@ -126,7 +125,7 @@ public class LifecycleChangeNotificationManager implements ILifecycleChangeNotif
//swallow LCN
return;
} else {
- VnfInfo vnf = cbamLcmApi.vnfsVnfInstanceIdGet(receivedNotification.getVnfInstanceId(), NOKIA_LCN_API_VERSION);
+ VnfInfo vnf = cbamLcmApi.vnfsVnfInstanceIdGet(receivedNotification.getVnfInstanceId(), NOKIA_LCN_API_VERSION).blockingFirst();
com.google.common.base.Optional<VnfProperty> externalVnfmId = tryFind(vnf.getExtensions(), prop -> prop.getName().equals(LifecycleManager.EXTERNAL_VNFM_ID));
if (!externalVnfmId.isPresent()) {
logger.warn(vnfHeader + " is not a managed VNF");
@@ -141,18 +140,24 @@ public class LifecycleChangeNotificationManager implements ILifecycleChangeNotif
throw buildFatalFailure(logger, "Unable to list VNFs / query VNF", e);
}
OperationExecutionsApi cbamOperationExecutionApi = restApiProvider.getCbamOperationExecutionApi(driverProperties.getVnfmId());
+ List<OperationExecution> operationExecutions;
try {
- List<OperationExecution> operationExecutions = cbamLcmApi.vnfsVnfInstanceIdOperationExecutionsGet(receivedNotification.getVnfInstanceId(), NOKIA_LCM_API_VERSION);
- OperationExecution operationExecution = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdGet(receivedNotification.getLifecycleOperationOccurrenceId(), NOKIA_LCM_API_VERSION);
- OperationExecution closestInstantiationToOperation = findLastInstantiationBefore(operationExecutions, operationExecution);
- String vimId = getVimId(cbamOperationExecutionApi, closestInstantiationToOperation);
- notificationSender.processNotification(receivedNotification, operationExecution, buildAffectedCps(operationExecution), vimId);
- if (isTerminationFinished(receivedNotification)) {
- //signal LifecycleManager to continue the deletion of the VNF
- processedNotifications.add(new ProcessedNotification(receivedNotification.getLifecycleOperationOccurrenceId(), receivedNotification.getStatus()));
- }
- } catch (ApiException e) {
- throw buildFatalFailure(logger, "Unable to retrieve the current VNF " + receivedNotification.getVnfInstanceId(), e);
+ operationExecutions = cbamLcmApi.vnfsVnfInstanceIdOperationExecutionsGet(receivedNotification.getVnfInstanceId(), NOKIA_LCM_API_VERSION).blockingFirst();
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to retrieve the operation executions for the VNF " + receivedNotification.getVnfInstanceId(), e);
+ }
+ OperationExecution operationExecution;
+ try {
+ operationExecution = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdGet(receivedNotification.getLifecycleOperationOccurrenceId(), NOKIA_LCM_API_VERSION).blockingFirst();
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to retrieve the operation execution with " + receivedNotification.getLifecycleOperationOccurrenceId() + " identifier", e);
+ }
+ OperationExecution closestInstantiationToOperation = findLastInstantiationBefore(operationExecutions, operationExecution);
+ String vimId = getVimId(cbamOperationExecutionApi, closestInstantiationToOperation);
+ notificationSender.processNotification(receivedNotification, operationExecution, buildAffectedCps(operationExecution), vimId);
+ if (isTerminationFinished(receivedNotification)) {
+ //signal LifecycleManager to continue the deletion of the VNF
+ processedNotifications.add(new ProcessedNotification(receivedNotification.getLifecycleOperationOccurrenceId(), receivedNotification.getStatus()));
}
}
@@ -162,7 +167,7 @@ public class LifecycleChangeNotificationManager implements ILifecycleChangeNotif
private String getVimId(OperationExecutionsApi cbamOperationExecutionApi, OperationExecution closestInstantiationToOperation) {
try {
- Object operationParams = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(closestInstantiationToOperation.getId(), NOKIA_LCM_API_VERSION);
+ Object operationParams = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(closestInstantiationToOperation.getId(), NOKIA_LCM_API_VERSION).blockingFirst();
return getVimId(operationParams);
} catch (Exception e) {
throw buildFatalFailure(logger, "Unable to detect last instantiation operation", e);
diff --git a/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java b/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java
new file mode 100644
index 00000000..ffeb88f4
--- /dev/null
+++ b/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java
@@ -0,0 +1,28 @@
+/*
+ * 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 okhttp3;
+
+import javax.net.ssl.HostnameVerifier;
+
+public class OakExtractor {
+ /**
+ * Cheat access control durting tests
+ */
+ public static HostnameVerifier extract(OkHttpClient.Builder okBuilder) {
+ return okBuilder.hostnameVerifier;
+ }
+}
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());
}
}
diff --git a/nokiav2/driverwar/pom.xml b/nokiav2/driverwar/pom.xml
index a9a5c13c..d9c4a686 100644
--- a/nokiav2/driverwar/pom.xml
+++ b/nokiav2/driverwar/pom.xml
@@ -41,7 +41,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
- <version>1.5.10.RELEASE</version>
+ <version>${spring.boot.version}</version>
</dependency>
</dependencies>
<build>
@@ -49,6 +49,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
+ <version>3.2.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
@@ -62,7 +63,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
- <version>1.5.10.RELEASE</version>
+ <version>${spring.boot.version}</version>
<configuration>
<mainClass>org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.NokiaSvnfmApplication</mainClass>
<layout>ZIP</layout>
@@ -71,7 +72,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.5</version>
+ <version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
diff --git a/nokiav2/generatedapis/pom.xml b/nokiav2/generatedapis/pom.xml
index 1e2c7d98..21114bc3 100644
--- a/nokiav2/generatedapis/pom.xml
+++ b/nokiav2/generatedapis/pom.xml
@@ -26,6 +26,14 @@
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>vfc/nfvo/driver/vnfm/svnfm/nokiav2/generatedapis</name>
+ <properties>
+ <gson-fire-version>1.8.2</gson-fire-version>
+ <retrofit-version>2.3.0</retrofit-version>
+ <rxjava-version>2.0.0</rxjava-version>
+ <threetenbp-version>1.3.5</threetenbp-version>
+ <oltu-version>1.0.1</oltu-version>
+ <swagger-core-version>1.5.15</swagger-core-version>
+ </properties>
<build>
<plugins>
<plugin>
@@ -41,6 +49,7 @@
<configuration>
<inputSpec>${basedir}/src/main/resources/nokia.vnfm.api.v3.lcm.json</inputSpec>
<language>java</language>
+ <library>retrofit2</library>
<output>${project.build.directory}/generated-sources/cbam</output>
<apiPackage>com.nokia.cbam.lcm.v32.api</apiPackage>
<modelPackage>com.nokia.cbam.lcm.v32.model</modelPackage>
@@ -60,12 +69,15 @@
<configuration>
<inputSpec>${basedir}/src/main/resources/nokia.vnfm.api.v3.lcn.subscription.json</inputSpec>
<language>java</language>
+ <library>retrofit2</library>
<output>${project.build.directory}/generated-sources/cbam</output>
<apiPackage>com.nokia.cbam.lcn.v32.api</apiPackage>
<modelPackage>com.nokia.cbam.lcn.v32.model</modelPackage>
<configOptions>
<generateSupportingFiles>false</generateSupportingFiles>
<sourceFolder>src/gen/java/main</sourceFolder>
+ <withXml>true</withXml>
+ <useRxJava2>true</useRxJava2>
</configOptions>
</configuration>
</execution>
@@ -77,6 +89,7 @@
<configuration>
<inputSpec>${basedir}/src/main/resources/nokia.catalog.json</inputSpec>
<language>java</language>
+ <library>retrofit2</library>
<output>${project.build.directory}/generated-sources/cbam</output>
<apiPackage>com.nokia.cbam.catalog.v1.api</apiPackage>
<modelPackage>com.nokia.cbam.catalog.v1.model</modelPackage>
@@ -94,6 +107,7 @@
<configuration>
<inputSpec>${basedir}/src/main/resources/vfc.catalog.swagger.json</inputSpec>
<language>java</language>
+ <library>retrofit2</library>
<output>${project.build.directory}/generated-sources/vfccatalog</output>
<apiPackage>org.onap.vfccatalog.api</apiPackage>
<modelPackage>org.onap.vfccatalog.model</modelPackage>
@@ -111,6 +125,7 @@
<configuration>
<inputSpec>${basedir}/src/main/resources/vfc.vnfdriver.swagger.json</inputSpec>
<language>java</language>
+ <library>retrofit2</library>
<output>${project.build.directory}/generated-sources/vnfmdriver</output>
<apiPackage>org.onap.vnfmdriver.api</apiPackage>
<modelPackage>org.onap.vnfmdriver.model</modelPackage>
@@ -120,6 +135,26 @@
</configOptions>
</configuration>
</execution>
+<!--
+ <execution>
+ <id>soadapter</id>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <inputSpec>${basedir}/src/main/resources/so.vnfm.json</inputSpec>
+ <language>java</language>
+ <library>retrofit2</library>
+ <output>${project.build.directory}/generated-sources/soadapter</output>
+ <apiPackage>org.onap.soadapter.api</apiPackage>
+ <modelPackage>org.onap.soadapter.model</modelPackage>
+ <configOptions>
+ <generateSupportingFiles>false</generateSupportingFiles>
+ <sourceFolder>src/gen/java/main</sourceFolder>
+ </configOptions>
+ </configuration>
+ </execution>
+-->
</executions>
</plugin>
<plugin>
@@ -157,36 +192,49 @@
</build>
<dependencies>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.8.2</version>
- </dependency>
- <dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
- <version>1.5.16</version>
+ <version>${swagger-core-version}</version>
</dependency>
<dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>2.9.9</version>
+ <groupId>com.squareup.retrofit2</groupId>
+ <artifactId>converter-gson</artifactId>
+ <version>${retrofit-version}</version>
</dependency>
<dependency>
- <!-- this does not have a compile time dependency, but is required to be able to deserialize the date to joda time -->
- <groupId>com.fasterxml.jackson.datatype</groupId>
- <artifactId>jackson-datatype-joda</artifactId>
- <!-- this version must be in sync with the dependency comming from spring boot -->
- <version>2.8.10</version>
+ <groupId>com.squareup.retrofit2</groupId>
+ <artifactId>retrofit</artifactId>
+ <version>${retrofit-version}</version>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
- <artifactId>okhttp</artifactId>
- <version>2.7.5</version>
+ <groupId>com.squareup.retrofit2</groupId>
+ <artifactId>converter-scalars</artifactId>
+ <version>${retrofit-version}</version>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
- <artifactId>logging-interceptor</artifactId>
- <version>2.7.5</version>
+ <groupId>org.apache.oltu.oauth2</groupId>
+ <artifactId>org.apache.oltu.oauth2.client</artifactId>
+ <version>${oltu-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.gsonfire</groupId>
+ <artifactId>gson-fire</artifactId>
+ <version>${gson-fire-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.threeten</groupId>
+ <artifactId>threetenbp</artifactId>
+ <version>${threetenbp-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.reactivex.rxjava2</groupId>
+ <artifactId>rxjava</artifactId>
+ <version>${rxjava-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.squareup.retrofit2</groupId>
+ <artifactId>adapter-rxjava2</artifactId>
+ <version>${retrofit-version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -196,14 +244,10 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>io.gsonfire</groupId>
- <artifactId>gson-fire</artifactId>
- <version>1.8.2</version>
- </dependency>
- <dependency>
- <groupId>org.threeten</groupId>
- <artifactId>threetenbp</artifactId>
- <version>1.3.6</version>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>24.0-jre</version>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
diff --git a/nokiav2/generatedapis/src/test/java/TestInhertence.java b/nokiav2/generatedapis/src/test/java/TestInhertence.java
index 8e7d551e..f7e1108a 100644
--- a/nokiav2/generatedapis/src/test/java/TestInhertence.java
+++ b/nokiav2/generatedapis/src/test/java/TestInhertence.java
@@ -16,10 +16,19 @@
import com.nokia.cbam.lcm.v32.ApiClient;
import com.nokia.cbam.lcm.v32.model.*;
+import okhttp3.Headers;
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
+import okhttp3.internal.http.RealResponseBody;
+import okio.Buffer;
+import okio.BufferedSource;
import org.junit.Test;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+
import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
public class TestInhertence {
@@ -28,7 +37,7 @@ public class TestInhertence {
* test OpenStack v2 inheritence handling in serialization and deserialization
*/
@Test
- public void testOpenStackV2(){
+ public void testOpenStackV2() throws IOException{
InstantiateVnfRequest req = new InstantiateVnfRequest();
OPENSTACKV2INFO vim = new OPENSTACKV2INFO();
req.getVims().add(vim);
@@ -36,78 +45,32 @@ public class TestInhertence {
OpenStackAccessInfoV2 accessInfo = new OpenStackAccessInfoV2();
accessInfo.setPassword("myPassword");
vim.setAccessInfo(accessInfo);
- String serialize = new ApiClient().getJSON().serialize(req);
- assertTrue(serialize.contains("myPassword"));
- InstantiateVnfRequest deserialize = new ApiClient().getJSON().deserialize(serialize, InstantiateVnfRequest.class);
+ Annotation[] x = new Annotation[0];
+ RequestBody requestBody = new ApiClient().getAdapterBuilder().build().requestBodyConverter(InstantiateVnfRequest.class, x, new Annotation[0]).convert(req);
+ assertTrue(getContent(requestBody).contains("myPassword"));
+ ResponseBody responseBody = toResponse(requestBody);
+ InstantiateVnfRequest deserialize = (InstantiateVnfRequest) new ApiClient().getAdapterBuilder().build().responseBodyConverter(InstantiateVnfRequest.class, new Annotation[0]).convert(responseBody);
assertEquals(1, deserialize.getVims().size());
OPENSTACKV2INFO deserializedVim = (OPENSTACKV2INFO) deserialize.getVims().get(0);
assertEquals("myPassword", deserializedVim.getAccessInfo().getPassword());
}
- /**
- * test OpenStack v3 inheritence handling in serialization and deserialization
- */
- @Test
- public void testOpenStackV3(){
- InstantiateVnfRequest req = new InstantiateVnfRequest();
- OPENSTACKV3INFO vim = new OPENSTACKV3INFO();
- req.getVims().add(vim);
- vim.setVimInfoType(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
- OpenStackAccessInfoV3 accessInfo = new OpenStackAccessInfoV3();
- accessInfo.setPassword("myPassword");
- vim.setAccessInfo(accessInfo);
- String serialize = new ApiClient().getJSON().serialize(req);
- assertTrue(serialize.contains("myPassword"));
- InstantiateVnfRequest deserialize = new ApiClient().getJSON().deserialize(serialize, InstantiateVnfRequest.class);
- assertEquals(1, deserialize.getVims().size());
- OPENSTACKV3INFO deserializedVim = (OPENSTACKV3INFO) deserialize.getVims().get(0);
- assertEquals("myPassword", deserializedVim.getAccessInfo().getPassword());
- }
-
- /**
- * test vCloud inheritence handling in serialization and deserialization
- */
- @Test
- public void testVCloud(){
- InstantiateVnfRequest req = new InstantiateVnfRequest();
- VMWAREVCLOUDINFO vim = new VMWAREVCLOUDINFO();
- req.getVims().add(vim);
- vim.setVimInfoType(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
- VCloudAccessInfo accessInfo = new VCloudAccessInfo();
- accessInfo.setPassword("myPassword");
- vim.setAccessInfo(accessInfo);
- String serialize = new ApiClient().getJSON().serialize(req);
- assertTrue(serialize.contains("myPassword"));
- InstantiateVnfRequest deserialize = new ApiClient().getJSON().deserialize(serialize, InstantiateVnfRequest.class);
- assertEquals(1, deserialize.getVims().size());
- VMWAREVCLOUDINFO deserializedVim = (VMWAREVCLOUDINFO) deserialize.getVims().get(0);
- assertEquals("myPassword", deserializedVim.getAccessInfo().getPassword());
+ private ResponseBody toResponse(RequestBody convert) throws IOException {
+ Headers headers = new Headers.Builder().build();
+ Buffer buffer = new Buffer();
+ convert.writeTo(buffer);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ buffer.copyTo(byteArrayOutputStream);
+ BufferedSource response = buffer;
+ return new RealResponseBody(headers, response);
}
- /**
- * test LCN serialization and deserialization
- */
- @Test
- public void testLcn() throws Exception{
- VnfLifecycleChangeNotification vnfLifecycleChangeNotification = new VnfLifecycleChangeNotification();
- vnfLifecycleChangeNotification.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
- vnfLifecycleChangeNotification.setVnfInstanceId("myId");
- String serialize = new ApiClient().getJSON().serialize(vnfLifecycleChangeNotification);
- VnfLifecycleChangeNotification deserialize = new ApiClient().getJSON().deserialize(serialize, VnfLifecycleChangeNotification.class);
- assertEquals("myId", deserialize.getVnfInstanceId());
+ private String getContent(RequestBody requestBody) throws IOException {
+ Buffer buffer = new Buffer();
+ requestBody.writeTo(buffer);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ buffer.copyTo(byteArrayOutputStream);
+ return new String(byteArrayOutputStream.toByteArray());
}
- /**
- * test arrays are not initialized to empty arrays
- */
- @Test
- public void testArrayBehaviour() throws Exception{
- VnfLifecycleChangeNotification vnfLifecycleChangeNotification = new VnfLifecycleChangeNotification();
- vnfLifecycleChangeNotification.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
- vnfLifecycleChangeNotification.setVnfInstanceId("myId");
- String serialize = new ApiClient().getJSON().serialize(vnfLifecycleChangeNotification);
- VnfLifecycleChangeNotification deserialize = new ApiClient().getJSON().deserialize(serialize, VnfLifecycleChangeNotification.class);
- assertNull(deserialize.getAffectedVirtualLinks());
- }
-
}
diff --git a/nokiav2/pom.xml b/nokiav2/pom.xml
index 42adcf03..6ada74f7 100644
--- a/nokiav2/pom.xml
+++ b/nokiav2/pom.xml
@@ -16,14 +16,9 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <!--<groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>0.1.1</version>
- -->
-<!-- FIXME this artifact is not available in nexus-->
- <groupId>org.onap.vfc.nfvo.driver.vnfm.svnfm</groupId>
- <artifactId>vfc-nfvo-driver-vnfm-svnfm</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <groupId>org.onap.vfc.nfvo.driver.vnfm.svnfm</groupId>
+ <artifactId>vfc-nfvo-driver-vnfm-svnfm</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.vfc.nfvo.driver.vnfm.svnfm.nokiav2</groupId>
@@ -33,8 +28,34 @@
<name>vfc-nfvo-driver-vnfm-svnfm-nokiav2</name>
<properties>
<jacoco.version>0.8.0</jacoco.version>
- </properties>
-<modules>
+ <spring.boot.version>1.5.10.RELEASE</spring.boot.version>
+<!-- <spring.boot.version>2.0.0.RELEASE</spring.boot.version> -->
+ </properties>
+ <!--
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.4.1</version>
+ <executions>
+ <execution>
+ <id>enforce</id>
+ <configuration>
+ <rules>
+ <DependencyConvergence/>
+ </rules>
+ </configuration>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ -->
+ <modules>
<module>generatedapis</module>
<module>driver</module>
<module>driverwar</module>
diff --git a/pom.xml b/pom.xml
index ffe5bc6a..1625b41f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,7 @@
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
- <version>0.1.1</version>
+ <version>1.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.vfc.nfvo.driver.vnfm.svnfm</groupId>