Changes for Checkstyle 8.32
[policy/models.git] / models-interactions / model-impl / sdc / src / test / java / org / onap / policy / sdc / ServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.sdc;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.UUID;
28 import org.junit.Test;
29
30 public class ServiceTest {
31
32     private static final String EQUALS_TEST = "equalsTest";
33     private static final String VERSION_111 = "1.1.1";
34
35     @Test
36     public void testConstructors() {
37         Service svc = new Service();
38         assertEquals(null, svc.getServiceUUID());
39         assertEquals(null, svc.getServiceInvariantUUID());
40         assertEquals(null, svc.getServiceName());
41         assertEquals(null, svc.getServiceVersion());
42
43         UUID uuid = UUID.randomUUID();
44         svc = new Service(uuid);
45         assertEquals(uuid, svc.getServiceUUID());
46         assertEquals(null, svc.getServiceInvariantUUID());
47         assertEquals(null, svc.getServiceName());
48         assertEquals(null, svc.getServiceVersion());
49
50         String name = "constTest";
51         svc = new Service(name);
52         assertEquals(null, svc.getServiceUUID());
53         assertEquals(name, svc.getServiceName());
54         assertEquals(null, svc.getServiceInvariantUUID());
55         assertEquals(null, svc.getServiceVersion());
56
57         uuid = UUID.randomUUID();
58         UUID uuidInvariant = UUID.randomUUID();
59         name = "constTestUUID";
60         String version = "0.0.1";
61         svc = new Service(uuid, uuidInvariant, name, version);
62         assertEquals(uuid, svc.getServiceUUID());
63         assertEquals(uuidInvariant, svc.getServiceInvariantUUID());
64         assertEquals(name, svc.getServiceName());
65         assertEquals(version, svc.getServiceVersion());
66
67         Service s2 = new Service(svc);
68         assertEquals(uuid, s2.getServiceUUID());
69         assertEquals(uuidInvariant, s2.getServiceInvariantUUID());
70         assertEquals(name, s2.getServiceName());
71         assertEquals(version, s2.getServiceVersion());
72     }
73
74     @Test
75     public void testUuid() {
76         Service svc = new Service();
77         UUID uuid = UUID.randomUUID();
78         svc.setServiceUUID(uuid);
79         assertEquals(uuid, svc.getServiceUUID());
80     }
81
82     @Test
83     public void testInvariantUuid() {
84         Service svc = new Service();
85         UUID uuid = UUID.randomUUID();
86         svc.setServiceInvariantUUID(uuid);
87         assertEquals(uuid, svc.getServiceInvariantUUID());
88     }
89
90     @Test
91     public void testName() {
92         Service svc = new Service();
93         String name = "nameTest";
94         svc.setServiceName(name);
95         assertEquals(name, svc.getServiceName());
96     }
97
98     @Test
99     public void testVersion() {
100         Service svc = new Service();
101         String version = "versionTest";
102         svc.setServiceVersion(version);
103         assertEquals(version, svc.getServiceVersion());
104     }
105
106     @Test
107     public void testEquals() {
108         Service s1 = new Service();
109         Service s2 = new Service(s1);
110         assertTrue(s1.equals(s2));
111         assertTrue(s2.equals(s1));
112
113         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
114         s2 = new Service(s1);
115         assertTrue(s1.equals(s2));
116         assertTrue(s2.equals(s1));
117     }
118
119     @Test
120     public void testToString() {
121         Service s1 = new Service();
122         Service s2 = new Service(s1);
123         assertEquals(s1.toString(), s2.toString());
124
125         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
126         s2 = new Service(s1);
127         assertEquals(s1.toString(), s2.toString());
128     }
129
130     @Test
131     public void testHashCode() {
132         Service s1 = new Service();
133         Service s2 = new Service(s1);
134         assertEquals(s1.hashCode(), s2.hashCode());
135
136         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
137         s2 = new Service(s1);
138         assertEquals(s1.hashCode(), s2.hashCode());
139     }
140 }