2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package com.att.nsa.dmaap.service;
\r
22 import org.junit.After;
\r
23 import org.junit.Before;
\r
24 import org.junit.Test;
\r
26 import org.junit.runner.RunWith;
\r
27 import org.mockito.InjectMocks;
\r
28 import org.mockito.Mock;
\r
29 import org.mockito.Mockito;
\r
30 import org.mockito.MockitoAnnotations;
\r
31 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
32 import org.powermock.modules.junit4.PowerMockRunner;
\r
34 import com.att.ajsc.beans.PropertiesMapBean;
\r
35 import com.att.nsa.cambria.CambriaApiException;
\r
36 import com.att.nsa.cambria.backends.ConsumerFactory.UnavailableException;
\r
37 import com.att.nsa.cambria.service.EventsService;
\r
38 import com.att.nsa.configs.ConfigDbException;
\r
39 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
\r
41 import static org.mockito.Mockito.when;
\r
43 import java.io.IOException;
\r
44 import java.io.InputStream;
\r
46 import javax.servlet.ServletInputStream;
\r
47 import javax.servlet.ServletOutputStream;
\r
48 import javax.servlet.http.HttpServletRequest;
\r
50 import com.att.nsa.cambria.beans.DMaaPContext;
\r
51 import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
\r
52 import com.att.nsa.cambria.exception.ErrorResponse;
\r
53 import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
\r
55 @RunWith(PowerMockRunner.class)
\r
56 @PrepareForTest({ PropertiesMapBean.class })
\r
57 public class EventsRestServiceTest {
\r
60 EventsRestService eventsRestRestService;
\r
63 private EventsService eventsService;
\r
66 ErrorResponse errorResponse;
\r
69 DMaaPContext dmaapContext;
\r
72 InputStream iStream;
\r
75 ServletInputStream servletInputStream;
\r
78 HttpServletRequest httpServReq;
\r
81 public void setUp() throws Exception {
\r
82 MockitoAnnotations.initMocks(this);
\r
86 public void tearDown() throws Exception {
\r
90 public void testGetEvents() throws CambriaApiException {
\r
92 eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
\r
96 @Test(expected = TopicExistsException.class)
\r
97 public void testGetEvents_TopicExistException() throws CambriaApiException, ConfigDbException, TopicExistsException,
\r
98 UnavailableException, IOException, AccessDeniedException {
\r
100 Mockito.doThrow(new TopicExistsException("topic exists")).when(eventsService).getEvents(dmaapContext,
\r
101 "topicName", "consumergroup", "consumerid");
\r
103 eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
\r
107 @Test(expected = DMaaPAccessDeniedException.class)
\r
108 public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,
\r
109 UnavailableException, IOException, AccessDeniedException {
\r
111 Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,
\r
112 "topicName", "consumergroup", "consumerid");
\r
114 eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
\r
118 /*@Test(expected = DMaaPAccessDeniedException.class)
\r
119 public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,
\r
120 UnavailableException, IOException, AccessDeniedException {
\r
122 Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,
\r
123 "topicName", "consumergroup", "consumerid");
\r
125 eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
\r
130 public void testPushEvents() throws CambriaApiException {
\r
132 eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
\r
138 public void testPushEvents_TopicExistException() throws CambriaApiException {
\r
140 eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
\r
145 public void tesTPushEventsWithTransaction() throws CambriaApiException, IOException {
\r
146 // when(dmaapContext.getRequest()).th
\r
147 // thenReturn(httpServReq);
\r
148 when(httpServReq.getInputStream()).thenReturn(servletInputStream);
\r
149 eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
\r