summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-24 14:00:54 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-25 21:32:03 +0200
commitc82c886215ed34953a51dff0710c6bd15cb80ee4 (patch)
tree783f928ba8e033bbf55b6cffa343c7ea47c40b59 /nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm
parent1489e4215e075ab3ffe8f7158559a38778cd0b34 (diff)
Removing jackson to mitigate cve-2017-4995
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728 Change-Id: Ib495d4706361cc39527dfe86463aa505d9564afa
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm')
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java15
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java7
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java32
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java11
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java26
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java306
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java326
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java19
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java12
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java73
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java46
12 files changed, 475 insertions, 403 deletions
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
index 4109b132..a99e8d8d 100644
--- 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
@@ -17,14 +17,6 @@
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;
@@ -34,6 +26,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+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;
public class HttpTestServer {
public Server _server;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java
index d1afeac4..00cb83b8 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java
@@ -18,15 +18,14 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.collect.Maps;
import com.nokia.cbam.lcm.v32.model.NetworkAddress;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import org.junit.Test;
import pl.pojo.tester.internal.field.AbstractFieldValueChanger;
import pl.pojo.tester.internal.field.DefaultFieldValueChanger;
import pl.pojo.tester.internal.field.collections.map.AbstractMapFieldValueChanger;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor;
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 2489d3c2..190f78ee 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
@@ -22,6 +22,16 @@ 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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import javax.servlet.http.HttpServletResponse;
import okhttp3.RequestBody;
import okio.Buffer;
import org.apache.commons.lang3.ArrayUtils;
@@ -36,11 +46,12 @@ 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.msb.api.ServiceResourceApi;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.MsbApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AaiSecurityProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
import org.onap.vfccatalog.api.VnfpackageApi;
@@ -52,17 +63,6 @@ import org.springframework.test.util.ReflectionTestUtils;
import retrofit2.Call;
import retrofit2.Response;
-import javax.servlet.http.HttpServletResponse;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static org.mockito.Mockito.when;
@@ -83,6 +83,8 @@ public class TestBase {
@Mock
protected MsbApiProvider msbApiProvider;
@Mock
+ protected AaiSecurityProvider aaiSecurityProvider;
+ @Mock
protected VnfmInfoProvider vnfmInfoProvider;
@Mock
protected VnfsApi vnfApi;
@@ -95,7 +97,7 @@ public class TestBase {
@Mock
protected SubscriptionsApi lcnApi;
@Mock
- protected MSBServiceClient msbClient;
+ protected ServiceResourceApi msbClient;
@Mock
protected DriverProperties driverProperties;
@Mock
@@ -142,7 +144,7 @@ public class TestBase {
when(cbamRestApiProvider.getCbamOperationExecutionApi(VNFM_ID)).thenReturn(operationExecutionApi);
when(cbamRestApiProvider.getCbamLcnApi(VNFM_ID)).thenReturn(lcnApi);
when(cbamRestApiProvider.getCbamCatalogApi(VNFM_ID)).thenReturn(cbamCatalogApi);
- when(msbApiProvider.getMsbClient()).thenReturn(msbClient);
+ when(msbApiProvider.getMsbApi()).thenReturn(msbClient);
when(vfcRestApiProvider.getNsLcmApi()).thenReturn(nsLcmApi);
when(vfcRestApiProvider.getVfcCatalogApi()).thenReturn(vfcCatalogApi);
when(systemFunctions.getHttpClient()).thenReturn(httpClient);
@@ -194,7 +196,7 @@ public class TestBase {
return files;
}
- protected void setFieldWithPropertyAnnotation(Object obj, String key, String value) {
+ protected void setFieldWithPropertyAnnotation(Object obj, String key, Object value) {
for (Field field : obj.getClass().getDeclaredFields()) {
for (Value fieldValue : field.getAnnotationsByType(Value.class)) {
if (fieldValue.value().equals(key)) {
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 1425d97c..90e064a2 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,11 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import okhttp3.Headers;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
@@ -33,12 +38,6 @@ 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.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import static junit.framework.TestCase.*;
import static org.junit.Assert.assertArrayEquals;
import static org.mockito.Mockito.*;
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
index cb541278..e21e638a 100644
--- 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
@@ -21,27 +21,24 @@ 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 java.util.ArrayList;
+import java.util.Map;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
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.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.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.*;
@@ -72,7 +69,7 @@ public class TestCbamRestApiProvider extends TestBase {
private Interceptor interceptor;
@Mock
private HostnameVerifier hostnameVerifier;
- private Set<NodeInfo> nodes = new HashSet<>();
+ private java.util.List<NodeInfo> nodes = new ArrayList<>();
private CbamRestApiProvider cbamRestApiProvider;
private CbamSecurityProvider cbamSecurityProvider = spy(new CbamSecurityProvider());
@@ -102,13 +99,12 @@ public class TestCbamRestApiProvider extends TestBase {
//when
ApiClient cbamLcmApi = cbamRestApiProvider.buildLcmApiClient(VNFM_ID);
//verify
- String actual = cbamLcmApi.getAdapterBuilder().build().baseUrl().toString();
- assertEquals("https://cbamurl:123/d/", actual);
+ assertEquals("https://cbamurl:123/d/", cbamLcmApi.getAdapterBuilder().build().baseUrl().toString());
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()));
+ assertEquals(hostnameVerifier, cbamLcmApi.getOkBuilder().build().hostnameVerifier());
}
/**
@@ -130,7 +126,7 @@ public class TestCbamRestApiProvider extends TestBase {
Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
assertEquals(1, apiAuthorizations.size());
assertEquals(interceptor, apiAuthorizations.values().iterator().next());
- assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ assertEquals(hostnameVerifier, cbamLcmApi.getOkBuilder().build().hostnameVerifier());
}
/**
@@ -152,7 +148,7 @@ public class TestCbamRestApiProvider extends TestBase {
Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
assertEquals(1, apiAuthorizations.size());
assertEquals(interceptor, apiAuthorizations.values().iterator().next());
- assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ assertEquals(hostnameVerifier, cbamLcmApi.getOkBuilder().build().hostnameVerifier());
}
/**
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
index 17c68e41..55d949e3 100644
--- 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
@@ -16,312 +16,26 @@
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.assertEquals;
-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);
- }
+ private CbamSecurityProvider securityProvider = new CbamSecurityProvider();
/**
- * empty trusted pem results in error if verification is required
+ * test property handling
*/
@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());
- }
- }
+ public void init() throws Exception {
+ setFieldWithPropertyAnnotation(securityProvider, "${skipCertificateVerification}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${skipHostnameVerification}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${trustedCertificates}", "cert");
- 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();
+ assertEquals(true, securityProvider.skipCertificateVerification());
+ assertEquals(true, securityProvider.skipHostnameVerification());
+ assertEquals("cert", securityProvider.trustedCertificates());
}
}
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 699a5900..7c1b1179 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,6 +16,8 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
+import java.io.IOException;
+import java.net.URI;
import okhttp3.Interceptor;
import okhttp3.Request;
import org.junit.After;
@@ -27,9 +29,6 @@ import org.mockito.Mockito;
import org.onap.vnfmdriver.model.VnfmInfo;
import org.springframework.http.HttpStatus;
-import java.io.IOException;
-import java.net.URI;
-
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java
new file mode 100644
index 00000000..8823b2e0
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java
@@ -0,0 +1,326 @@
+/*
+ * 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 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+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 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 TestGenericSecurityProvider extends TestBase {
+ GenericSecurityProvider 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/TestJobManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
index bed25400..743fb95e 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
@@ -20,6 +20,14 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.nokia.cbam.lcm.v32.model.*;
import io.reactivex.Observable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -34,15 +42,6 @@ import org.onap.vnfmdriver.model.JobStatus;
import org.springframework.test.util.ReflectionTestUtils;
import org.threeten.bp.OffsetDateTime;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.UUID;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
import static junit.framework.TestCase.*;
import static org.mockito.Mockito.*;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
@@ -425,7 +424,7 @@ public class TestJobManager extends TestBase {
fail();
} catch (RuntimeException e) {
assertEquals(expectedException, e.getCause());
- verify(logger).error("Unable to retrieve operation parameters of operation with " + operation.getId() +" identifier", expectedException);
+ verify(logger).error("Unable to retrieve operation parameters of operation with " + operation.getId() + " identifier", expectedException);
}
assertTrue(jobManager.hasOngoingJobs());
}
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 9095eea3..b7e30e2c 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
@@ -25,6 +25,9 @@ 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 java.nio.file.Paths;
+import java.util.*;
+import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -43,13 +46,10 @@ import org.onap.vnfmdriver.model.*;
import org.onap.vnfmdriver.model.ScaleDirection;
import org.threeten.bp.OffsetDateTime;
-import javax.servlet.http.HttpServletResponse;
-import java.nio.file.Paths;
-import java.util.*;
-
import static java.lang.Boolean.parseBoolean;
import static java.nio.file.Files.readAllBytes;
import static java.util.Optional.empty;
+
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
@@ -746,6 +746,8 @@ public class TestLifecycleManager extends TestBase {
return buildObservable(terminationOperation);
}
});
+ Observable<Void> delete = Mockito.mock(Observable.class);
+ when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(delete);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
@@ -754,10 +756,12 @@ public class TestLifecycleManager extends TestBase {
waitForJobToFinishInJobManager(finished);
assertEquals(1, actualTerminationRequest.getAllValues().size());
assertEquals(TerminationType.FORCEFUL, actualTerminationRequest.getValue().getTerminationType());
+ assertEquals(JOB_ID, new Gson().toJsonTree(actualTerminationRequest.getValue().getAdditionalParams()).getAsJsonObject().get("jobId").getAsString());
InOrder notificationIsProcessedBeforeDeletingTheVnf = Mockito.inOrder(vfcGrantManager, notificationManager, vnfApi);
notificationIsProcessedBeforeDeletingTheVnf.verify(vfcGrantManager).requestGrantForTerminate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, vnfInfo, JOB_ID);
notificationIsProcessedBeforeDeletingTheVnf.verify(notificationManager).waitForTerminationToBeProcessed("terminationId");
notificationIsProcessedBeforeDeletingTheVnf.verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
+ verify(systemFunctions).blockingFirst(delete);
verify(jobManager).spawnJob(VNF_ID, restResponse);
verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("termination"), eq(VNF_ID), anyString());
}
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 ffbda145..d668262f 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
@@ -20,35 +20,34 @@ import com.nokia.cbam.lcn.v32.model.CreateSubscriptionRequest;
import com.nokia.cbam.lcn.v32.model.Subscription;
import com.nokia.cbam.lcn.v32.model.SubscriptionAuthentication;
import com.nokia.cbam.lcn.v32.model.VnfNotificationType;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.mockito.*;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.msb.sdk.discovery.common.RouteException;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
-import org.onap.msb.sdk.discovery.entity.Node;
-import org.onap.msb.sdk.discovery.entity.RouteResult;
+import org.onap.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.MicroServiceInfo;
+import org.onap.msb.model.Node;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
-
import static com.nokia.cbam.lcn.v32.model.OperationType.*;
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
+import static org.onap.msb.model.MicroServiceInfo.ProtocolEnum.REST;
+import static org.onap.msb.model.MicroServiceInfo.VisualRangeEnum._1;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCN_API_VERSION;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestSelfRegistrationManager extends TestBase {
@Mock
private JobManager jobManager;
- private List<Subscription> subscriptions = new ArrayList<>();
+ private java.util.List<Subscription> subscriptions = new ArrayList<>();
private ArgumentCaptor<MicroServiceInfo> registeredMicroservice = ArgumentCaptor.forClass(MicroServiceInfo.class);
private ArgumentCaptor<CreateSubscriptionRequest> subscriptionToCreate = ArgumentCaptor.forClass(CreateSubscriptionRequest.class);
@InjectMocks
@@ -79,13 +78,13 @@ public class TestSelfRegistrationManager extends TestBase {
Subscription subscription = new 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(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenReturn(buildObservable(returnedMicroService));
//when
selfRegistrationManager.register();
//verify
InOrder registrationOrder = Mockito.inOrder(lcnApi, msbClient);
registrationOrder.verify(lcnApi).subscriptionsPost(any(), any());
- registrationOrder.verify(msbClient).registerMicroServiceInfo(any());
+ registrationOrder.verify(msbClient).addMicroService(any(), any(), any());
assertMicroserviceRegistered();
assertNewLcnSubscription();
@@ -111,6 +110,7 @@ public class TestSelfRegistrationManager extends TestBase {
assertTrue(subscriptionCreation.getFilter().getOperationTypes().contains(TERMINATE));
assertTrue(subscriptionCreation.getFilter().getOperationTypes().contains(INSTANTIATE));
assertEquals(4, subscriptionCreation.getFilter().getOperationTypes().size());
+ verify(logger).info("Subscribing to CBAM LCN {} with callback to {}", driverProperties.getCbamLcnUrl(), "http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
}
private void assertMicroserviceRegistered() {
@@ -120,16 +120,15 @@ public class TestSelfRegistrationManager extends TestBase {
assertEquals("0", node.getTtl());
assertEquals("1.2.3.4", node.getIp());
assertEquals("12345", node.getPort());
- assertEquals("REST", microserviceRequest.getProtocol());
+ assertEquals(REST, microserviceRequest.getProtocol());
assertNull(microserviceRequest.getMetadata());
//very strange, but it should be null for ONAP to work
- assertEquals("", microserviceRequest.getPath());
assertEquals(SelfRegistrationManager.SERVICE_NAME, microserviceRequest.getServiceName());
assertEquals("/api/NokiaSVNFM/v1", microserviceRequest.getUrl());
assertEquals("v1", microserviceRequest.getVersion());
- assertEquals(false, microserviceRequest.isEnable_ssl());
+ assertEquals(Boolean.FALSE, microserviceRequest.isEnableSsl());
//1 means internal service to ONAP
- assertEquals("1", microserviceRequest.getVisualRange());
+ assertEquals(_1, microserviceRequest.getVisualRange());
}
/**
@@ -139,7 +138,7 @@ public class TestSelfRegistrationManager extends TestBase {
public void testResubscription() throws Exception {
//given
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
- when(msbClient.registerMicroServiceInfo(registeredMicroservice.capture())).thenReturn(returnedMicroService);
+ when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenReturn(buildObservable(returnedMicroService));
Subscription existingSubscription = new Subscription();
existingSubscription.setId(UUID.randomUUID().toString());
existingSubscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
@@ -168,7 +167,7 @@ public class TestSelfRegistrationManager extends TestBase {
assertEquals(expectedException, e.getCause());
}
//verify
- verify(msbClient, never()).registerMicroServiceInfo(any());
+ verify(msbClient, never()).addMicroService(any(), any(), any());
verify(logger).error("Unable to subscribe to CBAM LCN", expectedException);
assertServiceDown();
}
@@ -187,8 +186,8 @@ public class TestSelfRegistrationManager extends TestBase {
return buildObservable(subscription);
});
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
- RouteException expectedException = new RouteException();
- when(msbClient.registerMicroServiceInfo(registeredMicroservice.capture())).thenThrow(expectedException);
+ RuntimeException expectedException = new RuntimeException();
+ when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenThrow(expectedException);
//when
try {
selfRegistrationManager.register();
@@ -216,14 +215,17 @@ public class TestSelfRegistrationManager extends TestBase {
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
when(jobManager.hasOngoingJobs()).thenReturn(false);
- MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
+ Observable delete = Mockito.mock(Observable.class);
+ when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(delete);
//when
selfRegistrationManager.deRegister();
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
+ verify(systemFunctions).blockingFirst(delete);
+ verify(logger).info("Deleting subscription with {} identifier", subscription.getId());
}
/**
@@ -238,11 +240,11 @@ public class TestSelfRegistrationManager extends TestBase {
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
when(jobManager.hasOngoingJobs()).thenReturn(false);
- when(msbClient.cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION)).then(new Answer<RouteResult>() {
+ when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
@Override
- public RouteResult answer(InvocationOnMock invocationOnMock) throws Throwable {
- when(msbClient.queryMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION)).thenThrow(new RouteException());
- throw new RouteException();
+ public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ when(msbClient.getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null)).thenThrow(new RuntimeException());
+ throw new RuntimeException();
}
});
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
@@ -250,8 +252,8 @@ public class TestSelfRegistrationManager extends TestBase {
selfRegistrationManager.deRegister();
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
- inOrder.verify(msbClient).queryMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
+ inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
@@ -266,13 +268,12 @@ public class TestSelfRegistrationManager extends TestBase {
subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
- when(msbClient.cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION)).then(new Answer<RouteResult>() {
+ when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
@Override
- public RouteResult answer(InvocationOnMock invocationOnMock) throws Throwable {
- throw new RouteException();
+ public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ throw new RuntimeException();
}
});
- MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
//when
try {
selfRegistrationManager.deRegister();
@@ -282,8 +283,8 @@ public class TestSelfRegistrationManager extends TestBase {
}
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
- inOrder.verify(msbClient).queryMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
+ inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null);
verify(lcnApi, Mockito.never()).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
@@ -310,7 +311,7 @@ public class TestSelfRegistrationManager extends TestBase {
}
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
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 dc1b8ddf..922e92bb 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
@@ -17,6 +17,11 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification;
import com.google.gson.*;
import com.nokia.cbam.lcm.v32.model.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import java.util.concurrent.*;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -26,11 +31,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.threeten.bp.OffsetDateTime;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Optional;
-import java.util.concurrent.*;
+import static java.util.Optional.empty;
import static com.nokia.cbam.lcm.v32.model.OperationType.*;
import static junit.framework.TestCase.*;
@@ -95,7 +96,6 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
}
private void prepOperation(OperationExecution operationExecution) {
- addEmptyModifiedConnectionPoints(operationExecution);
JsonElement root = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + JOB_ID + "\"}}");
operationExecution.setOperationParams(root);
switch (operationExecution.getOperationType()) {
@@ -349,6 +349,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
secondTerminationOperationExecution.setOperationParams(buildTerminationParams());
nonProcessedEvent.setLifecycleOperationOccurrenceId(secondTerminationOperationExecution.getId());
lifecycleChangeNotificationManager.handleLcn(nonProcessedEvent);
+ addEmptyModifiedConnectionPoints(terminationOperation);
//add second termination
recievedLcn.setOperation(OperationType.TERMINATE);
recievedLcn.setStatus(OperationStatus.FINISHED);
@@ -401,6 +402,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
lifecycleChangeNotificationManager.handleLcn(recievedLcn);
//verify
assertTrue(waitExitedWithSuccess.get());
+ assertEquals(empty(), affectedConnectionPoints.getValue());
}
/**
@@ -443,6 +445,34 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
verify(logger).warn("The operation failed and the affected connection points were not reported");
}
+
+ /**
+ * affected connection points are passed to the actual notification processor
+ */
+ @Test
+ public void testAffectedConnectionPointProcessing() throws Exception {
+ //given
+ recievedLcn.setOperation(OperationType.INSTANTIATE);
+ recievedLcn.setStatus(OperationStatus.FINISHED);
+ recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId());
+ instantiationOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(instantiationOperation);
+ OperationResult operationResult = new OperationResult();
+ ReportedAffectedConnectionPoints affectedCp = new ReportedAffectedConnectionPoints();
+ ReportedAffectedCp cp = new ReportedAffectedCp();
+ cp.setCpId("cpId");
+ affectedCp.getPost().add(cp);
+ operationResult.operationResult = affectedCp;
+ instantiationOperation.setAdditionalData(new Gson().toJsonTree(operationResult));
+
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ //verify
+ assertTrue(affectedConnectionPoints.getValue().isPresent());
+ ReportedAffectedConnectionPoints actualCps = new Gson().fromJson(new Gson().toJsonTree(affectedConnectionPoints.getValue().get()), ReportedAffectedConnectionPoints.class);
+ assertEquals(1, actualCps.getPost().size());
+ }
+
/**
* Failures in affected connection point processing are tolerated for failed operation
* (because the POST script was not able to run)
@@ -454,6 +484,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
recievedLcn.setStatus(OperationStatus.FAILED);
recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId());
instantiationOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(instantiationOperation);
JsonObject additionalData = (JsonObject) instantiationOperation.getAdditionalData();
additionalData.remove("operationResult");
//when
@@ -500,8 +531,10 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
request.setType(ScaleDirection.OUT);
scaleOperation.setOperationParams(request);
scaleOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(scaleOperation);
((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject().remove("cbam_post");
scaleOperation.setOperationType(OperationType.SCALE);
+
//when
lifecycleChangeNotificationManager.handleLcn(recievedLcn);
assertFalse(affectedConnectionPoints.getValue().isPresent());
@@ -522,6 +555,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
request.setType(ScaleDirection.OUT);
scaleOperation.setOperationParams(request);
scaleOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(scaleOperation);
JsonObject operationResult = ((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject();
operationResult.remove("cbam_post");
operationResult.addProperty("cbam_post", "");