Changed identifiers to concept identifiers
[policy/models.git] / models-pap / src / test / java / org / onap / policy / models / pap / concepts / PdpDeployPoliciesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.models.pap.concepts;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNull;
24
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.List;
28 import org.junit.Test;
29 import org.onap.policy.common.utils.coder.CoderException;
30 import org.onap.policy.common.utils.coder.StandardCoder;
31 import org.onap.policy.common.utils.resources.TextFileUtils;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
33
34 /**
35  * This only tests the methods that aren't already tested via TestModels.
36  */
37 public class PdpDeployPoliciesTest {
38     @Test
39     public void testPapPolicyIdentifier() throws CoderException, IOException {
40         assertNotNull(new PdpDeployPolicies());
41
42         List<ToscaConceptIdentifierOptVersion> tciListIn = new ArrayList<>();
43
44         ToscaConceptIdentifierOptVersion tci0 = new ToscaConceptIdentifierOptVersion("MyPolicy0", "1.2.0");
45         tciListIn.add(tci0);
46         ToscaConceptIdentifierOptVersion tci1 = new ToscaConceptIdentifierOptVersion("MyPolicy1", "1.2.1");
47         tciListIn.add(tci1);
48         ToscaConceptIdentifierOptVersion tci2 = new ToscaConceptIdentifierOptVersion("MyPolicy2", "1.2.2");
49         tciListIn.add(tci2);
50
51         PdpDeployPolicies policies = new PdpDeployPolicies();
52         policies.setPolicies(null);
53         assertNull(policies.getPolicies());
54
55         policies.setPolicies(tciListIn);
56
57         assertEquals(3, policies.getPolicies().size());
58
59         assertEquals("MyPolicy0", policies.getPolicies().get(0).getName());
60         assertEquals("1.2.0", policies.getPolicies().get(0).getVersion());
61         assertEquals("MyPolicy1", policies.getPolicies().get(1).getName());
62         assertEquals("1.2.1", policies.getPolicies().get(1).getVersion());
63         assertEquals("MyPolicy2", policies.getPolicies().get(2).getName());
64         assertEquals("1.2.2", policies.getPolicies().get(2).getVersion());
65
66         List<ToscaConceptIdentifierOptVersion> tciListOut = policies.getPolicies();
67         assertEquals(tciListIn, tciListOut);
68     }
69
70     @Test
71     public void testPapPolicyIdentifierSerialization() throws CoderException, IOException {
72         String idListString = TextFileUtils.getTextFileAsString("src/test/resources/json/PapPoliciesList.json");
73
74         StandardCoder coder = new StandardCoder();
75
76         PdpDeployPolicies policies = coder.decode(idListString, PdpDeployPolicies.class);
77
78         assertEquals(3, policies.getPolicies().size());
79
80         assertEquals("MyPolicy0", policies.getPolicies().get(0).getName());
81         assertEquals("1.2.0", policies.getPolicies().get(0).getVersion());
82         assertEquals("MyPolicy1", policies.getPolicies().get(1).getName());
83         assertEquals("1.2.1", policies.getPolicies().get(1).getVersion());
84         assertEquals("MyPolicy2", policies.getPolicies().get(2).getName());
85         assertEquals("1.2.2", policies.getPolicies().get(2).getVersion());
86
87         String idListStringBack = coder.encode(policies);
88         assertEquals(idListString.replaceAll("\\s+", ""), idListStringBack.replaceAll("\\s+", ""));
89     }
90 }