diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-10 15:59:42 +0100 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-10 16:10:01 +0100 |
commit | f5608b8ab40816febb064a61e80b52b572eda768 (patch) | |
tree | 2545e8bbb004f12043666f375bb8ef33d5a4e9b5 /nokiav2/driver/src/test/java/org/onap/vfc/nfvo | |
parent | b48be0c7c0f16b9724d98fcceac898cfe1942f7d (diff) |
Add missing tests
Change-Id: I6205fc147d0702c1f4242285f4414645a4e8a3de
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')
7 files changed, 54 insertions, 41 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 47e441ff..249e16c9 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.Before; 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.util.TestUtil; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.ContextClosedEvent; @@ -138,6 +139,16 @@ public class TestNokiaSvnfmApplication { } /** + * Spring will instantiate using reflection + */ + @Test + public void testUseStaticWay() throws Exception { + //verify + //the constructor is public even if has no private fields + new NokiaSvnfmApplication(); + } + + /** * static entry point calling an other static entry point can not be tested */ @Test diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java index aefe63a2..eb3674c3 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java @@ -121,16 +121,17 @@ public class TestMsbApiProvider extends TestBase { /** - * use HTTPS for known ports (443) should be removed if https://jira.onap.org/browse/MSB-151 is solved + * use HTTPS for known ports */ @Test - public void testMsb151IssueHack() throws Exception { + public void testMsbServiceOverssl() throws Exception { NodeInfo nonDocker = new NodeInfo(); nonDocker.setIp("173.1.2.3"); - nonDocker.setPort("443"); + nonDocker.setPort("123"); microServiceInfo.setServiceName("serviceName"); microServiceInfo.setVersion("v1"); microServiceInfo.setUrl("/lead/nslcm/v1"); + microServiceInfo.setEnable_ssl(true); when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("173.1.2.3->1.2.3.4"); nodes.add(nonDocker); msbApiProvider = new MsbApiProvider(environment) { @@ -142,32 +143,7 @@ public class TestMsbApiProvider extends TestBase { when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo); msbApiProvider.afterPropertiesSet(); //when - assertEquals("https://1.2.3.4:443/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1")); - } - - /** - * use HTTPS for known ports (443) should be removed if https://jira.onap.org/browse/MSB-151 is solved - */ - @Test - public void testMsb151IssueHack2() throws Exception { - NodeInfo nonDocker = new NodeInfo(); - nonDocker.setIp("173.1.2.3"); - nonDocker.setPort("8443"); - microServiceInfo.setServiceName("serviceName"); - microServiceInfo.setVersion("v1"); - microServiceInfo.setUrl("/lead/nslcm/v1"); - when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("173.1.2.3->1.2.3.4"); - nodes.add(nonDocker); - msbApiProvider = new MsbApiProvider(environment) { - @Override - public MSBServiceClient getMsbClient() { - return msbClient; - } - }; - when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo); - msbApiProvider.afterPropertiesSet(); - //when - assertEquals("https://1.2.3.4:8443/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1")); + assertEquals("https://1.2.3.4:123/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1")); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java index 5001eedf..2cd0aa1e 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java @@ -63,14 +63,11 @@ public class TestOnapVnfdBuilder extends TestBase { verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp"); verify(logger).warn("The {} ecp does not have an requirements section", "ecpWithIcpWithOutRequirements"); verify(logger).warn("The {} internal connection point of the {} ecp does not have a VDU", "icpWithoutVdu", "myEcpWithoutIcpWithoutVdu"); - verify(logger).warn("The {} internal connection point of the {} ecp does not have a requirements section", "icpWithOutRequiements", "myEcpWithoutIcpWithoutIcpReq"); - - verify(logger).warn("The {} internal connection point does not have a VDU", "icpWithOutVdu"); verify(logger).warn("The {} internal connection point does not have a requirements section", "icpWithOutRequiements"); verify(logger).warn("The {} internal connection point does not have a VL", "icpWithOutVl"); - + verify(logger).warn("The {} type is not converted", "tosca.nodes.nfv.Unknown"); } /** 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 4d10fd52..6b04d69d 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 @@ -28,6 +28,7 @@ import org.onap.vnfmdriver.model.VnfInstantiateRequest; import org.onap.vnfmdriver.model.VnfScaleRequest; import org.onap.vnfmdriver.model.VnfTerminateRequest; +import static java.util.Optional.empty; import static org.apache.http.HttpStatus.SC_CREATED; import static org.mockito.Mockito.verify; import static org.springframework.test.util.ReflectionTestUtils.setField; @@ -70,7 +71,7 @@ public class TestLcmApi extends TestBase { //when lcmApi.healVnf(req, VNFM_ID, VNF_ID, httpResponse); //verify - verify(lifecycleManager).healVnf(VNFM_ID, VNF_ID, req, httpResponse); + verify(lifecycleManager).healVnf(VNFM_ID, VNF_ID, req, empty(), httpResponse); verify(logger).info("REST: Heal VNF"); } 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 index f716cad6..7a525b37 100644 --- 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 @@ -21,6 +21,7 @@ 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; @@ -63,4 +64,12 @@ public class TestConditions { 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/vnfm/TestCbamTokenProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java index 44ba0e52..4b35f2ff 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 @@ -45,6 +45,10 @@ import java.security.KeyStoreException; import java.util.ArrayList; import java.util.Base64; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import static junit.framework.TestCase.*; import static org.mockito.Matchers.eq; @@ -54,10 +58,10 @@ import static org.springframework.test.util.ReflectionTestUtils.setField; class HttpTestServer { Server _server; - List<String> requests = new ArrayList<>(); - List<Integer> codes = new ArrayList<>(); - List<String> respones = new ArrayList<>(); - + volatile List<String> requests = new ArrayList<>(); + volatile List<Integer> codes = new ArrayList<>(); + volatile List<String> respones = new ArrayList<>(); + ExecutorService executorService = Executors.newCachedThreadPool(); public void start() throws Exception { configureServer(); startServer(); @@ -67,6 +71,18 @@ class HttpTestServer { requests.clear(); codes.clear(); _server.start(); + Future<?> serverStarted = executorService.submit(() -> { + while(true){ + try { + Thread.sleep(10); + if(_server.isStarted()){ + return; + } + } catch (InterruptedException e) { + } + } + }); + serverStarted.get(30, TimeUnit.SECONDS); } protected void configureServer() throws Exception { @@ -119,6 +135,8 @@ public class TestCbamTokenProvider extends TestBase { testServer.start(); URI uri = testServer._server.getURI(); setField(cbamTokenProvider, "cbamKeyCloakBaseUrl", uri.toString()); + + } private void addGoodTokenResponse() { 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 c601f7ee..c6e76ef6 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 @@ -49,6 +49,7 @@ import java.util.*; import static java.lang.Boolean.parseBoolean; import static java.nio.file.Files.readAllBytes; +import static java.util.Optional.empty; import static junit.framework.TestCase.*; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; @@ -1317,7 +1318,7 @@ public class TestLifecycleManager extends TestBase { String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }"; when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new JsonParser().parse(instantiationParams)); //when - JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, restResponse); + JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(), restResponse); //verify waitForJobToFinishInJobManager(finished); assertEquals(1, actualHealRequest.getAllValues().size()); @@ -1366,7 +1367,7 @@ public class TestLifecycleManager extends TestBase { } }); //when - JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, restResponse); + JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(), restResponse); //verify waitForJobToFinishInJobManager(finished); assertEquals(100, expectedExceptions.size()); @@ -1389,7 +1390,7 @@ public class TestLifecycleManager extends TestBase { healRequest.setAffectedvm(affectedVm); when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException); //when - JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, restResponse); + JobInfo job = lifecycleManager.healVnf(VNFM_ID, VNF_ID, healRequest, empty(), restResponse); //verify waitForJobToFinishInJobManager(finished); verify(logger).error("Unable to heal VNF with myVnfId identifier", expectedException); |