one more case added in DmaapClientUtilTest.java
[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  *  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  *        http://www.apache.org/licenses/LICENSE-2.0
11  *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.mr.client.impl;
23
24 import java.io.IOException;
25 import java.net.MalformedURLException;
26 import java.util.Collection;
27 import java.util.LinkedList;
28 import java.util.Set;
29
30 import org.junit.Before;
31 import org.junit.Rule;
32 import org.junit.Test;
33
34 import static com.github.tomakehurst.wiremock.client.WireMock.*;
35 import static org.junit.Assert.assertTrue;
36
37 import com.att.nsa.apiClient.http.HttpException;
38 import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
39 import org.onap.dmaap.mr.client.MRClient.MRApiException;
40 import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo;
41 import com.github.tomakehurst.wiremock.junit.WireMockRule;
42
43
44 public class MRMetaClientTest {
45         
46         @Rule public WireMockRule wireMock = new WireMockRule();
47         
48         @Before
49         public void setUp(){
50                 wireMock.stubFor(get(urlEqualTo("/topics"))
51                 .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));
52                 wireMock.stubFor(get(urlEqualTo("/topics/topic1"))
53                 .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));
54                 wireMock.stubFor(post(urlEqualTo("/topics/create"))
55                                 .willReturn(aResponse().withStatus(200)));
56         }
57         
58         @Test
59         public void getTopicsTest() 
60         {
61                 final Collection<String> hosts = new LinkedList<String> ();
62                 hosts.add ( "localhost:" + wireMock.port() );
63                 
64                 MRMetaClient c;
65                 try {
66                         c = new MRMetaClient(hosts);
67                         Set<String> setString=c.getTopics();
68                 } catch (IOException e) {
69                         e.printStackTrace();
70                 }
71                 
72                 
73         //      assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
74                 
75         }
76         
77         @Test
78         public void getTopicMetadataTest() {
79                 final Collection<String> hosts = new LinkedList<String> ();
80                 hosts.add ( "localhost:" + wireMock.port() );
81                 
82                 final String topic ="topic1";
83                 
84                 MRMetaClient c;
85                 try {
86                         c = new MRMetaClient(hosts);
87                         TopicInfo topicInfo=c.getTopicMetadata(topic);
88                 } catch (IOException | HttpObjectNotFoundException e) {
89                         e.printStackTrace();
90                 }       
91                 
92         }
93         
94         @Test
95         public void testcreateTopic(){
96                 final Collection<String> hosts = new LinkedList<String> ();
97                 hosts.add ( "localhost:" + wireMock.port() );
98                 
99                 MRMetaClient c;
100                 try {
101                         c = new MRMetaClient(hosts);
102                         c.createTopic("topic1", "testTopic", 1, 1);
103                 } catch (IOException | HttpException e) {
104                         e.printStackTrace();
105                 }
106         }
107         @Test
108         public void testupdateApiKey(){
109                 final Collection<String> hosts = new LinkedList<String> ();
110                 hosts.add ( "localhost:" + wireMock.port() );
111                 
112                 MRMetaClient c;
113                 try {
114                         c = new MRMetaClient(hosts);
115                         c.updateCurrentApiKey("test@onap.com", "test email");
116                 }catch (HttpException e) {
117                         
118                 } catch (IOException e) {
119                         // TODO Auto-generated catch block
120                         e.printStackTrace();
121                 }
122                 catch (NullPointerException e) {
123                         assertTrue(true);
124                 }
125                 
126         }
127
128         
129 }