2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.sdc;
24 import static org.junit.Assert.assertEquals;
26 import java.util.UUID;
27 import org.junit.Test;
29 public class ServiceTest {
31 private static final String EQUALS_TEST = "equalsTest";
32 private static final String VERSION_111 = "1.1.1";
35 public void testConstructors() {
36 Service svc = new Service();
37 assertEquals(null, svc.getServiceUUID());
38 assertEquals(null, svc.getServiceInvariantUUID());
39 assertEquals(null, svc.getServiceName());
40 assertEquals(null, svc.getServiceVersion());
42 UUID uuid = UUID.randomUUID();
43 svc = new Service(uuid);
44 assertEquals(uuid, svc.getServiceUUID());
45 assertEquals(null, svc.getServiceInvariantUUID());
46 assertEquals(null, svc.getServiceName());
47 assertEquals(null, svc.getServiceVersion());
49 String name = "constTest";
50 svc = new Service(name);
51 assertEquals(null, svc.getServiceUUID());
52 assertEquals(name, svc.getServiceName());
53 assertEquals(null, svc.getServiceInvariantUUID());
54 assertEquals(null, svc.getServiceVersion());
56 uuid = UUID.randomUUID();
57 UUID uuidInvariant = UUID.randomUUID();
58 name = "constTestUUID";
59 String version = "0.0.1";
60 svc = new Service(uuid, uuidInvariant, name, version);
61 assertEquals(uuid, svc.getServiceUUID());
62 assertEquals(uuidInvariant, svc.getServiceInvariantUUID());
63 assertEquals(name, svc.getServiceName());
64 assertEquals(version, svc.getServiceVersion());
66 Service s2 = new Service(svc);
67 assertEquals(uuid, s2.getServiceUUID());
68 assertEquals(uuidInvariant, s2.getServiceInvariantUUID());
69 assertEquals(name, s2.getServiceName());
70 assertEquals(version, s2.getServiceVersion());
74 public void testUuid() {
75 Service svc = new Service();
76 UUID uuid = UUID.randomUUID();
77 svc.setServiceUUID(uuid);
78 assertEquals(uuid, svc.getServiceUUID());
82 public void testInvariantUuid() {
83 Service svc = new Service();
84 UUID uuid = UUID.randomUUID();
85 svc.setServiceInvariantUUID(uuid);
86 assertEquals(uuid, svc.getServiceInvariantUUID());
90 public void testName() {
91 Service svc = new Service();
92 String name = "nameTest";
93 svc.setServiceName(name);
94 assertEquals(name, svc.getServiceName());
98 public void testVersion() {
99 Service svc = new Service();
100 String version = "versionTest";
101 svc.setServiceVersion(version);
102 assertEquals(version, svc.getServiceVersion());
106 public void testEquals() {
107 Service s1 = new Service();
108 Service s2 = new Service(s1);
109 assertEquals(s1, s2);
110 assertEquals(s2, s1);
112 s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
113 s2 = new Service(s1);
114 assertEquals(s1, s2);
115 assertEquals(s2, s1);
119 public void testToString() {
120 Service s1 = new Service();
121 Service s2 = new Service(s1);
122 assertEquals(s1.toString(), s2.toString());
124 s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
125 s2 = new Service(s1);
126 assertEquals(s1.toString(), s2.toString());
130 public void testHashCode() {
131 Service s1 = new Service();
132 Service s2 = new Service(s1);
133 assertEquals(s1.hashCode(), s2.hashCode());
135 s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
136 s2 = new Service(s1);
137 assertEquals(s1.hashCode(), s2.hashCode());