DMAAP-MR - Merge MR repos
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / mr / cambria / service / impl / AdminServiceImplemTest.java
diff --git a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/AdminServiceImplemTest.java b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/AdminServiceImplemTest.java
new file mode 100644 (file)
index 0000000..22db674
--- /dev/null
@@ -0,0 +1,183 @@
+/*-
+/*-
+ * ============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 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.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 org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertTrue;
+
+@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
+@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"));
+
+       }
+
+}