Removed MSB Dependencies
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / msb / entity / MicroServiceFullInfoTest.java
1 /**
2  * Copyright 2023 ZTE Corporation.
3  * <p>
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
7  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
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.
15  */
16
17 package org.onap.holmes.common.msb.entity;
18
19 import org.junit.Test;
20
21 import java.util.*;
22
23 import static org.junit.Assert.*;
24
25 public class MicroServiceFullInfoTest {
26     @Test
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");
35
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());
45         nodes.add(nodeInfo);
46         microServiceFullInfo.setNodes(nodes);
47
48         List<KeyValuePair> metadata = new ArrayList<>();
49         metadata.add(new KeyValuePair("key1", "value1"));
50         metadata.add(new KeyValuePair("key2", "value2"));
51         microServiceFullInfo.setMetadata(metadata);
52
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());
61     }
62
63     @Test
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");
72
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());
81
82         Set<NodeInfo> nodes = new HashSet<>();
83         nodes.add(nodeInfo);
84         microServiceFullInfo.setNodes(nodes);
85
86         List<KeyValuePair> metadata = new ArrayList<>();
87         metadata.add(new KeyValuePair("key1", "value1"));
88         metadata.add(new KeyValuePair("key2", "value2"));
89         microServiceFullInfo.setMetadata(metadata);
90
91         // Test the toString method
92         String expectedOutput = "MicroService List:\r\n" +
93                 "serviceName:service-name\r\n" +
94                 "version:1.0\r\n" +
95                 "url:http://example.com\r\n" +
96                 "protocol:http\r\n" +
97                 "visualRange:local\r\n" +
98                 "nodes:\r\n" +
99                 "  nodeId-node-1\r\n" +
100                 "  ip-127.0.0.1\r\n" +
101                 "  port-8080\r\n" +
102                 "  ttl-300\r\n" +
103                 "  Created_at-" + nodeInfo.getCreated_at() + "\r\n" +
104                 "  Updated_at-" + nodeInfo.getUpdated_at() + "\r\n" +
105                 "  Expiration-" + nodeInfo.getExpiration() + "\r\n" +
106                 "metadata:\r\n" +
107                 "  key-key1\r\n" +
108                 "  value-value1\r\n" +
109                 "  key-key2\r\n" +
110                 "  value-value2\r\n";
111
112         assertEquals(expectedOutput, microServiceFullInfo.toString());
113     }
114 }