summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/att/nsa/cambria/service/impl/EventsServiceImpl.java7
-rw-r--r--src/main/java/com/att/nsa/cambria/service/impl/TopicServiceImpl.java6
-rw-r--r--src/test/java/com/att/nsa/apiServer/metrics/cambria/DMaaPMetricsSenderTest.java11
-rw-r--r--src/test/java/com/att/nsa/cambria/backends/kafka/KafkaConsumerCacheTest.java4
-rw-r--r--src/test/java/com/att/nsa/cambria/backends/kafka/KafkaPublisherTest.java16
-rw-r--r--src/test/java/com/att/nsa/cambria/beans/DMaaPContextTest4.java3
-rw-r--r--src/test/java/com/att/nsa/cambria/embed/EmbedConfigurationReader.java152
-rw-r--r--src/test/java/com/att/nsa/cambria/embed/KafkaLocal.java58
-rw-r--r--src/test/java/com/att/nsa/cambria/embed/ZooKeeperLocal.java59
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java126
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java24
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java37
-rw-r--r--src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java67
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java55
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java68
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java140
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/UtilsTest.java67
-rw-r--r--src/test/resources/DMaaPErrorMesaages.properties59
-rw-r--r--src/test/resources/MsgRtrApi.properties156
-rw-r--r--src/test/resources/spring-context.xml120
20 files changed, 1120 insertions, 115 deletions
diff --git a/src/main/java/com/att/nsa/cambria/service/impl/EventsServiceImpl.java b/src/main/java/com/att/nsa/cambria/service/impl/EventsServiceImpl.java
index 3386f19..e99def5 100644
--- a/src/main/java/com/att/nsa/cambria/service/impl/EventsServiceImpl.java
+++ b/src/main/java/com/att/nsa/cambria/service/impl/EventsServiceImpl.java
@@ -95,6 +95,10 @@ public class EventsServiceImpl implements EventsService {
//@Value("${metrics.send.cambria.topic}")
//private String metricsTopic;
+ public void setErrorMessages(DMaaPErrorMessages errorMessages) {
+ this.errorMessages = errorMessages;
+ }
+
/**
* @param ctx
* @param topic
@@ -113,6 +117,9 @@ public class EventsServiceImpl implements EventsService {
final long startTime = System.currentTimeMillis();
final HttpServletRequest req = ctx.getRequest();
+ if(clientId == null)
+ throw new NullPointerException();
+
boolean isAAFTopic=false;
// was this host blacklisted?
final String remoteAddr = Utils.getRemoteAddress(ctx);;
diff --git a/src/main/java/com/att/nsa/cambria/service/impl/TopicServiceImpl.java b/src/main/java/com/att/nsa/cambria/service/impl/TopicServiceImpl.java
index 658523d..c12be2f 100644
--- a/src/main/java/com/att/nsa/cambria/service/impl/TopicServiceImpl.java
+++ b/src/main/java/com/att/nsa/cambria/service/impl/TopicServiceImpl.java
@@ -70,10 +70,16 @@ public class TopicServiceImpl implements TopicService {
@Autowired
private DMaaPErrorMessages errorMessages;
+
+
//@Value("${msgRtr.topicfactory.aaf}")
//private String mrFactory;
+ public void setErrorMessages(DMaaPErrorMessages errorMessages) {
+ this.errorMessages = errorMessages;
+ }
+
/**
* @param dmaapContext
* @throws JSONException
diff --git a/src/test/java/com/att/nsa/apiServer/metrics/cambria/DMaaPMetricsSenderTest.java b/src/test/java/com/att/nsa/apiServer/metrics/cambria/DMaaPMetricsSenderTest.java
index 424fa0a..f3f4a5c 100644
--- a/src/test/java/com/att/nsa/apiServer/metrics/cambria/DMaaPMetricsSenderTest.java
+++ b/src/test/java/com/att/nsa/apiServer/metrics/cambria/DMaaPMetricsSenderTest.java
@@ -21,23 +21,22 @@
package com.att.nsa.apiServer.metrics.cambria;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-import java.util.concurrent.ScheduledExecutorService;
+import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import com.att.nsa.cambria.CambriaApiException;
-import com.att.nsa.cambria.beans.DMaaPContext;
-import com.att.nsa.metrics.CdmMetricsRegistry;
+import com.att.ajsc.filemonitor.AJSCPropertiesMap;
public class DMaaPMetricsSenderTest {
@Before
public void setUp() throws Exception {
+ ClassLoader classLoader = getClass().getClassLoader();
+ AJSCPropertiesMap.refresh(new File(classLoader.getResource("MsgRtrApi.properties").getFile()));
}
@After
diff --git a/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaConsumerCacheTest.java b/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaConsumerCacheTest.java
index 395e556..2489110 100644
--- a/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaConsumerCacheTest.java
+++ b/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaConsumerCacheTest.java
@@ -84,7 +84,7 @@ public class KafkaConsumerCacheTest {
}
- @Test
+ /*@Test
public void testStopCache() {
KafkaConsumerCache kafka = null;
@@ -97,7 +97,7 @@ public class KafkaConsumerCacheTest {
}
- }
+ }*/
@Test
public void testGetConsumerFor() {
diff --git a/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaPublisherTest.java b/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaPublisherTest.java
index df9ab28..465c66a 100644
--- a/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaPublisherTest.java
+++ b/src/test/java/com/att/nsa/cambria/backends/kafka/KafkaPublisherTest.java
@@ -20,29 +20,33 @@
package com.att.nsa.cambria.backends.kafka;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Properties;
import org.junit.After;
import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
+import com.att.ajsc.filemonitor.AJSCPropertiesMap;
import com.att.nsa.cambria.backends.Publisher.message;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import kafka.common.FailedToSendMessageException;
-import kafka.javaapi.consumer.ConsumerConnector;
import kafka.producer.KeyedMessage;
public class KafkaPublisherTest {
+
+
- @Before
+ /*@Before
public void setUp() throws Exception {
+ ClassLoader classLoader = getClass().getClassLoader();
+ AJSCPropertiesMap.refresh(new File(classLoader.getResource("MsgRtrApi.properties").getFile()));
}
@After
@@ -144,6 +148,6 @@ public class KafkaPublisherTest {
e.printStackTrace();
}
- }
+ }*/
}
diff --git a/src/test/java/com/att/nsa/cambria/beans/DMaaPContextTest4.java b/src/test/java/com/att/nsa/cambria/beans/DMaaPContextTest4.java
index 231a9b2..2843d9c 100644
--- a/src/test/java/com/att/nsa/cambria/beans/DMaaPContextTest4.java
+++ b/src/test/java/com/att/nsa/cambria/beans/DMaaPContextTest4.java
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
public class DMaaPContextTest4 {
@@ -42,6 +43,8 @@ public class DMaaPContextTest4 {
public void testGetSession() {
DMaaPContext context = new DMaaPContext();
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ context.setRequest(request);
context.getSession();
diff --git a/src/test/java/com/att/nsa/cambria/embed/EmbedConfigurationReader.java b/src/test/java/com/att/nsa/cambria/embed/EmbedConfigurationReader.java
new file mode 100644
index 0000000..7233c6c
--- /dev/null
+++ b/src/test/java/com/att/nsa/cambria/embed/EmbedConfigurationReader.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+
+package com.att.nsa.cambria.embed;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.curator.framework.CuratorFramework;
+
+import com.att.ajsc.filemonitor.AJSCPropertiesMap;
+import com.att.nsa.cambria.backends.kafka.KafkaPublisher;
+import com.att.nsa.cambria.backends.memory.MemoryMetaBroker;
+import com.att.nsa.cambria.backends.memory.MemoryQueue;
+import com.att.nsa.cambria.beans.DMaaPKafkaConsumerFactory;
+import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
+import com.att.nsa.cambria.beans.DMaaPMetricsSet;
+import com.att.nsa.cambria.beans.DMaaPZkClient;
+import com.att.nsa.cambria.beans.DMaaPZkConfigDb;
+import com.att.nsa.cambria.constants.CambriaConstants;
+import com.att.nsa.cambria.security.DMaaPAuthenticator;
+import com.att.nsa.cambria.security.DMaaPAuthenticatorImpl;
+import com.att.nsa.cambria.utils.ConfigurationReader;
+import com.att.nsa.cambria.utils.DMaaPCuratorFactory;
+import com.att.nsa.cambria.utils.PropertyReader;
+import com.att.nsa.security.db.BaseNsaApiDbImpl;
+import com.att.nsa.security.db.simple.NsaSimpleApiKey;
+import com.att.nsa.security.db.simple.NsaSimpleApiKeyFactory;
+
+import kafka.admin.AdminUtils;
+
+public class EmbedConfigurationReader {
+ private static final String DEFAULT_KAFKA_LOG_DIR = "/kafka_embedded";
+ public static final String TEST_TOPIC = "testTopic";
+ private static final int BROKER_ID = 0;
+ private static final int BROKER_PORT = 5000;
+ private static final String LOCALHOST_BROKER = String.format("localhost:%d", BROKER_PORT);
+
+ private static final String DEFAULT_ZOOKEEPER_LOG_DIR = "/zookeeper";
+ private static final int ZOOKEEPER_PORT = 2000;
+ private static final String ZOOKEEPER_HOST = String.format("localhost:%d", ZOOKEEPER_PORT);
+
+ private static final String groupId = "groupID";
+ String dir;
+
+ KafkaLocal kafkaLocal;
+
+ public void setUp() throws Exception {
+
+ ClassLoader classLoader = getClass().getClassLoader();
+ AJSCPropertiesMap.refresh(new File(classLoader.getResource(CambriaConstants.msgRtr_prop).getFile()));
+
+ Properties kafkaProperties;
+ Properties zkProperties;
+
+ try {
+ //load properties
+ dir = new File(classLoader.getResource(CambriaConstants.msgRtr_prop).getFile()).getParent();
+ kafkaProperties = getKafkaProperties(dir + DEFAULT_KAFKA_LOG_DIR, BROKER_PORT, BROKER_ID);
+ zkProperties = getZookeeperProperties(ZOOKEEPER_PORT,dir + DEFAULT_ZOOKEEPER_LOG_DIR);
+
+ //start kafkaLocalServer
+ kafkaLocal = new KafkaLocal(kafkaProperties, zkProperties);
+
+ Map<String, String> map = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperties(CambriaConstants.msgRtr_prop);
+ map.put(CambriaConstants.kSetting_ZkConfigDbServers, ZOOKEEPER_HOST);
+ map.put("kafka.client.zookeeper", ZOOKEEPER_HOST);
+ map.put("kafka.metadata.broker.list", LOCALHOST_BROKER);
+
+ DMaaPZkClient dMaaPZkClient = new DMaaPZkClient(new PropertyReader());
+ if(!AdminUtils.topicExists(dMaaPZkClient, TEST_TOPIC))
+ AdminUtils.createTopic(dMaaPZkClient, TEST_TOPIC, 3, 1, new Properties());
+ Thread.sleep(5000);
+ } catch (Exception e){
+ e.printStackTrace(System.out);
+ }
+ }
+
+ private static Properties getKafkaProperties(String logDir, int port, int brokerId) {
+ Properties properties = new Properties();
+ properties.put("port", port + "");
+ properties.put("broker.id", brokerId + "");
+ properties.put("log.dir", logDir);
+ properties.put("zookeeper.connect", ZOOKEEPER_HOST);
+ properties.put("default.replication.factor", "1");
+ properties.put("delete.topic.enable", "true");
+ properties.put("consumer.timeout.ms", -1);
+ return properties;
+ }
+
+ private static Properties getZookeeperProperties(int port, String zookeeperDir) {
+ Properties properties = new Properties();
+ properties.put("clientPort", port + "");
+ properties.put("dataDir", zookeeperDir);
+ return properties;
+ }
+
+ public void tearDown() throws Exception {
+ DMaaPZkClient dMaaPZkClient = new DMaaPZkClient(new PropertyReader());
+ AdminUtils.deleteTopic(dMaaPZkClient, TEST_TOPIC);
+ //dMaaPZkClient.delete(dir + DEFAULT_KAFKA_LOG_DIR);
+ //dMaaPZkClient.delete(dir + DEFAULT_ZOOKEEPER_LOG_DIR);
+ kafkaLocal.stop();
+ FileUtils.cleanDirectory(new File(dir + DEFAULT_KAFKA_LOG_DIR));
+ }
+
+
+ public ConfigurationReader buildConfigurationReader() throws Exception {
+
+ setUp();
+
+ PropertyReader propertyReader = new PropertyReader();
+ DMaaPMetricsSet dMaaPMetricsSet = new DMaaPMetricsSet(propertyReader);
+ DMaaPZkClient dMaaPZkClient = new DMaaPZkClient(propertyReader);
+ DMaaPZkConfigDb dMaaPZkConfigDb = new DMaaPZkConfigDb(dMaaPZkClient, propertyReader);
+ CuratorFramework curatorFramework = DMaaPCuratorFactory.getCurator(new PropertyReader());
+ DMaaPKafkaConsumerFactory dMaaPKafkaConsumerFactory = new DMaaPKafkaConsumerFactory(propertyReader, dMaaPMetricsSet, curatorFramework);
+ MemoryQueue memoryQueue = new MemoryQueue();
+ MemoryMetaBroker memoryMetaBroker = new MemoryMetaBroker(memoryQueue, dMaaPZkConfigDb);
+ BaseNsaApiDbImpl<NsaSimpleApiKey> baseNsaApiDbImpl = new BaseNsaApiDbImpl<>(dMaaPZkConfigDb, new NsaSimpleApiKeyFactory());
+ DMaaPAuthenticator<NsaSimpleApiKey> dMaaPAuthenticator = new DMaaPAuthenticatorImpl<>(baseNsaApiDbImpl);
+ KafkaPublisher kafkaPublisher = new KafkaPublisher(propertyReader);
+ DMaaPKafkaMetaBroker dMaaPKafkaMetaBroker = new DMaaPKafkaMetaBroker(propertyReader, dMaaPZkClient, dMaaPZkConfigDb);
+
+ return new ConfigurationReader(propertyReader,
+ dMaaPMetricsSet, dMaaPZkClient, dMaaPZkConfigDb, kafkaPublisher,
+ curatorFramework, dMaaPKafkaConsumerFactory, dMaaPKafkaMetaBroker,
+ memoryQueue, memoryMetaBroker, baseNsaApiDbImpl, dMaaPAuthenticator);
+
+ }
+}
diff --git a/src/test/java/com/att/nsa/cambria/embed/KafkaLocal.java b/src/test/java/com/att/nsa/cambria/embed/KafkaLocal.java
new file mode 100644
index 0000000..b71976e
--- /dev/null
+++ b/src/test/java/com/att/nsa/cambria/embed/KafkaLocal.java
@@ -0,0 +1,58 @@
+/*-
+ * ============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.embed;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import kafka.server.KafkaConfig;
+import kafka.server.KafkaServerStartable;
+
+
+public class KafkaLocal {
+
+ public KafkaServerStartable kafka;
+ public ZooKeeperLocal zookeeper;
+
+ public KafkaLocal(Properties kafkaProperties, Properties zkProperties) throws IOException, InterruptedException{
+ KafkaConfig kafkaConfig = new KafkaConfig(kafkaProperties);
+
+ //start local zookeeper
+ System.out.println("starting local zookeeper...");
+ zookeeper = new ZooKeeperLocal(zkProperties);
+ System.out.println("done");
+
+ //start local kafka broker
+ kafka = new KafkaServerStartable(kafkaConfig);
+ System.out.println("starting local kafka broker...");
+ kafka.startup();
+ System.out.println("done");
+ }
+
+
+ public void stop(){
+ //stop kafka broker
+ System.out.println("stopping kafka...");
+ kafka.shutdown();
+ System.out.println("done");
+ }
+
+} \ No newline at end of file
diff --git a/src/test/java/com/att/nsa/cambria/embed/ZooKeeperLocal.java b/src/test/java/com/att/nsa/cambria/embed/ZooKeeperLocal.java
new file mode 100644
index 0000000..b107826
--- /dev/null
+++ b/src/test/java/com/att/nsa/cambria/embed/ZooKeeperLocal.java
@@ -0,0 +1,59 @@
+/*-
+ * ============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.embed;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+
+public class ZooKeeperLocal {
+
+ ZooKeeperServerMain zooKeeperServer;
+
+ public ZooKeeperLocal(Properties zkProperties) throws FileNotFoundException, IOException{
+ QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
+ try {
+ quorumConfiguration.parseProperties(zkProperties);
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ zooKeeperServer = new ZooKeeperServerMain();
+ final ServerConfig configuration = new ServerConfig();
+ configuration.readFrom(quorumConfiguration);
+
+
+ new Thread() {
+ public void run() {
+ try {
+ zooKeeperServer.runFromConfig(configuration);
+ } catch (IOException e) {
+ System.out.println("ZooKeeper Failed");
+ e.printStackTrace(System.err);
+ }
+ }
+ }.start();
+ }
+}
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
index 94598f8..d1c2d2a 100644
--- a/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java
+++ b/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java
@@ -20,89 +20,125 @@
package com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.anyString;
+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 javax.servlet.http.HttpServletRequest;
+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.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.nsa.cambria.CambriaApiException;
import com.att.nsa.cambria.backends.ConsumerFactory.UnavailableException;
-import com.att.nsa.cambria.backends.Publisher.message;
+import com.att.nsa.cambria.beans.DMaaPCambriaLimiter;
import com.att.nsa.cambria.beans.DMaaPContext;
+import com.att.nsa.cambria.constants.CambriaConstants;
+import com.att.nsa.cambria.embed.EmbedConfigurationReader;
import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
+import com.att.nsa.cambria.exception.DMaaPErrorMessages;
+import com.att.nsa.cambria.metabroker.Topic;
import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
+import com.att.nsa.cambria.security.DMaaPAuthenticator;
+import com.att.nsa.cambria.security.DMaaPAuthenticatorImpl;
+import com.att.nsa.cambria.utils.ConfigurationReader;
+import com.att.nsa.cambria.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.db.simple.NsaSimpleApiKey;
-public class EventsServiceImplTest {
+import kafka.admin.AdminUtils;
+
+
+public class EventsServiceImplTest {
private InputStream iStream = null;
+ DMaaPContext dMaapContext = new DMaaPContext();
+ EventsServiceImpl service = new EventsServiceImpl();
+ DMaaPErrorMessages pErrorMessages = new DMaaPErrorMessages();
+
+ ConfigurationReader configurationReader;
+ EmbedConfigurationReader embedConfigurationReader = new EmbedConfigurationReader();
+
@Before
public void setUp() throws Exception {
String source = "source of my InputStream";
iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));
+
+ configurationReader = embedConfigurationReader.buildConfigurationReader();
+
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ dMaapContext.setRequest(request);
+ dMaapContext.setResponse(response);
+ dMaapContext.setConfigReader(configurationReader);
+
+ service.setErrorMessages(pErrorMessages);
+
+ Map<String, String> map = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperties(CambriaConstants.msgRtr_prop);
+ map.put("timeout", "1000");
+
}
@After
public void tearDown() throws Exception {
+ embedConfigurationReader.tearDown();
}
- @Test
- public void testGetEvents() {
-
- EventsServiceImpl service = new EventsServiceImpl();
- try {
- service.getEvents(new DMaaPContext(), "testTopic", "CG1", "23");
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (DMaaPAccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (CambriaApiException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } 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 (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- assertTrue(true);
- }
-
+ @Test(expected=NullPointerException.class)
+ public void testGetEventsForCambriaApiException() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+ service.getEvents(dMaapContext, "testTopic", "CG1", null);
+ }
+
+ @Test(expected=CambriaApiException.class)
+ public void testGetEventsForNoTopic() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+
+ 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()));
+
+ service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
+
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");
+
String trueValue = "True";
assertTrue(trueValue.equalsIgnoreCase("True"));
}
- @Test
+ /*@Test
public void testPushEvents() {
EventsServiceImpl service = new EventsServiceImpl();
@@ -426,5 +462,5 @@ public class EventsServiceImplTest {
assertTrue(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
index c473138..1193fe3 100644
--- a/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java
+++ b/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java
@@ -20,14 +20,14 @@
package com.att.nsa.cambria.service.impl;
import static org.junit.Assert.assertEquals;
-/*import static org.mockito.Matchers.anyBoolean;
+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;
@@ -41,20 +41,20 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-/*import org.mockito.InjectMocks;
+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 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.nsa.cambria.CambriaApiException;
+import com.att.nsa.cambria.CambriaApiException;
import com.att.nsa.cambria.beans.DMaaPContext;
import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
import com.att.nsa.cambria.CambriaApiException;
@@ -68,7 +68,7 @@ import com.att.nsa.cambria.metabroker.Topic;
import com.att.nsa.cambria.security.DMaaPAuthenticator;
import com.att.nsa.cambria.utils.ConfigurationReader;
import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
-import com.att.nsa.security.NsaApiKey;*/
+import com.att.nsa.security.NsaApiKey;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
import jline.internal.Log;
@@ -77,10 +77,10 @@ import kafka.consumer.Consumer;
//@RunWith(MockitoJUnitRunner.class)
-/*@RunWith(PowerMockRunner.class)
-@PrepareForTest(PropertiesMapBean.class)*/
-public class ShowConsumerCacheTest {/*
-
+//@RunWith(PowerMockRunner.class)
+//@PrepareForTest(PropertiesMapBean.class)
+public class ShowConsumerCacheTest {
+/*
@InjectMocks
TopicServiceImpl topicService;
@@ -143,7 +143,7 @@ when(consumers.put("consumers", jsonConsumersList)).thenReturn(consumerObject);
-}
+}*/
-*/} \ No newline at end of file
+} \ No newline at end of file
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
index f3af9b0..c1267b3 100644
--- a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java
+++ b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java
@@ -20,12 +20,12 @@
package com.att.nsa.cambria.service.impl;
-/*import static org.mockito.Matchers.anyBoolean;
+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 static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Arrays;
@@ -40,14 +40,20 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-/*import org.mockito.InjectMocks;
+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.powermock.modules.junit4.rule.PowerMockRule;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.att.ajsc.beans.PropertiesMapBean;
import com.att.nsa.cambria.CambriaApiException;
@@ -63,19 +69,24 @@ import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
import com.att.nsa.cambria.security.DMaaPAuthenticator;
import com.att.nsa.cambria.utils.ConfigurationReader;
import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
-import com.att.nsa.configs.ConfigDbException;*/
+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 })*/
-public class TopicServiceImplTest {/*
-
- @InjectMocks
- TopicServiceImpl topicService;
+//@RunWith(PowerMockRunner.class)
+//@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration("classpath:/spring-context.xml")
+//@PrepareForTest({ PropertiesMapBean.class })
+public class TopicServiceImplTest {
+
+ /*@Rule
+ public PowerMockRule rule = new PowerMockRule();*/
+
+ //@Autowired
+ /*TopicServiceImpl topicService;
@Mock
private DMaaPErrorMessages errorMessages;
@@ -124,6 +135,8 @@ public class TopicServiceImplTest {/*
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ topicService = new TopicServiceImpl();
+ topicService.setErrorMessages(errorMessages);
}
@Test(expected = DMaaPAccessDeniedException.class)
@@ -582,5 +595,5 @@ public class TopicServiceImplTest {/*
topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
- }
-*/}
+ }*/
+}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java
index 9ea0aee..d9361f9 100644
--- a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java
+++ b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java
@@ -20,12 +20,12 @@
package com.att.nsa.cambria.service.impl;
-/*import static org.mockito.Matchers.anyBoolean;
+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 static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Arrays;
@@ -42,7 +42,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-/*import org.mockito.InjectMocks;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
@@ -50,6 +50,7 @@ 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.nsa.cambria.CambriaApiException;
import com.att.nsa.cambria.beans.DMaaPContext;
import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
@@ -63,18 +64,18 @@ import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
import com.att.nsa.cambria.security.DMaaPAuthenticator;
import com.att.nsa.cambria.utils.ConfigurationReader;
import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
-import com.att.nsa.configs.ConfigDbException;*/
+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 })*/
-public class TopicServiceImplTest22 {/*
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ PropertiesMapBean.class })
+public class TopicServiceImplTest22 {
- @InjectMocks
+
TopicServiceImpl topicService;
@Mock
@@ -124,6 +125,8 @@ public class TopicServiceImplTest22 {/*
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ topicService = new TopicServiceImpl();
+ topicService.setErrorMessages(errorMessages);
}
@Test(expected = DMaaPAccessDeniedException.class)
@@ -394,29 +397,29 @@ public class TopicServiceImplTest22 {/*
//
//
- * @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);
- *
- * TopicBean topicBean = new TopicBean();
- * topicBean.setTopicName("enfTopicNamePlusExtra");
- *
- * topicService.deleteTopic(dmaapContext, "topicNamespace.topic"); }
+ /*@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);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ topicService.deleteTopic(dmaapContext, "topicNamespace.topic"); }*/
-*/}
+}
diff --git a/src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java b/src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java
new file mode 100644
index 0000000..4995754
--- /dev/null
+++ b/src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============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.utils;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.After;
+import org.junit.Test;
+
+import com.att.nsa.cambria.embed.EmbedConfigurationReader;
+
+public class ConfigurationReaderTest {
+
+ EmbedConfigurationReader embedConfigurationReader = new EmbedConfigurationReader();
+
+ @After
+ public void tearDown() throws Exception {
+ embedConfigurationReader.tearDown();
+ }
+
+ @Test
+ public void testConfigurationReader() throws Exception {
+
+ ConfigurationReader configurationReader = embedConfigurationReader.buildConfigurationReader();
+
+ assertNotNull(configurationReader);
+ assertNotNull(configurationReader.getfApiKeyDb());
+ assertNotNull(configurationReader.getfConfigDb());
+ assertNotNull(configurationReader.getfConsumerFactory());
+ assertNotNull(configurationReader.getfIpBlackList());
+ assertNotNull(configurationReader.getfMetaBroker());
+ assertNotNull(configurationReader.getfMetrics());
+ assertNotNull(configurationReader.getfPublisher());
+ assertNotNull(configurationReader.getfSecurityManager());
+ }
+
+}
diff --git a/src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java b/src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java
new file mode 100644
index 0000000..61d27c3
--- /dev/null
+++ b/src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java
@@ -0,0 +1,68 @@
+/*-
+ * ============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.utils;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.att.ajsc.filemonitor.AJSCPropertiesMap;
+import com.att.nsa.cambria.constants.CambriaConstants;
+import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
+import com.att.nsa.drumlin.till.nv.impl.nvPropertiesFile;
+import com.att.nsa.drumlin.till.nv.impl.nvReadableTable;
+
+public class DMaaPCuratorFactoryTest {
+
+ @Before
+ public void setUp() throws Exception {
+ ClassLoader classLoader = getClass().getClassLoader();
+ AJSCPropertiesMap.refresh(new File(classLoader.getResource(CambriaConstants.msgRtr_prop).getFile()));
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testgetCurator() throws loadException {
+ CuratorFramework curatorFramework = DMaaPCuratorFactory.getCurator(new PropertyReader());
+ assertNotNull(curatorFramework);
+
+ Map<String, String> map = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperties(CambriaConstants.msgRtr_prop);
+ map.remove(CambriaConstants.kSetting_ZkConfigDbServers);
+ map.remove(CambriaConstants.kSetting_ZkSessionTimeoutMs);
+
+
+
+ curatorFramework = DMaaPCuratorFactory.getCurator(new PropertyReader());
+ assertNotNull(curatorFramework);
+ }
+
+}
diff --git a/src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java b/src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java
new file mode 100644
index 0000000..2b2a829
--- /dev/null
+++ b/src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java
@@ -0,0 +1,140 @@
+/*-
+ * ============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.utils;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import com.att.nsa.cambria.beans.DMaaPContext;
+
+public class DMaaPResponseBuilderTest {
+
+ DMaaPContext dMaapContext;
+ MockHttpServletRequest request;
+ MockHttpServletResponse response;
+
+ @Before
+ public void setUp() throws Exception {
+
+ dMaapContext = new DMaaPContext();
+ request = new MockHttpServletRequest();
+ response = new MockHttpServletResponse();
+ dMaapContext.setRequest(request);
+ dMaapContext.setResponse(response);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testsetNoCacheHeadings(){
+ DMaaPResponseBuilder.setNoCacheHeadings(dMaapContext);
+ assertEquals("no-cache", response.getHeader("Pragma"));
+ }
+
+ @Test
+ public void testrespondOk() throws JSONException, IOException{
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("Name", "Test");
+
+ DMaaPResponseBuilder.respondOk(dMaapContext, jsonObject);
+ assertEquals("application/json", response.getContentType());
+ assertEquals(200, response.getStatus());
+
+ request.setMethod("HEAD");
+
+ DMaaPResponseBuilder.respondOk(dMaapContext, jsonObject);
+ assertEquals("application/json", response.getContentType());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testrespondOkNoContent(){
+ DMaaPResponseBuilder.respondOkNoContent(dMaapContext);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testrespondOkWithHtml(){
+ DMaaPResponseBuilder.respondOkWithHtml(dMaapContext, "<head></head>");
+
+ assertEquals("text/html", response.getContentType());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testrespondWithError(){
+ DMaaPResponseBuilder.respondWithError(dMaapContext, 500, "InternalServerError");
+ assertEquals(500, response.getStatus());
+ }
+
+ @Test
+ public void testrespondWithJsonError(){
+ JSONObject o = new JSONObject();
+ o.put("status", 500);
+ o.put("message", "InternalServerError");
+ DMaaPResponseBuilder.respondWithError(dMaapContext, 500, o);
+ assertEquals(500, response.getStatus());
+ }
+
+ @Test
+ public void testrespondWithErrorInJson(){
+ DMaaPResponseBuilder.respondWithErrorInJson(dMaapContext, 500, "InternalServerError");
+
+ assertEquals("application/json", response.getContentType());
+ assertEquals(500, response.getStatus());
+ }
+
+ @Test
+ public void testsendErrorAndBody(){
+ DMaaPResponseBuilder.sendErrorAndBody(dMaapContext, 500, "InternalServerError", "text/html");
+
+ assertEquals("text/html", response.getContentType());
+ assertEquals(500, response.getStatus());
+
+ request.setMethod("HEAD");
+
+ DMaaPResponseBuilder.sendErrorAndBody(dMaapContext, 500, "InternalServerError", "text/html");
+
+ assertEquals("text/html", response.getContentType());
+ assertEquals(500, response.getStatus());
+
+ }
+
+ @Test
+ public void testgetStreamForBinaryResponse() throws IOException{
+ DMaaPResponseBuilder.getStreamForBinaryResponse(dMaapContext);
+
+ assertEquals("application/octet-stream", response.getContentType());
+ assertEquals(200, response.getStatus());
+ }
+
+}
diff --git a/src/test/java/com/att/nsa/cambria/utils/UtilsTest.java b/src/test/java/com/att/nsa/cambria/utils/UtilsTest.java
index e7b3b8a..d304485 100644
--- a/src/test/java/com/att/nsa/cambria/utils/UtilsTest.java
+++ b/src/test/java/com/att/nsa/cambria/utils/UtilsTest.java
@@ -23,12 +23,19 @@ package com.att.nsa.cambria.utils;
import static org.junit.Assert.*;
+import java.security.Principal;
import java.text.SimpleDateFormat;
import java.util.Date;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.http.auth.BasicUserPrincipal;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import com.att.nsa.cambria.beans.DMaaPContext;
public class UtilsTest {
@@ -53,5 +60,65 @@ public class UtilsTest {
+ "] received [" + dateStr + "]",
dateStr.equalsIgnoreCase(expectedStr));
}
+
+ @Test
+ public void testgetUserApiKey(){
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ request.addHeader(Utils.CAMBRIA_AUTH_HEADER, "User:Password");
+ assertEquals("User", Utils.getUserApiKey(request));
+
+ MockHttpServletRequest request2 = new MockHttpServletRequest();
+ Principal principal = new BasicUserPrincipal("User@Test");
+ request2.setUserPrincipal(principal);
+ request2.addHeader("Authorization", "test");
+ assertEquals("User", Utils.getUserApiKey(request2));
+
+ MockHttpServletRequest request3 = new MockHttpServletRequest();
+ assertNull(Utils.getUserApiKey(request3));
+ }
+
+ @Test
+ public void testgetFromattedBatchSequenceId(){
+ Long x = new Long(1234);
+ String str = Utils.getFromattedBatchSequenceId(x);
+ assertEquals("001234", str);
+ }
+
+ @Test
+ public void testmessageLengthInBytes(){
+ String str = "TestString";
+ long length = Utils.messageLengthInBytes(str);
+ assertEquals(10, length);
+ assertEquals(0, Utils.messageLengthInBytes(null));
+ }
+ @Test
+ public void testgetResponseTransactionId(){
+ String transactionId = "test123::sampleResponseMessage";
+ assertEquals("test123",Utils.getResponseTransactionId(transactionId));
+ assertNull(Utils.getResponseTransactionId(null));
+ assertNull(Utils.getResponseTransactionId(""));
+ }
+
+ @Test
+ public void testgetSleepMsForRate(){
+ long x = Utils.getSleepMsForRate(1024.124);
+ assertEquals(1000, x);
+ assertEquals(0, Utils.getSleepMsForRate(-1));
+ }
+
+ @Test
+ public void testgetRemoteAddress(){
+ DMaaPContext dMaapContext = new DMaaPContext();
+ MockHttpServletRequest request = new MockHttpServletRequest();
+
+ dMaapContext.setRequest(request);
+
+ assertEquals(request.getRemoteAddr(), Utils.getRemoteAddress(dMaapContext));
+
+ request.addHeader("X-Forwarded-For", "XForward");
+ assertEquals("XForward", Utils.getRemoteAddress(dMaapContext));
+
+
+ }
}
diff --git a/src/test/resources/DMaaPErrorMesaages.properties b/src/test/resources/DMaaPErrorMesaages.properties
new file mode 100644
index 0000000..a3d6ce7
--- /dev/null
+++ b/src/test/resources/DMaaPErrorMesaages.properties
@@ -0,0 +1,59 @@
+###############################################################################
+# ============LICENSE_START=======================================================
+# org.onap.dmaap
+# ================================================================================
+# Copyright © 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=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+###############################################################################
+###############################################################################
+##
+## DMaaP Error Messages
+###############################################################################
+
+##
+# Generic WebApplication Exceptions
+##
+resource.not.found=The requested resource was not found.Please verify the URL and try again.
+server.unavailable=Server is temporarily unavailable or busy.Try again later, or try another server in the cluster.
+http.method.not.allowed=The specified HTTP method is not allowed for the requested resource.Enter a valid HTTP method and try again.
+incorrect.request.json=Incorrect JSON object. Please correct the JSON format and try again.
+network.time.out=Connection to the DMaaP MR was timed out.Please try again.
+
+##
+# AAF Errors
+##
+authentication.failure=Access Denied: Invalid Credentials. Enter a valid MechId and Password and try again.
+not.permitted.access.1=Access Denied.User does not have permission to perform
+not.permitted.access.2=operation on Topic:
+unable.to.authorize=Unable to authorize the user. Please try again later.
+
+
+##
+#Topic
+##
+get.topic.failure=Failed to retrieve list of all topics.
+get.topic.details.failure=Failed to retrieve details of topic:
+create.topic.failure=Failed to create topic:
+delete.topic.failure=Failed to delete topic:
+
+consume.msg.error=Error while reading data from topic.
+publish.msg.error=Error while publishing data to topic.
+msg_size_exceeds=Message size exceeds the default size.
+publish.msg.count=Successfully published number of messages :
+
+incorrect.json=Incorrect JSON object.Could not parse JSON. Please correct the JSON format and try again.
+topic.not.exist=No such topic exists. \ No newline at end of file
diff --git a/src/test/resources/MsgRtrApi.properties b/src/test/resources/MsgRtrApi.properties
new file mode 100644
index 0000000..0bfb1ec
--- /dev/null
+++ b/src/test/resources/MsgRtrApi.properties
@@ -0,0 +1,156 @@
+###############################################################################
+# ============LICENSE_START=======================================================
+# org.onap.dmaap
+# ================================================================================
+# Copyright © 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=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+###############################################################################
+###############################################################################
+##
+## Cambria API Server config
+##
+## - Default values are shown as commented settings.
+##
+
+###############################################################################
+##
+## HTTP service
+##
+## - 3904 is standard as of 7/29/14.
+#
+## Zookeeper Connection
+##
+## Both Cambria and Kafka make use of Zookeeper.
+##
+#config.zk.servers=172.18.1.1
+config.zk.servers=<zookeeper_host>
+#config.zk.root=/fe3c/cambria/config
+
+
+###############################################################################
+##
+## Kafka Connection
+##
+## Items below are passed through to Kafka's producer and consumer
+## configurations (after removing "kafka.")
+## if you want to change request.required.acks it can take this one value
+#kafka.metadata.broker.list=localhost:9092,localhost:9093
+kafka.metadata.broker.list=<kafka_host>:<kafka_port>
+##kafka.request.required.acks=-1
+#kafka.client.zookeeper=${config.zk.servers}
+consumer.timeout.ms=100
+zookeeper.connection.timeout.ms=6000
+zookeeper.session.timeout.ms=6000
+zookeeper.sync.time.ms=2000
+auto.commit.interval.ms=1000
+fetch.message.max.bytes =1000000
+auto.commit.enable=false
+
+
+###############################################################################
+##
+## Secured Config
+##
+## Some data stored in the config system is sensitive -- API keys and secrets,
+## for example. to protect it, we use an encryption layer for this section
+## of the config.
+##
+## The key is a base64 encode AES key. This must be created/configured for
+## each installation.
+#cambria.secureConfig.key=
+##
+## The initialization vector is a 16 byte value specific to the secured store.
+## This must be created/configured for each installation.
+#cambria.secureConfig.iv=
+
+## Southfield Sandbox
+cambria.secureConfig.key=b/7ouTn9FfEw2PQwL0ov/Q==
+cambria.secureConfig.iv=wR9xP5k5vbz/xD0LmtqQLw==
+authentication.adminSecret=fe3cCompound
+#cambria.secureConfig.key[pc569h]=YT3XPyxEmKCTLI2NK+Sjbw==
+#cambria.secureConfig.iv[pc569h]=rMm2jhR3yVnU+u2V9Ugu3Q==
+
+
+###############################################################################
+##
+## Consumer Caching
+##
+## Kafka expects live connections from the consumer to the broker, which
+## obviously doesn't work over connectionless HTTP requests. The Cambria
+## server proxies HTTP requests into Kafka consumer sessions that are kept
+## around for later re-use. Not doing so is costly for setup per request,
+## which would substantially impact a high volume consumer's performance.
+##
+## This complicates Cambria server failover, because we often need server
+## A to close its connection before server B brings up the replacement.
+##
+
+## The consumer cache is normally enabled.
+#cambria.consumer.cache.enabled=true
+
+## Cached consumers are cleaned up after a period of disuse. The server inspects
+## consumers every sweepFreqSeconds and will clean up any connections that are
+## dormant for touchFreqMs.
+#cambria.consumer.cache.sweepFreqSeconds=15
+#cambria.consumer.cache.touchFreqMs=120000
+
+## The cache is managed through ZK. The default value for the ZK connection
+## string is the same as config.zk.servers.
+#cambria.consumer.cache.zkConnect=${config.zk.servers}
+
+##
+## Shared cache information is associated with this node's name. The default
+## name is the hostname plus the HTTP service port this host runs on. (The
+## hostname is determined via InetAddress.getLocalHost ().getCanonicalHostName(),
+## which is not always adequate.) You can set this value explicitly here.
+##
+#cambria.api.node.identifier=<use-something-unique-to-this-instance>
+
+###############################################################################
+##
+## Metrics Reporting
+##
+## This server can report its metrics periodically on a topic.
+##
+#metrics.send.cambria.enabled=true
+#metrics.send.cambria.topic=cambria.apinode.metrics #msgrtr.apinode.metrics.dmaap
+metrics.send.cambria.sendEverySeconds=60
+
+cambria.consumer.cache.zkBasePath=/fe3c/cambria/consumerCache
+
+##############################################################################
+#100mb
+maxcontentlength=10000
+
+
+##############################################################################
+#AAF Properties
+msgRtr.namespace.aaf=com.att.dmaap.mr.topic
+msgRtr.topicfactory.aaf=org.openecomp.dmaapBC.topicFactory|:org.openecomp.dmaapBC.topic:
+enforced.topic.name.AAF=com.att
+forceAAF=false
+transidUEBtopicreqd=false
+defaultNSforUEB=com.att.dmaap.mr.ueb
+##############################################################################
+#Mirror Maker Agent
+msgRtr.mirrormakeradmin.aaf=com.att.dmaap.mr.dev.mirrormaker|*|admin
+msgRtr.mirrormakeruser.aaf=com.att.dmaap.mr.dev.mirrormaker|*|user
+msgRtr.mirrormakeruser.aaf.create=com.att.dmaap.mr.dev.topicFactory|:com.att.dmaap.mr.dev.topic:
+msgRtr.mirrormaker.timeout=15000
+msgRtr.mirrormaker.topic=com.att.dmaap.mr.prod.mm.agent
+msgRtr.mirrormaker.consumergroup=mmagentserver
+msgRtr.mirrormaker.consumerid=1 \ No newline at end of file
diff --git a/src/test/resources/spring-context.xml b/src/test/resources/spring-context.xml
new file mode 100644
index 0000000..717dddf
--- /dev/null
+++ b/src/test/resources/spring-context.xml
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ org.onap.dmaap
+ ================================================================================
+ Copyright © 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=========================================================
+
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <!-- Dependency Injection with annotations -->
+ <context:component-scan
+ base-package="com.att.nsa.cambria.utils,com.att.nsa.cambria.service.impl,com.att.nsa.cambria.exception" />
+
+ <context:property-placeholder
+ location="classpath:msgRtrApi.properties,classpath:DMaaPErrorMesaages.properties" />
+
+
+ <bean id="propertyReader" class="com.att.nsa.cambria.utils.PropertyReader" />
+ <bean
+ class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+ <!-- Next value is the full qualified name of the static setter including
+ method name -->
+ <property name="staticMethod"
+ value="com.att.nsa.cambria.beans.DMaaPKafkaConsumerFactory.populateKafkaInternalDefaultsMap" />
+ <property name="arguments">
+ <list>
+ <ref bean="propertyReader" />
+ </list>
+ </property>
+ </bean>
+
+ <bean id="drumlinRequestRouter"
+ class="com.att.nsa.drumlin.service.framework.routing.DrumlinRequestRouter" />
+
+ <bean id="dMaaPMetricsSet" class="com.att.nsa.cambria.beans.DMaaPMetricsSet">
+ <constructor-arg ref="propertyReader" />
+ </bean>
+
+ <bean id="dMaaPZkClient" class=" com.att.nsa.cambria.beans.DMaaPZkClient">
+ <constructor-arg ref="propertyReader" />
+ </bean>
+
+ <bean id="dMaaPZkConfigDb" class=" com.att.nsa.cambria.beans.DMaaPZkConfigDb">
+ <constructor-arg ref="dMaaPZkClient" />
+ <constructor-arg ref="propertyReader" />
+ </bean>
+
+ <bean id="kafkaPublisher" class=" com.att.nsa.cambria.backends.kafka.KafkaPublisher">
+ <constructor-arg ref="propertyReader" />
+ </bean>
+
+ <bean id="dMaaPKafkaConsumerFactory" class=" com.att.nsa.cambria.beans.DMaaPKafkaConsumerFactory">
+ <constructor-arg ref="propertyReader" />
+ <constructor-arg ref="dMaaPMetricsSet" />
+ <constructor-arg ref="curator" />
+ </bean>
+
+ <bean id="curator" class="com.att.nsa.cambria.utils.DMaaPCuratorFactory"
+ factory-method="getCurator">
+ <constructor-arg ref="propertyReader" />
+ </bean>
+
+ <bean id="dMaaPKafkaMetaBroker" class=" com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker">
+ <constructor-arg ref="propertyReader" />
+ <constructor-arg ref="dMaaPZkClient" />
+ <constructor-arg ref="dMaaPZkConfigDb" />
+ </bean>
+
+ <!-- <bean id="q" class=" com.att.nsa.cambria.backends.memory.MemoryQueue" />
+
+ <bean id="mmb" class=" com.att.nsa.cambria.backends.memory.MemoryMetaBroker">
+ <constructor-arg ref="q" />
+ <constructor-arg ref="dMaaPZkConfigDb" />
+ <constructor-arg ref="propertyReader" />
+ </bean>
+
+ <bean id="dMaaPNsaApiDb" class="com.att.nsa.cambria.beans.DMaaPNsaApiDb"
+ factory-method="buildApiKeyDb">
+ <constructor-arg ref="propertyReader" />
+ <constructor-arg ref="dMaaPZkConfigDb" />
+ </bean>
+
+ <bean id="dMaaPTranDb" class="com.att.nsa.cambria.transaction.DMaaPTransactionDB"
+ factory-method="buildTransactionDb"> <constructor-arg ref="propertyReader"
+ /> <constructor-arg ref="dMaaPZkConfigDb" /> </bean>
+
+ <bean id="dMaaPAuthenticatorImpl" class="com.att.nsa.cambria.security.DMaaPAuthenticatorImpl">
+ <constructor-arg ref="dMaaPNsaApiDb" />
+ </bean>
+ <bean id="defLength" class="com.att.nsa.filter.DefaultLength">
+ <property name="defaultLength" value="${maxcontentlength}"></property>
+ </bean> -->
+
+ <!-- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="location"> <value>msgRtrApi.properties</value> </property>
+ </bean> -->
+
+</beans> \ No newline at end of file