commiting code for test coverage
[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 \r
36 import com.att.nsa.apiClient.http.HttpException;\r
37 import com.att.nsa.apiClient.http.HttpObjectNotFoundException;\r
38 import com.att.nsa.mr.client.MRTopicManager.TopicInfo;\r
39 import com.github.tomakehurst.wiremock.junit.WireMockRule;\r
40 \r
41 \r
42 public class MRMetaClientTest {\r
43         \r
44         @Rule public WireMockRule wireMock = new WireMockRule();\r
45         \r
46         @Before\r
47         public void setUp(){\r
48                 wireMock.stubFor(get(urlEqualTo("/topics"))\r
49                 .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));\r
50                 wireMock.stubFor(get(urlEqualTo("/topics/topic1"))\r
51                 .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));\r
52                 wireMock.stubFor(post(urlEqualTo("/topics/create"))\r
53                                 .willReturn(aResponse().withStatus(200)));\r
54         }\r
55         \r
56         @Test\r
57         public void getTopicsTest() \r
58         {\r
59                 final Collection<String> hosts = new LinkedList<String> ();\r
60                 hosts.add ( "localhost:" + wireMock.port() );\r
61                 \r
62                 MRMetaClient c;\r
63                 try {\r
64                         c = new MRMetaClient(hosts);\r
65                         Set<String> setString=c.getTopics();\r
66                 } catch (IOException e) {\r
67                         e.printStackTrace();\r
68                 }\r
69                 \r
70                 \r
71         //      assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );\r
72                 \r
73         }\r
74         \r
75         @Test\r
76         public void getTopicMetadataTest() {\r
77                 final Collection<String> hosts = new LinkedList<String> ();\r
78                 hosts.add ( "localhost:" + wireMock.port() );\r
79                 \r
80                 final String topic ="topic1";\r
81                 \r
82                 MRMetaClient c;\r
83                 try {\r
84                         c = new MRMetaClient(hosts);\r
85                         TopicInfo topicInfo=c.getTopicMetadata(topic);\r
86                 } catch (IOException | HttpObjectNotFoundException e) {\r
87                         e.printStackTrace();\r
88                 }       \r
89                 \r
90         }\r
91         \r
92         @Test\r
93         public void testcreateTopic(){\r
94                 final Collection<String> hosts = new LinkedList<String> ();\r
95                 hosts.add ( "localhost:" + wireMock.port() );\r
96                 \r
97                 MRMetaClient c;\r
98                 try {\r
99                         c = new MRMetaClient(hosts);\r
100                         c.createTopic("topic1", "testTopic", 1, 1);\r
101                 } catch (IOException | HttpException e) {\r
102                         e.printStackTrace();\r
103                 }\r
104         }\r
105 \r
106         \r
107 }\r