diff options
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java')
-rw-r--r-- | nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java | 48 |
1 files changed, 40 insertions, 8 deletions
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 ea1afe5f..17cf8258 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 @@ -27,6 +27,7 @@ import org.springframework.test.util.ReflectionTestUtils; import static java.lang.Long.valueOf; import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.fail; import static org.mockito.Mockito.*; public class TestGenericExternalSystemInfoProvider extends TestBase { @@ -52,12 +53,12 @@ public class TestGenericExternalSystemInfoProvider extends TestBase { //when VnfmInfo vnfmInfo = genericExternalSystemInfoProvider.getVnfmInfo(VNFM_ID); //verify - verify(logger).info("Quering VNFM info from source with " + VNFM_ID + " identifier"); + verify(logger).info("Querying VNFM info from source with " + VNFM_ID + " identifier"); assertEquals(expectedVnfmInfo, vnfmInfo); //when VnfmInfo vnfmInfo2 = genericExternalSystemInfoProvider.getVnfmInfo(VNFM_ID); //verify source system not called again - verify(logger).info("Quering VNFM info from source with " + VNFM_ID + " identifier"); + verify(logger).info("Querying VNFM info from source with " + VNFM_ID + " identifier"); verify(genericExternalSystemInfoProvider, Mockito.times(1)).queryVnfmInfoFromSource(VNFM_ID); } @@ -65,24 +66,24 @@ public class TestGenericExternalSystemInfoProvider extends TestBase { * the VNFM info is retrieved without the cache eviction period */ @Test + //sleeping is required to make time pass (for cache to notice the change) + //cache is configured with 1 ms cache eviction without sleep it is not + //deterministic that at least 1 ms time will pass between calls + @SuppressWarnings("squid:S2925") public void testQueryVnfmInfoOutside() throws Exception { VnfmInfo expectedVnfmInfo = Mockito.mock(VnfmInfo.class); when(genericExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID)).thenReturn(expectedVnfmInfo); when(environment.getProperty(GenericExternalSystemInfoProvider.VNFM_INFO_CACHE_EVICTION_IN_MS, Long.class, valueOf(GenericExternalSystemInfoProvider.DEFAULT_CACHE_EVICTION_TIMEOUT_IN_MS))).thenReturn(Long.valueOf(1)); genericExternalSystemInfoProvider.afterPropertiesSet(); - //when VnfmInfo vnfmInfo = genericExternalSystemInfoProvider.getVnfmInfo(VNFM_ID); //verify assertEquals(expectedVnfmInfo, vnfmInfo); //when - //sleeping is required to make time pass (for cache to notice the change) - //cache is configured with 1 ms cache eviction without sleep it is not - //deterministic that at least 1 ms time will pass between calls - Thread.sleep(10); //NO SONAR + Thread.sleep(10); VnfmInfo vnfmInfo2 = genericExternalSystemInfoProvider.getVnfmInfo(VNFM_ID); //verify source system called again - verify(logger, times(2)).info("Quering VNFM info from source with " + VNFM_ID + " identifier"); + verify(logger, times(2)).info("Querying VNFM info from source with " + VNFM_ID + " identifier"); verify(genericExternalSystemInfoProvider, Mockito.times(2)).queryVnfmInfoFromSource(VNFM_ID); } @@ -103,4 +104,35 @@ public class TestGenericExternalSystemInfoProvider extends TestBase { } } + + /** + * Unable to query VNFM results is propagated + */ + @Test + public void testUnableToQueryVnfmInfoProvider() throws Exception{ + class TestClass extends GenericExternalSystemInfoProvider { + + TestClass(Environment environment) { + super(environment); + } + + @Override + public VnfmInfo queryVnfmInfoFromSource(String vnfmId) { + throw new RuntimeException(); + } + + @Override + public VimInfo getVimInfo(String vimId) { + return null; + } + } + try { + new TestClass(null).getVnfmInfo(VNFM_ID); + fail(); + } + catch (Exception e){ + assertEquals("Unable to query VNFM info for myVnfmId", e.getMessage()); + verify(logger).error(eq("Unable to query VNFM info for myVnfmId"), any(RuntimeException.class)); + } + } } |