summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder/src/test/java/org/onap
diff options
context:
space:
mode:
authorGuobiao Mo <guobiaomo@chinamobile.com>2019-04-23 15:46:15 -0700
committerGuobiao Mo <guobiaomo@chinamobile.com>2019-04-23 15:46:15 -0700
commitc82dafde6b3f02cccba0822a340cb9d7bed35a1c (patch)
treeaa1593e841f213633873c9aff1bd2341d2f979ba /components/datalake-handler/feeder/src/test/java/org/onap
parent3ab4672bacf1870722e9129f9cd7f7fa18f602f2 (diff)
Move hard-coded strings to app configuration
Issue-ID: DCAEGEN2-1452 Change-Id: I6577ba3b5a8f877bbaa13d0c590d6a2072331136 Signed-off-by: Guobiao Mo <guobiaomo@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder/src/test/java/org/onap')
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java3
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java3
-rwxr-xr-xcomponents/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java11
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java14
4 files changed, 23 insertions, 8 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java
index ee3ceb7b..3e7d9986 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java
@@ -61,6 +61,9 @@ public class ApplicationConfigurationTest {
assertTrue(config.getKafkaConsumerCount() > 0);
assertNotNull(config.isAsync());
assertNotNull(config.isEnableSSL());
+ assertNotNull(config.getDefaultTopicName());
+ assertNotNull(config.getRawDataLabel());
+ assertNotNull(config.getTimestampLabel());
}
}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
index afd4503d..8be45d60 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
@@ -98,9 +98,6 @@ public class TopicTest {
Topic testTopic = new Topic("test");
testTopic.setDefaultTopic(defaultTopic);
- assertTrue(defaultTopic.isDefault());
- assertFalse(testTopic.isDefault());
-
assertTrue(testTopic.equals(new Topic("test")));
assertEquals(testTopic.hashCode(), (new Topic("test")).hashCode());
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java
index 9e40a2b1..9e1b2d99 100755
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java
@@ -34,6 +34,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.onap.datalake.feeder.domain.Topic;
import java.util.ArrayList;
@@ -98,6 +99,8 @@ public class CouchbaseServiceTest {
@Test
public void testSaveJsonsWithTopicId() {
+ ApplicationConfiguration appConfig = new ApplicationConfiguration();
+ appConfig.setTimestampLabel("datalake_ts_");
String text = "{ data: { data2 : { value : 'hello'}}}";
@@ -106,16 +109,19 @@ public class CouchbaseServiceTest {
Topic topic = new Topic("test getMessageId");
topic.setMessageIdPath("/data/data2/value");
List<JSONObject> jsons = new ArrayList<>();
- json.put("_ts", 1234);
+ json.put(appConfig.getTimestampLabel(), 1234);
jsons.add(json);
CouchbaseService couchbaseService = new CouchbaseService();
couchbaseService.bucket = bucket;
+ couchbaseService.config = appConfig;
couchbaseService.saveJsons(topic, jsons);
}
@Test
public void testSaveJsonsWithOutTopicId() {
+ ApplicationConfiguration appConfig = new ApplicationConfiguration();
+ appConfig.setTimestampLabel("datalake_ts_");
String text = "{ data: { data2 : { value : 'hello'}}}";
@@ -123,10 +129,11 @@ public class CouchbaseServiceTest {
Topic topic = new Topic("test getMessageId");
List<JSONObject> jsons = new ArrayList<>();
- json.put("_ts", 1234);
+ json.put(appConfig.getTimestampLabel(), 1234);
jsons.add(json);
CouchbaseService couchbaseService = new CouchbaseService();
couchbaseService.bucket = bucket;
+ couchbaseService.config = appConfig;
couchbaseService.saveJsons(topic, jsons);
}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
index 0e6db836..99f22398 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
@@ -23,6 +23,7 @@ package org.onap.datalake.feeder.service;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
@@ -36,6 +37,7 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.onap.datalake.feeder.domain.Db;
import org.onap.datalake.feeder.domain.Topic;
import org.onap.datalake.feeder.repository.TopicRepository;
@@ -49,6 +51,11 @@ import org.onap.datalake.feeder.repository.TopicRepository;
@RunWith(MockitoJUnitRunner.class)
public class TopicServiceTest {
+ static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
+
+ @Mock
+ private ApplicationConfiguration config;
+
@Mock
private TopicRepository topicRepository;
@@ -74,9 +81,10 @@ public class TopicServiceTest {
@Test
public void testGetDefaultTopic() {
- String name = "_DL_DEFAULT_";
- when(topicRepository.findById(name)).thenReturn(Optional.of(new Topic(name)));
- assertEquals(topicService.getDefaultTopic(), new Topic(name));
+ when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(new Topic(DEFAULT_TOPIC_NAME)));
+ when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
+ assertEquals(topicService.getDefaultTopic(), new Topic(DEFAULT_TOPIC_NAME));
+ assertTrue(topicService.istDefaultTopic(new Topic(DEFAULT_TOPIC_NAME)));
}
@Test(expected = IOException.class)