Format ONAP-XACML and add JUnit
[policy/engine.git] / ONAP-XACML / src / test / java / org / onap / policy / xacml / test / util / AAFEngineTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-XACML
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.xacml.test.util;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28
29 import com.att.research.xacml.api.XACML3;
30 import com.att.research.xacml.api.pip.PIPFinder;
31 import com.att.research.xacml.api.pip.PIPRequest;
32 import com.att.research.xacml.api.pip.PIPResponse;
33 import com.att.research.xacml.std.pip.StdPIPFinderFactory;
34 import com.att.research.xacml.std.pip.StdPIPRequest;
35 import com.att.research.xacml.util.XACMLProperties;
36
37 import java.util.Properties;
38
39 import org.junit.Test;
40 import org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine;
41
42 public class AAFEngineTest {
43     @Test
44     public void aafEngineTest() {
45         String testId = "testId";
46         System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "xacml.properties");
47         AAFEngine aafEngine = new AAFEngine();
48         assertTrue(AAFEngine.DEFAULT_DESCRIPTION
49                 .equals("PIP for authenticating aaf attributes using the AAF REST interface"));
50         assertTrue(AAFEngine.DEFAULT_ISSUER.equals("aaf"));
51
52         Properties props = new Properties();
53         try {
54             aafEngine.configure(testId, props);
55             assertEquals(aafEngine.getName(), testId);
56             assertEquals(aafEngine.getDescription(), AAFEngine.DEFAULT_DESCRIPTION);
57             assertEquals(aafEngine.getIssuer(), AAFEngine.DEFAULT_ISSUER);
58             assertEquals(aafEngine.attributesProvided().size(), 2);
59             assertEquals(aafEngine.attributesRequired().size(), 5);
60
61             PIPRequest pipRequest = new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, AAFEngine.AAF_RESPONSE_ID,
62                     XACML3.ID_DATATYPE_STRING);
63             StdPIPFinderFactory pipFactory = new StdPIPFinderFactory();
64             PIPFinder pipFinder = pipFactory.getFinder();
65             assertEquals(pipFinder.getPIPEngines().size(), 0);
66             PIPResponse pipResponse = aafEngine.getAttributes(pipRequest, pipFinder);
67             assertEquals(pipResponse.getStatus().isOk(), true);
68         } catch (Exception ex) {
69             fail("Not expecting any exceptions");
70         }
71     }
72 }