diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-26 14:25:44 +0200 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-26 14:27:41 +0200 |
commit | c088d641a7805e65694884d9f7ff89c88ac7a886 (patch) | |
tree | c711259c8cc02562e770401e5611cf823cbbd4c0 | |
parent | 6f07ddf3d394a5221c9acb722a3ca6556f70c862 (diff) |
Fix sonar issues
Change-Id: I24ffa257b614b6dfa9768a54689424989308c9cf
Issue-ID: VFC-728
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
23 files changed, 228 insertions, 112 deletions
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java index 0c57c376..172dd338 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java @@ -86,7 +86,7 @@ public class SelfRegistrationManager { public void deRegister() { try { logger.info("Cancelling micro service registration"); - systemFunctions().blockingFirst(msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)); + msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null).blockingFirst(); } catch (Exception e) { //ONAP throws 500 internal server error, but deletes the micro service boolean serviceFoundAfterDelete = false; @@ -123,7 +123,7 @@ public class SelfRegistrationManager { for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) { if (subscription.getCallbackUrl().equals(callbackUrl)) { logger.info("Deleting subscription with {} identifier", subscription.getId()); - systemFunctions().blockingFirst(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)); + lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION).blockingFirst(); } } } catch (Exception e) { diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java index 130004e4..52e9151d 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java @@ -22,7 +22,6 @@ import org.onap.aai.model.GenericVnf; import org.onap.aai.model.Relationship; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties; import org.slf4j.Logger; @@ -92,7 +91,7 @@ class GenericVnfManager extends AbstractManager { //FIXME whould be good to know if this parameter is relevant or not? (mandatory) vnf.setVnfType("NokiaVNF"); vnf.setIsClosedLoopDisabled(inMaintenance); - SystemFunctions.systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf)); + aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf).blockingFirst(); } private GenericVnf waitForVnfToAppearInAai(String vnfId) { diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java index 1d641cff..f1c47d5b 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java @@ -30,7 +30,6 @@ import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Component; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR; -import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; 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; @@ -63,7 +62,7 @@ class L3NetworkManager extends AbstractManager { void delete(String vnfId, AffectedVirtualLink removedVl) { L3Network l3Network = getNetwork(vnfId, removedVl).blockingFirst(); - systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion())); + aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()).blockingFirst(); } private void updateNetworkFields(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink, L3Network network) { @@ -82,7 +81,7 @@ class L3NetworkManager extends AbstractManager { addMissingRelation(network.getRelationshipList(), GenericVnfManager.linkTo(vnfId)); addSingletonRelation(network.getRelationshipList(), getRegionLink(vimId)); addSingletonRelation(network.getRelationshipList(), getTenantLink(vimId, extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "tenantId"))); - systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network)); + aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network).blockingFirst(); } private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) { diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java index 78da503e..ab216bd7 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java @@ -32,7 +32,6 @@ import org.springframework.stereotype.Component; import static java.lang.String.format; -import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; 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; @@ -124,6 +123,6 @@ class LInterfaceManager extends AbstractManager { String tenantId = affectedCp.getTenantId(); String vServerId = affectedCp.getServerProviderId(); String cpId = affectedCp.getCpId(); - systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface)); + aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface).blockingFirst(); } } diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java index 9528e1a7..bc31f4fe 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java @@ -28,7 +28,6 @@ import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Component; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR; -import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; /** * Responsible for managing {@link Vnfc} in AAI @@ -54,7 +53,7 @@ public class VnfcManager extends AbstractManager { void delete(String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc) { Vnfc vnfc = getVnfc(buildId(vnfId, cbamVnfc.getId())).blockingFirst(); - systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion())); + aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion()).blockingFirst(); } private Observable<Vnfc> getVnfc(String vnfcId) { @@ -79,6 +78,6 @@ public class VnfcManager extends AbstractManager { } addSingletonRelation(aaiVnfc.getRelationshipList(), VserverManager.linkTo(vimId, tenantId, cbamVnfc.getComputeResource().getResourceId())); addSingletonRelation(aaiVnfc.getRelationshipList(), GenericVnfManager.linkTo(vnfId)); - systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc)); + aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc).blockingFirst(); } }
\ No newline at end of file diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java index 3eba8b21..6aeefd77 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java @@ -31,13 +31,13 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Component; import static com.google.common.collect.Iterables.find; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.childElement; -import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; 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; @@ -47,7 +47,7 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge @Component @Conditional(value = Conditions.UseForDirect.class) class VserverManager extends AbstractManager { - private static Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractManager.class); + private static Logger logger = LoggerFactory.getLogger(AbstractManager.class); @Autowired VserverManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) { @@ -101,27 +101,25 @@ class VserverManager extends AbstractManager { server.setVserverName(additionalData.getAsJsonObject().get("name").getAsString()); server.setVserverId(cbamVnfc.getComputeResource().getResourceId()); server.setProvStatus("active"); - server.setRelationshipList(new ArrayList<>()); server.setVserverId(cbamVnfc.getComputeResource().getResourceId()); server.setVserverSelflink(extractSelfLink(cbamVnfc.getComputeResource().getAdditionalData())); + if (server.getRelationshipList() == null) { + server.setRelationshipList(new ArrayList<>()); + } addSingletonRelation(server.getRelationshipList(), GenericVnfManager.linkTo(vnfId)); + server.setVolumes(new ArrayList<>()); if (cbamVnfc.getStorageResourceIds() != null) { - if (server.getVolumes() == null) { - server.setVolumes(new ArrayList<>()); - } for (String virtualStorageId : cbamVnfc.getStorageResourceIds()) { Volume volume = new Volume(); AffectedVirtualStorage affectedStorage = find(affectedVirtualStorages, storage -> virtualStorageId.equals(storage.getId())); volume.setVolumeId(affectedStorage.getResource().getResourceId()); server.getVolumes().add(volume); } - } else { - server.setVolumes(new ArrayList<>()); } String tenantId = getTenantId(cbamVnfc); String cloudOwner = getCloudOwner(vimId); String regionName = getRegionName(vimId); - systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, server.getVserverId(), server)); + aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, server.getVserverId(), server).blockingFirst(); } private String extractSelfLink(Object additionalData) { diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java index 07cd8032..1c1e4c76 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java @@ -17,7 +17,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer; import com.google.gson.*; -import java.io.IOException; import java.io.StringReader; import org.yaml.snakeyaml.Yaml; @@ -32,7 +31,7 @@ public class CbamVnfdBuilder { * @param cbamVnfdContent the original CBAM VNFD * @return the modified content CBAM VNFD */ - public String build(String cbamVnfdContent) throws IOException { + public String build(String cbamVnfdContent) { JsonObject root = new Gson().toJsonTree(new Yaml().load(cbamVnfdContent)).getAsJsonObject(); JsonObject substitutionMappings = child(child(root, "topology_template"), "substitution_mappings"); JsonObject extensions = addChild(addChild(addChild(addChild(addChild(substitutionMappings, "capabilities"), "vnf"), "properties"), "modifiable_attributes"), "extensions"); diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java index c7fac86a..b67c7863 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java @@ -16,10 +16,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util; import com.google.common.io.ByteStreams; -import io.reactivex.Observable; import java.io.InputStream; import java.io.PrintStream; -import java.util.NoSuchElementException; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; @@ -162,18 +160,4 @@ public class SystemFunctions { public CloseableHttpClient getHttpClient() { return HttpClients.createDefault(); } - - /** - * Execute blocking first - * - * @param observable the observable - */ - public void blockingFirst(Observable<Void> observable) { - try { - observable.blockingFirst(); - } catch (NoSuchElementException e) { - //swallow void returns null :) - } - } - }
\ No newline at end of file diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java index 3a334361..6dd6b9d3 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java @@ -19,7 +19,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** - * Responsible for providing SSL factories for AAI + * Responsible for providing SSL factories for CBAM */ @Component public class CbamSecurityProvider extends GenericSecurityProvider { diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java index 1b813a39..9b69fcfb 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java @@ -332,22 +332,7 @@ public class LifecycleManager { accessInfov3.setProject(vim.getAccessInfo().getTenant()); accessInfov3.setRegion(getRegionName(vimId)); accessInfov3.setUsername(vimInfo.getUserName()); - EndpointInfo interfaceInfoV3 = new EndpointInfo(); - interfaceInfoV3.setEndpoint(vimInfo.getUrl()); - if (!isEmpty(vimInfo.getSslInsecure())) { - interfaceInfoV3.setSkipCertificateVerification(Boolean.parseBoolean(vimInfo.getSslInsecure())); - interfaceInfoV3.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure())); - } else { - interfaceInfoV3.setSkipCertificateHostnameCheck(true); - interfaceInfoV3.setSkipCertificateVerification(true); - } - if (!interfaceInfoV3.isSkipCertificateVerification()) { - interfaceInfoV3.setTrustedCertificates(new ArrayList<>()); - for (String trustedCertificate : StoreLoader.getCertifacates(vimInfo.getSslCacert())) { - interfaceInfoV3.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8)); - } - } - openstackv3INFO.setInterfaceInfo(interfaceInfoV3); + openstackv3INFO.setInterfaceInfo(getEndpointInfo(vimInfo)); openstackv3INFO.setId(vimId); return openstackv3INFO; } @@ -361,6 +346,13 @@ public class LifecycleManager { accessInfo.setTenant(vim.getAccessInfo().getTenant()); accessInfo.setUsername(vimInfo.getUserName()); accessInfo.setRegion(getRegionName(vimId)); + EndpointInfo interfaceEndpoint = getEndpointInfo(vimInfo); + openstackv2INFO.setInterfaceInfo(interfaceEndpoint); + openstackv2INFO.setId(vimId); + return openstackv2INFO; + } + + private EndpointInfo getEndpointInfo(VimInfo vimInfo) { EndpointInfo interfaceEndpoint = new EndpointInfo(); if (!isEmpty(vimInfo.getSslInsecure())) { interfaceEndpoint.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure())); @@ -376,9 +368,7 @@ public class LifecycleManager { interfaceEndpoint.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8)); } } - openstackv2INFO.setInterfaceInfo(interfaceEndpoint); - openstackv2INFO.setId(vimId); - return openstackv2INFO; + return interfaceEndpoint; } private VMWAREVCLOUDINFO buildVcloudInfo(String vimId, org.onap.vnfmdriver.model.VimInfo vimInfo) { @@ -389,22 +379,7 @@ public class LifecycleManager { accessInfo.setPassword(vimInfo.getPassword()); accessInfo.setUsername(vimInfo.getUserName()); accessInfo.setOrganization(getRegionName(vimId)); - EndpointInfo interfaceEndpoint = new EndpointInfo(); - if (!isEmpty(vimInfo.getSslInsecure())) { - interfaceEndpoint.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure())); - interfaceEndpoint.setSkipCertificateVerification(Boolean.parseBoolean(vimInfo.getSslInsecure())); - } else { - interfaceEndpoint.setSkipCertificateHostnameCheck(true); - interfaceEndpoint.setSkipCertificateVerification(true); - } - interfaceEndpoint.setEndpoint(vimInfo.getUrl()); - if (!interfaceEndpoint.isSkipCertificateVerification()) { - interfaceEndpoint.setTrustedCertificates(new ArrayList<>()); - for (String trustedCertificate : StoreLoader.getCertifacates(vimInfo.getSslCacert())) { - interfaceEndpoint.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8)); - } - } - vcloudInfo.setInterfaceInfo(interfaceEndpoint); + vcloudInfo.setInterfaceInfo(getEndpointInfo(vimInfo)); vcloudInfo.setId(vimId); return vcloudInfo; } @@ -442,7 +417,7 @@ public class LifecycleManager { if (vnf.getInstantiationState() == INSTANTIATED) { terminateVnf(vnfmId, vnfId, jobInfo, cbamRequest, vnf); } else { - systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION)); + cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst(); } }); } @@ -455,7 +430,7 @@ public class LifecycleManager { if (finishedOperation.getStatus() == FINISHED) { notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId()); logger.info("Deleting VNF with {}", vnfId); - systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION)); + cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst(); logger.info("VNF with {} has been deleted", vnfId); } else { diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java index 1485ef59..3ff04990 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java @@ -203,6 +203,8 @@ public class LifecycleChangeNotificationManager implements ILifecycleChangeNotif //calculated from operation execution result logger.warn("Unable to send information related to affected connection points during forceful termination"); return empty(); + } else { + //graceful termination should be handled as any other operation } } try { diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java index a0565206..c313e317 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java @@ -22,6 +22,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.onap.msb.ApiClient; import org.onap.msb.api.ServiceResourceApi; import org.onap.msb.model.MicroServiceFullInfo; @@ -185,4 +186,29 @@ public class TestMsbApiProvider extends TestBase { } } + /** + * Test API wrapping for LCM + * (questionable benefit [ this is more less ensured by Java type safety) ] + */ + @Test + public void testOperationExecutionsApiAPiWrapping() { + ApiClient c = Mockito.mock(ApiClient.class); + class TestClasss extends MsbApiProvider { + + TestClasss(Environment environment) { + super(environment); + } + + @Override + ApiClient buildApiClient() { + return c; + } + } + ServiceResourceApi defaultApi = Mockito.mock(ServiceResourceApi.class); + when(c.createService(ServiceResourceApi.class)).thenReturn(defaultApi); + //verify + TestClasss testInstnace = new TestClasss(environment); + assertEquals(defaultApi, testInstnace.getMsbApi()); + } + } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java index 9c53aba1..fafaf2cd 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java @@ -17,11 +17,13 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSocketFactory; +import okhttp3.Interceptor; import okhttp3.Protocol; import okhttp3.Request; import okhttp3.Response; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -29,6 +31,7 @@ import org.mockito.stubbing.Answer; import org.onap.aai.api.CloudInfrastructureApi; import org.onap.aai.api.ExternalSystemApi; import org.onap.aai.api.NetworkApi; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import static junit.framework.TestCase.assertEquals; @@ -79,9 +82,24 @@ public class TestAAIRestApiProvider extends TestBase { assertEquals("http://1.2.3.4/a/", apiClient.getAdapterBuilder().build().baseUrl().toString()); assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory()); assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier()); + + //given Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build(); + //when Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp); + //verify assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization")); + + //given + Interceptor.Chain chain = Mockito.mock(Interceptor.Chain.class); + when(chain.request()).thenReturn(new Request.Builder().url("http://1.2.3.4/d").build()); + ArgumentCaptor<Request> modifedRequest = ArgumentCaptor.forClass(Request.class); + when(chain.proceed(modifedRequest.capture())).thenReturn(resp); + //when + apiClient.getOkBuilder().interceptors().get(0).intercept(chain); + //verify + assertEquals(SelfRegistrationManager.SERVICE_NAME, modifedRequest.getValue().header("X-FromAppId")); + } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java index 514098b6..2b411ca5 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java @@ -109,7 +109,7 @@ public class TestGenericVnfManager extends TestBase { when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo)); when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> { vnfs.add(vnfInAaai); - return null; + return VOID_OBSERVABLE.value(); }); vnfInfo.setName("vnfName"); //when @@ -124,6 +124,7 @@ public class TestGenericVnfManager extends TestBase { assertEquals("vnfName", vnfSentToAai.getVnfName()); verify(systemFunctions, times(10)).sleep(3000); verify(networkApi, times(10)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); + VOID_OBSERVABLE.assertCalled(); } /** @@ -135,7 +136,7 @@ public class TestGenericVnfManager extends TestBase { vnfInAaai.setResourceVersion("v1"); when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(vnfInAaai)); when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo)); - when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(null); + when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); vnfInfo.setName("vnfName"); //when genericVnfManager.createOrUpdate(VNF_ID, true); @@ -148,6 +149,7 @@ public class TestGenericVnfManager extends TestBase { assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled()); assertEquals("vnfName", vnfSentToAai.getVnfName()); verify(systemFunctions, never()).sleep(anyLong()); + VOID_OBSERVABLE.assertCalled(); verify(networkApi, times(1)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); } @@ -198,7 +200,7 @@ public class TestGenericVnfManager extends TestBase { if (vnfSentToAAi.getResourceVersion() == null) { throw runtimeException; } - return null; + return VOID_OBSERVABLE.value(); }); vnfInfo.setName("vnfName"); //when @@ -217,6 +219,7 @@ public class TestGenericVnfManager extends TestBase { verify(networkApi, times(2)).createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), any()); verify(logger).warn(eq("The VNF with myVnfId identifier did not appear in time"), any(NoSuchElementException.class)); verify(logger).warn("The VNF with myVnfId identifier has been created since after the maximal wait for VNF to appear timeout", runtimeException); + VOID_OBSERVABLE.assertCalled(); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java index 47dbb95d..cdedafb5 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java @@ -68,7 +68,7 @@ public class TestL3NetworkManager extends TestBase { affectedVirtualLink.getResource().setResourceId("netProviderId"); L3Network existingNetwork = new L3Network(); when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingNetwork)); - when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null); + when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink); //verify @@ -83,6 +83,7 @@ public class TestL3NetworkManager extends TestBase { 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)); + VOID_OBSERVABLE.assertCalled(); } /** @@ -101,7 +102,7 @@ public class TestL3NetworkManager extends TestBase { l3Network.setResourceVersion("v3"); l3Network.setRelationshipList(new ArrayList<>()); when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network)); - when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null); + when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink); //verify @@ -117,6 +118,7 @@ public class TestL3NetworkManager extends TestBase { 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)); + VOID_OBSERVABLE.assertCalled(); } /** @@ -127,11 +129,14 @@ public class TestL3NetworkManager extends TestBase { affectedVirtualLink.setId("vlId"); L3Network l3Network = new L3Network(); l3Network.setResourceVersion("v3"); + l3Network.setNetworkId("myVnfId_vlId"); when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network)); + when(networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3")).thenReturn(VOID_OBSERVABLE.value()); //when l3NetworkManager.delete(VNF_ID, affectedVirtualLink); //verify networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3"); + VOID_OBSERVABLE.assertCalled(); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java index 3728bdb2..0ac93330 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java @@ -72,7 +72,7 @@ public class TestLInterfaceManager extends TestBase { lInterface.setResourceVersion("v3"); lInterface.setRelationshipList(new ArrayList<>()); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true); //verify @@ -90,6 +90,7 @@ public class TestLInterfaceManager extends TestBase { 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)); + VOID_OBSERVABLE.assertCalled(); } /** @@ -109,9 +110,8 @@ public class TestLInterfaceManager extends TestBase { affectedCp.setCpId("cpId"); LInterface lInterface = new LInterface(); lInterface.setResourceVersion("v3"); - lInterface.setRelationshipList(new ArrayList<>()); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true); //verify @@ -127,6 +127,7 @@ public class TestLInterfaceManager extends TestBase { assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList()); assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList()); assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID)); + VOID_OBSERVABLE.assertCalled(); } /** @@ -148,8 +149,9 @@ public class TestLInterfaceManager extends TestBase { LInterface lInterface = new LInterface(); lInterface.setResourceVersion("v3"); lInterface.setRelationshipList(new ArrayList<>()); + lInterface.getRelationshipList().add(VserverManager.linkTo(VIM_ID, "b", "c")); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true); //verify @@ -168,6 +170,8 @@ public class TestLInterfaceManager extends TestBase { 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)); + assertEquals(2, lInterface.getRelationshipList().size()); + VOID_OBSERVABLE.assertCalled(); } /** @@ -190,7 +194,7 @@ public class TestLInterfaceManager extends TestBase { lInterface.setResourceVersion("v3"); lInterface.setRelationshipList(new ArrayList<>()); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, false); //verify @@ -230,6 +234,7 @@ public class TestLInterfaceManager extends TestBase { lInterfaceManager.delete(VIM_ID, affectedCp); //verify cloudInfrastructureApi.deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", "v3"); + VOID_OBSERVABLE.assertCalled(); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java index 8b41c3f8..efec7b37 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java @@ -17,6 +17,7 @@ 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 java.util.ArrayList; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -62,8 +63,10 @@ public class TestVnfcManager extends TestBase { affectedVnfc.getComputeResource().setResourceId("serverProviderId"); affectedVnfc.setId("vnfcId"); Vnfc existingVnfc = new Vnfc(); + existingVnfc.setRelationshipList(new ArrayList<>()); + existingVnfc.getRelationshipList().add(GenericVnfManager.linkTo("any")); when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc)); - when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(null); + when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true); //verify @@ -78,6 +81,8 @@ public class TestVnfcManager extends TestBase { buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"), buildRelationshipData("vserver.vserver-id", "serverProviderId")); + assertEquals(2, vnfc.getRelationshipList().size()); + VOID_OBSERVABLE.assertCalled(); } /** @@ -93,10 +98,12 @@ public class TestVnfcManager extends TestBase { existingVnfc.setResourceVersion("v3"); existingVnfc.setVnfcName("myVnfId_vnfcId"); when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc)); + when(networkApi.deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3")).thenReturn(VOID_OBSERVABLE.value()); //when vnfcManager.delete(VNF_ID, affectedVnfc); //verify verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3"); + VOID_OBSERVABLE.assertCalled(); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java index 68f5ab5f..5140c556 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java @@ -91,12 +91,11 @@ public class TestVserverManager extends TestBase { affectedVnfc.setStorageResourceIds(new ArrayList<>()); affectedVnfc.getStorageResourceIds().add("sId"); - String url = "/cloud-regions/cloud-region///tenants/tenant//vservers/vserver/"; - Vserver existingVserver = new Vserver(); - existingVserver.setVolumes(new ArrayList<>()); + existingVserver.setRelationshipList(new ArrayList<>()); + existingVserver.getRelationshipList().add(VserverManager.linkTo(VIM_ID, "tenantId", "serverId2")); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true); //verify @@ -107,6 +106,8 @@ public class TestVserverManager extends TestBase { assertEquals("url", vserver.getVserverSelflink()); assertEquals(1, vserver.getVolumes().size()); assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId()); + assertEquals(2, vserver.getRelationshipList().size()); + VOID_OBSERVABLE.assertCalled(); } /** @@ -135,7 +136,7 @@ public class TestVserverManager extends TestBase { Vserver existingVserver = new Vserver(); existingVserver.setVolumes(new ArrayList<>()); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true); //verify @@ -146,6 +147,7 @@ public class TestVserverManager extends TestBase { assertEquals("unknown", vserver.getVserverSelflink()); assertEquals(1, vserver.getVolumes().size()); assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId()); + VOID_OBSERVABLE.assertCalled(); } /** @@ -172,7 +174,7 @@ public class TestVserverManager extends TestBase { Vserver existingVserver = new Vserver(); existingVserver.setVolumes(new ArrayList<>()); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true); //verify @@ -183,6 +185,7 @@ public class TestVserverManager extends TestBase { assertEquals("unknown", vserver.getVserverSelflink()); assertEquals(1, vserver.getVolumes().size()); assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId()); + VOID_OBSERVABLE.assertCalled(); } /** @@ -202,7 +205,7 @@ public class TestVserverManager extends TestBase { Vserver existingVserver = new Vserver(); existingVserver.setVolumes(new ArrayList<>()); when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver)); - when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null); + when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); //when vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true); //verify @@ -237,6 +240,7 @@ public class TestVserverManager extends TestBase { vserverManager.delete(VIM_ID, affectedVnfc); //verify verify(cloudInfrastructureApi).deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "v3"); + VOID_OBSERVABLE.assertCalled(); } @Test diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java index 190f78ee..a699ee9e 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java @@ -22,6 +22,7 @@ import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi; import com.nokia.cbam.lcm.v32.api.VnfsApi; import com.nokia.cbam.lcn.v32.api.SubscriptionsApi; import io.reactivex.Observable; +import io.reactivex.internal.operators.observable.ObservableFromCallable; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.lang.reflect.Field; @@ -29,9 +30,11 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import javax.servlet.http.HttpServletResponse; +import junit.framework.TestCase; import okhttp3.RequestBody; import okio.Buffer; import org.apache.commons.lang3.ArrayUtils; @@ -68,7 +71,9 @@ import static junit.framework.TestCase.assertTrue; import static org.mockito.Mockito.when; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip; + public class TestBase { + public static final String VNF_ID = "myVnfId"; public static final String VNFM_ID = "myVnfmId"; public static final String ONAP_CSAR_ID = "myOnapCsarId"; @@ -76,6 +81,7 @@ public class TestBase { public static final String JOB_ID = "myJobId"; public static final String CBAM_VNFD_ID = "cbamVnfdId"; protected static Call<Void> VOID_CALL = buildCall(null); + protected static VoidObservable VOID_OBSERVABLE = new VoidObservable(); @Mock protected CbamRestApiProvider cbamRestApiProvider; @Mock @@ -210,4 +216,23 @@ public class TestBase { } } } + + protected static class VoidObservable { + boolean called = false; + ObservableFromCallable<Void> s = new ObservableFromCallable(new Callable() { + @Override + public Object call() throws Exception { + called = true; + return ""; + } + }); + + public void assertCalled() { + TestCase.assertTrue(called); + } + + public Observable<Void> value() { + return s; + } + } } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java index 743fb95e..b34bc1d7 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java @@ -498,6 +498,51 @@ public class TestJobManager extends TestBase { } /** + * the modify attribute job is skipped, since it is not explicitly triggered by any external job + */ + @Test + public void testModifyAttributesOperationExecutionIsSkipped() throws Exception { + String jobId = jobManager.spawnJob(VNF_ID, httpResponse); + VnfInfo vnf = new VnfInfo(); + vnf.setId(VNF_ID); + vnfs.add(vnf); + VnfInfo detailedVnf = new VnfInfo(); + detailedVnf.setId(VNF_ID); + when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf)); + OperationExecution olderOperation = new OperationExecution(); + olderOperation.setId(UUID.randomUUID().toString()); + olderOperation.setStartTime(OffsetDateTime.now()); + olderOperation.setStatus(OperationStatus.FINISHED); + olderOperation.setOperationType(OperationType.TERMINATE); + OperationExecution newerOperation = new OperationExecution(); + newerOperation.setId(UUID.randomUUID().toString()); + newerOperation.setStartTime(OffsetDateTime.now().plusDays(1)); + newerOperation.setStatus(OperationStatus.FINISHED); + newerOperation.setOperationType(OperationType.MODIFY_INFO); + detailedVnf.setOperationExecutions(new ArrayList<>()); + detailedVnf.getOperationExecutions().add(olderOperation); + detailedVnf.getOperationExecutions().add(newerOperation); + JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}"); + List<String> queriedOperaionsInOrder = new ArrayList<>(); + when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(Mockito.anyString(), Mockito.eq(NOKIA_LCM_API_VERSION))) + .then(new Answer<Observable<Object>>() { + @Override + public Observable<Object> answer(InvocationOnMock invocationOnMock) throws Throwable { + queriedOperaionsInOrder.add(invocationOnMock.getArguments()[0].toString()); + if (invocationOnMock.getArguments()[0].equals(olderOperation.getId())) { + return buildObservable(new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}")); + } else { + throw new RuntimeException(); //this should be never reached + } + } + }); + JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId); + //verify + assertEquals(Lists.newArrayList(olderOperation.getId()), queriedOperaionsInOrder); + assertTrue(jobManager.hasOngoingJobs()); + } + + /** * if the registration process has not finished it is prevented to spawn jobs */ @Test 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 b7e30e2c..178f0b5a 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 @@ -746,8 +746,7 @@ public class TestLifecycleManager extends TestBase { return buildObservable(terminationOperation); } }); - Observable<Void> delete = Mockito.mock(Observable.class); - when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(delete); + when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(VOID_OBSERVABLE.value()); JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } "); when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters)); //when @@ -761,7 +760,7 @@ public class TestLifecycleManager extends TestBase { notificationIsProcessedBeforeDeletingTheVnf.verify(vfcGrantManager).requestGrantForTerminate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, vnfInfo, JOB_ID); notificationIsProcessedBeforeDeletingTheVnf.verify(notificationManager).waitForTerminationToBeProcessed("terminationId"); notificationIsProcessedBeforeDeletingTheVnf.verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION); - verify(systemFunctions).blockingFirst(delete); + VOID_OBSERVABLE.assertCalled(); verify(jobManager).spawnJob(VNF_ID, restResponse); verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("termination"), eq(VNF_ID), anyString()); } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java index d668262f..640d29be 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java @@ -41,6 +41,8 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; import static org.onap.msb.model.MicroServiceInfo.ProtocolEnum.REST; import static org.onap.msb.model.MicroServiceInfo.VisualRangeEnum._1; +import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.DRIVER_VERSION; +import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.SERVICE_NAME; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCN_API_VERSION; import static org.springframework.test.util.ReflectionTestUtils.setField; @@ -123,7 +125,7 @@ public class TestSelfRegistrationManager extends TestBase { assertEquals(REST, microserviceRequest.getProtocol()); assertNull(microserviceRequest.getMetadata()); //very strange, but it should be null for ONAP to work - assertEquals(SelfRegistrationManager.SERVICE_NAME, microserviceRequest.getServiceName()); + assertEquals(SERVICE_NAME, microserviceRequest.getServiceName()); assertEquals("/api/NokiaSVNFM/v1", microserviceRequest.getUrl()); assertEquals("v1", microserviceRequest.getVersion()); assertEquals(Boolean.FALSE, microserviceRequest.isEnableSsl()); @@ -183,6 +185,7 @@ public class TestSelfRegistrationManager extends TestBase { subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); subscription.setId(UUID.randomUUID().toString()); subscriptions.add(subscription); + when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value()); return buildObservable(subscription); }); MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo(); @@ -215,16 +218,18 @@ public class TestSelfRegistrationManager extends TestBase { subscription.setId(UUID.randomUUID().toString()); subscriptions.add(subscription); when(jobManager.hasOngoingJobs()).thenReturn(false); - Observable delete = Mockito.mock(Observable.class); - when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(delete); + when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value()); + VoidObservable MSB_DELETE = new VoidObservable(); + when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).thenReturn(MSB_DELETE.value()); //when selfRegistrationManager.deRegister(); //verify InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi); - inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null); + inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null); inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION); assertServiceDown(); - verify(systemFunctions).blockingFirst(delete); + VOID_OBSERVABLE.assertCalled(); + MSB_DELETE.assertCalled(); verify(logger).info("Deleting subscription with {} identifier", subscription.getId()); } @@ -240,22 +245,23 @@ public class TestSelfRegistrationManager extends TestBase { subscription.setId(UUID.randomUUID().toString()); subscriptions.add(subscription); when(jobManager.hasOngoingJobs()).thenReturn(false); - when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() { + when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() { @Override public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable { - when(msbClient.getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null)).thenThrow(new RuntimeException()); + when(msbClient.getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null)).thenThrow(new RuntimeException()); throw new RuntimeException(); } }); - MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo(); + when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value()); //when selfRegistrationManager.deRegister(); //verify InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi); - inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null); - inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null); + inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null); + inOrder.verify(msbClient).getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null); inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION); assertServiceDown(); + VOID_OBSERVABLE.assertCalled(); } /** @@ -268,7 +274,7 @@ public class TestSelfRegistrationManager extends TestBase { subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); subscription.setId(UUID.randomUUID().toString()); subscriptions.add(subscription); - when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() { + when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() { @Override public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable { throw new RuntimeException(); @@ -283,8 +289,8 @@ public class TestSelfRegistrationManager extends TestBase { } //verify InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi); - inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null); - inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null); + inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null); + inOrder.verify(msbClient).getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null); verify(lcnApi, Mockito.never()).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION); assertServiceDown(); } @@ -302,6 +308,7 @@ public class TestSelfRegistrationManager extends TestBase { when(jobManager.hasOngoingJobs()).thenReturn(false); RuntimeException expectedException = new RuntimeException(); doThrow(expectedException).when(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION); + when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).thenReturn(VOID_OBSERVABLE.value()); //when try { selfRegistrationManager.deRegister(); @@ -311,7 +318,7 @@ public class TestSelfRegistrationManager extends TestBase { } //verify InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi); - inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null); + inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null); inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION); assertServiceDown(); } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java index 922e92bb..449217f9 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 @@ -427,6 +427,24 @@ public class TestLifecycleChangeNotificationManager extends TestBase { } /** + * Forceful termination results in an empty affected connection points + */ + @Test + public void testGracefullTermination() { + //given + recievedLcn.setOperation(OperationType.INSTANTIATE); + recievedLcn.setStatus(OperationStatus.FINISHED); + recievedLcn.setLifecycleOperationOccurrenceId(terminationOperation.getId()); + ((JsonObject) terminationOperation.getOperationParams()).addProperty("terminationType", "GRACEFUL"); + addEmptyModifiedConnectionPoints(terminationOperation); + terminationOperation.setStatus(OperationStatus.FINISHED); + terminationOperation.setOperationType(OperationType.TERMINATE); + //when + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + assertTrue(affectedConnectionPoints.getValue().isPresent()); + } + + /** * Failures in affected connection point processing are tolerated for failed operation * (because the POST script was not able to run) */ |