Sonar Fixes policy/models, removing model-yaml
[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-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
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
26 import java.util.UUID;
27 import org.junit.Test;
28
29 public class ServiceTest {
30
31     private static final String EQUALS_TEST = "equalsTest";
32     private static final String VERSION_111 = "1.1.1";
33
34     @Test
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());
41
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());
48
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());
55
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());
65
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());
71     }
72
73     @Test
74     public void testUuid() {
75         Service svc = new Service();
76         UUID uuid = UUID.randomUUID();
77         svc.setServiceUUID(uuid);
78         assertEquals(uuid, svc.getServiceUUID());
79     }
80
81     @Test
82     public void testInvariantUuid() {
83         Service svc = new Service();
84         UUID uuid = UUID.randomUUID();
85         svc.setServiceInvariantUUID(uuid);
86         assertEquals(uuid, svc.getServiceInvariantUUID());
87     }
88
89     @Test
90     public void testName() {
91         Service svc = new Service();
92         String name = "nameTest";
93         svc.setServiceName(name);
94         assertEquals(name, svc.getServiceName());
95     }
96
97     @Test
98     public void testVersion() {
99         Service svc = new Service();
100         String version = "versionTest";
101         svc.setServiceVersion(version);
102         assertEquals(version, svc.getServiceVersion());
103     }
104
105     @Test
106     public void testEquals() {
107         Service s1 = new Service();
108         Service s2 = new Service(s1);
109         assertEquals(s1, s2);
110         assertEquals(s2, s1);
111
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);
116     }
117
118     @Test
119     public void testToString() {
120         Service s1 = new Service();
121         Service s2 = new Service(s1);
122         assertEquals(s1.toString(), s2.toString());
123
124         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
125         s2 = new Service(s1);
126         assertEquals(s1.toString(), s2.toString());
127     }
128
129     @Test
130     public void testHashCode() {
131         Service s1 = new Service();
132         Service s2 = new Service(s1);
133         assertEquals(s1.hashCode(), s2.hashCode());
134
135         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
136         s2 = new Service(s1);
137         assertEquals(s1.hashCode(), s2.hashCode());
138     }
139 }