2 * ============LICENSE_START=======================================================
3 * policy-yaml unit test
4 * ================================================================================
5 * Copyright (C) 2017-2019 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.controlloop.policy;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
27 import java.io.FileInputStream;
28 import java.io.InputStreamReader;
30 import org.junit.Test;
31 import org.onap.policy.common.utils.coder.YamlJsonTranslator;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class ControlLoopPolicyTest {
36 private static final Logger logger = LoggerFactory.getLogger(ControlLoopPolicyTest.class);
39 public void test1() throws Exception {
40 this.test("src/test/resources/v1.0.0/policy_Test.yaml");
44 public void testvService1() throws Exception {
45 this.test("src/test/resources/v1.0.0/policy_vService.yaml");
49 public void testOpenLoop() throws Exception {
50 this.test("src/test/resources/v1.0.0/policy_OpenLoop.yaml");
54 public void testvdns() throws Exception {
55 this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vDNS.yaml");
59 public void testvFirewall() throws Exception {
60 this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml");
64 public void testvcpe() throws Exception {
65 this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_vCPE.yaml");
69 public void testvpci() throws Exception {
70 this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_vPCI.yaml");
74 public void testvolte() throws Exception {
75 this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_VOLTE.yaml");
79 * Does the actual test.
81 * @param testFile input file
82 * @throws Exception if an error occurs
84 public void test(String testFile) throws Exception {
85 try (InputStreamReader fileInputStream = new InputStreamReader(new FileInputStream(testFile))) {
87 // Read the yaml into our Java Object
89 ControlLoopPolicy controlLoopPolicy1 =
90 new YamlJsonTranslator().fromYaml(fileInputStream, ControlLoopPolicy.class);
91 assertNotNull(controlLoopPolicy1);
92 dump(controlLoopPolicy1);
95 // Now dump it to a yaml string
97 String dumpedYaml = new YamlJsonTranslator().toYaml(controlLoopPolicy1);
98 logger.debug(dumpedYaml);
100 // Read that string back into our java object
102 ControlLoopPolicy controlLoopPolicy2 =
103 new YamlJsonTranslator().fromYaml(dumpedYaml, ControlLoopPolicy.class);
104 assertNotNull(controlLoopPolicy2);
105 dump(controlLoopPolicy2);
107 // test serialization
108 assertEquals(controlLoopPolicy1, controlLoopPolicy2);
112 public void dump(Object obj) {
113 logger.debug("Dumping ", obj.getClass().getName());
114 logger.debug("{}", obj);