2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.test;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.fail;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.junit.Test;
34 import org.openecomp.policy.api.NotificationScheme;
35 import org.openecomp.policy.api.PolicyEngine;
36 import org.openecomp.policy.api.PolicyEngineException;
38 import org.openecomp.policy.common.logging.flexlogger.*;
40 public class PolicyEngineTest {
42 private static final Logger logger = FlexLogger.getLogger(PolicyEngineTest.class);
43 private PolicyEngine policyEngine = null;
44 private String filePath = null;
47 public void testPolicyEngineForFail() {
50 policyEngine = new PolicyEngine(filePath);
51 } catch (PolicyEngineException e) {
52 logger.warn(e.getMessage());
54 assertNull(policyEngine);
55 // Test even for this case.
58 policyEngine = new PolicyEngine(filePath);
59 } catch (PolicyEngineException e) {
60 logger.warn(e.getMessage());
62 assertNull(policyEngine);
66 public void testPolicyEngineforPropertyFileError() {
67 filePath = "Test/config_error.property";
68 isFileAvailable(filePath);
70 policyEngine = new PolicyEngine(filePath);
71 } catch (PolicyEngineException e) {
72 logger.warn(e.getMessage());
74 assertNull(policyEngine);
78 public void testPolicyEngineforPDPURLError() {
79 String filePath = "Test/config_fail.properties";
80 isFileAvailable(filePath);
82 policyEngine = new PolicyEngine(filePath);
83 } catch (PolicyEngineException e) {
84 logger.warn(e.getMessage());
86 assertNull(policyEngine);
90 public void testPolicyEngineForPass() {
91 String filePath = "Test/config_pass.properties";
92 isFileAvailable(filePath);
94 policyEngine = new PolicyEngine(filePath);
95 } catch (PolicyEngineException e) {
96 logger.warn(e.getMessage());
98 assertNotNull(policyEngine);
102 public void testPolicyEngineForUEBPass() {
103 String filePath = "Test/config_UEB_pass.properties";
104 isFileAvailable(filePath);
106 policyEngine = new PolicyEngine(filePath);
107 } catch (PolicyEngineException e) {
108 logger.warn(e.getMessage());
110 assertNotNull(policyEngine);
115 public void testPolicyEngineForUEBBadType() {
116 String filePath = "Test/config_UEB_bad_type.properties";
117 isFileAvailable(filePath);
119 policyEngine = new PolicyEngine(filePath);
120 } catch (PolicyEngineException e) {
121 logger.warn(e.getMessage());
123 assertNotNull(policyEngine);
127 public void testPolicyEngineForUEBBadServerType() {
128 String filePath = "Test/config_UEB_badservers.properties";
129 isFileAvailable(filePath);
131 policyEngine = new PolicyEngine(filePath);
132 } catch (PolicyEngineException e) {
133 logger.warn(e.getMessage());
135 assertNotNull(policyEngine);
139 public void testPolicyEngineNotficationAutoUEB() {
140 String filePath = "Test/config_UEB_pass.properties";
141 isFileAvailable(filePath);
143 policyEngine = new PolicyEngine(filePath);
144 policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS);
145 } catch (PolicyEngineException e) {
146 logger.warn(e.getMessage());
148 assertNotNull(policyEngine);
152 public void testPolicyEngineNotficationAuto() {
153 String filePath = "Test/config_pass.properties";
154 isFileAvailable(filePath);
156 policyEngine = new PolicyEngine(filePath);
157 policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS);
158 //policyEngine.getNotification();
159 } catch (PolicyEngineException e) {
160 logger.warn(e.getMessage());
162 assertNotNull(policyEngine);
165 public void isFileAvailable(String filePath) {
166 Path file = Paths.get(filePath);
167 if (Files.notExists(file)) {
168 logger.error("File Doesn't Exist "+ file.toString());
169 fail("File: " +filePath + " Not found");