aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRam Koya <rk541m@att.com>2018-08-30 16:02:47 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-30 16:02:47 +0000
commitbdeb5f44dc6811518884228c2ae4397a9323c9f4 (patch)
tree7521c948eeddbfc0ccb80a8362f7c49dca71b501
parentb2dc1f263aaa57453775800a8ec082c024cf868c (diff)
parent5fc125c5159ae84e211ff2d8b03cd43475493142 (diff)
Merge "Add Tests to InternalServletTest"
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java4
-rw-r--r--[-rwxr-xr-x]datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java41
2 files changed, 39 insertions, 6 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
index 414fc185..c7f639ed 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
@@ -38,8 +38,8 @@ public class DrServletTestBase {
public void setUp() throws Exception {
Properties props = new Properties();
props.setProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false");
- props.setProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir", "datarouter-prov/unit-test-logs");
- props.setProperty("org.onap.dmaap.datarouter.provserver.spooldir", "resources/spooldir");
+ props.setProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir", "unit-test-logs");
+ props.setProperty("org.onap.dmaap.datarouter.provserver.spooldir", "unit-test-logs/spool");
props.setProperty("org.onap.dmaap.datarouter.provserver.https.relaxation", "false");
FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true);
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true);
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
index 97900d4d..5f6b7ae3 100755..100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
+import java.io.File;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
@@ -154,6 +155,19 @@ public class InternalServletTest extends DrServletTestBase {
}
@Test
+ 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 testFile = new File("unit-test-logs/testFile.txt");
+ testFile.createNewFile();
+ testFile.deleteOnExit();
+ ServletOutputStream outStream = mock(ServletOutputStream.class);
+ when(response.getOutputStream()).thenReturn(outStream);
+ internalServlet.doGet(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ }
+
+ @Test
public void Given_Request_Is_HTTP_GET_With_Api_In_Endpoint_Request_Succeeds() throws Exception {
when(request.getPathInfo()).thenReturn("/api/Key");
setParametersToNotContactDb(false);
@@ -167,10 +181,7 @@ public class InternalServletTest extends DrServletTestBase {
public void Given_Request_Is_HTTP_GET_With_Drlogs_In_Endpoint_Request_Succeeds()
throws Exception {
when(request.getPathInfo()).thenReturn("/drlogs/");
- PowerMockito.mockStatic(LogfileLoader.class);
- LogfileLoader logfileLoader = mock(LogfileLoader.class);
- when(logfileLoader.getBitSet()).thenReturn(new RLEBitSet());
- PowerMockito.when(LogfileLoader.getLoader()).thenReturn(logfileLoader);
+ mockLogfileLoader();
ServletOutputStream outStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outStream);
internalServlet.doGet(request, response);
@@ -332,6 +343,21 @@ public class InternalServletTest extends DrServletTestBase {
}
@Test
+ public void Given_Request_Is_HTTP_POST_To_Logs_Then_Request_Succeeds()
+ throws Exception {
+ when(request.getHeader("Content-Encoding")).thenReturn("gzip");
+ when(request.getPathInfo()).thenReturn("/logs/");
+ ServletInputStream inStream = mock(ServletInputStream.class);
+ when(request.getInputStream()).thenReturn(inStream);
+ File testDir = new File("unit-test-logs/spool");
+ testDir.mkdirs();
+ testDir.deleteOnExit();
+ mockLogfileLoader();
+ internalServlet.doPost(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_CREATED));
+ }
+
+ @Test
public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated()
throws Exception {
when(request.getHeader("Content-Type")).thenReturn("stub_contentType");
@@ -452,4 +478,11 @@ public class InternalServletTest extends DrServletTestBase {
Map<String, Integer> map = new HashMap<>();
FieldUtils.writeDeclaredStaticField(NodeClass.class, "map", map, true);
}
+
+ private void mockLogfileLoader() {
+ PowerMockito.mockStatic(LogfileLoader.class);
+ LogfileLoader logfileLoader = mock(LogfileLoader.class);
+ when(logfileLoader.getBitSet()).thenReturn(new RLEBitSet());
+ PowerMockito.when(LogfileLoader.getLoader()).thenReturn(logfileLoader);
+ }
}