-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP Policy Engine\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-package com.att.nsa.dmaap.service;\r
-\r
-import java.util.Date;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-import org.junit.runner.RunWith;\r
-import org.mockito.InjectMocks;\r
-import org.mockito.Mock;\r
-import org.mockito.Mockito;\r
-import org.mockito.MockitoAnnotations;\r
-import static org.mockito.Matchers.any;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import static org.mockito.Mockito.when;\r
-\r
-import com.att.ajsc.beans.PropertiesMapBean;\r
-import org.onap.dmaap.dmf.mr.CambriaApiException;\r
-import org.onap.dmaap.dmf.mr.backends.ConsumerFactory.UnavailableException;\r
-import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;\r
-import org.onap.dmaap.dmf.mr.service.EventsService;\r
-import com.att.nsa.configs.ConfigDbException;\r
-import org.onap.dmaap.dmf.mr.utils.Utils;\r
-import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;\r
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
-\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.util.Date;\r
-\r
-import javax.servlet.ServletInputStream;\r
-import javax.servlet.ServletOutputStream;\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.onap.dmaap.dmf.mr.beans.DMaaPContext;\r
-import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;\r
-import org.onap.dmaap.dmf.mr.exception.ErrorResponse;\r
-import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;\r
-\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({ PropertiesMapBean.class })\r
-public class EventsRestServiceTest {\r
-\r
- @InjectMocks\r
- EventsRestService eventsRestRestService;\r
-\r
- @Mock\r
- private EventsService eventsService;\r
-\r
- @Mock\r
- ErrorResponse errorResponse;\r
-\r
- @Mock\r
- DMaaPContext dmaapContext;\r
-\r
- @Mock\r
- InputStream iStream;\r
-\r
- @Mock\r
- ServletInputStream servletInputStream;\r
-\r
- @Mock\r
- HttpServletRequest request;\r
-\r
- @Mock\r
- private DMaaPErrorMessages errorMessages;\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- MockitoAnnotations.initMocks(this);\r
- }\r
-\r
- @After\r
- public void tearDown() throws Exception {\r
- }\r
-\r
- @Test\r
- public void testGetEvents() throws CambriaApiException {\r
-\r
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
-\r
- }\r
-\r
- @Test\r
- public void testGetEvents_error() {\r
-\r
- try {\r
- PowerMockito.doThrow(new IOException()).when(eventsService).getEvents(any(), any(),\r
- any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | UnavailableException | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- try {\r
- PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).getEvents(any(), any(),\r
- any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | UnavailableException | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- try {\r
- PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).getEvents(any(),\r
- any(), any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | UnavailableException | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- }\r
-\r
- @Test(expected = TopicExistsException.class)\r
- public void testGetEvents_TopicExistException() throws CambriaApiException, ConfigDbException, TopicExistsException,\r
- UnavailableException, IOException, AccessDeniedException {\r
-\r
- Mockito.doThrow(new TopicExistsException("topic exists")).when(eventsService).getEvents(any(),\r
- any(), any(), any());\r
-\r
- eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
-\r
- }\r
-\r
- @Test(expected = DMaaPAccessDeniedException.class)\r
- public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException,\r
- TopicExistsException, UnavailableException, IOException, AccessDeniedException {\r
-\r
- Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(any(),\r
- any(), any(), any());\r
-\r
- eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
-\r
- }\r
-\r
- /*\r
- * @Test(expected = DMaaPAccessDeniedException.class) public void\r
- * testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException,\r
- * ConfigDbException, TopicExistsException, UnavailableException,\r
- * IOException, AccessDeniedException {\r
- * \r
- * Mockito.doThrow(new\r
- * DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(\r
- * dmaapContext, "topicName", "consumergroup", "consumerid");\r
- * \r
- * eventsService.getEvents(dmaapContext, "topicName", "consumergroup",\r
- * "consumerid");\r
- * \r
- * }\r
- */\r
-\r
- @Test\r
- public void testPushEvents() throws CambriaApiException {\r
-\r
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
-\r
- }\r
-\r
- @Test\r
- public void testPushEvents_error() {\r
-\r
- try {\r
- PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(any(), any(), any(),\r
- any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | missingReqdSetting | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- try {\r
- PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(any(), any(),\r
- any(), any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | missingReqdSetting | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- try {\r
- PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(any(),\r
- any(), any(), any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | missingReqdSetting | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- }\r
-\r
- @Test\r
- public void testPushEvents_TopicExistException() throws CambriaApiException {\r
-\r
- eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
-\r
- }\r
-\r
- @Test\r
- public void tesTPushEventsWithTransaction() throws CambriaApiException, IOException {\r
- when(request.getInputStream()).thenReturn(servletInputStream);\r
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
-\r
- }\r
-\r
- @Test\r
- public void tesTPushEventsWithTransaction_error() throws IOException {\r
- when(request.getInputStream()).thenReturn(servletInputStream);\r
- ServletInputStream stream = request.getInputStream();\r
-\r
- try {\r
- PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(any(),\r
- any(), any(), any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | missingReqdSetting | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- try {\r
- PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(any(),any(),\r
- any(), any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | missingReqdSetting | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- try {\r
- PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(any(), any(), any(),\r
- any(), any());\r
- } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
- | missingReqdSetting | IOException excp) {\r
- assertTrue(false);\r
- } catch (CambriaApiException e) {\r
- assertTrue(false);\r
- }\r
-\r
- try {\r
- eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
- } catch (CambriaApiException e) {\r
- assertTrue(true);\r
- }\r
-\r
- }\r
-\r
-}\r
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+ 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.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.api.mockito.PowerMockito;
+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.onap.dmaap.dmf.mr.beans.DMaaPContext;
+import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
+import org.onap.dmaap.dmf.mr.exception.ErrorResponse;
+import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ PropertiesMapBean.class })
+public class EventsRestServiceTest {
+
+ @InjectMocks
+ EventsRestService eventsRestRestService;
+
+ @Mock
+ private EventsService eventsService;
+
+ @Mock
+ ErrorResponse errorResponse;
+
+ @Mock
+ DMaaPContext dmaapContext;
+
+ @Mock
+ InputStream iStream;
+
+ @Mock
+ ServletInputStream servletInputStream;
+
+ @Mock
+ HttpServletRequest request;
+
+ @Mock
+ private DMaaPErrorMessages errorMessages;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @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);
+ }
+
+ }
+
+ @Test(expected = TopicExistsException.class)
+ public void testGetEvents_TopicExistException() throws CambriaApiException, ConfigDbException, TopicExistsException,
+ UnavailableException, IOException, AccessDeniedException {
+
+ Mockito.doThrow(new TopicExistsException("topic exists")).when(eventsService).getEvents(any(),
+ any(), any(), any());
+
+ eventsService.getEvents(dmaapContext, "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(any(),
+ any(), any(), any());
+
+ eventsService.getEvents(dmaapContext, "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");
+
+ }
+
+ @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
+ public void testPushEvents_TopicExistException() throws CambriaApiException {
+
+ eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
+
+ }
+
+ @Test
+ public void tesTPushEventsWithTransaction() throws CambriaApiException, IOException {
+ when(request.getInputStream()).thenReturn(servletInputStream);
+ eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
+
+ }
+
+ @Test
+ public void tesTPushEventsWithTransaction_error() throws IOException {
+ 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);
+ }
+
+ }
+
+}