2fa822a334937e221f04fbb8438329642369c8b0
[policy/engine.git] / PolicyEngineUtils / src / test / java / org / onap / policy / utils / test / AAFClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineUtils
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.utils.test;
22
23 import static org.junit.Assert.assertFalse;
24
25 import java.util.Properties;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.utils.AAFPolicyClient;
30 import org.onap.policy.utils.AAFPolicyClientImpl;
31 import org.onap.policy.utils.AAFPolicyException;
32
33 public class AAFClientTest {
34     AAFPolicyClient afClient;
35     String pass = "test";
36     
37     @Before
38     public void setUp() throws AAFPolicyException{
39         Properties props = new Properties();
40         props.setProperty("ENVIRONMENT", "TEST");
41         props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
42         afClient  = AAFPolicyClient.getInstance(props);
43     }
44     
45     @Test
46     public void invalidClientTest() throws AAFPolicyException{
47         assertFalse(afClient.checkAuth("test", pass));
48         assertFalse(afClient.checkPerm("test", pass, "policy-engine.config", "*", "*"));
49         Properties props = new Properties();
50         props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
51         afClient  = AAFPolicyClient.getInstance(props);
52         assertFalse(afClient.checkAuth("test", pass));
53         props.setProperty("ENVIRONMENT", "PROD");
54         props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
55         afClient.updateProperties(props);
56         assertFalse(afClient.checkAuth("test", pass));
57         props.setProperty("aaf_url", "test");
58         afClient.updateProperties(props);
59         assertFalse(afClient.checkAuth("test", pass));
60         props = new Properties();
61         props.setProperty("ENVIRONMENT", "123");
62         afClient.updateProperties(props);
63         assertFalse(afClient.checkAuth("test", pass));
64         assertFalse(afClient.checkAuthPerm("test", pass, "decision", "*", "read"));
65     }
66     
67     @Test(expected = AAFPolicyException.class)
68     public void invalidAAFInstance() throws AAFPolicyException{
69         Properties props = new Properties();
70         props.setProperty("aafClient.impl.className", "errorClass");
71         afClient  = AAFPolicyClient.getInstance(props);
72     }
73     
74     @Test(expected = AAFPolicyException.class)
75     public void testPropNullException() throws AAFPolicyException {
76         afClient.updateProperties(null);
77     }
78
79     @Test(expected = AAFPolicyException.class)
80     public void testPropEmptyException() throws AAFPolicyException {
81         afClient.updateProperties(new Properties());
82     }
83     
84     @Test(expected = AAFPolicyException.class)
85     public void testAAFException() throws AAFPolicyException{
86         new AAFPolicyException();
87         new AAFPolicyException("error", new Exception());
88         throw new AAFPolicyException("error", new Exception(), false, false);
89     }
90 }