2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
15 package org.onap.msb.sdk.discovery.util;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.onap.msb.sdk.discovery.common.RouteException;
23 public class HttpClientUtilTest {
25 private String testIp = "http://127.0.0.1:8500";
26 private String errorIp = "http://127.0.0.3:8500";
29 public void test_httpGet_fail() {
31 Assert.assertNull(HttpClientUtil.httpGet(errorIp));
32 } catch (Exception e) {
33 Assert.assertTrue(e instanceof RouteException);
38 public void test_httpdelete() {
40 HttpClientUtil.delete(testIp, "service");
42 } catch (Exception e) {
43 Assert.assertTrue(e instanceof RouteException);
48 public void test_httpPostWithJSON() {
49 String url = testIp + "/v1/catalog/service";
50 String json = "[{\"Node\":\"server\",\"Address\":\"127.0.0.1\",\"TaggedAddresses\":{\"lan\":\"127.0.0.1\",\"wan\":\"127.0.0.1\"},\"ServiceID\":\"_CJ-SNMP_10.74.216.65_12005\",\"ServiceName\":\"CJ-SNMP\",\"ServiceAddress\":\"10.74.216.65\",\"ServicePort\":12005,\"ServiceEnableTagOverride\":false,\"CreateIndex\":1813280,\"ModifyIndex\":1815062}]";
53 HttpClientUtil.httpPostWithJSON(url, json);
54 Assert.assertEquals("Consul Agent", HttpClientUtil.httpGet(testIp));
55 } catch (Exception e) {
56 Assert.assertTrue(e instanceof RouteException);
61 public void test_httpPutWithJSON() {
62 String url = testIp + "/v1/catalog/service";
63 String json = "[{\"Node\":\"server\",\"Address\":\"127.0.0.1\",\"TaggedAddresses\":{\"lan\":\"127.0.0.1\",\"wan\":\"127.0.0.1\"},\"ServiceID\":\"_CJ-SNMP_10.74.216.65_12005\",\"ServiceName\":\"CJ-SNMP\",\"ServiceAddress\":\"10.74.216.65\",\"ServicePort\":12005,\"ServiceEnableTagOverride\":false,\"CreateIndex\":1813280,\"ModifyIndex\":1815062}]";
66 HttpClientUtil.httpPutWithJSON(url, json);
67 Assert.assertEquals("Consul Agent", HttpClientUtil.httpGet(testIp));
68 } catch (Exception e) {
69 Assert.assertTrue(e instanceof RouteException);