2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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;
25 import static org.junit.Assert.assertTrue;
27 import java.util.UUID;
29 import org.junit.Test;
31 public class ServiceTest {
33 private static final String EQUALS_TEST = "equalsTest";
34 private static final String VERSION_111 = "1.1.1";
37 public void testConstructors() {
38 Service svc = new Service();
39 assertEquals(null, svc.getServiceUuid());
40 assertEquals(null, svc.getServiceInvariantUuid());
41 assertEquals(null, svc.getServiceName());
42 assertEquals(null, svc.getServiceVersion());
44 UUID uuid = UUID.randomUUID();
45 svc = new Service(uuid);
46 assertEquals(uuid, svc.getServiceUuid());
47 assertEquals(null, svc.getServiceInvariantUuid());
48 assertEquals(null, svc.getServiceName());
49 assertEquals(null, svc.getServiceVersion());
51 String name = "constTest";
52 svc = new Service(name);
53 assertEquals(null, svc.getServiceUuid());
54 assertEquals(name, svc.getServiceName());
55 assertEquals(null, svc.getServiceInvariantUuid());
56 assertEquals(null, svc.getServiceVersion());
58 uuid = UUID.randomUUID();
59 UUID uuidInvariant = UUID.randomUUID();
60 name = "constTestUUID";
61 String version = "0.0.1";
62 svc = new Service(uuid, uuidInvariant, name, version);
63 assertEquals(uuid, svc.getServiceUuid());
64 assertEquals(uuidInvariant, svc.getServiceInvariantUuid());
65 assertEquals(name, svc.getServiceName());
66 assertEquals(version, svc.getServiceVersion());
68 Service s2 = new Service(svc);
69 assertEquals(uuid, s2.getServiceUuid());
70 assertEquals(uuidInvariant, s2.getServiceInvariantUuid());
71 assertEquals(name, s2.getServiceName());
72 assertEquals(version, s2.getServiceVersion());
76 public void testUuid() {
77 Service svc = new Service();
78 UUID uuid = UUID.randomUUID();
79 svc.setServiceUuid(uuid);
80 assertEquals(uuid, svc.getServiceUuid());
84 public void testInvariantUuid() {
85 Service svc = new Service();
86 UUID uuid = UUID.randomUUID();
87 svc.setServiceInvariantUuid(uuid);
88 assertEquals(uuid, svc.getServiceInvariantUuid());
92 public void testName() {
93 Service svc = new Service();
94 String name = "nameTest";
95 svc.setServiceName(name);
96 assertEquals(name, svc.getServiceName());
100 public void testVersion() {
101 Service svc = new Service();
102 String version = "versionTest";
103 svc.setServiceVersion(version);
104 assertEquals(version, svc.getServiceVersion());
108 public void testEquals() {
109 Service s1 = new Service();
110 Service s2 = new Service(s1);
111 assertTrue(s1.equals(s2));
112 assertTrue(s2.equals(s1));
114 s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
115 s2 = new Service(s1);
116 assertTrue(s1.equals(s2));
117 assertTrue(s2.equals(s1));
121 public void testToString() {
122 Service s1 = new Service();
123 Service s2 = new Service(s1);
124 assertEquals(s1.toString(), s2.toString());
126 s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
127 s2 = new Service(s1);
128 assertEquals(s1.toString(), s2.toString());
132 public void testHashCode() {
133 Service s1 = new Service();
134 Service s2 = new Service(s1);
135 assertEquals(s1.hashCode(), s2.hashCode());
137 s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
138 s2 = new Service(s1);
139 assertEquals(s1.hashCode(), s2.hashCode());