1 /*******************************************************************************
\r
2 * ============LICENSE_START=======================================================
\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
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
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
21 *******************************************************************************/
\r
22 package com.att.nsa.mr.client.impl;
\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
30 import org.junit.Before;
\r
31 import org.junit.Rule;
\r
32 import org.junit.Test;
\r
34 import static com.github.tomakehurst.wiremock.client.WireMock.*;
\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
42 public class MRMetaClientTest {
\r
44 @Rule public WireMockRule wireMock = new WireMockRule();
\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
57 public void getTopicsTest()
\r
59 final Collection<String> hosts = new LinkedList<String> ();
\r
60 hosts.add ( "localhost:" + wireMock.port() );
\r
64 c = new MRMetaClient(hosts);
\r
65 Set<String> setString=c.getTopics();
\r
66 } catch (IOException e) {
\r
67 e.printStackTrace();
\r
71 // assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
\r
76 public void getTopicMetadataTest() {
\r
77 final Collection<String> hosts = new LinkedList<String> ();
\r
78 hosts.add ( "localhost:" + wireMock.port() );
\r
80 final String topic ="topic1";
\r
84 c = new MRMetaClient(hosts);
\r
85 TopicInfo topicInfo=c.getTopicMetadata(topic);
\r
86 } catch (IOException | HttpObjectNotFoundException e) {
\r
87 e.printStackTrace();
\r
93 public void testcreateTopic(){
\r
94 final Collection<String> hosts = new LinkedList<String> ();
\r
95 hosts.add ( "localhost:" + wireMock.port() );
\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