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