aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ONAP-PDP-REST/pom.xml35
-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/services/BRMSRawPolicyServiceTest.java61
-rw-r--r--ONAP-PDP/pom.xml24
-rw-r--r--ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactoryTest.java78
-rw-r--r--ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineTest.java45
-rw-r--r--ONAP-REST/pom.xml40
-rw-r--r--ONAP-XACML/pom.xml24
-rw-r--r--ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineFactoryTest.java59
-rw-r--r--ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPItemSetChangeNotifierTest.java43
-rw-r--r--PolicyEngineAPI/pom.xml26
-rw-r--r--PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java1350
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java52
13 files changed, 1519 insertions, 1217 deletions
diff --git a/ONAP-PDP-REST/pom.xml b/ONAP-PDP-REST/pom.xml
index b559269b3..f800a8f31 100644
--- a/ONAP-PDP-REST/pom.xml
+++ b/ONAP-PDP-REST/pom.xml
@@ -48,6 +48,26 @@
</plugins>
</build>
<dependencies>
+ <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito -->
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@@ -151,11 +171,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>1.9.5</version>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
@@ -166,16 +181,6 @@
<version>0.3.1</version>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
- <version>1.5.6</version>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>1.5.6</version>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
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/services/BRMSRawPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java
index 5f20dfb85..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,46 +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.PolicyParameters;
public class BRMSRawPolicyServiceTest {
- @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);
- }
- }
+ @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/pom.xml b/ONAP-PDP/pom.xml
index 02057bd3a..a2cbc8b37 100644
--- a/ONAP-PDP/pom.xml
+++ b/ONAP-PDP/pom.xml
@@ -34,6 +34,25 @@
</parent>
<dependencies>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito -->
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.onap.policy.engine</groupId>
<version>${project.version}</version>
<artifactId>ONAP-REST</artifactId>
@@ -94,6 +113,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.mockrunner</groupId>
+ <artifactId>mockrunner</artifactId>
+ <version>0.3.1</version>
+ </dependency>
</dependencies>
</project>
diff --git a/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactoryTest.java b/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactoryTest.java
index 0c9d24615..1bde7dd84 100644
--- a/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactoryTest.java
+++ b/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactoryTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP
* ================================================================================
- * 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.
@@ -21,32 +21,66 @@ package org.onap.policy.xacml.pdp;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
import java.util.Properties;
-
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import com.att.research.xacml.util.FactoryException;
+import com.att.research.xacml.util.FactoryFinder;
+import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory;
+@RunWith(PowerMockRunner.class)
public class ONAPPDPEngineFactoryTest {
+ @Test
+ public final void testNewEngine() {
+ ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
+ try {
+ assertTrue(pdpEngine.newEngine() != null);
+ } catch (Exception e) {
+ fail("operation failed, e=" + e);
+ }
+ }
+
+ @Test
+ public final void testNewEngineProperties() {
+ ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
+ Properties properties = new Properties();
+ try {
+ assertTrue(pdpEngine.newEngine(properties) != null);
+ } catch (Exception e) {
+ fail("operation failed, e=" + e);
+ }
+ }
+
+ @PrepareForTest({EvaluationContextFactory.class, FactoryFinder.class})
+ @Test(expected = FactoryException.class)
+ public void negTestEngine() throws FactoryException {
+ // Setup test data
+ PowerMockito.mockStatic(FactoryFinder.class);
+ PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(null);
- @Test
- public final void testNewEngine() {
- ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
- try{
- assertTrue(pdpEngine.newEngine() != null);
- }catch (Exception e) {
- fail("operation failed, e="+e);
- }
+ // Negative test factory
+ ONAPPDPEngineFactory factory = new ONAPPDPEngineFactory();
+ factory.newEngine();
+ fail("Expecting an exception.");
+ }
- }
+ @PrepareForTest({EvaluationContextFactory.class, FactoryFinder.class})
+ @Test(expected = FactoryException.class)
+ public void negTestEngine2() throws FactoryException {
+ // Setup test data
+ PowerMockito.mockStatic(FactoryFinder.class);
+ PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(null);
- @Test
- public final void testNewEngineProperties() {
- ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
- Properties properties = new Properties();
- try{
- assertTrue(pdpEngine.newEngine(properties) != null);
- }catch (Exception e) {
- fail("operation failed, e="+e);
- }
- }
+ // Negative test factory
+ ONAPPDPEngineFactory factory = new ONAPPDPEngineFactory();
+ Properties properties = new Properties();
+ factory.newEngine(properties);
+ fail("Expecting an exception.");
+ }
}
diff --git a/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineTest.java b/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineTest.java
new file mode 100644
index 000000000..6eb6e4cfc
--- /dev/null
+++ b/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/ONAPPDPEngineTest.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PDP
+ * ================================================================================
+ * 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.xacml.pdp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+import org.mockito.Mockito;
+import com.att.research.xacml.api.Request;
+import com.att.research.xacml.api.Response;
+import com.att.research.xacml.api.pdp.PDPException;
+import com.att.research.xacml.api.pdp.ScopeResolver;
+import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory;
+
+public class ONAPPDPEngineTest {
+ @Test
+ public void testEngine() throws PDPException {
+ EvaluationContextFactory factory = Mockito.mock(EvaluationContextFactory.class);
+ ScopeResolver resolver = Mockito.mock(ScopeResolver.class);
+ ONAPPDPEngine engine = new ONAPPDPEngine(factory, resolver);
+ assertNotNull(engine);
+
+ Request pepRequest = Mockito.mock(Request.class);
+ Response response = engine.decide(pepRequest);
+ assertEquals(1, response.getResults().size());
+ }
+}
diff --git a/ONAP-REST/pom.xml b/ONAP-REST/pom.xml
index 5111d5190..920ef216f 100644
--- a/ONAP-REST/pom.xml
+++ b/ONAP-REST/pom.xml
@@ -22,21 +22,15 @@
Apache Ivy version: 2.0.0-beta1 20071206070608 -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
<modelVersion>4.0.0</modelVersion>
-
<parent>
<groupId>org.onap.policy.engine</groupId>
<artifactId>PolicyEngineSuite</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
-
<artifactId>ONAP-REST</artifactId>
-
<description>ONAP REST</description>
-
<packaging>jar</packaging>
-
<dependencies>
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
<dependency>
@@ -44,6 +38,26 @@
<artifactId>snakeyaml</artifactId>
<version>1.16</version>
</dependency>
+ <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito -->
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@@ -110,11 +124,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>1.9.5</version>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
@@ -195,15 +204,8 @@
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>8.5.9</version>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4-common</artifactId>
- <version>1.6.4</version>
- </dependency>
-
+ </dependency>
</dependencies>
-
<properties>
<springframework.version>4.3.3.RELEASE</springframework.version>
<hibernate.version>4.3.10.Final</hibernate.version>
diff --git a/ONAP-XACML/pom.xml b/ONAP-XACML/pom.xml
index b6f12c005..8bfa06b35 100644
--- a/ONAP-XACML/pom.xml
+++ b/ONAP-XACML/pom.xml
@@ -32,6 +32,25 @@
<artifactId>ONAP-XACML</artifactId>
<packaging>jar</packaging>
<dependencies>
+ <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito -->
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.onap.policy.engine</groupId>
<version>${project.version}</version>
@@ -59,11 +78,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>2.7.22</version>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineFactoryTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineFactoryTest.java
index 3fa49551b..500136fc0 100644
--- a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineFactoryTest.java
+++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineFactoryTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-XACML
* ================================================================================
- * 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,32 +20,55 @@
package org.onap.policy.xacml.test.std.pap;
import static org.junit.Assert.assertTrue;
-
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.Properties;
-
import org.junit.Test;
import org.onap.policy.xacml.std.pap.StdEngineFactory;
-
import com.att.research.xacml.api.pap.PAPException;
+import com.att.research.xacml.std.pap.StdEngine;
import com.att.research.xacml.util.FactoryException;
public class StdEngineFactoryTest {
+ @Test
+ public void testStdEngineFactory() throws FactoryException, PAPException, IOException {
+ StdEngineFactory stdFactory = new StdEngineFactory();
+ System.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
+ assertTrue(stdFactory.newEngine() != null);
+ Properties properties = new Properties();
+ properties.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
+ assertTrue(stdFactory.newEngine(properties) != null);
+
+ StdEngineFactory stdFactoryNew = new StdEngineFactory();
+ System.setProperty("xacml.pap.pdps", "src/test/resources/pdpstest");
+ assertTrue(stdFactoryNew.newEngine() != null);
+ }
+
+ @Test
+ public void testNegativeCase() throws FactoryException, PAPException {
+ // Setup test data
+ Properties props = new Properties();
+ props.setProperty(StdEngine.PROP_PAP_REPO, "/tmp");
+ // Set the system property temporarily
+ String systemKey = StdEngine.PROP_PAP_REPO;
+ String oldProperty = System.getProperty(systemKey);
+ System.setProperty(systemKey, "/tmp");
- @Test
- public void testStdEngineFactory() throws FactoryException, PAPException, IOException{
-
- StdEngineFactory stdFactory = new StdEngineFactory();
- System.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
- assertTrue(stdFactory.newEngine() != null);
- Properties properties = new Properties();
- properties.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
- assertTrue(stdFactory.newEngine(properties) != null);
-
- StdEngineFactory stdFactoryNew = new StdEngineFactory();
- System.setProperty("xacml.pap.pdps", "src/test/resources/pdpstest");
- assertTrue(stdFactoryNew.newEngine() != null);
+ // Test factory failure cases
+ try {
+ StdEngineFactory factory = new StdEngineFactory();
+ factory.newEngine();
+ factory.newEngine(props);
+ } catch (Exception ex) {
+ fail("Not expecting any exceptions: " + ex);
+ }
- }
+ // Restore the original system property
+ if (oldProperty != null) {
+ System.setProperty(systemKey, oldProperty);
+ } else {
+ System.clearProperty(systemKey);
+ }
+ }
}
diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPItemSetChangeNotifierTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPItemSetChangeNotifierTest.java
new file mode 100644
index 000000000..1be34ee00
--- /dev/null
+++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPItemSetChangeNotifierTest.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-XACML
+ * ================================================================================
+ * 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.xacml.test.std.pap;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.policy.xacml.api.pap.OnapPDP;
+import org.onap.policy.xacml.api.pap.OnapPDPGroup;
+import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier;
+import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener;
+
+public class StdPDPItemSetChangeNotifierTest {
+ @Test
+ public void testNotifier() {
+ StdPDPItemSetChangeNotifier notifier = new StdPDPItemSetChangeNotifier();
+ StdItemSetChangeListener listener = Mockito.mock(StdItemSetChangeListener.class);
+ notifier.addItemSetChangeListener(listener);
+ notifier.removeItemSetChangeListener(listener);
+ notifier.fireChanged();
+ OnapPDP pdp = Mockito.mock(OnapPDP.class);
+ notifier.firePDPChanged(pdp);
+ OnapPDPGroup group = Mockito.mock(OnapPDPGroup.class);
+ notifier.firePDPGroupChanged(group);
+ }
+}
diff --git a/PolicyEngineAPI/pom.xml b/PolicyEngineAPI/pom.xml
index be3700eba..6ffef7594 100644
--- a/PolicyEngineAPI/pom.xml
+++ b/PolicyEngineAPI/pom.xml
@@ -31,6 +31,26 @@
<artifactId>PolicyEngineAPI</artifactId>
<dependencies>
+ <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito -->
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.7.3</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
@@ -119,12 +139,6 @@
</exclusion>
</exclusions>
</dependency>
- <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.10.19</version>
- </dependency>
</dependencies>
<build>
<plugins>
diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java
index 1218f1914..4ede02806 100644
--- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java
+++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java
@@ -22,8 +22,8 @@ package org.onap.policy.std;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
@@ -72,7 +72,6 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.DecisionRequestParameters;
import org.onap.policy.api.DecisionResponse;
@@ -102,826 +101,887 @@ import org.onap.policy.api.PushPolicyParameters;
import org.onap.policy.models.APIDictionaryResponse;
import org.onap.policy.models.APIPolicyConfigResponse;
import org.onap.policy.std.utils.PolicyConfigConstants;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(PowerMockRunner.class)
public class StdPolicyEngineTest {
- private static final String ONAP_NAME_VAL = "ONAP_NAME";
- private static final String POLICY_VERSION = "1.0.0";
- private static final String POLICY_NAME = "ONAP";
- private static final String COMMENTS = "";
- private static final UUID REQUEST_UUID = UUID.randomUUID();
- private static final String SERVER_NAME = "localhost.com";
- private static final String PDP_PROP_VALUE = "http://localhost:8092/pdp/ , test, test";
- private static final String PDP_PROP_VALUE_1 = "https://localhost:8091/pdp/ , onap, onap";
- private static final String JSON_CONFIGURATION = "{\"name\":\"value\"}";
- private static final String XML_CONFIGURATION =
- "<map><entry><string>name</string><string>value</string></entry></map>";
-
- @Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
-
- private static final String CONFIG_PROPERTIES_FILE = "config_pass.properties";
- private static final String INVALID_CONFIG_PROPERTY_FILE = "config_fail.properties";
-
- @Test
- public void testStdPolicyEngineInitialize_noException() throws Exception {
- final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
-
- creatPropertyFile(file, getDefaultProperties());
-
- final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
- policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
- assertEquals("TEST", StdPolicyEngine.getEnvironment());
- assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
- assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
- assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList());
- }
-
- @Test
- public void testStdPolicyEngineWithPropertiesInitialize_noException() throws Exception {
- final StdPolicyEngine policyEngine = new StdPolicyEngine(getDefaultProperties(), (String) null);
- policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
- assertEquals("TEST", StdPolicyEngine.getEnvironment());
- assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
- assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
- assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList());
- }
-
- @Test
- public void testStdPolicyEngineInitializeWithSingleServerName_noException() throws Exception {
- final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
-
- final Properties properties = new Properties();
- properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
- properties.setProperty(CLIENT_ID_PROP_NAME, "test");
- properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
- properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB);
- properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME);
- properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
- properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
- creatPropertyFile(file, properties);
-
- final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
- policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
- assertEquals(Arrays.asList(SERVER_NAME), policyEngine.getNotificationURLList());
- }
-
- @Test
- public void testStdPolicyEngineInitializeWithSingleNotificationType_noException() throws Exception {
- final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
-
- final Properties properties = new Properties();
- properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
- properties.setProperty(CLIENT_ID_PROP_NAME, "test");
- properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
- properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB);
- properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME);
- properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
- properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
- creatPropertyFile(file, properties);
-
- final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
- policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
- assertEquals(Arrays.asList(UEB), policyEngine.getNotificationType());
- }
-
- @Test(expected = PolicyEngineException.class)
- public void testStdPolicyEngineInitialize_InvalidPropertyFile_Exception() throws PolicyEngineException {
- new StdPolicyEngine("Invalid.properties", (String) null);
- }
-
- @Test(expected = PolicyEngineException.class)
- public void testStdPolicyEngineInitialize_InvalidPropertyFileWithExt_Exception() throws Exception {
- final File emptyFile = temporaryFolder.newFile("EmptyFile.txt");
- new StdPolicyEngine(emptyFile.toString(), (String) null);
- }
-
- @Test(expected = PolicyEngineException.class)
- public void testStdPolicyEngineInitialize_NullArguments_Exception() throws Exception {
- new StdPolicyEngine((String)null, (String) null);
- }
-
- @Test(expected = PolicyEngineException.class)
- public void testStdPolicyEngineWithPropertiesInitialize_NullArguments_Exception() throws Exception {
- new StdPolicyEngine((Properties)null, (String) null);
- }
-
- @Test(expected = PolicyEngineException.class)
- public void testStdPolicyEngineInitialize_PropertyFileMissingMandatoryProperties_Exception() throws Exception {
- final File file = temporaryFolder.newFile(INVALID_CONFIG_PROPERTY_FILE);
- final Properties properties = new Properties();
- properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
- creatPropertyFile(file, properties);
-
- new StdPolicyEngine(file.toString(), (String) null);
- }
-
- @Test
- public void testStdPolicyEngineInitialize_MultiplePdp_noException() throws Exception {
- final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
-
- final Properties properties = new Properties();
- properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE + PolicyConfigConstants.SEMICOLLON + PDP_PROP_VALUE_1);
- properties.setProperty(CLIENT_ID_PROP_NAME, "test");
- properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
- properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
- properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
- properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
- properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
- creatPropertyFile(file, properties);
-
- final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
- policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
- assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
- StdPolicyEngine.rotatePDPList();
- assertEquals("https://localhost:8091/pdp/", StdPolicyEngine.getPDPURL());
- assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
- assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList());
- }
-
- @Test(expected = PolicyEngineException.class)
- public void testStdPolicyEngineInitialize_NoPDP_noException() throws Exception {
- final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
-
- final Properties properties = new Properties();
- properties.setProperty(CLIENT_ID_PROP_NAME, "test");
- properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
- properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
- properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
- properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
- properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
- creatPropertyFile(file, properties);
-
- new StdPolicyEngine(file.toString(), (String) null);
- }
-
- @Test
- public void testStdPolicyEngineInitializeNotificationTypeDMMAP_noException() throws Exception {
- final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
-
- final Properties properties = new Properties();
- properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
- properties.setProperty(CLIENT_ID_PROP_NAME, "test");
- properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
- properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, DMAAP);
- properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
- properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
- properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
- creatPropertyFile(file, properties);
-
- final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
- policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
-
- assertEquals(Arrays.asList(DMAAP), policyEngine.getNotificationType());
-
- }
-
- @Test
- public void testStdPolicyEngineSendEvent_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doReturn(new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED)).when(spyPolicyEngine)
- .callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any());
-
- final Collection<PolicyResponse> actualPolicyResponses =
- spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID);
-
- assertEquals(1, actualPolicyResponses.size());
-
- }
-
- @Test(expected = PolicyEventException.class)
- public void testStdPolicyEngineSendEvent_NullEventRequestParameters_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- spyPolicyEngine.sendEvent((EventRequestParameters) null);
- }
-
- @Test(expected = PolicyEventException.class)
- public void testStdPolicyEngineSendEvent_EventRequestParameters_CallPDPThrow401Exception_Exception()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- Mockito.doThrow(new RuntimeException(new RestClientException("Error 401"))).when(spyPolicyEngine)
- .callNewPDP(any(), any(), any(), any());
+ private static final String ONAP_NAME_VAL = "ONAP_NAME";
+ private static final String POLICY_VERSION = "1.0.0";
+ private static final String POLICY_NAME = "ONAP";
+ private static final String COMMENTS = "";
+ private static final UUID REQUEST_UUID = UUID.randomUUID();
+ private static final String SERVER_NAME = "localhost.com";
+ private static final String PDP_PROP_VALUE = "http://localhost:8092/pdp/ , test, test";
+ private static final String PDP_PROP_VALUE_1 = "https://localhost:8091/pdp/ , onap, onap";
+ private static final String JSON_CONFIGURATION = "{\"name\":\"value\"}";
+ private static final String XML_CONFIGURATION =
+ "<map><entry><string>name</string><string>value</string></entry></map>";
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ private static final String CONFIG_PROPERTIES_FILE = "config_pass.properties";
+ private static final String INVALID_CONFIG_PROPERTY_FILE = "config_fail.properties";
+
+ @Test
+ public void testStdPolicyEngineInitialize_noException() throws Exception {
+ final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
+
+ creatPropertyFile(file, getDefaultProperties());
+
+ final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
+ policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
+ assertEquals("TEST", StdPolicyEngine.getEnvironment());
+ assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
+ assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
+ assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList());
+ }
+
+ @Test
+ public void testStdPolicyEngineWithPropertiesInitialize_noException() throws Exception {
+ final StdPolicyEngine policyEngine = new StdPolicyEngine(getDefaultProperties(), (String) null);
+ policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
+ assertEquals("TEST", StdPolicyEngine.getEnvironment());
+ assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
+ assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
+ assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList());
+ }
+
+ @Test
+ public void testStdPolicyEngineInitializeWithSingleServerName_noException() throws Exception {
+ final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
+
+ final Properties properties = new Properties();
+ properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
+ properties.setProperty(CLIENT_ID_PROP_NAME, "test");
+ properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
+ properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB);
+ properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME);
+ properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
+ properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
+ creatPropertyFile(file, properties);
+
+ final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
+ policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
+ assertEquals(Arrays.asList(SERVER_NAME), policyEngine.getNotificationURLList());
+ }
+
+ @Test
+ public void testStdPolicyEngineInitializeWithSingleNotificationType_noException()
+ throws Exception {
+ final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
+
+ final Properties properties = new Properties();
+ properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
+ properties.setProperty(CLIENT_ID_PROP_NAME, "test");
+ properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
+ properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB);
+ properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME);
+ properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
+ properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
+ creatPropertyFile(file, properties);
+
+ final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
+ policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
+ assertEquals(Arrays.asList(UEB), policyEngine.getNotificationType());
+ }
+
+ @Test(expected = PolicyEngineException.class)
+ public void testStdPolicyEngineInitialize_InvalidPropertyFile_Exception()
+ throws PolicyEngineException {
+ new StdPolicyEngine("Invalid.properties", (String) null);
+ }
+
+ @Test(expected = PolicyEngineException.class)
+ public void testStdPolicyEngineInitialize_InvalidPropertyFileWithExt_Exception()
+ throws Exception {
+ final File emptyFile = temporaryFolder.newFile("EmptyFile.txt");
+ new StdPolicyEngine(emptyFile.toString(), (String) null);
+ }
+
+ @Test(expected = PolicyEngineException.class)
+ public void testStdPolicyEngineInitialize_NullArguments_Exception() throws Exception {
+ new StdPolicyEngine((String) null, (String) null);
+ }
+
+ @Test(expected = PolicyEngineException.class)
+ public void testStdPolicyEngineWithPropertiesInitialize_NullArguments_Exception()
+ throws Exception {
+ new StdPolicyEngine((Properties) null, (String) null);
+ }
+
+ @Test(expected = PolicyEngineException.class)
+ public void testStdPolicyEngineInitialize_PropertyFileMissingMandatoryProperties_Exception()
+ throws Exception {
+ final File file = temporaryFolder.newFile(INVALID_CONFIG_PROPERTY_FILE);
+ final Properties properties = new Properties();
+ properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
+ creatPropertyFile(file, properties);
+
+ new StdPolicyEngine(file.toString(), (String) null);
+ }
+
+ @Test
+ public void testStdPolicyEngineInitialize_MultiplePdp_noException() throws Exception {
+ final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
+
+ final Properties properties = new Properties();
+ properties.setProperty(PDP_URL_PROP_NAME,
+ PDP_PROP_VALUE + PolicyConfigConstants.SEMICOLLON + PDP_PROP_VALUE_1);
+ properties.setProperty(CLIENT_ID_PROP_NAME, "test");
+ properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
+ properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
+ properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
+ properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
+ properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
+ creatPropertyFile(file, properties);
+
+ final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
+ policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
+ assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
+ StdPolicyEngine.rotatePDPList();
+ assertEquals("https://localhost:8091/pdp/", StdPolicyEngine.getPDPURL());
+ assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
+ assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList());
+ }
+
+ @Test(expected = PolicyEngineException.class)
+ public void testStdPolicyEngineInitialize_NoPDP_noException() throws Exception {
+ final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
+
+ final Properties properties = new Properties();
+ properties.setProperty(CLIENT_ID_PROP_NAME, "test");
+ properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
+ properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
+ properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
+ properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
+ properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
+ creatPropertyFile(file, properties);
+
+ new StdPolicyEngine(file.toString(), (String) null);
+ }
+
+ @Test
+ public void testStdPolicyEngineInitializeNotificationTypeDMMAP_noException() throws Exception {
+ final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
+
+ final Properties properties = new Properties();
+ properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
+ properties.setProperty(CLIENT_ID_PROP_NAME, "test");
+ properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
+ properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, DMAAP);
+ properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
+ properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
+ properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
+ creatPropertyFile(file, properties);
+
+ final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
+ policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
+
+ assertEquals(Arrays.asList(DMAAP), policyEngine.getNotificationType());
+
+ }
+
+ @Test
+ public void testStdPolicyEngineSendEvent_noException() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doReturn(new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED))
+ .when(spyPolicyEngine).callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any());
+
+ final Collection<PolicyResponse> actualPolicyResponses =
spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID);
- }
- @Test
- public void testStdPolicyEngineSendEvent_EventRequestParameters_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ assertEquals(1, actualPolicyResponses.size());
- final ResponseEntity<StdPolicyResponse[]> stubbedResponse =
- new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED);
+ }
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any());
+ @Test(expected = PolicyEventException.class)
+ public void testStdPolicyEngineSendEvent_NullEventRequestParameters_Exception() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ spyPolicyEngine.sendEvent((EventRequestParameters) null);
+ }
- final EventRequestParameters eventRequestParameters = new EventRequestParameters();
- eventRequestParameters.setEventAttributes(Collections.emptyMap());
- eventRequestParameters.setRequestID(REQUEST_UUID);
+ @Test(expected = PolicyEventException.class)
+ public void testStdPolicyEngineSendEvent_EventRequestParameters_CallPDPThrow401Exception_Exception()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ Mockito.doThrow(new RuntimeException(new RestClientException("Error 401")))
+ .when(spyPolicyEngine).callNewPDP(any(), any(), any(), any());
+ spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID);
+ }
- final Collection<PolicyResponse> actualPolicyResponses = spyPolicyEngine.sendEvent(eventRequestParameters);
+ @Test
+ public void testStdPolicyEngineSendEvent_EventRequestParameters_noException() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- assertEquals(1, actualPolicyResponses.size());
+ final ResponseEntity<StdPolicyResponse[]> stubbedResponse =
+ new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED);
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(),
+ any(), any());
- @Test
- public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigJSON_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final EventRequestParameters eventRequestParameters = new EventRequestParameters();
+ eventRequestParameters.setEventAttributes(Collections.emptyMap());
+ eventRequestParameters.setRequestID(REQUEST_UUID);
- final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
- getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION), HttpStatus.ACCEPTED);
+ final Collection<PolicyResponse> actualPolicyResponses =
+ spyPolicyEngine.sendEvent(eventRequestParameters);
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ assertEquals(1, actualPolicyResponses.size());
- final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
+ }
- assertEquals(1, actualPolicyResponses.size());
+ @Test
+ public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigJSON_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
- assertNotNull(actualPolicyConfig.toJSON());
+ final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
+ getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION), HttpStatus.ACCEPTED);
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- @Test
- public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigOther_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final Collection<PolicyConfig> actualPolicyResponses =
+ spyPolicyEngine.getConfig(new ConfigRequestParameters());
- final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
- new ResponseEntity<>(getAPIPolicyConfigResponse(PolicyType.OTHER, COMMENTS), HttpStatus.ACCEPTED);
+ assertEquals(1, actualPolicyResponses.size());
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
+ assertNotNull(actualPolicyConfig.toJSON());
- final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
+ }
- assertEquals(1, actualPolicyResponses.size());
+ @Test
+ public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigOther_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
- assertNotNull(actualPolicyConfig.toOther());
+ final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
+ getAPIPolicyConfigResponse(PolicyType.OTHER, COMMENTS), HttpStatus.ACCEPTED);
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- @Test
- public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigXML_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final Collection<PolicyConfig> actualPolicyResponses =
+ spyPolicyEngine.getConfig(new ConfigRequestParameters());
- final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
- getAPIPolicyConfigResponse(PolicyType.XML, XML_CONFIGURATION), HttpStatus.ACCEPTED);
+ assertEquals(1, actualPolicyResponses.size());
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
+ assertNotNull(actualPolicyConfig.toOther());
- final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
+ }
- assertEquals(1, actualPolicyResponses.size());
+ @Test
+ public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigXML_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
- assertNotNull(actualPolicyConfig.toXML());
+ final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
+ getAPIPolicyConfigResponse(PolicyType.XML, XML_CONFIGURATION), HttpStatus.ACCEPTED);
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- @Test
- public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigProperties_noException()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final Collection<PolicyConfig> actualPolicyResponses =
+ spyPolicyEngine.getConfig(new ConfigRequestParameters());
- final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
- new ResponseEntity<>(getAPIPolicyConfigResponse(PolicyType.PROPERTIES, COMMENTS), HttpStatus.ACCEPTED);
+ assertEquals(1, actualPolicyResponses.size());
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
+ assertNotNull(actualPolicyConfig.toXML());
- final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
+ }
- assertEquals(1, actualPolicyResponses.size());
+ @Test
+ public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigProperties_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
- assertNotNull(actualPolicyConfig.toProperties());
+ final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
+ getAPIPolicyConfigResponse(PolicyType.PROPERTIES, COMMENTS), HttpStatus.ACCEPTED);
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- @Test(expected = PolicyConfigException.class)
- public void testStdPolicyEngineSendEvent_ConfigRequestParameters_CallPDPThrow404Exception_Exception()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(new RuntimeException(new RestClientException("Error 404"))).when(spyPolicyEngine).callNewPDP(any(),
- any(), any(), any());
+ final Collection<PolicyConfig> actualPolicyResponses =
spyPolicyEngine.getConfig(new ConfigRequestParameters());
- }
- @Test
- public void testStdPolicyEngineListConfig_ConfigRequestParametersPolicyConfigProperties_noException()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ assertEquals(1, actualPolicyResponses.size());
- final APIPolicyConfigResponse[] apiPolicyConfigResponse =
- getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION);
+ final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
+ assertNotNull(actualPolicyConfig.toProperties());
- final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
- new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
+ }
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ @Test(expected = PolicyConfigException.class)
+ public void testStdPolicyEngineSendEvent_ConfigRequestParameters_CallPDPThrow404Exception_Exception()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(new RuntimeException(new RestClientException("Error 404"))).when(spyPolicyEngine)
+ .callNewPDP(any(), any(), any(), any());
+ spyPolicyEngine.getConfig(new ConfigRequestParameters());
+ }
- final Collection<String> actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters());
- assertEquals(1, actualResponse.size());
- assertNotNull(actualResponse.iterator().next());
+ @Test
+ public void testStdPolicyEngineListConfig_ConfigRequestParametersPolicyConfigProperties_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- }
+ final APIPolicyConfigResponse[] apiPolicyConfigResponse =
+ getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION);
- @Test
- public void testStdPolicyEngineListConfig_ConfigRequestParametersMessageConfigContainsPE300_noException()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
+ new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
- final APIPolicyConfigResponse[] apiPolicyConfigResponse =
- getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION, PolicyConfigConstants.PE300);
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
- new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
+ final Collection<String> actualResponse =
+ spyPolicyEngine.listConfig(new ConfigRequestParameters());
+ assertEquals(1, actualResponse.size());
+ assertNotNull(actualResponse.iterator().next());
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ }
- final Collection<String> actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters());
+ @Test
+ public void testStdPolicyEngineListConfig_ConfigRequestParametersMessageConfigContainsPE300_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- assertEquals(1, actualResponse.size());
+ final APIPolicyConfigResponse[] apiPolicyConfigResponse = getAPIPolicyConfigResponse(
+ PolicyType.JSON, JSON_CONFIGURATION, PolicyConfigConstants.PE300);
- }
-
- @Test
- public void testStdPolicyEngineListConfig_ConfigRequestParametersWithTestProperty_noException() throws Exception {
- final Properties defaultProperties = getDefaultProperties();
- defaultProperties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "test");
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine("test" + CONFIG_PROPERTIES_FILE, defaultProperties);
+ final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
+ new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
- final Collection<String> actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters());
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- assertEquals(1, actualResponse.size());
+ final Collection<String> actualResponse =
+ spyPolicyEngine.listConfig(new ConfigRequestParameters());
- }
+ assertEquals(1, actualResponse.size());
- @Test
- public void testStdPolicyEnginGetDecision_PolicyDecision_noException() throws Exception {
+ }
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ @Test
+ public void testStdPolicyEngineListConfig_ConfigRequestParametersWithTestProperty_noException()
+ throws Exception {
+ final Properties defaultProperties = getDefaultProperties();
+ defaultProperties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "test");
+ final StdPolicyEngine spyPolicyEngine =
+ getSpyPolicyEngine("test" + CONFIG_PROPERTIES_FILE, defaultProperties);
- final ResponseEntity<StdDecisionResponse> stubbedResponse =
- new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
+ final Collection<String> actualResponse =
+ spyPolicyEngine.listConfig(new ConfigRequestParameters());
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ assertEquals(1, actualResponse.size());
- final DecisionResponse actualResponse =
- spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
+ }
- assertNotNull(actualResponse);
- }
+ @Test
+ public void testStdPolicyEnginGetDecision_PolicyDecision_noException() throws Exception {
- @Test(expected = PolicyDecisionException.class)
- public void testStdPolicyEngineGetDecision_PolicyDecision_CallPDPThrow400Exception_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(new RuntimeException(new RestClientException("Error 400"))).when(spyPolicyEngine)
- .callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
- spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
- }
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- @Test
- public void testStdPolicyEnginGetDecision_DecisionRequestParameters_noException() throws Exception {
+ final ResponseEntity<StdDecisionResponse> stubbedResponse =
+ new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- final ResponseEntity<StdDecisionResponse> stubbedResponse =
- new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
+ final DecisionResponse actualResponse =
+ spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST),
- any(), any());
+ assertNotNull(actualResponse);
+ }
- final DecisionRequestParameters requestParameters = new DecisionRequestParameters();
- requestParameters.setOnapName(ONAP_NAME_VAL);
- requestParameters.setRequestID(REQUEST_UUID);
- requestParameters.setDecisionAttributes(Collections.emptyMap());
+ @Test(expected = PolicyDecisionException.class)
+ public void testStdPolicyEngineGetDecision_PolicyDecision_CallPDPThrow400Exception_Exception()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(new RuntimeException(new RestClientException("Error 400"))).when(spyPolicyEngine)
+ .callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
+ spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
+ }
- final DecisionResponse actualResponse = spyPolicyEngine.getDecision(requestParameters);
+ @Test
+ public void testStdPolicyEnginGetDecision_DecisionRequestParameters_noException()
+ throws Exception {
- assertNotNull(actualResponse);
- }
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- @Test(expected = PolicyDecisionException.class)
- public void ttestStdPolicyEnginGetDecision_NullDecisionRequestParameters_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- spyPolicyEngine.getDecision((DecisionRequestParameters) null);
- }
+ final ResponseEntity<StdDecisionResponse> stubbedResponse =
+ new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
- @Test
- public void testStdPolicyEnginGetMetrics_MetricsRequestParameters_noException() throws Exception {
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME),
+ eq(HttpMethod.POST), any(), any());
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final DecisionRequestParameters requestParameters = new DecisionRequestParameters();
+ requestParameters.setOnapName(ONAP_NAME_VAL);
+ requestParameters.setRequestID(REQUEST_UUID);
+ requestParameters.setDecisionAttributes(Collections.emptyMap());
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Metrics", HttpStatus.ACCEPTED);
+ final DecisionResponse actualResponse = spyPolicyEngine.getDecision(requestParameters);
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET),
- any(), any());
+ assertNotNull(actualResponse);
+ }
- final MetricsResponse actualResponse = spyPolicyEngine.getMetrics(new MetricsRequestParameters());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.ACCEPTED.value(), actualResponse.getResponseCode());
+ @Test(expected = PolicyDecisionException.class)
+ public void ttestStdPolicyEnginGetDecision_NullDecisionRequestParameters_Exception()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ spyPolicyEngine.getDecision((DecisionRequestParameters) null);
+ }
- }
+ @Test
+ public void testStdPolicyEnginGetMetrics_MetricsRequestParameters_noException() throws Exception {
- @Test
- public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowHttpException_ResponseWithHttpCode()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))).when(spyPolicyEngine)
- .callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), any(), any());
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final MetricsResponse actualResponse = spyPolicyEngine.getMetrics(new MetricsRequestParameters());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Metrics", HttpStatus.ACCEPTED);
- }
-
- @Test(expected = PolicyException.class)
- public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowPolicyException_Exception()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME),
- eq(HttpMethod.GET), any(), any());
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME),
+ eq(HttpMethod.GET), any(), any());
+ final MetricsResponse actualResponse =
spyPolicyEngine.getMetrics(new MetricsRequestParameters());
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.ACCEPTED.value(), actualResponse.getResponseCode());
- }
-
- @Test
- public void testStdPolicyEnginPushPolicy_PushPolicyParameters_noException() throws Exception {
+ }
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ @Test
+ public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowHttpException_ResponseWithHttpCode()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY)))
+ .when(spyPolicyEngine)
+ .callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), any(), any());
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ final MetricsResponse actualResponse =
+ spyPolicyEngine.getMetrics(new MetricsRequestParameters());
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
- any(), any());
+ }
- final PolicyChangeResponse actualResponse = spyPolicyEngine.pushPolicy(new PushPolicyParameters());
+ @Test(expected = PolicyException.class)
+ public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowPolicyException_Exception()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME),
+ eq(HttpMethod.GET), any(), any());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
- }
+ spyPolicyEngine.getMetrics(new MetricsRequestParameters());
- @Test
- public void testStdPolicyEnginePushPolicy_PushPolicyParametersThrowsHttpClientErrorException_ResponseWithHttpCode()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))).when(spyPolicyEngine)
- .callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
+ }
- final PolicyChangeResponse actualResponse = spyPolicyEngine.pushPolicy(new PushPolicyParameters());
+ @Test
+ public void testStdPolicyEnginPushPolicy_PushPolicyParameters_noException() throws Exception {
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- }
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- @Test(expected = PolicyException.class)
- public void testStdPolicyEnginePushPolicy_PushPolicyParameters_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME),
- eq(HttpMethod.PUT), any(), any());
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.PUT), any(), any());
+ final PolicyChangeResponse actualResponse =
spyPolicyEngine.pushPolicy(new PushPolicyParameters());
- }
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
+ }
- @Test
- public void testStdPolicyEnginDeletePolicy_DeletePolicyParameters_noException() throws Exception {
+ @Test
+ public void testStdPolicyEnginePushPolicy_PushPolicyParametersThrowsHttpClientErrorException_ResponseWithHttpCode()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY)))
+ .when(spyPolicyEngine)
+ .callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final PolicyChangeResponse actualResponse =
+ spyPolicyEngine.pushPolicy(new PushPolicyParameters());
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(DELETE_POLICY_RESOURCE_NAME),
- eq(HttpMethod.DELETE), any(), any());
+ }
- final PolicyChangeResponse actualResponse = spyPolicyEngine.deletePolicy(new DeletePolicyParameters());
+ @Test(expected = PolicyException.class)
+ public void testStdPolicyEnginePushPolicy_PushPolicyParameters_Exception() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.PUT), any(), any());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
- }
+ spyPolicyEngine.pushPolicy(new PushPolicyParameters());
- @Test
- public void testStdPolicyEnginGetDictionaryItem_DictionaryParameters_noException() throws Exception {
+ }
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ @Test
+ public void testStdPolicyEnginDeletePolicy_DeletePolicyParameters_noException() throws Exception {
- final ResponseEntity<APIDictionaryResponse> stubbedResponse =
- new ResponseEntity<>(getAPIDictionaryResponse(), HttpStatus.OK);
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME),
- eq(HttpMethod.POST), any(), any());
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(DELETE_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.DELETE), any(), any());
- assertNotNull(actualResponse);
- }
+ final PolicyChangeResponse actualResponse =
+ spyPolicyEngine.deletePolicy(new DeletePolicyParameters());
- @Test
- public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp400ExceptionThrown_ResponseWithHttpCode()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Error 400")))
- .when(spyPolicyEngine)
- .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
+ }
- final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
+ @Test
+ public void testStdPolicyEnginGetDictionaryItem_DictionaryParameters_noException()
+ throws Exception {
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.BAD_REQUEST.value(), actualResponse.getResponseCode());
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- }
+ final ResponseEntity<APIDictionaryResponse> stubbedResponse =
+ new ResponseEntity<>(getAPIDictionaryResponse(), HttpStatus.OK);
- @Test
- public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp401ExceptionThrown_ResponseWithHttpCode()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.UNAUTHORIZED, "Error 401")))
- .when(spyPolicyEngine)
- .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
+ doReturn(stubbedResponse).when(spyPolicyEngine)
+ .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
- final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
+ final DictionaryResponse actualResponse =
+ spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.UNAUTHORIZED.value(), actualResponse.getResponseCode());
+ assertNotNull(actualResponse);
+ }
- }
+ @Test
+ public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp400ExceptionThrown_ResponseWithHttpCode()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Error 400")))
+ .when(spyPolicyEngine)
+ .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
- @Test
- public void testStdPolicyGetDictionaryItem_DictionaryParametersWithRunTimeExceptionThrown_ResponseWithHttpCode()
- throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error")))
- .when(spyPolicyEngine)
- .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
+ final DictionaryResponse actualResponse =
+ spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
- final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.BAD_REQUEST.value(), actualResponse.getResponseCode());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), actualResponse.getResponseCode());
+ }
- }
+ @Test
+ public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp401ExceptionThrown_ResponseWithHttpCode()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(
+ new RuntimeException(new HttpClientErrorException(HttpStatus.UNAUTHORIZED, "Error 401")))
+ .when(spyPolicyEngine)
+ .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
- @Test
- public void testStdPolicyEnginCreateDictionaryItem_DictionaryParameters_noException() throws Exception {
+ final DictionaryResponse actualResponse =
+ spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.UNAUTHORIZED.value(), actualResponse.getResponseCode());
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ }
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_DICTIONARY_ITEM_RESOURCE_NAME),
- eq(HttpMethod.PUT), any(), any());
+ @Test
+ public void testStdPolicyGetDictionaryItem_DictionaryParametersWithRunTimeExceptionThrown_ResponseWithHttpCode()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doThrow(new RuntimeException(
+ new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error")))
+ .when(spyPolicyEngine)
+ .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
- final PolicyChangeResponse actualResponse = spyPolicyEngine.createDictionaryItem(new DictionaryParameters());
+ final DictionaryResponse actualResponse =
+ spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
- }
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), actualResponse.getResponseCode());
- @Test
- public void testStdPolicyEnginUpdateDictionaryItem_DictionaryParameters_noException() throws Exception {
+ }
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ @Test
+ public void testStdPolicyEnginCreateDictionaryItem_DictionaryParameters_noException()
+ throws Exception {
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_DICTIONARY_ITEM_RESOURCE_NAME),
- eq(HttpMethod.PUT), any(), any());
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- final PolicyChangeResponse actualResponse = spyPolicyEngine.updateDictionaryItem(new DictionaryParameters());
+ doReturn(stubbedResponse).when(spyPolicyEngine)
+ .callNewPDP(eq(CREATE_DICTIONARY_ITEM_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
- }
+ final PolicyChangeResponse actualResponse =
+ spyPolicyEngine.createDictionaryItem(new DictionaryParameters());
- @Test
- public void testStdPolicyEnginPolicyEngineImport_ImportParameters_noException() throws Exception {
- final File emptyfile = temporaryFolder.newFile("emptyFile.txt");
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
+ }
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ @Test
+ public void testStdPolicyEnginUpdateDictionaryItem_DictionaryParameters_noException()
+ throws Exception {
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(POLICY_ENGINE_IMPORT_RESOURCE_NAME),
- eq(HttpMethod.POST), any(), any());
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final ImportParameters importParameters = new ImportParameters();
- importParameters.setFilePath(emptyfile.toString());
- final PolicyChangeResponse actualResponse = spyPolicyEngine.policyEngineImport(importParameters);
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine)
+ .callNewPDP(eq(UPDATE_DICTIONARY_ITEM_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
- @Test
- public void testStdPolicyEnginCreatePolicy_PolicyParameters_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final PolicyChangeResponse actualResponse =
+ spyPolicyEngine.updateDictionaryItem(new DictionaryParameters());
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
+ }
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
- any(), any());
+ @Test
+ public void testStdPolicyEnginPolicyEngineImport_ImportParameters_noException() throws Exception {
+ final File emptyfile = temporaryFolder.newFile("emptyFile.txt");
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final PolicyChangeResponse actualResponse = spyPolicyEngine.createPolicy(new PolicyParameters());
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine)
+ .callNewPDP(eq(POLICY_ENGINE_IMPORT_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
- @Test
- public void testStdPolicyEnginUpdatePolicy_PolicyParameters_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final ImportParameters importParameters = new ImportParameters();
+ importParameters.setFilePath(emptyfile.toString());
+ final PolicyChangeResponse actualResponse =
+ spyPolicyEngine.policyEngineImport(importParameters);
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
+ }
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
- any(), any());
+ @Test
+ public void testStdPolicyEnginCreatePolicy_PolicyParameters_noException() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final PolicyChangeResponse actualResponse = spyPolicyEngine.updatePolicy(new PolicyParameters());
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- assertNotNull(actualResponse);
- assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.PUT), any(), any());
- @Test(expected = PolicyException.class)
- public void testStdPolicyEnginPushPolicy_NullValues_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ final PolicyChangeResponse actualResponse =
+ spyPolicyEngine.createPolicy(new PolicyParameters());
- spyPolicyEngine.pushPolicy(null, null, null, null, null);
- }
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
+ }
- @Test(expected = PolicyException.class)
- public void testStdPolicyEnginPushPolicy_EmptyPolicyScope_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ @Test
+ public void testStdPolicyEnginUpdatePolicy_PolicyParameters_noException() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- spyPolicyEngine.pushPolicy("", null, null, null, null);
- }
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- @Test(expected = PolicyException.class)
- public void testStdPolicyEnginPushPolicy_EmptyPolicyName_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.PUT), any(), any());
- spyPolicyEngine.pushPolicy("POLICY_SCOPE", "", null, null, null);
- }
+ final PolicyChangeResponse actualResponse =
+ spyPolicyEngine.updatePolicy(new PolicyParameters());
- @Test
- public void testStdPolicyEnginPushPolicy_PolicyParameters_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ assertNotNull(actualResponse);
+ assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
+ }
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ @Test(expected = PolicyException.class)
+ public void testStdPolicyEnginPushPolicy_NullValues_Exception() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
- any(), any());
+ spyPolicyEngine.pushPolicy(null, null, null, null, null);
+ }
- final String actualResponse =
- spyPolicyEngine.pushPolicy("POLICY_SCOPE", ONAP_NAME_VAL, "POLICY_TYPE", "POLICY_GROUP", REQUEST_UUID);
+ @Test(expected = PolicyException.class)
+ public void testStdPolicyEnginPushPolicy_EmptyPolicyScope_Exception() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- assertNotNull(actualResponse);
- }
+ spyPolicyEngine.pushPolicy("", null, null, null, null);
+ }
- @Test
- public void testStdPolicyEnginCreateUpdateConfigPolicy_PolicyParameters_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
+ @Test(expected = PolicyException.class)
+ public void testStdPolicyEnginPushPolicy_EmptyPolicyName_Exception() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
+ spyPolicyEngine.pushPolicy("POLICY_SCOPE", "", null, null, null);
+ }
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
- any(), any());
+ @Test
+ public void testStdPolicyEnginPushPolicy_PolicyParameters_noException() throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- final String actualResponse = spyPolicyEngine.createUpdateConfigPolicy("POLICY_NAME", ONAP_NAME_VAL,
- ONAP_NAME_VAL, "CONFIG_NAME", Collections.emptyMap(), PolicyType.JSON.toString().toUpperCase(), "",
- "POLICY_SCOPE", REQUEST_UUID, "", "", "", new Date().toString(), true);
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- assertNotNull(actualResponse);
- }
-
- @Test(expected = PolicyException.class)
- public void testStdPolicyEnginCreateUpdateConfigPolicy_NullPolicyName_Exception() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
-
- spyPolicyEngine.createUpdateConfigPolicy(null, null, null, null, null, null, null, null, null, null, null, null,
- null, true);
- }
-
- @Test
- public void testStdPolicyEnginCreateUpdateConfigFirewallPolicy_PolicyParameters_noException() throws Exception {
- final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
-
- final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
-
- doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
- any(), any());
-
- final String actualResponse =
- spyPolicyEngine.createUpdateConfigFirewallPolicy("POLICY_NAME", getJsonObject(JSON_CONFIGURATION),
- "POLICY_SCOPE", REQUEST_UUID, "", "", "", new Date().toString(), true);
-
- assertNotNull(actualResponse);
- }
-
- private JsonObject getJsonObject(final String jsonString) {
- try (final JsonReader jsonReader = Json.createReader(new StringReader(jsonString));) {
- return jsonReader.readObject();
- }
- }
-
- private StdPolicyEngine getSpyPolicyEngine() throws IOException, PolicyEngineException {
- return getSpyPolicyEngine(CONFIG_PROPERTIES_FILE, getDefaultProperties());
- }
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.PUT), any(), any());
- private StdPolicyEngine getSpyPolicyEngine(final String filename, final Properties properties)
- throws IOException, PolicyEngineException {
- final File file = temporaryFolder.newFile(filename);
+ final String actualResponse = spyPolicyEngine.pushPolicy("POLICY_SCOPE", ONAP_NAME_VAL,
+ "POLICY_TYPE", "POLICY_GROUP", REQUEST_UUID);
- creatPropertyFile(file, properties);
+ assertNotNull(actualResponse);
+ }
- final StdPolicyEngine spyPolicyEngine = spy(new StdPolicyEngine(file.toString(), (String) null));
- spyPolicyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
- return spyPolicyEngine;
- }
+ @Test
+ public void testStdPolicyEnginCreateUpdateConfigPolicy_PolicyParameters_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- private Properties getDefaultProperties() {
- final Properties properties = new Properties();
- properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
- properties.setProperty(CLIENT_ID_PROP_NAME, "test");
- properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
- properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
- properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
- properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
- properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
- properties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "false");
- return properties;
- }
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
- private StdDecisionResponse getStdDecisionResponse() {
- final StdDecisionResponse response = new StdDecisionResponse();
- response.setDecision(PolicyDecision.PERMIT);
- response.setDetails(PolicyDecision.PERMIT.name());
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.PUT), any(), any());
- return response;
- }
+ final String actualResponse =
+ spyPolicyEngine.createUpdateConfigPolicy("POLICY_NAME", ONAP_NAME_VAL, ONAP_NAME_VAL,
+ "CONFIG_NAME", Collections.emptyMap(), PolicyType.JSON.toString().toUpperCase(), "",
+ "POLICY_SCOPE", REQUEST_UUID, "", "", "", new Date().toString(), true);
- private APIDictionaryResponse getAPIDictionaryResponse() {
- final APIDictionaryResponse response = new APIDictionaryResponse();
- response.setResponseCode(0);
- response.setResponseMessage("");
- response.setDictionaryData(Collections.<String, String>emptyMap());
- response.setDictionaryJson(Collections.<String, String>emptyMap());
- return response;
- }
+ assertNotNull(actualResponse);
+ }
- private StdPolicyResponse[] getStdPolicyResponse() {
- final StdPolicyResponse response = new StdPolicyResponse();
- response.setPolicyResponseStatus(PolicyResponseStatus.ACTION_TAKEN);
- return new StdPolicyResponse[] {response};
- }
+ @Test(expected = PolicyException.class)
+ public void testStdPolicyEnginCreateUpdateConfigPolicy_NullPolicyName_Exception()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- private void creatPropertyFile(final File file, final Properties properties) throws IOException {
- try (final BufferedWriter bufferedWriter = Files.newBufferedWriter(file.toPath());) {
- properties.store(bufferedWriter, COMMENTS);
- }
- }
+ spyPolicyEngine.createUpdateConfigPolicy(null, null, null, null, null, null, null, null, null,
+ null, null, null, null, true);
+ }
+
+ @Test
+ public void testStdPolicyEnginCreateUpdateConfigFirewallPolicy_PolicyParameters_noException()
+ throws Exception {
+ final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
- private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
- final String configuration) {
-
- return getAPIPolicyConfigResponse(policyType, configuration, null);
- }
-
- private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
- final String configuration, final String policyConfigMessage) {
- final APIPolicyConfigResponse configResponse = new APIPolicyConfigResponse();
- configResponse.setConfig(configuration);
- configResponse.setMatchingConditions(getMatchingConditions());
- configResponse.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_RETRIEVED);
- configResponse.setPolicyName(POLICY_NAME);
- configResponse.setPolicyType(PolicyConfigType.BRMS_RAW);
- configResponse.setType(policyType);
- configResponse.setPolicyVersion(POLICY_VERSION);
- configResponse.setProperty(Collections.emptyMap());
- configResponse.setPolicyConfigMessage(policyConfigMessage);
-
- return new APIPolicyConfigResponse[] {configResponse};
- }
-
- private Map<String, String> getMatchingConditions() {
- final Map<String, String> attributes = new HashMap<>();
- attributes.put(ONAP_NAME, POLICY_NAME);
- attributes.put(CONFIG_NAME, "Configuration_name");
- return attributes;
- }
+ final ResponseEntity<String> stubbedResponse =
+ new ResponseEntity<>("Successful", HttpStatus.OK);
+
+ doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME),
+ eq(HttpMethod.PUT), any(), any());
+
+ final String actualResponse = spyPolicyEngine.createUpdateConfigFirewallPolicy("POLICY_NAME",
+ getJsonObject(JSON_CONFIGURATION), "POLICY_SCOPE", REQUEST_UUID, "", "", "",
+ new Date().toString(), true);
+
+ assertNotNull(actualResponse);
+ }
+
+ private JsonObject getJsonObject(final String jsonString) {
+ try (final JsonReader jsonReader = Json.createReader(new StringReader(jsonString));) {
+ return jsonReader.readObject();
+ }
+ }
+
+ private StdPolicyEngine getSpyPolicyEngine() throws IOException, PolicyEngineException {
+ return getSpyPolicyEngine(CONFIG_PROPERTIES_FILE, getDefaultProperties());
+ }
+
+ private StdPolicyEngine getSpyPolicyEngine(final String filename, final Properties properties)
+ throws IOException, PolicyEngineException {
+ final File file = temporaryFolder.newFile(filename);
+
+ creatPropertyFile(file, properties);
+
+ final StdPolicyEngine spyPolicyEngine =
+ spy(new StdPolicyEngine(file.toString(), (String) null));
+ spyPolicyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
+ return spyPolicyEngine;
+ }
+
+ private Properties getDefaultProperties() {
+ final Properties properties = new Properties();
+ properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
+ properties.setProperty(CLIENT_ID_PROP_NAME, "test");
+ properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
+ properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
+ properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
+ properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
+ properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
+ properties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "false");
+ return properties;
+ }
+
+ private StdDecisionResponse getStdDecisionResponse() {
+ final StdDecisionResponse response = new StdDecisionResponse();
+ response.setDecision(PolicyDecision.PERMIT);
+ response.setDetails(PolicyDecision.PERMIT.name());
+
+ return response;
+ }
+
+ private APIDictionaryResponse getAPIDictionaryResponse() {
+ final APIDictionaryResponse response = new APIDictionaryResponse();
+ response.setResponseCode(0);
+ response.setResponseMessage("");
+ response.setDictionaryData(Collections.<String, String>emptyMap());
+ response.setDictionaryJson(Collections.<String, String>emptyMap());
+ return response;
+ }
+
+ private StdPolicyResponse[] getStdPolicyResponse() {
+ final StdPolicyResponse response = new StdPolicyResponse();
+ response.setPolicyResponseStatus(PolicyResponseStatus.ACTION_TAKEN);
+ return new StdPolicyResponse[] {response};
+ }
+
+ private void creatPropertyFile(final File file, final Properties properties) throws IOException {
+ try (final BufferedWriter bufferedWriter = Files.newBufferedWriter(file.toPath());) {
+ properties.store(bufferedWriter, COMMENTS);
+ }
+ }
+
+ private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
+ final String configuration) {
+
+ return getAPIPolicyConfigResponse(policyType, configuration, null);
+ }
+
+ private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
+ final String configuration, final String policyConfigMessage) {
+ final APIPolicyConfigResponse configResponse = new APIPolicyConfigResponse();
+ configResponse.setConfig(configuration);
+ configResponse.setMatchingConditions(getMatchingConditions());
+ configResponse.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_RETRIEVED);
+ configResponse.setPolicyName(POLICY_NAME);
+ configResponse.setPolicyType(PolicyConfigType.BRMS_RAW);
+ configResponse.setType(policyType);
+ configResponse.setPolicyVersion(POLICY_VERSION);
+ configResponse.setProperty(Collections.emptyMap());
+ configResponse.setPolicyConfigMessage(policyConfigMessage);
+
+ return new APIPolicyConfigResponse[] {configResponse};
+ }
+
+ private Map<String, String> getMatchingConditions() {
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put(ONAP_NAME, POLICY_NAME);
+ attributes.put(CONFIG_NAME, "Configuration_name");
+ return attributes;
+ }
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java
new file mode 100644
index 000000000..f77fe72c9
--- /dev/null
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * PolicyEngineUtils
+ * ================================================================================
+ * 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.utils.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.Date;
+import org.junit.Test;
+import org.onap.policy.jpa.BackUpMonitorEntity;
+
+public class BackUpMonitorEntityTest {
+ @Test
+ public void testEntity() {
+ String value = "testVal";
+ Date date = new Date();
+
+ BackUpMonitorEntity entity = new BackUpMonitorEntity();
+ assertNotNull(entity);
+
+ entity.setResourceName(value);
+ entity.setResourceNodeName(value);
+ entity.setFlag(value);
+ entity.setNotificationRecord(value);
+ entity.prePersist();
+ entity.preUpdate();
+ entity.setTimeStamp(date);
+
+ assertEquals(value, entity.getResourceName());
+ assertEquals(value, entity.getResourceNodeName());
+ assertEquals(value, entity.getFlag());
+ assertEquals(value, entity.getNotificationRecord());
+ assertEquals(date, entity.getTimeStamp());
+ }
+}