diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-04-05 11:30:13 +0200 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-04-05 14:35:45 +0200 |
commit | 0fe2fb09a5397ff8e9467071b6b5bd03f4793f63 (patch) | |
tree | e31220c504b9949d1e84dc84b8feb9353c0080a3 /nokiav2/driver/src/test/java/org/onap/vfc/nfvo | |
parent | e1b05751d48a07f42ea97ffe3511a132ed12876b (diff) |
Fix sonar issues
Change-Id: I87fdb199c591093d726ae807e501da94f61cfb5a
Issue-ID: VFC-728
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo')
7 files changed, 272 insertions, 10 deletions
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 92e19a3c..444660b1 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 @@ -21,6 +21,7 @@ import org.junit.Test; import org.mockito.*; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.Useless; import org.slf4j.Logger; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.ContextClosedEvent; @@ -149,8 +150,10 @@ public class TestNokiaSvnfmApplication { /** * static entry point calling an other static entry point can not be tested + * only using powermock */ @Test + @Useless public void useless() throws Exception { try { NokiaSvnfmApplication.main(null); 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 ebc2159d..77005f41 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 @@ -41,7 +41,6 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION; -import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestSoLifecycleManager extends TestBase { @@ -56,7 +55,6 @@ public class TestSoLifecycleManager extends TestBase { @Before public void init() { - setField(SoLifecycleManager.class, "logger", logger); soLifecycleManager = new SoLifecycleManager(lifecycleManager, vimInfoProvider, cbamRestApiProvider, jobManager); } @@ -382,10 +380,10 @@ public class TestSoLifecycleManager extends TestBase { } /** - * test VNF scale + * test VNF scale in */ @Test - public void testScaling() throws Exception { + public void testScaleIn() throws Exception { SoVnfScaleRequest soRequest = new SoVnfScaleRequest(); ArgumentCaptor<org.onap.vnfmdriver.model.VnfScaleRequest> driverRequest = ArgumentCaptor.forClass(org.onap.vnfmdriver.model.VnfScaleRequest.class); JobInfo jobInfo = new JobInfo(); @@ -408,6 +406,32 @@ public class TestSoLifecycleManager extends TestBase { } /** + * test VNF scale out + */ + @Test + public void testScaleOut() throws Exception { + SoVnfScaleRequest soRequest = new SoVnfScaleRequest(); + ArgumentCaptor<org.onap.vnfmdriver.model.VnfScaleRequest> driverRequest = ArgumentCaptor.forClass(org.onap.vnfmdriver.model.VnfScaleRequest.class); + JobInfo jobInfo = new JobInfo(); + jobInfo.setJobId(JOB_ID); + + soRequest.setAspectId("aspectId"); + soRequest.setDirection(SoScaleDirection.OUT); + soRequest.setSteps(2); + JsonObject additionalParams = new JsonObject(); + soRequest.setAdditionalParams(additionalParams); + when(lifecycleManager.scaleVnf(eq(VNFM_ID), eq(VNF_ID), driverRequest.capture(), eq(httpResponse))).thenReturn(jobInfo); + //when + SoJobHandler jobHandler = soLifecycleManager.scale(VNFM_ID, VNF_ID, soRequest, httpResponse); + //verify + assertEquals(JOB_ID, jobHandler.getJobId()); + assertEquals(2, Integer.parseInt(driverRequest.getValue().getNumberOfSteps())); + assertEquals("aspectId", driverRequest.getValue().getAspectId()); + assertEquals(org.onap.vnfmdriver.model.ScaleDirection.OUT, driverRequest.getValue().getType()); + assertEquals(additionalParams, driverRequest.getValue().getAdditionalParam()); + } + + /** * test VNF heal */ @Test @@ -454,6 +478,27 @@ public class TestSoLifecycleManager extends TestBase { } /** + * test VNF deactivation + */ + @Test + public void testDeactivationForceFull() throws Exception { + SoVnfTerminationRequest soRequest = new SoVnfTerminationRequest(); + ArgumentCaptor<org.onap.vnfmdriver.model.VnfTerminateRequest> driverRequest = ArgumentCaptor.forClass(org.onap.vnfmdriver.model.VnfTerminateRequest.class); + JobInfo jobInfo = new JobInfo(); + jobInfo.setJobId(JOB_ID); + soRequest.setMode(SoTerminationMode.FORCEFUL); + JsonObject additionalParams = new JsonObject(); + soRequest.setAdditionalParams(additionalParams); + when(lifecycleManager.terminateAndDelete(eq(VNFM_ID), eq(VNF_ID), driverRequest.capture(), eq(httpResponse))).thenReturn(jobInfo); + //when + SoJobHandler jobHandler = soLifecycleManager.deactivate(VNFM_ID, VNF_ID, soRequest, httpResponse); + //verify + assertEquals(JOB_ID, jobHandler.getJobId()); + assertEquals(VnfTerminationType.FORCEFUL, driverRequest.getValue().getTerminationType()); + assertEquals(null, driverRequest.getValue().getGracefulTerminationTimeout()); + } + + /** * test VNF deletion */ @Test diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSoApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSoApi.java new file mode 100644 index 00000000..be1ee5a7 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSoApi.java @@ -0,0 +1,160 @@ +/* + * 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.restapi; + +import junit.framework.TestCase; +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.so.SoLifecycleManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; +import org.onap.vnfmadapter.so.model.*; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.springframework.test.util.ReflectionTestUtils.setField; + + +public class TestSoApi extends TestBase { + + @Mock + private SoLifecycleManager soLifecycleManager; + @InjectMocks + private SoApi soApi; + @Mock + private SoJobHandler jobHandler; + + @Before + public void initMocks() throws Exception { + setField(SoApi.class, "logger", logger); + } + + /** + * test create + */ + @Test + public void testCreate() { + SoVnfCreationRequest soRequest = Mockito.mock(SoVnfCreationRequest.class); + SoVnfCreationResponse vnf = new SoVnfCreationResponse(); + when(soLifecycleManager.create(VNFM_ID, soRequest)).thenReturn(vnf); + //when + SoVnfCreationResponse actual = soApi.createVnf(soRequest, VNFM_ID, httpResponse); + //verify + verify(logger).info("REST: Create the VNF"); + TestCase.assertEquals(vnf, actual); + } + + /** + * test activation + */ + @Test + public void testActivate() { + SoVnfActivationRequest soRequest = Mockito.mock(SoVnfActivationRequest.class); + when(soLifecycleManager.activate(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler); + //when + SoJobHandler soJobHandler = soApi.activateVnf(soRequest, VNFM_ID, VNF_ID, httpResponse); + //verify + verify(logger).info("REST: Activate the VNF"); + TestCase.assertEquals(jobHandler, soJobHandler); + } + + /** + * test scale + */ + @Test + public void testScale() { + SoVnfScaleRequest soRequest = Mockito.mock(SoVnfScaleRequest.class); + when(soLifecycleManager.scale(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler); + //when + SoJobHandler soJobHandler = soApi.scaleVnf(soRequest, VNFM_ID, VNF_ID, httpResponse); + //verify + verify(logger).info("REST: Scale the VNF"); + TestCase.assertEquals(jobHandler, soJobHandler); + } + + /** + * test heal + */ + @Test + public void testHeal() { + SoVnfHealRequest soRequest = Mockito.mock(SoVnfHealRequest.class); + when(soLifecycleManager.heal(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler); + //when + SoJobHandler soJobHandler = soApi.healVnf(soRequest, VNFM_ID, VNF_ID, httpResponse); + //verify + verify(logger).info("REST: Heal the VNF"); + TestCase.assertEquals(jobHandler, soJobHandler); + } + + + /** + * test custom + */ + @Test + public void testCustom() { + SoVnfCustomOperation soRequest = Mockito.mock(SoVnfCustomOperation.class); + when(soLifecycleManager.customOperation(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler); + //when + SoJobHandler soJobHandler = soApi.executeCustomOperation(soRequest, VNFM_ID, VNF_ID, httpResponse); + //verify + verify(logger).info("REST: Execute custom operation on the VNF"); + TestCase.assertEquals(jobHandler, soJobHandler); + } + + /** + * test deactivation + */ + @Test + public void testDeactivation() { + SoVnfTerminationRequest soRequest = Mockito.mock(SoVnfTerminationRequest.class); + when(soLifecycleManager.deactivate(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler); + //when + SoJobHandler soJobHandler = soApi.deactivateVnf(soRequest, VNFM_ID, VNF_ID, httpResponse); + //verify + verify(logger).info("REST: Deactivate the VNF"); + TestCase.assertEquals(jobHandler, soJobHandler); + } + + /** + * test delete + */ + @Test + public void testDelete() { + //when + soApi.deleteVnf(VNFM_ID, VNF_ID, httpResponse); + //verify + verify(logger).info("REST: Delete the VNF"); + verify(soLifecycleManager).delete(VNFM_ID, VNF_ID); + } + + /** + * test deactivation + */ + @Test + public void testGetJob() { + SoJobDetail jobDetail = new SoJobDetail(); + when(soLifecycleManager.getJobDetails(VNFM_ID, JOB_ID)).thenReturn(jobDetail); + //when + SoJobDetail actial = soApi.getJob(VNFM_ID, JOB_ID, httpResponse); + //verify + verify(logger).trace("REST: Query the job"); + TestCase.assertEquals(jobDetail, actial); + } + +} diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java index df97d4a4..0b31fef5 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java @@ -20,6 +20,7 @@ import java.util.Base64; import java.util.HashSet; import java.util.Set; import org.junit.Test; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.Useless; import static org.junit.Assert.*; @@ -108,9 +109,9 @@ public class TestSystemFunctions { /** * Test HTTP client wrapping - * (semi useless test) */ @Test + @Useless //more less already ensured by Java type safety public void testHttp() { assertNotNull(SystemFunctions.systemFunctions().getHttpClient()); } 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 e21e638a..7817edfd 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 @@ -72,13 +72,15 @@ public class TestCbamRestApiProvider extends TestBase { private java.util.List<NodeInfo> nodes = new ArrayList<>(); private CbamRestApiProvider cbamRestApiProvider; - private CbamSecurityProvider cbamSecurityProvider = spy(new CbamSecurityProvider()); + private CbamSecurityProvider cbamSecurityProvider ; @Before public void init() { + CbamSecurityProvider real = new CbamSecurityProvider(); + setFieldWithPropertyAnnotation(real, "${skipCertificateVerification}", true); + setFieldWithPropertyAnnotation(real, "${skipHostnameVerification}", true); + cbamSecurityProvider = spy(real); microServiceInfo.setNodes(nodes); - setField(cbamSecurityProvider, "skipCertificateVerification", true); - setField(cbamSecurityProvider, "skipHostnameVerification", true); cbamRestApiProvider = new CbamRestApiProvider(driverProperties, 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); @@ -156,6 +158,7 @@ public class TestCbamRestApiProvider extends TestBase { * (questionable benefit [ this is more less ensured by Java type safety) ] */ @Test + @Useless public void testCatalogAPiWrapping() { com.nokia.cbam.catalog.v1.ApiClient c = Mockito.mock(com.nokia.cbam.catalog.v1.ApiClient.class); class TestClasss extends CbamRestApiProvider { @@ -169,6 +172,7 @@ public class TestCbamRestApiProvider extends TestBase { } } DefaultApi defaultApi = Mockito.mock(DefaultApi.class); + //when when(c.createService(DefaultApi.class)).thenReturn(defaultApi); //verify TestClasss testInstnace = new TestClasss(); @@ -181,6 +185,7 @@ public class TestCbamRestApiProvider extends TestBase { * (questionable benefit [ this is more less ensured by Java type safety) ] */ @Test + @Useless public void testLcmAPiWrapping() { com.nokia.cbam.lcn.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcn.v32.ApiClient.class); class TestClasss extends CbamRestApiProvider { @@ -194,6 +199,7 @@ public class TestCbamRestApiProvider extends TestBase { } } SubscriptionsApi defaultApi = Mockito.mock(SubscriptionsApi.class); + //when when(c.createService(SubscriptionsApi.class)).thenReturn(defaultApi); //verify TestClasss testInstnace = new TestClasss(); @@ -206,6 +212,7 @@ public class TestCbamRestApiProvider extends TestBase { * (questionable benefit [ this is more less ensured by Java type safety) ] */ @Test + @Useless public void testLcnAPiWrapping() { com.nokia.cbam.lcm.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcm.v32.ApiClient.class); class TestClasss extends CbamRestApiProvider { @@ -219,6 +226,7 @@ public class TestCbamRestApiProvider extends TestBase { } } VnfsApi defaultApi = Mockito.mock(VnfsApi.class); + //when when(c.createService(VnfsApi.class)).thenReturn(defaultApi); //verify TestClasss testInstnace = new TestClasss(); @@ -231,6 +239,7 @@ public class TestCbamRestApiProvider extends TestBase { * (questionable benefit [ this is more less ensured by Java type safety) ] */ @Test + @Useless public void testOperationExecutionsApiAPiWrapping() { com.nokia.cbam.lcm.v32.ApiClient c = Mockito.mock(com.nokia.cbam.lcm.v32.ApiClient.class); class TestClasss extends CbamRestApiProvider { @@ -244,6 +253,7 @@ public class TestCbamRestApiProvider extends TestBase { } } OperationExecutionsApi defaultApi = Mockito.mock(OperationExecutionsApi.class); + //when when(c.createService(OperationExecutionsApi.class)).thenReturn(defaultApi); //verify TestClasss testInstnace = new TestClasss(); 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 index 22db05b2..6a98e9e0 100644 --- 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 @@ -18,18 +18,36 @@ 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 { +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()); - assertPojoMethodsFor(DriverProperties.class).areWellImplemented(); } } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/Useless.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/Useless.java new file mode 100644 index 00000000..e13a5fd0 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/Useless.java @@ -0,0 +1,25 @@ +/* + * 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; + + +/** + * Used to note nearly useless tests + */ +public @interface Useless { + +}
\ No newline at end of file |