summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/att/nsa/cambria/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/att/nsa/cambria/service')
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/AdminServiceImplemTest.java182
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/ApiKeysServiceImplTest.java331
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/BaseTransactionDbImplTest.java158
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java312
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/JUnitTestSuite.java43
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/MMServiceImplTest.java382
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/MessageTest.java64
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/MetricsServiceImplTest.java95
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java149
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/TestRunner.java41
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java766
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/TransactionServiceImplTest.java97
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/UIServiceImplTest.java302
13 files changed, 0 insertions, 2922 deletions
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/AdminServiceImplemTest.java b/src/test/java/com/att/nsa/cambria/service/impl/AdminServiceImplemTest.java
deleted file mode 100644
index fd87cdb..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/AdminServiceImplemTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*-
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import com.att.dmf.mr.backends.ConsumerFactory;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;
-import com.att.dmf.mr.service.impl.AdminServiceImpl;
-import com.att.dmf.mr.utils.ConfigurationReader;
-import com.att.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"));
-
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/ApiKeysServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/ApiKeysServiceImplTest.java
deleted file mode 100644
index 89b25af..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/ApiKeysServiceImplTest.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*-
- * ============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 com.att.nsa.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 com.att.dmf.mr.backends.ConsumerFactory;
-import com.att.dmf.mr.beans.ApiKeyBean;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;
-import com.att.dmf.mr.service.impl.ApiKeysServiceImpl;
-import com.att.dmf.mr.utils.ConfigurationReader;
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;
-import com.att.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
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/BaseTransactionDbImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/BaseTransactionDbImplTest.java
deleted file mode 100644
index baef7be..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/BaseTransactionDbImplTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import com.att.dmf.mr.CambriaApiException;
-import com.att.dmf.mr.backends.ConsumerFactory.UnavailableException;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.metabroker.Broker.TopicExistsException;
-import com.att.dmf.mr.service.impl.BaseTransactionDbImpl;
-import com.att.dmf.mr.transaction.DMaaPTransactionObjDB.KeyExistsException;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class BaseTransactionDbImplTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testCreateTransactionObj() {
-
-
- try {
-
- BaseTransactionDbImpl service = new BaseTransactionDbImpl(null, null);
- service.createTransactionObj("transition");
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- assertTrue(true);
- } catch (KeyExistsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
- @Test
- public void testSaveTransactionObj() {
-
-
- try {
-
- BaseTransactionDbImpl service = new BaseTransactionDbImpl(null, null);
- service.saveTransactionObj(null);
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
- @Test
- public void testLoadTransactionObj() {
-
- try {
-
- BaseTransactionDbImpl service = new BaseTransactionDbImpl(null, null);
- service.loadTransactionObj("34");
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
-
- @Test
- public void testLoadAllTransactionObjs() {
-
- try {
-
- BaseTransactionDbImpl service = new BaseTransactionDbImpl(null, null);
- service.loadAllTransactionObjs();
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
-
-
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java
deleted file mode 100644
index 8cd560d..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.mockito.Mockito.when;
-import static org.mockito.Matchers.anyString;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ConcurrentModificationException;
-import java.util.Map;
-import java.util.Properties;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-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;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-
-import com.att.ajsc.beans.PropertiesMapBean;
-import com.att.ajsc.filemonitor.AJSCPropertiesMap;
-import com.att.dmf.mr.CambriaApiException;
-import com.att.dmf.mr.security.DMaaPAAFAuthenticator;
-import com.att.dmf.mr.security.DMaaPAuthenticator;
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;
-import com.att.dmf.mr.utils.ConfigurationReader;
-import com.att.dmf.mr.backends.ConsumerFactory.UnavailableException;
-import com.att.dmf.mr.beans.DMaaPCambriaLimiter;
-import com.att.dmf.mr.backends.ConsumerFactory;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.beans.DMaaPKafkaMetaBroker;
-import com.att.dmf.mr.constants.CambriaConstants;
-import com.att.dmf.mr.exception.DMaaPAccessDeniedException;
-import com.att.dmf.mr.exception.DMaaPErrorMessages;
-import com.att.dmf.mr.metabroker.Topic;
-import com.att.dmf.mr.metabroker.Broker.TopicExistsException;
-import com.att.dmf.mr.service.impl.EventsServiceImpl;
-import com.att.dmf.mr.utils.PropertyReader;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.invalidSettingValue;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
-import com.att.nsa.limits.Blacklist;
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-import com.att.nsa.security.NsaApiKey;
-import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-
-import kafka.admin.AdminUtils;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ DMaaPAuthenticatorImpl.class, AJSCPropertiesMap.class })
-public class EventsServiceImplTest {
-
- private InputStream iStream = null;
- DMaaPContext dMaapContext = new DMaaPContext();
- EventsServiceImpl service = new EventsServiceImpl();
- DMaaPErrorMessages pErrorMessages = new DMaaPErrorMessages();
- @Mock
- ConfigurationReader configurationReader;
- @Mock
- Blacklist blacklist;
- @Mock
- DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
- @Mock
- DMaaPAAFAuthenticator dmaapAAFauthenticator;
- @Mock
- NsaApiKey user;
- @Mock
- NsaSimpleApiKey nsaSimpleApiKey;
- @Mock
- DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
- @Mock
- Topic createdTopic;
- @Mock
- ConsumerFactory factory;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- String source = "source of my InputStream";
- iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));
-
- MockHttpServletRequest request = new MockHttpServletRequest();
- MockHttpServletResponse response = new MockHttpServletResponse();
- dMaapContext.setRequest(request);
- dMaapContext.setResponse(response);
- when(blacklist.contains(anyString())).thenReturn(false);
- when(configurationReader.getfIpBlackList()).thenReturn(blacklist);
- dMaapContext.setConfigReader(configurationReader);
-
- service.setErrorMessages(pErrorMessages);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "timeout")).thenReturn("100");
-
- AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "timeout");
-
- }
-
- @Test(expected = CambriaApiException.class)
- public void testGetEvents() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException {
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- service.getEvents(dMaapContext, "testTopic", "CG1", "23");
- }
-
- @Test(expected = CambriaApiException.class)
- public void testGetEventsBlackListErr() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException {
- when(blacklist.contains(anyString())).thenReturn(true);
- when(configurationReader.getfIpBlackList()).thenReturn(blacklist);
- dMaapContext.setConfigReader(configurationReader);
- service.getEvents(dMaapContext, "testTopic", "CG1", "23");
- }
-
- @Test(expected = CambriaApiException.class)
- public void testGetEventsNoTopicError() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException {
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(null);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- service.getEvents(dMaapContext, "testTopic", "CG1", "23");
- }
-
- @Test(expected = CambriaApiException.class)
- public void testGetEventsuserNull() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException {
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(null);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- MockHttpServletRequest mockRequest = new MockHttpServletRequest();
- mockRequest.addHeader("Authorization", "passed");
- dMaapContext.setRequest(mockRequest);
- dMaapContext.getRequest().getHeader("Authorization");
- service.getEvents(dMaapContext, "testTopic", "CG1", "23");
- }
-
- @Test(expected = CambriaApiException.class)
- public void testGetEventsExcp2() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException {
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- when(configurationReader.getfRateLimiter()).thenThrow(new ConcurrentModificationException("Error occurred"));
- service.getEvents(dMaapContext, "testTopic", "CG1", "23");
- }
-
- @Test(expected = CambriaApiException.class)
- public void testPushEvents() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
- invalidSettingValue, loadException {
-
- // AdminUtils.createTopic(configurationReader.getZk(), "testTopic", 10,
- // 1, new Properties());
-
- configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
-
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
-
- service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
-
- service.getEvents(dMaapContext, "testTopic", "CG1", "23");
-
- /*
- * String trueValue = "True";
- * assertTrue(trueValue.equalsIgnoreCase("True"));
- */
-
- }
-
- @Test(expected = CambriaApiException.class)
- public void testPushEventsBlackListedIp() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
- invalidSettingValue, loadException {
-
- // AdminUtils.createTopic(configurationReader.getZk(), "testTopic", 10,
- // 1, new Properties());
- when(blacklist.contains(anyString())).thenReturn(true);
- when(configurationReader.getfIpBlackList()).thenReturn(blacklist);
- configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
-
- service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
-
- }
-
- @Test(expected = NullPointerException.class)
- public void testPushEventsNoUser() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
- invalidSettingValue, loadException {
-
- configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
-
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(null);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- MockHttpServletRequest mockRequest = new MockHttpServletRequest();
- mockRequest.addHeader("Authorization", "passed");
- mockRequest.addHeader("Authorization", "passed");
- dMaapContext.setRequest(mockRequest);
- dMaapContext.getRequest().getHeader("Authorization");
- service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
-
- }
-
- @Test(expected = CambriaApiException.class)
- public void testPushEventsWtTransaction() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
- invalidSettingValue, loadException {
-
- configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
-
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "transidUEBtopicreqd")).thenReturn("true");
-
- service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
-
- }
-
- @Test(expected = CambriaApiException.class)
- public void testPushEventsWtTransactionError() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
- TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
- invalidSettingValue, loadException {
-
- configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
-
- when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
- when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
- PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "transidUEBtopicreqd")).thenReturn("true");
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "event.batch.length")).thenReturn("0");
- when(configurationReader.getfPublisher()).thenThrow(new ConcurrentModificationException("Error occurred"));
-
- service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
-
- }
-
- @Test
- public void testIsTransEnabled1() {
-
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
- "transidUEBtopicreqd")).thenReturn("true");
- assertTrue(service.isTransEnabled());
-
- }
- @Test
- public void testIsTransEnabled2() {
-
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
- "transidUEBtopicreqd")).thenReturn("false");
- assertFalse(service.isTransEnabled());
-
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/JUnitTestSuite.java b/src/test/java/com/att/nsa/cambria/service/impl/JUnitTestSuite.java
deleted file mode 100644
index 8abafcc..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/JUnitTestSuite.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import junit.framework.TestSuite;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-import org.apache.log4j.Logger;
-
-@RunWith(Suite.class)
-@SuiteClasses({ UIServiceImplTest.class, AdminServiceImplemTest.class, ApiKeysServiceImplTest.class,
- ShowConsumerCacheTest.class,TopicServiceImplTest.class, TransactionServiceImplTest.class, MMServiceImplTest.class,
- BaseTransactionDbImplTest.class, MetricsServiceImplTest.class,EventsServiceImplTest.class})
-public class JUnitTestSuite {
- private static final Logger LOGGER = Logger.getLogger(JUnitTestSuite.class);
-
- public static void main(String[] args) {
- LOGGER.info("Running the test suite");
-
- TestSuite tstSuite = new TestSuite();
- LOGGER.info("Total Test Counts " + tstSuite.countTestCases());
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/MMServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/MMServiceImplTest.java
deleted file mode 100644
index f97952c..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/MMServiceImplTest.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.ConcurrentModificationException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import com.att.ajsc.beans.PropertiesMapBean;
-import com.att.ajsc.filemonitor.AJSCPropertiesMap;
-import com.att.dmf.mr.CambriaApiException;
-import com.att.dmf.mr.backends.ConsumerFactory;
-import com.att.dmf.mr.backends.ConsumerFactory.UnavailableException;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.beans.DMaaPKafkaMetaBroker;
-import com.att.dmf.mr.constants.CambriaConstants;
-import com.att.dmf.mr.exception.DMaaPErrorMessages;
-import com.att.dmf.mr.metabroker.Topic;
-import com.att.dmf.mr.metabroker.Broker.TopicExistsException;
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;
-import com.att.dmf.mr.service.impl.MMServiceImpl;
-import com.att.dmf.mr.utils.ConfigurationReader;
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;
-import com.att.dmf.mr.utils.Emailer;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
-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.simple.NsaSimpleApiKey;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import static org.mockito.Matchers.anyString;
-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;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class, PropertiesMapBean.class,
- AJSCPropertiesMap.class })
-public class MMServiceImplTest {
-
- @InjectMocks
- MMServiceImpl service;
-
- @Mock
- DMaaPContext dmaapContext;
- @Mock
- ConsumerFactory factory;
- @Mock
- private DMaaPErrorMessages errorMessages;
- @Mock
- ConfigurationReader configReader;
- @Mock
- Blacklist Blacklist;
- @Mock
- Emailer emailer;
- @Mock
- DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
- @Mock
- Topic metatopic;
-
- @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);
-
- MockHttpServletRequest request = new MockHttpServletRequest();
- MockHttpServletResponse response = new MockHttpServletResponse();
- PowerMockito.when(dmaapContext.getRequest()).thenReturn(request);
- PowerMockito.when(dmaapContext.getResponse()).thenReturn(response);
-
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(PropertiesMapBean.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "timeout")).thenReturn("1000");
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "pretty")).thenReturn("true");
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "meta")).thenReturn("true");
- PowerMockito.when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
-
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testSubscribe_Blacklistip() {
-
- try {
- PowerMockito.when(Blacklist.contains("127.0.0.1")).thenReturn(true);
- service.subscribe(dmaapContext, "testTopic", "CG1", "23");
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- } catch (CambriaApiException e) {
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TopicExistsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (AccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (UnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- @Test
- public void testSubscribe_NullTopic() {
-
- try {
- PowerMockito.when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
- service.subscribe(dmaapContext, "testTopic", "CG1", "23");
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- assertTrue(true);
- } catch (CambriaApiException e) {
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TopicExistsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (AccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (UnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- @Test(expected = CambriaApiException.class)
- public void testSubscribe_NullTopic_Error() throws ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException,
- CambriaApiException, IOException {
-
- PowerMockito.when(configReader.getfMetrics()).thenThrow(new ConcurrentModificationException("Error occurred"));
- PowerMockito.when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(metatopic);
- service.subscribe(dmaapContext, "testTopic", "CG1", "23");
- }
-
- @Test
- public void testPushEvents_wttransaction() {
-
- String source = "source of my InputStream";
-
- try {
- InputStream iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));
- service.pushEvents(dmaapContext, "msgrtr.apinode.metrics.dmaap", iStream, "3", "12:00:00");
-
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- assertTrue(true);
- } catch (CambriaApiException e) {
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TopicExistsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (AccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (missingReqdSetting e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Test(expected = CambriaApiException.class)
- public void testPushEvents_wttransaction_error() throws Exception {
-
- String source = "source of my InputStream";
-
- InputStream iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(PropertiesMapBean.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "event.batch.length")).thenReturn("-5");
- PowerMockito.when(configReader.getfPublisher()).thenThrow(new ConcurrentModificationException("Error occurred"));
- service.pushEvents(dmaapContext, "msgrtr.apinode.metrics.dmaap1", iStream, "3", "12:00:00");
-
- }
-
- @Test
- public void testPushEvents() {
-
- String source = "source of my InputStream";
-
- try {
- InputStream iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));
- service.pushEvents(dmaapContext, "testTopic", iStream, "3", "12:00:00");
-
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- assertTrue(true);
- } catch (CambriaApiException e) {
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TopicExistsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (AccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (missingReqdSetting e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- @Test
- public void testPushEvents_blacklistip() {
-
- String source = "source of my InputStream";
-
- try {
- PowerMockito.when(Blacklist.contains("127.0.0.1")).thenReturn(true);
- InputStream iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));
- service.pushEvents(dmaapContext, "testTopic", iStream, "3", "12:00:00");
-
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- assertTrue(true);
- } catch (CambriaApiException e) {
- assertTrue(true);
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TopicExistsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (AccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (missingReqdSetting 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
-
- }
- };
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/MessageTest.java b/src/test/java/com/att/nsa/cambria/service/impl/MessageTest.java
deleted file mode 100644
index 1d5c9c0..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/MessageTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import com.att.dmf.mr.backends.Publisher.message;
-import com.att.dmf.mr.beans.LogDetails;
-
-public class MessageTest implements message {
-
- @Override
- public String getKey() {
- // TODO Auto-generated method stub
- return "123";
- }
-
- @Override
- public String getMessage() {
- // TODO Auto-generated method stub
- return "Msg";
- }
-
- @Override
- public void setLogDetails(LogDetails logDetails) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public LogDetails getLogDetails() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean isTransactionEnabled() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void setTransactionEnabled(boolean transactionEnabled) {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/MetricsServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/MetricsServiceImplTest.java
deleted file mode 100644
index e372d38..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/MetricsServiceImplTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.att.dmf.mr.CambriaApiException;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.service.impl.MetricsServiceImpl;
-
-public class MetricsServiceImplTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testGet() {
-
- MetricsServiceImpl service = new MetricsServiceImpl();
- try {
- service.get(new DMaaPContext());
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- assertTrue(true);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
-
- @Test
- public void testGetMetricByName() {
-
- MetricsServiceImpl service = new MetricsServiceImpl();
- try {
- service.getMetricByName(new DMaaPContext(), "uptime");
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- assertTrue(true);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (CambriaApiException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java b/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java
deleted file mode 100644
index 4dd3076..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.junit.Assert;
-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;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import com.att.aft.dme2.internal.jettison.json.JSONArray;
-import com.att.aft.dme2.internal.jettison.json.JSONException;
-import com.att.aft.dme2.internal.jettison.json.JSONObject;
-
-import com.att.ajsc.beans.PropertiesMapBean;
-import com.att.dmf.mr.CambriaApiException;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.beans.DMaaPKafkaMetaBroker;
-import com.att.dmf.mr.CambriaApiException;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.beans.TopicBean;
-import com.att.dmf.mr.constants.CambriaConstants;
-import com.att.dmf.mr.exception.DMaaPAccessDeniedException;
-import com.att.dmf.mr.exception.DMaaPErrorMessages;
-import com.att.dmf.mr.metabroker.Broker.TopicExistsException;
-import com.att.dmf.mr.metabroker.Topic;
-import com.att.dmf.mr.security.DMaaPAuthenticator;
-import com.att.dmf.mr.utils.ConfigurationReader;
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;
-import com.att.nsa.security.NsaApiKey;
-import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-
-import jline.internal.Log;
-import kafka.consumer.Consumer;
-
-
-
-//@RunWith(MockitoJUnitRunner.class)
-//@RunWith(PowerMockRunner.class)
-//@PrepareForTest(PropertiesMapBean.class)
-public class ShowConsumerCacheTest {
-/*
-@InjectMocks
-TopicServiceImpl topicService;
-
-@Mock
-private DMaaPErrorMessages errorMessages;
-
-@Mock
-DMaaPContext dmaapContext;
-
-@Mock
-ConfigurationReader configReader;
-
-
-@Mock
-JSONObject consumers;
-
-@Mock
-JSONObject consumerObject;
-
-@Mock
-JSONArray jsonConsumersList;
-
-@Mock
-DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
-
-@Mock
-NsaApiKey user;
-
-@Mock
-NsaSimpleApiKey nsaSimpleApiKey;
-
-@Mock
-HttpServletRequest httpServReq;
-
-
-@Before
-public void setUp(){
-MockitoAnnotations.initMocks(this);
-}
-
-
-//@Test(expected = DMaaPAccessDeniedException.class)
-@Test
-public void testShowConsmerCache()throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException, JSONException{
-Assert.assertNotNull(topicService);
-
-String myName = "Brian";
-Object created = null;
-Object accessed = null;
-Object log = null;
-Object info = null;
-
-when(consumerObject.put("name", myName)).thenReturn(consumerObject);
-when(consumerObject.put("created", created)).thenReturn(consumerObject);
-when(consumerObject.put("accessed", accessed)).thenReturn(consumerObject);
-when(consumerObject.put("accessed", Consumer.class)).thenReturn(consumerObject);
-when(jsonConsumersList.put(consumerObject)).thenReturn(null);
-
-when(consumers.put("consumers", jsonConsumersList)).thenReturn(consumerObject);
-
-
-
-}*/
-
-
-} \ No newline at end of file
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/TestRunner.java b/src/test/java/com/att/nsa/cambria/service/impl/TestRunner.java
deleted file mode 100644
index cf240b7..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/TestRunner.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
-import org.junit.runner.notification.Failure;
-import org.apache.log4j.Logger;
-
-public class TestRunner {
- private static final Logger LOGGER = Logger.getLogger(TestRunner.class);
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Result result = JUnitCore.runClasses(JUnitTestSuite.class);
- for (Failure failure : result.getFailures()) {
- LOGGER.info(failure.toString());
-
- }
- LOGGER.info(result.wasSuccessful());
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java
deleted file mode 100644
index 47b351e..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java
+++ /dev/null
@@ -1,766 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashSet;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-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;
-
-import com.att.ajsc.beans.PropertiesMapBean;
-import com.att.ajsc.filemonitor.AJSCPropertiesMap;
-import com.att.dmf.mr.CambriaApiException;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.beans.DMaaPKafkaMetaBroker;
-import com.att.dmf.mr.beans.TopicBean;
-import com.att.dmf.mr.constants.CambriaConstants;
-import com.att.dmf.mr.exception.DMaaPAccessDeniedException;
-import com.att.dmf.mr.exception.DMaaPErrorMessages;
-import com.att.dmf.mr.metabroker.Broker.TopicExistsException;
-import com.att.dmf.mr.metabroker.Topic;
-import com.att.dmf.mr.security.DMaaPAAFAuthenticator;
-import com.att.dmf.mr.security.DMaaPAuthenticator;
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;
-import com.att.dmf.mr.service.impl.TopicServiceImpl;
-import com.att.dmf.mr.utils.ConfigurationReader;
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.security.NsaAcl;
-import com.att.nsa.security.NsaApiKey;
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-
-//@RunWith(MockitoJUnitRunner.class)
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ PropertiesMapBean.class, DMaaPAuthenticatorImpl.class,AJSCPropertiesMap.class,DMaaPResponseBuilder.class })
-public class TopicServiceImplTest {
-
- TopicServiceImpl topicService;
-
- @Mock
- private DMaaPErrorMessages errorMessages;
-
- @Mock
- DMaaPContext dmaapContext;
-
- @Mock
- ConfigurationReader configReader;
-
- @Mock
- ServletOutputStream oStream;
-
- @Mock
- DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
-
- @Mock
- DMaaPAAFAuthenticator dmaapAAFauthenticator;
- @Mock
- NsaApiKey user;
-
- @Mock
- NsaSimpleApiKey nsaSimpleApiKey;
-
- @Mock
- HttpServletRequest httpServReq;
-
- @Mock
- HttpServletResponse httpServRes;
-
- @Mock
- DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
-
- @Mock
- Topic createdTopic;
-
- @Mock
- NsaAcl nsaAcl;
-
- @Mock
- JSONObject jsonObj;
-
- @Mock
- JSONArray jsonArray;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- topicService = new TopicServiceImpl();
- topicService.setErrorMessages(errorMessages);
- NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
- PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
- PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
- }
-
- @Test(expected = NullPointerException.class)
- public void testCreateTopicWithEnforcedName()
- throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
-
- Assert.assertNotNull(topicService);
- PowerMockito.mockStatic(PropertiesMapBean.class);
-
- when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
- .thenReturn("enfTopicName");
-
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
-
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
- topicService.createTopic(dmaapContext, topicBean);
- }
-
- @Test
- public void testCreateTopicWithTopicNameNotEnforced()
- throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,IOException,TopicExistsException, com.att.dmf.mr.metabroker.Broker1.TopicExistsException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(PropertiesMapBean.class);
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
-
- when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
- .thenReturn("enfTopicName");
-
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
-
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
-
- when(nsaAcl.isActive()).thenReturn(true);
- when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
-
- when(createdTopic.getName()).thenReturn("topicName");
- when(createdTopic.getOwner()).thenReturn("Owner");
- when(createdTopic.getDescription()).thenReturn("Description");
- when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
- when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
-
- when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
- .thenReturn(createdTopic);
-
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("NotEnforcedTopicName");
-
- topicService.createTopic(dmaapContext, topicBean);
-
- verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
- anyBoolean());
- }
-
- @Test(expected = NullPointerException.class)
- public void testCreateTopicNoUserInContextAndNoAuthHeader()
- throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(PropertiesMapBean.class);
-
- when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
- .thenReturn("enfTopicName");
-
- when(httpServReq.getHeader("Authorization")).thenReturn(null);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
-
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
- topicService.createTopic(dmaapContext, topicBean);
- }
-
- @Test(expected = NullPointerException.class)
- public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
- throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(PropertiesMapBean.class);
-
- when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
- .thenReturn("enfTopicName");
-
- when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
-
- // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
- // anyString())).thenReturn(false);
-
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
- topicService.createTopic(dmaapContext, topicBean);
- }
-
- @Test(expected = TopicExistsException.class)
- public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException {
-
- Assert.assertNotNull(topicService);
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
-
- topicService.getTopic(dmaapContext, "topicName");
- }
-
- @Test
- public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException {
-
- Assert.assertNotNull(topicService);
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
-
- when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
-
- when(createdTopic.getName()).thenReturn("topicName");
- when(createdTopic.getDescription()).thenReturn("topicDescription");
- when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
-
- when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
- when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
-
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(httpServRes.getOutputStream()).thenReturn(oStream);
-
- topicService.getTopic(dmaapContext, "topicName");
- }
-
- @Test(expected = TopicExistsException.class)
- public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
-
- topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
-
- }
-
- @Test
- public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
- when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
- topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
- }
-
- @Test(expected = TopicExistsException.class)
- public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
-
- topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
-
- }
-
- @Test
- public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-
- when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
-
- topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
- }
-
- @Test
- public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
-
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
-
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("topicFactoryAAF");
-
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-
- when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
-
- topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
- }
-
- @Test(expected=TopicExistsException.class)
- public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
-
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
-
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("topicFactoryAAF");
-
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
-
- when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
-
- topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
- }
-
- @Test
- public void testdeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
- }
-
- @Test(expected=TopicExistsException.class)
- public void testdeleteTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
- }
-
- /*@Test(expected=DMaaPAccessDeniedException.class)
- public void testdeleteTopic_authHeader() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
- PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(null);
- topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
- }*/
-
- @Test
- public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
- }
-
- @Test(expected=TopicExistsException.class)
- public void testPermitConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
- }
-
- @Test
- public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
- }
-
- @Test(expected=TopicExistsException.class)
- public void testdenyConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
- }
-
-
- @Test
- public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
- }
-
- @Test(expected=TopicExistsException.class)
- public void testPermitPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
- }
-
- @Test
- public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
- }
-
- @Test(expected=TopicExistsException.class)
- public void testDenyPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
-
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
- }
-
- @Test
- public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.getAllTopics(dmaapContext);
- }
-
- @Test
- public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-
- Assert.assertNotNull(topicService);
-
- // PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
- PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
- .thenReturn("hello");
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
- TopicBean topicBean = new TopicBean();
- topicBean.setTopicName("enfTopicNamePlusExtra");
-
- topicService.getTopics(dmaapContext);
- }
-
-
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/TransactionServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/TransactionServiceImplTest.java
deleted file mode 100644
index d7fcde4..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/TransactionServiceImplTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import com.att.aft.dme2.internal.jettison.json.JSONException;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.service.impl.TransactionServiceImpl;
-import com.att.dmf.mr.transaction.TransactionObj;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TransactionServiceImplTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testCheckTransaction() {
-
- TransactionServiceImpl service = new TransactionServiceImpl();
- service.checkTransaction(new TransactionObj("23", 1100, 1000, 10));
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
- @Test
- public void testGetAllTransactionObjs() {
-
- TransactionServiceImpl service = new TransactionServiceImpl();
- try {
- service.getAllTransactionObjs(new DMaaPContext());
- } catch (ConfigDbException | IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
- @Test
- public void testGetTransactionObj() {
-
- TransactionServiceImpl service = new TransactionServiceImpl();
- try {
- service.getTransactionObj(new DMaaPContext(), "23");
- } catch (ConfigDbException | IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/UIServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/UIServiceImplTest.java
deleted file mode 100644
index d47c2d6..0000000
--- a/src/test/java/com/att/nsa/cambria/service/impl/UIServiceImplTest.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*-
- * ============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 com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.att.dmf.mr.backends.ConsumerFactory;
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.beans.DMaaPKafkaMetaBroker;
-import com.att.dmf.mr.metabroker.Topic;
-import com.att.dmf.mr.service.impl.UIServiceImpl;
-import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;
-import com.att.dmf.mr.utils.ConfigurationReader;
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;
-import com.att.nsa.configs.ConfigDbException;
-import com.att.nsa.security.db.NsaApiDb;
-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 UIServiceImplTest {
-
- @InjectMocks
- UIServiceImpl service;
-
- @Mock
- DMaaPContext dmaapContext;
- @Mock
- ConsumerFactory factory;
-
- @Mock
- ConfigurationReader configReader;
-
- @Mock
- DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
-
- @Mock
- Topic metatopic;
-
- @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.getfApiKeyDb()).thenReturn(fApiKeyDb);
- PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
- PowerMockito.when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testHello() {
-
- try {
- service.hello(dmaapContext);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
-
- }
-
- @Test
- public void testGetApiKeysTable() {
-
- try {
- service.getApiKeysTable(dmaapContext);
- } 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();
- }
- assertTrue(true);
-
- }
-
- @Test
- public void testGetApiKey() {
-
- try {
- service.getApiKey(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 (Exception e) {
- // TODO Auto-generated catch block
- assertTrue(true);
- }
-
- }
-
- @Test
- public void testGetApiKey_invalidkey() {
-
- try {
- service.getApiKey(dmaapContext, "k56HmWT72J");
- } 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 (Exception e) {
- // TODO Auto-generated catch block
- assertTrue(true);
- }
-
- }
-
- @Test
- public void testGetTopicsTable() {
-
- try {
- List<Topic> topics = new ArrayList<Topic>();
- topics.add(metatopic);
- when(dmaapKafkaMetaBroker.getAllTopics()).thenReturn(topics);
- service.getTopicsTable(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();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- assertTrue(true);
-
- }
-
- @Test
- public void testGetTopic() {
-
- try {
- when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(metatopic);
- service.getTopic(dmaapContext, "testTopic");
- } 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 (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- assertTrue(true);
- }
-
- @Test
- public void testGetTopic_nulltopic() {
-
- try {
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
- service.getTopic(dmaapContext, "testTopic");
- } 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 (Exception e) {
- // TODO Auto-generated catch block
- assertTrue(true);
- }
-
- }
-
- 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 {
- Map<String, NsaSimpleApiKey> map = new HashMap<String, NsaSimpleApiKey>();
- map.put("testkey", new NsaSimpleApiKey("testkey", "password"));
- map.put("admin", new NsaSimpleApiKey("admin", "password"));
-
- return map;
- }
-
- @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
-
- }
- };
-
-}