Refactor Prov DB handling
[dmaap/datarouter.git] / datarouter-prov / src / test / java / org / onap / dmaap / datarouter / provisioning / InternalServletTest.java
index b421e99..5153166 100644 (file)
@@ -44,6 +44,7 @@ import javax.servlet.http.HttpServletResponse;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.read.ListAppender;
 import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -54,7 +55,9 @@ import org.mockito.Mock;
 import org.onap.dmaap.datarouter.provisioning.beans.Deleteable;
 import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
 import org.onap.dmaap.datarouter.provisioning.beans.LogRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
 import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
+import org.onap.dmaap.datarouter.provisioning.utils.Poker;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
@@ -169,7 +172,9 @@ public class InternalServletTest extends DrServletTestBase {
   public void Given_Request_Is_HTTP_GET_Starts_With_Logs_In_Endpoint_And_File_Exists_Then_Request_Returns_Ok()
       throws Exception {
     when(request.getPathInfo()).thenReturn("/logs/testFile.txt");
+    File testDir = new File("unit-test-logs");
     File testFile = new File("unit-test-logs/testFile.txt");
+    testDir.mkdirs();
     testFile.createNewFile();
     testFile.deleteOnExit();
     ServletOutputStream outStream = mock(ServletOutputStream.class);
@@ -274,6 +279,16 @@ public class InternalServletTest extends DrServletTestBase {
     verifyEnteringExitCalled(listAppender);
   }
 
+  @Test
+  public void Given_Request_Is_HTTP_DELETE_With_LogRollInterval_Api_In_Endpoint_Request_Succeeds() {
+    when(request.getPathInfo()).thenReturn("/api/LOGROLL_INTERVAL");
+    internalServlet.doDelete(request, response);
+    verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+    Parameters p1 = Parameters.getParameter("NODES");
+    Assert.assertEquals("{\"keyname\":\"NODES\",\"value\":\"dmaap-dr-node\"}", p1.asJSONObject().toString());
+    Assert.assertEquals("PARAM: keyname=NODES, value=dmaap-dr-node", p1.toString());
+  }
+
   @Test
   public void Given_Request_Is_HTTP_DELETE_With_Api_In_Endpoint_And_Delete_Fails_Then_Internal_Server_Error_Is_Generated()
       throws Exception {
@@ -330,8 +345,7 @@ public class InternalServletTest extends DrServletTestBase {
   }
 
   @Test
-  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated()
-      throws Exception {
+  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() {
     when(request.getHeader("Content-Type")).thenReturn("stub_contentType");
     when(request.getPathInfo()).thenReturn("/logs/");
     internalServlet.doPost(request, response);
@@ -339,8 +353,7 @@ public class InternalServletTest extends DrServletTestBase {
   }
 
   @Test
-  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Encoding_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated()
-      throws Exception {
+  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Encoding_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() {
     when(request.getHeader("Content-Encoding")).thenReturn("not-supported");
     when(request.getPathInfo()).thenReturn("/logs/");
     internalServlet.doPost(request, response);
@@ -362,8 +375,7 @@ public class InternalServletTest extends DrServletTestBase {
   }
 
   @Test
-  public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated()
-      throws Exception {
+  public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated() {
     when(request.getHeader("Content-Type")).thenReturn("stub_contentType");
     when(request.getPathInfo()).thenReturn("/drlogs/");
     internalServlet.doPost(request, response);
@@ -381,6 +393,13 @@ public class InternalServletTest extends DrServletTestBase {
     verify(response).setStatus(eq(HttpServletResponse.SC_OK));
   }
 
+  @Test
+  public void Given_Request_Is_HTTP_POST_To_Api_And_Request_Succeeds() {
+    when(request.getPathInfo()).thenReturn("/api/NEW_PARAM?val=blah");
+    internalServlet.doPost(request, response);
+    verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+  }
+
   @Test
   public void Given_Request_Is_HTTP_POST_With_Incorrect_Endpoint_Then_Not_Found_Error_Is_Generated()
       throws Exception {