diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-05-02 23:27:40 +0200 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-05-02 23:27:40 +0200 |
commit | 005f0ee244e6fff6ba208e0f65476a1470316d80 (patch) | |
tree | 678854ca30e7438558de3a75bc7ee431916b2ed1 /nokiav2 | |
parent | 4dc3d0aaae1f11499357839dac9e92f13ce0e934 (diff) |
Add missing tests
Change-Id: Id6d9e7112c60dbab765e66c97f6a81e466989b6a
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728
Diffstat (limited to 'nokiav2')
22 files changed, 538 insertions, 20 deletions
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java index 40abab1a..f1c2a6f0 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java @@ -55,10 +55,6 @@ public class NokiaSvnfmApplication { systemFunctions().newSpringApplication(NokiaSvnfmApplication.class).run(args); } - private static boolean isDirect(ConfigurableApplicationContext applicationContext) { - return newHashSet(applicationContext.getEnvironment().getActiveProfiles()).contains("direct"); - } - /** * Responsible for starting the self registration process after the servlet has been started * and is ready to answer REST request @@ -104,7 +100,8 @@ public class NokiaSvnfmApplication { return true; }; executorService.submit(() -> { - while (!jobManagerForVfc.isPreparingForShutDown() && !jobManagerForSo.isPreparingForShutDown()) { + boolean notPrepareForShutDown = !jobManagerForVfc.isPreparingForShutDown() && !jobManagerForSo.isPreparingForShutDown(); + while (notPrepareForShutDown) { try { executorService.submit(singleRegistration).get(); //registration successful @@ -112,11 +109,17 @@ public class NokiaSvnfmApplication { } catch (Exception e) { logger.warn("Unable to execute self registration process", e); } + systemFunctions().sleep(5000); } + logger.warn("Component is preparing for shutdown giving up component start"); }); } + private static boolean isDirect(ConfigurableApplicationContext applicationContext) { + return newHashSet(applicationContext.getEnvironment().getActiveProfiles()).contains("direct"); + } + } /** diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java index 270d004c..c5110642 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java @@ -68,6 +68,7 @@ public class VnfmCredentials { } @Override + @SuppressWarnings("squid:S2068") //the password is hashed public String toString() { return "VnfmCredentials{" + "username='" + username + '\'' + diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java index fb4de3f2..ce8f7448 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java @@ -121,6 +121,6 @@ public class AAIExternalSystemInfoProvider extends GenericExternalSystemInfoProv @Override public Set<String> getVnfms() { EsrVnfmList esrVnfmList = aaiRestApiProvider.getExternalSystemApi().getExternalSystemEsrVnfmList().blockingFirst(); - return newHashSet(transform(esrVnfmList.getEsrVnfm(), esr -> esr.getVnfmId())); + return newHashSet(transform(esrVnfmList.getEsrVnfm(), EsrVnfm::getVnfmId)); } } 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 953eda95..d0df8a80 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 @@ -99,7 +99,7 @@ public class GenericVnfManager extends AbstractManager { vnf.setRelationshipList(new ArrayList<>()); } if (nsId.isPresent()) { - addSingletonRelation(vnf.getRelationshipList(), linkTo(nsId.get())); + addSingletonRelation(vnf.getRelationshipList(), linkToNs(nsId.get())); } aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf).blockingFirst(); } 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 ec2ad27c..882a1649 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 @@ -27,6 +27,8 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child; */ public class CbamVnfdBuilder { + public static final String DEFAULT = "default"; + /** * @param cbamVnfdContent the original CBAM VNFD * @return the modified content CBAM VNFD @@ -36,11 +38,11 @@ public class CbamVnfdBuilder { JsonObject substitutionMappings = child(child(root, "topology_template"), "substitution_mappings"); JsonObject extensions = addChild(addChild(addChild(addChild(addChild(substitutionMappings, "capabilities"), "vnf"), "properties"), "modifiable_attributes"), "extensions"); JsonObject onapCsarId = addChild(extensions, "onapCsarId"); - onapCsarId.add("default", new JsonPrimitive("kuku")); + onapCsarId.add(DEFAULT, new JsonPrimitive("kuku")); JsonObject externalVnfmId = addChild(extensions, "externalVnfmId"); - externalVnfmId.add("default", new JsonPrimitive("kuku")); + externalVnfmId.add(DEFAULT, new JsonPrimitive("kuku")); JsonObject vimId = addChild(extensions, "vimId"); - vimId.add("default", new JsonPrimitive("kuku")); + vimId.add(DEFAULT, new JsonPrimitive("kuku")); JsonObject interfaces = child(substitutionMappings, "interfaces"); JsonObject basic = addChild(interfaces, "Basic"); addOperationParams(addChild(basic, "instantiate")); diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java index 736735e1..029e627c 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java @@ -44,6 +44,7 @@ import static org.springframework.web.bind.annotation.RequestMethod.POST; @Controller @RequestMapping(value = BASE_URL) public class LcmApi { + public static final String IDENTIFIER = " identifier"; private static Logger logger = getLogger(LcmApi.class); private final LifecycleManager lifecycleManager; @@ -84,7 +85,7 @@ public class LcmApi { @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE) @ResponseBody public JobInfo terminateVnf(@RequestBody VnfTerminateRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) { - logger.info("REST: Terminate VNF with " + vnfId + " identifier"); + logger.info("REST: Terminate VNF with " + vnfId + IDENTIFIER); return lifecycleManager.terminateAndDelete(vnfmId, vnfId, request, httpResponse); } @@ -99,7 +100,7 @@ public class LcmApi { @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = GET, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) @ResponseBody public VnfInfo queryVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) { - logger.info("REST: Query VNF with " + vnfId + " identifier"); + logger.info("REST: Query VNF with " + vnfId + IDENTIFIER); return lifecycleManager.queryVnf(vnfmId, vnfId); } @@ -114,7 +115,7 @@ public class LcmApi { @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE) @ResponseBody public JobDetailInfo getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) { - logger.debug("REST: Query job with " + jobId + " identifier"); + logger.debug("REST: Query job with " + jobId + IDENTIFIER); return jobManager.getJob(vnfmId, jobId); } @@ -130,7 +131,7 @@ public class LcmApi { @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) @ResponseBody public JobInfo scaleVnf(@RequestBody VnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) { - logger.info("REST: Scale VNF with " + vnfId + " identifier"); + logger.info("REST: Scale VNF with " + vnfId + IDENTIFIER); return lifecycleManager.scaleVnf(vnfmId, vnfId, request, httpResponse); } @@ -146,7 +147,7 @@ public class LcmApi { @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) @ResponseBody public JobInfo healVnf(@RequestBody VnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) { - logger.info("REST: Heal VNF with " + vnfId + " identifier"); + logger.info("REST: Heal VNF with " + vnfId + IDENTIFIER); return lifecycleManager.healVnf(vnfmId, vnfId, request, empty(), httpResponse); } } diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java index 7908d2e4..aeeae423 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java @@ -160,7 +160,7 @@ public class CatalogManager { } } - private boolean isPackageReplicatedToCbam(String cbamVnfdId, DefaultApi cbamCatalogApi) throws IOException { + private boolean isPackageReplicatedToCbam(String cbamVnfdId, DefaultApi cbamCatalogApi) { for (CatalogAdapterVnfpackage vnfPackage : cbamCatalogApi.list().blockingFirst()) { if (vnfPackage.getVnfdId().equals(cbamVnfdId)) { return true; diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java index cda091c0..a695df9b 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamRestApiProvider.java @@ -22,7 +22,6 @@ 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 org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider; -import org.onap.vnfmdriver.model.VnfmInfo; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider.convert; @@ -97,7 +96,6 @@ public class CbamRestApiProvider { @VisibleForTesting ApiClient buildLcmApiClient(String vnfmId) { - VnfmInfo vnfmInfo = vnfmInfoProvider.getVnfmInfo(vnfmId); ApiClient apiClient = new ApiClient(); apiClient.getOkBuilder().sslSocketFactory(cbamSecurityProvider.buildSSLSocketFactory(), cbamSecurityProvider.buildTrustManager()); apiClient.getOkBuilder().hostnameVerifier(cbamSecurityProvider.buildHostnameVerifier()); diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/Constants.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/Constants.java index 3d4ec93a..1b6b4eb2 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/Constants.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/Constants.java @@ -22,7 +22,12 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManag * Common constants */ public class Constants { + public static final String BASE_SUFFIX = "/" + SelfRegistrationManager.SERVICE_NAME + "/v1"; public static final String BASE_URL = "/api" + BASE_SUFFIX; public static final String LCN_URL = "/lcn"; + + private Constants(){ + //use in static way + } } diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManagerForSo.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManagerForSo.java index 0fca4309..71758624 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManagerForSo.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManagerForSo.java @@ -20,6 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +/** + * Responsible for providing jobs for SO + */ @Component public class JobManagerForSo extends JobManager { diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManagerForSo.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManagerForSo.java index b2f2bba2..70051e36 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManagerForSo.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManagerForSo.java @@ -24,7 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** - * Responsible for executing lifecycle operation on the VNF + * Responsible for executing lifecycle operation on the VNF operated by SO */ @Component public class LifecycleManagerForSo extends LifecycleManager { diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java index 69a74bc3..8964c80b 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java @@ -96,6 +96,155 @@ public class TestNokiaSvnfmApplication extends TestBase { assertTrue(ApplicationReadyEvent.class.isAssignableFrom(event.getClass())); } + /** + * Assert that the self registration process is started after the servlet is up and is able to answer REST requests. + */ + @Test + @SuppressWarnings("squid:S2925") //the execution is asynchronous no other way to wait + public void testRegistrationIsNotCalledIfPreparingForShutdown() throws Exception { + //given + ApplicationReadyEvent event = Mockito.mock(ApplicationReadyEvent.class); + useSo(event); + when(jobManagerForSo.isPreparingForShutDown()).thenReturn(true); + //when + selfRegistrationTriggerer.onApplicationEvent(event); + //verify + boolean success = false; + while (!success) { + try { + verify(logger).warn("Component is preparing for shutdown giving up component start"); + success = true; + } catch (Error e) { + + } + Thread.sleep(10); + } + verify(selfRegistrationManagerForSo, never()).register(); + // this forces the event to be fired after the servlet is up (prevents refactor) + assertTrue(ApplicationReadyEvent.class.isAssignableFrom(event.getClass())); + } + + + /** + * Assert that the self registration process is started after the servlet is up and is able to answer REST requests. + */ + @Test + @SuppressWarnings("squid:S2925") //the execution is asynchronous no other way to wait + public void testRegistrationIsCalledAfterComponentIsUpForSo() throws Exception { + //given + ApplicationReadyEvent event = Mockito.mock(ApplicationReadyEvent.class); + useSo(event); + //when + selfRegistrationTriggerer.onApplicationEvent(event); + //verify + boolean success = false; + while (!success) { + try { + verify(selfRegistrationManagerForSo).register(); + verify(logger).info("Self registration started"); + verify(logger).info("Self registration finished"); + success = true; + } catch (Error e) { + + } + Thread.sleep(10); + } + // this forces the event to be fired after the servlet is up (prevents refactor) + assertTrue(ApplicationReadyEvent.class.isAssignableFrom(event.getClass())); + } + + /** + * Failuires in the self registration process is retried for SO + */ + @Test + @SuppressWarnings("squid:S2925") //the execution is asynchronous no other way to wait + public void testFailuresInRegistrationIsRetriedForSo() throws Exception { + //given + ApplicationReadyEvent event = Mockito.mock(ApplicationReadyEvent.class); + RuntimeException e2 = new RuntimeException(); + useSo(event); + Set<Boolean> calls = new HashSet<>(); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocationOnMock) throws Throwable { + if(calls.size() == 0){ + calls.add(true); + throw e2; + } + return null; + } + }).when(selfRegistrationManagerForSo).register(); + //when + selfRegistrationTriggerer.onApplicationEvent(event); + //verify + boolean success = false; + while (!success) { + try { + verify(logger).info("Self registration finished"); + success = true; + } catch (Error e) { + + } + Thread.sleep(10); + } + verify(selfRegistrationManagerForSo, times(2)).register(); + verify(systemFunctions).sleep(5000); + verify(logger, times(2)).info("Self registration started"); + verify(logger).error("Self registration failed", e2); + // this forces the event to be fired after the servlet is up (prevents refactor) + assertTrue(ApplicationReadyEvent.class.isAssignableFrom(event.getClass())); + } + + /** + * Failuires in the self registration process is retried for VFC + */ + @Test + @SuppressWarnings("squid:S2925") //the execution is asynchronous no other way to wait + public void testFailuresInRegistrationIsRetriedForVfc() throws Exception { + //given + ApplicationReadyEvent event = Mockito.mock(ApplicationReadyEvent.class); + RuntimeException e2 = new RuntimeException(); + useVfc(event); + Set<Boolean> calls = new HashSet<>(); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocationOnMock) throws Throwable { + if(calls.size() == 0){ + calls.add(true); + throw e2; + } + return null; + } + }).when(selfRegistrationManagerForVfc).register(); + //when + selfRegistrationTriggerer.onApplicationEvent(event); + //verify + boolean success = false; + while (!success) { + try { + verify(logger).info("Self registration finished"); + success = true; + } catch (Error e) { + + } + Thread.sleep(10); + } + verify(selfRegistrationManagerForVfc, times(2)).register(); + verify(systemFunctions).sleep(5000); + verify(logger, times(2)).info("Self registration started"); + verify(logger).error("Self registration failed", e2); + // this forces the event to be fired after the servlet is up (prevents refactor) + assertTrue(ApplicationReadyEvent.class.isAssignableFrom(event.getClass())); + } + + private void useSo(ApplicationReadyEvent event) { + ConfigurableApplicationContext context = Mockito.mock(ConfigurableApplicationContext.class); + ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class); + when(context.getEnvironment()).thenReturn(environment); + when(event.getApplicationContext()).thenReturn(context); + when(environment.getActiveProfiles()).thenReturn(new String[]{"direct"}); + } + private void useVfc(ApplicationReadyEvent event) { ConfigurableApplicationContext context = Mockito.mock(ConfigurableApplicationContext.class); ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class); @@ -111,6 +260,13 @@ public class TestNokiaSvnfmApplication extends TestBase { when(environment.getActiveProfiles()).thenReturn(new String[]{}); } + private void useSo(ContextClosedEvent event) { + ApplicationContext context = Mockito.mock(ApplicationContext.class); + when(context.getEnvironment()).thenReturn(environment); + when(event.getApplicationContext()).thenReturn(context); + when(environment.getActiveProfiles()).thenReturn(new String[]{"direct"}); + } + /** * Assert that the self de-registration process is started after the servlet has been ramped down */ @@ -133,6 +289,27 @@ public class TestNokiaSvnfmApplication extends TestBase { } /** + * Assert that the self de-registration process is started after the servlet has been ramped down + */ + @Test + public void testUnRegistrationIsCalledAfterComponentIsUpForSo() throws Exception { + //given + ContextClosedEvent event = Mockito.mock(ContextClosedEvent.class); + useSo(event); + //when + selfUnregistrationTriggerer.onApplicationEvent(event); + //verify + InOrder inOrder = Mockito.inOrder(jobManagerForVfc, jobManagerForSo, selfRegistrationManagerForSo); + inOrder.verify(jobManagerForVfc).prepareForShutdown(); + inOrder.verify(jobManagerForSo).prepareForShutdown(); + inOrder.verify(selfRegistrationManagerForSo).deRegister(); + verify(logger).info("Self de-registration started"); + verify(logger).info("Self de-registration finished"); + // this forces the event to be fired after the servlet is down (prevents refactor) + assertTrue(ContextClosedEvent.class.isAssignableFrom(event.getClass())); + } + + /** * Assert that the self registration process is started after the servlet is up and is able to answer REST requests. */ @Test @@ -151,9 +328,9 @@ public class TestNokiaSvnfmApplication extends TestBase { */ @Test @SuppressWarnings("squid:S2925") //the execution is asynchronous no other way to wait + public void failedFirstRegistration() { //given - Set<RuntimeException> expectedException = new HashSet<>(); doAnswer(new Answer() { @Override 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 347d6d2b..cee26fd1 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 @@ -59,13 +59,16 @@ import org.onap.vfccatalog.api.VnfpackageApi; import org.onap.vnfmdriver.api.NslcmApi; import org.onap.vnfmdriver.model.VnfmInfo; import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; import org.springframework.test.util.ReflectionTestUtils; import retrofit2.Call; import retrofit2.Response; import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertTrue; import static org.mockito.Mockito.when; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR; @@ -265,4 +268,11 @@ public class TestBase { return s; } } + + protected void assertBean(Class<?> clazz){ + assertEquals(1, clazz.getDeclaredConstructors().length); + Autowired annotation = clazz.getDeclaredConstructors()[0].getAnnotation(Autowired.class); + assertNotNull(annotation); + assertNotNull(clazz.getAnnotation(Component.class)); + } } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCatalogManagerForSo.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCatalogManagerForSo.java new file mode 100644 index 00000000..8d2094b1 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCatalogManagerForSo.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.SdcPackageProvider; + +import static junit.framework.TestCase.assertNotNull; + +public class TestCatalogManagerForSo extends TestBase{ + /** + * Test bean + */ + @Test + public void testPojo(){ + SdcPackageProvider sdcPackageProvider = Mockito.mock(SdcPackageProvider.class); + CatalogManagerForSo catalogManagerForSo = new CatalogManagerForSo(cbamRestApiProviderForSo, sdcPackageProvider); + assertNotNull(catalogManagerForSo); + assertBean(JobManagerForVfc.class); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCatalogManagerForVfc.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCatalogManagerForVfc.java new file mode 100644 index 00000000..1a21bd51 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCatalogManagerForVfc.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.SdcPackageProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcPackageProvider; + +import static junit.framework.TestCase.assertNotNull; + +public class TestCatalogManagerForVfc extends TestBase{ + /** + * Test bean + */ + @Test + public void testPojo(){ + VfcPackageProvider vfcPackageProvider = Mockito.mock(VfcPackageProvider.class); + CatalogManagerForVfc catalogManagerForVfc = new CatalogManagerForVfc(cbamRestApiProviderForVfc, vfcPackageProvider); + assertNotNull(catalogManagerForVfc); + assertBean(JobManagerForVfc.class); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProviderForSo.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProviderForSo.java new file mode 100644 index 00000000..7a7955eb --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProviderForSo.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + +import static org.junit.Assert.*; + +public class TestCbamRestApiProviderForSo { + +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProviderForSo.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProviderForSo.java new file mode 100644 index 00000000..4777d9fb --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProviderForSo.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + + +import junit.framework.TestCase; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIExternalSystemInfoProvider; + +public class TestCbamTokenProviderForSo extends TestBase { + @Test + public void testBean(){ + CbamTokenProviderForSo cbamTokenProvider = Mockito.mock(CbamTokenProviderForSo.class); + AAIExternalSystemInfoProvider aaiExternalSystemInfoProvider = Mockito.mock(AAIExternalSystemInfoProvider.class); + CbamSecurityProvider cbamSecurityProvider = Mockito.mock(CbamSecurityProvider.class); + CbamRestApiProviderForSo cbamRestApiProviderForSo = new CbamRestApiProviderForSo(cbamTokenProvider, aaiExternalSystemInfoProvider, cbamSecurityProvider); + TestCase.assertNotNull(cbamRestApiProviderForSo); + assertBean(CbamRestApiProviderForSo.class); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProviderForVfc.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProviderForVfc.java new file mode 100644 index 00000000..59712d72 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProviderForVfc.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + + +import junit.framework.TestCase; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIExternalSystemInfoProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcExternalSystemInfoProvider; + +public class TestCbamTokenProviderForVfc extends TestBase { + @Test + public void testBean(){ + CbamTokenProviderForVfc cbamTokenProvider = Mockito.mock(CbamTokenProviderForVfc.class); + VfcExternalSystemInfoProvider vfcExternalSystemInfoProvider = Mockito.mock(VfcExternalSystemInfoProvider.class); + CbamSecurityProvider cbamSecurityProvider = Mockito.mock(CbamSecurityProvider.class); + CbamRestApiProviderForVfc cbamRestApiProviderForVfc = new CbamRestApiProviderForVfc(cbamTokenProvider, vfcExternalSystemInfoProvider, cbamSecurityProvider); + TestCase.assertNotNull(cbamRestApiProviderForSo); + assertBean(CbamRestApiProviderForSo.class); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManagerForSo.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManagerForSo.java new file mode 100644 index 00000000..d25859fa --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManagerForSo.java @@ -0,0 +1,34 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + +import junit.framework.TestCase; +import org.junit.Test; + +import static junit.framework.TestCase.assertNotNull; + +public class TestJobManagerForSo extends TestBase { + + /** + * Test bean + */ + @Test + public void testPojo(){ + JobManagerForSo jobManagerForSo = new JobManagerForSo(cbamRestApiProviderForSo, selfRegistrationManagerForSo); + assertNotNull(jobManagerForSo); + assertBean(JobManagerForVfc.class); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManagerForVfc.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManagerForVfc.java new file mode 100644 index 00000000..1a073b58 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManagerForVfc.java @@ -0,0 +1,33 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + +import org.junit.Test; + +import static junit.framework.TestCase.assertNotNull; + +public class TestJobManagerForVfc extends TestBase { + + /** + * Test bean + */ + @Test + public void testPojo(){ + JobManagerForVfc jobManagerForVfc = new JobManagerForVfc(cbamRestApiProviderForVfc, selfRegistrationManagerForVfc); + assertNotNull(jobManagerForVfc); + assertBean(JobManagerForVfc.class); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManagerForSo.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManagerForSo.java new file mode 100644 index 00000000..ae51dc85 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManagerForSo.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + +import junit.framework.TestCase; +import org.junit.Test; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIExternalSystemInfoProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.GrantlessGrantManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManagerForSo; + +import static junit.framework.TestCase.assertNotNull; +import static org.mockito.Mockito.mock; + +public class TestLifecycleManagerForSo extends TestBase{ + + /** + * Test bean + */ + @Test + public void testBean(){ + CatalogManagerForSo catalogManager = mock(CatalogManagerForSo.class); + GrantlessGrantManager grantManager = mock(GrantlessGrantManager.class); + AAIExternalSystemInfoProvider aaiExternalSystemInfoProvider = mock(AAIExternalSystemInfoProvider.class); + JobManagerForSo jobManagerForSo = mock(JobManagerForSo.class); + LifecycleChangeNotificationManagerForSo lifecycleChangeNotificationManagerForSo = mock(LifecycleChangeNotificationManagerForSo.class); + LifecycleManagerForSo lifecycleManagerForSo = new LifecycleManagerForSo(catalogManager, grantManager, cbamRestApiProviderForSo, aaiExternalSystemInfoProvider, jobManagerForSo, lifecycleChangeNotificationManagerForSo); + assertNotNull(lifecycleManagerForSo); + assertBean(LifecycleChangeNotificationManagerForSo.class); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManagerForVfc.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManagerForVfc.java new file mode 100644 index 00000000..e245e58a --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManagerForVfc.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; + +import org.junit.Test; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIExternalSystemInfoProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.GrantlessGrantManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcExternalSystemInfoProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManagerForSo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManagerForVfc; + +import static junit.framework.TestCase.assertNotNull; +import static org.mockito.Mockito.mock; + +public class TestLifecycleManagerForVfc extends TestBase{ + /** + * Test bean + */ + @Test + public void testBean(){ + CatalogManagerForVfc catalogManager = mock(CatalogManagerForVfc.class); + GrantlessGrantManager grantManager = mock(GrantlessGrantManager.class); + VfcExternalSystemInfoProvider aaiExternalSystemInfoProvider = mock(VfcExternalSystemInfoProvider.class); + JobManagerForVfc jobManagerForSo = mock(JobManagerForVfc.class); + LifecycleChangeNotificationManagerForVfc lifecycleChangeNotificationManagerForSo = mock(LifecycleChangeNotificationManagerForVfc.class); + LifecycleManagerForVfc lifecycleManagerForSo = new LifecycleManagerForVfc(catalogManager, grantManager, cbamRestApiProviderForVfc, aaiExternalSystemInfoProvider, jobManagerForSo, lifecycleChangeNotificationManagerForSo); + assertNotNull(lifecycleManagerForSo); + assertBean(LifecycleChangeNotificationManagerForVfc.class); + } +}
\ No newline at end of file |