update the package name
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / cambria / service / impl / ApiKeysServiceImplTest.java
-/*-\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
-\r
-package com.att.nsa.cambria.service.impl;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-import java.io.IOException;\r
-import java.util.Arrays;\r
-import java.util.HashSet;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import com.att.dmf.mr.backends.ConsumerFactory;\r
-import com.att.dmf.mr.beans.ApiKeyBean;\r
-import com.att.dmf.mr.beans.DMaaPContext;\r
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;\r
-import com.att.dmf.mr.service.impl.ApiKeysServiceImpl;\r
-import com.att.dmf.mr.utils.ConfigurationReader;\r
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;\r
-import com.att.dmf.mr.utils.Emailer;\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.NsaApiDb;\r
-import com.att.nsa.security.db.NsaApiDb.KeyExistsException;\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 ApiKeysServiceImplTest {\r
-       \r
-       @InjectMocks\r
-       ApiKeysServiceImpl service;\r
-\r
-       @Mock\r
-       DMaaPContext dmaapContext;\r
-       @Mock\r
-       ConsumerFactory factory;\r
-\r
-       @Mock\r
-       ConfigurationReader configReader;\r
-       @Mock\r
-       Blacklist Blacklist;\r
-       @Mock\r
-       Emailer emailer;\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(configReader.getfApiKeyDb()).thenReturn(fApiKeyDb);\r
-               PowerMockito.when(configReader.getSystemEmailer()).thenReturn(emailer);\r
-               PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);\r
-               PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
-       \r
-       }\r
-\r
-       @After\r
-       public void tearDown() throws Exception {\r
-       }\r
-\r
-       \r
-       @Test\r
-       public void testGetAllApiKeys() {\r
-               \r
-                service = new ApiKeysServiceImpl();\r
-               try {\r
-                       service.getAllApiKeys(dmaapContext);\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-                       \r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               }\r
-               assertTrue(true);\r
-        \r
-       }\r
-       \r
-       @Test\r
-       public void testGetApiKey() {\r
-               \r
-               ApiKeysServiceImpl service = new ApiKeysServiceImpl();\r
-               try {\r
-                       service.getApiKey(dmaapContext, "testkey");\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-                       assertTrue(true);\r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-               }\r
-               assertTrue(true);\r
-        \r
-       }\r
-       \r
-       @Test\r
-       public void testGetApiKey_error() {\r
-               \r
-               ApiKeysServiceImpl service = new ApiKeysServiceImpl();\r
-               try {\r
-                       service.getApiKey(dmaapContext, "k35Hdw6Sde");\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                       assertTrue(true);\r
-               }\r
-        \r
-       }\r
-       \r
-       @Test\r
-       public void testCreateApiKey() {\r
-               \r
-               ApiKeysServiceImpl service = new ApiKeysServiceImpl();\r
-               try {\r
-                       service.createApiKey(dmaapContext, new ApiKeyBean("test@onap.com", "testing apikey bean"));\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (KeyExistsException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch(NoClassDefFoundError e) {\r
-                       \r
-               }\r
-                assertTrue(true);\r
-       }\r
-       \r
-       @Test\r
-       public void testUpdateApiKey() {\r
-               \r
-               ApiKeysServiceImpl service = new ApiKeysServiceImpl();\r
-               try {\r
-                       \r
-                       service.updateApiKey(dmaapContext, "admin", new ApiKeyBean("test@onapt.com", "testing apikey bean"));\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (AccessDeniedException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               }\r
-                assertTrue(true);\r
-        \r
-       }\r
-       @Test\r
-       public void testUpdateApiKey_error() {\r
-               \r
-               ApiKeysServiceImpl service = new ApiKeysServiceImpl();\r
-               try {\r
-                       \r
-                       service.updateApiKey(dmaapContext, null, new ApiKeyBean("test@onapt.com", "testing apikey bean"));\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-                       assertTrue(true);\r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                        assertTrue(true);\r
-               } catch (AccessDeniedException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               }\r
-        \r
-       }\r
-       \r
-       @Test\r
-       public void testDeleteApiKey() {\r
-               \r
-               ApiKeysServiceImpl service = new ApiKeysServiceImpl();\r
-               try {\r
-                       \r
-                       service.deleteApiKey(dmaapContext, null);\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-                       assertTrue(true);\r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (AccessDeniedException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               }\r
-        \r
-       }\r
-       \r
-       @Test\r
-       public void testDeleteApiKey_error() {\r
-               \r
-               ApiKeysServiceImpl service = new ApiKeysServiceImpl();\r
-               try {\r
-                       \r
-                       service.deleteApiKey(dmaapContext, "admin");\r
-               } catch (NullPointerException e) {\r
-                       // TODO Auto-generated catch block\r
-                       //e.printStackTrace();\r
-                       assertTrue(true);\r
-               } catch (ConfigDbException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               } catch (AccessDeniedException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               }\r
-        \r
-       }\r
-       \r
-       NsaApiDb<NsaSimpleApiKey> fApiKeyDb= new NsaApiDb<NsaSimpleApiKey>() {\r
-               \r
-               \r
-               Set<String> keys = new HashSet<>(Arrays.asList("testkey","admin"));\r
-               \r
-               \r
-               @Override\r
-               public NsaSimpleApiKey createApiKey(String arg0, String arg1)\r
-                               throws com.att.nsa.security.db.NsaApiDb.KeyExistsException, ConfigDbException {\r
-                       // TODO Auto-generated method stub\r
-                       return new NsaSimpleApiKey(arg0, arg1);\r
-               }\r
-\r
-               @Override\r
-               public boolean deleteApiKey(NsaSimpleApiKey arg0) throws ConfigDbException {\r
-                       // TODO Auto-generated method stub\r
-                       return false;\r
-               }\r
-\r
-               @Override\r
-               public boolean deleteApiKey(String arg0) throws ConfigDbException {\r
-                       // TODO Auto-generated method stub\r
-                       return false;\r
-               }\r
-\r
-               @Override\r
-               public Map<String, NsaSimpleApiKey> loadAllKeyRecords() throws ConfigDbException {\r
-                       // TODO Auto-generated method stub\r
-                       return null;\r
-               }\r
-\r
-               @Override\r
-               public Set<String> loadAllKeys() throws ConfigDbException {\r
-                       // TODO Auto-generated method stub\r
-                       \r
-                       return keys ;\r
-               }\r
-\r
-               @Override\r
-               public NsaSimpleApiKey loadApiKey(String arg0) throws ConfigDbException {\r
-                       if(!keys.contains(arg0)){\r
-                               return null;\r
-                       }\r
-                       return new NsaSimpleApiKey(arg0, "password");\r
-               }\r
-\r
-               @Override\r
-               public void saveApiKey(NsaSimpleApiKey arg0) throws ConfigDbException {\r
-                       // TODO Auto-generated method stub\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 java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.onap.dmaap.dmf.mr.backends.ConsumerFactory;
+import org.onap.dmaap.dmf.mr.beans.ApiKeyBean;
+import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
+import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
+import org.onap.dmaap.dmf.mr.service.impl.ApiKeysServiceImpl;
+import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
+import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
+import org.onap.dmaap.dmf.mr.utils.Emailer;
+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.NsaApiDb;
+import com.att.nsa.security.db.NsaApiDb.KeyExistsException;
+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 ApiKeysServiceImplTest {
+       
+       @InjectMocks
+       ApiKeysServiceImpl service;
+
+       @Mock
+       DMaaPContext dmaapContext;
+       @Mock
+       ConsumerFactory factory;
+
+       @Mock
+       ConfigurationReader configReader;
+       @Mock
+       Blacklist Blacklist;
+       @Mock
+       Emailer emailer;
+
+       @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(configReader.getfApiKeyDb()).thenReturn(fApiKeyDb);
+               PowerMockito.when(configReader.getSystemEmailer()).thenReturn(emailer);
+               PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
+               PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+       
+       }
+
+       @After
+       public void tearDown() throws Exception {
+       }
+
+       
+       @Test
+       public void testGetAllApiKeys() {
+               
+                service = new ApiKeysServiceImpl();
+               try {
+                       service.getAllApiKeys(dmaapContext);
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+                       
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               assertTrue(true);
+        
+       }
+       
+       @Test
+       public void testGetApiKey() {
+               
+               ApiKeysServiceImpl service = new ApiKeysServiceImpl();
+               try {
+                       service.getApiKey(dmaapContext, "testkey");
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+                       assertTrue(true);
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+               }
+               assertTrue(true);
+        
+       }
+       
+       @Test
+       public void testGetApiKey_error() {
+               
+               ApiKeysServiceImpl service = new ApiKeysServiceImpl();
+               try {
+                       service.getApiKey(dmaapContext, "k35Hdw6Sde");
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       assertTrue(true);
+               }
+        
+       }
+       
+       @Test
+       public void testCreateApiKey() {
+               
+               ApiKeysServiceImpl service = new ApiKeysServiceImpl();
+               try {
+                       service.createApiKey(dmaapContext, new ApiKeyBean("test@onap.com", "testing apikey bean"));
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (KeyExistsException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch(NoClassDefFoundError e) {
+                       
+               }
+                assertTrue(true);
+       }
+       
+       @Test
+       public void testUpdateApiKey() {
+               
+               ApiKeysServiceImpl service = new ApiKeysServiceImpl();
+               try {
+                       
+                       service.updateApiKey(dmaapContext, "admin", new ApiKeyBean("test@onapt.com", "testing apikey bean"));
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (AccessDeniedException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+                assertTrue(true);
+        
+       }
+       @Test
+       public void testUpdateApiKey_error() {
+               
+               ApiKeysServiceImpl service = new ApiKeysServiceImpl();
+               try {
+                       
+                       service.updateApiKey(dmaapContext, null, new ApiKeyBean("test@onapt.com", "testing apikey bean"));
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+                       assertTrue(true);
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                        assertTrue(true);
+               } catch (AccessDeniedException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+        
+       }
+       
+       @Test
+       public void testDeleteApiKey() {
+               
+               ApiKeysServiceImpl service = new ApiKeysServiceImpl();
+               try {
+                       
+                       service.deleteApiKey(dmaapContext, null);
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+                       assertTrue(true);
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (AccessDeniedException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+        
+       }
+       
+       @Test
+       public void testDeleteApiKey_error() {
+               
+               ApiKeysServiceImpl service = new ApiKeysServiceImpl();
+               try {
+                       
+                       service.deleteApiKey(dmaapContext, "admin");
+               } catch (NullPointerException e) {
+                       // TODO Auto-generated catch block
+                       //e.printStackTrace();
+                       assertTrue(true);
+               } catch (ConfigDbException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (AccessDeniedException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+        
+       }
+       
+       NsaApiDb<NsaSimpleApiKey> fApiKeyDb= new NsaApiDb<NsaSimpleApiKey>() {
+               
+               
+               Set<String> keys = new HashSet<>(Arrays.asList("testkey","admin"));
+               
+               
+               @Override
+               public NsaSimpleApiKey createApiKey(String arg0, String arg1)
+                               throws com.att.nsa.security.db.NsaApiDb.KeyExistsException, ConfigDbException {
+                       // TODO Auto-generated method stub
+                       return new NsaSimpleApiKey(arg0, arg1);
+               }
+
+               @Override
+               public boolean deleteApiKey(NsaSimpleApiKey arg0) throws ConfigDbException {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               @Override
+               public boolean deleteApiKey(String arg0) throws ConfigDbException {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               @Override
+               public Map<String, NsaSimpleApiKey> loadAllKeyRecords() throws ConfigDbException {
+                       // TODO Auto-generated method stub
+                       return null;
+               }
+
+               @Override
+               public Set<String> loadAllKeys() throws ConfigDbException {
+                       // TODO Auto-generated method stub
+                       
+                       return keys ;
+               }
+
+               @Override
+               public NsaSimpleApiKey loadApiKey(String arg0) throws ConfigDbException {
+                       if(!keys.contains(arg0)){
+                               return null;
+                       }
+                       return new NsaSimpleApiKey(arg0, "password");
+               }
+
+               @Override
+               public void saveApiKey(NsaSimpleApiKey arg0) throws ConfigDbException {
+                       // TODO Auto-generated method stub
+                       
+               }
+       };
 }
\ No newline at end of file