2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.onap.policy.rest;
23 import static org.junit.Assert.fail;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
30 import javax.servlet.ServletConfig;
31 import javax.servlet.ServletOutputStream;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37 import org.apache.log4j.Level;
38 import org.apache.log4j.Logger;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.Mockito;
42 import org.springframework.mock.web.MockHttpServletResponse;
43 import org.springframework.mock.web.MockServletConfig;
45 public class XACMLRestTest extends Mockito{
46 private static Log logger = LogFactory.getLog(XACMLRestTest.class);
48 private List<String> headers = new ArrayList<>();
50 private HttpServletRequest httpServletRequest;
51 private HttpServletResponse httpServletResponse;
52 private ServletOutputStream mockOutput;
53 private ServletConfig servletConfig;
58 httpServletRequest = Mockito.mock(HttpServletRequest.class);
59 Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
60 Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
61 Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
63 mockOutput = Mockito.mock(ServletOutputStream.class);
65 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
68 Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
69 } catch (IOException e) {
73 servletConfig = Mockito.mock(MockServletConfig.class);
74 Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
75 Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties");
77 System.setProperty("xacml.properties", "xacml.pdp.properties");
78 System.setProperty("xacml.rest.pdp.config", "config_testing");
79 System.setProperty("xacml.rest.pep.idfile", "testclient.properties");
80 System.setProperty("xacml.rest.pdp.webapps", "/webapps");
81 System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
82 System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml");
83 System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml");
84 System.setProperty("xacml.rest.pdp.register", "false");
88 public void testXacmlInit(){
89 logger.info("XACMLRestTest - testInit");
91 XACMLRest.xacmlInit(servletConfig);
92 Logger.getRootLogger().setLevel(Level.DEBUG);
93 XACMLRest.dumpRequest(httpServletRequest);
94 XACMLRest.loadXacmlProperties(null, null);
95 } catch (Exception e) {