2 * Copyright 2023 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.holmes.common.msb.entity;
19 import org.junit.Test;
23 import static org.junit.Assert.*;
25 public class MicroServiceFullInfoTest {
27 public void testGettersAndSetters() {
28 MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
29 microServiceFullInfo.setServiceName("service-name");
30 microServiceFullInfo.setVersion("1.0");
31 microServiceFullInfo.setUrl("http://example.com");
32 microServiceFullInfo.setProtocol("http");
33 microServiceFullInfo.setVisualRange("local");
34 microServiceFullInfo.setStatus("active");
36 Set<NodeInfo> nodes = new HashSet<>();
37 NodeInfo nodeInfo = new NodeInfo();
38 nodeInfo.setNodeId("node-1");
39 nodeInfo.setIp("127.0.0.1");
40 nodeInfo.setPort("8080");
41 nodeInfo.setTtl("300");
42 nodeInfo.setCreated_at(new Date());
43 nodeInfo.setUpdated_at(new Date());
44 nodeInfo.setExpiration(new Date());
46 microServiceFullInfo.setNodes(nodes);
48 List<KeyValuePair> metadata = new ArrayList<>();
49 metadata.add(new KeyValuePair("key1", "value1"));
50 metadata.add(new KeyValuePair("key2", "value2"));
51 microServiceFullInfo.setMetadata(metadata);
53 assertEquals("service-name", microServiceFullInfo.getServiceName());
54 assertEquals("1.0", microServiceFullInfo.getVersion());
55 assertEquals("http://example.com", microServiceFullInfo.getUrl());
56 assertEquals("http", microServiceFullInfo.getProtocol());
57 assertEquals("local", microServiceFullInfo.getVisualRange());
58 assertEquals("active", microServiceFullInfo.getStatus());
59 assertEquals(nodes, microServiceFullInfo.getNodes());
60 assertEquals(metadata, microServiceFullInfo.getMetadata());
64 public void testToString() {
65 MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
66 microServiceFullInfo.setServiceName("service-name");
67 microServiceFullInfo.setVersion("1.0");
68 microServiceFullInfo.setUrl("http://example.com");
69 microServiceFullInfo.setProtocol("http");
70 microServiceFullInfo.setVisualRange("local");
71 microServiceFullInfo.setStatus("active");
73 NodeInfo nodeInfo = new NodeInfo();
74 nodeInfo.setNodeId("node-1");
75 nodeInfo.setIp("127.0.0.1");
76 nodeInfo.setPort("8080");
77 nodeInfo.setTtl("300");
78 nodeInfo.setCreated_at(new Date());
79 nodeInfo.setUpdated_at(new Date());
80 nodeInfo.setExpiration(new Date());
82 Set<NodeInfo> nodes = new HashSet<>();
84 microServiceFullInfo.setNodes(nodes);
86 List<KeyValuePair> metadata = new ArrayList<>();
87 metadata.add(new KeyValuePair("key1", "value1"));
88 metadata.add(new KeyValuePair("key2", "value2"));
89 microServiceFullInfo.setMetadata(metadata);
91 // Test the toString method
92 String expectedOutput = "MicroService List:\r\n" +
93 "serviceName:service-name\r\n" +
95 "url:http://example.com\r\n" +
97 "visualRange:local\r\n" +
99 " nodeId-node-1\r\n" +
100 " ip-127.0.0.1\r\n" +
103 " Created_at-" + nodeInfo.getCreated_at() + "\r\n" +
104 " Updated_at-" + nodeInfo.getUpdated_at() + "\r\n" +
105 " Expiration-" + nodeInfo.getExpiration() + "\r\n" +
108 " value-value1\r\n" +
112 assertEquals(expectedOutput, microServiceFullInfo.toString());