[DMAAP-CLIENT] First sonar issues review part2
[dmaap/messagerouter/dmaapclient.git] / src / test / java / org / onap / dmaap / mr / client / impl / MRMetaClientTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  *  ================================================================================
7  *  Modifications Copyright © 2021 Orange.
8  *  ================================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  *  ============LICENSE_END=========================================================
20  *
21  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  *
23  *******************************************************************************/
24
25 package org.onap.dmaap.mr.client.impl;
26
27 import com.att.nsa.apiClient.http.HttpException;
28 import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
29 import org.junit.Test;
30 import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo;
31
32 import java.io.IOException;
33 import java.util.Collection;
34 import java.util.LinkedList;
35 import java.util.Set;
36
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.assertTrue;
39
40
41 public class MRMetaClientTest {
42
43     @Test
44     public void getTopicsTest() {
45         final Collection<String> hosts = new LinkedList<String>();
46         hosts.add("localhost:" + 3904);
47
48         MRMetaClient c;
49         try {
50             c = new MRMetaClient(hosts);
51             Set<String> setString = c.getTopics();
52         } catch (IOException e) {
53             e.printStackTrace();
54         }
55         assertNotNull(hosts);
56
57
58         //assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
59
60     }
61
62     @Test
63     public void getTopicMetadataTest() {
64         final Collection<String> hosts = new LinkedList<String>();
65         hosts.add("localhost:" + 3904);
66
67         final String topic = "topic1";
68
69         MRMetaClient c;
70         try {
71             c = new MRMetaClient(hosts);
72             TopicInfo topicInfo = c.getTopicMetadata(topic);
73         } catch (IOException | HttpObjectNotFoundException e) {
74             e.printStackTrace();
75         }
76         assertNotNull(topic);
77
78     }
79
80     @Test
81     public void testcreateTopic() {
82         final Collection<String> hosts = new LinkedList<String>();
83         hosts.add("localhost:" + 3904);
84
85         MRMetaClient c;
86         try {
87             c = new MRMetaClient(hosts);
88             c.createTopic("topic1", "testTopic", 1, 1);
89         } catch (IOException | HttpException e) {
90             e.printStackTrace();
91         }
92         assertNotNull(hosts);
93     }
94
95     @Test
96     public void testupdateApiKey() {
97         final Collection<String> hosts = new LinkedList<String>();
98         hosts.add("localhost:" + 3904);
99
100         MRMetaClient c;
101         try {
102             c = new MRMetaClient(hosts);
103             c.updateCurrentApiKey("test@onap.com", "test email");
104         } catch (HttpException e) {
105
106         } catch (IOException e) {
107             // TODO Auto-generated catch block
108             e.printStackTrace();
109         } catch (NullPointerException e) {
110             assertTrue(true);
111         }
112
113     }
114
115
116 }