Complete unit test for models-pdp
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / authorative / concepts / ToscaPolicyTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Models
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.tosca.authorative.concepts;
22
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25
26 import java.util.LinkedHashMap;
27
28 import org.junit.Test;
29
30 /**
31  * Tests methods not tested by {@link PojosTest}.
32  */
33 public class ToscaPolicyTest {
34
35     @Test
36     public void testGetIdentifier_testGetTypeIdentifier() {
37         assertThatThrownBy(() -> {
38             new ToscaPolicy(null);
39         }).hasMessage("copyObject is marked @NonNull but is null");
40
41
42         ToscaPolicy policy = new ToscaPolicy();
43
44         policy.setName("my_name");
45         policy.setVersion("1.2.3");
46         policy.setType("my_type");
47         policy.setTypeVersion("3.2.1");
48
49         ToscaPolicyIdentifier ident = policy.getIdentifier();
50         assertEquals("my_name", ident.getName());
51         assertEquals("1.2.3", ident.getVersion());
52
53         ToscaPolicyTypeIdentifier type = policy.getTypeIdentifier();
54         assertEquals("my_type", type.getName());
55         assertEquals("3.2.1", type.getVersion());
56
57         ToscaPolicy clonedPolicy0 = new ToscaPolicy(policy);
58         assertEquals(0, policy.compareTo(clonedPolicy0));
59
60         policy.setProperties(new LinkedHashMap<String, Object>());
61         policy.getProperties().put("PropertyKey", "PropertyValue");
62         ToscaPolicy clonedPolicy1 = new ToscaPolicy(policy);
63         assertEquals(0, policy.compareTo(clonedPolicy1));
64     }
65 }