aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/test/java/org/onap
diff options
context:
space:
mode:
authoreconwar <conor.ward@ericsson.com>2018-08-30 06:53:01 +0000
committereconwar <conor.ward@ericsson.com>2018-08-30 06:53:01 +0000
commit5fc125c5159ae84e211ff2d8b03cd43475493142 (patch)
tree1028da46c28718fa338552a2f18ce0ac1fadfe01 /datarouter-prov/src/test/java/org/onap
parent49be863f0005d80724a99acf13f31c4e03c5be68 (diff)
Add Tests to InternalServletTest
Change-Id: I836844b6b1f8779c5fb631fcf6593b798a09b599 Signed-off-by: Conor Ward <conor.ward@ericsson.com> Issue-ID: DMAAP-101
Diffstat (limited to 'datarouter-prov/src/test/java/org/onap')
-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);
+ }
}