Remove unused imports in controlpolicy
[policy/drools-applications.git] / controlloop / common / eventmanager / src / test / java / org / onap / policy / controlloop / SupportUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * util
4  * ================================================================================
5  * Copyright (C) 2017-2018 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.controlloop;
22
23 import static org.junit.Assert.fail;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.nio.charset.StandardCharsets;
30
31 import org.apache.commons.io.IOUtils;
32 import org.onap.policy.controlloop.policy.ControlLoopPolicy;
33 import org.yaml.snakeyaml.Yaml;
34 import org.yaml.snakeyaml.constructor.Constructor;
35
36 public final class SupportUtil {
37
38     public static class Pair<A, B> {
39         public final A key;
40         public final B value;
41
42         public Pair(A key, B value) {
43             this.key = key;
44             this.value = value;
45         }
46     }
47
48     /**
49      * Load yaml into a Pair object.
50      * 
51      * @param testFile the yaml file
52      * @return a Pair
53      */
54     public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
55         try (InputStream is = new FileInputStream(new File(testFile))) {
56             String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
57             //
58             // Read the yaml into our Java Object
59             //
60             Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
61             Object obj = yaml.load(contents);
62             return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);
63         } catch (IOException e) {
64             fail(e.getLocalizedMessage());
65         }
66         return null;
67     }
68
69 }