-/*-\r
-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP Policy Engine\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package com.att.nsa.cambria.service.impl;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-import java.io.IOException;\r
-\r
-import com.att.dmf.mr.backends.ConsumerFactory;\r
-import com.att.dmf.mr.beans.DMaaPContext;\r
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;\r
-import com.att.dmf.mr.service.impl.AdminServiceImpl;\r
-import com.att.dmf.mr.utils.ConfigurationReader;\r
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;\r
-import com.att.nsa.configs.ConfigDbException;\r
-import com.att.nsa.limits.Blacklist;\r
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
-import com.att.nsa.security.db.simple.NsaSimpleApiKey;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.junit.runner.RunWith;\r
-import org.mockito.InjectMocks;\r
-import org.mockito.Mock;\r
-import org.mockito.MockitoAnnotations;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class })\r
-public class AdminServiceImplemTest {\r
-\r
- @InjectMocks\r
- AdminServiceImpl adminServiceImpl;\r
-\r
- @Mock\r
- DMaaPContext dmaapContext;\r
- @Mock\r
- ConsumerFactory factory;\r
-\r
- @Mock\r
- ConfigurationReader configReader;\r
- @Mock\r
- Blacklist Blacklist;\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
-\r
- MockitoAnnotations.initMocks(this);\r
- PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);\r
- NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");\r
-\r
- PowerMockito.when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
- PowerMockito.when(configReader.getfConsumerFactory()).thenReturn(factory);\r
- PowerMockito.when(configReader.getfIpBlackList()).thenReturn(Blacklist);\r
-\r
- PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);\r
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
- }\r
-\r
- @After\r
- public void tearDown() throws Exception {\r
- }\r
-\r
- // ISSUES WITH AUTHENTICATION\r
- @Test\r
- public void testShowConsumerCache() {\r
-\r
- try {\r
- adminServiceImpl.showConsumerCache(dmaapContext);\r
- } catch (IOException | AccessDeniedException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- // e.printStackTrace();\r
- assertTrue(true);\r
- }\r
-\r
- String trueValue = "True";\r
- assertTrue(trueValue.equalsIgnoreCase("True"));\r
-\r
- }\r
-\r
- @Test\r
- public void testDropConsumerCache() {\r
-\r
- try {\r
- adminServiceImpl.dropConsumerCache(dmaapContext);\r
- } catch (IOException | AccessDeniedException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- // e.printStackTrace();\r
- assertTrue(true);\r
- }\r
-\r
- String trueValue = "True";\r
- assertTrue(trueValue.equalsIgnoreCase("True"));\r
-\r
- }\r
-\r
- @Test\r
- public void testGetBlacklist() {\r
-\r
- try {\r
- adminServiceImpl.getBlacklist(dmaapContext);\r
- } catch (IOException | AccessDeniedException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- // e.printStackTrace();\r
- assertTrue(true);\r
- }\r
-\r
- String trueValue = "True";\r
- assertTrue(trueValue.equalsIgnoreCase("True"));\r
-\r
- }\r
-\r
- @Test\r
- public void testAddToBlacklist() {\r
-\r
- try {\r
- adminServiceImpl.addToBlacklist(dmaapContext, "120.120.120.120");\r
- } catch (IOException | AccessDeniedException | ConfigDbException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- // e.printStackTrace();\r
- assertTrue(true);\r
- }\r
-\r
- String trueValue = "True";\r
- assertTrue(trueValue.equalsIgnoreCase("True"));\r
-\r
- }\r
-\r
- @Test\r
- public void testRemoveFromBlacklist() {\r
-\r
- try {\r
- adminServiceImpl.removeFromBlacklist(dmaapContext, "120.120.120.120");\r
- } catch (IOException | AccessDeniedException | ConfigDbException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- // e.printStackTrace();\r
- assertTrue(true);\r
- }\r
-\r
- String trueValue = "True";\r
- assertTrue(trueValue.equalsIgnoreCase("True"));\r
-\r
- }\r
-\r
-}\r
+/*-
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+ package org.onap.dmaap.mr.cambria.service.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.onap.dmaap.dmf.mr.backends.ConsumerFactory;
+import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
+import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
+import org.onap.dmaap.dmf.mr.service.impl.AdminServiceImpl;
+import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
+import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
+import com.att.nsa.configs.ConfigDbException;
+import com.att.nsa.limits.Blacklist;
+import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
+import com.att.nsa.security.db.simple.NsaSimpleApiKey;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class })
+public class AdminServiceImplemTest {
+
+ @InjectMocks
+ AdminServiceImpl adminServiceImpl;
+
+ @Mock
+ DMaaPContext dmaapContext;
+ @Mock
+ ConsumerFactory factory;
+
+ @Mock
+ ConfigurationReader configReader;
+ @Mock
+ Blacklist Blacklist;
+
+ @Before
+ public void setUp() throws Exception {
+
+ MockitoAnnotations.initMocks(this);
+ PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
+ NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
+
+ PowerMockito.when(dmaapContext.getConfigReader()).thenReturn(configReader);
+ PowerMockito.when(configReader.getfConsumerFactory()).thenReturn(factory);
+ PowerMockito.when(configReader.getfIpBlackList()).thenReturn(Blacklist);
+
+ PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ // ISSUES WITH AUTHENTICATION
+ @Test
+ public void testShowConsumerCache() {
+
+ try {
+ adminServiceImpl.showConsumerCache(dmaapContext);
+ } catch (IOException | AccessDeniedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ assertTrue(true);
+ }
+
+ String trueValue = "True";
+ assertTrue(trueValue.equalsIgnoreCase("True"));
+
+ }
+
+ @Test
+ public void testDropConsumerCache() {
+
+ try {
+ adminServiceImpl.dropConsumerCache(dmaapContext);
+ } catch (IOException | AccessDeniedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ assertTrue(true);
+ }
+
+ String trueValue = "True";
+ assertTrue(trueValue.equalsIgnoreCase("True"));
+
+ }
+
+ @Test
+ public void testGetBlacklist() {
+
+ try {
+ adminServiceImpl.getBlacklist(dmaapContext);
+ } catch (IOException | AccessDeniedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ assertTrue(true);
+ }
+
+ String trueValue = "True";
+ assertTrue(trueValue.equalsIgnoreCase("True"));
+
+ }
+
+ @Test
+ public void testAddToBlacklist() {
+
+ try {
+ adminServiceImpl.addToBlacklist(dmaapContext, "120.120.120.120");
+ } catch (IOException | AccessDeniedException | ConfigDbException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ assertTrue(true);
+ }
+
+ String trueValue = "True";
+ assertTrue(trueValue.equalsIgnoreCase("True"));
+
+ }
+
+ @Test
+ public void testRemoveFromBlacklist() {
+
+ try {
+ adminServiceImpl.removeFromBlacklist(dmaapContext, "120.120.120.120");
+ } catch (IOException | AccessDeniedException | ConfigDbException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ assertTrue(true);
+ }
+
+ String trueValue = "True";
+ assertTrue(trueValue.equalsIgnoreCase("True"));
+
+ }
+
+}