[POLICY-22] Reorganizing drools-apps
[policy/drools-applications.git] / controlloop / common / policy-yaml / src / test / java / org / onap / policy / controlloop / compiler / ControlLoopCompilerTest.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.*;
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 public class ControlLoopCompilerTest {
34
35         @Test 
36         public void testTest() {
37                 try {
38                         this.test("src/test/resources/v1.0.0/test.yaml");
39                 } catch (Exception e) {
40                         fail(e.getMessage());
41                 }
42         }
43         
44         @Test 
45         public void testBad1() {
46                 try {
47                         this.test("src/test/resources/v1.0.0/bad_trigger_1.yaml");
48                 } catch (Exception e) {
49                         e.printStackTrace();
50                 }
51         }
52         @Test 
53         public void testBad2() {
54                 try {
55                         this.test("src/test/resources/v1.0.0/bad_trigger_2.yaml");
56                 } catch (Exception e) {
57                         e.printStackTrace();
58                 }
59         }
60         
61         @Test 
62         public void testBad() {
63                 try {
64                         this.test("src/test/resources/v1.0.0/bad_policies_1.yaml");
65                 } catch (Exception e) {
66                 }
67         }
68         
69         public void test(String testFile) throws Exception {
70                 try (InputStream is = new FileInputStream(new File(testFile))) {
71                         ControlLoopCompiler.compile(is, null);
72                 } catch (FileNotFoundException e) {
73                         fail(e.getMessage());
74                 } catch (IOException e) {
75                         fail(e.getMessage());
76                 } catch (Exception e) {
77                         throw e;
78                 }
79         }
80
81 }