From 2920426bd0f8369a178895138e97b0b19372c413 Mon Sep 17 00:00:00 2001 From: Guobiao Mo Date: Mon, 29 Apr 2019 17:05:39 -0700 Subject: Use TopicConfig in backend Issue-ID: DCAEGEN2-1200 Change-Id: Ia18993524c272c42ba48485a636f04f94af0cd0a Signed-off-by: Guobiao Mo --- .../feeder/controller/TopicControllerTest.java | 4 +- .../org/onap/datalake/feeder/domain/TopicTest.java | 39 +------- .../onap/datalake/feeder/dto/TopicConfigTest.java | 100 +++++++++++++++++++++ .../feeder/service/CouchbaseServiceTest.java | 4 +- .../feeder/service/ElasticsearchServiceTest.java | 2 +- .../feeder/service/MongodbServiceTest.java | 2 +- 6 files changed, 108 insertions(+), 43 deletions(-) create mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/TopicConfigTest.java (limited to 'components/datalake-handler/feeder/src/test/java') diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java index 7c2bf916..e96d940c 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java @@ -136,12 +136,12 @@ public class TopicControllerTest { when(topicRepository.findById("a")).thenReturn(Optional.of(a)); TopicConfig ac = new TopicConfig(); ac.setName("a"); - ac.setEnable(true); + ac.setEnabled(true); PostReturnBody postConfig1 = topicController.updateTopic("a", ac, mockBindingResult, httpServletResponse); assertEquals(200, postConfig1.getStatusCode()); TopicConfig ret = postConfig1.getReturnBody(); assertEquals("a", ret.getName()); - assertEquals(true, ret.isEnable()); + assertEquals(true, ret.isEnabled()); when(mockBindingResult.hasErrors()).thenReturn(true); PostReturnBody postConfig2 = topicController.updateTopic("a", ac, mockBindingResult, httpServletResponse); assertEquals(null, postConfig2); 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 b583473a..74f0884f 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 @@ -19,7 +19,6 @@ */ package org.onap.datalake.feeder.domain; -import org.json.JSONObject; import org.junit.Test; import org.onap.datalake.feeder.enumeration.DataFormat; @@ -27,7 +26,6 @@ import java.util.HashSet; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; /** @@ -38,35 +36,9 @@ import static org.junit.Assert.assertTrue; public class TopicTest { - @Test - public void getMessageId() { - String text = "{ data: { data2 : { value : 'hello'}}}"; - - JSONObject json = new JSONObject(text); - - Topic topic = new Topic("test getMessageId"); - topic.setMessageIdPath("/data/data2/value"); - - String value = topic.getMessageId(json); - - assertEquals(value, "hello"); - } - @Test public void getMessageIdFromMultipleAttributes() { - String text = "{ data: { data2 : { value : 'hello'}, data3 : 'world'}}"; - - JSONObject json = new JSONObject(text); - - Topic topic = new Topic("test getMessageId"); - topic.setMessageIdPath("/data/data2/value,/data/data3"); - - String value = topic.getMessageId(json); - assertEquals(value, "hello^world"); - - topic.setMessageIdPath(""); - assertNull(topic.getMessageId(json)); - + Topic topic = new Topic("test getMessageId"); Topic defaultTopic = new Topic("_DL_DEFAULT_"); Topic testTopic = new Topic("test"); @@ -99,13 +71,6 @@ public class TopicTest { defaultTopic.setDbs(new HashSet<>()); defaultTopic.getDbs().add(new Db("Elasticsearch")); - assertTrue(defaultTopic.supportElasticsearch()); - assertFalse(testTopic.supportCouchbase()); - assertFalse(testTopic.supportDruid()); - assertFalse(testTopic.supportMongoDB()); - - defaultTopic.getDbs().remove(new Db("Elasticsearch")); - assertFalse(testTopic.supportElasticsearch()); assertEquals(defaultTopic.getDataFormat(), null); defaultTopic.setCorrelateClearedMessage(true); @@ -116,7 +81,7 @@ public class TopicTest { assertTrue(defaultTopic.isEnabled()); assertTrue(defaultTopic.isSaveRaw()); - assertEquals(defaultTopic.getDataFormat(), DataFormat.XML); + assertEquals(defaultTopic.getTopicConfig().getDataFormat2(), DataFormat.XML); defaultTopic.setDataFormat(null); assertEquals(testTopic.getDataFormat(), null); diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/TopicConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/TopicConfigTest.java new file mode 100644 index 00000000..c65e920e --- /dev/null +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/TopicConfigTest.java @@ -0,0 +1,100 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 China Mobile + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.datalake.feeder.dto; + +import org.json.JSONObject; +import org.junit.Test; +import org.onap.datalake.feeder.domain.Db; +import org.onap.datalake.feeder.domain.Topic; + +import java.util.HashSet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * Test Topic + * + * @author Guobiao Mo + */ + +public class TopicConfigTest { + + @Test + public void getMessageId() { + String text = "{ data: { data2 : { value : 'hello'}}}"; + + JSONObject json = new JSONObject(text); + + Topic topic = new Topic("test getMessageId"); + topic.setMessageIdPath("/data/data2/value"); + + TopicConfig topicConfig = topic.getTopicConfig(); + + String value = topicConfig.getMessageId(json); + + assertEquals(value, "hello"); + } + + @Test + public void getMessageIdFromMultipleAttributes() { + String text = "{ data: { data2 : { value : 'hello'}, data3 : 'world'}}"; + + JSONObject json = new JSONObject(text); + + Topic topic = new Topic("test getMessageId"); + topic.setMessageIdPath("/data/data2/value,/data/data3"); + + TopicConfig topicConfig = topic.getTopicConfig(); + + String value = topicConfig.getMessageId(json); + assertEquals(value, "hello^world"); + + topic.setMessageIdPath(""); + topicConfig = topic.getTopicConfig(); + assertNull(topicConfig.getMessageId(json)); + + } + + @Test + public void testIs() { + Topic testTopic = new Topic("test"); + + assertTrue(testTopic.equals(new Topic("test"))); + assertEquals(testTopic.hashCode(), (new Topic("test")).hashCode()); + + testTopic.setDbs(new HashSet<>()); + testTopic.getDbs().add(new Db("Elasticsearch")); + + TopicConfig testTopicConfig = testTopic.getTopicConfig(); + + assertTrue(testTopicConfig.supportElasticsearch()); + assertFalse(testTopicConfig.supportCouchbase()); + assertFalse(testTopicConfig.supportDruid()); + assertFalse(testTopicConfig.supportMongoDB()); + + testTopic.getDbs().remove(new Db("Elasticsearch")); + testTopicConfig = testTopic.getTopicConfig(); + assertFalse(testTopicConfig.supportElasticsearch()); + + } +} 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 9e1b2d99..0efde44c 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 @@ -114,7 +114,7 @@ public class CouchbaseServiceTest { CouchbaseService couchbaseService = new CouchbaseService(); couchbaseService.bucket = bucket; couchbaseService.config = appConfig; - couchbaseService.saveJsons(topic, jsons); + couchbaseService.saveJsons(topic.getTopicConfig(), jsons); } @@ -134,7 +134,7 @@ public class CouchbaseServiceTest { CouchbaseService couchbaseService = new CouchbaseService(); couchbaseService.bucket = bucket; couchbaseService.config = appConfig; - couchbaseService.saveJsons(topic, jsons); + couchbaseService.saveJsons(topic.getTopicConfig(), jsons); } @Test diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java index de2c1674..9590b0a4 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java @@ -89,7 +89,7 @@ public class ElasticsearchServiceTest { when(config.getElasticsearchType()).thenReturn("doc"); when(config.isAsync()).thenReturn(true); - elasticsearchService.saveJsons(topic, jsons); + elasticsearchService.saveJsons(topic.getTopicConfig(), jsons); } } \ No newline at end of file diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java index 41856760..016381be 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java @@ -83,6 +83,6 @@ public class MongodbServiceTest { jsons.add(jsonObject); jsons.add(jsonObject2); - mongodbService.saveJsons(topic, jsons); + mongodbService.saveJsons(topic.getTopicConfig(), jsons); } } \ No newline at end of file -- cgit 1.2.3-korg