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
35 import static org.junit.Assert.assertTrue;
\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
44 public class MRMetaClientTest {
\r
46 @Rule public WireMockRule wireMock = new WireMockRule();
\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
59 public void getTopicsTest()
\r
61 final Collection<String> hosts = new LinkedList<String> ();
\r
62 hosts.add ( "localhost:" + wireMock.port() );
\r
66 c = new MRMetaClient(hosts);
\r
67 Set<String> setString=c.getTopics();
\r
68 } catch (IOException e) {
\r
69 e.printStackTrace();
\r
73 // assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
\r
78 public void getTopicMetadataTest() {
\r
79 final Collection<String> hosts = new LinkedList<String> ();
\r
80 hosts.add ( "localhost:" + wireMock.port() );
\r
82 final String topic ="topic1";
\r
86 c = new MRMetaClient(hosts);
\r
87 TopicInfo topicInfo=c.getTopicMetadata(topic);
\r
88 } catch (IOException | HttpObjectNotFoundException e) {
\r
89 e.printStackTrace();
\r
95 public void testcreateTopic(){
\r
96 final Collection<String> hosts = new LinkedList<String> ();
\r
97 hosts.add ( "localhost:" + wireMock.port() );
\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
108 public void testupdateApiKey(){
\r
109 final Collection<String> hosts = new LinkedList<String> ();
\r
110 hosts.add ( "localhost:" + wireMock.port() );
\r
114 c = new MRMetaClient(hosts);
\r
115 c.updateCurrentApiKey("test@onap.com", "test email");
\r
116 }catch (HttpException e) {
\r
118 } catch (IOException e) {
\r
119 // TODO Auto-generated catch block
\r
120 e.printStackTrace();
\r
122 catch (NullPointerException e) {
\r