summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSunil Unnava <su622b@att.com>2018-03-06 19:38:54 -0500
committerSunil Unnava <su622b@att.com>2018-03-06 19:39:05 -0500
commit63548522dfacfdc11826facecf6d2a06a95f8295 (patch)
tree3015b87ada318e553fbf61904f74bbd72ec0a1fc /src/test
parentfbe26a20e749c3177f84cd05c67e757ac107b9a8 (diff)
testcases for code coverage
Issue-ID: DMAAP-271 Change-Id: Ifacdeeaca0176bf3a5e509cb0d27e7ec1e89bd8c Signed-off-by: Sunil Unnava <su622b@att.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/AdminRestServiceTest.java185
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java94
2 files changed, 277 insertions, 2 deletions
diff --git a/src/test/java/com/att/nsa/dmaap/service/AdminRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/AdminRestServiceTest.java
index d9b39dc..e9a14c7 100644
--- a/src/test/java/com/att/nsa/dmaap/service/AdminRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/AdminRestServiceTest.java
@@ -29,22 +29,32 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import com.att.nsa.cambria.CambriaApiException;
+
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
+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 com.att.nsa.cambria.beans.DMaaPContext;
+
+import java.io.IOException;
import java.util.Enumeration;
import com.att.nsa.cambria.service.AdminService;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
+import com.att.nsa.cambria.beans.DMaaPContext;
+import com.att.nsa.cambria.utils.ConfigurationReader;
+import org.powermock.core.classloader.annotations.PrepareForTest;
@RunWith(PowerMockRunner.class)
+@PrepareForTest({ ServiceUtil.class })
public class AdminRestServiceTest {
-
+
@InjectMocks
AdminRestService adminRestService;
@@ -56,13 +66,20 @@ public class AdminRestServiceTest {
@Mock
HttpServletRequest httpServReq;
+ @Mock
+ private HttpServletResponse response;
@Mock
Enumeration headerNames;
+ @Mock
+ private DMaaPContext dmaaPContext;
+ @Mock
+ private ConfigurationReader configReader;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+
}
@After
@@ -76,10 +93,55 @@ public class AdminRestServiceTest {
}
@Test
+ public void testGetConsumerCache_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).showConsumerCache(dmaaPContext);
+ try {
+ adminRestService.getConsumerCache();
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
public void testDropConsumerCache() throws CambriaApiException, AccessDeniedException {
adminRestService.dropConsumerCache();
}
+
+ @Test
+ public void testDropConsumerCach_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).dropConsumerCache(dmaaPContext);
+ try {
+ adminRestService.dropConsumerCache();
+ }
+ catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+
+ }
+ @Test
+ public void testDropConsumerCach_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).dropConsumerCache(dmaaPContext);
+ try {
+ adminRestService.dropConsumerCache();
+ }
+ catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+
+ }
@Test
public void testGetBlacklist() throws CambriaApiException, AccessDeniedException {
@@ -92,6 +154,46 @@ public class AdminRestServiceTest {
adminRestService.getBlacklist();
}
+
+ //@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);
+ 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
+ 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);
+ 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
public void testAddToBlacklist() throws CambriaApiException, AccessDeniedException {
@@ -103,11 +205,90 @@ public class AdminRestServiceTest {
}
@Test
- public void testRemoveFromBlacklist() throws CambriaApiException, AccessDeniedException, ConfigDbException {
+ public void testAddToBlacklist_error() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException {
+ PowerMockito.mockStatic(ServiceUtil.class);
+ PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaaPContext);
+ PowerMockito.doThrow(new AccessDeniedException("error")).when(adminService).addToBlacklist(dmaaPContext,"120.120.120.120");
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ try {
+ adminRestService.addToBlacklist("120.120.120.120");
+ }catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
+ public void testAddToBlacklist_error1() throws CambriaApiException, AccessDeniedException,IOException, ConfigDbException {
+
+ PowerMockito.mockStatic(ServiceUtil.class);
+ PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaaPContext);
+ PowerMockito.doThrow(new IOException("error")).when(adminService).addToBlacklist(dmaaPContext,"120.120.120.120");
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ try {
+ adminRestService.addToBlacklist("120.120.120.120");
+ }catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
+ public void testRemoveFromBlacklist() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException {
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+
+ adminRestService.removeFromBlacklist("120.120.120.120");
+
+ }
+
+ @Test
+ public void testRemoveFromBlacklist_error() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException{
+
+ PowerMockito.mockStatic(ServiceUtil.class);
+ PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaaPContext);
+ PowerMockito.doThrow(new IOException("error")).when(adminService).removeFromBlacklist(dmaaPContext,"120.120.120.120");
+
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ try {
+
+ adminRestService.removeFromBlacklist("120.120.120.120");
+ }catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+ catch (AccessDeniedException e) {
+ assertTrue(true);
+ }
+ catch (ConfigDbException e) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
+ public void testRemoveFromBlacklist_error1() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException {
+
+ PowerMockito.mockStatic(ServiceUtil.class);
+ PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaaPContext);
+ PowerMockito.doThrow(new AccessDeniedException("error")).when(adminService).removeFromBlacklist(dmaaPContext,"120.120.120.120");
+
when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ try {
adminRestService.removeFromBlacklist("120.120.120.120");
+ }catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+ catch (AccessDeniedException e) {
+ assertTrue(true);
+ }
+ catch (ConfigDbException e) {
+ assertTrue(true);
+ }
}
diff --git a/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
index d85ef9b..b25578c 100644
--- a/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
@@ -173,6 +173,63 @@ public class MMRestServiceTest {
assertTrue(true);
}
+ @Test
+ public void testCallCreateMirrorMaker_error4() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException {
+ prepareForTestCommon();
+
+ // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
+ // name:\"test\", consumer:\"test\", producer:\"test\",
+ // whitelist:\"test\",status:\"test\" }}";
+ String sampleJson = "{ messageID:\"test\", createMirrorMaker: { name:\"test@#\", consumer:\"test\", producer:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callCreateMirrorMaker(inputSteam);
+ assertTrue(true);
+
+ }
+ @Test
+ public void testCallCreateMirrorMaker_3() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException {
+ prepareForTestCommon();
+
+ // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
+ // name:\"test\", consumer:\"test\", producer:\"test\",
+ // whitelist:\"test\",status:\"test\" }}";
+ String sampleJson = "{ messageID:\"test\", createMirrorMaker: { name:\"\", consumer:\"test\", producer:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callCreateMirrorMaker(inputSteam);
+ assertTrue(true);
+
+ }
+ @Test
+ public void testCallCreateMirrorMaker_error2() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException {
+ prepareForTestCommon();
+
+ // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
+ // name:\"test\", consumer:\"test\", producer:\"test\",
+ // whitelist:\"test\",status:\"test\" }}";
+ String sampleJson = "{ messageID:\"test\", createMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\",whitelist:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callCreateMirrorMaker(inputSteam);
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testCallCreateMirrorMaker_error1() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException {
+ prepareForTestCommon();
+
+ // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
+ // name:\"test\", consumer:\"test\", producer:\"test\",
+ // whitelist:\"test\",status:\"test\" }}";
+ String sampleJson = "{ messageID:\"test\"}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callCreateMirrorMaker(inputSteam);
+ assertTrue(true);
+
+ }
@Test
public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
@@ -194,6 +251,43 @@ public class MMRestServiceTest {
mmRestService.callUpdateMirrorMaker(inputSteam);
assertTrue(true);
}
+
+ @Test
+ public void testCallUpdateMirrorMaker_error1() throws ConfigDbException, CambriaApiException {
+ prepareForTestCommon();
+
+ String sampleJson = "{ messageID:\"test@1\", updateMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callUpdateMirrorMaker(inputSteam);
+ assertTrue(true);
+ }
+ @Test
+ public void testCallUpdateMirrorMaker_error2() throws ConfigDbException, CambriaApiException {
+ prepareForTestCommon();
+
+ String sampleJson = "{ messageID:\"test\", updateMirrorMaker: { name:\"\", consumer:\"test\", producer:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callUpdateMirrorMaker(inputSteam);
+ assertTrue(true);
+ }
+ @Test
+ public void testCallUpdateMirrorMaker_error3() throws ConfigDbException, CambriaApiException {
+ prepareForTestCommon();
+
+ String sampleJson = "{ messageID:\"test\", updateMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callUpdateMirrorMaker(inputSteam);
+ assertTrue(true);
+ }
+ @Test
+ public void testCallUpdateMirrorMaker_error4() throws ConfigDbException, CambriaApiException {
+ prepareForTestCommon();
+
+ String sampleJson = "{ messageID:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callUpdateMirrorMaker(inputSteam);
+ assertTrue(true);
+ }
@Test
public void testCallDeleteMirrorMaker() throws ConfigDbException, CambriaApiException {