3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.dmaap.mr.cambria.service.impl;
24 import static org.junit.Assert.*;
26 import java.io.IOException;
28 import org.onap.dmaap.dmf.mr.backends.ConsumerFactory;
29 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
30 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
31 import org.onap.dmaap.dmf.mr.service.impl.AdminServiceImpl;
32 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
33 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
34 import com.att.nsa.configs.ConfigDbException;
35 import com.att.nsa.limits.Blacklist;
36 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
37 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.junit.runner.RunWith;
43 import org.mockito.InjectMocks;
44 import org.mockito.Mock;
45 import org.mockito.MockitoAnnotations;
46 import org.powermock.api.mockito.PowerMockito;
47 import org.powermock.core.classloader.annotations.PowerMockIgnore;
48 import org.powermock.core.classloader.annotations.PrepareForTest;
49 import org.powermock.modules.junit4.PowerMockRunner;
51 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
52 @RunWith(PowerMockRunner.class)
53 @PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class })
54 public class AdminServiceImplemTest {
57 AdminServiceImpl adminServiceImpl;
60 DMaaPContext dmaapContext;
62 ConsumerFactory factory;
65 ConfigurationReader configReader;
70 public void setUp() throws Exception {
72 MockitoAnnotations.initMocks(this);
73 PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
74 NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
76 PowerMockito.when(dmaapContext.getConfigReader()).thenReturn(configReader);
77 PowerMockito.when(configReader.getfConsumerFactory()).thenReturn(factory);
78 PowerMockito.when(configReader.getfIpBlackList()).thenReturn(Blacklist);
80 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
81 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
85 public void tearDown() throws Exception {
88 // ISSUES WITH AUTHENTICATION
90 public void testShowConsumerCache() {
93 adminServiceImpl.showConsumerCache(dmaapContext);
94 } catch (IOException | AccessDeniedException e) {
95 // TODO Auto-generated catch block
97 } catch (NullPointerException e) {
98 // TODO Auto-generated catch block
99 // e.printStackTrace();
103 String trueValue = "True";
104 assertTrue(trueValue.equalsIgnoreCase("True"));
109 public void testDropConsumerCache() {
112 adminServiceImpl.dropConsumerCache(dmaapContext);
113 } catch (IOException | AccessDeniedException e) {
114 // TODO Auto-generated catch block
116 } catch (NullPointerException e) {
117 // TODO Auto-generated catch block
118 // e.printStackTrace();
122 String trueValue = "True";
123 assertTrue(trueValue.equalsIgnoreCase("True"));
128 public void testGetBlacklist() {
131 adminServiceImpl.getBlacklist(dmaapContext);
132 } catch (IOException | AccessDeniedException e) {
133 // TODO Auto-generated catch block
135 } catch (NullPointerException e) {
136 // TODO Auto-generated catch block
137 // e.printStackTrace();
141 String trueValue = "True";
142 assertTrue(trueValue.equalsIgnoreCase("True"));
147 public void testAddToBlacklist() {
150 adminServiceImpl.addToBlacklist(dmaapContext, "120.120.120.120");
151 } catch (IOException | AccessDeniedException | ConfigDbException e) {
152 // TODO Auto-generated catch block
154 } catch (NullPointerException e) {
155 // TODO Auto-generated catch block
156 // e.printStackTrace();
160 String trueValue = "True";
161 assertTrue(trueValue.equalsIgnoreCase("True"));
166 public void testRemoveFromBlacklist() {
169 adminServiceImpl.removeFromBlacklist(dmaapContext, "120.120.120.120");
170 } catch (IOException | AccessDeniedException | ConfigDbException e) {
171 // TODO Auto-generated catch block
173 } catch (NullPointerException e) {
174 // TODO Auto-generated catch block
175 // e.printStackTrace();
179 String trueValue = "True";
180 assertTrue(trueValue.equalsIgnoreCase("True"));