[POLICY-22] Reorganizing drools-apps
[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 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_vUSP_1707_appc.yaml");
41                 } catch (Exception e) {
42                         fail(e.getMessage());
43                 }
44         }
45         
46         @Test 
47         public void testBad1() {
48                 try {
49                         this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml");
50                 } catch (Exception e) {
51                         e.printStackTrace();
52                 }
53         }
54         
55         @Test 
56         public void testBad2() {
57                 try {
58                         this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml");
59                 } catch (Exception e) {
60                         e.printStackTrace();
61                 }
62         }
63         
64         @Test 
65         public void testBad3() {
66                 try {
67                         this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml");
68                 } catch (Exception e) {
69                         e.printStackTrace();
70                 }
71         }
72         
73         @Test 
74         public void testBad4() {
75                 try {
76                         this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml");
77                 } catch (Exception e) {
78                         e.printStackTrace();
79                 }
80         }
81         
82         public void test(String testFile) throws Exception {
83                 try (InputStream is = new FileInputStream(new File(testFile))) {
84                         ControlLoopGuardCompiler.compile(is, null);
85                 } catch (FileNotFoundException e) {
86                         fail(e.getMessage());
87                 } catch (IOException e) {
88                         fail(e.getMessage());
89                 } catch (Exception e) {
90                         throw e;
91                 }
92         }
93         
94 }