summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorsawantmandar <ms5838@att.com>2019-03-14 13:18:15 -0500
committersawantmandar <ms5838@att.com>2019-03-14 13:18:35 -0500
commit107d91e51ada160bef2135b3fe356679167e1b3c (patch)
tree9568ec7279c70464509a75a0d0cf873dec39c0b0 /src/test
parentcca85abfb66e0c280eff5ed2c7570941c2ed423e (diff)
updating test cases for more coverage
Issue-ID: DMAAP-1097 Change-Id: I5973532bc53e814127d8439f3155c9fce869eee6 Signed-off-by: sawantmandar <ms5838@att.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/dmaap/service/AdminRestServiceTest.java52
-rw-r--r--src/test/java/org/onap/dmaap/service/EventsRestServiceTest.java18
-rw-r--r--src/test/java/org/onap/dmaap/util/ContentLengthInterceptorTest.java19
3 files changed, 61 insertions, 28 deletions
diff --git a/src/test/java/org/onap/dmaap/service/AdminRestServiceTest.java b/src/test/java/org/onap/dmaap/service/AdminRestServiceTest.java
index 0f99ff5..b766581 100644
--- a/src/test/java/org/onap/dmaap/service/AdminRestServiceTest.java
+++ b/src/test/java/org/onap/dmaap/service/AdminRestServiceTest.java
@@ -20,36 +20,34 @@
package org.onap.dmaap.service;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.any;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.dmaap.dmf.mr.CambriaApiException;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
+import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
+import org.onap.dmaap.dmf.mr.service.AdminService;
+import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
-
-import java.io.IOException;
-import java.util.Enumeration;
-import org.onap.dmaap.dmf.mr.service.AdminService;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
-import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
-import org.powermock.core.classloader.annotations.PrepareForTest;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ ServiceUtil.class })
@@ -145,9 +143,12 @@ public class AdminRestServiceTest {
@Test
public void testGetBlacklist() throws CambriaApiException, AccessDeniedException {
+ Vector headers = new Vector();
+ headers.add("Content-type");
+ Enumeration headerNms = headers.elements();
when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(httpServReq.getHeaderNames()).thenReturn(headerNames);
+ when(httpServReq.getHeaderNames()).thenReturn(headerNms);
when(headerNames.nextElement()).thenReturn("key");
when(httpServReq.getHeader("key")).thenReturn("value");
@@ -155,37 +156,32 @@ public class AdminRestServiceTest {
}
- //@Test
+ @Test
public void testGetBlacklist_error() throws CambriaApiException, AccessDeniedException,IOException {
- PowerMockito.mockStatic(ServiceUtil.class);
- PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaaPContext);
- PowerMockito.doThrow(new IOException("error")).when(adminService).getBlacklist(dmaaPContext);
+ PowerMockito.doThrow(new IOException("error")).when(adminService).getBlacklist(any(DMaaPContext.class));
when(dmaapContext.getRequest()).thenReturn(httpServReq);
when(httpServReq.getHeaderNames()).thenReturn(headerNames);
when(headerNames.nextElement()).thenReturn("key");
when(httpServReq.getHeader("key")).thenReturn("value");
- when(headerNames.hasMoreElements()).thenReturn(false);
+
try {
adminRestService.getBlacklist();
}
catch (CambriaApiException e) {
assertTrue(true);
}
-
}
- ////@Test
+ @Test
public void testGetBlacklist_error1() throws CambriaApiException, AccessDeniedException,IOException {
- PowerMockito.mockStatic(ServiceUtil.class);
- PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaaPContext);
- PowerMockito.doThrow(new AccessDeniedException("error")).when(adminService).getBlacklist(dmaaPContext);
+ PowerMockito.doThrow(new AccessDeniedException("error")).when(adminService).getBlacklist(any(DMaaPContext.class));
when(dmaapContext.getRequest()).thenReturn(httpServReq);
when(httpServReq.getHeaderNames()).thenReturn(headerNames);
when(headerNames.nextElement()).thenReturn("key");
when(httpServReq.getHeader("key")).thenReturn("value");
- when(headerNames.hasMoreElements()).thenReturn(false);
+
try {
adminRestService.getBlacklist();
}
diff --git a/src/test/java/org/onap/dmaap/service/EventsRestServiceTest.java b/src/test/java/org/onap/dmaap/service/EventsRestServiceTest.java
index 7f30cf4..f7e701a 100644
--- a/src/test/java/org/onap/dmaap/service/EventsRestServiceTest.java
+++ b/src/test/java/org/onap/dmaap/service/EventsRestServiceTest.java
@@ -257,6 +257,24 @@ public class EventsRestServiceTest {
}
@Test
+ public void testGetEventsToException() throws CambriaApiException {
+ try {
+ eventsRestRestService.getEventsToException("/topic");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGetEventsToExceptionWithConsumerGroup() throws CambriaApiException {
+ try {
+ eventsRestRestService.getEventsToException("/topic", "1234");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
public void testPushEvents_TopicExistException() throws CambriaApiException {
eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
diff --git a/src/test/java/org/onap/dmaap/util/ContentLengthInterceptorTest.java b/src/test/java/org/onap/dmaap/util/ContentLengthInterceptorTest.java
index 0608d2e..26c9305 100644
--- a/src/test/java/org/onap/dmaap/util/ContentLengthInterceptorTest.java
+++ b/src/test/java/org/onap/dmaap/util/ContentLengthInterceptorTest.java
@@ -70,6 +70,25 @@ public class ContentLengthInterceptorTest {
assertTrue(true);
}
+ @Test
+ public void testAllowOrRejectChunked() throws Exception {
+ PowerMockito.when(req.getHeader("Transfer-Encoding")).thenReturn("chunked");
+ PowerMockito.when(req.getHeader("Content-Length")).thenReturn("1027");
+ System.setProperty("maxcontentlength", "1024");
+
+ interceptor.allowOrReject(req, res, map);
+ assertTrue(true);
+ }
+
+ @Test
+ public void testAllowOrRejectNullTransferEncoding() throws Exception {
+ PowerMockito.when(req.getHeader("Transfer-Encoding")).thenReturn(null);
+ PowerMockito.when(req.getHeader("Content-Length")).thenReturn("1027");
+ System.setProperty("maxcontentlength", "1024");
+
+ interceptor.allowOrReject(req, res, map);
+ assertTrue(true);
+ }
//@Test(expected = NullPointerException.class)
public void testAllowOrRejectWithException() throws Exception {
PowerMockito.when(req.getHeader("Transfer-Encoding")).thenThrow(new NumberFormatException());