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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
19 package org.onap.policy.models.pap.concepts;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNull;
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;
35 * This only tests the methods that aren't already tested via TestModels.
37 public class PdpDeployPoliciesTest {
39 public void testPapPolicyIdentifier() throws CoderException, IOException {
40 assertNotNull(new PdpDeployPolicies());
42 List<ToscaConceptIdentifierOptVersion> tciListIn = new ArrayList<>();
44 ToscaConceptIdentifierOptVersion tci0 = new ToscaConceptIdentifierOptVersion("MyPolicy0", "1.2.0");
46 ToscaConceptIdentifierOptVersion tci1 = new ToscaConceptIdentifierOptVersion("MyPolicy1", "1.2.1");
48 ToscaConceptIdentifierOptVersion tci2 = new ToscaConceptIdentifierOptVersion("MyPolicy2", "1.2.2");
51 PdpDeployPolicies policies = new PdpDeployPolicies();
52 policies.setPolicies(null);
53 assertNull(policies.getPolicies());
55 policies.setPolicies(tciListIn);
57 assertEquals(3, policies.getPolicies().size());
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());
66 List<ToscaConceptIdentifierOptVersion> tciListOut = policies.getPolicies();
67 assertEquals(tciListIn, tciListOut);
71 public void testPapPolicyIdentifierSerialization() throws CoderException, IOException {
72 String idListString = TextFileUtils.getTextFileAsString("src/test/resources/json/PapPoliciesList.json");
74 StandardCoder coder = new StandardCoder();
76 PdpDeployPolicies policies = coder.decode(idListString, PdpDeployPolicies.class);
78 assertEquals(3, policies.getPolicies().size());
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());
87 String idListStringBack = coder.encode(policies);
88 assertEquals(idListString.replaceAll("\\s+", ""), idListStringBack.replaceAll("\\s+", ""));