1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.mr.client.impl;
24 import java.io.IOException;
25 import java.net.MalformedURLException;
26 import java.util.Collection;
27 import java.util.LinkedList;
30 import org.junit.Before;
31 import org.junit.Rule;
32 import org.junit.Test;
34 import static com.github.tomakehurst.wiremock.client.WireMock.*;
35 import static org.junit.Assert.assertTrue;
37 import com.att.nsa.apiClient.http.HttpException;
38 import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
39 import org.onap.dmaap.mr.client.MRClient.MRApiException;
40 import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo;
41 import com.github.tomakehurst.wiremock.junit.WireMockRule;
44 public class MRMetaClientTest {
46 @Rule public WireMockRule wireMock = new WireMockRule();
50 wireMock.stubFor(get(urlEqualTo("/topics"))
51 .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));
52 wireMock.stubFor(get(urlEqualTo("/topics/topic1"))
53 .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));
54 wireMock.stubFor(post(urlEqualTo("/topics/create"))
55 .willReturn(aResponse().withStatus(200)));
59 public void getTopicsTest()
61 final Collection<String> hosts = new LinkedList<String> ();
62 hosts.add ( "localhost:" + wireMock.port() );
66 c = new MRMetaClient(hosts);
67 Set<String> setString=c.getTopics();
68 } catch (IOException e) {
73 // assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
78 public void getTopicMetadataTest() {
79 final Collection<String> hosts = new LinkedList<String> ();
80 hosts.add ( "localhost:" + wireMock.port() );
82 final String topic ="topic1";
86 c = new MRMetaClient(hosts);
87 TopicInfo topicInfo=c.getTopicMetadata(topic);
88 } catch (IOException | HttpObjectNotFoundException e) {
95 public void testcreateTopic(){
96 final Collection<String> hosts = new LinkedList<String> ();
97 hosts.add ( "localhost:" + wireMock.port() );
101 c = new MRMetaClient(hosts);
102 c.createTopic("topic1", "testTopic", 1, 1);
103 } catch (IOException | HttpException e) {
108 public void testupdateApiKey(){
109 final Collection<String> hosts = new LinkedList<String> ();
110 hosts.add ( "localhost:" + wireMock.port() );
114 c = new MRMetaClient(hosts);
115 c.updateCurrentApiKey("test@onap.com", "test email");
116 }catch (HttpException e) {
118 } catch (IOException e) {
119 // TODO Auto-generated catch block
122 catch (NullPointerException e) {