Removing passwordencryption key
[dmaap/datarouter.git] / datarouter-prov / src / test / java / org / onap / dmaap / datarouter / provisioning / LogServletTest.java
index 03e3d4f..a52f1a0 100755 (executable)
@@ -43,8 +43,7 @@ import javax.persistence.Persistence;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
 import static org.powermock.api.mockito.PowerMockito.when;
 
 
@@ -60,7 +59,10 @@ public class LogServletTest extends DrServletTestBase {
     @Mock
     private HttpServletResponse response;
 
-    ListAppender<ILoggingEvent> listAppender;
+    @Mock
+    private ServletOutputStream servletOutputStream;
+
+    private ListAppender<ILoggingEvent> listAppender;
 
     @BeforeClass
     public static void init() {
@@ -151,8 +153,7 @@ public class LogServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_HTTP_GET_And_Is_FeedLog_A_STATUS_OK_Response_Is_Generated()
-            throws Exception {
+    public void Given_Request_Is_HTTP_GET_And_Is_FeedLog_A_STATUS_OK_Response_Is_Generated() {
         logServlet.doGet(request, response);
         verify(response).setStatus(eq(HttpServletResponse.SC_OK));
         verifyEnteringExitCalled(listAppender);
@@ -175,12 +176,43 @@ public class LogServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_A_STATUS_OK_Response_Is_Generated()
+    public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_A_STATUS_OK_Response_Is_Generated() {
+        when(request.getParameter("type")).thenReturn("pub");
+        when(request.getParameter("expiryReason")).thenReturn(null);
+        logServlet.doGet(request, response);
+        verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+    }
+
+    @Test
+    public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_With_Filename_That_exists_A_STATUS_OK_Response_Is_Generated_And_Correct_Value_Returned()
             throws Exception {
         when(request.getParameter("type")).thenReturn("pub");
+        when(request.getPathInfo()).thenReturn("/1");
+        when(request.getParameter("publishId")).thenReturn("ID");
         when(request.getParameter("expiryReason")).thenReturn(null);
+        when(request.getParameter("statusCode")).thenReturn("204");
+        when(request.getParameter("filename")).thenReturn("file123");
         logServlet.doGet(request, response);
         verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+        verify(servletOutputStream, times(1)).print("[");
+        verify(servletOutputStream, times(1)).print(matches("\n\\{\"statusCode\":204,\"publishId\":\"ID\",\"requestURI\":\"URL/file123\",\"sourceIP\":\"172.0.0.8\",\"method\":\"PUT\",\"contentType\":\"application/vnd.dmaap-dr.log-list; version=1.0\",\"endpointId\":\"user\",\"type\":\"pub\",\"date\":\"2050-05-14T1[6-7]:46:04.422Z\",\"contentLength\":100,\"fileName\":\"file123\"}"));
+        verify(servletOutputStream, times(1)).print("[");
+    }
+
+    @Test
+    public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_With_Filename_That_Doesnt_exist_A_STATUS_OK_Response_Is_Generated_And_Empty_Array_Returned()
+            throws Exception {
+        when(request.getParameter("type")).thenReturn("pub");
+        when(request.getPathInfo()).thenReturn("/1");
+        when(request.getParameter("publishId")).thenReturn("ID");
+        when(request.getParameter("expiryReason")).thenReturn(null);
+        when(request.getParameter("statusCode")).thenReturn("204");
+        when(request.getParameter("filename")).thenReturn("file456");
+        logServlet.doGet(request, response);
+        verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+        verify(servletOutputStream, times(1)).print("[");
+        verify(servletOutputStream, times(0)).print(matches("\n\\{\"statusCode\":204,\"publishId\":\"ID\",\"requestURI\":\"URL/file123\",\"sourceIP\":\"172.0.0.8\",\"method\":\"PUT\",\"contentType\":\"application/vnd.dmaap-dr.log-list; version=1.0\",\"endpointId\":\"user\",\"type\":\"pub\",\"date\":\"2050-05-14T1[6-7]:46:04.422Z\",\"contentLength\":100,\"fileName\":\"file123\"}"));
+        verify(servletOutputStream, times(1)).print("[");
     }
 
     @Test
@@ -232,9 +264,9 @@ public class LogServletTest extends DrServletTestBase {
         when(request.getParameter("publishId")).thenReturn("bad_PublishID");
         when(request.getParameter("statusCode")).thenReturn("-1");
         when(request.getParameter("expiryReason")).thenReturn("other");
-        when(request.getParameter("start")).thenReturn(null);
-        when(request.getParameter("end")).thenReturn(null);
-        ServletOutputStream s = mock(ServletOutputStream.class);
-        when(response.getOutputStream()).thenReturn(s);
+        when(request.getParameter("start")).thenReturn("2536159564422");
+        when(request.getParameter("end")).thenReturn("2536159564422");
+        servletOutputStream = mock(ServletOutputStream.class);
+        when(response.getOutputStream()).thenReturn(servletOutputStream);
     }
 }
\ No newline at end of file