28e59d9ad3afe8bd3c5f6f1818a3cbfc49fe85b3
[policy/drools-applications.git] / controlloop / common / policy-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  * ================================================================================
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.compiler;
22
23 import static org.junit.Assert.fail;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.InputStream;
30
31 import org.junit.Test;
32
33 import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
34
35 public class ControlLoopGuardCompilerTest {
36
37     @Test 
38     public void testTest1() {
39         try {
40             this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
41         } catch (Exception e) {
42             fail(e.getMessage());
43         }
44     }
45
46     @Test 
47     public void testTest2() {
48         try {
49             this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
50         } catch (Exception e) {
51             fail(e.getMessage());
52         }
53     }
54
55     @Test 
56     public void testBad1() {
57         try {
58             this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml");
59         } catch (Exception e) {
60             e.printStackTrace();
61         }
62     }
63
64     @Test 
65     public void testBad2() {
66         try {
67             this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml");
68         } catch (Exception e) {
69             e.printStackTrace();
70         }
71     }
72
73     @Test 
74     public void testBad3() {
75         try {
76             this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml");
77         } catch (Exception e) {
78             e.printStackTrace();
79         }
80     }
81
82     @Test 
83     public void testBad4() {
84         try {
85             this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml");
86         } catch (Exception e) {
87             e.printStackTrace();
88         }
89     }
90
91     /**
92      * Does the actual test.
93      * 
94      * @param testFile input test file
95      * @throws Exception exception thrown
96      */
97     public void test(String testFile) throws Exception {
98         try (InputStream is = new FileInputStream(new File(testFile))) {
99             ControlLoopGuardCompiler.compile(is, null);
100         } catch (FileNotFoundException e) {
101             fail(e.getMessage());
102         } catch (IOException e) {
103             fail(e.getMessage());
104         } catch (Exception e) {
105             throw e;
106         }
107     }
108
109 }