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 com.att.nsa.configs.ConfigDbException;
25 import com.att.nsa.limits.Blacklist;
26 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
27 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.dmaap.dmf.mr.backends.ConsumerFactory;
36 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
37 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
38 import org.onap.dmaap.dmf.mr.service.impl.AdminServiceImpl;
39 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
40 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
41 import org.powermock.api.mockito.PowerMockito;
42 import org.powermock.core.classloader.annotations.PowerMockIgnore;
43 import org.powermock.core.classloader.annotations.PrepareForTest;
44 import org.powermock.modules.junit4.PowerMockRunner;
46 import java.io.IOException;
48 import static org.junit.Assert.assertTrue;
50 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
51 @RunWith(PowerMockRunner.class)
52 @PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class })
53 public class AdminServiceImplemTest {
56 AdminServiceImpl adminServiceImpl;
59 DMaaPContext dmaapContext;
61 ConsumerFactory factory;
64 ConfigurationReader configReader;
69 public void setUp() throws Exception {
71 MockitoAnnotations.initMocks(this);
72 PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
73 NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
75 PowerMockito.when(dmaapContext.getConfigReader()).thenReturn(configReader);
76 PowerMockito.when(configReader.getfConsumerFactory()).thenReturn(factory);
77 PowerMockito.when(configReader.getfIpBlackList()).thenReturn(Blacklist);
79 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
80 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
84 public void tearDown() throws Exception {
87 // ISSUES WITH AUTHENTICATION
89 public void testShowConsumerCache() {
92 adminServiceImpl.showConsumerCache(dmaapContext);
93 } catch (IOException | AccessDeniedException e) {
94 // TODO Auto-generated catch block
96 } catch (NullPointerException e) {
97 // TODO Auto-generated catch block
98 // e.printStackTrace();
102 String trueValue = "True";
103 assertTrue(trueValue.equalsIgnoreCase("True"));
108 public void testDropConsumerCache() {
111 adminServiceImpl.dropConsumerCache(dmaapContext);
112 } catch (IOException | AccessDeniedException e) {
113 // TODO Auto-generated catch block
115 } catch (NullPointerException e) {
116 // TODO Auto-generated catch block
117 // e.printStackTrace();
121 String trueValue = "True";
122 assertTrue(trueValue.equalsIgnoreCase("True"));
127 public void testGetBlacklist() {
130 adminServiceImpl.getBlacklist(dmaapContext);
131 } catch (IOException | AccessDeniedException e) {
132 // TODO Auto-generated catch block
134 } catch (NullPointerException e) {
135 // TODO Auto-generated catch block
136 // e.printStackTrace();
140 String trueValue = "True";
141 assertTrue(trueValue.equalsIgnoreCase("True"));
146 public void testAddToBlacklist() {
149 adminServiceImpl.addToBlacklist(dmaapContext, "120.120.120.120");
150 } catch (IOException | AccessDeniedException | ConfigDbException e) {
151 // TODO Auto-generated catch block
153 } catch (NullPointerException e) {
154 // TODO Auto-generated catch block
155 // e.printStackTrace();
159 String trueValue = "True";
160 assertTrue(trueValue.equalsIgnoreCase("True"));
165 public void testRemoveFromBlacklist() {
168 adminServiceImpl.removeFromBlacklist(dmaapContext, "120.120.120.120");
169 } catch (IOException | AccessDeniedException | ConfigDbException e) {
170 // TODO Auto-generated catch block
172 } catch (NullPointerException e) {
173 // TODO Auto-generated catch block
174 // e.printStackTrace();
178 String trueValue = "True";
179 assertTrue(trueValue.equalsIgnoreCase("True"));