[POLICY-122] Policy GUI Fixes
[policy/engine.git] / PolicyEngineAPI / src / test / java / org / openecomp / policy / test / PolicyEngineTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineAPI
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.openecomp.policy.test;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.fail;
26
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30
31 import org.junit.Test;
32 import org.openecomp.policy.api.NotificationScheme;
33 import org.openecomp.policy.api.PolicyEngine;
34 import org.openecomp.policy.api.PolicyEngineException;
35 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
36 import org.openecomp.policy.common.logging.flexlogger.Logger; 
37
38 public class PolicyEngineTest {
39
40         private static final Logger logger = FlexLogger.getLogger(PolicyEngineTest.class);
41         private PolicyEngine policyEngine = null;
42         private String filePath = null;
43         
44         @Test
45         public void testPolicyEngineForFail() {
46                 filePath = null;
47                 try {
48                         policyEngine = new PolicyEngine(filePath);
49                 } catch (PolicyEngineException e) {
50                         logger.warn(e.getMessage());
51                 }
52                 assertNull(policyEngine);
53                 // Test even for this case.
54                 filePath = "NotNull";
55                 try {
56                         policyEngine = new PolicyEngine(filePath);
57                 } catch (PolicyEngineException e) {
58                         logger.warn(e.getMessage());
59                 }
60                 assertNull(policyEngine);
61         }
62         
63         @Test
64         public void testPolicyEngineforPropertyFileError() {
65                 filePath = "Test/config_error.property";
66                 isFileAvailable(filePath);
67                 try {
68                         policyEngine = new PolicyEngine(filePath);
69                 } catch (PolicyEngineException e) {
70                         logger.warn(e.getMessage());
71                 }
72                 assertNull(policyEngine);
73         }
74         
75         @Test
76         public void testPolicyEngineforPDPURLError() {
77                 String filePath = "Test/config_fail.properties";
78                 isFileAvailable(filePath);
79                 try {
80                         policyEngine = new PolicyEngine(filePath);
81                 } catch (PolicyEngineException e) {
82                         logger.warn(e.getMessage());
83                 }
84                 assertNull(policyEngine);
85         }
86         
87         @Test
88         public void testPolicyEngineForPass() {
89                 String filePath = "Test/config_pass.properties";
90                 isFileAvailable(filePath);
91                 try {
92                         policyEngine = new PolicyEngine(filePath);
93                 } catch (PolicyEngineException e) {
94                         logger.warn(e.getMessage());
95                 }
96                 assertNotNull(policyEngine);
97         }
98         
99         @Test
100         public void testPolicyEngineForUEBPass() {
101                 String filePath = "Test/config_UEB_pass.properties";
102                 isFileAvailable(filePath);
103                 try {
104                         policyEngine = new PolicyEngine(filePath);
105                 } catch (PolicyEngineException e) {
106                         logger.warn(e.getMessage());
107                 }
108                 assertNotNull(policyEngine);
109         }
110         
111         
112         @Test
113         public void testPolicyEngineForUEBBadType() {
114                 String filePath = "Test/config_UEB_bad_type.properties";
115                 isFileAvailable(filePath);
116                 try {
117                         policyEngine = new PolicyEngine(filePath);
118                 } catch (PolicyEngineException e) {
119                         logger.warn(e.getMessage());
120                 }
121                 assertNotNull(policyEngine);
122         }
123         
124         @Test
125         public void testPolicyEngineForUEBBadServerType() {
126                 String filePath = "Test/config_UEB_badservers.properties";
127                 isFileAvailable(filePath);
128                 try {
129                         policyEngine = new PolicyEngine(filePath);
130                 } catch (PolicyEngineException e) {
131                         logger.warn(e.getMessage());
132                 }
133                 assertNotNull(policyEngine);
134         }
135         
136         @Test
137         public void testPolicyEngineNotficationAutoUEB() {
138                 String filePath = "Test/config_UEB_pass.properties";
139                 isFileAvailable(filePath);
140                 try {
141                         policyEngine = new PolicyEngine(filePath);
142                         policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS);
143                 } catch (PolicyEngineException e) {
144                         logger.warn(e.getMessage());
145                 }
146                 assertNotNull(policyEngine);
147         }
148         
149         @Test
150         public void testPolicyEngineNotficationAuto() {
151                 String filePath = "Test/config_pass.properties";
152                 isFileAvailable(filePath);
153                 try {
154                         policyEngine = new PolicyEngine(filePath);
155                         policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS);
156                         //policyEngine.getNotification();
157                 } catch (PolicyEngineException e) {
158                         logger.warn(e.getMessage());
159                 }
160                 assertNotNull(policyEngine);
161         }
162
163         public void isFileAvailable(String filePath) {
164                 Path file = Paths.get(filePath);
165                 if (Files.notExists(file)) {
166                         logger.error("File Doesn't Exist "+ file.toString());
167                         fail("File: " +filePath + " Not found");
168                 }
169         }
170 }