Fixed the Policy API issues and Bugfixes
[policy/engine.git] / ECOMP-ControlloopPolicy / src / test / java / org / openecomp / policy / controlloop / compiler / ControlLoopGuardCompilerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 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 package org.openecomp.policy.controlloop.compiler;
21
22 import static org.junit.Assert.fail;
23
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.IOException;
28 import java.io.InputStream;
29
30 import org.junit.Test;
31 import org.openecomp.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
32
33 public class ControlLoopGuardCompilerTest {
34         
35         @Test 
36         public void testTest1() {
37                 try {
38                         this.test("src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml");
39                 } catch (Exception e) {
40                         fail(e.getMessage());
41                 }
42         }
43         
44         @Test 
45         public void testTest2() {
46                 try {
47                         this.test("src/test/resources/v2.0.0-guard/policy_guard_1707_appc.yaml");
48                 } catch (Exception e) {
49                         fail(e.getMessage());
50                 }
51         }
52         
53         @Test 
54         public void testBad1() {
55                 try {
56                         this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml");
57                 } catch (Exception e) {
58                         e.printStackTrace();
59                 }
60         }
61         
62         @Test 
63         public void testBad2() {
64                 try {
65                         this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml");
66                 } catch (Exception e) {
67                         e.printStackTrace();
68                 }
69         }
70         
71         @Test 
72         public void testBad3() {
73                 try {
74                         this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml");
75                 } catch (Exception e) {
76                         e.printStackTrace();
77                 }
78         }
79         
80         @Test 
81         public void testBad4() {
82                 try {
83                         this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml");
84                 } catch (Exception e) {
85                         e.printStackTrace();
86                 }
87         }
88         
89         public void test(String testFile) throws Exception {
90                 try (InputStream is = new FileInputStream(new File(testFile))) {
91                         ControlLoopGuardCompiler.compile(is, null);
92                 } catch (FileNotFoundException e) {
93                         fail(e.getMessage());
94                 } catch (IOException e) {
95                         fail(e.getMessage());
96                 } catch (Exception e) {
97                         throw e;
98                 }
99         }
100         
101 }