Added Junis for Policy ONAP-REST
[policy/engine.git] / ONAP-REST / src / test / java / org / onap / policy / rest / XACMLRestTest.java
index 3de4364..419b14d 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-REST
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.rest;
 
-/*import java.io.IOException;
-import java.io.InputStream;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Properties;
-import java.util.Random;
 
 import javax.servlet.ServletConfig;
-import javax.servlet.ServletInputStream;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import junit.framework.TestCase;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.springframework.mock.web.MockHttpServletResponse;
 import org.springframework.mock.web.MockServletConfig;
 
-import com.att.research.xacml.util.XACMLProperties;
-import com.mockrunner.mock.web.MockServletInputStream;
-
-public class XACMLRestTest extends TestCase{
+public class XACMLRestTest extends Mockito{
        private static Log logger       = LogFactory.getLog(XACMLRestTest.class);
-       
-       private List<String> headers = new ArrayList<String>();
-       
+
+       private List<String> headers = new ArrayList<>();
+
        private HttpServletRequest httpServletRequest;
        private HttpServletResponse httpServletResponse;
        private ServletOutputStream mockOutput;
-       private ServletInputStream mockInput;
        private ServletConfig servletConfig; 
 
-        
-    @Before
-    public void setUp(){
-       httpServletRequest = Mockito.mock(HttpServletRequest.class);
-       Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
-       Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
-       Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
-       
-       mockOutput = Mockito.mock(ServletOutputStream.class);
-       
-       httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
-       
-       try {
+
+       @Before
+       public void setUp(){
+               httpServletRequest = Mockito.mock(HttpServletRequest.class);
+               Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
+               Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
+               Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
+
+               mockOutput = Mockito.mock(ServletOutputStream.class);
+
+               httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+
+               try {
                        Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
                } catch (IOException e) {
                        fail();
                }
 
-       servletConfig = Mockito.mock(MockServletConfig.class);
-       Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
-       //pdpServlet = new XACMLPdpServlet();
-       
-       Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties");
-       
+               servletConfig = Mockito.mock(MockServletConfig.class);
+               Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
+               Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties");
+
                System.setProperty("xacml.properties", "xacml.pdp.properties");
                System.setProperty("xacml.rest.pdp.config", "config_testing");
                System.setProperty("xacml.rest.pep.idfile", "testclient.properties"); 
@@ -90,18 +82,19 @@ public class XACMLRestTest extends TestCase{
                System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml");
                System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml");
                System.setProperty("xacml.rest.pdp.register", "false");
-    }
-       
-    @Test
-       public void testDummy(){
+       }
+
+       @Test
+       public void testXacmlInit(){
                logger.info("XACMLRestTest - testInit");
                try {   
-                       assertTrue(true);
+                       XACMLRest.xacmlInit(servletConfig);
+                       Logger.getRootLogger().setLevel(Level.DEBUG);
+                       XACMLRest.dumpRequest(httpServletRequest);
+                       XACMLRest.loadXacmlProperties(null, null);
                } catch (Exception e) {
                        fail();
-                       
                }
 
        }
-}
-*/
\ No newline at end of file
+}
\ No newline at end of file