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;
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.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
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);
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 {
}
@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);
}
@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);
}
@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);
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 {