summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-12 13:35:11 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-12 13:41:20 +0100
commit626ebae46807adeab6d0b9d5568515f457c7ece3 (patch)
tree143819aec0ae5597f60eff13499ae69d698f6cbc /nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm
parentf5608b8ab40816febb064a61e80b52b572eda768 (diff)
add direct information source
Change-Id: I3def669ecc9ea0a5df2c95f65be3d4ffc7fdf3b8 Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm')
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java100
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java189
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java238
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestGrantlessGrantManager.java80
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java130
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java253
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java230
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java250
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java143
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java230
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java108
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java253
12 files changed, 2204 insertions, 0 deletions
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
new file mode 100644
index 00000000..a428ee90
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java
@@ -0,0 +1,100 @@
+/*
+ * 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.ct;
+
+import com.google.gson.JsonObject;
+import com.nokia.cbam.lcm.v32.model.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.NokiaSvnfmApplication;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIExternalSystemInfoProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AAINotificationProcessor;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
+import org.onap.vnfmdriver.model.VimInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+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)
+@SpringBootTest(classes = NokiaSvnfmApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+@ActiveProfiles("direct")
+public class CTDirectReal {
+ @Autowired
+ private AAIExternalSystemInfoProvider externalSystemInfoProvider;
+ @Autowired
+ private AAINotificationProcessor notificationProcessor;
+
+ /**
+ * The following is not a real test, but only start the driver locally.
+ * It takes parameters from application-real.properties
+ */
+ @Test
+ public void testBasicWorkflow() throws Exception {
+ VimInfo nokia_regionOne = externalSystemInfoProvider.getVimInfo("Nokia_RegionOne");
+
+ VnfLifecycleChangeNotification recievedNot = new VnfLifecycleChangeNotification();
+ recievedNot.setVnfInstanceId("CBAM-d8deb02a7a51449dba576ac9eabb55b8");
+ ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
+ recievedNot.setAffectedVirtualLinks(new ArrayList<>());
+ AffectedVirtualLink link = new AffectedVirtualLink();
+ recievedNot.getAffectedVirtualLinks().add(link);
+ link.setId("vlid1");
+ link.setChangeType(ChangeType.REMOVED);
+ link.setVirtualLinkDescId("vldId1");
+ link.setResource(new ResourceHandle());
+ link.getResource().setResourceId("netProviderId1");
+ link.getResource().setAdditionalData(additionalData("name", "networkName"));
+ recievedNot.setAffectedVnfcs(new ArrayList<>());
+ AffectedVnfc vnfc = new AffectedVnfc();
+ vnfc.setId("myVnfcId1");
+ vnfc.setChangeType(ChangeType.ADDED);
+ vnfc.setVduId("myVduId");
+ vnfc.setStorageResourceIds(new ArrayList<>());
+ vnfc.setComputeResource(new ResourceHandle());
+ vnfc.getComputeResource().setResourceId("serverProvId1");
+ JsonObject additionalData = additionalData("name", "serverName");
+ additionalData.addProperty("tenantId", "de8fd0d1d5874503a47b920c10f4322a");
+ vnfc.getComputeResource().setAdditionalData(additionalData);
+ recievedNot.getAffectedVnfcs().add(vnfc);
+ ReportedAffectedCp addedCp = new ReportedAffectedCp();
+ addedCp.setCpId("cpId");
+ addedCp.setIpAddress("1.2.3.4");
+ addedCp.setMacAddress("a:b:c:d:e:f");
+ addedCp.setNetworkProviderId("netProviderId1");
+ addedCp.setServerProviderId("serverProvId1");
+ addedCp.setProviderId("portId");
+ addedCp.setTenantId("de8fd0d1d5874503a47b920c10f4322a");
+ addedCp.setCpdId("cpdId");
+ affectedConnectionPoints.getPost().add(addedCp);
+ notificationProcessor.processNotification(recievedNot, null, of(affectedConnectionPoints), "Nokia_RegionOne");
+ Thread.sleep(10000000 * 1000L);
+ }
+
+ JsonObject additionalData(String key, String value) {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty(key, value);
+ return jsonObject;
+ }
+
+
+}
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
new file mode 100644
index 00000000..c1da617e
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
@@ -0,0 +1,189 @@
+/*
+ * 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.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.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+import org.onap.vnfmdriver.model.VimInfo;
+import org.onap.vnfmdriver.model.VnfmInfo;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.fail;
+import static org.mockito.Mockito.verify;
+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;
+
+ @Before
+ public void init() {
+ aaiExternalSystemInfoProvider = new AAIExternalSystemInfoProvider(environment, aaiRestApiProvider);
+ setField(AAIExternalSystemInfoProvider.class, "logger", logger);
+ }
+
+ /**
+ * test query VIM success scenario
+ */
+ @Test
+ public void testVim() throws Exception {
+ EsrSystemInfoList vims = OBJECT_FACTORY.createEsrSystemInfoList();
+ EsrSystemInfo vim = OBJECT_FACTORY.createEsrSystemInfo();
+ vims.getEsrSystemInfo().add(vim);
+ vim.setPassword("myPassword");
+ vim.setUserName("myUsername");
+ vim.setServiceUrl("http://1.2.3.4:1234/a");
+ vim.setVersion("v123");
+ vim.setSystemStatus("active");
+ vim.setSystemName("name");
+ 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
+ VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
+ assertEquals("myPassword", vimInfo.getPassword());
+ assertEquals("true", vimInfo.getSslInsecure());
+ assertEquals(null, vimInfo.getSslCacert());
+ assertEquals("myUsername", vimInfo.getUserName());
+ assertEquals("name", vimInfo.getDescription());
+ assertEquals("name", vimInfo.getName());
+ assertEquals("http://1.2.3.4:1234/a", vimInfo.getUrl());
+ assertEquals("active", vimInfo.getStatus());
+ assertEquals("type", vimInfo.getType());
+ assertEquals("v123", vimInfo.getVersion());
+ assertEquals(VIM_ID, vimInfo.getVimId());
+ assertEquals(null, vimInfo.getCreateTime());
+
+ }
+
+ /**
+ * test query VIM success scenario for SSL
+ */
+ @Test
+ public void testVimSsl() throws Exception {
+ EsrSystemInfoList vims = OBJECT_FACTORY.createEsrSystemInfoList();
+ EsrSystemInfo vim = OBJECT_FACTORY.createEsrSystemInfo();
+ vims.getEsrSystemInfo().add(vim);
+ vim.setPassword("myPassword");
+ vim.setUserName("myUsername");
+ vim.setServiceUrl("https://1.2.3.4:1234/a");
+ vim.setVersion("v123");
+ vim.setSystemStatus("active");
+ vim.setSystemName("name");
+ vim.setType("type");
+ 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
+ VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
+ assertEquals("myPassword", vimInfo.getPassword());
+ assertEquals("false", vimInfo.getSslInsecure());
+ assertEquals("cert", vimInfo.getSslCacert());
+ assertEquals("myUsername", vimInfo.getUserName());
+ assertEquals("name", vimInfo.getDescription());
+ assertEquals("name", vimInfo.getName());
+ assertEquals("https://1.2.3.4:1234/a", vimInfo.getUrl());
+ assertEquals("active", vimInfo.getStatus());
+ assertEquals("type", vimInfo.getType());
+ assertEquals("v123", vimInfo.getVersion());
+ assertEquals(VIM_ID, vimInfo.getVimId());
+ assertEquals(null, vimInfo.getCreateTime());
+ }
+
+ /**
+ * unable to query VIM from AAI results in error
+ */
+ @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
+ try {
+ aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
+ fail();
+ } catch (Exception e) {
+ verify(logger).error("Unable to query VIM with myCloudOwnerId_myRegionName identifier from AAI", expectedException);
+ assertEquals(expectedException, e.getCause());
+ }
+ }
+
+ /**
+ * test VNFM query success scenario
+ */
+ @Test
+ public void testVnfmQuery() throws Exception {
+ EsrVnfm vnfm = OBJECT_FACTORY.createEsrVnfm();
+ vnfm.setVimId(VIM_ID);
+ vnfm.setEsrSystemInfoList(OBJECT_FACTORY.createEsrSystemInfoList());
+ EsrSystemInfo esrInfo = OBJECT_FACTORY.createEsrSystemInfo();
+ vnfm.getEsrSystemInfoList().getEsrSystemInfo().add(esrInfo);
+ esrInfo.setPassword("myPassword");
+ esrInfo.setUserName("myUsername");
+ esrInfo.setServiceUrl("https://1.2.3.4:1234/a");
+ esrInfo.setVersion("v123");
+ esrInfo.setSystemStatus("active");
+ esrInfo.setSystemName("name");
+ esrInfo.setType("type");
+ esrInfo.setSslInsecure(false);
+ 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
+ VnfmInfo actualVnfmInfo = aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
+ //verify
+ assertEquals("myPassword", actualVnfmInfo.getPassword());
+ assertEquals("https://1.2.3.4:1234/a", actualVnfmInfo.getUrl());
+ assertEquals("myUsername", actualVnfmInfo.getUserName());
+ assertEquals(null, actualVnfmInfo.getCreateTime());
+ assertEquals(null, actualVnfmInfo.getDescription());
+ assertEquals("name", actualVnfmInfo.getName());
+ assertEquals("type", actualVnfmInfo.getType());
+ assertEquals("vendor", actualVnfmInfo.getVendor());
+ assertEquals("v123", actualVnfmInfo.getVersion());
+ assertEquals(VIM_ID, actualVnfmInfo.getVimId());
+ assertEquals(VNFM_ID, actualVnfmInfo.getVnfmId());
+ }
+
+ /**
+ * unable to query VNFM from AAI results in error
+ */
+ @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
+ try {
+ aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
+ fail();
+ } catch (Exception e) {
+ verify(logger).error("Unable to query VNFM with " + VNFM_ID + " identifier from AAI", expectedException);
+ assertEquals(expectedException, e.getCause());
+ }
+ }
+} \ No newline at end of file
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
new file mode 100644
index 00000000..953f7da0
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
@@ -0,0 +1,238 @@
+/*
+ * 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.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.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 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();
+
+ public static String marshall(Object object) throws Exception {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ JAXBContext.newInstance(object.getClass()).createMarshaller().marshal(object, bos);
+ return bos.toString();
+ }
+
+ 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();
+ }
+ }
+
+ @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);
+ }
+
+ /**
+ * test HTTP GET success scenario
+ */
+ @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));
+ //when
+ GenericVnf actualVnf = aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", GenericVnf.class);
+ //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());
+ }
+ }
+
+ /**
+ * response content is not used when not requesting result
+ */
+ @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);
+ //when
+ Void result = aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", Void.class);
+ //verify
+ assertNull(result);
+ }
+
+ /**
+ * test HTTP PUT success scenario
+ */
+ @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));
+ //when
+ L3Network actualResponse = aaiRestApiProvider.put(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", request, L3Network.class);
+ //verify
+ GenericVnf actualValue = unmarshal(payload.getValue(), GenericVnf.class);
+ assertEquals("myVnfId", actualValue.getVnfId());
+ assertEquals("myNetworkId", actualResponse.getNetworkId());
+ assertHeaders();
+ }
+
+ /**
+ * test HTTP delete success scenario
+ */
+ @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);
+ //when
+ aaiRestApiProvider.delete(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl");
+ //verify
+ assertHeaders();
+ //the when above is the verify
+ }
+
+ /**
+ * invalid request content results in error
+ */
+ @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());
+ }
+ }
+
+ /**
+ * invalid response content results in error
+ */
+ @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());
+ }
+ }
+
+ /**
+ * test AAI service names in AAI
+ */
+ @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"));
+ }
+}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestGrantlessGrantManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestGrantlessGrantManager.java
new file mode 100644
index 00000000..ad9b7fc8
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestGrantlessGrantManager.java
@@ -0,0 +1,80 @@
+/*
+ * 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.Before;
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+import org.onap.vnfmdriver.model.GrantVNFResponseVim;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.springframework.test.util.ReflectionTestUtils.setField;
+
+public class TestGrantlessGrantManager extends TestBase {
+ private GrantlessGrantManager grantlessGrantManager;
+
+ @Before
+ public void init() {
+ grantlessGrantManager = new GrantlessGrantManager();
+ setField(GrantlessGrantManager.class, "logger", logger);
+ }
+
+ /**
+ * grant is only logged for healing
+ */
+ @Test
+ public void testGrantForHeal() throws Exception {
+ //when
+ grantlessGrantManager.requestGrantForHeal(null, null, null, null, null, null);
+ //verify
+ verify(logger).info("No grant is requested in direct mode");
+ }
+
+ /**
+ * grant is only logged for instantiation
+ */
+ @Test
+ public void testGrantForInstantiate() throws Exception {
+ //when
+ GrantVNFResponseVim grant = grantlessGrantManager.requestGrantForInstantiate(null, null, VIM_ID, null, null, null, null);
+ //verify
+ verify(logger).info("No grant is requested in direct mode");
+ assertEquals(VIM_ID, grant.getVimId());
+ }
+
+ /**
+ * grant is only logged for scaling
+ */
+ @Test
+ public void testGrantForScaling() throws Exception {
+ //when
+ grantlessGrantManager.requestGrantForScale(null, null, null, null, null, null);
+ //verify
+ verify(logger).info("No grant is requested in direct mode");
+ }
+
+ /**
+ * grant is only logged for termination
+ */
+ @Test
+ public void testGrantForTerminate() throws Exception {
+ //when
+ grantlessGrantManager.requestGrantForTerminate(null, null, null, null, null, null);
+ //verify
+ verify(logger).info("No grant is requested in direct mode");
+ }
+}
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
new file mode 100644
index 00000000..199f7255
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java
@@ -0,0 +1,130 @@
+/*
+ * 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.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;
+import static org.mockito.Matchers.any;
+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.core.SelfRegistrationManager.SERVICE_NAME;
+import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;
+import static org.springframework.test.util.ReflectionTestUtils.setField;
+
+public class TestSdcPackageProvider extends TestBase {
+ private SdcPackageProvider sdcPackageProvider;
+
+ @Before
+ public void init() {
+ sdcPackageProvider = new SdcPackageProvider(msbApiProvider, driverProperties);
+ setField(SdcPackageProvider.class, "logger", logger);
+ setFieldWithPropertyAnnotation(sdcPackageProvider, "${sdcUsername}", "sdcUsername");
+ setFieldWithPropertyAnnotation(sdcPackageProvider, "${sdcPassword}", "sdcPassword");
+ when(msbApiProvider.getMicroServiceUrl("sdc", "v1")).thenReturn("https://1.2.3.4:456/g");
+ }
+
+ /**
+ * test package download from SDC
+ */
+ @Test
+ public void testPackageDownload() throws Exception {
+ when(entity.getContent()).thenReturn(new ByteArrayInputStream("test".getBytes()));
+ //when
+ byte[] result = sdcPackageProvider.getPackage("csarId");
+ //verify
+ assertEquals("test", new String("test"));
+ HttpGet httpGet = (HttpGet) request.getValue();
+ assertEquals(VNFM_ID, httpGet.getFirstHeader("X-ECOMP-InstanceID").getValue());
+ assertEquals(SERVICE_NAME, httpGet.getFirstHeader("X-FromAppId").getValue());
+ assertEquals(APPLICATION_OCTET_STREAM_VALUE, httpGet.getFirstHeader(ACCEPT).getValue());
+ assertEquals("https://1.2.3.4:456/g/sdc/v1/catalog/resources/csarId/toscaModel", httpGet.getURI().toASCIIString());
+ }
+
+ /**
+ * failure to download package from SDC is propagated
+ */
+ @Test
+ public void testFailedPackageDownload() throws Exception {
+ IOException expectedException = new IOException();
+ when(httpClient.execute(any())).thenThrow(expectedException);
+ try {
+ sdcPackageProvider.getPackage("csarId");
+ fail();
+ } catch (Exception e) {
+ assertEquals("Unable to download csarId package from SDC", e.getMessage());
+ assertEquals(expectedException, e.getCause());
+ verify(logger).error("Unable to download csarId package from SDC", expectedException);
+ }
+ }
+
+ /**
+ * get VNFD from ONAP package
+ */
+ @Test
+ public void testGetVnfd() throws Exception {
+ byte[] onapPackageContent = TestUtil.loadFile("unittests/TestCbamCatalogManager.sample.csar");
+ when(entity.getContent()).thenReturn(new ByteArrayInputStream(onapPackageContent));
+ //when
+ String cbamVnfdId = sdcPackageProvider.getCbamVnfdId("csarId");
+ //verify
+ assertEquals("Nokia~SimpleDual_scalable~1.0~1.0", cbamVnfdId);
+ }
+
+ /**
+ * unable to download package from SDC during get CBAM VNFD id
+ */
+ @Test
+ public void testUnableToDownloadPackageDuringVnfdIdGet() throws Exception {
+ IOException expectedException = new IOException();
+ when(httpClient.execute(any())).thenThrow(expectedException);
+ try {
+ sdcPackageProvider.getCbamVnfdId("csarId");
+ fail();
+ } catch (Exception e) {
+ assertEquals("Unable to download csarId package from SDC", e.getMessage());
+ assertEquals(expectedException, e.getCause());
+ verify(logger).error("Unable to download csarId package from SDC", expectedException);
+ }
+ }
+
+ /**
+ * invalid VNF package results in error
+ */
+ @Test
+ public void testInvalidVNFDContent() throws Exception {
+ byte[] onapPackageContent = "invalidZip".getBytes();
+ when(entity.getContent()).thenReturn(new ByteArrayInputStream(onapPackageContent));
+ try {
+ sdcPackageProvider.getCbamVnfdId("csarId");
+ fail();
+ } catch (Exception e) {
+ assertEquals("Unable to extract CBAM VNFD id from ONAP package", e.getMessage());
+ verify(logger).error(eq("Unable to extract CBAM VNFD id from ONAP package"), any(NoSuchElementException.class));
+ }
+ }
+}
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
new file mode 100644
index 00000000..bc8f7835
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java
@@ -0,0 +1,253 @@
+/*
+ * 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.notification;
+
+import com.google.gson.JsonObject;
+import com.nokia.cbam.lcm.v32.model.*;
+import org.jetbrains.annotations.NotNull;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
+
+import 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 org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.springframework.test.util.ReflectionTestUtils.setField;
+
+public class TestAAINotificationProcessor extends TestBase {
+ @Mock
+ private GenericVnfManager genericVnfManager;
+ @Mock
+ private L3NetworkManager l3NetworkManager;
+ @Mock
+ private LInterfaceManager lInterfaceManager;
+ @Mock
+ private VnfcManager vnfcManager;
+ @Mock
+ private VserverManager vserverManager;
+ private AAINotificationProcessor aaiNotificationProcessor;
+
+ @Before
+ public void init() {
+ aaiNotificationProcessor = new AAINotificationProcessor(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
+ setField(AAINotificationProcessor.class, "logger", logger);
+ }
+
+ /**
+ * test objects are manipulated in correct order in AAA
+ * (other is dependency between the objects though relations)
+ */
+ @Test
+ public void testObjectManipulationOrder() throws Exception {
+ VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
+ recievenNotification.setAffectedVnfcs(new ArrayList<>());
+ recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
+ ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
+ recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
+ recievenNotification.setVnfInstanceId(VNF_ID);
+ recievenNotification.setStatus(OperationStatus.STARTED);
+ AffectedVirtualLink addedLink = buildVl(recievenNotification, ADDED);
+ AffectedVirtualLink removedLink = buildVl(recievenNotification, REMOVED);
+ AffectedVirtualLink modifiedLink = buildVl(recievenNotification, MODIFIED);
+ AffectedVnfc addedVnfc = buildVnfc(recievenNotification, ADDED, "tenantId1");
+ AffectedVnfc removedVnfc = buildVnfc(recievenNotification, REMOVED, "tenantId2");
+ AffectedVnfc modifedVnfc = buildVnfc(recievenNotification, MODIFIED, "tenantId3");
+ boolean inMaintenance = true;
+ ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
+
+ ReportedAffectedCp removedCp = buildCp();
+ removedCp.setServerProviderId("serverId");
+ affectedConnectionPoints.getPre().add(removedCp);
+
+ ReportedAffectedCp removedCpWithoutServer = buildCp();
+ removedCpWithoutServer.setServerProviderId(null);
+ affectedConnectionPoints.getPre().add(removedCpWithoutServer);
+
+ ReportedAffectedCp addedCp = buildCp();
+ addedCp.setServerProviderId("serverId");
+ affectedConnectionPoints.getPost().add(addedCp);
+ //when
+ aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
+ //verify
+ InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
+ inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink);
+ inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, modifiedLink);
+ inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, addedVnfc, affectedVirtualStorages, inMaintenance);
+ inOrder.verify(vnfcManager).update(VIM_ID, "tenantId1", VNF_ID, addedVnfc, inMaintenance);
+ inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, modifedVnfc, affectedVirtualStorages, inMaintenance);
+ inOrder.verify(vnfcManager).update(VIM_ID, "tenantId3", VNF_ID, modifedVnfc, inMaintenance);
+ inOrder.verify(lInterfaceManager).delete(VIM_ID, removedCp);
+ inOrder.verify(lInterfaceManager).update(VNF_ID, VIM_ID, addedCp, inMaintenance);
+ inOrder.verify(vnfcManager).delete(VNF_ID, removedVnfc);
+ inOrder.verify(vserverManager).delete(VIM_ID, removedVnfc);
+ inOrder.verify(l3NetworkManager).delete(VNF_ID, removedLink);
+ verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, removedCpWithoutServer, inMaintenance);
+ verify(lInterfaceManager, never()).delete(VIM_ID, removedCpWithoutServer);
+ }
+
+ /**
+ * - unchanged CP is updated
+ * - changed CP is updated
+ */
+ @Test
+ public void testCps() throws Exception {
+ VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
+ recievenNotification.setAffectedVnfcs(new ArrayList<>());
+ recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
+ recievenNotification.setVnfInstanceId(VNF_ID);
+ recievenNotification.setStatus(OperationStatus.STARTED);
+ ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
+ recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
+ boolean inMaintenance = true;
+ ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
+
+ ReportedAffectedCp unchangedCp = buildCp();
+ unchangedCp.setCpId("unchanged");
+ affectedConnectionPoints.getPre().add(unchangedCp);
+ affectedConnectionPoints.getPost().add(unchangedCp);
+
+ ReportedAffectedCp changedCpBefore = buildCp();
+ changedCpBefore.setCpId("changedBefore");
+ ReportedAffectedCp changedCpAfter = buildCp();
+ changedCpAfter.setCpId("changedAfter");
+ changedCpAfter.setCpId(changedCpBefore.getCpId());
+ affectedConnectionPoints.getPre().add(changedCpBefore);
+ affectedConnectionPoints.getPost().add(changedCpAfter);
+
+ //when
+ aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
+ //verify
+ verify(lInterfaceManager).update(VNF_ID, VIM_ID, unchangedCp, inMaintenance);
+ verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, changedCpBefore, inMaintenance);
+ verify(lInterfaceManager).update(VNF_ID, VIM_ID, changedCpAfter, inMaintenance);
+ }
+
+ /**
+ * the end notification calls resource managers with not in maintenance state
+ */
+ @Test
+ public void testEndNotification() throws Exception {
+ VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
+ recievenNotification.setAffectedVnfcs(new ArrayList<>());
+ recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
+ ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
+ recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
+ recievenNotification.setVnfInstanceId(VNF_ID);
+ recievenNotification.setStatus(OperationStatus.FINISHED);
+ AffectedVirtualLink addedLink = buildVl(recievenNotification, ADDED);
+ AffectedVirtualLink removedLink = buildVl(recievenNotification, REMOVED);
+ AffectedVirtualLink modifiedLink = buildVl(recievenNotification, MODIFIED);
+ AffectedVnfc addedVnfc = buildVnfc(recievenNotification, ADDED, "tenantId1");
+ AffectedVnfc removedVnfc = buildVnfc(recievenNotification, REMOVED, "tenantId2");
+ AffectedVnfc modifedVnfc = buildVnfc(recievenNotification, MODIFIED, "tenantId3");
+ boolean inMaintenance = false;
+ ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
+
+ ReportedAffectedCp removedCp = buildCp();
+ removedCp.setServerProviderId("serverId");
+ affectedConnectionPoints.getPre().add(removedCp);
+
+ ReportedAffectedCp removedCpWithoutServer = buildCp();
+ removedCpWithoutServer.setServerProviderId(null);
+ affectedConnectionPoints.getPre().add(removedCpWithoutServer);
+
+ ReportedAffectedCp addedCp = buildCp();
+ addedCp.setServerProviderId("serverId");
+ affectedConnectionPoints.getPost().add(addedCp);
+
+ ReportedAffectedCp cpWithoutServer = buildCp();
+ cpWithoutServer.setServerProviderId(null);
+ affectedConnectionPoints.getPost().add(cpWithoutServer);
+
+ //when
+ aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
+ //verify
+ InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
+ inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink);
+ inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, modifiedLink);
+ inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, addedVnfc, affectedVirtualStorages, inMaintenance);
+ inOrder.verify(vnfcManager).update(VIM_ID, "tenantId1", VNF_ID, addedVnfc, inMaintenance);
+ inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, modifedVnfc, affectedVirtualStorages, inMaintenance);
+ inOrder.verify(vnfcManager).update(VIM_ID, "tenantId3", VNF_ID, modifedVnfc, inMaintenance);
+ inOrder.verify(lInterfaceManager).delete(VIM_ID, removedCp);
+ inOrder.verify(lInterfaceManager).update(VNF_ID, VIM_ID, addedCp, inMaintenance);
+ inOrder.verify(vnfcManager).delete(VNF_ID, removedVnfc);
+ inOrder.verify(vserverManager).delete(VIM_ID, removedVnfc);
+ inOrder.verify(l3NetworkManager).delete(VNF_ID, removedLink);
+ verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, removedCpWithoutServer, inMaintenance);
+ verify(lInterfaceManager, never()).delete(VIM_ID, removedCpWithoutServer);
+ verify(logger).warn("The changed {} connection point is not linked to any server", cpWithoutServer.getCpId());
+ }
+
+
+
+ /**
+ * if changes connection points are not present a warning is logged
+ */
+ @Test
+ public void testMissingChangedConnectionPoints() throws Exception {
+ VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
+ recievenNotification.setAffectedVnfcs(new ArrayList<>());
+ recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
+ recievenNotification.setVnfInstanceId(VNF_ID);
+ //when
+ aaiNotificationProcessor.processNotification(recievenNotification, null, empty(), VIM_ID);
+ //verify
+ verify(logger).warn("The changed connection points are not present in VNF with {} identifier", VNF_ID);
+ }
+
+ @NotNull
+ private ReportedAffectedCp buildCp() {
+ ReportedAffectedCp cp = new ReportedAffectedCp();
+ cp.setServerProviderId(UUID.randomUUID().toString());
+ cp.setName(UUID.randomUUID().toString());
+ cp.setEcpdId(UUID.randomUUID().toString());
+ cp.setMacAddress(UUID.randomUUID().toString());
+ cp.setNetworkProviderId(UUID.randomUUID().toString());
+ cp.setCpdId(UUID.randomUUID().toString());
+ cp.setCpId(UUID.randomUUID().toString());
+ cp.setTenantId(UUID.randomUUID().toString());
+ return cp;
+ }
+
+ private AffectedVirtualLink buildVl(VnfLifecycleChangeNotification recievenNotification, ChangeType changeType) {
+ AffectedVirtualLink affectedVirtualLink = new AffectedVirtualLink();
+ affectedVirtualLink.setChangeType(changeType);
+ recievenNotification.getAffectedVirtualLinks().add(affectedVirtualLink);
+ return affectedVirtualLink;
+ }
+
+ private AffectedVnfc buildVnfc(VnfLifecycleChangeNotification recievenNotification, ChangeType changeType, String tenantId) {
+ AffectedVnfc addedVnfc = new AffectedVnfc();
+ addedVnfc.setChangeType(changeType);
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("tenantId", tenantId);
+ addedVnfc.setComputeResource(new ResourceHandle());
+ addedVnfc.getComputeResource().setAdditionalData(additionalData);
+ recievenNotification.getAffectedVnfcs().add(addedVnfc);
+ return addedVnfc;
+ }
+}
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
new file mode 100644
index 00000000..2495daf1
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java
@@ -0,0 +1,230 @@
+/*
+ * 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.notification;
+
+import com.google.gson.JsonObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.aai.domain.yang.v11.*;
+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 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;
+
+ @Before
+ public void init() {
+ dummyManager = new DummyManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
+ }
+
+ /**
+ * if the REST resource does not exists the provided instance is used
+ */
+ @Test
+ public void testIfResourceDoesNotExists() throws Exception {
+ GenericVnf newInstance = OBJECT_FACTORY.createGenericVnf();
+ when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "url", GenericVnf.class)).thenThrow(new NoSuchElementException());
+ //when
+ GenericVnf actualInstance = dummyManager.createOrGet(AAIRestApiProvider.AAIService.CLOUD, "url", newInstance);
+ //verify
+ assertEquals(newInstance, actualInstance);
+ }
+
+ /**
+ * if the REST resource exists it is not recreated
+ */
+ @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);
+ //when
+ GenericVnf actualInstance = dummyManager.createOrGet(AAIRestApiProvider.AAIService.CLOUD, "url", newInstance);
+ //verify
+ assertEquals(existingInstance, actualInstance);
+ }
+
+ @Test
+ public void testBuildRelationshipData() {
+ RelationshipData relationshipData = AbstractManager.buildRelationshipData("key", "value");
+ assertEquals("key", relationshipData.getRelationshipKey());
+ assertEquals("value", relationshipData.getRelationshipValue());
+ }
+
+ @Test
+ public void testExtractMandatoryValue() {
+ JsonObject object = new JsonObject();
+ object.addProperty("key", "value");
+ assertEquals("value", AbstractManager.extractMandatoryValue(object, "key"));
+ }
+
+ /**
+ * the same relation is replaced
+ */
+ @Test
+ public void testAddSingletonRelationForExisting() {
+ RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
+ Relationship relation = OBJECT_FACTORY.createRelationship();
+ relation.setRelatedTo("unknownRelation");
+ relations.getRelationship().add(relation);
+ Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ sameRelation.setRelatedTo("relatedTo");
+ relations.getRelationship().add(sameRelation);
+ RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ data.setRelationshipValue("v");
+ data.setRelationshipKey("k");
+ sameRelation.getRelationshipData().add(data);
+
+ Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ newRelation.setRelatedTo("relatedTo");
+ RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ data2.setRelationshipValue("v2");
+ data2.setRelationshipKey("k2");
+ newRelation.getRelationshipData().add(data2);
+
+ //when
+ AbstractManager.addSingletonRelation(relations, 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());
+ }
+
+ /**
+ * the missing relation is created
+ */
+ @Test
+ public void testAddSingletonRelation() {
+ RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
+ Relationship relation = OBJECT_FACTORY.createRelationship();
+ relation.setRelatedTo("unknownRelation");
+ relations.getRelationship().add(relation);
+
+ Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ newRelation.setRelatedTo("relatedTo");
+ RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ data2.setRelationshipValue("v2");
+ data2.setRelationshipKey("k2");
+ newRelation.getRelationshipData().add(data2);
+
+ //when
+ AbstractManager.addSingletonRelation(relations, 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());
+ }
+
+ /**
+ * the same relation is replaced
+ */
+ @Test
+ public void testAddMissingRelationForExisting() {
+ RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
+ Relationship relation = OBJECT_FACTORY.createRelationship();
+ relation.setRelatedTo("unknownRelation");
+ relations.getRelationship().add(relation);
+ Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ sameRelation.setRelatedTo("relatedTo");
+ relations.getRelationship().add(sameRelation);
+ RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ data.setRelationshipValue("v");
+ data.setRelationshipKey("k");
+ sameRelation.getRelationshipData().add(data);
+
+ Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ newRelation.setRelatedTo("relatedTo");
+ RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ data2.setRelationshipValue("v2");
+ data2.setRelationshipKey("k2");
+ newRelation.getRelationshipData().add(data2);
+
+ //when
+ AbstractManager.addMissingRelation(relations, 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());
+ }
+
+ /**
+ * adding the same relation is not duplicated
+ */
+ @Test
+ public void testAddMissingRelation() {
+ RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
+ Relationship relation = OBJECT_FACTORY.createRelationship();
+ relation.setRelatedTo("unknownRelation");
+ relations.getRelationship().add(relation);
+
+ Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ sameRelation.setRelatedTo("relatedTo");
+ relations.getRelationship().add(sameRelation);
+ RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ data.setRelationshipValue("v");
+ data.setRelationshipKey("k");
+ sameRelation.getRelationshipData().add(data);
+
+ Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ newRelation.setRelatedTo("relatedTo");
+ RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ data2.setRelationshipValue("v");
+ data2.setRelationshipKey("k");
+ newRelation.getRelationshipData().add(data2);
+
+ //when
+ AbstractManager.addMissingRelation(relations, 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());
+ }
+
+ class DummyManager extends AbstractManager {
+
+ DummyManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
+ super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
+ }
+
+ @Override
+ protected Logger getLogger() {
+ return logger;
+ }
+ }
+
+
+}
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
new file mode 100644
index 00000000..861966f3
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
@@ -0,0 +1,250 @@
+/*
+ * 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.notification;
+
+import com.nokia.cbam.lcm.v32.ApiException;
+import com.nokia.cbam.lcm.v32.model.VnfInfo;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+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.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 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;
+ private GenericVnfManager genericVnfManager;
+ private VnfInfo vnfInfo = new VnfInfo();
+
+ static void assertRelation(RelationshipList relationShips, String relatedTo, RelationshipData... data) {
+ for (Relationship relationship : relationShips.getRelationship()) {
+ if (relationship.getRelatedTo().equals(relatedTo)) {
+ assertEquals(data.length, relationship.getRelationshipData().size());
+ int i = 0;
+ for (RelationshipData c : data) {
+ assertEquals(c.getRelationshipKey(), relationship.getRelationshipData().get(i).getRelationshipKey());
+ assertEquals(c.getRelationshipValue(), relationship.getRelationshipData().get(i).getRelationshipValue());
+ i++;
+ }
+ return;
+ }
+ }
+ fail();
+ }
+
+ @Before
+ public void init() {
+ genericVnfManager = new GenericVnfManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
+ setField(GenericVnfManager.class, "logger", logger);
+ AtomicLong currentTime = new AtomicLong(0L);
+ when(systemFunctions.currentTimeMillis()).thenAnswer(new Answer<Long>() {
+ @Override
+ public Long answer(InvocationOnMock invocation) throws Throwable {
+ return currentTime.get();
+ }
+ });
+ Mockito.doAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ currentTime.addAndGet((Long) invocation.getArguments()[0] + 1);
+ return null;
+ }
+ }).when(systemFunctions).sleep(anyLong());
+ }
+
+ /**
+ * 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();
+ Set<GenericVnf> vnfs = new HashSet<>();
+ when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenAnswer((Answer<GenericVnf>) invocation -> {
+ if (vnfs.size() == 0) {
+ throw new NoSuchElementException();
+ }
+ return vnfs.iterator().next();
+ });
+ when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
+ vnfs.add(vnfInAaai);
+ return null;
+ });
+ 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("NokiaVNF", vnfSentToAai.getVnfType());
+ 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);
+ }
+
+ /**
+ * if the VNF exist it is updated
+ */
+ @Test
+ public void testUpdateExistingVnf() throws Exception {
+ GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ vnfInAaai.setResourceVersion("v1");
+ when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
+ when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(vnfInfo);
+ when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).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("NokiaVNF", vnfSentToAai.getVnfType());
+ 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);
+ }
+
+ /**
+ * error is propagated if unable to query VNF from CBAM
+ */
+ @Test
+ public void testUnableToQueryVnfFromCBAM() throws Exception {
+ GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ vnfInAaai.setResourceVersion("v1");
+ when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
+ ApiException expectedException = new ApiException();
+ when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
+ when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
+ vnfInAaai.setResourceVersion("v2");
+ return null;
+ });
+ vnfInfo.setName("vnfName");
+ //when
+ try {
+ genericVnfManager.createOrUpdate(VNF_ID, true);
+ } catch (Exception e) {
+ verify(logger).error("Unable to query VNF with myVnfId identifier from CBAM", expectedException);
+ assertEquals("Unable to query VNF with myVnfId identifier from CBAM", e.getMessage());
+ }
+ }
+
+ /**
+ * if the VNF is created after the last attempt to query VNF, but before the
+ * the driver creates the VNF it is not created but updated
+ */
+ @Test
+ public void testConcurency1() throws Exception {
+ GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ 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 -> {
+ queryCount.add(queryCount.size());
+ if (queryCount.size() >= 11) {
+ return vnfInAaai;
+ }
+ throw new NoSuchElementException();
+ });
+ when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(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];
+ if (vnfSentToAAi.getResourceVersion() == null) {
+ throw runtimeException;
+ }
+ return 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("NokiaVNF", vnfSentToAai.getVnfType());
+ 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), anyString(), eq(Void.class));
+ verify(logger).warn(eq("The VNF with myVnfId identifier did not appear in time"), any(NoSuchElementException.class));
+ verify(logger).warn("The VNF with myVnfId identifier has been created since after the maximal wait for VNF to appear timeout", runtimeException);
+ }
+
+ /**
+ * test how entities can refer to a VNF
+ */
+ @Test
+ public void testRelations() {
+ //when
+ Relationship relationship = GenericVnfManager.linkTo(VNF_ID);
+ //verify
+ assertEquals("generic-vnf", relationship.getRelatedTo());
+ assertEquals(1, relationship.getRelationshipData().size());
+ assertEquals("generic-vnf.vnf-id", relationship.getRelationshipData().get(0).getRelationshipKey());
+ assertEquals(VNF_ID, relationship.getRelationshipData().get(0).getRelationshipValue());
+ }
+
+ /**
+ * test inheritence
+ */
+ @Test
+ public void testInheritence() {
+ assertEquals(logger, genericVnfManager.getLogger());
+ }
+}
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
new file mode 100644
index 00000000..159d6e63
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
@@ -0,0 +1,143 @@
+/*
+ * 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.notification;
+
+import com.google.gson.JsonObject;
+import com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
+import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+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.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;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
+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;
+
+ @Before
+ public void init() {
+ l3NetworkManager = new L3NetworkManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
+ setField(L3NetworkManager.class, "logger", logger);
+ }
+
+ /**
+ * test L3 network creation
+ */
+ @Test
+ public void testUpdate() throws Exception {
+ affectedVirtualLink.setId("vlId");
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("name", "netName");
+ additionalData.addProperty("tenantId", "myTenantId");
+ 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);
+ //when
+ l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
+ //verify
+ assertEquals("myVnfId_vlId", payload.getValue().getNetworkId());
+ assertEquals("netName", payload.getValue().getNetworkName());
+ assertEquals("netProviderId", payload.getValue().getNeutronNetworkId());
+ assertFalse(payload.getValue().isIsBoundToVpn());
+ assertFalse(payload.getValue().isIsProviderNetwork());
+ assertFalse(payload.getValue().isIsSharedNetwork());
+ assertFalse(payload.getValue().isIsExternalNetwork());
+ assertEquals("active", payload.getValue().getOperationalStatus());
+ assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
+ assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
+ assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ }
+
+ /**
+ * Test existing resource update
+ */
+ @Test
+ public void testExistingUpdate() throws Exception {
+ affectedVirtualLink.setId("vlId");
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("name", "netName");
+ additionalData.addProperty("tenantId", "myTenantId");
+ affectedVirtualLink.setResource(new ResourceHandle());
+ affectedVirtualLink.getResource().setAdditionalData(additionalData);
+ affectedVirtualLink.getResource().setResourceId("netProviderId");
+ L3Network l3Network = OBJECT_FACTORY.createL3Network();
+ 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);
+ //when
+ l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
+ //verify
+ assertEquals("myVnfId_vlId", payload.getValue().getNetworkId());
+ assertEquals("netName", payload.getValue().getNetworkName());
+ assertEquals("netProviderId", payload.getValue().getNeutronNetworkId());
+ assertFalse(payload.getValue().isIsBoundToVpn());
+ assertFalse(payload.getValue().isIsProviderNetwork());
+ assertFalse(payload.getValue().isIsSharedNetwork());
+ assertFalse(payload.getValue().isIsExternalNetwork());
+ assertEquals("active", payload.getValue().getOperationalStatus());
+ assertEquals("v3", payload.getValue().getResourceVersion());
+ assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
+ assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
+ assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ }
+ /**
+ * test L3 network deletion
+ */
+ @Test
+ public void testDelete() throws Exception {
+ affectedVirtualLink.setId("vlId");
+ //when
+ l3NetworkManager.delete(VNF_ID, affectedVirtualLink);
+ //verify
+ verify(aaiRestApiProvider).delete(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId");
+ }
+
+ /**
+ * test inheritence
+ */
+ @Test
+ public void testInheritence() {
+ assertEquals(logger, l3NetworkManager.getLogger());
+ }
+
+
+}
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
new file mode 100644
index 00000000..ef9f569e
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
@@ -0,0 +1,230 @@
+/*
+ * 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.notification;
+
+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.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 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;
+
+ @Before
+ public void init() {
+ lInterfaceManager = new LInterfaceManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
+ setField(LInterfaceManager.class, "logger", logger);
+ }
+
+ /**
+ * test update success scenario
+ */
+ @Test
+ public void testUpdate() throws Exception {
+ ReportedAffectedCp affectedCp = new ReportedAffectedCp();
+ affectedCp.setCpdId("cpdId");
+ affectedCp.setTenantId("myTenantId");
+ affectedCp.setProviderId("portProviderId");
+ affectedCp.setServerProviderId("serverProviderId");
+ affectedCp.setNetworkProviderId("networkProviderId");
+ affectedCp.setMacAddress("mac");
+ affectedCp.setIpAddress("1.2.3.4");
+ 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);
+ //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("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("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));
+ }
+
+ /**
+ * test update success scenario without IP
+ */
+ @Test
+ public void testUpdateWithoutIp() throws Exception {
+ ReportedAffectedCp affectedCp = new ReportedAffectedCp();
+ affectedCp.setCpdId("cpdId");
+ affectedCp.setTenantId("myTenantId");
+ affectedCp.setProviderId("portProviderId");
+ affectedCp.setServerProviderId("serverProviderId");
+ affectedCp.setNetworkProviderId("networkProviderId");
+ affectedCp.setMacAddress("mac");
+ 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);
+ //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("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());
+ assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ }
+
+ /**
+ * test update success scenario
+ */
+ @Test
+ public void testExistingUpdate() throws Exception {
+ ReportedAffectedCp affectedCp = new ReportedAffectedCp();
+ affectedCp.setCpdId("cpdId");
+ affectedCp.setTenantId("myTenantId");
+ affectedCp.setProviderId("portProviderId");
+ affectedCp.setServerProviderId("serverProviderId");
+ affectedCp.setNetworkProviderId("networkProviderId");
+ affectedCp.setMacAddress("mac");
+ affectedCp.setIpAddress("1.2.3.4");
+ affectedCp.setEcpdId("ecpdId");
+ affectedCp.setName("name");
+ affectedCp.setCpId("cpId");
+ LInterface lInterface = OBJECT_FACTORY.createLInterface();
+ 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);
+ //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("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("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
+ assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
+ assertEquals("v3", lInterface.getResourceVersion());
+ assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ }
+
+ /**
+ * test update success scenario for IPv6 address
+ */
+ @Test
+ public void testUpdateForIpv6() throws Exception {
+ ReportedAffectedCp affectedCp = new ReportedAffectedCp();
+ affectedCp.setCpdId("cpdId");
+ affectedCp.setTenantId("myTenantId");
+ affectedCp.setProviderId("portProviderId");
+ affectedCp.setServerProviderId("serverProviderId");
+ affectedCp.setNetworkProviderId("networkProviderId");
+ affectedCp.setMacAddress("mac");
+ affectedCp.setIpAddress("::");
+ 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);
+ //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("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(1, actualInterface.getL3InterfaceIpv6AddressList().size());
+ assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv6AddressList().get(0).getNeutronNetworkId());
+ assertEquals("::", actualInterface.getL3InterfaceIpv6AddressList().get(0).getL3InterfaceIpv6Address());
+ assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ }
+
+ /**
+ * test L3 network deletion
+ */
+ @Test
+ public void testDelete() throws Exception {
+ ReportedAffectedCp affectedCp = new ReportedAffectedCp();
+ affectedCp.setCpId("cpId");
+ affectedCp.setCpdId("cpdId");
+ affectedCp.setTenantId("myTenantId");
+ affectedCp.setProviderId("portProviderId");
+ affectedCp.setServerProviderId("serverProviderId");
+ affectedCp.setNetworkProviderId("networkProviderId");
+ //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");
+ }
+
+ /**
+ * test inheritence
+ */
+ @Test
+ public void testInheritence() {
+ assertEquals(logger, lInterfaceManager.getLogger());
+ }
+
+
+}
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
new file mode 100644
index 00000000..87a1149b
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
@@ -0,0 +1,108 @@
+/*
+ * 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.notification;
+
+import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
+import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+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.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.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;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
+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;
+
+ @Before
+ public void init() {
+ vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
+ setField(VnfcManager.class, "logger", logger);
+ }
+
+ /**
+ * test update
+ */
+ @Test
+ public void testUpdate() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ 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);
+ //when
+ vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
+ //verify
+ Vnfc vnfc = payload.getValue();
+ assertEquals("myVnfId_vnfcId", vnfc.getVnfcName());
+ assertEquals("vnfcId", vnfc.getNfcFunction());
+ assertEquals("vnfcId", vnfc.getNfcNamingCode());
+ assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+
+ assertRelation(vnfc.getRelationshipList(), "vserver",
+ buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
+ buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
+ buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
+ buildRelationshipData("vserver.vserver-id", "serverProviderId"));
+ }
+
+ /**
+ * test delete
+ */
+ @Test
+ public void testDelete() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ 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);
+ //when
+ vnfcManager.delete(VNF_ID, affectedVnfc);
+ //verify
+ aaiRestApiProvider.delete(logger, NETWORK, "/vnfcs/vnfc/myVnfId_vnfcId");
+ }
+
+ /**
+ * test inheritence
+ */
+ @Test
+ public void testInheritence() {
+ assertEquals(logger, vnfcManager.getLogger());
+ }
+
+
+}
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
new file mode 100644
index 00000000..bb5d1d3d
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
@@ -0,0 +1,253 @@
+/*
+ * 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.notification;
+
+import com.google.gson.JsonArray;
+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 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.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.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;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
+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;
+
+ @Before
+ public void init() {
+ vserverManager = new VserverManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
+ setField(VserverManager.class, "logger", logger);
+ }
+
+ /**
+ * test update
+ */
+ @Test
+ public void testUpdate() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ affectedVnfc.setComputeResource(new ResourceHandle());
+ affectedVnfc.getComputeResource().setResourceId("serverProviderId");
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("name", "serverName");
+ additionalData.addProperty("tenantId", "myTenantId");
+ JsonArray links = new JsonArray();
+ links.add(new JsonObject());
+ JsonObject nonRelSelfink = new JsonObject();
+ nonRelSelfink.addProperty("rel", "self2");
+ nonRelSelfink.addProperty("href", "url");
+ links.add(nonRelSelfink);
+
+ JsonObject link = new JsonObject();
+ link.addProperty("rel", "self");
+ link.addProperty("href", "url");
+ links.add(link);
+ additionalData.add("links", links);
+ affectedVnfc.getComputeResource().setAdditionalData(additionalData);
+ affectedVnfc.setId("vnfcId");
+ List<AffectedVirtualStorage> affectedStorages = new ArrayList<>();
+ affectedStorages.add(new AffectedVirtualStorage());
+ affectedStorages.get(0).setId("sId");
+ affectedStorages.get(0).setResource(new ResourceHandle());
+ affectedStorages.get(0).getResource().setResourceId("storageProviderId");
+ affectedVnfc.setStorageResourceIds(new ArrayList<>());
+ affectedVnfc.getStorageResourceIds().add("sId");
+
+ String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
+
+ 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);
+ //when
+ vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
+ //verify
+ Vserver vserver = payload.getValue();
+ assertEquals("serverProviderId", vserver.getVserverId());
+ 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());
+ }
+
+ /**
+ * test missing links
+ */
+ @Test
+ public void testUpdateEmptyLinks() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ affectedVnfc.setComputeResource(new ResourceHandle());
+ affectedVnfc.getComputeResource().setResourceId("serverProviderId");
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("name", "serverName");
+ additionalData.addProperty("tenantId", "myTenantId");
+ JsonArray links = new JsonArray();
+ additionalData.add("links", links);
+ affectedVnfc.getComputeResource().setAdditionalData(additionalData);
+ affectedVnfc.setId("vnfcId");
+ List<AffectedVirtualStorage> affectedStorages = new ArrayList<>();
+ affectedStorages.add(new AffectedVirtualStorage());
+ affectedStorages.get(0).setId("sId");
+ affectedStorages.get(0).setResource(new ResourceHandle());
+ affectedStorages.get(0).getResource().setResourceId("storageProviderId");
+ 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);
+ //when
+ vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
+ //verify
+ Vserver vserver = payload.getValue();
+ assertEquals("serverProviderId", vserver.getVserverId());
+ 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());
+ }
+
+ /**
+ * test update when links is not present on vServer
+ */
+ @Test
+ public void testUpdateWithNoLinks() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ affectedVnfc.setComputeResource(new ResourceHandle());
+ affectedVnfc.getComputeResource().setResourceId("serverProviderId");
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("name", "serverName");
+ additionalData.addProperty("tenantId", "myTenantId");
+ affectedVnfc.getComputeResource().setAdditionalData(additionalData);
+ affectedVnfc.setId("vnfcId");
+ List<AffectedVirtualStorage> affectedStorages = new ArrayList<>();
+ affectedStorages.add(new AffectedVirtualStorage());
+ affectedStorages.get(0).setId("sId");
+ affectedStorages.get(0).setResource(new ResourceHandle());
+ affectedStorages.get(0).getResource().setResourceId("storageProviderId");
+ 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);
+ //when
+ vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
+ //verify
+ Vserver vserver = payload.getValue();
+ assertEquals("serverProviderId", vserver.getVserverId());
+ 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());
+ }
+
+ /**
+ * test update when removing volumes
+ */
+ @Test
+ public void testUpdateWithRemovingVolumes() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ affectedVnfc.setComputeResource(new ResourceHandle());
+ affectedVnfc.getComputeResource().setResourceId("serverProviderId");
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("name", "serverName");
+ additionalData.addProperty("tenantId", "myTenantId");
+ 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);
+ //when
+ vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
+ //verify
+ Vserver vserver = payload.getValue();
+ assertEquals("serverProviderId", vserver.getVserverId());
+ assertEquals("active", vserver.getProvStatus());
+ assertEquals("serverName", vserver.getVserverName());
+ assertEquals("unknown", vserver.getVserverSelflink());
+ assertEquals(0, vserver.getVolumes().getVolume().size());
+ }
+
+ /**
+ * test delete
+ */
+ @Test
+ public void testDelete() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ affectedVnfc.setComputeResource(new ResourceHandle());
+ affectedVnfc.getComputeResource().setResourceId("serverProviderId");
+ JsonObject additionalData = new JsonObject();
+ additionalData.addProperty("name", "serverName");
+ additionalData.addProperty("tenantId", "myTenantId");
+ affectedVnfc.getComputeResource().setAdditionalData(additionalData);
+ affectedVnfc.setId("vnfcId");
+ //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);
+ }
+
+ @Test
+ public void testLinks() {
+ Relationship relationship = VserverManager.linkTo(VIM_ID, "myTenantPrivderId", "serverProviderId");
+ RelationshipList relationships = new RelationshipList();
+ relationships.getRelationship().add(relationship);
+ assertRelation(relationships, "vserver",
+ buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
+ buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
+ buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
+ buildRelationshipData("vserver.vserver-id", "serverProviderId"));
+ }
+
+ /**
+ * test inheritence
+ */
+ @Test
+ public void testInheritence() {
+ assertEquals(logger, vserverManager.getLogger());
+ }
+
+
+}