Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / onap / core / TestGenericExternalSystemInfoProvider.java
index 4426383..efa4523 100644 (file)
@@ -26,7 +26,9 @@ import org.springframework.core.env.Environment;
 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 +54,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,25 +67,57 @@ 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)
         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);
     }
 
+    /**
+     * 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));
+        }
+    }
+
     class TestClass extends GenericExternalSystemInfoProvider {
 
         TestClass(Environment environment) {
@@ -100,5 +134,4 @@ public class TestGenericExternalSystemInfoProvider extends TestBase {
             return null;
         }
     }
-
 }