2 * Copyright 2017 ZTE Corporation.
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;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.onap.msb.sdk.discovery.common.RouteException;
22 import org.onap.msb.sdk.discovery.entity.Node;
23 import org.onap.msb.sdk.discovery.entity.NodeInfo;
25 public class MsbUtilTest {
28 public void test_getConsulServiceName(){
29 Assert.assertEquals("test", MsbUtil.getConsulServiceName("test",""));
30 Assert.assertEquals("test-ns", MsbUtil.getConsulServiceName("test","ns"));
34 public void test_getLbNodes(){
37 node.setIp("127.0.0.1");
40 Set<NodeInfo> nodes=MsbUtil.getLbNodes(node);
41 Assert.assertEquals(1, nodes.size());
45 public void test_checkServiceName(){
47 MsbUtil.checkServiceName("testName");
48 MsbUtil.checkServiceName("");
50 } catch (RouteException e) {
51 Assert.assertTrue(e instanceof RouteException);
58 public void test_checkVersion(){
60 Assert.assertEquals("v1", MsbUtil.checkVersion("v1"));
61 Assert.assertEquals("null", MsbUtil.checkVersion(""));
62 MsbUtil.checkVersion("version");
64 } catch (RouteException e) {
65 Assert.assertTrue(e instanceof RouteException);
72 public void test_checkHost(){
74 MsbUtil.checkHost("127.0.0.1","2565");
75 MsbUtil.checkHost("127.0.0.1","");
76 } catch (RouteException e) {
77 Assert.assertTrue(e instanceof RouteException);
78 Assert.assertEquals("DATA_FORMAT_ERROR",e.getErrorCode());
79 Assert.assertNotEquals("ERROR",e.getErrorMsg());
81 e.setErrorCode("DATA_FORMAT_ERROR_TEST");
82 e.setErrorMsg("ERROR");
83 Assert.assertNotEquals("DATA_FORMAT_ERROR",e.getErrorCode());
84 Assert.assertEquals("ERROR",e.getErrorMsg());
90 public void test_checkIp(){
92 MsbUtil.checkHost("","2565");
93 } catch (RouteException e) {
94 Assert.assertTrue(e instanceof RouteException);