commiting code for test coverage
[dmaap/messagerouter/messageservice.git] / src / test / java / com / att / nsa / dmaap / service / MMRestServiceTest.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 \r
21 package com.att.nsa.dmaap.service;\r
22 \r
23 import static org.junit.Assert.*;\r
24 \r
25 //import static org.mockito.Matchers.anyString;\r
26 //import static org.mockito.Mockito.when;\r
27 \r
28 import java.io.IOException;\r
29 import java.io.InputStream;\r
30 \r
31 import javax.servlet.ServletOutputStream;\r
32 import javax.servlet.http.HttpServletRequest;\r
33 import javax.servlet.http.HttpServletResponse;\r
34 \r
35 import org.junit.After;\r
36 import org.json.JSONArray;\r
37 import org.json.JSONException;\r
38 import org.json.JSONObject;\r
39 import org.junit.Assert;\r
40 import org.junit.Before;\r
41 import org.junit.Test;\r
42 \r
43 import org.junit.runner.RunWith;\r
44 /*import org.mockito.InjectMocks;\r
45 import org.mockito.Mock;\r
46 import org.mockito.MockitoAnnotations;\r
47 import org.powermock.api.mockito.PowerMockito;\r
48 import org.powermock.core.classloader.annotations.PrepareForTest;\r
49 import org.powermock.modules.junit4.PowerMockRunner;*/\r
50 \r
51 import com.att.ajsc.beans.PropertiesMapBean;\r
52 import com.att.ajsc.filemonitor.AJSCPropertiesMap;\r
53 import com.att.nsa.cambria.CambriaApiException;\r
54 import com.att.nsa.cambria.beans.DMaaPContext;\r
55 import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;\r
56 import com.att.nsa.cambria.constants.CambriaConstants;\r
57 import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;\r
58 import com.att.nsa.cambria.exception.DMaaPErrorMessages;\r
59 import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;\r
60 import com.att.nsa.cambria.metabroker.Topic;\r
61 import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;\r
62 import com.att.nsa.cambria.security.DMaaPAAFAuthenticatorImpl;\r
63 import com.att.nsa.cambria.security.DMaaPAuthenticator;\r
64 import com.att.nsa.cambria.service.MMService;\r
65 import com.att.nsa.cambria.utils.ConfigurationReader;\r
66 import com.att.nsa.configs.ConfigDbException;\r
67 import com.att.nsa.dmaap.mmagent.CreateMirrorMaker;\r
68 import com.att.nsa.dmaap.mmagent.MirrorMaker;\r
69 import com.att.nsa.dmaap.mmagent.UpdateMirrorMaker;\r
70 import com.att.nsa.security.NsaAcl;\r
71 import com.att.nsa.security.NsaApiKey;\r
72 import com.att.nsa.security.db.simple.NsaSimpleApiKey;\r
73 \r
74 //@RunWith(MockitoJUnitRunner.class)\r
75 /*@RunWith(PowerMockRunner.class)\r
76 @PrepareForTest({ PropertiesMapBean.class, AJSCPropertiesMap.class })*/\r
77 public class MMRestServiceTest {/*\r
78 \r
79         @InjectMocks\r
80         MMRestService mmRestService;\r
81 \r
82         @Mock\r
83         private MMService mmservice;\r
84 \r
85         @Mock\r
86         CreateMirrorMaker cMirroMaker;\r
87 \r
88         @Mock\r
89         UpdateMirrorMaker uMirroMaker;\r
90 \r
91         private TopicRestService service = new TopicRestService();\r
92         @Mock\r
93         private DMaaPErrorMessages errorMessages;\r
94 \r
95         @Mock\r
96         DMaaPContext dmaapContext;\r
97 \r
98         @Mock\r
99         ConfigurationReader configReader;\r
100 \r
101         @Mock\r
102         ServletOutputStream oStream;\r
103 \r
104         @Mock\r
105         DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;\r
106 \r
107         @Mock\r
108         MirrorMaker mMaker;\r
109 \r
110         @Mock\r
111         DMaaPAAFAuthenticator dmaapAAFauthenticator;\r
112 \r
113         @Mock\r
114         DMaaPAAFAuthenticatorImpl impl;\r
115 \r
116         @Mock\r
117         NsaApiKey user;\r
118 \r
119         @Mock\r
120         NsaSimpleApiKey nsaSimpleApiKey;\r
121 \r
122         @Mock\r
123         HttpServletRequest httpServReq;\r
124 \r
125         @Mock\r
126         HttpServletResponse httpServRes;\r
127 \r
128         @Mock\r
129         InputStream iStream;\r
130 \r
131         @Mock\r
132         DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;\r
133 \r
134         @Mock\r
135         Topic createdTopic;\r
136 \r
137         @Mock\r
138         NsaAcl nsaAcl;\r
139 \r
140         @Mock\r
141         JSONObject jsonObj;\r
142 \r
143         @Mock\r
144         JSONArray jsonArray;\r
145 \r
146         @Before\r
147         public void setUp() throws Exception {\r
148 \r
149                 MockitoAnnotations.initMocks(this);\r
150         }\r
151 \r
152         @After\r
153         public void tearDown() throws Exception {\r
154         }\r
155 \r
156 \r
157         @Test\r
158         public void testCallCreateMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
159                         TopicExistsException, JSONException, ConfigDbException {\r
160 \r
161                 Assert.assertNotNull(mmRestService);\r
162                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
163                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
164                 when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
165 \r
166                 PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
167 \r
168                 assertTrue(true);\r
169                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))\r
170                                 .thenReturn("admin");\r
171 \r
172                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))\r
173                                 .thenReturn("100");\r
174 \r
175                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))\r
176                                 .thenReturn("mirrormaker.topic");\r
177 \r
178                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))\r
179                                 .thenReturn("mirrormaker.consumergroup");\r
180 \r
181                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))\r
182                                 .thenReturn("mirrormaker.consumerid");\r
183 \r
184                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
185 \r
186                 when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
187         \r
188 \r
189                 // when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
190                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);\r
191                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
192                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
193                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
194 \r
195                 when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);\r
196 \r
197                 when(mMaker.getName()).thenReturn("mirroMakerName");\r
198                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
199                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
200                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");\r
201 \r
202                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
203                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
204                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
205 \r
206                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
207 \r
208                 mmRestService.callCreateMirrorMaker(iStream);\r
209         }\r
210 \r
211         @Test\r
212         public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
213                         TopicExistsException, JSONException, ConfigDbException {\r
214 \r
215                 Assert.assertNotNull(mmRestService);\r
216                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
217                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
218                 when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
219 \r
220                 PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
221 \r
222                 assertTrue(true);\r
223                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))\r
224                                 .thenReturn("admin");\r
225 \r
226                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))\r
227                                 .thenReturn("100");\r
228 \r
229                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))\r
230                                 .thenReturn("mirrormaker.topic");\r
231 \r
232                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))\r
233                                 .thenReturn("mirrormaker.consumergroup");\r
234 \r
235                 when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))\r
236                                 .thenReturn("mirrormaker.consumerid");\r
237 \r
238                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
239 \r
240                 when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
241         \r
242 \r
243                 // when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
244                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);\r
245                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
246                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
247                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
248 \r
249                 when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);\r
250 \r
251                 when(mMaker.getName()).thenReturn("mirroMakerName");\r
252                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
253                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
254                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");\r
255 \r
256                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
257                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
258                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
259 \r
260                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
261 \r
262                 mmRestService.callListAllMirrorMaker(iStream);\r
263         }\r
264 \r
265 \r
266 */}\r