0d25667a1469ab52335e024468375a2881e0f894
[dcaegen2/services.git] / components / datalake-handler / feeder / src / test / java / org / onap / datalake / feeder / domain / TopicTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DataLake
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.datalake.feeder.domain;
21
22 import org.junit.Test;
23 import org.onap.datalake.feeder.enumeration.DataFormat;
24
25 import java.util.HashSet;
26
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;
31
32 /**
33  * Test Topic
34  *
35  * @author Guobiao Mo
36  */
37
38 public class TopicTest {
39
40     @Test
41     public void getMessageIdFromMultipleAttributes() {
42         Topic topic = new Topic("test getMessageId"); 
43         Topic defaultTopic = new Topic("_DL_DEFAULT_");
44         Topic testTopic = new Topic("test");
45
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()));
63     }
64
65     @Test
66     public void testIs() {
67         Topic defaultTopic = new Topic("_DL_DEFAULT_");
68         Topic testTopic = new Topic("test");
69         testTopic.setId(1);
70         Topic testTopic2 = new Topic("test2");
71         testTopic2.setId(1);
72
73         assertTrue(testTopic.equals(testTopic2));
74         assertEquals(testTopic.hashCode(), testTopic2.hashCode());
75         assertNotEquals(testTopic.toString(), "test");
76
77         defaultTopic.setDbs(new HashSet<>());
78         defaultTopic.getDbs().add(new Db("Elasticsearch"));
79
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());
88
89         assertEquals(defaultTopic.getTopicConfig().getDataFormat2(), DataFormat.XML);
90
91         defaultTopic.setDataFormat(null);
92         assertEquals(testTopic.getDataFormat(), null);
93
94         Topic testTopic1 = new Topic("test");
95         assertFalse(testTopic1.isCorrelateClearedMessage());
96     }
97 }