diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-04-27 12:22:22 +0200 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-04-27 23:41:20 +0200 |
commit | 88a64ebf39dea43a4f0d69d18e5ab5933febea98 (patch) | |
tree | 5bafe04c3b2d0ce153beab0437440505d89b4d58 /nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia | |
parent | 2322725653143b3b8dd3b764273f5161c1f32104 (diff) |
Fix component startup
Change-Id: Ia45d4a682f8faceb8c045ffedd7611bc61b21b7b
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia')
32 files changed, 373 insertions, 292 deletions
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java index 640097f3..69e3482c 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java @@ -20,18 +20,19 @@ import org.junit.runners.Suite; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestGenericExternalSystemInfoProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestIpMappingProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestMsbApiProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestSelfRegistrationManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestAAIExternalSystemInfoProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestAAIRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestGrantlessGrantManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestSdcPackageProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.*; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.so.TestSoLifecycleManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.*; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestCbamVnfPackageBuilder; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestCbamVnfdBuilder; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestOnapVnfPackageBuilder; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestOnapVnfdBuilder; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi.*; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.TestConditions; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.TestRealConfig; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.TestServletInitializer; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.*; @@ -60,6 +61,8 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedA TestGrantlessGrantManager.class, TestSdcPackageProvider.class, + TestSoLifecycleManager.class, + TestVfcExternalSystemInfoProvider.class, TestVfcGrantManager.class, TestVfcPackageProvider.class, @@ -77,7 +80,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedA TestSwaggerApi.class, TestSwaggerDefinitionConsistency.class, - TestConditions.class, TestServletInitializer.class, TestRealConfig.class, @@ -97,7 +99,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedA TestCbamRestApiProvider.class, TestCbamSecurityProvider.class, TestCbamTokenProvider.class, - TestDriverProperties.class, TestJobManager.class, TestVfcGrantManager.class, TestLifecycleManager.class, 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 b4eed27c..69a74bc3 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 @@ -25,11 +25,15 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManagerForSo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManagerForVfc; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.event.ContextClosedEvent; +import org.springframework.core.env.ConfigurableEnvironment; import static junit.framework.TestCase.*; import static org.mockito.Mockito.*; @@ -38,7 +42,9 @@ import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestNokiaSvnfmApplication extends TestBase { @Mock - private JobManager jobManager; + private JobManagerForVfc jobManagerForVfc; + @Mock + private JobManagerForSo jobManagerForSo; private NokiaSvnfmApplication.SelfRegistrationTrigger selfRegistrationTriggerer; private NokiaSvnfmApplication.SelfDeRegistrationTrigger selfUnregistrationTriggerer; @@ -46,8 +52,8 @@ public class TestNokiaSvnfmApplication extends TestBase { @Before public void initMocks() throws Exception { - selfRegistrationTriggerer = new NokiaSvnfmApplication.SelfRegistrationTrigger(selfRegistrationManager, jobManager); - selfUnregistrationTriggerer = new NokiaSvnfmApplication.SelfDeRegistrationTrigger(selfRegistrationManager, jobManager); + selfRegistrationTriggerer = new NokiaSvnfmApplication.SelfRegistrationTrigger(selfRegistrationManagerForVfc, selfRegistrationManagerForSo, jobManagerForSo, jobManagerForVfc); + selfUnregistrationTriggerer = new NokiaSvnfmApplication.SelfDeRegistrationTrigger(selfRegistrationManagerForVfc, selfRegistrationManagerForSo, jobManagerForSo, jobManagerForVfc); setField(NokiaSvnfmApplication.class, "logger", logger); } @@ -70,13 +76,14 @@ public class TestNokiaSvnfmApplication extends TestBase { public void testRegistrationIsCalledAfterComponentIsUp() throws Exception { //given ApplicationReadyEvent event = Mockito.mock(ApplicationReadyEvent.class); + useVfc(event); //when selfRegistrationTriggerer.onApplicationEvent(event); //verify boolean success = false; while (!success) { try { - verify(selfRegistrationManager).register(); + verify(selfRegistrationManagerForVfc).register(); verify(logger).info("Self registration started"); verify(logger).info("Self registration finished"); success = true; @@ -89,6 +96,21 @@ public class TestNokiaSvnfmApplication extends TestBase { assertTrue(ApplicationReadyEvent.class.isAssignableFrom(event.getClass())); } + private void useVfc(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[]{}); + } + + private void useVfc(ContextClosedEvent event) { + ApplicationContext context = Mockito.mock(ApplicationContext.class); + when(context.getEnvironment()).thenReturn(environment); + when(event.getApplicationContext()).thenReturn(context); + when(environment.getActiveProfiles()).thenReturn(new String[]{}); + } + /** * Assert that the self de-registration process is started after the servlet has been ramped down */ @@ -96,12 +118,14 @@ public class TestNokiaSvnfmApplication extends TestBase { public void testUnRegistrationIsCalledAfterComponentIsUp() throws Exception { //given ContextClosedEvent event = Mockito.mock(ContextClosedEvent.class); + useVfc(event); //when selfUnregistrationTriggerer.onApplicationEvent(event); //verify - InOrder inOrder = Mockito.inOrder(jobManager, selfRegistrationManager); - inOrder.verify(jobManager).prepareForShutdown(); - inOrder.verify(selfRegistrationManager).deRegister(); + InOrder inOrder = Mockito.inOrder(jobManagerForVfc, jobManagerForSo, selfRegistrationManagerForVfc); + inOrder.verify(jobManagerForVfc).prepareForShutdown(); + inOrder.verify(jobManagerForSo).prepareForShutdown(); + inOrder.verify(selfRegistrationManagerForVfc).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) @@ -115,11 +139,11 @@ public class TestNokiaSvnfmApplication extends TestBase { public void testPreparingForShutdownDoesNotStartRegistration() throws Exception { //given ApplicationReadyEvent event = Mockito.mock(ApplicationReadyEvent.class); - when(jobManager.isPreparingForShutDown()).thenReturn(true); + when(jobManagerForVfc.isPreparingForShutDown()).thenReturn(true); //when selfRegistrationTriggerer.onApplicationEvent(event); //verify - verify(selfRegistrationManager, never()).register(); + verify(selfRegistrationManagerForVfc, never()).register(); } /** @@ -129,6 +153,7 @@ public class TestNokiaSvnfmApplication extends TestBase { @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 @@ -140,8 +165,9 @@ public class TestNokiaSvnfmApplication extends TestBase { } return null; } - }).when(selfRegistrationManager).register(); + }).when(selfRegistrationManagerForVfc).register(); ApplicationReadyEvent event = Mockito.mock(ApplicationReadyEvent.class); + useVfc(event); //when selfRegistrationTriggerer.onApplicationEvent(event); //verify @@ -167,8 +193,9 @@ public class TestNokiaSvnfmApplication extends TestBase { public void failedDeRegistration() { //given RuntimeException expectedException = new RuntimeException(); - Mockito.doThrow(expectedException).when(selfRegistrationManager).deRegister(); + Mockito.doThrow(expectedException).when(selfRegistrationManagerForVfc).deRegister(); ContextClosedEvent event = Mockito.mock(ContextClosedEvent.class); + useVfc(event); //when try { selfUnregistrationTriggerer.onApplicationEvent(event); diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java index 2bd0820c..a284f28f 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java @@ -50,6 +50,8 @@ public class CTDirectReal { */ @Test public void testBasicWorkflow() throws Exception { + SystemFunctions.systemFunctions().sleep(10000000 * 1000L); + VimInfo nokia_regionOne = externalSystemInfoProvider.getVimInfo("Nokia_RegionOne"); VnfLifecycleChangeNotification recievedNot = new VnfLifecycleChangeNotification(); @@ -86,8 +88,7 @@ public class CTDirectReal { addedCp.setTenantId("de8fd0d1d5874503a47b920c10f4322a"); addedCp.setCpdId("cpdId"); affectedConnectionPoints.getPost().add(addedCp); - notificationProcessor.processNotification(recievedNot, null, of(affectedConnectionPoints), "Nokia_RegionOne"); - SystemFunctions.systemFunctions().sleep(10000000 * 1000L); + notificationProcessor.processNotification(recievedNot, null, of(affectedConnectionPoints), "Nokia_RegionOne", "vnfmId"); } JsonObject additionalData(String key, String value) { diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java index efa45234..850579f0 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java @@ -16,6 +16,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core; +import java.util.Set; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -108,6 +109,11 @@ public class TestGenericExternalSystemInfoProvider extends TestBase { public VimInfo getVimInfo(String vimId) { return null; } + + @Override + public Set<String> getVnfms() { + return null; + } } try { new TestClass(null).getVnfmInfo(VNFM_ID); @@ -133,5 +139,10 @@ public class TestGenericExternalSystemInfoProvider extends TestBase { public VimInfo getVimInfo(String vimId) { return null; } + + @Override + public Set<String> getVnfms() { + return null; + } } } 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/onap/core/TestSelfRegistrationManager.java index 671b4b50..d1e2dea1 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/onap/core/TestSelfRegistrationManager.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core; import com.google.common.collect.Lists; import com.nokia.cbam.lcn.v32.model.CreateSubscriptionRequest; @@ -26,18 +26,22 @@ import java.util.Arrays; import java.util.UUID; import org.junit.Before; import org.junit.Test; -import org.mockito.*; +import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; +import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.onap.msb.model.MicroServiceFullInfo; import org.onap.msb.model.MicroServiceInfo; import org.onap.msb.model.Node; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; +import static com.google.common.collect.Sets.newHashSet; import static com.nokia.cbam.lcn.v32.model.OperationType.*; import static junit.framework.TestCase.*; -import static org.mockito.Mockito.any; import static org.mockito.Mockito.*; import static org.onap.msb.model.MicroServiceInfo.ProtocolEnum.REST; import static org.onap.msb.model.MicroServiceInfo.VisualRangeEnum._1; @@ -52,14 +56,14 @@ public class TestSelfRegistrationManager extends TestBase { private java.util.List<Subscription> subscriptions = new ArrayList<>(); private ArgumentCaptor<MicroServiceInfo> registeredMicroservice = ArgumentCaptor.forClass(MicroServiceInfo.class); private ArgumentCaptor<CreateSubscriptionRequest> subscriptionToCreate = ArgumentCaptor.forClass(CreateSubscriptionRequest.class); - @InjectMocks private SelfRegistrationManager selfRegistrationManager; @Before public void initMocks() throws Exception { + selfRegistrationManager = new SelfRegistrationManager(vnfmInfoProvider, msbApiProvider, cbamRestApiProvider); + setField(SelfRegistrationManager.class, "logger", logger); when(lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION)).thenReturn(buildObservable(subscriptions)); - when(driverProperties.getVnfmId()).thenReturn(VNFM_ID); setField(selfRegistrationManager, "driverMsbExternalIp", "1.2.3.4"); setField(selfRegistrationManager, "driverVnfmExternalIp", "5.6.7.8"); setField(selfRegistrationManager, "driverPort", "12345"); @@ -78,6 +82,8 @@ public class TestSelfRegistrationManager extends TestBase { public void testRegistration() throws Exception { //given Subscription subscription = new Subscription(); + subscription.setId(SUBCRIPTION_ID); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenReturn(buildObservable(subscription)); MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo(); when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenReturn(buildObservable(returnedMicroService)); @@ -87,7 +93,7 @@ public class TestSelfRegistrationManager extends TestBase { InOrder registrationOrder = Mockito.inOrder(lcnApi, msbClient); registrationOrder.verify(lcnApi).subscriptionsPost(any(), any()); registrationOrder.verify(msbClient).addMicroService(any(), any(), any()); - + assertEquals(VNFM_ID, selfRegistrationManager.getVnfmId(SUBCRIPTION_ID)); assertMicroserviceRegistered(); assertNewLcnSubscription(); assertServiceUp(); @@ -112,7 +118,7 @@ public class TestSelfRegistrationManager extends TestBase { assertTrue(subscriptionCreation.getFilter().getOperationTypes().contains(TERMINATE)); assertTrue(subscriptionCreation.getFilter().getOperationTypes().contains(INSTANTIATE)); assertEquals(4, subscriptionCreation.getFilter().getOperationTypes().size()); - verify(logger).info("Subscribing to CBAM LCN {} with callback to {}", driverProperties.getCbamLcnUrl(), "http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); + verify(logger).info("Subscribing to CBAM LCN {} with callback to {}", HTTP_LCN_URL, "http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); } private void assertMicroserviceRegistered() { @@ -142,6 +148,7 @@ public class TestSelfRegistrationManager extends TestBase { MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo(); when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenReturn(buildObservable(returnedMicroService)); Subscription existingSubscription = new Subscription(); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); existingSubscription.setId(UUID.randomUUID().toString()); existingSubscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); subscriptions.add(existingSubscription); @@ -161,6 +168,7 @@ public class TestSelfRegistrationManager extends TestBase { //given RuntimeException expectedException = new RuntimeException(); when(lcnApi.subscriptionsPost(any(), any())).thenThrow(expectedException); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); //when try { selfRegistrationManager.register(); @@ -181,6 +189,8 @@ public class TestSelfRegistrationManager extends TestBase { public void testFailedMsbPublish() throws Exception { //given Subscription subscription = new Subscription(); + subscription.setId(SUBCRIPTION_ID); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenAnswer(invocationOnMock -> { subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); subscription.setId(UUID.randomUUID().toString()); @@ -188,7 +198,6 @@ public class TestSelfRegistrationManager extends TestBase { when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value()); return buildObservable(subscription); }); - MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo(); RuntimeException expectedException = new RuntimeException(); when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenThrow(expectedException); //when @@ -215,8 +224,16 @@ public class TestSelfRegistrationManager extends TestBase { //given Subscription subscription = new Subscription(); subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); - subscription.setId(UUID.randomUUID().toString()); - subscriptions.add(subscription); + subscription.setId(SUBCRIPTION_ID); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); + when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenAnswer(invocationOnMock -> { + 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); + }); + selfRegistrationManager.assureSubscription(VNFM_ID); when(jobManager.hasOngoingJobs()).thenReturn(false); when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value()); VoidObservable MSB_DELETE = new VoidObservable(); @@ -242,8 +259,16 @@ public class TestSelfRegistrationManager extends TestBase { //given Subscription subscription = new Subscription(); subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); - subscription.setId(UUID.randomUUID().toString()); - subscriptions.add(subscription); + subscription.setId(SUBCRIPTION_ID); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); + when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenAnswer(invocationOnMock -> { + 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); + }); + selfRegistrationManager.assureSubscription(VNFM_ID); when(jobManager.hasOngoingJobs()).thenReturn(false); when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() { @Override @@ -272,7 +297,8 @@ public class TestSelfRegistrationManager extends TestBase { //given Subscription subscription = new Subscription(); subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); - subscription.setId(UUID.randomUUID().toString()); + subscription.setId(SUBCRIPTION_ID); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); subscriptions.add(subscription); when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() { @Override @@ -303,8 +329,16 @@ public class TestSelfRegistrationManager extends TestBase { //given Subscription subscription = new Subscription(); subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn"); - subscription.setId(UUID.randomUUID().toString()); - subscriptions.add(subscription); + subscription.setId(SUBCRIPTION_ID); + when(vnfmInfoProvider.getVnfms()).thenReturn(newHashSet(VNFM_ID)); + when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenAnswer(invocationOnMock -> { + 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); + }); + selfRegistrationManager.assureSubscription(VNFM_ID); when(jobManager.hasOngoingJobs()).thenReturn(false); RuntimeException expectedException = new RuntimeException(); doThrow(expectedException).when(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION); diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestVnfmCredentials.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestVnfmCredentials.java new file mode 100644 index 00000000..5043efc7 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestVnfmCredentials.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.onap.core; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class TestVnfmCredentials { + + @Test + public void testPojo() { + VnfmCredentials vnfmCredentials = new VnfmCredentials("myUsername", "myPassword", "myClientId", "myClientSecret"); + assertEquals("myUsername", vnfmCredentials.getUsername()); + assertEquals("myClientId", vnfmCredentials.getClientId()); + assertEquals("myPassword", vnfmCredentials.getPassword()); + assertEquals("myClientSecret", vnfmCredentials.getClientSecret()); + assertEquals("VnfmCredentials{username='myUsername', password='450ad03db9395dfccb5e03066fd7f16cfba2b61e23d516373714471459052ec90a9a4bf3a151e600ea8aaed36e3b8c21a3d38ab1705839749d130da4380f1448', clientId='myClientId', clientSecret='ce1b1f932289546075ea7f98928cf9948181c1b72e12f61a244e1a49d85f52afa74dcb3b290b8eae2b7e26c3bebcd798a641e43533144e9624be741f8827065c'}", vnfmCredentials.toString()); + assertTrue(!vnfmCredentials.toString().contains("myPassword")); + assertTrue(!vnfmCredentials.toString().contains("myClientSecret")); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestVnfmUrls.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestVnfmUrls.java new file mode 100644 index 00000000..f4f2f330 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestVnfmUrls.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.onap.core; + +import org.junit.Test; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; + +import static org.junit.Assert.assertEquals; + +public class TestVnfmUrls extends TestBase { + + @Test + public void testPojo() { + VnfmUrls vnfmUrls = new VnfmUrls(HTTP_AUTH_URL, HTTP_LCM_URL, HTTP_LCN_URL, HTTP_CATLOG_URL); + assertEquals(HTTP_AUTH_URL, vnfmUrls.getAuthUrl()); + assertEquals(HTTP_LCN_URL, vnfmUrls.getLcnUrl()); + assertEquals(HTTP_LCM_URL, vnfmUrls.getLcmUrl()); + assertEquals(HTTP_CATLOG_URL, vnfmUrls.getCatalogUrl()); + } +}
\ No newline at end of file diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java index bd5e42f1..efbe1f8f 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 @@ -31,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.aai.auth.HttpBasicAuth; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; @@ -82,15 +83,12 @@ 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()); + HttpBasicAuth basic = (HttpBasicAuth) apiClient.getApiAuthorizations().get("basic"); + assertEquals("username", basic.getUsername()); + assertEquals("aaiPassword", basic.getPassword()); //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); @@ -122,8 +120,9 @@ public class TestAAIRestApiProvider extends TestBase { assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory()); assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier()); Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build(); - Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp); - assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization")); + HttpBasicAuth basic = (HttpBasicAuth) apiClient.getApiAuthorizations().get("basic"); + assertEquals("username", basic.getUsername()); + assertEquals("aaiPassword", basic.getPassword()); } /** @@ -146,8 +145,9 @@ public class TestAAIRestApiProvider extends TestBase { assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory()); assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier()); Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build(); - Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp); - assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization")); + HttpBasicAuth basic = (HttpBasicAuth) apiClient.getApiAuthorizations().get("basic"); + assertEquals("username", basic.getUsername()); + assertEquals("aaiPassword", basic.getPassword()); } /** @@ -170,8 +170,9 @@ public class TestAAIRestApiProvider extends TestBase { assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory()); assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier()); Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build(); - Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp); - assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization")); + HttpBasicAuth basic = (HttpBasicAuth) apiClient.getApiAuthorizations().get("basic"); + assertEquals("username", basic.getUsername()); + assertEquals("aaiPassword", basic.getPassword()); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java index 1af96992..3c8333e4 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java @@ -27,10 +27,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.fail; import static org.apache.http.HttpHeaders.ACCEPT; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.SERVICE_NAME; import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; import static org.springframework.test.util.ReflectionTestUtils.setField; @@ -40,7 +37,7 @@ public class TestSdcPackageProvider extends TestBase { @Before public void init() { - sdcPackageProvider = new SdcPackageProvider(msbApiProvider, driverProperties); + sdcPackageProvider = new SdcPackageProvider(msbApiProvider); setField(SdcPackageProvider.class, "logger", logger); setFieldWithPropertyAnnotation(sdcPackageProvider, "${sdcUsername}", "sdcUsername"); setFieldWithPropertyAnnotation(sdcPackageProvider, "${sdcPassword}", "sdcPassword"); @@ -58,7 +55,7 @@ public class TestSdcPackageProvider extends TestBase { //verify assertEquals("test", new String("test")); HttpGet httpGet = (HttpGet) request.getValue(); - assertEquals(VNFM_ID, httpGet.getFirstHeader("X-ECOMP-InstanceID").getValue()); + assertEquals(SERVICE_NAME, httpGet.getFirstHeader("X-ECOMP-InstanceID").getValue()); assertEquals(SERVICE_NAME, httpGet.getFirstHeader("X-FromAppId").getValue()); assertEquals(APPLICATION_OCTET_STREAM_VALUE, httpGet.getFirstHeader(ACCEPT).getValue()); assertEquals("https://1.2.3.4:456/g/sdc/v1/catalog/resources/csarId/toscaModel", httpGet.getURI().toASCIIString()); diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java index d183e38e..8b95f00d 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java @@ -89,7 +89,7 @@ public class TestAAINotificationProcessor extends TestBase { addedCp.setServerProviderId("serverId"); affectedConnectionPoints.getPost().add(addedCp); //when - aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID); + aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager); inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink); @@ -137,7 +137,7 @@ public class TestAAINotificationProcessor extends TestBase { affectedConnectionPoints.getPost().add(changedCpAfter); //when - aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID); + aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify verify(lInterfaceManager).update(VNF_ID, VIM_ID, unchangedCp, inMaintenance); verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, changedCpBefore, inMaintenance); @@ -182,7 +182,7 @@ public class TestAAINotificationProcessor extends TestBase { affectedConnectionPoints.getPost().add(cpWithoutServer); //when - aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID); + aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager); inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink); @@ -212,7 +212,7 @@ public class TestAAINotificationProcessor extends TestBase { recievenNotification.setAffectedVirtualLinks(new ArrayList<>()); recievenNotification.setVnfInstanceId(VNF_ID); //when - aaiNotificationProcessor.processNotification(recievenNotification, null, empty(), VIM_ID); + aaiNotificationProcessor.processNotification(recievenNotification, null, empty(), VIM_ID, VNFM_ID); //verify verify(logger).warn("The changed connection points are not present in VNF with {} identifier", VNF_ID); } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java index 8991b819..04513d39 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java @@ -26,7 +26,6 @@ import org.onap.aai.model.Relationship; import org.onap.aai.model.RelationshipData; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import org.slf4j.Logger; @@ -40,7 +39,7 @@ public class TestAbstractManager extends TestBase { @Before public void init() { - dummyManager = new DummyManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties); + dummyManager = new DummyManager(aaiRestApiProvider, cbamRestApiProvider); } /** @@ -234,8 +233,8 @@ public class TestAbstractManager extends TestBase { class DummyManager extends AbstractManager { - DummyManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) { - super(aaiRestApiProvider, cbamRestApiProvider, driverProperties); + DummyManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider) { + super(aaiRestApiProvider, cbamRestApiProvider); } @Override 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 9feaf74c..5ade389d 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 @@ -33,22 +33,23 @@ import org.onap.aai.api.NetworkApi; import org.onap.aai.model.GenericVnf; import org.onap.aai.model.Relationship; import org.onap.aai.model.RelationshipData; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import static java.lang.Boolean.TRUE; +import static java.util.Optional.of; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.fail; -import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.eq; import static org.mockito.Mockito.*; import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestGenericVnfManager extends TestBase { private ArgumentCaptor<GenericVnf> payload = ArgumentCaptor.forClass(GenericVnf.class); + @Mock private AAIRestApiProvider aaiRestApiProvider; @Mock @@ -75,7 +76,7 @@ public class TestGenericVnfManager extends TestBase { @Before public void init() { when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi); - genericVnfManager = new GenericVnfManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties); + genericVnfManager = new GenericVnfManager(aaiRestApiProvider, cbamRestApiProviderForSo); setField(GenericVnfManager.class, "logger", logger); AtomicLong currentTime = new AtomicLong(0L); when(systemFunctions.currentTimeMillis()).thenAnswer(new Answer<Long>() { @@ -106,19 +107,20 @@ public class TestGenericVnfManager extends TestBase { } return buildObservable(vnfs.iterator().next()); }); - when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo)); + when(cbamRestApiProviderForSo.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 VOID_OBSERVABLE.value(); }); vnfInfo.setName("vnfName"); //when - genericVnfManager.createOrUpdate(VNF_ID, true); + genericVnfManager.createOrUpdate(VNF_ID, true, VNFM_ID, of("nsId")); //verify GenericVnf vnfSentToAai = payload.getValue(); assertEquals(VNF_ID, vnfSentToAai.getVnfId()); assertEquals(VNF_ID, vnfSentToAai.getVnfId()); assertEquals("NokiaVNF", vnfSentToAai.getVnfType()); + assertEquals(SelfRegistrationManager.SERVICE_NAME, vnfSentToAai.getNfType()); assertEquals(TRUE, vnfSentToAai.isInMaint()); assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled()); assertEquals("vnfName", vnfSentToAai.getVnfName()); @@ -135,11 +137,11 @@ public class TestGenericVnfManager extends TestBase { GenericVnf vnfInAaai = new GenericVnf(); 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(cbamRestApiProviderForSo.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo)); when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(VOID_OBSERVABLE.value()); vnfInfo.setName("vnfName"); //when - genericVnfManager.createOrUpdate(VNF_ID, true); + genericVnfManager.createOrUpdate(VNF_ID, true, VNFM_ID, of("nsId")); //verify GenericVnf vnfSentToAai = payload.getValue(); assertEquals(VNF_ID, vnfSentToAai.getVnfId()); @@ -162,7 +164,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)); RuntimeException expectedException = new RuntimeException(); - when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenThrow(expectedException); + when(cbamRestApiProviderForSo.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenThrow(expectedException); when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> { vnfInAaai.setResourceVersion("v2"); return null; @@ -170,7 +172,7 @@ public class TestGenericVnfManager extends TestBase { vnfInfo.setName("vnfName"); //when try { - genericVnfManager.createOrUpdate(VNF_ID, true); + genericVnfManager.createOrUpdate(VNF_ID, true, VNFM_ID, of("nsId")); } catch (Exception e) { verify(logger).error("Unable to query VNF with myVnfId identifier from CBAM", expectedException); assertEquals("Unable to query VNF with myVnfId identifier from CBAM", e.getMessage()); @@ -193,7 +195,7 @@ public class TestGenericVnfManager extends TestBase { } throw new NoSuchElementException(); }); - when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo)); + when(cbamRestApiProviderForSo.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo)); RuntimeException runtimeException = new RuntimeException(); when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> { GenericVnf vnfSentToAAi = (GenericVnf) invocation.getArguments()[1]; @@ -204,7 +206,7 @@ public class TestGenericVnfManager extends TestBase { }); vnfInfo.setName("vnfName"); //when - genericVnfManager.createOrUpdate(VNF_ID, true); + genericVnfManager.createOrUpdate(VNF_ID, true, VNFM_ID, of("nsId")); //verify GenericVnf vnfSentToAai = payload.getValue(); assertEquals(VNF_ID, vnfSentToAai.getVnfId()); 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 30141638..f160447b 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 @@ -49,7 +49,7 @@ public class TestL3NetworkManager extends TestBase { @Before public void init() { - l3NetworkManager = new L3NetworkManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties); + l3NetworkManager = new L3NetworkManager(aaiRestApiProvider, cbamRestApiProviderForSo); setField(L3NetworkManager.class, "logger", logger); when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi); } 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 6d03eb55..e22491f2 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 @@ -47,7 +47,7 @@ public class TestLInterfaceManager extends TestBase { @Before public void init() { - lInterfaceManager = new LInterfaceManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties); + lInterfaceManager = new LInterfaceManager(aaiRestApiProvider, cbamRestApiProviderForSo); setField(LInterfaceManager.class, "logger", logger); when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi); } 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 b2dc063a..43a47d24 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 @@ -27,12 +27,11 @@ import org.mockito.Mock; import org.onap.aai.api.NetworkApi; import org.onap.aai.model.Vnfc; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProviderForSo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import static junit.framework.TestCase.assertEquals; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner; @@ -44,13 +43,15 @@ public class TestVnfcManager extends TestBase { @Mock private AAIRestApiProvider aaiRestApiProvider; + @Mock + private CbamRestApiProviderForSo cbamRestApiProviderForSo; private VnfcManager vnfcManager; @Mock private NetworkApi networkApi; @Before public void init() { - vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties); + vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProviderForSo); setField(VnfcManager.class, "logger", logger); when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi); } 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 080615a1..892b4e8e 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 @@ -30,12 +30,11 @@ import org.onap.aai.api.CloudInfrastructureApi; import org.onap.aai.model.Relationship; import org.onap.aai.model.Vserver; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProviderForSo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import static junit.framework.TestCase.assertEquals; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner; @@ -47,13 +46,15 @@ public class TestVserverManager extends TestBase { @Mock private AAIRestApiProvider aaiRestApiProvider; + @Mock + private CbamRestApiProviderForSo cbamRestApiProviderForSo; private VserverManager vserverManager; @Mock private CloudInfrastructureApi cloudInfrastructureApi; @Before public void init() { - vserverManager = new VserverManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties); + vserverManager = new VserverManager(aaiRestApiProvider, cbamRestApiProviderForSo); setField(VserverManager.class, "logger", logger); when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi); } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/TestSoLifecycleManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/TestSoLifecycleManager.java index 77005f41..582b41df 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/TestSoLifecycleManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/TestSoLifecycleManager.java @@ -27,11 +27,9 @@ import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VimInfoProvider; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.AdditionalParameters; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIExternalSystemInfoProvider; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.GenericVnfManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.*; import org.onap.vnfmadapter.so.model.*; import org.onap.vnfmdriver.model.*; @@ -46,16 +44,18 @@ public class TestSoLifecycleManager extends TestBase { private static final String VNFD_ID = "cbamVnfdId"; @Mock - private LifecycleManager lifecycleManager; + private LifecycleManagerForSo lifecycleManager; @Mock - private VimInfoProvider vimInfoProvider; + private AAIExternalSystemInfoProvider vimInfoProvider; @Mock - private JobManager jobManager; + private JobManagerForSo jobManager; + @Mock + private GenericVnfManager genericVnfManager; private SoLifecycleManager soLifecycleManager; @Before public void init() { - soLifecycleManager = new SoLifecycleManager(lifecycleManager, vimInfoProvider, cbamRestApiProvider, jobManager); + soLifecycleManager = new SoLifecycleManager(lifecycleManager, vimInfoProvider, cbamRestApiProviderForSo, jobManager, genericVnfManager); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java index b9d44603..f1ed1e16 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java @@ -28,10 +28,9 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManagerForVfc; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import org.onap.vnfmdriver.model.*; @@ -50,8 +49,7 @@ public class TestVfcGrantManager extends TestBase { private GrantVNFResponseVim vim = new GrantVNFResponseVim(); private GrantVNFResponse grantResponse = new GrantVNFResponse(); @Mock - private CatalogManager cbamCatalogManager; - @InjectMocks + private CatalogManagerForVfc cbamCatalogManager; private VfcGrantManager vfcGrantManager; @Before @@ -59,6 +57,7 @@ public class TestVfcGrantManager extends TestBase { setField(VfcGrantManager.class, "logger", logger); when(nsLcmApi.grantvnf(grantRequest.capture())).thenReturn(buildObservable(grantResponse)); grantResponse.setVim(vim); + vfcGrantManager = new VfcGrantManager(cbamCatalogManager, cbamRestApiProviderForVfc, vfcRestApiProvider); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java index ded1bcd9..06cb6434 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java @@ -42,8 +42,6 @@ import static java.util.Optional.empty; import static java.util.Optional.of; import static junit.framework.TestCase.*; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; import static org.mockito.Mockito.*; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION; import static org.springframework.test.util.ReflectionTestUtils.setField; @@ -62,7 +60,7 @@ public class TestVfcNotificationSender extends TestBase { @Before public void init() throws Exception { - vfcNotificationSender = new VfcNotificationSender(driverProperties, vfcRestApiProvider); + vfcNotificationSender = new VfcNotificationSender(vfcRestApiProvider); setField(VfcNotificationSender.class, "logger", logger); when(nsLcmApi.vNFLCMNotification(eq(VNFM_ID), eq(VNF_ID), sentLcnToVfc.capture())).thenReturn(null); instantiationOperation.setId("instantiationOperationExecutionId"); @@ -114,7 +112,7 @@ public class TestVfcNotificationSender extends TestBase { recievedLcn.setStatus(OperationStatus.STARTED); recievedLcn.setOperation(OperationType.INSTANTIATE); //when - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); assertNull(sentLcnToVfc.getValue().getAffectedVl()); @@ -188,7 +186,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -271,7 +269,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -352,7 +350,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, terminationOperation, of(affectedConnectionPoints), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, terminationOperation, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -473,7 +471,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -585,7 +583,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); scaleOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -698,7 +696,7 @@ public class TestVfcNotificationSender extends TestBase { scaleOperation.setAdditionalData(additionalData); scaleOperation.setOperationType(OperationType.SCALE); //when - vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -762,7 +760,7 @@ public class TestVfcNotificationSender extends TestBase { scaleOperation.setOperationType(OperationType.SCALE); when(logger.isInfoEnabled()).thenReturn(false); //when - vfcNotificationSender.processNotification(recievedLcn, scaleOperation, empty(), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, scaleOperation, empty(), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -821,7 +819,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID, VNFM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -846,7 +844,7 @@ public class TestVfcNotificationSender extends TestBase { recievedLcn.setOperation(OperationType.INSTANTIATE); //when try { - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID, VNFM_ID); //verify fail(); } catch (Exception e) { diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java index 9f3c00ec..8a79a33a 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java @@ -39,10 +39,7 @@ import org.springframework.http.HttpStatus; import org.springframework.mock.web.DelegatingServletOutputStream; import static junit.framework.TestCase.*; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip; import static org.springframework.test.util.ReflectionTestUtils.setField; diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java index 15505ba7..55252c2b 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java @@ -18,10 +18,9 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManagerForVfc; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManagerForVfc; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import org.onap.vnfmdriver.model.VnfHealRequest; import org.onap.vnfmdriver.model.VnfInstantiateRequest; @@ -38,15 +37,15 @@ import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestLcmApi extends TestBase { @Mock - private LifecycleManager lifecycleManager; + private LifecycleManagerForVfc lifecycleManager; @Mock - private JobManager jobManager; - @InjectMocks + private JobManagerForVfc jobManager; private LcmApi lcmApi; @Before public void initMocks() throws Exception { setField(LcmApi.class, "logger", logger); + lcmApi = new LcmApi(lifecycleManager, jobManager); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java index 67842f61..d600f18b 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java @@ -19,10 +19,10 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi; import com.nokia.cbam.lcm.v32.model.VnfLifecycleChangeNotification; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManager; +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 org.mockito.Mockito.verify; import static org.springframework.test.util.ReflectionTestUtils.setField; @@ -33,13 +33,16 @@ public class TestLcnApi extends TestBase { @Mock private VnfLifecycleChangeNotification lcn; @Mock - private LifecycleChangeNotificationManager lcnManager; - @InjectMocks + private LifecycleChangeNotificationManagerForVfc lifecycleChangeNotificationManagerForVfc; + @Mock + private LifecycleChangeNotificationManagerForSo lifecycleChangeNotificationManagerForSo; + private LcnApi lcnApi; @Before public void initMocks() throws Exception { setField(LcnApi.class, "logger", logger); + lcnApi = new LcnApi(lifecycleChangeNotificationManagerForSo, lifecycleChangeNotificationManagerForVfc); } /** @@ -59,7 +62,7 @@ public class TestLcnApi extends TestBase { //when lcnApi.handleLcn(lcn); //verify - verify(lcnManager).handleLcn(lcn); + verify(lifecycleChangeNotificationManagerForVfc).handleLcn(lcn); verify(logger).info("REST: handle LCN"); } } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java index f9b6f3ce..bbe78793 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java @@ -19,8 +19,9 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi; import javax.servlet.ServletOutputStream; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManagerForVfc; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -32,13 +33,14 @@ import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestSwaggerApi extends TestBase { - @InjectMocks private SwaggerApi swaggerApi; - + @Mock + private SelfRegistrationManagerForVfc selfRegistrationManagerForVfc; @Before public void initMocks() throws Exception { setField(SwaggerApi.class, "logger", logger); + swaggerApi = new SwaggerApi(selfRegistrationManagerForVfc); } /** @@ -47,7 +49,7 @@ public class TestSwaggerApi extends TestBase { @Test public void testSwaggerRetrieval() throws Exception { byte[] bytes = new byte[]{1, 2}; - when(selfRegistrationManager.getSwaggerApiDefinition()).thenReturn(bytes); + when(selfRegistrationManagerForVfc.getSwaggerApiDefinition()).thenReturn(bytes); ServletOutputStream os = Mockito.mock(ServletOutputStream.class); when(httpResponse.getOutputStream()).thenReturn(os); //when diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java deleted file mode 100644 index 671764ae..00000000 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestConditions.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2016-2017, Nokia Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring; - -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.env.Environment; - -import static org.mockito.Mockito.when; - -public class TestConditions { - - @Mock - private ConditionContext conditionContext; - @Mock - private Environment environment; - - private String[] activeProfiles = new String[]{"a", "b"}; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - when(conditionContext.getEnvironment()).thenReturn(environment); - when(environment.getActiveProfiles()).thenReturn(activeProfiles); - } - - /** - * if direct integration is not specified VF-C based integration is used - */ - @Test - public void testVfcBased() throws Exception { - //verify - TestCase.assertTrue(new Conditions.UseForVfc().matches(conditionContext, null)); - TestCase.assertFalse(new Conditions.UseForDirect().matches(conditionContext, null)); - } - - /** - * if direct integration is not specified VF-C based integration is used - */ - @Test - public void testDirectBased() throws Exception { - activeProfiles[1] = "direct"; - //verify - TestCase.assertFalse(new Conditions.UseForVfc().matches(conditionContext, null)); - TestCase.assertTrue(new Conditions.UseForDirect().matches(conditionContext, null)); - } - - /** - * use class in a static way - */ - @Test - public void useStaticway() { - TestUtil.coveragePrivateConstructorForClassesWithStaticMethodsOnly(Conditions.class); - } - -} diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/MultiExceptionTest.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/MultiExceptionTest.java new file mode 100644 index 00000000..549aa759 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/MultiExceptionTest.java @@ -0,0 +1,50 @@ +/* + * 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.util; + + +import com.google.common.collect.Lists; +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +public class MultiExceptionTest { + @Test + public void testConstruction() { + Exception c1 = new Exception(); + Exception c2 = new Exception(); + //when + MultiException e = new MultiException("msg", c1, c2); + //verify + assertEquals("msg", e.getMessage()); + assertEquals(c1, e.getCauses().get(0)); + assertEquals(c2, e.getCauses().get(1)); + assertEquals(2, e.getCauses().size()); + } + + @Test + public void testConstruction2() { + Exception c1 = new Exception(); + Exception c2 = new Exception(); + //when + MultiException e = new MultiException("msg", Lists.newArrayList(c1, c2)); + //verify + assertEquals("msg", e.getMessage()); + assertEquals(c1, e.getCauses().get(0)); + assertEquals(c2, e.getCauses().get(1)); + assertEquals(2, e.getCauses().size()); + } +}
\ No newline at end of file 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 804f395d..347d6d2b 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 @@ -50,12 +50,14 @@ import org.onap.msb.api.ServiceResourceApi; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.MsbApiProvider; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManagerForSo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManagerForVfc; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AaiSecurityProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcRestApiProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions; import org.onap.vfccatalog.api.VnfpackageApi; import org.onap.vnfmdriver.api.NslcmApi; +import org.onap.vnfmdriver.model.VnfmInfo; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; @@ -66,6 +68,7 @@ import retrofit2.Response; import static junit.framework.TestCase.assertEquals; 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; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip; @@ -77,10 +80,19 @@ public class TestBase { public static final String VIM_ID = "myCloudOwnerId_myRegionName"; public static final String JOB_ID = "myJobId"; public static final String CBAM_VNFD_ID = "cbamVnfdId"; + public static final String HTTP_AUTH_URL = "http://authurl/"; + public static final String HTTP_LCM_URL = "http://lcmurl/"; + public static final String HTTP_LCN_URL = "http://lcnurl/"; + public static final String HTTP_CATLOG_URL = "http://catlogurl/"; + public static final String SUBCRIPTION_ID = "subcriptionId"; protected static VoidObservable VOID_OBSERVABLE = new VoidObservable(); @Mock protected CbamRestApiProvider cbamRestApiProvider; @Mock + protected CbamRestApiProviderForSo cbamRestApiProviderForSo; + @Mock + protected CbamRestApiProviderForVfc cbamRestApiProviderForVfc; + @Mock protected VfcRestApiProvider vfcRestApiProvider; @Mock protected MsbApiProvider msbApiProvider; @@ -93,7 +105,9 @@ public class TestBase { @Mock protected OperationExecutionsApi operationExecutionApi; @Mock - protected SelfRegistrationManager selfRegistrationManager; + protected SelfRegistrationManagerForVfc selfRegistrationManagerForVfc; + @Mock + protected SelfRegistrationManagerForSo selfRegistrationManagerForSo; @Mock protected Logger logger; @Mock @@ -101,7 +115,7 @@ public class TestBase { @Mock protected ServiceResourceApi msbClient; @Mock - protected DriverProperties driverProperties; + protected Constants driverProperties; @Mock protected NslcmApi nsLcmApi; @Mock @@ -124,6 +138,8 @@ public class TestBase { @Mock protected Environment environment; + protected VnfmInfo vnfmInfo = new VnfmInfo(); + protected static <T> Call<T> buildCall(T response) { Call<T> call = Mockito.mock(Call.class); try { @@ -146,18 +162,34 @@ public class TestBase { when(cbamRestApiProvider.getCbamOperationExecutionApi(VNFM_ID)).thenReturn(operationExecutionApi); when(cbamRestApiProvider.getCbamLcnApi(VNFM_ID)).thenReturn(lcnApi); when(cbamRestApiProvider.getCbamCatalogApi(VNFM_ID)).thenReturn(cbamCatalogApi); + when(cbamRestApiProviderForSo.getCbamLcmApi(VNFM_ID)).thenReturn(vnfApi); + when(cbamRestApiProviderForSo.getCbamOperationExecutionApi(VNFM_ID)).thenReturn(operationExecutionApi); + when(cbamRestApiProviderForSo.getCbamLcnApi(VNFM_ID)).thenReturn(lcnApi); + when(cbamRestApiProviderForSo.getCbamCatalogApi(VNFM_ID)).thenReturn(cbamCatalogApi); + + when(cbamRestApiProviderForVfc.getCbamLcmApi(VNFM_ID)).thenReturn(vnfApi); + when(cbamRestApiProviderForVfc.getCbamOperationExecutionApi(VNFM_ID)).thenReturn(operationExecutionApi); + when(cbamRestApiProviderForVfc.getCbamLcnApi(VNFM_ID)).thenReturn(lcnApi); + when(cbamRestApiProviderForVfc.getCbamCatalogApi(VNFM_ID)).thenReturn(cbamCatalogApi); + when(msbApiProvider.getMsbApi()).thenReturn(msbClient); when(vfcRestApiProvider.getNsLcmApi()).thenReturn(nsLcmApi); when(vfcRestApiProvider.getVfcCatalogApi()).thenReturn(vfcCatalogApi); when(systemFunctions.getHttpClient()).thenReturn(httpClient); when(httpClient.execute(request.capture())).thenReturn(response); when(response.getEntity()).thenReturn(entity); - when(driverProperties.getVnfmId()).thenReturn(VNFM_ID); when(systemFunctions.getHttpClient()).thenReturn(httpClient); when(logger.isInfoEnabled()).thenReturn(true); when(logger.isDebugEnabled()).thenReturn(true); when(logger.isWarnEnabled()).thenReturn(true); when(logger.isErrorEnabled()).thenReturn(true); + when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(vnfmInfo); + vnfmInfo.setUrl(HTTP_AUTH_URL + SEPARATOR + HTTP_LCM_URL + SEPARATOR + HTTP_LCN_URL + SEPARATOR + HTTP_CATLOG_URL); + vnfmInfo.setUserName("myUsername" + SEPARATOR + "myClientId"); + vnfmInfo.setPassword("myPassword" + SEPARATOR + "myClientSecret"); + when(selfRegistrationManagerForSo.getVnfmId(SUBCRIPTION_ID)).thenReturn(VNFM_ID); + when(selfRegistrationManagerForVfc.getVnfmId(SUBCRIPTION_ID)).thenReturn(VNFM_ID); + } @After @@ -215,7 +247,7 @@ public class TestBase { throw new NoSuchElementException("The " + obj.getClass() + " does not have a filed with " + key + " annotation"); } - protected static class VoidObservable { + public static class VoidObservable { boolean called = false; ObservableFromCallable<Void> s = new ObservableFromCallable(new Callable() { @Override diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java index 74c40a2a..e9170e4c 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java @@ -36,7 +36,6 @@ import org.onap.msb.model.MicroServiceFullInfo; import org.onap.msb.model.NodeInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.IpMappingProvider; -import org.onap.vnfmdriver.model.VnfmInfo; import org.springframework.core.env.Environment; import static junit.framework.TestCase.assertEquals; @@ -80,7 +79,7 @@ public class TestCbamRestApiProvider extends TestBase { setFieldWithPropertyAnnotation(real, "${skipHostnameVerification}", true); cbamSecurityProvider = spy(real); microServiceInfo.setNodes(nodes); - cbamRestApiProvider = new CbamRestApiProvider(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); + cbamRestApiProvider = new CbamRestApiProvider(cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn(""); when(environment.getProperty(GenericExternalSystemInfoProvider.VNFM_INFO_CACHE_EVICTION_IN_MS, Long.class, Long.valueOf(10 * 60 * 1000))).thenReturn(10 * 60 * 1000L); } @@ -90,9 +89,6 @@ public class TestCbamRestApiProvider extends TestBase { */ @Test public void testCbamLcmApi() throws Exception { - VnfmInfo expectedVnfmInfo = new VnfmInfo(); - when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(expectedVnfmInfo); - expectedVnfmInfo.setUrl("https://cbamurl:123/d/"); ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>(); doAnswer(sslSocketFactoryResultCaptor).when(cbamSecurityProvider).buildSSLSocketFactory(); when(cbamSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier); @@ -100,7 +96,7 @@ public class TestCbamRestApiProvider extends TestBase { //when ApiClient cbamLcmApi = cbamRestApiProvider.buildLcmApiClient(VNFM_ID); //verify - assertEquals("https://cbamurl:123/d/", cbamLcmApi.getAdapterBuilder().build().baseUrl().toString()); + assertEquals(HTTP_LCM_URL, cbamLcmApi.getAdapterBuilder().build().baseUrl().toString()); assertEquals(sslSocketFactoryResultCaptor.getResult(), cbamLcmApi.getOkBuilder().build().sslSocketFactory()); Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations(); assertEquals(1, apiAuthorizations.size()); @@ -117,12 +113,11 @@ public class TestCbamRestApiProvider extends TestBase { doAnswer(sslSocketFactoryResultCaptor).when(cbamSecurityProvider).buildSSLSocketFactory(); when(cbamSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier); when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn(interceptor); - when(driverProperties.getCbamCatalogUrl()).thenReturn("https://cbamurl:123/d/"); //when com.nokia.cbam.catalog.v1.ApiClient cbamLcmApi = cbamRestApiProvider.buildCatalogApiClient(VNFM_ID); //verify String actual = cbamLcmApi.getAdapterBuilder().build().baseUrl().toString(); - assertEquals("https://cbamurl:123/d/", actual); + assertEquals(HTTP_CATLOG_URL, actual); assertEquals(sslSocketFactoryResultCaptor.getResult(), cbamLcmApi.getOkBuilder().build().sslSocketFactory()); Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations(); assertEquals(1, apiAuthorizations.size()); @@ -139,12 +134,11 @@ public class TestCbamRestApiProvider extends TestBase { doAnswer(sslSocketFactoryResultCaptor).when(cbamSecurityProvider).buildSSLSocketFactory(); when(cbamSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier); when(cbamTokenProvider.getToken(VNFM_ID)).thenReturn(interceptor); - when(driverProperties.getCbamLcnUrl()).thenReturn("https://cbamurl:123/d/"); //when com.nokia.cbam.lcn.v32.ApiClient cbamLcmApi = cbamRestApiProvider.buildLcnApiClient(VNFM_ID); //verify String actual = cbamLcmApi.getAdapterBuilder().build().baseUrl().toString(); - assertEquals("https://cbamurl:123/d/", actual); + assertEquals(HTTP_LCN_URL, actual); assertEquals(sslSocketFactoryResultCaptor.getResult(), cbamLcmApi.getOkBuilder().build().sslSocketFactory()); Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations(); assertEquals(1, apiAuthorizations.size()); @@ -162,7 +156,7 @@ public class TestCbamRestApiProvider extends TestBase { com.nokia.cbam.catalog.v1.ApiClient c = Mockito.mock(com.nokia.cbam.catalog.v1.ApiClient.class); class TestClasss extends CbamRestApiProvider { public TestClasss() { - super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); + super(cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); } @Override @@ -189,7 +183,7 @@ public class TestCbamRestApiProvider extends TestBase { com.nokia.cbam.lcn.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcn.v32.ApiClient.class); class TestClasss extends CbamRestApiProvider { public TestClasss() { - super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); + super(cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); } @Override @@ -216,7 +210,7 @@ public class TestCbamRestApiProvider extends TestBase { com.nokia.cbam.lcm.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcm.v32.ApiClient.class); class TestClasss extends CbamRestApiProvider { public TestClasss() { - super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); + super(cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); } @Override @@ -243,7 +237,7 @@ public class TestCbamRestApiProvider extends TestBase { com.nokia.cbam.lcm.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcm.v32.ApiClient.class); class TestClasss extends CbamRestApiProvider { public TestClasss() { - super(driverProperties, cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); + super(cbamTokenProvider, vnfmInfoProvider, cbamSecurityProvider); } @Override diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java index 26816a13..6c6a6aeb 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java @@ -26,13 +26,10 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mockito; -import org.onap.vnfmdriver.model.VnfmInfo; import org.springframework.http.HttpStatus; import static junit.framework.TestCase.*; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestCbamTokenProvider extends TestBase { @@ -40,7 +37,6 @@ public class TestCbamTokenProvider extends TestBase { private static String GOOD_RESPONSE = "{ \"access_token\" : \"myToken\", \"expires_in\" : 1000 }"; @InjectMocks private CbamTokenProvider cbamTokenProvider; - private VnfmInfo vnfmInfo = new VnfmInfo(); private HttpTestServer testServer; public static String extractToken(Interceptor token) throws IOException { @@ -56,18 +52,13 @@ public class TestCbamTokenProvider extends TestBase { @Before public void initMocks() throws Exception { setField(CbamTokenProvider.class, "logger", logger); - setField(cbamTokenProvider, "username", "myUserName"); - setField(cbamTokenProvider, "password", "myPassword"); setField(cbamTokenProvider, "skipCertificateVerification", true); setField(cbamTokenProvider, "skipHostnameVerification", true); when(vnfmInfoProvider.getVnfmInfo(VNFM_ID)).thenReturn(vnfmInfo); - vnfmInfo.setPassword("vnfmPassword"); - vnfmInfo.setUserName("vnfmUserName"); - vnfmInfo.setUrl("http://127.0.0.3:12345"); testServer = new HttpTestServer(); testServer.start(); URI uri = testServer._server.getURI(); - setField(cbamTokenProvider, "cbamKeyCloakBaseUrl", uri.toString()); + vnfmInfo.setUrl(vnfmInfo.getUrl().replace(HTTP_AUTH_URL, uri.toString())); } private void addGoodTokenResponse() { @@ -203,9 +194,9 @@ public class TestCbamTokenProvider extends TestBase { private void assertTokenRequest(String body) { assertContains(body, "grant_type", "password"); - assertContains(body, "client_id", "vnfmUserName"); - assertContains(body, "client_secret", "vnfmPassword"); - assertContains(body, "username", "myUserName"); + assertContains(body, "client_id", "myClientId"); + assertContains(body, "client_secret", "myClientSecret"); + assertContains(body, "username", "myUsername"); assertContains(body, "password", "myPassword"); } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestDriverProperties.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestDriverProperties.java deleted file mode 100644 index 1db7d975..00000000 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestDriverProperties.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016-2017, Nokia Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm; - -import org.junit.Test; - -import static junit.framework.TestCase.assertEquals; -import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; - - -public class TestDriverProperties extends TestBase { - - /** - * Test basic POJO behaviour - */ - @Test - public void test() { - assertPojoMethodsFor(DriverProperties.class).areWellImplemented(); - } - - /** - * Test parameter initialization by Spring - * - changes in this constants should be also altered in - * - application*.properties - * - in deployment configuration file - * - documentation - */ - @Test - public void testSpringParameterLoading() { - DriverProperties driverProperties = new DriverProperties(); - setFieldWithPropertyAnnotation(driverProperties, "${cbamCatalogUrl}", "cbamCatalogUrl"); - setFieldWithPropertyAnnotation(driverProperties, "${cbamLcnUrl}", "cbamLcnUrl"); - setFieldWithPropertyAnnotation(driverProperties, "${vnfmId}", "vnfmId"); - assertEquals("cbamCatalogUrl", driverProperties.getCbamCatalogUrl()); - assertEquals("cbamLcnUrl", driverProperties.getCbamLcnUrl()); - assertEquals("vnfmId", driverProperties.getVnfmId()); - - } -} 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 432fff6d..79dcac31 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 @@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletResponse; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -54,7 +53,6 @@ public class TestJobManager extends TestBase { @Mock private HttpServletResponse httpResponse; - @InjectMocks private JobManager jobManager; private List<VnfInfo> vnfs = new ArrayList<>(); @@ -62,7 +60,8 @@ public class TestJobManager extends TestBase { public void initMocks() throws Exception { ReflectionTestUtils.setField(JobManager.class, "logger", logger); when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfs)); - when(selfRegistrationManager.isReady()).thenReturn(true); + when(selfRegistrationManagerForVfc.isReady()).thenReturn(true); + jobManager = new JobManager(cbamRestApiProviderForVfc, selfRegistrationManagerForVfc); } /** @@ -550,7 +549,7 @@ public class TestJobManager extends TestBase { @Test public void noJobCanBeStartedIfRegistrationNotFinished() throws Exception { //given - when(selfRegistrationManager.isReady()).thenReturn(false); + when(selfRegistrationManagerForVfc.isReady()).thenReturn(false); //when try { jobManager.spawnJob(VNF_ID, httpResponse); 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 fba5e0d5..14e764c9 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 @@ -51,7 +51,6 @@ import static java.nio.file.Files.readAllBytes; import static java.util.Optional.empty; import static junit.framework.TestCase.*; -import static org.mockito.Mockito.eq; import static org.mockito.Mockito.*; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; 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 449217f9..bfb30abd 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 @@ -71,6 +71,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase { healOperation.setId("healOperaitonExecutionId"); healOperation.setOperationType(OperationType.HEAL); recievedLcn.setLifecycleOperationOccurrenceId("instantiationOperationExecutionId"); + recievedLcn.setSubscriptionId(SUBCRIPTION_ID); healOperation.setStartTime(OffsetDateTime.now().plusDays(1)); recievedLcn.setVnfInstanceId(VNF_ID); when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecutions)); @@ -78,7 +79,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase { prepOperation(scaleOperation); prepOperation(healOperation); prepOperation(terminationOperation); - doNothing().when(notificationSender).processNotification(eq(recievedLcn), currentOperationExecution.capture(), affectedConnectionPoints.capture(), eq(VIM_ID)); + doNothing().when(notificationSender).processNotification(eq(recievedLcn), currentOperationExecution.capture(), affectedConnectionPoints.capture(), eq(VIM_ID), eq(VNFM_ID)); InstantiateVnfRequest instantiateVnfRequest = new InstantiateVnfRequest(); VimInfo vimInfo = new VimInfo(); vimInfo.setId(VIM_ID); @@ -341,6 +342,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase { //given //add an non processed notification VnfLifecycleChangeNotification nonProcessedEvent = new VnfLifecycleChangeNotification(); + nonProcessedEvent.setSubscriptionId(SUBCRIPTION_ID); nonProcessedEvent.setStatus(OperationStatus.FINISHED); nonProcessedEvent.setOperation(OperationType.TERMINATE); OperationExecution secondTerminationOperationExecution = new OperationExecution(); |