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