diff options
author | Rama-Huawei <rama.subba.reddy.s@huawei.com> | 2019-04-12 14:56:10 +0530 |
---|---|---|
committer | Rama-Huawei <rama.subba.reddy.s@huawei.com> | 2019-04-12 14:59:53 +0530 |
commit | a78b0157c60d8c03b87ca996a2d262f0e662487b (patch) | |
tree | 37bb5bd4d8d8a7bbb45202323016e4074d786184 /components/datalake-handler/feeder/src/test/java/org | |
parent | 48a7904878cb39b8d88d96e6c0451230292c9371 (diff) |
Unit test code for datalake seed code
Increased the domain code coverage to 100%
Issue-ID: DCAEGEN2-1309
Change-Id: I09496bb476d9f7e8de30fb2c85a03a457be43bb9
Signed-off-by: Rama-Huawei <rama.subba.reddy.s@huawei.com>
Diffstat (limited to 'components/datalake-handler/feeder/src/test/java/org')
2 files changed, 173 insertions, 111 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTest.java index ea1d6894..81a7560c 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTest.java @@ -1,44 +1,76 @@ /* -* ============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========================================================= -*/ + * ============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.domain; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; -import org.junit.Test; - +import static org.junit.Assert.assertTrue; + /** * Test Db - * - * @author Guobiao Mo * + * @author Guobiao Mo */ - -public class DbTest { + +public class DbTest { @Test - public void testIs() { - Db couchbase=new Db("Couchbase"); - Db mongoDB=new Db("MongoDB"); - Db mongoDB2=new Db("MongoDB"); - assertNotEquals(couchbase.hashCode(), mongoDB.hashCode()); - assertNotEquals(couchbase, mongoDB); - assertEquals(mongoDB, mongoDB2); - } + public void testIs() { + + Db couchbase = new Db("Couchbase"); + Db mongoDB = new Db("MongoDB"); + Db mongoDB2 = new Db("MongoDB"); + assertNotEquals(couchbase.hashCode(), mongoDB.hashCode()); + assertNotEquals(couchbase, mongoDB); + assertEquals(mongoDB, mongoDB2); + assertFalse(mongoDB2.equals(null)); + assertFalse(mongoDB2.equals(new Topic())); + + new Db(); + mongoDB2.setHost("localhost"); + mongoDB2.setPort(1234); + mongoDB2.setLogin("root"); + mongoDB2.setPass("root123"); + mongoDB2.setDatabase("mongoDB2"); + mongoDB2.setEncrypt(true); + mongoDB2.setProperty1("property1"); + mongoDB2.setProperty2("property2"); + mongoDB2.setProperty3("property3"); + Set<Topic> hash_set = new HashSet<>(); + hash_set.add(new Topic("topic1")); + mongoDB2.setTopics(hash_set); + assertTrue("localhost".equals(mongoDB2.getHost())); + assertFalse("1234".equals(mongoDB2.getPort())); + assertTrue("root".equals(mongoDB2.getLogin())); + assertTrue("root123".equals(mongoDB2.getPass())); + assertTrue("mongoDB2".equals(mongoDB2.getDatabase())); + assertFalse("true".equals(mongoDB2.getEncrypt())); + assertTrue("property1".equals(mongoDB2.getProperty1())); + assertTrue("property2".equals(mongoDB2.getProperty2())); + assertTrue("property3".equals(mongoDB2.getProperty3())); + assertFalse("topic1".equals(mongoDB2.getTopics())); + } } 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 1e402522..e21773cb 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 @@ -1,101 +1,131 @@ /* -* ============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========================================================= -*/ + * ============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.domain; +import org.json.JSONObject; +import org.junit.Test; +import org.onap.datalake.feeder.enumeration.DataFormat; + +import java.util.HashSet; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.util.HashSet; - -import org.json.JSONObject; -import org.junit.Test; -import org.onap.datalake.feeder.enumeration.DataFormat; - /** * Test Topic - * - * @author Guobiao Mo * + * @author Guobiao Mo */ - -public class TopicTest { + +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"); + 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"); + 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 defaultTopic = new Topic("_DL_DEFAULT_"); + Topic testTopic = new Topic("test"); + testTopic.setDefaultTopic(defaultTopic); + + assertEquals(3650, testTopic.getTtl()); + defaultTopic.setTtl(20); + assertEquals(20, testTopic.getTtl()); + topic.setDefaultTopic(new Topic("defaultTopic")); + topic.setLogin("root"); + topic.setPass("root123"); + topic.setEnabled(true); + topic.setSaveRaw(true); + topic.setCorrelateClearedMessage(true); + topic.setMessageIdPath("/data/data2/value"); + assertTrue("defaultTopic".equals(topic.getDefaultTopic().toString())); + assertTrue("root".equals(topic.getLogin())); + assertTrue("root123".equals(topic.getPass())); + assertFalse("true".equals(topic.getEnabled())); + assertFalse("true".equals(topic.getSaveRaw())); + assertFalse("true".equals(topic.getCorrelateClearedMessage())); + assertTrue("/data/data2/value".equals(topic.getMessageIdPath())); + assertFalse(topic.equals(null)); + assertFalse(topic.equals(new Db())); } @Test - public void testIs() { - Topic defaultTopic=new Topic("_DL_DEFAULT_"); - 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()); - - defaultTopic.setDbs(new HashSet<>()); - defaultTopic.getDbs().add(new Db("Elasticsearch")); - assertTrue(testTopic.supportElasticsearch()); - assertFalse(testTopic.supportCouchbase()); - assertFalse(testTopic.supportDruid()); - assertFalse(testTopic.supportMongoDB()); - - defaultTopic.getDbs().remove(new Db("Elasticsearch")); - assertFalse(testTopic.supportElasticsearch()); - - defaultTopic.setCorrelateClearedMessage(true); - defaultTopic.setDataFormat("XML"); - defaultTopic.setEnabled(true); - defaultTopic.setSaveRaw(true); - assertTrue(testTopic.isCorrelateClearedMessage()); - assertTrue(testTopic.isEnabled()); - assertTrue(testTopic.isSaveRaw()); - - assertEquals(defaultTopic.getDataFormat(), DataFormat.XML); - } + public void testIs() { + Topic defaultTopic = new Topic("_DL_DEFAULT_"); + 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()); + + defaultTopic.setDbs(new HashSet<>()); + defaultTopic.getDbs().add(new Db("Elasticsearch")); + assertTrue(testTopic.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); + defaultTopic.setDataFormat("XML"); + defaultTopic.setEnabled(true); + defaultTopic.setSaveRaw(true); + assertTrue(testTopic.isCorrelateClearedMessage()); + assertTrue(testTopic.isEnabled()); + assertTrue(testTopic.isSaveRaw()); + + assertEquals(defaultTopic.getDataFormat(), DataFormat.XML); + + defaultTopic.setDataFormat(null); + assertEquals(testTopic.getDataFormat(), null); + + Topic testTopic1 = new Topic("test"); + assertFalse(testTopic1.isCorrelateClearedMessage()); + } } |