aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PDP-REST/src/test/java/org/onap')
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java899
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java82
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java58
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java18
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java91
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java4
12 files changed, 682 insertions, 494 deletions
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
index 8c7fd7ef7..b017bc2a4 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
@@ -20,16 +20,12 @@
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;
import java.util.List;
import java.util.Properties;
import java.util.Random;
-
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
@@ -39,475 +35,468 @@ import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.onap.policy.common.ia.DbDAO;
import org.onap.policy.common.ia.IntegrityAuditProperties;
import org.onap.policy.common.im.IntegrityMonitor;
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.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.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
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;
-public class XACMLPdpServletTest extends TestCase{
- private static Logger LOGGER = FlexLogger.getLogger(XACMLPdpServletTest.class);
-
- private List<String> headers = new ArrayList<>();
-
- private HttpServletRequest httpServletRequest;
- private HttpServletResponse httpServletResponse;
- private ServletOutputStream mockOutput;
- private ServletInputStream mockInput;
- private ServletConfig servletConfig;
- private XACMLPdpServlet pdpServlet;
- private IntegrityMonitor im;
-
- private DbDAO dbDAO;
- private String persistenceUnit;
- private Properties properties;
- private String resourceName;
- private String dbDriver;
- private String dbUrl;
- private String dbUser;
- private String dbPwd;
- private String siteName;
- private String nodeType;
- private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
- 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");
- properties.put(IntegrityAuditProperties.DB_USER, XACMLPdpServletTest.DEFAULT_DB_USER);
- properties.put(IntegrityAuditProperties.DB_PWD, XACMLPdpServletTest.DEFAULT_DB_PWD);
- properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
- properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
- //properties.put("com.sun.management.jmxremote.port", "9999");
- dbDriver = XACMLPdpServletTest.DEFAULT_DB_DRIVER;
- dbUrl = "jdbc:h2:file:./sql/xacmlTest";
- dbUser = XACMLPdpServletTest.DEFAULT_DB_USER;
- dbPwd = XACMLPdpServletTest.DEFAULT_DB_PWD;
- siteName = "SiteA";
- nodeType = "pdp";
- persistenceUnit = "testPdpPU";
- resourceName = "siteA.pdp1";
-
- System.setProperty("com.sun.management.jmxremote.port", "9999");
-
- EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
-
- EntityManager em = emf.createEntityManager();
- // Start a transaction
- EntityTransaction et = em.getTransaction();
-
- IntegrityMonitor im = null;
- try {
- im = IntegrityMonitor.getInstance(resourceName, properties);
- } catch (Exception e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- }
- //cleanDb(persistenceUnit, properties);
-
- 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));
- Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pdp/test");
-
- 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);
- //servletConfig
- Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
- pdpServlet = new XACMLPdpServlet();
- pdpServlet.setIm(im);
-
- Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("src/test/resources/xacml.pdp.properties");
-
- System.setProperty("xacml.properties", "src/test/resources/xacml.pdp.properties");
- System.setProperty("xacml.rest.pdp.config", "src/test/resources/config_testing");
- System.setProperty("xacml.rest.pdp.webapps", "src/test/resources/webapps");
- /*System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
- 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");
- System.setProperty("com.sun.management.jmxremote.port", "9999");
-
- im = Mockito.mock(IntegrityMonitor.class);
- // Need PowerMockito for mocking static method getInstance(...)
- PowerMockito.mockStatic(IntegrityMonitor.class);
- try {
- // when IntegrityMonitor.getInstance is called, return the mock object
- PowerMockito.when(IntegrityMonitor.getInstance(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(im);
- } catch (Exception e1) {
- LOGGER.error("Exception Occured"+e1);
- }
-
- try {
- Mockito.doNothing().when(im).startTransaction();
- } catch (IntegrityMonitorException e) {
- fail();
- }
- Mockito.doNothing().when(im).endTransaction();
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({IntegrityMonitor.class})
+public class XACMLPdpServletTest extends TestCase {
+ private static Logger LOGGER = FlexLogger.getLogger(XACMLPdpServletTest.class);
+ private List<String> headers = new ArrayList<>();
+
+ private HttpServletRequest httpServletRequest;
+ private HttpServletResponse httpServletResponse;
+ private ServletOutputStream mockOutput;
+ private ServletInputStream mockInput;
+ private ServletConfig servletConfig;
+ private XACMLPdpServlet pdpServlet;
+ private String persistenceUnit;
+ private Properties properties;
+ private String resourceName;
+ private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
+ private static final String DEFAULT_DB_USER = "sa";
+ private static final String DEFAULT_DB_PWD = "";
+ private StdPDPStatus status;
+ private StdPDPPolicy foobarPolicy;
+
+ @Override
+ @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");
+ properties.put(IntegrityAuditProperties.DB_USER, XACMLPdpServletTest.DEFAULT_DB_USER);
+ properties.put(IntegrityAuditProperties.DB_PWD, XACMLPdpServletTest.DEFAULT_DB_PWD);
+ properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
+ properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
+ persistenceUnit = "testPdpPU";
+ resourceName = "siteA.pdp1";
+
+ System.setProperty("com.sun.management.jmxremote.port", "9999");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
+
+ EntityManager em = emf.createEntityManager();
+ // Start a transaction
+ EntityTransaction et = em.getTransaction();
+
+ IntegrityMonitor im = null;
+ try {
+ im = IntegrityMonitor.getInstance(resourceName, properties);
+ } catch (Exception e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ }
+ // cleanDb(persistenceUnit, properties);
+
+ 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));
+ Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pdp/test");
+
+ 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);
+ // servletConfig
+ Mockito.when(servletConfig.getInitParameterNames())
+ .thenReturn(Collections.enumeration(headers));
+ pdpServlet = new XACMLPdpServlet();
+ pdpServlet.setIm(im);
+
+ Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME"))
+ .thenReturn("src/test/resources/xacml.pdp.properties");
+
+ System.setProperty("xacml.properties", "src/test/resources/xacml.pdp.properties");
+ System.setProperty("xacml.rest.pdp.config", "src/test/resources/config_testing");
+ System.setProperty("xacml.rest.pdp.webapps", "src/test/resources/webapps");
+ /*
+ * System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
+ * 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");
+ System.setProperty("com.sun.management.jmxremote.port", "9999");
+
+ im = Mockito.mock(IntegrityMonitor.class);
+ // Need PowerMockito for mocking static method getInstance(...)
+ PowerMockito.mockStatic(IntegrityMonitor.class);
+ try {
+ // when IntegrityMonitor.getInstance is called, return the mock object
+ PowerMockito
+ .when(IntegrityMonitor.getInstance(Mockito.anyString(), Mockito.any(Properties.class)))
+ .thenReturn(im);
+ } catch (Exception e1) {
+ LOGGER.error("Exception Occured" + e1);
+ }
+
+ try {
+ Mockito.doNothing().when(im).startTransaction();
+ } 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 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
- public void testDoGetNoTypeError(){
- LOGGER.info("XACMLPdpServletTest - testDoGetNoTypeError");
- try{
-
- pdpServlet.init(servletConfig);
- pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- assertTrue(true);
- }catch(Exception e){
- System.out.println("Unexpected exception in testDoGetNoTypeError");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoGetConfigType(){
- LOGGER.info("XACMLPdpServletTest - testDoGetConfigType");
- Mockito.when(httpServletRequest.getParameter("type")).thenReturn("config");
-
- try{
- pdpServlet.init(servletConfig);
- pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoGetConfigType");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
-
- }
-
- @Test
- public void testDoGetTypeHb(){
- LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb");
- try{
- Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb");
- pdpServlet.init(servletConfig);
- pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- assertTrue(true);
- }catch(Exception e){
- System.out.println("Unexpected exception in testDoGetTypeHb");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoGetTypeStatus(){
- LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus");
- try{
- Mockito.when(httpServletRequest.getParameter("type")).thenReturn("Status");
- pdpServlet.init(servletConfig);
- pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- assertTrue(true);
- }catch(Exception e){
- System.out.println("Unexpected exception in testDoGetTypeStatus");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPost(){
- LOGGER.info("XACMLPdpServletTest - testDoPost");
- try{
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPost");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPostToLong(){
- LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
- try{
- Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostToLong");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPostContentLengthNegative(){
- LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
- try{
- Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(-1);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostContentLengthNegative");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPostContentTypeNonValid(){
- LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
- try{
- Mockito.when(httpServletRequest.getContentType()).thenReturn(";");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostContentTypeNonValid");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPostContentTypeConfigurationError(){
- LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
- try{
- Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostContentTypeConfigurationError");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPutCacheEmpty(){
- LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty");
- mockInput = Mockito.mock(ServletInputStream.class);
-
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("cache");
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
- Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT must contain at least one property");
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPutCacheEmpty");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPutConfigPolicies(){
- LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies");
- byte[] b = new byte[20];
- new Random().nextBytes(b);
-
- mockInput = new MockServletInputStream(b);
-
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
- Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPutConfigPolicies");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- public void testDoPutToLong(){
- LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
-
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(1000000000);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Content-Length larger than server will accept.");
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPutToLong");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPutInvalidContentType(){
- LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
-
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/json");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid cache: 'policies' or content-type: 'text/json'");
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPutInvalidContentType");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDestroy(){
- LOGGER.info("XACMLPdpServletTest - testDestroy");
-
- try{
- pdpServlet.init(servletConfig);
- pdpServlet.destroy();
- }catch(Exception e){
- System.out.println("Unexpected exception in testDestroy");
- 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
+ public void testDoGetNoTypeError() {
+ LOGGER.info("XACMLPdpServletTest - testDoGetNoTypeError");
+ try {
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doGet(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoGetNoTypeError");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoGetConfigType() {
+ LOGGER.info("XACMLPdpServletTest - testDoGetConfigType");
+ Mockito.when(httpServletRequest.getParameter("type")).thenReturn("config");
+
+ try {
+ pdpServlet.init(servletConfig);
+ pdpServlet.doGet(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoGetConfigType");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+
+ }
+
+ @Test
+ public void testDoGetTypeHb() {
+ LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb");
+ try {
+ Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb");
+ pdpServlet.init(servletConfig);
+ pdpServlet.doGet(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoGetTypeHb");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoGetTypeStatus() {
+ LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus");
+ try {
+ Mockito.when(httpServletRequest.getParameter("type")).thenReturn("Status");
+ pdpServlet.init(servletConfig);
+ pdpServlet.doGet(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoGetTypeStatus");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPost() {
+ LOGGER.info("XACMLPdpServletTest - testDoPost");
+ try {
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPost(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPost");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPostToLong() {
+ LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
+ try {
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPost(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPostToLong");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPostContentLengthNegative() {
+ LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
+ try {
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(-1);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPost(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPostContentLengthNegative");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPostContentTypeNonValid() {
+ LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
+ try {
+ Mockito.when(httpServletRequest.getContentType()).thenReturn(";");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPost(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPostContentTypeNonValid");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPostContentTypeConfigurationError() {
+ LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
+ try {
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPost(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPostContentTypeConfigurationError");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPutCacheEmpty() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty");
+ mockInput = Mockito.mock(ServletInputStream.class);
+
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("cache");
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "PUT must contain at least one property");
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPutCacheEmpty");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPutConfigPolicies() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies");
+ byte[] b = new byte[20];
+ new Random().nextBytes(b);
+
+ mockInput = new MockServletInputStream(b);
+
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPutConfigPolicies");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ public void testDoPutToLong() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
+
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(1000000000);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "Content-Length larger than server will accept.");
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPutToLong");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPutInvalidContentType() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
+
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/json");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "Invalid cache: 'policies' or content-type: 'text/json'");
+ assertTrue(true);
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDoPutInvalidContentType");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDestroy() {
+ LOGGER.info("XACMLPdpServletTest - testDestroy");
+
+ try {
+ pdpServlet.init(servletConfig);
+ pdpServlet.destroy();
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in testDestroy");
+ LOGGER.error("Exception Occured" + e);
+ fail();
+ }
+ }
}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java
new file mode 100644
index 000000000..a48791cf0
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.rest.api.models;
+
+import static org.junit.Assert.assertEquals;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.policy.api.PolicyConfigStatus;
+import org.onap.policy.api.PolicyDecision;
+import org.onap.policy.api.PolicyResponseStatus;
+import org.onap.policy.api.PolicyType;
+
+public class PDPResponseTest {
+ @Test
+ public void testSetAndGet() {
+ // Test values
+ String message = "testMessage";
+ String config = "testConfig";
+ String policyName = "testPolicyName";
+ String policyVersion = "1.0";
+ PolicyResponseStatus policyResponseStatus = PolicyResponseStatus.ACTION_ADVISED;
+ PolicyConfigStatus policyConfigStatus = PolicyConfigStatus.CONFIG_RETRIEVED;
+ PolicyType type = PolicyType.JSON;
+ Map<String, String> property = new HashMap<String, String>();
+ PolicyDecision policyDecision = PolicyDecision.PERMIT;
+
+ PDPResponse response = new PDPResponse();
+
+ response.setStatus(message, policyResponseStatus, policyConfigStatus);
+ response.setConfig(config);
+ assertEquals(config, response.getConfig());
+ response.setType(type);
+ assertEquals(type, response.getType());
+ response.setPolicyConfigStatus(policyConfigStatus);
+ assertEquals(policyConfigStatus, response.getPolicyConfigStatus());
+ response.setPolicyConfigMessage(message);
+ assertEquals(message, response.getPolicyConfigMessage());
+ response.setProperty(property);
+ assertEquals(property, response.getProperty());
+ response.setPolicyName(policyName);
+ assertEquals(policyName, response.getPolicyName());
+ response.setPolicyVersion(policyVersion);
+ assertEquals(policyVersion, response.getPolicyVersion());
+ response.setMatchingConditions(property);
+ assertEquals(property, response.getMatchingConditions());
+ response.setResponseAttributes(property);
+ assertEquals(property, response.getResponseAttributes());
+ response.setPolicyResponseStatus(policyResponseStatus);
+ assertEquals(policyResponseStatus, response.getPolicyResponseStatus());
+ response.setDecision(policyDecision);
+ assertEquals(policyDecision, response.getDecision());
+ response.setDetails(message);
+ assertEquals(message, response.getDetails());
+ response.setActionAdvised(property);
+ assertEquals(property, response.getActionAdvised());
+ response.setActionTaken(property);
+ assertEquals(property, response.getActionTaken());
+ response.setRequestAttributes(property);
+ assertEquals(property, response.getRequestAttributes());
+ response.setPolicyResponseMessage(message);
+ assertEquals(message, response.getPolicyResponseMessage());
+ }
+}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java
index 8867a7828..23e47f418 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java
@@ -50,7 +50,7 @@ public class BRMSParamPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
@@ -80,7 +80,7 @@ public class BRMSParamPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java
index 8d5312705..b9e9403d4 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java
@@ -20,31 +20,43 @@
package org.onap.policy.pdp.rest.api.services;
import static org.junit.Assert.assertEquals;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
import org.junit.Test;
-import org.onap.policy.api.PolicyException;
import org.onap.policy.api.PolicyParameters;
public class BRMSRawPolicyServiceTest {
- @Test
- public void testRaw() throws PolicyException {
- String systemKey = "xacml.properties";
- String testVal = "testVal";
- PolicyParameters testParams = new PolicyParameters();
-
- // Set the system property temporarily
- String oldProperty = System.getProperty(systemKey);
- System.setProperty(systemKey, "xacml.pdp.properties");
-
- BRMSRawPolicyService service = new BRMSRawPolicyService(testVal, testVal, testParams, testVal);
- assertEquals(service.getValidation(), false);
- assertEquals(service.getMessage(), "PE300 - Data Issue: No Rule Body given");
-
- // Restore the original system property
- if (oldProperty != null) {
- System.setProperty(systemKey, oldProperty);
- }
- else {
- System.clearProperty(systemKey);
- }
- }
+ @Test
+ public void testRaw() throws FileNotFoundException, IOException {
+ Properties prop = new Properties();
+ prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
+ String succeeded = prop.getProperty("xacml.rest.pap.url");
+ List<String> paps = Arrays.asList(succeeded.split(","));
+ PAPServices.setPaps(paps);
+ PAPServices.setJunit(true);
+ prop.clear();
+
+ String systemKey = "xacml.properties";
+ String testVal = "testVal";
+ PolicyParameters testParams = new PolicyParameters();
+
+ // Set the system property temporarily
+ String oldProperty = System.getProperty(systemKey);
+ System.setProperty(systemKey, "xacml.pdp.properties");
+
+ BRMSRawPolicyService service = new BRMSRawPolicyService(testVal, testVal, testParams, testVal);
+ assertEquals(false, service.getValidation());
+ assertEquals("PE300 - Data Issue: No Rule Body given", service.getMessage());
+
+ // Restore the original system property
+ if (oldProperty != null) {
+ System.setProperty(systemKey, oldProperty);
+ } else {
+ System.clearProperty(systemKey);
+ }
+ }
}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java
index de884b349..c21bc9c77 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java
@@ -47,7 +47,7 @@ public class ClosedLoopFaultPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
@@ -69,7 +69,7 @@ public class ClosedLoopFaultPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java
index 19bb279e6..99dc67742 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java
@@ -47,7 +47,7 @@ public class ClosedLoopPMPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
@@ -69,7 +69,7 @@ public class ClosedLoopPMPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java
index 389d9bfc1..16f5a4732 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java
@@ -20,13 +20,27 @@
package org.onap.policy.pdp.rest.api.services;
import static org.junit.Assert.assertEquals;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
import org.junit.Test;
-import org.onap.policy.api.PolicyException;
import org.onap.policy.api.PolicyParameters;
public class ConfigPolicyServiceTest {
@Test
- public void testRaw() throws PolicyException {
+ public void testRaw() throws FileNotFoundException, IOException {
+ Properties prop = new Properties();
+ prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
+ String succeeded = prop.getProperty("xacml.rest.pap.url");
+ List<String> paps = Arrays.asList(succeeded.split(","));
+ PAPServices.setPaps(paps);
+ PAPServices.setJunit(true);
+
String systemKey = "xacml.properties";
String testVal = "testVal";
PolicyParameters testParams = new PolicyParameters();
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java
index 0fcb0027c..fe0668115 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java
@@ -49,7 +49,7 @@ public class DecisionPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyClass(PolicyClass.Decision);
@@ -94,7 +94,7 @@ public class DecisionPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java
index 4343a5060..ccedd7553 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java
@@ -46,7 +46,7 @@ public class FirewallPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); //required
@@ -67,7 +67,7 @@ public class FirewallPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java
index a9301e728..e460a853b 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java
@@ -47,7 +47,7 @@ public class MicroServicesPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
@@ -69,7 +69,7 @@ public class MicroServicesPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java
new file mode 100644
index 000000000..79ca2e646
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pdp.rest.api.services;
+
+import static org.junit.Assert.*;
+
+import java.io.FileInputStream;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.api.PolicyConfigType;
+import org.onap.policy.api.PolicyException;
+import org.onap.policy.api.PolicyParameters;
+
+public class OptimizationPolicyServiceTest {
+
+ OptimizationPolicyService service = null;
+
+ @Before
+ public void setUp() throws Exception {
+ Properties prop = new Properties();
+ prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
+ String succeeded = prop.getProperty("xacml.rest.pap.url");
+ List<String> paps = Arrays.asList(succeeded.split(","));
+ PAPServices.setPaps(paps);
+ PAPServices.setJunit(true);
+ prop.clear();
+
+ PolicyParameters policyParameters = new PolicyParameters();
+ policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
+ policyParameters.setPolicyName("Test.testOOFPolicy");
+ policyParameters.setOnapName("OOF");
+ policyParameters.setRequestID(UUID.randomUUID());
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ policyParameters.setGuard(true);
+ policyParameters.setRiskLevel("5");
+ policyParameters.setRiskType("TEST");
+ policyParameters.setConfigBody("{\"optimization\":\"test\"}");
+ String policyName = "testOOFPolicy";
+ String policyScope = "Test";
+ service = new OptimizationPolicyService(policyName, policyScope, policyParameters, date.toString());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testOptimizationPolicyService() {
+ assertNotNull(service);
+ }
+
+ @Test
+ public final void testGetMessage() {
+ String message = service.getMessage();
+ assertNull(message);
+ }
+
+ @Test
+ public final void testGetResult() throws PolicyException {
+ String result = service.getResult(false);
+ assertEquals("success",result);
+ }
+
+}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java
index 9d1d13910..93fde841d 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java
@@ -40,7 +40,7 @@ public class PAPServicesTest {
@Before
public void setUp() throws Exception {
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
Properties prop = new Properties();
prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
String succeeded = prop.getProperty("xacml.rest.pap.url");
@@ -53,7 +53,7 @@ public class PAPServicesTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test