Merge "Policy:Blocker"
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / XACMLPdpServletTest.java
index 594b51c..8c7fd7e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PDP-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.
@@ -20,6 +20,9 @@
 
 package org.onap.policy.pdp.rest;
 
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -42,17 +45,20 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.onap.policy.common.ia.DbDAO;
 import org.onap.policy.common.ia.IntegrityAuditProperties;
-import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.IntegrityMonitor;
-import org.onap.policy.common.im.StandbyStatusException;
+import org.onap.policy.common.im.IntegrityMonitorException;
+import org.onap.policy.common.logging.ONAPLoggingContext;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
-
-import org.onap.policy.pdp.rest.XACMLPdpServletTest;
+import org.onap.policy.rest.XACMLRestProperties;
+import org.onap.policy.xacml.std.pap.StdPDPPolicy;
+import org.onap.policy.xacml.std.pap.StdPDPStatus;
 import org.powermock.api.mockito.PowerMockito;
 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;
 
 import junit.framework.TestCase;
@@ -84,10 +90,19 @@ public class XACMLPdpServletTest extends TestCase{
        private static final String DEFAULT_DB_USER = "sa";
        private static final String DEFAULT_DB_PWD = "";
 
-        
+       private StdPDPStatus status;
+       private StdPDPPolicy foobarPolicy;
+
     @Before
     public void setUp(){
-       
+       status = new StdPDPStatus();
+       foobarPolicy = new StdPDPPolicy();
+               foobarPolicy.setId("foobar");
+               foobarPolicy.setVersion("123"); 
+               foobarPolicy.setName("nothing");
+               status.addLoadedPolicy(foobarPolicy);
+
+
        properties = new Properties();
                properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPdpServletTest.DEFAULT_DB_DRIVER);
                properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
@@ -168,24 +183,89 @@ public class XACMLPdpServletTest extends TestCase{
                
                try {
                        Mockito.doNothing().when(im).startTransaction();
-               } catch (StandbyStatusException | AdministrativeStateException e) {
+               } catch (IntegrityMonitorException e) {
                        fail();
                }
                Mockito.doNothing().when(im).endTransaction();
     }
-    
+
        @Test
     public void testInit(){
                LOGGER.info("XACMLPdpServletTest - testInit");
                try {   
                        pdpServlet.init(servletConfig);
+
+                       assertTrue(true);
+               } catch (Exception e) {
+                       LOGGER.error("Exception Occured"+e);
+                       fail();
+                       
+               }
+
+       }
+
+       @Test
+       public void testUebNotification() {
+               LOGGER.info("XACMLPdpServletTest - testUebNotification");
+               try {   
+
+                       XACMLProperties.reloadProperties();
+                       System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pdp.ueb.properties");
+                       XACMLProperties.getProperties();
+
+                  pdpServlet.init(servletConfig);
+
+                       status.setStatus(com.att.research.xacml.api.pap.PDPStatus.Status.UPDATING_CONFIGURATION);
+                       
+                       XACMLPdpLoader.validatePolicies(properties, status);
+                       XACMLPdpLoader.sendNotification();
+                       assertTrue(true);
+               } catch (Exception e) {
+                       LOGGER.error("Exception Occured"+e);
+                       fail();
+                       
+               }
+               
+       }
+
+       @Test
+       public void testDmaapNotification() {
+               LOGGER.info("XACMLPdpServletTest - testDmaapNotification");
+               try {   
+                       
+                       XACMLProperties.reloadProperties();
+                       System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pdp.dmaap.properties");
+                       XACMLProperties.getProperties();
+               
+                       pdpServlet.init(servletConfig);
+
+                       status.setStatus(com.att.research.xacml.api.pap.PDPStatus.Status.UPDATING_CONFIGURATION);
+                       
+                       XACMLPdpLoader.validatePolicies(properties, status);
+                       XACMLPdpLoader.sendNotification();
                        assertTrue(true);
                } catch (Exception e) {
                        LOGGER.error("Exception Occured"+e);
                        fail();
                        
                }
+               
+       }
+       
 
+       @Test
+       public void testXACMLPdpRegisterThread() {
+               LOGGER.info("XACMLPdpServletTest - testXACMLPdpRegisterThread");
+               try {
+                       ONAPLoggingContext baseLoggingContext = new ONAPLoggingContext();
+                       baseLoggingContext.setServer("localhost");
+                       XACMLPdpRegisterThread regThread = new XACMLPdpRegisterThread(baseLoggingContext);
+                       regThread.run();
+                       assertTrue(true);
+               } catch (Exception e) {
+                       LOGGER.error("Exception Occured"+e);
+                       fail();
+               }
        }
        
        @Test
@@ -203,7 +283,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }
-       
+   
        @Test
        public void testDoGetConfigType(){
                LOGGER.info("XACMLPdpServletTest - testDoGetConfigType");
@@ -221,7 +301,7 @@ public class XACMLPdpServletTest extends TestCase{
                }
 
        }
-       
+    
        @Test
        public void testDoGetTypeHb(){
                LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb");
@@ -237,7 +317,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }
-       
+    
        @Test
        public void testDoGetTypeStatus(){
                LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus");
@@ -253,7 +333,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }       
-       
+    
        @Test
        public void testDoPost(){
                LOGGER.info("XACMLPdpServletTest - testDoPost");
@@ -267,7 +347,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }
-       
+
        @Test
        public void testDoPostToLong(){
                LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -284,7 +364,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }       
-       
+
        @Test
        public void testDoPostContentLengthNegative(){
                LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -301,7 +381,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }       
-       
+
        @Test
        public void testDoPostContentTypeNonValid(){
                LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -318,7 +398,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }       
-       
+    
        @Test
        public void testDoPostContentTypeConfigurationError(){
                LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
@@ -335,7 +415,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }       
-       
+    
        @Test
        public void testDoPutCacheEmpty(){
                LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty");
@@ -355,7 +435,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }
-       
+    
        @Test
        public void testDoPutConfigPolicies(){
                LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies");
@@ -416,7 +496,7 @@ public class XACMLPdpServletTest extends TestCase{
                        fail();
                }
        }               
-       
+
        @Test
        public void testDestroy(){
                LOGGER.info("XACMLPdpServletTest - testDestroy");