<scope>provided</scope>
</dependency>
- </dependencies>
+ </dependencies>
<profiles>
<!-- Use this profile to run the AJSC locally. This profile can be successfully
shutdown WITHIN eclipse even in a Windows environment. Debugging is also
package org.onap.dmaap.service;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doThrow;
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.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.dmaap.dmf.mr.CambriaApiException;
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.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({ ServiceUtil.class })
+@RunWith(MockitoJUnitRunner.class)
public class AdminRestServiceTest {
@InjectMocks
@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
- public void tearDown() throws Exception {
- }
@Test
public void testGetConsumerCache() throws CambriaApiException, AccessDeniedException {
}
- @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(expected=CambriaApiException.class)
+ public void testGetConsumerCache_IOException() throws CambriaApiException, AccessDeniedException, IOException {
+ doThrow(new IOException("error")).when(adminService).showConsumerCache(ArgumentMatchers.any(DMaaPContext.class));
+ adminRestService.getConsumerCache();
+ fail("Was expecting an exception to be thrown");
}
@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(expected=CambriaApiException.class)
+ public void testDropConsumerCach_IOException() throws CambriaApiException, AccessDeniedException ,IOException{
+ doThrow(new IOException("error")).when(adminService).dropConsumerCache(ArgumentMatchers.any(DMaaPContext.class));
+
+ adminRestService.dropConsumerCache();
+ fail("Was expecting an exception to be thrown");
}
- @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 {
+
+ @Test(expected=CambriaApiException.class)
+ public void testDropConsumerCache_AccessDeniedException() throws CambriaApiException, AccessDeniedException,IOException {
+ doThrow(new AccessDeniedException("error")).when(adminService).dropConsumerCache(ArgumentMatchers.any(DMaaPContext.class));
+
adminRestService.dropConsumerCache();
- }
- catch (CambriaApiException e) {
- assertTrue(true);
- }
-
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testDropConsumerCache_JSONException() throws CambriaApiException, AccessDeniedException,IOException {
+ doThrow(new JSONException("error")).when(adminService).dropConsumerCache(ArgumentMatchers.any(DMaaPContext.class));
+ adminRestService.dropConsumerCache();
+ fail("Was expecting an exception to be thrown");
}
@Test
- public void testGetBlacklist() throws CambriaApiException, AccessDeniedException {
+ public void testGetBlacklist() throws CambriaApiException {
Vector headers = new Vector();
headers.add("Content-type");
Enumeration headerNms = headers.elements();
-
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
when(httpServReq.getHeaderNames()).thenReturn(headerNms);
- when(headerNames.nextElement()).thenReturn("key");
- when(httpServReq.getHeader("key")).thenReturn("value");
adminRestService.getBlacklist();
-
}
-
- @Test
- public void testGetBlacklist_error() throws CambriaApiException, AccessDeniedException,IOException {
-
- PowerMockito.doThrow(new IOException("error")).when(adminService).getBlacklist(any(DMaaPContext.class));
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
+
+ @Test(expected=CambriaApiException.class)
+ public void testGetBlacklist_AccessDeniedException() throws CambriaApiException, AccessDeniedException, IOException {
+
when(httpServReq.getHeaderNames()).thenReturn(headerNames);
- when(headerNames.nextElement()).thenReturn("key");
- when(httpServReq.getHeader("key")).thenReturn("value");
+ doThrow(new AccessDeniedException("error")).when(adminService).getBlacklist(ArgumentMatchers.any(DMaaPContext.class));
- try {
adminRestService.getBlacklist();
- }
- catch (CambriaApiException e) {
- assertTrue(true);
- }
+ fail("Was expecting an exception to be thrown");
}
-
- @Test
- public void testGetBlacklist_error1() throws CambriaApiException, AccessDeniedException,IOException {
-
- PowerMockito.doThrow(new AccessDeniedException("error")).when(adminService).getBlacklist(any(DMaaPContext.class));
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
+
+ @Test(expected=CambriaApiException.class)
+ public void testGetBlacklist_IOException() throws CambriaApiException, AccessDeniedException,IOException {
when(httpServReq.getHeaderNames()).thenReturn(headerNames);
- when(headerNames.nextElement()).thenReturn("key");
- when(httpServReq.getHeader("key")).thenReturn("value");
+ doThrow(new IOException("error")).when(adminService).getBlacklist(ArgumentMatchers.any(DMaaPContext.class));
- try {
adminRestService.getBlacklist();
- }
- catch (CambriaApiException e) {
- assertTrue(true);
- }
-
+ fail("Was expecting an exception to be thrown");
}
@Test
public void testAddToBlacklist() throws CambriaApiException, AccessDeniedException {
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
adminRestService.addToBlacklist("120.120.120.120");
}
-
- @Test
- 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(expected=CambriaApiException.class)
+ public void testAddToBlacklist_IOException() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException {
+ doThrow(new IOException("error")).when(adminService).addToBlacklist(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+ adminRestService.addToBlacklist("120.120.120.120");
+ fail("Was expecting an exception to be thrown");
}
-
- @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 {
+
+ @Test(expected=CambriaApiException.class)
+ public void testAddToBlacklist_AccessDeniedException() throws CambriaApiException, AccessDeniedException,IOException, ConfigDbException {
+ doThrow(new AccessDeniedException("error")).when(adminService).addToBlacklist(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+
adminRestService.addToBlacklist("120.120.120.120");
- }catch (CambriaApiException e) {
- assertTrue(true);
- }
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testAddToBlacklist_ConfigDbException() throws CambriaApiException, AccessDeniedException,IOException, ConfigDbException {
+ doThrow(new ConfigDbException("error")).when(adminService).addToBlacklist(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+ adminRestService.addToBlacklist("120.120.120.120");
+ fail("Was expecting an exception to be thrown");
}
@Test
- public void testRemoveFromBlacklist() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException {
-
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ public void testRemoveFromBlacklist() throws CambriaApiException, AccessDeniedException, ConfigDbException {
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 {
+ @Test(expected=CambriaApiException.class)
+ public void testRemoveFromBlacklist_ConfigDbException() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException{
+ doThrow(new ConfigDbException("error")).when(adminService).removeFromBlacklist(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
adminRestService.removeFromBlacklist("120.120.120.120");
- }catch (CambriaApiException e) {
- assertTrue(true);
- }
- catch (AccessDeniedException e) {
- assertTrue(true);
- }
- catch (ConfigDbException e) {
- assertTrue(true);
- }
-
+ fail("Was expecting an exception to be thrown");
}
-
- @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 {
+ @Test(expected=CambriaApiException.class)
+ public void testRemoveFromBlacklist_IOException() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException{
+ doThrow(new IOException("error")).when(adminService).removeFromBlacklist(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
adminRestService.removeFromBlacklist("120.120.120.120");
- }catch (CambriaApiException e) {
- assertTrue(true);
- }
- catch (AccessDeniedException e) {
- assertTrue(true);
- }
- catch (ConfigDbException e) {
- assertTrue(true);
- }
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testRemoveFromBlacklist_AccessDeniedException() throws CambriaApiException, AccessDeniedException, ConfigDbException,IOException {
+ doThrow(new AccessDeniedException("error")).when(adminService).removeFromBlacklist(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+ adminRestService.removeFromBlacklist("120.120.120.120");
+ fail("Was expecting an exception to be thrown");
}
}
\ No newline at end of file
package org.onap.dmaap.service;
-import static org.junit.Assert.*;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doThrow;
-import org.onap.dmaap.dmf.mr.CambriaApiException;
-import org.onap.dmaap.dmf.mr.beans.ApiKeyBean;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
+import com.att.nsa.security.db.NsaApiDb.KeyExistsException;
+import java.io.IOException;
+import org.json.JSONException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.json.JSONException;
-
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-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.mockito.junit.MockitoJUnitRunner;
+import org.onap.dmaap.dmf.mr.CambriaApiException;
+import org.onap.dmaap.dmf.mr.beans.ApiKeyBean;
import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
-
-import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
import org.onap.dmaap.dmf.mr.service.ApiKeysService;
-import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.security.db.NsaApiDb.KeyExistsException;
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({ ServiceUtil.class })
+@RunWith(MockitoJUnitRunner.class)
public class ApiKeysRestServiceTest {
-
@InjectMocks
private ApiKeysRestService service;
@Mock
ApiKeysService apiKeyService;
- @Mock
- DMaaPContext dmaapContext;
-
- @Mock
- HttpServletRequest httpServReq;
- @Mock
- private HttpServletResponse response;
- @Mock
- private ConfigurationReader configReader;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
@Test
public void testGetAllApiKeys() {
-
try {
service.getAllApiKeys();
} catch (CambriaApiException e) {
}
- @Test
- public void testGetAllApiKeys_error() throws ConfigDbException, IOException {
- PowerMockito.mockStatic(ServiceUtil.class);
- PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaapContext);
- PowerMockito.doThrow(new IOException("error")).when(apiKeyService).getAllApiKeys(dmaapContext);
- try {
- service.getAllApiKeys();
- } catch (CambriaApiException e) {
- // TODO Auto-generated catch block
- assertTrue(true);
- } catch (NullPointerException e) {
- assertTrue(true);
- }
+ @Test(expected=CambriaApiException.class)
+ public void testGetAllApiKeys_IOException() throws ConfigDbException, IOException, CambriaApiException {
+ doThrow(new IOException("error")).when(apiKeyService).getAllApiKeys(ArgumentMatchers.any(DMaaPContext.class));
+ service.getAllApiKeys();
+ fail("Was expecting an exception to be thrown");
+ }
+ @Test(expected=CambriaApiException.class)
+ public void testGetAllApiKeys_ConfigDBException() throws ConfigDbException, IOException, CambriaApiException {
+ doThrow(new ConfigDbException("error")).when(apiKeyService).getAllApiKeys(ArgumentMatchers.any(DMaaPContext.class));
+ service.getAllApiKeys();
+ fail("Was expecting an exception to be thrown");
}
@Test
public void testGetApiKey() {
-
try {
service.getApiKey("apikeyName");
} catch (CambriaApiException e) {
} catch (NullPointerException e) {
assertTrue(true);
}
-
}
- @Test
- public void testGetApiKey_error() throws ConfigDbException, IOException {
- PowerMockito.mockStatic(ServiceUtil.class);
- PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaapContext);
- PowerMockito.doThrow(new IOException("error")).when(apiKeyService).getApiKey(dmaapContext, "apikeyName");
+ @Test(expected=CambriaApiException.class)
+ public void testGetApiKey_IOException() throws ConfigDbException, IOException, CambriaApiException {
+ String apikeyName = "apikeyName";
+ doThrow(new IOException("error")).when(apiKeyService).getApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
- try {
- service.getApiKey("apikeyName");
- } catch (CambriaApiException e) {
- // TODO Auto-generated catch block
- assertTrue(true);
- } catch (NullPointerException e) {
- assertTrue(true);
- }
+ service.getApiKey(apikeyName);
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testGetApiKey_ConfigDBException() throws ConfigDbException, IOException, CambriaApiException {
+ String apikeyName = "apikeyName";
+ doThrow(new ConfigDbException("error")).when(apiKeyService).getApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+ service.getApiKey(apikeyName);
+ fail("Was expecting an exception to be thrown");
}
@Test
public void testCreateApiKey() {
-
try {
service.createApiKey(new ApiKeyBean("hs647a@att.com", "test apikey"));
} catch (CambriaApiException e) {
} catch (NullPointerException e) {
assertTrue(true);
}
-
}
- @Test
- public void testCreateApiKey_error()
+ @Test(expected=CambriaApiException.class)
+ public void testCreateApiKey_ConfigDbException()
throws CambriaApiException, JSONException, KeyExistsException, ConfigDbException, IOException {
ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
- PowerMockito.mockStatic(ServiceUtil.class);
- PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaapContext);
- PowerMockito.doThrow(new IOException("error")).when(apiKeyService).createApiKey(dmaapContext, bean);
- try {
- service.createApiKey(bean);
- } catch (CambriaApiException e) {
- assertTrue(true);
- } catch (NullPointerException e) {
- assertTrue(true);
- }
+ doThrow(new ConfigDbException("error")).when(apiKeyService).createApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(ApiKeyBean.class));
+
+ service.createApiKey(bean);
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testCreateApiKey_IOException()
+ throws CambriaApiException, JSONException, KeyExistsException, ConfigDbException, IOException {
+ ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
+
+ doThrow(new IOException("error")).when(apiKeyService).createApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(ApiKeyBean.class));
+
+ service.createApiKey(bean);
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testCreateApiKey_KeyExistsException()
+ throws CambriaApiException, JSONException, KeyExistsException, ConfigDbException, IOException {
+
+ ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
+
+ doThrow(new KeyExistsException("error")).when(apiKeyService).createApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(ApiKeyBean.class));
+
+ service.createApiKey(bean);
+ fail("Was expecting an exception to be thrown");
}
@Test
public void testUpdateApiKey() {
-
try {
service.updateApiKey("apikeyName", new ApiKeyBean("hs647a@att.com", "test apikey"));
} catch (CambriaApiException e) {
} catch (NullPointerException e) {
assertTrue(true);
}
-
}
- @Test
- public void testUpdateApiKey_error() throws CambriaApiException, JSONException, KeyExistsException,
+ @Test(expected=CambriaApiException.class)
+ public void testUpdateApiKey_ConfigDbException() throws CambriaApiException, JSONException,
ConfigDbException, IOException, AccessDeniedException {
ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
- PowerMockito.mockStatic(ServiceUtil.class);
- PowerMockito.when(ServiceUtil.getDMaaPContext(configReader, httpServReq, response)).thenReturn(dmaapContext);
- PowerMockito.doThrow(new IOException("error")).when(apiKeyService).updateApiKey(dmaapContext, "apikeyName",
- bean);
- try {
- service.updateApiKey("apikeyName", bean);
- } catch (CambriaApiException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- assertTrue(true);
- }
+ doThrow(new ConfigDbException("error")).when(apiKeyService).updateApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(ApiKeyBean.class));
+
+ service.updateApiKey("apikeyName", bean);
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testUpdateApiKey_IOException() throws CambriaApiException, JSONException,
+ ConfigDbException, IOException, AccessDeniedException {
+
+ ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
+ doThrow(new IOException("error")).when(apiKeyService).updateApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(ApiKeyBean.class));
+
+ service.updateApiKey("apikeyName", bean);
+ fail("Was expecting an exception to be thrown");
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testUpdateApiKey_AccessDeniedException() throws CambriaApiException, JSONException,
+ ConfigDbException, IOException, AccessDeniedException {
+
+ ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
+ doThrow(new AccessDeniedException("error")).when(apiKeyService).updateApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(ApiKeyBean.class));
+ service.updateApiKey("apikeyName", bean);
+ fail("Was expecting an exception to be thrown");
}
@Test
} catch (NullPointerException e) {
assertTrue(true);
}
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testDeleteApiKey_AccessDeniedException() throws CambriaApiException, JSONException,
+ ConfigDbException, IOException, AccessDeniedException {
+
+ ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
+ doThrow(new AccessDeniedException("error")).when(apiKeyService).deleteApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+
+ service.deleteApiKey("apikeyName");
+ fail("Was expecting an exception to be thrown");
+ }
+ @Test(expected=CambriaApiException.class)
+ public void testDeleteApiKey_IOException() throws CambriaApiException, JSONException,
+ ConfigDbException, IOException, AccessDeniedException {
+
+ ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
+ doThrow(new IOException("error")).when(apiKeyService).deleteApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+
+ service.deleteApiKey("apikeyName");
+ fail("Was expecting an exception to be thrown");
}
+ @Test(expected=CambriaApiException.class)
+ public void testDeleteApiKey_ConfigDbException() throws CambriaApiException, JSONException,
+ ConfigDbException, IOException, AccessDeniedException {
+
+ ApiKeyBean bean = new ApiKeyBean("test@onap.com", "test apikey");
+ doThrow(new ConfigDbException("error")).when(apiKeyService).deleteApiKey(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+
+ service.deleteApiKey("apikeyName");
+ fail("Was expecting an exception to be thrown");
+ }
}
\ No newline at end of file
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
package org.onap.dmaap.service;
-import java.util.Date;
-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.Mockito;
-import org.mockito.MockitoAnnotations;
import static org.mockito.Matchers.any;
-
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.api.mockito.PowerMockito;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
-import com.att.ajsc.beans.PropertiesMapBean;
-import org.onap.dmaap.dmf.mr.CambriaApiException;
-import org.onap.dmaap.dmf.mr.backends.ConsumerFactory.UnavailableException;
-import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
-import org.onap.dmaap.dmf.mr.service.EventsService;
import com.att.nsa.configs.ConfigDbException;
-import org.onap.dmaap.dmf.mr.utils.Utils;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-
-import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.io.InputStream;
-import java.util.Date;
-
import javax.servlet.ServletInputStream;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
-
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.dmaap.dmf.mr.CambriaApiException;
+import org.onap.dmaap.dmf.mr.backends.ConsumerFactory.UnavailableException;
import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
+import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
import org.onap.dmaap.dmf.mr.exception.ErrorResponse;
import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
+import org.onap.dmaap.dmf.mr.service.EventsService;
+import org.springframework.test.context.ContextConfiguration;
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({ PropertiesMapBean.class })
+@RunWith(MockitoJUnitRunner.class)
+@ContextConfiguration
public class EventsRestServiceTest {
@InjectMocks
- EventsRestService eventsRestRestService;
+ EventsRestService eventsRestService;
@Mock
private EventsService eventsService;
@Mock
ErrorResponse errorResponse;
- @Mock
- DMaaPContext dmaapContext;
-
@Mock
InputStream iStream;
HttpServletRequest request;
@Mock
- private DMaaPErrorMessages errorMessages;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
- @After
- public void tearDown() throws Exception {
- }
+ DMaaPErrorMessages errorMessages;
@Test
public void testGetEvents() throws CambriaApiException {
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
-
- }
-
- @Test
- public void testGetEvents_error() {
-
- try {
- PowerMockito.doThrow(new IOException()).when(eventsService).getEvents(any(), any(),
- any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | UnavailableException | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
-
- try {
- PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).getEvents(any(), any(),
- any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | UnavailableException | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
-
- try {
- PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).getEvents(any(),
- any(), any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | UnavailableException | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
+ eventsRestService.getEvents("topicName", "consumergroup", "consumerid");
}
- @Test(expected = TopicExistsException.class)
+ @Test(expected = CambriaApiException.class)
public void testGetEvents_TopicExistException() throws CambriaApiException, ConfigDbException, TopicExistsException,
UnavailableException, IOException, AccessDeniedException {
- Mockito.doThrow(new TopicExistsException("topic exists")).when(eventsService).getEvents(any(),
+ doThrow(new TopicExistsException("topic exists")).when(eventsService).getEvents(any(),
any(), any(), any());
- eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
-
+ eventsRestService.getEvents("topicName", "consumergroup", "consumerid");
}
- @Test(expected = DMaaPAccessDeniedException.class)
+ @Test(expected = CambriaApiException.class)
public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException,
TopicExistsException, UnavailableException, IOException, AccessDeniedException {
- Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(any(),
+ doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(any(),
any(), any(), any());
- eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
+ eventsRestService.getEvents("topicName", "consumergroup", "consumerid");
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetEvents_AccessDeniedException() throws CambriaApiException,
+ ConfigDbException, TopicExistsException, UnavailableException, IOException, AccessDeniedException {
+ doThrow(new ConfigDbException("error")).when(eventsService).getEvents( ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+
+ eventsRestService.getEvents("topicName", "consumergroup", "consumerid");
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetEvents_ConfigDbException() throws CambriaApiException,
+ ConfigDbException, TopicExistsException, UnavailableException, IOException, AccessDeniedException {
+ doThrow(new ConfigDbException("error")).when(eventsService).getEvents( ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+
+ eventsRestService.getEvents("topicName", "consumergroup", "consumerid");
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetEvents_UnavailableException() throws CambriaApiException,
+ ConfigDbException, TopicExistsException, UnavailableException, IOException, AccessDeniedException {
+ doThrow(new ConfigDbException("error")).when(eventsService).getEvents( ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+
+ eventsRestService.getEvents("topicName", "consumergroup", "consumerid");
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetEvents_IOException() throws CambriaApiException,
+ ConfigDbException, TopicExistsException, UnavailableException, IOException, AccessDeniedException {
+ doThrow(new ConfigDbException("error")).when(eventsService).getEvents( ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+ eventsRestService.getEvents("topicName", "consumergroup", "consumerid");
}
- /*
- * @Test(expected = DMaaPAccessDeniedException.class) public void
- * testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException,
- * ConfigDbException, TopicExistsException, UnavailableException,
- * IOException, AccessDeniedException {
- *
- * Mockito.doThrow(new
- * DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(
- * dmaapContext, "topicName", "consumergroup", "consumerid");
- *
- * eventsService.getEvents(dmaapContext, "topicName", "consumergroup",
- * "consumerid");
- *
- * }
- */
@Test
public void testPushEvents() throws CambriaApiException {
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
+ eventsRestService.pushEvents("topicName", iStream, "partitionKey");
}
- @Test
- public void testPushEvents_error() {
-
- try {
- PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(any(), any(), any(),
- any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | missingReqdSetting | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
-
- try {
- PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(any(), any(),
- any(), any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | missingReqdSetting | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
-
- try {
- PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(any(),
- any(), any(), any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | missingReqdSetting | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
+ @Test(expected = CambriaApiException.class)
+ public void testPushEvents_TopicExistsException()
+ throws AccessDeniedException, CambriaApiException, IOException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.isNull());
+
+ eventsRestService.pushEvents("topicName", iStream, "partitionKey");
}
- @Test
+ @Test(expected = CambriaApiException.class)
+ public void testPushEvents_DMaaPAccessDeniedException()
+ throws AccessDeniedException, CambriaApiException, IOException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.isNull());
+
+ eventsRestService.pushEvents("topicName", iStream, "partitionKey");
+
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testPushEvents_ConfigDbException()
+ throws AccessDeniedException, CambriaApiException, IOException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ doThrow(new ConfigDbException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.isNull());
+
+ eventsRestService.pushEvents("topicName", iStream, "partitionKey");
+
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testPushEvents_IOException()
+ throws AccessDeniedException, CambriaApiException, IOException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ doThrow(new IOException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.isNull());
+
+ eventsRestService.pushEvents("topicName", iStream, "partitionKey");
+
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testPushEvents_missingReqdSetting()
+ throws AccessDeniedException, CambriaApiException, IOException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ doThrow(new missingReqdSetting("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.isNull());
+
+ eventsRestService.pushEvents("topicName", iStream, "partitionKey");
+
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testPushEvents_AccessDeniedException()
+ throws AccessDeniedException, CambriaApiException, IOException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ doThrow(new AccessDeniedException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.isNull());
+
+ eventsRestService.pushEvents("topicName", iStream, "partitionKey");
+
+ }
+
+ @Test(expected = CambriaApiException.class)
public void testGetEventsToException() throws CambriaApiException {
- try {
- eventsRestRestService.getEventsToException("/topic");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
+
+ eventsRestService.getEventsToException("/topic");
}
-
- @Test
+
+ @Test(expected = CambriaApiException.class)
public void testGetEventsToExceptionWithConsumerGroup() throws CambriaApiException {
- try {
- eventsRestRestService.getEventsToException("/topic", "1234");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
+ eventsRestService.getEventsToException("/topic", "1234");
}
-
+
@Test
- public void testPushEvents_TopicExistException() throws CambriaApiException {
+ public void testPushEventsWithTransaction() throws CambriaApiException, IOException {
+ when(request.getInputStream()).thenReturn(servletInputStream);
+ eventsRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ }
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWithTransaction_TopicExistsException()
+ throws IOException, CambriaApiException, AccessDeniedException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ when(request.getInputStream()).thenReturn(servletInputStream);
+ doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+ eventsRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ }
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWithTransaction_AccessDeniedException()
+ throws IOException, CambriaApiException, AccessDeniedException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ when(request.getInputStream()).thenReturn(servletInputStream);
+ doThrow(new AccessDeniedException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+ eventsRestService.pushEventsWithTransaction("topicName", "partitionKey");
}
- @Test
- public void tesTPushEventsWithTransaction() throws CambriaApiException, IOException {
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWithTransaction_DMaaPAccessDeniedException()
+ throws IOException, CambriaApiException, AccessDeniedException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
when(request.getInputStream()).thenReturn(servletInputStream);
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+ eventsRestService.pushEventsWithTransaction("topicName", "partitionKey");
}
- @Test
- public void tesTPushEventsWithTransaction_error() throws IOException {
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWithTransaction_missingReqdSetting()
+ throws IOException, CambriaApiException, AccessDeniedException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ when(request.getInputStream()).thenReturn(servletInputStream);
+ doThrow(new missingReqdSetting("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+
+ eventsRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWithTransaction_IOException()
+ throws IOException, CambriaApiException, AccessDeniedException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
when(request.getInputStream()).thenReturn(servletInputStream);
- ServletInputStream stream = request.getInputStream();
-
- try {
- PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(any(),
- any(), any(), any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | missingReqdSetting | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
-
- try {
- PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(any(),any(),
- any(), any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | missingReqdSetting | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
-
- try {
- PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(any(), any(), any(),
- any(), any());
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
- | missingReqdSetting | IOException excp) {
- assertTrue(false);
- } catch (CambriaApiException e) {
- assertTrue(false);
- }
-
- try {
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
- } catch (CambriaApiException e) {
- assertTrue(true);
- }
+ doThrow(new IOException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+ eventsRestService.pushEventsWithTransaction("topicName", "partitionKey");
}
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWithTransaction_ConfigDbException()
+ throws IOException, CambriaApiException, AccessDeniedException, TopicExistsException, ConfigDbException,
+ missingReqdSetting {
+ when(request.getInputStream()).thenReturn(servletInputStream);
+ doThrow(new ConfigDbException("error")).when(eventsService).pushEvents(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(InputStream.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class));
+
+ eventsRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ }
}
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
+import com.att.ajsc.beans.PropertiesMapBean;
+import com.att.ajsc.filemonitor.AJSCPropertiesMap;
+import com.att.nsa.configs.ConfigDbException;
+import com.att.nsa.security.NsaAcl;
+import com.att.nsa.security.NsaApiKey;
+import com.att.nsa.security.db.simple.NsaSimpleApiKey;
import java.io.ByteArrayInputStream;
-
-//import static org.mockito.Matchers.anyString;
-//import static org.mockito.Mockito.when;
-
-import java.io.IOException;
import java.io.InputStream;
-
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
-import org.onap.dmaap.dmf.mr.CambriaApiException;
-import org.onap.dmaap.dmf.mr.backends.ConsumerFactory.UnavailableException;
import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
-import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
import org.onap.dmaap.dmf.mr.metabroker.Topic;
import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticatorImpl;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import com.att.ajsc.beans.PropertiesMapBean;
-import com.att.ajsc.filemonitor.AJSCPropertiesMap;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.security.NsaAcl;
-import com.att.nsa.security.NsaApiKey;
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-
//@RunWith(MockitoJUnitRunner.class)
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("jdk.internal.reflect.*")
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
try {
prepareForTestCommon();
} catch (Exception e) {
-
+
}
// String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCallCreateMirrorMaker_error1() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCallListAllMirrorMaker() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCallUpdateMirrorMaker() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCallUpdateMirrorMaker_error1() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
public void testCallUpdateMirrorMaker_error2() {
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
public void testCallUpdateMirrorMaker_error3() {
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
public void testCallUpdateMirrorMaker_error4() {
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
.thenReturn(null);
-
+
String sampleJson = "{ messageID:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
try {
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCallDeleteMirrorMaker() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCallDeleteMirrorMakerAafPermissionError() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
-
+
+
@Test
public void testListWhiteList() {
prepareForTestCommon();
String sampleJson = "{ name:\"test\", namespace:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
- String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
+ String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
try {
PowerMockito.when(mmservice.subscribe(any(), anyString(), anyString(), anyString())).thenReturn(msgSubscribe);
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
String sampleJson = "{ name:\"test\", namespace:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
- String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
+ String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
try {
PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
String sampleJson = "{ name:\"test\", namespace:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
- String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
+ String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
try {
PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
public void testListWhiteListJSONError() {
String sampleJson = "{ namespace:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
- String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
+ String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
try {
mmRestService.listWhiteList(inputSteam);
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
-
-
-
+
+
+
+
@Test
public void testCreateWhiteList() {
prepareForTestCommon();
-
+
String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
PowerMockito
.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))
.thenReturn(null);
-
+
String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCreateWhiteListAafPermissionError() {
prepareForTestCommon();
PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
.thenReturn(null);
-
+
String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
} catch (Exception e) {
assertTrue(true);
}
-
- }
-
+
+ }
+
@Test
public void testCreateWhiteListJSONError() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
- }
-
+
+ }
+
@Test
public void testDeleteWhiteList() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
@Test
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testDeleteWhiteListMirrorMakerAafPermissionError() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
-
+
+
@Test
public void testDeleteWhiteListJsonError() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
- }
-
+
+ }
+
@Test
public void testDeleteWhiteListJsonFormattingError() {
prepareForTestCommon();
} catch (Exception e) {
assertTrue(true);
}
-
+
}
-
+
@Test
public void testCallPubSubForWhitelist() {
prepareForTestCommon();
-
+
String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
- String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
+ String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
try {
PowerMockito.when(mmservice.subscribe(any(), anyString(), anyString(), anyString())).thenReturn(msgSubscribe);
assertTrue(true);
}
}
-
+
@Test
public void testCallPubSub() {
prepareForTestCommon();
-
+
String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
- String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
+ String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
try {
PowerMockito.when(mmservice.subscribe(any(), anyString(), anyString(), anyString())).thenReturn(msgSubscribe);
assertTrue(true);
}
}
-
+
@Test
public void testCallPubSubForWhitelistNoMsgFromSubscribe() {
prepareForTestCommon();
-
+
String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
try {
@Test
public void testGetListMirrorMaker() {
prepareForTestCommon();
-
- String sampleJson = "[{ messageID:\"test123\", listMirrorMaker:[\"test\"]}]";
+
+ String sampleJson = "[{ messageID:\"test123\", listMirrorMaker:[\"test\"]}]";
try {
mmRestService.getListMirrorMaker(sampleJson, "test123");
} catch (Exception e) {
assertTrue(true);
- }
+ }
}
-
+
private void prepareForTestCommon() {
Assert.assertNotNull(mmRestService);
try {
PowerMockito.when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
} catch (ConfigDbException e) {
-
+
}
}
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
package org.onap.dmaap.service;
-import org.junit.After;
-import org.junit.Before;
+import static org.mockito.Mockito.doThrow;
+
+import java.io.IOException;
+
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import com.att.ajsc.beans.PropertiesMapBean;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
import org.onap.dmaap.dmf.mr.CambriaApiException;
import org.onap.dmaap.dmf.mr.service.MetricsService;
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({ PropertiesMapBean.class })
+@RunWith(MockitoJUnitRunner.class)
public class MetricsRestServiceTest {
@InjectMocks
@Mock
private MetricsService metricsService;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
- @After
- public void tearDown() throws Exception {
- }
@Test
public void testGetMetrics() throws CambriaApiException {
metricsRestService.getMetrics();
}
-
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetMetrics_IOException() throws CambriaApiException, IOException {
+ doThrow(new IOException("error")).when(metricsService).get(ArgumentMatchers.any(DMaaPContext.class));
+ metricsRestService.getMetrics();
+ }
+
+
@Test
public void testGetMetricsByName() throws CambriaApiException {
metricsRestService.getMetricsByName("metricsName");
-
}
-
+ @Test(expected = CambriaApiException.class)
+ public void testGetMetricsByName_IOException() throws CambriaApiException, IOException {
+ doThrow(new IOException("error")).when(metricsService).getMetricByName(ArgumentMatchers.any(DMaaPContext.class), ArgumentMatchers.any(String.class));
+ metricsRestService.getMetricsByName("metricsName");
+ }
}
\ No newline at end of file
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
package org.onap.dmaap.service;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import com.att.aft.dme2.internal.jettison.json.JSONException;
+import com.att.ajsc.beans.PropertiesMapBean;
+import com.att.nsa.configs.ConfigDbException;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import com.att.ajsc.beans.PropertiesMapBean;
import org.onap.dmaap.dmf.mr.CambriaApiException;
import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
-import org.onap.dmaap.dmf.mr.service.EventsService;
import org.onap.dmaap.dmf.mr.service.TransactionService;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-import com.att.aft.dme2.internal.jettison.json.JSONException;
import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("jdk.internal.reflect.*")