Add unit test cases
[dmaap/messagerouter/messageservice.git] / src / test / java / com / att / nsa / dmaap / service / AdminRestServiceTest.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 org.junit.After;\r
24 import org.junit.Before;\r
25 import org.junit.Test;\r
26 import org.junit.runner.RunWith;\r
27 \r
28 import org.mockito.InjectMocks;\r
29 import org.mockito.Mock;\r
30 import org.mockito.MockitoAnnotations;\r
31 import com.att.nsa.cambria.CambriaApiException;\r
32 import static org.mockito.Mockito.when;\r
33 \r
34 import org.powermock.core.classloader.annotations.PrepareForTest;\r
35 import org.powermock.modules.junit4.PowerMockRunner;\r
36 \r
37 import javax.servlet.http.HttpServletRequest;\r
38 \r
39 import com.att.nsa.cambria.beans.DMaaPContext;\r
40 import java.util.Enumeration;\r
41 import com.att.nsa.cambria.service.AdminService;\r
42 import com.att.nsa.configs.ConfigDbException;\r
43 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
44 \r
45 @RunWith(PowerMockRunner.class)\r
46 public class AdminRestServiceTest {\r
47         \r
48         @InjectMocks\r
49         AdminRestService adminRestService;\r
50 \r
51         @Mock\r
52         AdminService adminService;\r
53 \r
54         @Mock\r
55         DMaaPContext dmaapContext;\r
56 \r
57         @Mock\r
58         HttpServletRequest httpServReq;\r
59 \r
60         @Mock\r
61         Enumeration headerNames;\r
62 \r
63         @Before\r
64         public void setUp() throws Exception {\r
65                 MockitoAnnotations.initMocks(this);\r
66         }\r
67 \r
68         @After\r
69         public void tearDown() throws Exception {\r
70         }\r
71 \r
72         @Test\r
73         public void testGetConsumerCache() throws CambriaApiException, AccessDeniedException {\r
74                 adminRestService.getConsumerCache();\r
75 \r
76         }\r
77 \r
78         @Test\r
79         public void testDropConsumerCache() throws CambriaApiException, AccessDeniedException {\r
80                 adminRestService.dropConsumerCache();\r
81 \r
82         }\r
83 \r
84         @Test\r
85         public void testGetBlacklist() throws CambriaApiException, AccessDeniedException {\r
86 \r
87                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
88                 when(httpServReq.getHeaderNames()).thenReturn(headerNames);\r
89                 when(headerNames.nextElement()).thenReturn("key");\r
90                 when(httpServReq.getHeader("key")).thenReturn("value");\r
91 \r
92                 adminRestService.getBlacklist();\r
93 \r
94         }\r
95 \r
96         @Test\r
97         public void testAddToBlacklist() throws CambriaApiException, AccessDeniedException {\r
98 \r
99                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
100 \r
101                 adminRestService.addToBlacklist("120.120.120.120");\r
102 \r
103         }\r
104         \r
105         @Test\r
106         public void testRemoveFromBlacklist() throws CambriaApiException, AccessDeniedException, ConfigDbException {\r
107 \r
108                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
109 \r
110                 adminRestService.removeFromBlacklist("120.120.120.120");\r
111 \r
112         }\r
113 \r
114 }