import static org.junit.Assert.*;\r
\r
import static org.mockito.Matchers.anyString;\r
+import static org.mockito.Matchers.any;\r
import static org.mockito.Mockito.when;\r
\r
import java.io.IOException;\r
+import java.util.ConcurrentModificationException;\r
+\r
import javax.servlet.ServletOutputStream;\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
import org.powermock.modules.junit4.PowerMockRunner;\r
\r
import com.att.ajsc.beans.PropertiesMapBean;\r
-import com.att.nsa.cambria.CambriaApiException;\r
-import com.att.nsa.cambria.beans.DMaaPContext;\r
-import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;\r
-import com.att.nsa.cambria.beans.TopicBean;\r
-import com.att.nsa.cambria.constants.CambriaConstants;\r
-import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;\r
-import com.att.nsa.cambria.exception.DMaaPErrorMessages;\r
-import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;\r
-import com.att.nsa.cambria.metabroker.Topic;\r
-import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;\r
-import com.att.nsa.cambria.security.DMaaPAuthenticator;\r
-import com.att.nsa.cambria.service.TopicService;\r
-import com.att.nsa.cambria.utils.ConfigurationReader;\r
-import com.att.nsa.cambria.utils.DMaaPResponseBuilder;\r
+import org.onap.dmaap.dmf.mr.CambriaApiException;\r
+import org.onap.dmaap.dmf.mr.beans.DMaaPContext;\r
+import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;\r
+import org.onap.dmaap.dmf.mr.beans.TopicBean;\r
+import org.onap.dmaap.dmf.mr.constants.CambriaConstants;\r
+import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;\r
+import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;\r
+import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;\r
+import org.onap.dmaap.dmf.mr.metabroker.Topic;\r
+import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;\r
+import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;\r
+import org.onap.dmaap.dmf.mr.service.TopicService;\r
+import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;\r
+import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;\r
import com.att.nsa.configs.ConfigDbException;\r
import com.att.nsa.security.NsaAcl;\r
import com.att.nsa.security.NsaApiKey;\r
public class TopicRestServiceTest {\r
\r
@InjectMocks\r
- TopicRestService topicService;\r
+ TopicRestService topicRestService;\r
\r
@Mock\r
- private TopicService tService;\r
+ private TopicService topicService;\r
\r
private TopicRestService service = new TopicRestService();\r
@Mock\r
public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, JSONException, ConfigDbException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
\r
PowerMockito.mockStatic(PropertiesMapBean.class);\r
\r
\r
when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
\r
- topicService.getTopics();\r
+ topicRestService.getTopics();\r
}\r
\r
@Test\r
public void testGetTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, JSONException, ConfigDbException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
\r
PowerMockito.mockStatic(PropertiesMapBean.class);\r
\r
\r
when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
\r
- topicService.getTopics();\r
+ topicRestService.getTopics();\r
+ }\r
+\r
+ @Test\r
+ public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ PowerMockito.mockStatic(PropertiesMapBean.class);\r
+\r
+ assertTrue(true);\r
+ when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))\r
+ .thenReturn("namespace");\r
+\r
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(httpServReq.getHeader("Authorization")).thenReturn(null);\r
+\r
+ when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
+ String perms = "namespace" + "|" + "*" + "|" + "view";\r
+ when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);\r
+\r
+ when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).getTopics(any());\r
+ } catch (JSONException | ConfigDbException | IOException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.getTopics();\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test(expected = DMaaPAccessDeniedException.class)\r
public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, JSONException, ConfigDbException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
\r
PowerMockito.mockStatic(PropertiesMapBean.class);\r
\r
\r
when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
\r
- topicService.getAllTopics();\r
+ topicRestService.getAllTopics();\r
}\r
\r
@Test\r
public void testGetAllTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, JSONException, ConfigDbException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
PowerMockito.mockStatic(PropertiesMapBean.class);\r
\r
assertTrue(true);\r
\r
when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
\r
- topicService.getAllTopics();\r
+ topicRestService.getAllTopics();\r
+ }\r
+\r
+ @Test\r
+ public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
+ PowerMockito.mockStatic(PropertiesMapBean.class);\r
+\r
+ assertTrue(true);\r
+ when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))\r
+ .thenReturn("namespace");\r
+\r
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(httpServReq.getHeader("Authorization")).thenReturn(null);\r
+\r
+ when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
+\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).getAllTopics(any());\r
+ } catch (JSONException | ConfigDbException | IOException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.getAllTopics();\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test(expected = DMaaPAccessDeniedException.class)\r
public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, JSONException, ConfigDbException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
\r
PowerMockito.mockStatic(PropertiesMapBean.class);\r
\r
\r
when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
\r
- topicService.getTopic("topicName");\r
+ topicRestService.getTopic("topicName");\r
}\r
\r
@Test\r
public void testGetTopic_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, JSONException, ConfigDbException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
\r
PowerMockito.mockStatic(PropertiesMapBean.class);\r
\r
\r
when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
\r
- topicService.getTopic("topicName");\r
+ topicRestService.getTopic("topicName");\r
+ }\r
+\r
+ @Test\r
+ public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ PowerMockito.mockStatic(PropertiesMapBean.class);\r
+\r
+ assertTrue(true);\r
+ when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))\r
+ .thenReturn("enfTopicName");\r
+\r
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(httpServReq.getHeader("Authorization")).thenReturn(null);\r
+\r
+ when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
+\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).getTopic(any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.getTopic("topicName");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test\r
public void testCreateTopic()\r
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ topicRestService.createTopic(topicBean);\r
+ }\r
+\r
+ @Test\r
+ public void testCreateTopic_error() {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.createTopic(topicBean);\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).createTopic(any(), any());\r
+ } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.createTopic(topicBean);\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+\r
+ try {\r
+ PowerMockito.doThrow(new TopicExistsException("error")).when(topicService).createTopic(any(), any());\r
+ } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.createTopic(topicBean);\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+\r
+ try {\r
+ PowerMockito.doThrow(new AccessDeniedException()).when(topicService).createTopic(any(), any());\r
+ } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.createTopic(topicBean);\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test\r
public void testDeleteTopic()\r
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ topicRestService.deleteTopic("enfTopicNamePlusExtra");\r
+ }\r
+\r
+ @Test\r
+ public void testDeleteTopic_error()\r
+ throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.deleteTopic("enfTopicNamePlusExtra");\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).deleteTopic(any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.deleteTopic("enfTopicNamePlusExtra");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+\r
+ try {\r
+ PowerMockito.doThrow(new AccessDeniedException()).when(topicService).deleteTopic(any(),\r
+ any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.deleteTopic("enfTopicNamePlusExtra");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test\r
public void testGetPublishersByTopicName()\r
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");\r
+ }\r
+\r
+ @Test\r
+ public void testGetPublishersByTopicName_error() {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.getPublishersByTopicName("enfTopicNamePlusExtra");\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).getPublishersByTopicName(any(),\r
+ any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException e) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test\r
public void testPermitPublisherForTopic()\r
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ }\r
+\r
+ @Test\r
+ public void testPermitPublisherForTopic_error()\r
+ throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).permitPublisherForTopic(any(),\r
+ any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+\r
+ try {\r
+ PowerMockito.doThrow(new AccessDeniedException()).when(topicService).permitPublisherForTopic(any(),\r
+ any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test\r
public void testDenyPublisherForTopic()\r
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ }\r
+\r
+ @Test\r
+ public void testDenyPublisherForTopic_error()\r
+ throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).denyPublisherForTopic(any(),\r
+ any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+\r
+ try {\r
+ PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyPublisherForTopic(any(),\r
+ any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+\r
}\r
\r
@Test\r
public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, AccessDeniedException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.getConsumersByTopicName("enfTopicNamePlusExtra");\r
+ topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");\r
+ }\r
+\r
+ @Test\r
+ public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
+ TopicExistsException, AccessDeniedException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).getConsumersByTopicName(any(),\r
+ any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
@Test\r
public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, AccessDeniedException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+ }\r
+\r
+ @Test\r
+ public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
+ TopicExistsException, AccessDeniedException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).permitConsumerForTopic(any(),\r
+ any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,\r
+ IOException, TopicExistsException, AccessDeniedException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+ topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
}\r
\r
@Test\r
public void testDenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, AccessDeniedException {\r
\r
- Assert.assertNotNull(topicService);\r
+ Assert.assertNotNull(topicRestService);\r
+\r
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+ TopicBean topicBean = new TopicBean();\r
+ topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+ topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+ }\r
+\r
+ @Test\r
+ public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
+ TopicExistsException, AccessDeniedException {\r
+\r
+ Assert.assertNotNull(topicRestService);\r
\r
when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
TopicBean topicBean = new TopicBean();\r
topicBean.setTopicName("enfTopicNamePlusExtra");\r
\r
- topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+ try {\r
+ PowerMockito.doThrow(new IOException()).when(topicService).denyConsumerForTopic(any(),\r
+ any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
+\r
+ try {\r
+ PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyConsumerForTopic(any(),\r
+ any(), any());\r
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+ | DMaaPAccessDeniedException excp) {\r
+ assertTrue(false);\r
+ }\r
+\r
+ try {\r
+ topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+ } catch (CambriaApiException excp) {\r
+ assertTrue(true);\r
+ }\r
}\r
\r
}\r