Add test cases for 65% branch coverage
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / DRNodeCadiFilterTest.java
index f6737b1..bb36718 100644 (file)
@@ -1,4 +1,4 @@
-/**-\r
+/*\r
  * ============LICENSE_START=======================================================\r
  *  Copyright (C) 2019 Nordix Foundation.\r
  * ================================================================================\r
 \r
 package org.onap.dmaap.datarouter.node;\r
 \r
+import static org.mockito.Mockito.doThrow;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.io.IOException;\r
+import javax.servlet.FilterChain;\r
+import javax.servlet.ServletException;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
 import org.junit.runner.RunWith;\r
@@ -32,19 +43,10 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;\r
 import org.powermock.modules.junit4.PowerMockRunner;\r
 \r
-import javax.servlet.FilterChain;\r
-import javax.servlet.ServletException;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-import java.io.IOException;\r
-\r
-import static org.mockito.Mockito.*;\r
-\r
 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")\r
 @PrepareForTest({CadiFilter.class})\r
 @RunWith(PowerMockRunner.class)\r
-public class DRNodeCadiFilterTest\r
-{\r
+public class DRNodeCadiFilterTest {\r
 \r
     @Mock\r
     private PropAccess access;\r
@@ -67,7 +69,8 @@ public class DRNodeCadiFilterTest
     }\r
 \r
     @Test\r
-    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called() throws Exception {\r
+    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
@@ -75,12 +78,13 @@ public class DRNodeCadiFilterTest
         PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");\r
         when(request.getPathInfo()).thenReturn("/publish/5");\r
         when(request.getMethod()).thenReturn("GET");\r
-        cadiFilter.doFilter(request,response,chain);\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(1)).doFilter(request, response);\r
     }\r
 \r
     @Test\r
-    public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called() throws Exception {\r
+    public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
@@ -88,12 +92,13 @@ public class DRNodeCadiFilterTest
         PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");\r
         when(request.getPathInfo()).thenReturn("/internal/5");\r
         when(request.getMethod()).thenReturn("GET");\r
-        cadiFilter.doFilter(request,response,chain);\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(1)).doFilter(request, response);\r
     }\r
 \r
     @Test\r
-    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called() throws Exception {\r
+    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
@@ -102,20 +107,22 @@ public class DRNodeCadiFilterTest
         when(request.getPathInfo()).thenReturn("/publish/5/fileId");\r
         when(request.getMethod()).thenReturn("GET");\r
         PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));\r
-        cadiFilter.doFilter(request,response,chain);\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(0)).doFilter(request, response);\r
     }\r
 \r
     @Test\r
-    public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter() throws Exception {\r
+    public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
         PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);\r
         when(request.getPathInfo()).thenReturn("/publish/5");\r
         when(request.getMethod()).thenReturn("DELETE");\r
-        doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  Possible missing fileid.");\r
-        cadiFilter.doFilter(request,response,chain);\r
+        doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND,\r
+                "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  Possible missing fileid.");\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(1)).doFilter(request, response);\r
     }\r
 }\r