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
21 package com.att.nsa.dmaap.service;
\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
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
34 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
35 import org.powermock.modules.junit4.PowerMockRunner;
\r
37 import javax.servlet.http.HttpServletRequest;
\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
45 @RunWith(PowerMockRunner.class)
\r
46 public class AdminRestServiceTest {
\r
49 AdminRestService adminRestService;
\r
52 AdminService adminService;
\r
55 DMaaPContext dmaapContext;
\r
58 HttpServletRequest httpServReq;
\r
61 Enumeration headerNames;
\r
64 public void setUp() throws Exception {
\r
65 MockitoAnnotations.initMocks(this);
\r
69 public void tearDown() throws Exception {
\r
73 public void testGetConsumerCache() throws CambriaApiException, AccessDeniedException {
\r
74 adminRestService.getConsumerCache();
\r
79 public void testDropConsumerCache() throws CambriaApiException, AccessDeniedException {
\r
80 adminRestService.dropConsumerCache();
\r
85 public void testGetBlacklist() throws CambriaApiException, AccessDeniedException {
\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
92 adminRestService.getBlacklist();
\r
97 public void testAddToBlacklist() throws CambriaApiException, AccessDeniedException {
\r
99 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
101 adminRestService.addToBlacklist("120.120.120.120");
\r
106 public void testRemoveFromBlacklist() throws CambriaApiException, AccessDeniedException, ConfigDbException {
\r
108 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
110 adminRestService.removeFromBlacklist("120.120.120.120");
\r