commiting code for test coverage
[dmaap/messagerouter/messageservice.git] / src / test / java / com / att / nsa / dmaap / service / EventsRestServiceTest.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP Policy Engine\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
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \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
19  */\r
20 package com.att.nsa.dmaap.service;\r
21 \r
22 import org.junit.After;\r
23 import org.junit.Before;\r
24 import org.junit.Test;\r
25 \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
33 \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
40 \r
41 //import static org.mockito.Mockito.when;\r
42 \r
43 import java.io.IOException;\r
44 import java.io.InputStream;\r
45 \r
46 import javax.servlet.ServletInputStream;\r
47 import javax.servlet.ServletOutputStream;\r
48 import javax.servlet.http.HttpServletRequest;\r
49 \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
54 \r
55 /*@RunWith(PowerMockRunner.class)\r
56 @PrepareForTest({ PropertiesMapBean.class })*/\r
57 public class EventsRestServiceTest {/*\r
58 \r
59         @InjectMocks\r
60         EventsRestService eventsRestRestService;\r
61 \r
62         @Mock\r
63         private EventsService eventsService;\r
64         \r
65         @Mock\r
66         ErrorResponse errorResponse;\r
67         \r
68         @Mock\r
69         DMaaPContext dmaapContext;\r
70 \r
71         @Mock\r
72         InputStream iStream;\r
73 \r
74         @Mock\r
75         ServletInputStream servletInputStream;\r
76 \r
77         @Mock\r
78         HttpServletRequest httpServReq;\r
79 \r
80         @Before\r
81         public void setUp() throws Exception {\r
82                 MockitoAnnotations.initMocks(this);\r
83         }\r
84 \r
85         @After\r
86         public void tearDown() throws Exception {\r
87         }\r
88 \r
89         @Test\r
90         public void testGetEvents() throws CambriaApiException {\r
91 \r
92                 eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
93 \r
94         }\r
95 \r
96         @Test(expected = TopicExistsException.class)\r
97         public void testGetEvents_TopicExistException() throws CambriaApiException, ConfigDbException, TopicExistsException,\r
98                         UnavailableException, IOException, AccessDeniedException {\r
99 \r
100                 Mockito.doThrow(new TopicExistsException("topic exists")).when(eventsService).getEvents(dmaapContext,\r
101                                 "topicName", "consumergroup", "consumerid");\r
102 \r
103                 eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
104 \r
105         }\r
106         \r
107         @Test(expected = DMaaPAccessDeniedException.class)\r
108         public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,\r
109                         UnavailableException, IOException, AccessDeniedException {\r
110 \r
111                 Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,\r
112                                 "topicName", "consumergroup", "consumerid");\r
113 \r
114                 eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
115 \r
116         }\r
117         \r
118         @Test(expected = DMaaPAccessDeniedException.class)\r
119         public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,\r
120                         UnavailableException, IOException, AccessDeniedException {\r
121 \r
122                 Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,\r
123                                 "topicName", "consumergroup", "consumerid");\r
124 \r
125                 eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
126 \r
127         }\r
128 \r
129         @Test\r
130         public void testPushEvents() throws CambriaApiException {\r
131 \r
132                 eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
133 \r
134         }\r
135         \r
136 \r
137         @Test\r
138         public void testPushEvents_TopicExistException() throws CambriaApiException {\r
139 \r
140                 eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
141 \r
142         }\r
143 \r
144         @Test\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
150 \r
151         }\r
152 \r
153 */}\r