remove dependency of drool-application/yaml in actors
[policy/models.git] / models-interactions / model-yaml / src / test / java / org / onap / policy / controlloop / compiler / ControlLoopGuardCompilerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml unit test
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.onap.policy.controlloop.compiler;
23
24 import static org.junit.Assert.fail;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.io.InputStream;
31
32 import org.junit.Test;
33
34 import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
35
36 public class ControlLoopGuardCompilerTest {
37
38     @Test 
39     public void testTest1() {
40         try {
41             this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
42         } catch (Exception e) {
43             fail(e.getMessage());
44         }
45     }
46
47     @Test 
48     public void testTest2() {
49         try {
50             this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
51         } catch (Exception e) {
52             fail(e.getMessage());
53         }
54     }
55
56     @Test 
57     public void testBad1() {
58         try {
59             this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml");
60         } catch (Exception e) {
61             e.printStackTrace();
62         }
63     }
64
65     @Test 
66     public void testBad2() {
67         try {
68             this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml");
69         } catch (Exception e) {
70             e.printStackTrace();
71         }
72     }
73
74     @Test 
75     public void testBad3() {
76         try {
77             this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml");
78         } catch (Exception e) {
79             e.printStackTrace();
80         }
81     }
82
83     @Test 
84     public void testBad4() {
85         try {
86             this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml");
87         } catch (Exception e) {
88             e.printStackTrace();
89         }
90     }
91
92     /**
93      * Does the actual test.
94      * 
95      * @param testFile input test file
96      * @throws Exception exception thrown
97      */
98     public void test(String testFile) throws Exception {
99         try (InputStream is = new FileInputStream(new File(testFile))) {
100             ControlLoopGuardCompiler.compile(is, null);
101         } catch (FileNotFoundException e) {
102             fail(e.getMessage());
103         } catch (IOException e) {
104             fail(e.getMessage());
105         } catch (Exception e) {
106             throw e;
107         }
108     }
109
110 }