commiting code for test coverage
[dmaap/messagerouter/dmaapclient.git] / src / test / java / com / att / nsa / mr / client / impl / MRMetaClientTest.java
diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRMetaClientTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRMetaClientTest.java
new file mode 100644 (file)
index 0000000..dc2214f
--- /dev/null
@@ -0,0 +1,107 @@
+/*******************************************************************************\r
+ *  ============LICENSE_START=======================================================\r
+ *  org.onap.dmaap\r
+ *  ================================================================================\r
+ *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ *  ================================================================================\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *  \r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ *  ============LICENSE_END=========================================================\r
+ *\r
+ *  ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ *  \r
+ *******************************************************************************/\r
+package com.att.nsa.mr.client.impl;\r
+\r
+import java.io.IOException;\r
+import java.net.MalformedURLException;\r
+import java.util.Collection;\r
+import java.util.LinkedList;\r
+import java.util.Set;\r
+\r
+import org.junit.Before;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+\r
+import static com.github.tomakehurst.wiremock.client.WireMock.*;\r
+\r
+import com.att.nsa.apiClient.http.HttpException;\r
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;\r
+import com.att.nsa.mr.client.MRTopicManager.TopicInfo;\r
+import com.github.tomakehurst.wiremock.junit.WireMockRule;\r
+\r
+\r
+public class MRMetaClientTest {\r
+       \r
+       @Rule public WireMockRule wireMock = new WireMockRule();\r
+       \r
+       @Before\r
+       public void setUp(){\r
+               wireMock.stubFor(get(urlEqualTo("/topics"))\r
+                .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));\r
+               wireMock.stubFor(get(urlEqualTo("/topics/topic1"))\r
+                .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));\r
+               wireMock.stubFor(post(urlEqualTo("/topics/create"))\r
+                               .willReturn(aResponse().withStatus(200)));\r
+       }\r
+       \r
+       @Test\r
+       public void getTopicsTest() \r
+       {\r
+               final Collection<String> hosts = new LinkedList<String> ();\r
+               hosts.add ( "localhost:" + wireMock.port() );\r
+               \r
+               MRMetaClient c;\r
+               try {\r
+                       c = new MRMetaClient(hosts);\r
+                       Set<String> setString=c.getTopics();\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               \r
+       //      assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );\r
+               \r
+       }\r
+       \r
+       @Test\r
+       public void getTopicMetadataTest() {\r
+               final Collection<String> hosts = new LinkedList<String> ();\r
+               hosts.add ( "localhost:" + wireMock.port() );\r
+               \r
+               final String topic ="topic1";\r
+               \r
+               MRMetaClient c;\r
+               try {\r
+                       c = new MRMetaClient(hosts);\r
+                       TopicInfo topicInfo=c.getTopicMetadata(topic);\r
+               } catch (IOException | HttpObjectNotFoundException e) {\r
+                       e.printStackTrace();\r
+               }       \r
+               \r
+       }\r
+       \r
+       @Test\r
+       public void testcreateTopic(){\r
+               final Collection<String> hosts = new LinkedList<String> ();\r
+               hosts.add ( "localhost:" + wireMock.port() );\r
+               \r
+               MRMetaClient c;\r
+               try {\r
+                       c = new MRMetaClient(hosts);\r
+                       c.createTopic("topic1", "testTopic", 1, 1);\r
+               } catch (IOException | HttpException e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+\r
+       \r
+}\r