summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/test/java
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-08 21:44:02 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-08 21:44:02 +0100
commitf6228e56abb06a36212216bc5674e69e6c0d9610 (patch)
treee4f212d8c47c2484343989794fa93f6bd5566392 /nokiav2/driver/src/test/java
parent270744e18b624e750e3a5f4fac59780068196147 (diff)
Adding missing tests
Change-Id: I2b0de4c101535259f133436d6997ae393ba6c8ef Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/test/java')
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java40
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java78
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java111
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java20
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java29
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java19
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java162
7 files changed, 390 insertions, 69 deletions
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
index 17cf8258..a0d4ea4d 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
@@ -87,29 +87,11 @@ public class TestGenericExternalSystemInfoProvider extends TestBase {
verify(genericExternalSystemInfoProvider, Mockito.times(2)).queryVnfmInfoFromSource(VNFM_ID);
}
- class TestClass extends GenericExternalSystemInfoProvider {
-
- TestClass(Environment environment) {
- super(environment);
- }
-
- @Override
- public VnfmInfo queryVnfmInfoFromSource(String vnfmId) {
- return null;
- }
-
- @Override
- public VimInfo getVimInfo(String vimId) {
- return null;
- }
- }
-
-
/**
* Unable to query VNFM results is propagated
*/
@Test
- public void testUnableToQueryVnfmInfoProvider() throws Exception{
+ public void testUnableToQueryVnfmInfoProvider() throws Exception {
class TestClass extends GenericExternalSystemInfoProvider {
TestClass(Environment environment) {
@@ -129,10 +111,26 @@ public class TestGenericExternalSystemInfoProvider extends TestBase {
try {
new TestClass(null).getVnfmInfo(VNFM_ID);
fail();
- }
- catch (Exception e){
+ } catch (Exception e) {
assertEquals("Unable to query VNFM info for myVnfmId", e.getMessage());
verify(logger).error(eq("Unable to query VNFM info for myVnfmId"), any(RuntimeException.class));
}
}
+
+ class TestClass extends GenericExternalSystemInfoProvider {
+
+ TestClass(Environment environment) {
+ super(environment);
+ }
+
+ @Override
+ public VnfmInfo queryVnfmInfoFromSource(String vnfmId) {
+ return null;
+ }
+
+ @Override
+ public VimInfo getVimInfo(String vimId) {
+ return null;
+ }
+ }
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
index a2bf0305..4bbf0764 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
@@ -159,6 +159,32 @@ public class TestVfcGrantManager extends TestBase {
}
/**
+ * grant is requested for termination if the the VNF is instantiated even if has no VNFCs
+ */
+ @Test
+ public void testGrantIsRequestedIfInstantiatedWithNoVnfcs() {
+ VnfInfo vnf = new VnfInfo();
+ vnf.setId(VNF_ID);
+ vnf.setInstantiationState(InstantiationState.INSTANTIATED);
+ InstantiatedVnfInfo instantiatedVnfInfo = new InstantiatedVnfInfo();
+ vnf.setInstantiatedVnfInfo(instantiatedVnfInfo);
+ VnfProperty prop = new VnfProperty();
+ prop.setName(LifecycleManager.ONAP_CSAR_ID);
+ prop.setValue(ONAP_CSAR_ID);
+ vnf.setVnfConfigurableProperties(new ArrayList<>());
+ vnf.getVnfConfigurableProperties().add(prop);
+ //when
+ vfcGrantManager.requestGrantForTerminate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, vnf, JOB_ID);
+ //verify
+ assertEquals(1, grantRequest.getAllValues().size());
+ GrantVNFRequest request = grantRequest.getValue();
+ assertVduInGrant(request.getRemoveResource(), "vdu1", 0);
+ assertVduInGrant(request.getRemoveResource(), "vdu2", 0);
+ assertEquals(0, request.getAddResource().size());
+ assertBasicGrantAttributes(request, org.onap.vnfmdriver.model.OperationType.TERMINAL);
+ }
+
+ /**
* test failure logging & propagation during grant request for instantiation
*/
@Test
@@ -179,7 +205,7 @@ public class TestVfcGrantManager extends TestBase {
}
/**
- * failuire is to request grant is logged
+ * failure is to request grant is logged
*/
@Test
public void testFailureToRequestGrantIsLogged() throws Exception {
@@ -211,7 +237,7 @@ public class TestVfcGrantManager extends TestBase {
}
/**
- * failuire is to request grant is logged
+ * failure is to request grant is logged
*/
@Test
public void testFailureToRequestGrantForScaleIsLogged() throws Exception {
@@ -259,6 +285,54 @@ public class TestVfcGrantManager extends TestBase {
}
/**
+ * test grant request for scale out without VDUs
+ */
+ @Test
+ public void testGrantDuringScaleOutWithoutVdus() throws Exception {
+ String cbamVnfdContent = new String(readAllBytes(Paths.get(TestVfcGrantManager.class.getResource("/unittests/vnfd.scale.yaml").toURI())));
+ VnfScaleRequest scaleRequest = new VnfScaleRequest();
+ scaleRequest.setType(ScaleDirection.OUT);
+ scaleRequest.setAspectId("aspectWithOutVdu");
+ scaleRequest.setNumberOfSteps("2");
+ VnfInfo vnf = new VnfInfo();
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ vnf.setVnfdId(CBAM_VNFD_ID);
+ when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent);
+ //when
+ vfcGrantManager.requestGrantForScale(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, scaleRequest, JOB_ID);
+ //verify
+ assertEquals(1, grantRequest.getAllValues().size());
+ GrantVNFRequest request = grantRequest.getValue();
+ assertVduInGrant(request.getAddResource(), "vdu1", 0);
+ assertVduInGrant(request.getAddResource(), "vdu2", 0);
+ assertEquals(0, request.getRemoveResource().size());
+ assertBasicGrantAttributes(request, org.onap.vnfmdriver.model.OperationType.SCALEOUT);
+ }
+
+ /**
+ * test grant request for scale out without resources
+ */
+ @Test
+ public void testGrantDuringScaleOutForEmptyAspect() throws Exception {
+ String cbamVnfdContent = new String(readAllBytes(Paths.get(TestVfcGrantManager.class.getResource("/unittests/vnfd.scale.yaml").toURI())));
+ VnfScaleRequest scaleRequest = new VnfScaleRequest();
+ scaleRequest.setType(ScaleDirection.OUT);
+ scaleRequest.setAspectId("emptyAspect");
+ scaleRequest.setNumberOfSteps("2");
+ VnfInfo vnf = new VnfInfo();
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ vnf.setVnfdId(CBAM_VNFD_ID);
+ when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent);
+ //when
+ try {
+ vfcGrantManager.requestGrantForScale(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, scaleRequest, JOB_ID);
+ fail();
+ } catch (Exception e) {
+ assertEquals("Missing child emptyAspect", e.getMessage());
+ }
+ }
+
+ /**
* test grant request for scale in
*/
@Test
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
index 008d8272..d28e224f 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
@@ -41,6 +41,8 @@ import org.threeten.bp.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
+import static java.util.Optional.empty;
+import static java.util.Optional.of;
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
@@ -114,7 +116,7 @@ public class TestVfcNotificationSender extends TestBase {
recievedLcn.setStatus(OperationStatus.STARTED);
recievedLcn.setOperation(OperationType.INSTANTIATE);
//when
- vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedCp, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID);
//verify
assertEquals(1, sentLcnToVfc.getAllValues().size());
assertNull(sentLcnToVfc.getValue().getAffectedVl());
@@ -188,7 +190,7 @@ public class TestVfcNotificationSender extends TestBase {
JsonElement additionalData = new Gson().toJsonTree(operationResult);
instantiationOperation.setAdditionalData(additionalData);
//when
- vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedConnectionPoints, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID);
//verify
assertEquals(1, sentLcnToVfc.getAllValues().size());
@@ -271,7 +273,7 @@ public class TestVfcNotificationSender extends TestBase {
JsonElement additionalData = new Gson().toJsonTree(operationResult);
instantiationOperation.setAdditionalData(additionalData);
//when
- vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedConnectionPoints, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID);
//verify
assertEquals(1, sentLcnToVfc.getAllValues().size());
@@ -352,7 +354,7 @@ public class TestVfcNotificationSender extends TestBase {
JsonElement additionalData = new Gson().toJsonTree(operationResult);
instantiationOperation.setAdditionalData(additionalData);
//when
- vfcNotificationSender.processNotification(recievedLcn, terminationOperation, affectedConnectionPoints, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, terminationOperation, of(affectedConnectionPoints), VIM_ID);
//verify
assertEquals(1, sentLcnToVfc.getAllValues().size());
@@ -473,7 +475,7 @@ public class TestVfcNotificationSender extends TestBase {
JsonElement additionalData = new Gson().toJsonTree(operationResult);
instantiationOperation.setAdditionalData(additionalData);
//when
- vfcNotificationSender.processNotification(recievedLcn, healOperation, affectedConnectionPoints, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID);
//verify
assertEquals(1, sentLcnToVfc.getAllValues().size());
@@ -585,7 +587,7 @@ public class TestVfcNotificationSender extends TestBase {
JsonElement additionalData = new Gson().toJsonTree(operationResult);
scaleOperation.setAdditionalData(additionalData);
//when
- vfcNotificationSender.processNotification(recievedLcn, scaleOperation, affectedConnectionPoints, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID);
//verify
assertEquals(1, sentLcnToVfc.getAllValues().size());
@@ -698,7 +700,7 @@ public class TestVfcNotificationSender extends TestBase {
scaleOperation.setAdditionalData(additionalData);
scaleOperation.setOperationType(OperationType.SCALE);
//when
- vfcNotificationSender.processNotification(recievedLcn, scaleOperation, affectedConnectionPoints, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID);
//verify
assertEquals(1, sentLcnToVfc.getAllValues().size());
@@ -742,6 +744,99 @@ public class TestVfcNotificationSender extends TestBase {
assertEquals(VNF_ID, sentLcnToVfc.getValue().getVnfInstanceId());
}
+
+ /**
+ * en empty LCN is sent even if nothing has changed
+ */
+ @Test
+ public void testNothingChanged() {
+ //given
+ recievedLcn.setOperation(OperationType.SCALE);
+ recievedLcn.setStatus(OperationStatus.FINISHED);
+ recievedLcn.setLifecycleOperationOccurrenceId(scaleOperation.getId());
+ ScaleVnfRequest request = new ScaleVnfRequest();
+ request.setAdditionalParams(new JsonParser().parse("{ \"jobId\" : \"" + JOB_ID + "\" }"));
+ request.setType(ScaleDirection.IN);
+ scaleOperation.setOperationParams(request);
+ OperationResult operationResult = new OperationResult();
+ JsonElement additionalData = new Gson().toJsonTree(operationResult);
+ scaleOperation.setAdditionalData(additionalData);
+ scaleOperation.setOperationType(OperationType.SCALE);
+ when(logger.isInfoEnabled()).thenReturn(false);
+ //when
+ vfcNotificationSender.processNotification(recievedLcn, scaleOperation, empty(), VIM_ID);
+ //verify
+ assertEquals(1, sentLcnToVfc.getAllValues().size());
+
+ assertNull(sentLcnToVfc.getValue().getAffectedVl());
+ assertNull(sentLcnToVfc.getValue().getAffectedVnfc());
+ assertNull(sentLcnToVfc.getValue().getAffectedCp());
+ assertNull(sentLcnToVfc.getValue().getAffectedVirtualStorage());
+ assertEquals(JOB_ID, sentLcnToVfc.getValue().getJobId());
+ assertEquals(org.onap.vnfmdriver.model.OperationType.SCALEIN, sentLcnToVfc.getValue().getOperation());
+ assertEquals(VnfLcmNotificationStatus.RESULT, sentLcnToVfc.getValue().getStatus());
+ assertEquals(VNF_ID, sentLcnToVfc.getValue().getVnfInstanceId());
+ verify(logger, never()).info(eq("Sending LCN: {}"), anyString());
+ }
+
+ /**
+ * If a connection point is not modified it is not contained in the LCN
+ */
+ @Test
+ public void testNonModifiedCP() {
+ //given
+ recievedLcn.setOperation(OperationType.HEAL);
+ recievedLcn.setStatus(OperationStatus.FINISHED);
+
+ ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
+ ReportedAffectedCp affectedCp = new ReportedAffectedCp();
+ affectedCp.setCpdId("cpVnfdId");
+ affectedCp.setIpAddress("1.2.3.4");
+ affectedCp.setMacAddress("myMac");
+ affectedCp.setName("myPortName");
+ affectedCp.setCpId("cpId");
+
+ // affectedCp.setEcpdId("ecpdId");
+ affectedCp.setNetworkProviderId("networkProviderId");
+ affectedCp.setProviderId("portProviderId");
+ affectedCp.setServerProviderId("serverProviderId");
+ affectedCp.setTenantId("tenantId");
+ affectedConnectionPoints.getPre().add(affectedCp);
+
+ ReportedAffectedCp after = new ReportedAffectedCp();
+ after.setCpdId("cpVnfdId");
+ after.setIpAddress("1.2.3.4");
+ after.setMacAddress("myMac");
+ after.setName("myPortName");
+ after.setCpId("cpId");
+
+ // affectedCp.setEcpdId("ecpdId");
+ after.setNetworkProviderId("networkProviderId");
+ after.setProviderId("portProviderId");
+ after.setServerProviderId("serverProviderId");
+ after.setTenantId("tenantId");
+ affectedConnectionPoints.getPost().add(after);
+
+
+ OperationResult operationResult = new OperationResult();
+ operationResult.operationResult = affectedConnectionPoints;
+ JsonElement additionalData = new Gson().toJsonTree(operationResult);
+ instantiationOperation.setAdditionalData(additionalData);
+ //when
+ vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID);
+ //verify
+ assertEquals(1, sentLcnToVfc.getAllValues().size());
+
+ assertNull(sentLcnToVfc.getValue().getAffectedVl());
+ assertNull(sentLcnToVfc.getValue().getAffectedVnfc());
+ assertEquals(0, sentLcnToVfc.getValue().getAffectedCp().size());
+ assertNull(sentLcnToVfc.getValue().getAffectedVirtualStorage());
+ assertEquals(JOB_ID, sentLcnToVfc.getValue().getJobId());
+ assertEquals(org.onap.vnfmdriver.model.OperationType.HEAL, sentLcnToVfc.getValue().getOperation());
+ assertEquals(VnfLcmNotificationStatus.RESULT, sentLcnToVfc.getValue().getStatus());
+ assertEquals(VNF_ID, sentLcnToVfc.getValue().getVnfInstanceId());
+ }
+
/**
* Unable to send notification to VF-C results in error
*/
@@ -753,7 +848,7 @@ public class TestVfcNotificationSender extends TestBase {
recievedLcn.setOperation(OperationType.INSTANTIATE);
//when
try {
- vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedCp, VIM_ID);
+ vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID);
//verify
fail();
} catch (Exception e) {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
index fd93dce2..5001eedf 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
@@ -15,6 +15,7 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
+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;
@@ -23,11 +24,19 @@ import java.util.NoSuchElementException;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
+import static org.mockito.Mockito.verify;
+import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestOnapVnfdBuilder extends TestBase {
private OnapVnfdBuilder packageTransformer = new OnapVnfdBuilder();
+
+ @Before
+ public void init() {
+ setField(OnapVnfdBuilder.class, "logger", logger);
+ }
+
@Test
public void indent() {
assertEquals(" x", packageTransformer.indent("x", 2));
@@ -51,6 +60,17 @@ public class TestOnapVnfdBuilder extends TestBase {
@Test
public void testNodes() {
assertEquals(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.onap.yaml")), packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.cbam.yaml"))));
+ verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp");
+ verify(logger).warn("The {} ecp does not have an requirements section", "ecpWithIcpWithOutRequirements");
+ verify(logger).warn("The {} internal connection point of the {} ecp does not have a VDU", "icpWithoutVdu", "myEcpWithoutIcpWithoutVdu");
+
+ verify(logger).warn("The {} internal connection point of the {} ecp does not have a requirements section", "icpWithOutRequiements", "myEcpWithoutIcpWithoutIcpReq");
+
+
+ verify(logger).warn("The {} internal connection point does not have a VDU", "icpWithOutVdu");
+ verify(logger).warn("The {} internal connection point does not have a requirements section", "icpWithOutRequiements");
+ verify(logger).warn("The {} internal connection point does not have a VL", "icpWithOutVl");
+
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
index 95bdc5f4..218c478e 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
@@ -17,7 +17,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
import com.google.common.collect.Lists;
-import junit.framework.TestCase;
import org.apache.http.entity.ContentType;
import org.junit.Before;
import org.junit.Test;
@@ -41,9 +40,9 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertTrue;
-import static junit.framework.TestCase.fail;
+import static junit.framework.TestCase.*;
+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.vnfm.CatalogManager.getFileInZip;
@@ -121,17 +120,33 @@ public class TestConverterApi extends TestBase {
* error is propagated if unable to extract package from HTTP request
*/
@Test
- public void testUnableToExtractPackageToBeConverted() throws Exception{
+ public void testUnableToExtractPackageToBeConverted() throws Exception {
IOException expectedException = new IOException();
when(httpRequest.getParts()).thenThrow(expectedException);
try {
converterApi.convert(httpResponse, httpRequest);
fail();
- }
- catch (Exception e){
+ } catch (Exception e) {
verify(logger).error("Unable to extract package from REST parameters", expectedException);
assertEquals("Unable to extract package from REST parameters", e.getMessage());
assertEquals(expectedException, e.getCause());
}
}
+
+ /**
+ * error is propagated if unable to extract package from HTTP request
+ */
+ @Test
+ public void testUnableToConvertPackage() throws Exception {
+ Part part = Mockito.mock(Part.class);
+ when(part.getInputStream()).thenReturn(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip")));
+ when(httpRequest.getParts()).thenReturn(Lists.newArrayList(part));
+ try {
+ converterApi.convert(httpResponse, httpRequest);
+ fail();
+ } catch (Exception e) {
+ verify(logger).error(eq("Unable to convert VNF package"), any(RuntimeException.class));
+ assertEquals("Unable to convert VNF package", e.getMessage());
+ }
+ }
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
index 3ff53643..c601f7ee 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
@@ -52,6 +52,7 @@ import static java.nio.file.Files.readAllBytes;
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION;
import static org.springframework.test.util.ReflectionTestUtils.setField;
@@ -251,8 +252,8 @@ public class TestLifecycleManager extends TestBase {
//the 3.2 API does not accept empty array
assertNull(actualVnfModifyRequest.getValue().getVnfConfigurableProperties());
verify(jobManager).spawnJob(VNF_ID, restResponse);
- //verify(logger).info(eq("Additional parameters for instantiation: {}"), anyString());
- //FIXME
+ verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("creation"), eq("not yet specified"), anyString());
+ verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("instantiation"), eq(VNF_ID), anyString());
}
/**
@@ -263,7 +264,7 @@ public class TestLifecycleManager extends TestBase {
//given
VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OTHER_VIM_INFO);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo);
- when(logger.isDebugEnabled()).thenReturn(false);
+ when(logger.isInfoEnabled()).thenReturn(false);
//when
try {
lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
@@ -273,7 +274,8 @@ public class TestLifecycleManager extends TestBase {
assertEquals("Only OPENSTACK_V2_INFO, OPENSTACK_V3_INFO and VMWARE_VCLOUD_INFO is the supported VIM types", e.getMessage());
}
verify(vnfApi, never()).vnfsPost(Mockito.any(), Mockito.any());
- verify(logger, never()).debug(eq("Additional parameters for instantiation: {}"), anyString());
+ verify(logger, never()).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("creation"), eq("not yet specified"), anyString());
+ verify(logger, never()).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("instantiation"), eq(VNF_ID), anyString());
verify(logger).error("Only OPENSTACK_V2_INFO, OPENSTACK_V3_INFO and VMWARE_VCLOUD_INFO is the supported VIM types");
}
@@ -296,6 +298,9 @@ public class TestLifecycleManager extends TestBase {
grantResponse.setAccessInfo(accessInfo);
ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution);
+ JsonObject inputs = child((JsonObject) instantiationRequest.getAdditionalParam(), "inputs");
+ JsonObject vnfs = child(child(inputs, "vnfs"), ONAP_CSAR_ID);
+ vnfs.remove("additionalParams");
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
waitForJobToFinishInJobManager(finished);
@@ -305,9 +310,9 @@ public class TestLifecycleManager extends TestBase {
assertEquals(StoreLoader.getCertifacates(caCert).iterator().next(), new String(actualVim.getInterfaceInfo().getTrustedCertificates().get(0)));
assertTrue(!actualVim.getInterfaceInfo().isSkipCertificateVerification());
assertTrue(!actualVim.getInterfaceInfo().isSkipCertificateHostnameCheck());
+ verify(logger).warn("No additional parameters were specified for the operation");
}
-
/**
* non specified SSL verification means not verified
*/
@@ -753,6 +758,7 @@ public class TestLifecycleManager extends TestBase {
notificationIsProcessedBeforeDeletingTheVnf.verify(notificationManager).waitForTerminationToBeProcessed("terminationId");
notificationIsProcessedBeforeDeletingTheVnf.verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
verify(jobManager).spawnJob(VNF_ID, restResponse);
+ verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("termination"), eq(VNF_ID), anyString());
}
/**
@@ -1158,6 +1164,8 @@ public class TestLifecycleManager extends TestBase {
assertEquals(Integer.valueOf(2), sRequest.getNumberOfSteps());
assertTrue("{\"jobId\":\"myJobId\",\"a\":\"b\"}".equals(new Gson().toJson(sRequest.getAdditionalParams())) || "{\"a\":\"b\",\"jobId\":\"myJobId\"}".equals(new Gson().toJson(sRequest.getAdditionalParams())));
verify(jobManager).spawnJob(VNF_ID, restResponse);
+ verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("scale"), eq(VNF_ID), anyString());
+
}
/**
@@ -1322,6 +1330,7 @@ public class TestLifecycleManager extends TestBase {
assertEquals("vmName", root.get("vmName").getAsString());
assertEquals(JOB_ID, root.get("jobId").getAsString());
verify(jobManager).spawnJob(VNF_ID, restResponse);
+ verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("heal"), eq(VNF_ID), anyString());
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
index 18567f4c..7121bea6 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
@@ -31,10 +31,8 @@ import org.threeten.bp.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
+import java.util.Optional;
+import java.util.concurrent.*;
import static com.nokia.cbam.lcm.v32.model.OperationType.*;
import static junit.framework.TestCase.*;
@@ -56,7 +54,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
private OperationExecution terminationOperation = new OperationExecution();
private ArgumentCaptor<OperationExecution> currentOperationExecution = ArgumentCaptor.forClass(OperationExecution.class);
- private ArgumentCaptor<ReportedAffectedConnectionPoints> affectedConnectionPoints = ArgumentCaptor.forClass(ReportedAffectedConnectionPoints.class);
+ private ArgumentCaptor<Optional> affectedConnectionPoints = ArgumentCaptor.forClass(Optional.class);
private List<VnfInfo> vnfs = new ArrayList<>();
private VnfInfo vnf = new VnfInfo();
@@ -240,6 +238,19 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
}
/**
+ * LCN is not logged in case of non info log level
+ */
+ @Test
+ public void testNoLogging() throws Exception {
+ vnf.getExtensions().clear();
+ when(logger.isInfoEnabled()).thenReturn(false);
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ //verify
+ verify(logger, never()).info(eq("Received LCN: {}"), anyString());
+ }
+
+ /**
* if the VNF is not managed by this VNFM the LCN is dropped
*/
@Test
@@ -345,6 +356,38 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
}
/**
+ * the processing of the start notification does not trigger the deletion of the VNF
+ */
+ @Test
+ public void testStartLcnForTerminate() throws Exception {
+ recievedLcn.setOperation(OperationType.TERMINATE);
+ recievedLcn.setStatus(OperationStatus.STARTED);
+ recievedLcn.setLifecycleOperationOccurrenceId(terminationOperation.getId());
+ ExecutorService executorService = Executors.newCachedThreadPool();
+ Future<Boolean> waitExitedWithSuccess = executorService.submit(() -> {
+ try {
+ lifecycleChangeNotificationManager.waitForTerminationToBeProcessed(terminationOperation.getId());
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ });
+ //processing the start notification
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ //verify
+ try {
+ waitExitedWithSuccess.get(10, TimeUnit.MILLISECONDS);
+ fail();
+ } catch (Exception e) {
+ }
+ recievedLcn.setStatus(OperationStatus.FINISHED);
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ //verify
+ assertTrue(waitExitedWithSuccess.get());
+ }
+
+ /**
* Forceful termination results in an empty affected connection points
*/
@Test
@@ -361,11 +404,50 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
terminationOperation.setOperationType(OperationType.TERMINATE);
//when
lifecycleChangeNotificationManager.handleLcn(recievedLcn);
- assertNull(affectedConnectionPoints.getValue());
+ assertFalse(affectedConnectionPoints.getValue().isPresent());
verify(logger).warn("Unable to send information related to affected connection points during forceful termination");
}
/**
+ * Failures in affected connection point processing are tolerated for failed operation
+ * (because the POST script was not able to run)
+ */
+ @Test
+ public void testFailedOperations() throws Exception {
+ //given
+ recievedLcn.setOperation(OperationType.INSTANTIATE);
+ recievedLcn.setStatus(OperationStatus.FAILED);
+ recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId());
+ instantiationOperation.setAdditionalData(null);
+ instantiationOperation.setStatus(OperationStatus.FAILED);
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ //verify
+ assertFalse(affectedConnectionPoints.getValue().isPresent());
+ verify(logger).warn("The operation failed and the affected connection points were not reported");
+ }
+
+ /**
+ * Failures in affected connection point processing are tolerated for failed operation
+ * (because the POST script was not able to run)
+ */
+ @Test
+ public void testMissingOperationResult() throws Exception {
+ //given
+ recievedLcn.setOperation(OperationType.INSTANTIATE);
+ recievedLcn.setStatus(OperationStatus.FAILED);
+ recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId());
+ instantiationOperation.setStatus(OperationStatus.FAILED);
+ JsonObject additionalData = (JsonObject) instantiationOperation.getAdditionalData();
+ additionalData.remove("operationResult");
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ //verify
+ assertFalse(affectedConnectionPoints.getValue().isPresent());
+ verify(logger).warn("The operation failed and the affected connection points were not reported");
+ }
+
+ /**
* test end notification scenario for failed scale-out
* - LCN is sent to VF-C, but the
*/
@@ -384,12 +466,58 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
scaleOperation.setOperationType(OperationType.SCALE);
//when
lifecycleChangeNotificationManager.handleLcn(recievedLcn);
- assertEquals(0, affectedConnectionPoints.getValue().getPost().size());
- assertEquals(0, affectedConnectionPoints.getValue().getPre().size());
+ assertFalse(affectedConnectionPoints.getValue().isPresent());
+ verify(logger).warn("The operation failed and the affected connection points were not reported");
+ }
+
+ /**
+ * if the cbam_post is missing error handling should be applied
+ */
+ @Test
+ public void testMissingPostResultForFailedOperation() {
+ //given
+ recievedLcn.setOperation(OperationType.SCALE);
+ recievedLcn.setStatus(OperationStatus.FAILED);
+ recievedLcn.setLifecycleOperationOccurrenceId(scaleOperation.getId());
+ ScaleVnfRequest request = new ScaleVnfRequest();
+ request.setAdditionalParams(new JsonParser().parse("{ \"type\" : \"IN\", \"jobId\" : \"" + JOB_ID + "\" }"));
+ request.setType(ScaleDirection.OUT);
+ scaleOperation.setOperationParams(request);
+ scaleOperation.setStatus(OperationStatus.FAILED);
+ ((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject().remove("cbam_post");
+ scaleOperation.setOperationType(OperationType.SCALE);
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ assertFalse(affectedConnectionPoints.getValue().isPresent());
verify(logger).warn("The operation failed and the affected connection points were not reported");
}
/**
+ * if invalid type is specified for cbam_post error handling should be applied
+ */
+ @Test
+ public void testInvalidPost() {
+ //given
+ recievedLcn.setOperation(OperationType.SCALE);
+ recievedLcn.setStatus(OperationStatus.FAILED);
+ recievedLcn.setLifecycleOperationOccurrenceId(scaleOperation.getId());
+ ScaleVnfRequest request = new ScaleVnfRequest();
+ request.setAdditionalParams(new JsonParser().parse("{ \"type\" : \"IN\", \"jobId\" : \"" + JOB_ID + "\" }"));
+ request.setType(ScaleDirection.OUT);
+ scaleOperation.setOperationParams(request);
+ scaleOperation.setStatus(OperationStatus.FAILED);
+ JsonObject operationResult = ((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject();
+ operationResult.remove("cbam_post");
+ operationResult.addProperty("cbam_post", "");
+ scaleOperation.setOperationType(OperationType.SCALE);
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ assertFalse(affectedConnectionPoints.getValue().isPresent());
+ verify(logger).warn("The operation failed and the affected connection points were not reported");
+ }
+
+
+ /**
* test end notification success scenario for scale-out
* - LCN is sent to VF-C
*/
@@ -419,24 +547,6 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
}
}
- /**
- * missing connection points are tolerated in case of failed operations
- */
- @Test
- public void testMissingConnectionPoints() {
- //given
- recievedLcn.setOperation(OperationType.INSTANTIATE);
- recievedLcn.setStatus(OperationStatus.FAILED);
- recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId());
- instantiationOperation.setAdditionalData(null);
- instantiationOperation.setStatus(OperationStatus.FAILED);
- //when
- lifecycleChangeNotificationManager.handleLcn(recievedLcn);
- assertEquals(0, affectedConnectionPoints.getValue().getPost().size());
- assertEquals(0, affectedConnectionPoints.getValue().getPre().size());
- verify(logger).warn("The operation failed and the affected connection points were not reported");
- }
-
private JsonObject buildTerminationParams() {
JsonObject root = new JsonObject();
root.add("terminationType", new JsonPrimitive("GRACEFULL"));