Merge "50% Code Coverage-MSB Java SDK"
[msb/java-sdk.git] / src / test / java / org / onap / msb / sdk / discovery / util / MsbUtilTest.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
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
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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
12  * the License.
13  */
14
15 package org.onap.msb.sdk.discovery.util;
16
17 import java.util.Set;
18
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;
24
25 public class MsbUtilTest {
26
27         @Test
28         public void test_getConsulServiceName(){
29                 Assert.assertEquals("test", MsbUtil.getConsulServiceName("test",""));
30                 Assert.assertEquals("test-ns", MsbUtil.getConsulServiceName("test","ns"));
31         }
32         
33         @Test
34         public void test_getLbNodes(){
35                 
36                 Node node=new Node();
37                 node.setIp("127.0.0.1");
38                 node.setPort("8089");
39                 
40                 Set<NodeInfo> nodes=MsbUtil.getLbNodes(node);
41                 Assert.assertEquals(1, nodes.size());
42         }
43         
44         @Test
45         public void test_checkServiceName(){
46                 try {
47                         MsbUtil.checkServiceName("testName");
48                         MsbUtil.checkServiceName("");
49
50                 } catch (RouteException e) {
51                 Assert.assertTrue(e instanceof RouteException);
52
53                 }
54                 
55         }
56         
57         @Test
58         public void test_checkVersion(){
59                 try {
60                         Assert.assertEquals("v1", MsbUtil.checkVersion("v1"));
61                         Assert.assertEquals("null", MsbUtil.checkVersion(""));
62                          MsbUtil.checkVersion("version");
63
64                 } catch (RouteException e) {
65                 Assert.assertTrue(e instanceof RouteException);
66
67                 }
68                 
69         }
70         
71         @Test
72         public void test_checkHost(){
73                 try {
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());
80                 
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());
85
86                 }
87         }
88         
89         @Test
90         public void test_checkIp(){
91                 try {
92                         MsbUtil.checkHost("","2565");
93                 } catch (RouteException e) {
94                 Assert.assertTrue(e instanceof RouteException);
95                 
96
97                 }
98         }
99 }