migrate model-impl from drools-applications
[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 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
29 import org.junit.Test;
30
31 public class ServiceTest {
32
33     @Test
34     public void testConstructors() {
35         Service svc = new Service();
36         assertEquals(null, svc.getServiceUUID());
37         assertEquals(null, svc.getServiceInvariantUUID());
38         assertEquals(null, svc.getServiceName());
39         assertEquals(null, svc.getServiceVersion());
40
41         UUID uuid = UUID.randomUUID();
42         svc = new Service(uuid);
43         assertEquals(uuid, svc.getServiceUUID());
44         assertEquals(null, svc.getServiceInvariantUUID());
45         assertEquals(null, svc.getServiceName());
46         assertEquals(null, svc.getServiceVersion());
47
48         String name = "constTest";
49         svc = new Service(name);
50         assertEquals(null, svc.getServiceUUID());
51         assertEquals(name, svc.getServiceName());
52         assertEquals(null, svc.getServiceInvariantUUID());
53         assertEquals(null, svc.getServiceVersion());
54
55         uuid = UUID.randomUUID();
56         UUID uuidInvariant = UUID.randomUUID();
57         name = "constTestUUID";
58         String version = "0.0.1";
59         svc = new Service(uuid, uuidInvariant, name, version);
60         assertEquals(uuid, svc.getServiceUUID());
61         assertEquals(uuidInvariant, svc.getServiceInvariantUUID());
62         assertEquals(name, svc.getServiceName());
63         assertEquals(version, svc.getServiceVersion());
64
65         Service s2 = new Service(svc);
66         assertEquals(uuid, s2.getServiceUUID());
67         assertEquals(uuidInvariant, s2.getServiceInvariantUUID());
68         assertEquals(name, s2.getServiceName());
69         assertEquals(version, s2.getServiceVersion());
70     }
71
72     @Test
73     public void testUuid() {
74         Service svc = new Service();
75         UUID uuid = UUID.randomUUID();
76         svc.setServiceUUID(uuid);
77         assertEquals(uuid, svc.getServiceUUID());
78     }
79
80     @Test
81     public void testInvariantUuid() {
82         Service svc = new Service();
83         UUID uuid = UUID.randomUUID();
84         svc.setServiceInvariantUUID(uuid);
85         assertEquals(uuid, svc.getServiceInvariantUUID());
86     }
87
88     @Test
89     public void testName() {
90         Service svc = new Service();
91         String name = "nameTest";
92         svc.setServiceName(name);
93         assertEquals(name, svc.getServiceName());
94     }
95
96     @Test
97     public void testVersion() {
98         Service svc = new Service();
99         String version = "versionTest";
100         svc.setServiceVersion(version);
101         assertEquals(version, svc.getServiceVersion());
102     }
103
104     @Test
105     public void testEquals() {
106         Service s1 = new Service();
107         Service s2 = new Service(s1);
108         assertTrue(s1.equals(s2));
109         assertTrue(s2.equals(s1));
110
111         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1");
112         s2 = new Service(s1);
113         assertTrue(s1.equals(s2));
114         assertTrue(s2.equals(s1));
115     }
116
117     @Test
118     public void testToString() {
119         Service s1 = new Service();
120         Service s2 = new Service(s1);
121         assertEquals(s1.toString(), s2.toString());
122
123         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1");
124         s2 = new Service(s1);
125         assertEquals(s1.toString(), s2.toString());
126     }
127
128     @Test
129     public void testHashCode() {
130         Service s1 = new Service();
131         Service s2 = new Service(s1);
132         assertEquals(s1.hashCode(), s2.hashCode());
133
134         s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1");
135         s2 = new Service(s1);
136         assertEquals(s1.hashCode(), s2.hashCode());
137     }
138 }