2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 China Mobile
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.datalake.feeder.domain;
22 import org.junit.Test;
23 import org.onap.datalake.feeder.enumeration.DataFormat;
25 import java.util.HashSet;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotEquals;
30 import static org.junit.Assert.assertTrue;
38 public class TopicTest {
41 public void getMessageIdFromMultipleAttributes() {
42 Topic topic = new Topic("test getMessageId");
43 Topic defaultTopic = new Topic("_DL_DEFAULT_");
44 Topic testTopic = new Topic("test");
46 assertEquals(3650, testTopic.getTtl());
47 defaultTopic.setTtl(20);
48 assertEquals(20, defaultTopic.getTtl());
49 topic.setLogin("root");
50 topic.setPass("root123");
51 topic.setEnabled(true);
52 topic.setSaveRaw(true);
53 topic.setCorrelateClearedMessage(true);
54 topic.setMessageIdPath("/data/data2/value");
55 assertTrue("root".equals(topic.getLogin()));
56 assertTrue("root123".equals(topic.getPass()));
57 assertFalse("true".equals(topic.getEnabled()));
58 assertFalse("true".equals(topic.getSaveRaw()));
59 assertFalse("true".equals(topic.getCorrelateClearedMessage()));
60 assertTrue("/data/data2/value".equals(topic.getMessageIdPath()));
61 assertFalse(topic.equals(null));
62 assertFalse(topic.equals(new Db()));
66 public void testIs() {
67 Topic defaultTopic = new Topic("_DL_DEFAULT_");
68 Topic testTopic = new Topic("test");
70 Topic testTopic2 = new Topic("test2");
73 assertTrue(testTopic.equals(testTopic2));
74 assertEquals(testTopic.hashCode(), testTopic2.hashCode());
75 assertNotEquals(testTopic.toString(), "test");
77 defaultTopic.setDbs(new HashSet<>());
78 defaultTopic.getDbs().add(new Db("Elasticsearch"));
80 assertEquals(defaultTopic.getDataFormat(), null);
81 defaultTopic.setCorrelateClearedMessage(true);
82 defaultTopic.setDataFormat("XML");
83 defaultTopic.setEnabled(true);
84 defaultTopic.setSaveRaw(true);
85 assertTrue(defaultTopic.isCorrelateClearedMessage());
86 assertTrue(defaultTopic.isEnabled());
87 assertTrue(defaultTopic.isSaveRaw());
89 assertEquals(defaultTopic.getTopicConfig().getDataFormat2(), DataFormat.XML);
91 defaultTopic.setDataFormat(null);
92 assertEquals(testTopic.getDataFormat(), null);
94 Topic testTopic1 = new Topic("test");
95 assertFalse(testTopic1.isCorrelateClearedMessage());