summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/test/java
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
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')
-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.java2
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java1
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java61
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java51
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java310
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java42
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java7
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java8
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java146
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java94
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java32
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java84
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java25
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java74
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java10
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java6
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java7
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java15
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java1
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java2
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java11
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java29
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java1
-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
43 files changed, 1042 insertions, 910 deletions
diff --git a/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java b/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java
deleted file mode 100644
index ffeb88f4..00000000
--- a/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java
+++ /dev/null
@@ -1,28 +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 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 f0b24762..640097f3 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
@@ -41,8 +41,6 @@ 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({
TestGenericExternalSystemInfoProvider.class,
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java
index 78939fdf..2bd0820c 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java
@@ -18,6 +18,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.ct;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.*;
+import java.util.ArrayList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.NokiaSvnfmApplication;
@@ -32,8 +33,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
-import java.util.ArrayList;
-
import static java.util.Optional.of;
@RunWith(value = SpringRunner.class)
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
index a0d4ea4d..efa45234 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
@@ -26,6 +26,7 @@ import org.springframework.core.env.Environment;
import org.springframework.test.util.ReflectionTestUtils;
import static java.lang.Long.valueOf;
+
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.*;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
index eb3674c3..a0565206 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
@@ -16,20 +16,20 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.onap.msb.sdk.discovery.common.RouteException;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.NodeInfo;
-import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+import org.onap.msb.ApiClient;
+import org.onap.msb.api.ServiceResourceApi;
+import org.onap.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.NodeInfo;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamTokenProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.springframework.core.env.Environment;
-import java.util.HashSet;
-import java.util.Set;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.verify;
@@ -42,7 +42,7 @@ public class TestMsbApiProvider extends TestBase {
@Mock
private CbamTokenProvider cbamTokenProvider;
private MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
- private Set<NodeInfo> nodes = new HashSet<>();
+ private List<NodeInfo> nodes = new ArrayList<>();
private MsbApiProvider msbApiProvider;
@Before
@@ -60,9 +60,9 @@ public class TestMsbApiProvider extends TestBase {
setFieldWithPropertyAnnotation(msbApiProvider, "${messageBusIp}", "mymessageBusIp");
setFieldWithPropertyAnnotation(msbApiProvider, "${messageBusPort}", "123");
//when
- MSBServiceClient msbClient = msbApiProvider.getMsbClient();
+ ApiClient msbClient = msbApiProvider.buildApiClient();
//verify
- assertEquals("mymessageBusIp:123", msbClient.getMsbSvrAddress());
+ assertEquals("http://mymessagebusip:123/api/msdiscover/v1/", msbClient.getAdapterBuilder().build().baseUrl().toString());
}
/**
@@ -79,18 +79,34 @@ public class TestMsbApiProvider extends TestBase {
nodes.add(dockerAccessPoint);
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(buildObservable(microServiceInfo));
//when
try {
msbApiProvider.getMicroServiceUrl("serviceName", "v1");
fail();
} catch (Exception e) {
- assertEquals("The serviceName service with v1 does not have any valid nodes[172.1.2.3:null ttl:]", e.getMessage());
- verify(logger).error("The serviceName service with v1 does not have any valid nodes[172.1.2.3:null ttl:]");
+ String msg = "The serviceName service with v1 does not have any valid nodes[class NodeInfo {\n" +
+ " ip: 172.1.2.3\n" +
+ " port: null\n" +
+ " lbServerParams: null\n" +
+ " checkType: null\n" +
+ " checkUrl: null\n" +
+ " checkInterval: null\n" +
+ " checkTimeOut: null\n" +
+ " ttl: null\n" +
+ " haRole: null\n" +
+ " nodeId: null\n" +
+ " status: null\n" +
+ " expiration: null\n" +
+ " createdAt: null\n" +
+ " updatedAt: null\n" +
+ "}]";
+ assertEquals(msg, e.getMessage());
+ verify(logger).error(msg);
}
}
@@ -109,11 +125,11 @@ public class TestMsbApiProvider extends TestBase {
nodes.add(nonDocker);
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(buildObservable(microServiceInfo));
msbApiProvider.afterPropertiesSet();
//when
assertEquals("http://1.2.3.4:234/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1"));
@@ -131,16 +147,16 @@ public class TestMsbApiProvider extends TestBase {
microServiceInfo.setServiceName("serviceName");
microServiceInfo.setVersion("v1");
microServiceInfo.setUrl("/lead/nslcm/v1");
- microServiceInfo.setEnable_ssl(true);
+ microServiceInfo.setEnableSsl(true);
when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("173.1.2.3->1.2.3.4");
nodes.add(nonDocker);
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(buildObservable(microServiceInfo));
msbApiProvider.afterPropertiesSet();
//when
assertEquals("https://1.2.3.4:123/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1"));
@@ -153,13 +169,12 @@ public class TestMsbApiProvider extends TestBase {
public void testUnableQueryMicroserviInfo() throws Exception {
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- RouteException expectedException = new RouteException();
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenThrow(expectedException);
-
+ RuntimeException expectedException = new RuntimeException();
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(Observable.error(expectedException));
//when
try {
msbApiProvider.getMicroServiceUrl("serviceName", "v1");
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
index c1da617e..912a2209 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
@@ -15,13 +15,15 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.EsrSystemInfo;
-import org.onap.aai.domain.yang.v11.EsrSystemInfoList;
-import org.onap.aai.domain.yang.v11.EsrVnfm;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
+import org.onap.aai.api.CloudInfrastructureApi;
+import org.onap.aai.api.ExternalSystemApi;
+import org.onap.aai.model.CloudRegion;
+import org.onap.aai.model.EsrSystemInfo;
+import org.onap.aai.model.EsrVnfm;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.onap.vnfmdriver.model.VimInfo;
import org.onap.vnfmdriver.model.VnfmInfo;
@@ -33,15 +35,20 @@ import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestAAIExternalSystemInfoProvider extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private AAIExternalSystemInfoProvider aaiExternalSystemInfoProvider;
@Mock
private AAIRestApiProvider aaiRestApiProvider;
+ @Mock
+ private ExternalSystemApi externalSystemApi;
+ @Mock
+ private CloudInfrastructureApi cloudInfrastructureApi;
@Before
public void init() {
- aaiExternalSystemInfoProvider = new AAIExternalSystemInfoProvider(environment, aaiRestApiProvider);
setField(AAIExternalSystemInfoProvider.class, "logger", logger);
+ aaiExternalSystemInfoProvider = new AAIExternalSystemInfoProvider(environment, aaiRestApiProvider);
+ when(aaiRestApiProvider.getExternalSystemApi()).thenReturn(externalSystemApi);
+ when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi);
}
/**
@@ -49,9 +56,10 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testVim() throws Exception {
- EsrSystemInfoList vims = OBJECT_FACTORY.createEsrSystemInfoList();
- EsrSystemInfo vim = OBJECT_FACTORY.createEsrSystemInfo();
- vims.getEsrSystemInfo().add(vim);
+ CloudRegion cloudRegion = new CloudRegion();
+ cloudRegion.setEsrSystemInfoList(new ArrayList<>());
+ EsrSystemInfo vim = new EsrSystemInfo();
+ cloudRegion.getEsrSystemInfoList().add(vim);
vim.setPassword("myPassword");
vim.setUserName("myUsername");
vim.setServiceUrl("http://1.2.3.4:1234/a");
@@ -61,7 +69,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
vim.setType("type");
vim.setSslInsecure(true);
vim.setVendor("vendor");
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/esr-system-info-list", EsrSystemInfoList.class)).thenReturn(vims);
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenReturn(buildObservable(cloudRegion));
//when
VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
assertEquals("myPassword", vimInfo.getPassword());
@@ -84,9 +92,10 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testVimSsl() throws Exception {
- EsrSystemInfoList vims = OBJECT_FACTORY.createEsrSystemInfoList();
- EsrSystemInfo vim = OBJECT_FACTORY.createEsrSystemInfo();
- vims.getEsrSystemInfo().add(vim);
+ CloudRegion cloudRegion = new CloudRegion();
+ cloudRegion.setEsrSystemInfoList(new ArrayList<>());
+ EsrSystemInfo vim = new EsrSystemInfo();
+ cloudRegion.getEsrSystemInfoList().add(vim);
vim.setPassword("myPassword");
vim.setUserName("myUsername");
vim.setServiceUrl("https://1.2.3.4:1234/a");
@@ -97,7 +106,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
vim.setSslInsecure(false);
vim.setSslCacert("cert");
vim.setVendor("vendor");
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/esr-system-info-list", EsrSystemInfoList.class)).thenReturn(vims);
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenReturn(buildObservable(cloudRegion));
//when
VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
assertEquals("myPassword", vimInfo.getPassword());
@@ -120,7 +129,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
@Test
public void testVimUnableToQuery() throws Exception {
RuntimeException expectedException = new RuntimeException();
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/esr-system-info-list", EsrSystemInfoList.class)).thenThrow(expectedException);
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenThrow(expectedException);
//when
try {
aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
@@ -136,11 +145,11 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testVnfmQuery() throws Exception {
- EsrVnfm vnfm = OBJECT_FACTORY.createEsrVnfm();
+ EsrVnfm vnfm = new EsrVnfm();
vnfm.setVimId(VIM_ID);
- vnfm.setEsrSystemInfoList(OBJECT_FACTORY.createEsrSystemInfoList());
- EsrSystemInfo esrInfo = OBJECT_FACTORY.createEsrSystemInfo();
- vnfm.getEsrSystemInfoList().getEsrSystemInfo().add(esrInfo);
+ vnfm.setEsrSystemInfoList(new ArrayList<>());
+ EsrSystemInfo esrInfo = new EsrSystemInfo();
+ vnfm.getEsrSystemInfoList().add(esrInfo);
esrInfo.setPassword("myPassword");
esrInfo.setUserName("myUsername");
esrInfo.setServiceUrl("https://1.2.3.4:1234/a");
@@ -152,7 +161,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
esrInfo.setSslCacert("cert");
esrInfo.setVendor("vendor");
vnfm.setVnfmId(VNFM_ID);
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.ESR, "/esr-vnfm-list/esr-vnfm/" + VNFM_ID + "?depth=all", EsrVnfm.class)).thenReturn(vnfm);
+ when(externalSystemApi.getExternalSystemEsrVnfmListEsrVnfm(VNFM_ID)).thenReturn(buildObservable(vnfm));
//when
VnfmInfo actualVnfmInfo = aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
@@ -176,7 +185,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
@Test
public void testVnfmUnableToQuery() throws Exception {
RuntimeException expectedException = new RuntimeException();
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.ESR, "/esr-vnfm-list/esr-vnfm/" + VNFM_ID + "?depth=all", EsrVnfm.class)).thenThrow(expectedException);
+ when(externalSystemApi.getExternalSystemEsrVnfmListEsrVnfm(VNFM_ID)).thenThrow(expectedException);
//when
try {
aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
index 953f7da0..9c53aba1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
@@ -15,224 +15,216 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
+import okhttp3.Protocol;
+import okhttp3.Request;
+import okhttp3.Response;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.onap.aai.domain.yang.v11.GenericVnf;
-import org.onap.aai.domain.yang.v11.L3Network;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.restclient.client.RestClient;
-import org.onap.aai.restclient.enums.RestAuthenticationMode;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.onap.aai.api.CloudInfrastructureApi;
+import org.onap.aai.api.ExternalSystemApi;
+import org.onap.aai.api.NetworkApi;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import javax.xml.bind.JAXBContext;
-import java.io.ByteArrayOutputStream;
-import java.io.StringReader;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static java.util.Base64.getEncoder;
-import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
-import static junit.framework.TestCase.*;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static junit.framework.TestCase.assertEquals;
+import static org.mockito.Mockito.*;
import static org.springframework.test.util.ReflectionTestUtils.setField;
-public class TestAAIRestApiProvider extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
- @Mock
- private RestClient restClient;
- private AAIRestApiProvider aaiRestApiProvider;
- private ArgumentCaptor<Map> headers = ArgumentCaptor.forClass(Map.class);
- private ArgumentCaptor<String> payload = ArgumentCaptor.forClass(String.class);
-
- private OperationResult result = new OperationResult();
+class ResultCaptor<T> implements Answer {
+ private T result = null;
- public static String marshall(Object object) throws Exception {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- JAXBContext.newInstance(object.getClass()).createMarshaller().marshal(object, bos);
- return bos.toString();
+ public T getResult() {
+ return result;
}
- public static <T> T unmarshal(String content, Class<T> clazz) {
- try {
- return (T) JAXBContext.newInstance(clazz).createUnmarshaller().unmarshal(new StringReader(content));
- } catch (Exception e) {
- throw new RuntimeException();
- }
+ @Override
+ public T answer(InvocationOnMock invocationOnMock) throws Throwable {
+ result = (T) invocationOnMock.callRealMethod();
+ return result;
}
+}
+
+public class TestAAIRestApiProvider extends TestBase {
+ private AAIRestApiProvider aaiRestApiProvider;
+ @Mock
+ private HostnameVerifier hostnameVerifier;
+ private AaiSecurityProvider aaiSecurityProvider = spy(new AaiSecurityProvider());
@Before
public void init() {
- //MockitoAnnotations.initMocks(this);
- AAIRestApiProvider real = new AAIRestApiProvider(msbApiProvider);
- setField(AAIRestApiProvider.class, "logger", logger);
- setFieldWithPropertyAnnotation(real, "${aaiUsername}", "aaiUsername");
- setFieldWithPropertyAnnotation(real, "${aaiPassword}", "aaiPassword");
- aaiRestApiProvider = Mockito.spy(real);
- when(aaiRestApiProvider.buildRawClient()).thenReturn(restClient);
- when(restClient.basicAuthPassword("aaiPassword")).thenReturn(restClient);
- when(restClient.basicAuthUsername("aaiUsername")).thenReturn(restClient);
- when(restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC)).thenReturn(restClient);
- when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.CLOUD.getServiceName(), "v11")).thenReturn("x://1.2.3.4:4/a");
- result.setResultCode(201);
+ aaiRestApiProvider = new AAIRestApiProvider(msbApiProvider, aaiSecurityProvider);
}
/**
- * test HTTP GET success scenario
+ * test building a client to access AAI API
*/
@Test
- public void testGetSuccess() throws Exception {
- GenericVnf vnf = OBJECT_FACTORY.createGenericVnf();
- vnf.setVnfId("myVnfId");
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResult(marshall(vnf));
+ public void testApiClientBuilder() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.NETWORK.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a/");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- GenericVnf actualVnf = aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", GenericVnf.class);
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.NETWORK);
//verify
- assertEquals(vnf.getVnfId(), actualVnf.getVnfId());
- assertHeaders();
- }
-
- /**
- * HTTP GET on non existing resource results in {@link java.util.NoSuchElementException}
- */
- @Test
- public void testGetMissingResource() throws Exception {
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResultCode(404);
- //when
- try {
- aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", GenericVnf.class);
- fail();
- } catch (NoSuchElementException e) {
- verify(logger).debug("The resource at /myurl does not exists");
- assertEquals("The resource at /myurl does not exists", e.getMessage());
- }
- }
-
- /**
- * Non known HTTP response code is propagated
- */
- @Test
- public void testUnknownErroCode() throws Exception {
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResultCode(502);
- result.setFailureCause("myFail");
- //when
- try {
- aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", GenericVnf.class);
- fail();
- } catch (RuntimeException e) {
- verify(logger).error("Bad response. Code: 502 cause: myFail");
- assertEquals("Bad response. Code: 502 cause: myFail", e.getMessage());
- }
+ assertEquals("http://1.2.3.4/a/", apiClient.getAdapterBuilder().build().baseUrl().toString());
+ assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory());
+ assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier());
+ Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * response content is not used when not requesting result
+ * is slash is missing from micro service URL it is added
*/
@Test
- public void testNoResult() throws Exception {
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResultCode(202);
+ public void testApiClientBuilderMissingSlash() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.NETWORK.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- Void result = aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", Void.class);
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.NETWORK);
//verify
- assertNull(result);
+ assertEquals("http://1.2.3.4/a/", apiClient.getAdapterBuilder().build().baseUrl().toString());
+ assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory());
+ assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier());
+ Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * test HTTP PUT success scenario
+ * test building a client to access AAI API
*/
@Test
- public void putSuccess() throws Exception {
- when(restClient.put(eq("x://1.2.3.4:4/a/myurl"), payload.capture(), headers.capture(), eq(APPLICATION_XML_TYPE), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- GenericVnf request = OBJECT_FACTORY.createGenericVnf();
- request.setVnfId("myVnfId");
- L3Network response = OBJECT_FACTORY.createL3Network();
- response.setNetworkId("myNetworkId");
- result.setResult(marshall(response));
+ public void testApiClientBuilderForCloud() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.CLOUD.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a/");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- L3Network actualResponse = aaiRestApiProvider.put(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", request, L3Network.class);
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.CLOUD);
//verify
- GenericVnf actualValue = unmarshal(payload.getValue(), GenericVnf.class);
- assertEquals("myVnfId", actualValue.getVnfId());
- assertEquals("myNetworkId", actualResponse.getNetworkId());
- assertHeaders();
+ assertEquals("http://1.2.3.4/a/", apiClient.getAdapterBuilder().build().baseUrl().toString());
+ assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory());
+ assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier());
+ Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * test HTTP delete success scenario
+ * test building a client to access AAI API
*/
@Test
- public void deleteSuccess() throws Exception {
- when(restClient.delete(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
+ public void testApiClientBuilderForExternalSystems() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.ESR.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a/");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- aaiRestApiProvider.delete(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl");
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.ESR);
//verify
- assertHeaders();
- //the when above is the verify
+ assertEquals("http://1.2.3.4/a/", apiClient.getAdapterBuilder().build().baseUrl().toString());
+ assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory());
+ assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier());
+ Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * invalid request content results in error
+ * Test API wrapping for NetworkApi
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
*/
@Test
- public void testInvalidInput() throws Exception {
- when(restClient.put(eq("x://1.2.3.4:4/a/myurl"), payload.capture(), headers.capture(), eq(APPLICATION_XML_TYPE), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- //when
- try {
- aaiRestApiProvider.put(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", "Invalid content", L3Network.class);
- //verify
- fail();
- } catch (Exception e) {
- assertEquals("Unable to marshal content", e.getMessage());
- verify(logger).error("Unable to marshal content", e.getCause());
+ public void testNetworkApiAPiWrapping() {
+ org.onap.aai.ApiClient c = Mockito.mock(org.onap.aai.ApiClient.class);
+ class TestClasss extends AAIRestApiProvider {
+ public TestClasss() {
+ super(msbApiProvider, aaiSecurityProvider);
+ }
+
+ @Override
+ org.onap.aai.ApiClient buildApiClient(AAIRestApiProvider.AAIService service) {
+ return c;
+ }
}
+ NetworkApi defaultApi = Mockito.mock(NetworkApi.class);
+ when(c.createService(NetworkApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertEquals(defaultApi, testInstnace.getNetworkApi());
}
/**
- * invalid response content results in error
+ * Test API wrapping for CloudInfrastructureApi
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
*/
@Test
- public void testInvalidResponse() throws Exception {
- when(restClient.put(eq("x://1.2.3.4:4/a/myurl"), payload.capture(), headers.capture(), eq(APPLICATION_XML_TYPE), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- GenericVnf request = OBJECT_FACTORY.createGenericVnf();
- request.setVnfId("myVnfId");
- result.setResult("invalid");
- //when
- try {
- aaiRestApiProvider.put(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", request, L3Network.class);
- //verify
- fail();
- } catch (Exception e) {
- assertEquals("Unable to unmarshal content", e.getMessage());
- verify(logger).error("Unable to unmarshal content", e.getCause());
+ public void testCloudInfrastructureApiWrapping() {
+ org.onap.aai.ApiClient c = Mockito.mock(org.onap.aai.ApiClient.class);
+ class TestClasss extends AAIRestApiProvider {
+ public TestClasss() {
+ super(msbApiProvider, aaiSecurityProvider);
+ }
+
+ @Override
+ org.onap.aai.ApiClient buildApiClient(AAIRestApiProvider.AAIService service) {
+ return c;
+ }
}
+ CloudInfrastructureApi defaultApi = Mockito.mock(CloudInfrastructureApi.class);
+ when(c.createService(CloudInfrastructureApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertEquals(defaultApi, testInstnace.getCloudInfrastructureApi());
}
/**
- * test AAI service names in AAI
+ * Test API wrapping for ExternalSystemApi
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
*/
@Test
- public void testServiceNames() {
- //the names have been base64-ed to prevent "smart" IDEs (idea) to refactor the tests too for the otherwise known fix constants in external systems
- assertEquals("YWFpLWNsb3VkSW5mcmFzdHJ1Y3R1cmU=", getEncoder().encodeToString(AAIRestApiProvider.AAIService.CLOUD.getServiceName().getBytes()));
- assertEquals("YWFpLW5ldHdvcms=", getEncoder().encodeToString(AAIRestApiProvider.AAIService.NETWORK.getServiceName().getBytes()));
- assertEquals("YWFpLWV4dGVybmFsU3lzdGVt", getEncoder().encodeToString(AAIRestApiProvider.AAIService.ESR.getServiceName().getBytes()));
- }
-
- private void assertHeaders() {
- Map<String, List<String>> actualHeaders = headers.getValue();
- assertEquals(2, actualHeaders.size());
- assertEquals(newArrayList("NokiaSVNFM"), actualHeaders.get("X-FromAppId"));
- assertEquals(newArrayList("application/xml"), actualHeaders.get("Accept"));
+ public void testExternalSystemApiWrapping() {
+ org.onap.aai.ApiClient c = Mockito.mock(org.onap.aai.ApiClient.class);
+ class TestClasss extends AAIRestApiProvider {
+ public TestClasss() {
+ super(msbApiProvider, aaiSecurityProvider);
+ }
+
+ @Override
+ org.onap.aai.ApiClient buildApiClient(AAIRestApiProvider.AAIService service) {
+ return c;
+ }
+ }
+ ExternalSystemApi defaultApi = Mockito.mock(ExternalSystemApi.class);
+ when(c.createService(ExternalSystemApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertEquals(defaultApi, testInstnace.getExternalSystemApi());
}
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java
new file mode 100644
index 00000000..4fbd0b27
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java
@@ -0,0 +1,42 @@
+/*
+ * 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.direct;
+
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+
+import static junit.framework.TestCase.assertEquals;
+
+
+public class TestAaiSecurityProvider extends TestBase {
+ private AaiSecurityProvider securityProvider = new AaiSecurityProvider();
+
+ /**
+ * test property handling
+ */
+ @Test
+ public void init() throws Exception {
+ setFieldWithPropertyAnnotation(securityProvider, "${skipHostnameVerificationForAai}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${skipCertificateVerificationForAai}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${trustedCertificatesForAai}", "cert");
+
+ 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/onap/direct/TestSdcPackageProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java
index 199f7255..87b065f0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java
@@ -15,16 +15,15 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.NoSuchElementException;
import org.apache.http.client.methods.HttpGet;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.apache.http.HttpHeaders.ACCEPT;
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 7bc7df7a..d183e38e 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,6 +17,8 @@ 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 java.util.ArrayList;
+import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
@@ -26,12 +28,10 @@ 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 java.util.ArrayList;
-import java.util.UUID;
-
-import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
import static java.util.Optional.empty;
import static java.util.Optional.of;
+
+import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.springframework.test.util.ReflectionTestUtils.setField;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java
index 2495daf1..8991b819 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java
@@ -16,23 +16,24 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.gson.JsonObject;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.*;
+import org.onap.aai.model.GenericVnf;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.RelationshipData;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.slf4j.Logger;
-import java.util.NoSuchElementException;
-
+import static io.reactivex.Observable.error;
import static junit.framework.TestCase.assertEquals;
-import static org.mockito.Mockito.when;
public class TestAbstractManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private DummyManager dummyManager;
@@ -47,10 +48,9 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testIfResourceDoesNotExists() throws Exception {
- GenericVnf newInstance = OBJECT_FACTORY.createGenericVnf();
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "url", GenericVnf.class)).thenThrow(new NoSuchElementException());
+ GenericVnf newInstance = new GenericVnf();
//when
- GenericVnf actualInstance = dummyManager.createOrGet(AAIRestApiProvider.AAIService.CLOUD, "url", newInstance);
+ GenericVnf actualInstance = dummyManager.createOrGet(error(new RuntimeException()), newInstance);
//verify
assertEquals(newInstance, actualInstance);
}
@@ -60,16 +60,17 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testIfResourceExists() throws Exception {
- GenericVnf newInstance = OBJECT_FACTORY.createGenericVnf();
- GenericVnf existingInstance = OBJECT_FACTORY.createGenericVnf();
- existingInstance.setVnfId("id");
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "url", GenericVnf.class)).thenReturn(existingInstance);
+ GenericVnf newInstance = new GenericVnf();
+ GenericVnf existingInstance = new GenericVnf();
//when
- GenericVnf actualInstance = dummyManager.createOrGet(AAIRestApiProvider.AAIService.CLOUD, "url", newInstance);
+ GenericVnf actualInstance = dummyManager.createOrGet(buildObservable(existingInstance), newInstance);
//verify
assertEquals(existingInstance, actualInstance);
}
+ /**
+ * Test relationship data builder
+ */
@Test
public void testBuildRelationshipData() {
RelationshipData relationshipData = AbstractManager.buildRelationshipData("key", "value");
@@ -77,6 +78,9 @@ public class TestAbstractManager extends TestBase {
assertEquals("value", relationshipData.getRelationshipValue());
}
+ /**
+ * test mandatory value extraction
+ */
@Test
public void testExtractMandatoryValue() {
JsonObject object = new JsonObject();
@@ -89,33 +93,36 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddSingletonRelationForExisting() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ List<Relationship> relationships = new ArrayList<>();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
- Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ relation.setRelationshipData(new ArrayList<>());
+ relationships.add(relation);
+ Relationship sameRelation = new Relationship();
sameRelation.setRelatedTo("relatedTo");
- relations.getRelationship().add(sameRelation);
- RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ relationships.add(sameRelation);
+ RelationshipData data = new RelationshipData();
data.setRelationshipValue("v");
data.setRelationshipKey("k");
+ sameRelation.setRelationshipData(new ArrayList<>());
sameRelation.getRelationshipData().add(data);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
data2.setRelationshipValue("v2");
data2.setRelationshipKey("k2");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addSingletonRelation(relations, newRelation);
+ AbstractManager.addSingletonRelation(relationships, newRelation);
//verify
- assertEquals(2, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(2, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k2", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v2", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
}
/**
@@ -123,25 +130,28 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddSingletonRelation() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
+ List<Relationship> relationships = new ArrayList<>();
+
+ relationships.add(relation);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
+ ;
data2.setRelationshipValue("v2");
data2.setRelationshipKey("k2");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addSingletonRelation(relations, newRelation);
+ AbstractManager.addSingletonRelation(relationships, newRelation);
//verify
- assertEquals(2, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(2, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k2", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v2", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
}
/**
@@ -149,35 +159,39 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddMissingRelationForExisting() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ List<Relationship> relationships = new ArrayList<>();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
- Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ relationships.add(relation);
+ Relationship sameRelation = new Relationship();
sameRelation.setRelatedTo("relatedTo");
- relations.getRelationship().add(sameRelation);
- RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ relationships.add(sameRelation);
+ RelationshipData data = new RelationshipData();
+ ;
data.setRelationshipValue("v");
data.setRelationshipKey("k");
+ sameRelation.setRelationshipData(new ArrayList<>());
sameRelation.getRelationshipData().add(data);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
+ ;
data2.setRelationshipValue("v2");
data2.setRelationshipKey("k2");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addMissingRelation(relations, newRelation);
+ AbstractManager.addMissingRelation(relationships, newRelation);
//verify
- assertEquals(3, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
- assertEquals("k2", relations.getRelationship().get(2).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v2", relations.getRelationship().get(2).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(3, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals("k2", relationships.get(2).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v2", relationships.get(2).getRelationshipData().get(0).getRelationshipValue());
}
/**
@@ -185,33 +199,37 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddMissingRelation() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
+ List<Relationship> relationships = new ArrayList<>();
+ relationships.add(relation);
- Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ Relationship sameRelation = new Relationship();
sameRelation.setRelatedTo("relatedTo");
- relations.getRelationship().add(sameRelation);
- RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ relationships.add(sameRelation);
+ RelationshipData data = new RelationshipData();
+ ;
data.setRelationshipValue("v");
data.setRelationshipKey("k");
+ sameRelation.setRelationshipData(new ArrayList<>());
sameRelation.getRelationshipData().add(data);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
+ ;
data2.setRelationshipValue("v");
data2.setRelationshipKey("k");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addMissingRelation(relations, newRelation);
+ AbstractManager.addMissingRelation(relationships, newRelation);
//verify
- assertEquals(2, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(2, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
}
class DummyManager extends AbstractManager {
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 7cddb50e..514098b6 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
@@ -16,6 +16,12 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
+import io.reactivex.Observable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -23,35 +29,35 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.aai.domain.yang.v11.*;
+import org.onap.aai.api.NetworkApi;
+import org.onap.aai.model.GenericVnf;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.RelationshipData;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.HashSet;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
+import static java.lang.Boolean.TRUE;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestGenericVnfManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<GenericVnf> payload = ArgumentCaptor.forClass(GenericVnf.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
+ @Mock
+ private NetworkApi networkApi;
private GenericVnfManager genericVnfManager;
private VnfInfo vnfInfo = new VnfInfo();
- static void assertRelation(RelationshipList relationShips, String relatedTo, RelationshipData... data) {
- for (Relationship relationship : relationShips.getRelationship()) {
+ static void assertRelation(List<Relationship> relationShips, String relatedTo, RelationshipData... data) {
+ for (Relationship relationship : relationShips) {
if (relationship.getRelatedTo().equals(relatedTo)) {
assertEquals(data.length, relationship.getRelationshipData().size());
int i = 0;
@@ -68,6 +74,7 @@ public class TestGenericVnfManager extends TestBase {
@Before
public void init() {
+ when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
genericVnfManager = new GenericVnfManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(GenericVnfManager.class, "logger", logger);
AtomicLong currentTime = new AtomicLong(0L);
@@ -87,33 +94,20 @@ public class TestGenericVnfManager extends TestBase {
}
/**
- * retrieving an existing VNF
- */
- @Test
- public void testGetExistingVnf() throws Exception {
- GenericVnf aaiVnf = OBJECT_FACTORY.createGenericVnf();
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(aaiVnf);
- //when
- GenericVnf vnf = genericVnfManager.getExistingVnf(VNF_ID);
- //verify
- assertEquals(aaiVnf, vnf);
- }
-
- /**
* if the VNF does not exist it is created
*/
@Test
public void createNonExistingVnf() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
Set<GenericVnf> vnfs = new HashSet<>();
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenAnswer((Answer<GenericVnf>) invocation -> {
+ when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenAnswer((Answer<Observable<GenericVnf>>) invocation -> {
if (vnfs.size() == 0) {
throw new NoSuchElementException();
}
- return vnfs.iterator().next();
+ return buildObservable(vnfs.iterator().next());
});
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 -> {
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
vnfs.add(vnfInAaai);
return null;
});
@@ -123,13 +117,13 @@ public class TestGenericVnfManager extends TestBase {
//verify
GenericVnf vnfSentToAai = payload.getValue();
assertEquals(VNF_ID, vnfSentToAai.getVnfId());
- assertEquals(VNF_ID, vnfSentToAai.getVnfInstanceId());
+ assertEquals(VNF_ID, vnfSentToAai.getVnfId());
assertEquals("NokiaVNF", vnfSentToAai.getVnfType());
- assertEquals(true, vnfSentToAai.isInMaint());
- assertEquals(true, vnfSentToAai.isIsClosedLoopDisabled());
+ assertEquals(TRUE, vnfSentToAai.isInMaint());
+ assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
assertEquals("vnfName", vnfSentToAai.getVnfName());
verify(systemFunctions, times(10)).sleep(3000);
- verify(aaiRestApiProvider, times(10)).get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class);
+ verify(networkApi, times(10)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
/**
@@ -137,24 +131,24 @@ public class TestGenericVnfManager extends TestBase {
*/
@Test
public void testUpdateExistingVnf() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
vnfInAaai.setResourceVersion("v1");
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
+ when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(vnfInAaai));
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);
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(null);
vnfInfo.setName("vnfName");
//when
genericVnfManager.createOrUpdate(VNF_ID, true);
//verify
GenericVnf vnfSentToAai = payload.getValue();
assertEquals(VNF_ID, vnfSentToAai.getVnfId());
- assertEquals(VNF_ID, vnfSentToAai.getVnfInstanceId());
+ assertEquals(VNF_ID, vnfSentToAai.getVnfId());
assertEquals("NokiaVNF", vnfSentToAai.getVnfType());
- assertEquals(true, vnfSentToAai.isInMaint());
- assertEquals(true, vnfSentToAai.isIsClosedLoopDisabled());
+ assertEquals(TRUE, vnfSentToAai.isInMaint());
+ assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
assertEquals("vnfName", vnfSentToAai.getVnfName());
verify(systemFunctions, never()).sleep(anyLong());
- verify(aaiRestApiProvider, times(1)).get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class);
+ verify(networkApi, times(1)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
/**
@@ -162,12 +156,12 @@ public class TestGenericVnfManager extends TestBase {
*/
@Test
public void testUnableToQueryVnfFromCBAM() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
vnfInAaai.setResourceVersion("v1");
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
+ when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(vnfInAaai));
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 -> {
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
vnfInAaai.setResourceVersion("v2");
return null;
});
@@ -187,20 +181,20 @@ public class TestGenericVnfManager extends TestBase {
*/
@Test
public void testConcurency1() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
vnfInAaai.setResourceVersion("v3");
Set<Integer> queryCount = new HashSet<>();
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenAnswer((Answer<GenericVnf>) invocation -> {
+ when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenAnswer((Answer<Observable>) invocationOnMock -> {
queryCount.add(queryCount.size());
if (queryCount.size() >= 11) {
- return vnfInAaai;
+ return buildObservable(vnfInAaai);
}
throw new NoSuchElementException();
});
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];
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
+ GenericVnf vnfSentToAAi = (GenericVnf) invocation.getArguments()[1];
if (vnfSentToAAi.getResourceVersion() == null) {
throw runtimeException;
}
@@ -212,15 +206,15 @@ public class TestGenericVnfManager extends TestBase {
//verify
GenericVnf vnfSentToAai = payload.getValue();
assertEquals(VNF_ID, vnfSentToAai.getVnfId());
- assertEquals(VNF_ID, vnfSentToAai.getVnfInstanceId());
+ assertEquals(VNF_ID, vnfSentToAai.getVnfId());
assertEquals("NokiaVNF", vnfSentToAai.getVnfType());
- assertEquals(true, vnfSentToAai.isInMaint());
- assertEquals(true, vnfSentToAai.isIsClosedLoopDisabled());
+ assertEquals(TRUE, vnfSentToAai.isInMaint());
+ assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
assertEquals("vnfName", vnfSentToAai.getVnfName());
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), any(), eq(Void.class));
+ verify(networkApi, times(11)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+ verify(networkApi, times(2)).createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), any());
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 373c5dd0..47dbb95d 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
@@ -18,24 +18,20 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.L3Network;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.domain.yang.v11.RelationshipList;
+import org.onap.aai.api.NetworkApi;
+import org.onap.aai.model.L3Network;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
@@ -43,17 +39,19 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestL3NetworkManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<L3Network> payload = ArgumentCaptor.forClass(L3Network.class);
private AffectedVirtualLink affectedVirtualLink = new AffectedVirtualLink();
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private L3NetworkManager l3NetworkManager;
+ @Mock
+ private NetworkApi networkApi;
@Before
public void init() {
l3NetworkManager = new L3NetworkManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(L3NetworkManager.class, "logger", logger);
+ when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
}
/**
@@ -68,8 +66,9 @@ public class TestL3NetworkManager extends TestBase {
affectedVirtualLink.setResource(new ResourceHandle());
affectedVirtualLink.getResource().setAdditionalData(additionalData);
affectedVirtualLink.getResource().setResourceId("netProviderId");
- when(aaiRestApiProvider.get(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId", L3Network.class)).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/l3-networks/l3-network/myVnfId_vlId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ L3Network existingNetwork = new L3Network();
+ when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingNetwork));
+ when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
//when
l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
//verify
@@ -98,11 +97,11 @@ public class TestL3NetworkManager extends TestBase {
affectedVirtualLink.setResource(new ResourceHandle());
affectedVirtualLink.getResource().setAdditionalData(additionalData);
affectedVirtualLink.getResource().setResourceId("netProviderId");
- L3Network l3Network = OBJECT_FACTORY.createL3Network();
+ L3Network l3Network = new L3Network();
l3Network.setResourceVersion("v3");
- l3Network.setRelationshipList(new RelationshipList());
- when(aaiRestApiProvider.get(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId", L3Network.class)).thenReturn(l3Network);
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/l3-networks/l3-network/myVnfId_vlId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ l3Network.setRelationshipList(new ArrayList<>());
+ when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
+ when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
//when
l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
//verify
@@ -126,10 +125,13 @@ public class TestL3NetworkManager extends TestBase {
@Test
public void testDelete() throws Exception {
affectedVirtualLink.setId("vlId");
+ L3Network l3Network = new L3Network();
+ l3Network.setResourceVersion("v3");
+ when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
//when
l3NetworkManager.delete(VNF_ID, affectedVirtualLink);
//verify
- verify(aaiRestApiProvider).delete(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId");
+ networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3");
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
index ef9f569e..3728bdb2 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
@@ -15,40 +15,41 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.LInterface;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.domain.yang.v11.RelationshipList;
+import org.onap.aai.api.CloudInfrastructureApi;
+import org.onap.aai.model.LInterface;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
-import java.util.NoSuchElementException;
+import static java.lang.Boolean.FALSE;
+import static java.lang.Boolean.TRUE;
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestLInterfaceManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<LInterface> payload = ArgumentCaptor.forClass(LInterface.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private LInterfaceManager lInterfaceManager;
+ @Mock
+ private CloudInfrastructureApi cloudInfrastructureApi;
@Before
public void init() {
lInterfaceManager = new LInterfaceManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(LInterfaceManager.class, "logger", logger);
+ when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi);
}
/**
@@ -67,22 +68,25 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ LInterface lInterface = new LInterface();
+ lInterface.setResourceVersion("v3");
+ lInterface.setRelationshipList(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(true, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(TRUE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
assertEquals(1, actualInterface.getL3InterfaceIpv4AddressList().size());
- assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
@@ -103,22 +107,25 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ LInterface lInterface = new LInterface();
+ lInterface.setResourceVersion("v3");
+ lInterface.setRelationshipList(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(true, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(TRUE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
- assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
- assertEquals(0, actualInterface.getL3InterfaceIpv4AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
+ assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
}
@@ -138,25 +145,25 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- LInterface lInterface = OBJECT_FACTORY.createLInterface();
+ LInterface lInterface = new LInterface();
lInterface.setResourceVersion("v3");
- lInterface.setRelationshipList(new RelationshipList());
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenReturn(lInterface);
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ lInterface.setRelationshipList(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(true, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(TRUE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
assertEquals(1, actualInterface.getL3InterfaceIpv4AddressList().size());
- assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
assertEquals("v3", lInterface.getResourceVersion());
@@ -179,21 +186,24 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ LInterface lInterface = new LInterface();
+ lInterface.setResourceVersion("v3");
+ lInterface.setRelationshipList(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, false);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(false, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(FALSE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
- assertEquals(0, actualInterface.getL3InterfaceIpv4AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
assertEquals(1, actualInterface.getL3InterfaceIpv6AddressList().size());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv6AddressList().get(0).getNeutronNetworkId());
assertEquals("::", actualInterface.getL3InterfaceIpv6AddressList().get(0).getL3InterfaceIpv6Address());
@@ -212,10 +222,14 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setProviderId("portProviderId");
affectedCp.setServerProviderId("serverProviderId");
affectedCp.setNetworkProviderId("networkProviderId");
+ LInterface lInterface = new LInterface();
+ lInterface.setResourceVersion("v3");
+ lInterface.setRelationshipList(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
//when
lInterfaceManager.delete(VIM_ID, affectedCp);
//verify
- verify(aaiRestApiProvider).delete(logger, CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId");
+ cloudInfrastructureApi.deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", "v3");
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
index 87a1149b..8b41c3f8 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
@@ -21,17 +21,15 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.domain.yang.v11.Vnfc;
+import org.onap.aai.api.NetworkApi;
+import org.onap.aai.model.Vnfc;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
@@ -39,17 +37,19 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestVnfcManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<Vnfc> payload = ArgumentCaptor.forClass(Vnfc.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private VnfcManager vnfcManager;
+ @Mock
+ private NetworkApi networkApi;
@Before
public void init() {
vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(VnfcManager.class, "logger", logger);
+ when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
}
/**
@@ -61,8 +61,9 @@ public class TestVnfcManager extends TestBase {
affectedVnfc.setComputeResource(new ResourceHandle());
affectedVnfc.getComputeResource().setResourceId("serverProviderId");
affectedVnfc.setId("vnfcId");
- when(aaiRestApiProvider.get(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), eq(Vnfc.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vnfc existingVnfc = new Vnfc();
+ when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
+ when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(null);
//when
vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
//verify
@@ -88,12 +89,14 @@ public class TestVnfcManager extends TestBase {
affectedVnfc.setComputeResource(new ResourceHandle());
affectedVnfc.getComputeResource().setResourceId("serverProviderId");
affectedVnfc.setId("vnfcId");
- when(aaiRestApiProvider.get(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), eq(Vnfc.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vnfc existingVnfc = new Vnfc();
+ existingVnfc.setResourceVersion("v3");
+ existingVnfc.setVnfcName("myVnfId_vnfcId");
+ when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
//when
vnfcManager.delete(VNF_ID, affectedVnfc);
//verify
- aaiRestApiProvider.delete(logger, NETWORK, "/vnfcs/vnfc/myVnfId_vnfcId");
+ verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3");
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
index bb5d1d3d..68f5ab5f 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
@@ -20,22 +20,22 @@ import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.AffectedVirtualStorage;
import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.*;
+import org.onap.aai.api.CloudInfrastructureApi;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.Vserver;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
@@ -43,17 +43,19 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestVserverManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<Vserver> payload = ArgumentCaptor.forClass(Vserver.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private VserverManager vserverManager;
+ @Mock
+ private CloudInfrastructureApi cloudInfrastructureApi;
@Before
public void init() {
vserverManager = new VserverManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(VserverManager.class, "logger", logger);
+ when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi);
}
/**
@@ -89,12 +91,12 @@ public class TestVserverManager extends TestBase {
affectedVnfc.setStorageResourceIds(new ArrayList<>());
affectedVnfc.getStorageResourceIds().add("sId");
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
+ String url = "/cloud-regions/cloud-region///tenants/tenant//vservers/vserver/";
- Vserver existingVserver = OBJECT_FACTORY.createVserver();
- existingVserver.setVolumes(new Volumes());
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenReturn(existingVserver);
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vserver existingVserver = new Vserver();
+ existingVserver.setVolumes(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -103,8 +105,8 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("url", vserver.getVserverSelflink());
- assertEquals(1, vserver.getVolumes().getVolume().size());
- assertEquals("storageProviderId", vserver.getVolumes().getVolume().get(0).getVolumeId());
+ assertEquals(1, vserver.getVolumes().size());
+ assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
}
/**
@@ -130,9 +132,10 @@ public class TestVserverManager extends TestBase {
affectedVnfc.setStorageResourceIds(new ArrayList<>());
affectedVnfc.getStorageResourceIds().add("sId");
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vserver existingVserver = new Vserver();
+ existingVserver.setVolumes(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -141,8 +144,8 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("unknown", vserver.getVserverSelflink());
- assertEquals(1, vserver.getVolumes().getVolume().size());
- assertEquals("storageProviderId", vserver.getVolumes().getVolume().get(0).getVolumeId());
+ assertEquals(1, vserver.getVolumes().size());
+ assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
}
/**
@@ -166,9 +169,10 @@ public class TestVserverManager extends TestBase {
affectedVnfc.setStorageResourceIds(new ArrayList<>());
affectedVnfc.getStorageResourceIds().add("sId");
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vserver existingVserver = new Vserver();
+ existingVserver.setVolumes(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -177,8 +181,8 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("unknown", vserver.getVserverSelflink());
- assertEquals(1, vserver.getVolumes().getVolume().size());
- assertEquals("storageProviderId", vserver.getVolumes().getVolume().get(0).getVolumeId());
+ assertEquals(1, vserver.getVolumes().size());
+ assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
}
/**
@@ -195,9 +199,10 @@ public class TestVserverManager extends TestBase {
affectedVnfc.getComputeResource().setAdditionalData(additionalData);
affectedVnfc.setId("vnfcId");
List<AffectedVirtualStorage> affectedStorages = new ArrayList<>();
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vserver existingVserver = new Vserver();
+ existingVserver.setVolumes(new ArrayList<>());
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -206,7 +211,7 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("unknown", vserver.getVserverSelflink());
- assertEquals(0, vserver.getVolumes().getVolume().size());
+ assertEquals(0, vserver.getVolumes().size());
}
/**
@@ -222,18 +227,23 @@ public class TestVserverManager extends TestBase {
additionalData.addProperty("tenantId", "myTenantId");
affectedVnfc.getComputeResource().setAdditionalData(additionalData);
affectedVnfc.setId("vnfcId");
+ Vserver existingVserver = new Vserver();
+ existingVserver.setResourceVersion("v3");
+ existingVserver.setVserverId("serverProviderId");
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+
//when
vserverManager.delete(VIM_ID, affectedVnfc);
//verify
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- aaiRestApiProvider.delete(logger, CLOUD, url);
+ verify(cloudInfrastructureApi).deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "v3");
}
@Test
public void testLinks() {
Relationship relationship = VserverManager.linkTo(VIM_ID, "myTenantPrivderId", "serverProviderId");
- RelationshipList relationships = new RelationshipList();
- relationships.getRelationship().add(relationship);
+ List<Relationship> relationships = new ArrayList<>();
+ relationships.add(relationship);
assertRelation(relationships, "vserver",
buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
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 53e8f8d7..6fc61981 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
@@ -21,6 +21,10 @@ 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 java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -34,12 +38,8 @@ import org.onap.vnfmdriver.model.*;
import org.onap.vnfmdriver.model.ScaleDirection;
import retrofit2.Call;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import static java.nio.file.Files.readAllBytes;
+
import static junit.framework.TestCase.*;
import static org.mockito.Mockito.*;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION;
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 4fbae45f..a701a159 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
@@ -27,6 +27,8 @@ import com.nokia.cbam.lcm.v32.model.ChangeType;
import com.nokia.cbam.lcm.v32.model.*;
import com.nokia.cbam.lcm.v32.model.OperationType;
import com.nokia.cbam.lcm.v32.model.ScaleDirection;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -36,11 +38,9 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffec
import org.onap.vnfmdriver.model.*;
import org.threeten.bp.OffsetDateTime;
-import java.util.ArrayList;
-import java.util.List;
-
import static java.util.Optional.empty;
import static java.util.Optional.of;
+
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
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 b09a11b1..8d344c5b 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
@@ -15,6 +15,8 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.HttpGet;
import org.junit.Assert;
@@ -29,9 +31,6 @@ import org.onap.vfccatalog.model.VnfPkgDetailInfo;
import org.onap.vfccatalog.model.VnfPkgInfo;
import retrofit2.Call;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.verify;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java
index 9c9f7958..8ba697d0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java
@@ -15,13 +15,12 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
-import org.junit.Test;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Mockito.when;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
index 2cd0aa1e..a97ee4f1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
@@ -15,13 +15,12 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
+import java.util.NoSuchElementException;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.verify;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
index 218c478e..8f8cc8c1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
@@ -17,6 +17,13 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
import com.google.common.collect.Lists;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
import org.apache.http.entity.ContentType;
import org.junit.Before;
import org.junit.Test;
@@ -32,14 +39,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.DelegatingServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.Part;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.Arrays;
-
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java
index 6b04d69d..dbbad3f0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java
@@ -29,6 +29,7 @@ import org.onap.vnfmdriver.model.VnfScaleRequest;
import org.onap.vnfmdriver.model.VnfTerminateRequest;
import static java.util.Optional.empty;
+
import static org.apache.http.HttpStatus.SC_CREATED;
import static org.mockito.Mockito.verify;
import static org.springframework.test.util.ReflectionTestUtils.setField;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java
index fc6b97b4..67842f61 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java
@@ -57,7 +57,7 @@ public class TestLcnApi extends TestBase {
@Test
public void testHandleLcn() {
//when
- lcnApi.handleLcn(lcn, httpResponse);
+ lcnApi.handleLcn(lcn);
//verify
verify(lcnManager).handleLcn(lcn);
verify(logger).info("REST: handle LCN");
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java
index 638f7237..f9b6f3ce 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java
@@ -16,6 +16,7 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
+import javax.servlet.ServletOutputStream;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -24,8 +25,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
-import javax.servlet.ServletOutputStream;
-
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;
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 6096802a..f88305a0 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
@@ -21,17 +21,16 @@ 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;
-import org.junit.Test;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import org.springframework.web.bind.annotation.RequestMapping;
-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;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil.loadFile;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java
index 6bcce07f..22a9d06c 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java
@@ -17,19 +17,16 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
import com.nokia.cbam.lcm.v32.model.*;
-import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
-import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.MediaType;
-import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.mock.http.MockHttpInputMessage;
import org.springframework.mock.http.MockHttpOutputMessage;
+import org.threeten.bp.OffsetDateTime;
-import java.io.IOException;
-import java.io.InputStream;
-
+import static com.google.common.collect.Iterables.filter;
import static junit.framework.TestCase.assertEquals;
public class TestRealConfig {
@@ -41,22 +38,26 @@ public class TestRealConfig {
public void test() throws Exception {
HttpMessageConverters converters = new RealConfig().customConverters();
//verify
- converters.getConverters().get(0).canRead(VnfIdentifierCreationNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(VnfIdentifierDeletionNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(VnfInfoAttributeValueChangeNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(VnfLifecycleChangeNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(String.class, MediaType.APPLICATION_JSON);
+ GsonHttpMessageConverter httpMessageConverter1 = filter(converters.getConverters(), GsonHttpMessageConverter.class).iterator().next();
+ httpMessageConverter1.canRead(VnfIdentifierCreationNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(VnfIdentifierDeletionNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(VnfInfoAttributeValueChangeNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(VnfLifecycleChangeNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(String.class, MediaType.APPLICATION_JSON);
- HttpMessageConverter<VnfLifecycleChangeNotification> httpMessageConverter = (HttpMessageConverter<VnfLifecycleChangeNotification>) converters.getConverters().get(0);
MockHttpOutputMessage out = new MockHttpOutputMessage();
VnfLifecycleChangeNotification not = new VnfLifecycleChangeNotification();
not.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
not.setVnfInstanceId("vnfId");
- httpMessageConverter.write(not, MediaType.APPLICATION_JSON, out);
+ OffsetDateTime now = OffsetDateTime.now();
+ not.setTimestamp(now);
+ httpMessageConverter1.write(not, MediaType.APPLICATION_JSON, out);
String write = out.getBodyAsString();
HttpInputMessage x = new MockHttpInputMessage(write.getBytes());
- VnfLifecycleChangeNotification deserialized = (VnfLifecycleChangeNotification) httpMessageConverter.read(VnfLifecycleChangeNotification.class, x);
+ VnfLifecycleChangeNotification deserialized = (VnfLifecycleChangeNotification) httpMessageConverter1.read(VnfLifecycleChangeNotification.class, x);
assertEquals("vnfId", deserialized.getVnfInstanceId());
+ assertEquals(now, deserialized.getTimestamp());
+
}
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java
index 39a8e648..d1cbbb68 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java
@@ -16,6 +16,8 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
+import java.util.HashMap;
+import java.util.List;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.security.config.annotation.ObjectPostProcessor;
@@ -27,9 +29,6 @@ import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.test.util.ReflectionTestUtils;
-import java.util.HashMap;
-import java.util.List;
-
import static junit.framework.TestCase.assertTrue;
public class TestSecurityConfig {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java
index 2dc33f3b..d995fcd1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java
@@ -16,9 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -31,6 +28,8 @@ import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
+import org.junit.BeforeClass;
+import org.junit.Test;
import static com.google.common.collect.Sets.newHashSet;
import static org.junit.Assert.*;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java
index ec1ebd78..df97d4a4 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java
@@ -16,11 +16,10 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
-import org.junit.Test;
-
import java.util.Base64;
import java.util.HashSet;
import java.util.Set;
+import org.junit.Test;
import static org.junit.Assert.*;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java
index f5d9cc41..767505e6 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java
@@ -17,7 +17,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
import com.google.common.io.ByteStreams;
-
import java.io.InputStream;
import java.lang.reflect.Constructor;
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", "");