summaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PDP-REST')
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java18
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java24
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java82
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java4
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java4
10 files changed, 116 insertions, 36 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
index 5c9f8602f..102d43f0c 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
@@ -550,20 +550,14 @@ public class XACMLPdpLoader {
// properties
//
changed = true;
+ } catch (MalformedURLException e) {
+ papUrls.failed();
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy '" + policy
+ + "' had bad URL in new configuration, URL='" + propLocation + "'");
} catch (Exception e) {
papUrls.failed();
- if (e instanceof MalformedURLException) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy '"
- + policy
- + "' had bad URL in new configuration, URL='"
- + propLocation + "'");
-
- } else {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while retrieving policy "
- + policy
- + " from URL "
- + url + ", e=" + e);
- }
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while retrieving policy "
+ + policy + " from URL " + url + ", e=" + e);
}
papUrls.getNext();
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
index 59194841f..3c0ea3894 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
@@ -54,12 +54,16 @@ public class PAPServices {
private int responseCode = 0;
private static String environment = "DEVL";
- public static Boolean junit = false;
+ private static Boolean isJunit = false;
private static List<String> paps = null;
private static final Object papResourceLock = new Object();
private String operation = null;
private String requestMethod = null;
- private String encoding = null;
+ private String encoding = null;
+
+ public static void setJunit(boolean isJunit) {
+ PAPServices.isJunit = isJunit;
+ }
public PAPServices() {
environment = PDPApiAuth.getEnvironment();
@@ -164,7 +168,7 @@ public class PAPServices {
} else if(content != null){
// the content is an object to be encoded in JSON
ObjectMapper mapper = new ObjectMapper();
- if (!junit) {
+ if (!isJunit) {
mapper.writeValue(connection.getOutputStream(),
content);
}
@@ -174,7 +178,7 @@ public class PAPServices {
responseCode = connection.getResponseCode();
// If Connected to PAP then break from the loop and continue
// with the Request
- if (connection.getResponseCode() > 0 || junit) {
+ if (connection.getResponseCode() > 0 || isJunit) {
connected = true;
break;
} else {
@@ -183,7 +187,7 @@ public class PAPServices {
}
} catch (Exception e) {
// This means that the PAP is not working
- if (junit) {
+ if (isJunit) {
connected = true;
break;
}
@@ -212,7 +216,7 @@ public class PAPServices {
XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ "Decoding the result ", e);
}
- if (junit) {
+ if (isJunit) {
response = SUCCESS;
}
}else{
@@ -326,10 +330,10 @@ public class PAPServices {
private String checkResponse(HttpURLConnection connection, UUID requestID) throws IOException {
String response = null;
- if (responseCode == 200 || junit) {
+ if (responseCode == 200 || isJunit) {
// Check for successful creation of policy
String isSuccess = null;
- if (!junit) { // is this a junit test?
+ if (!isJunit) { // is this a junit test?
isSuccess = connection.getHeaderField("successMapKey");
operation = connection.getHeaderField("operation");
} else {
@@ -603,7 +607,7 @@ public class PAPServices {
responseCode = connection.getResponseCode();
// If Connected to PAP then break from the loop and continue
// with the Request
- if (connection.getResponseCode() > 0 || junit) {
+ if (connection.getResponseCode() > 0 || isJunit) {
connected = true;
break;
} else {
@@ -612,7 +616,7 @@ public class PAPServices {
}
} catch (Exception e) {
// This means that the PAP is not working
- if (junit) {
+ if (isJunit) {
connected = true;
break;
}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java
new file mode 100644
index 000000000..a48791cf0
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/models/PDPResponseTest.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.rest.api.models;
+
+import static org.junit.Assert.assertEquals;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.policy.api.PolicyConfigStatus;
+import org.onap.policy.api.PolicyDecision;
+import org.onap.policy.api.PolicyResponseStatus;
+import org.onap.policy.api.PolicyType;
+
+public class PDPResponseTest {
+ @Test
+ public void testSetAndGet() {
+ // Test values
+ String message = "testMessage";
+ String config = "testConfig";
+ String policyName = "testPolicyName";
+ String policyVersion = "1.0";
+ PolicyResponseStatus policyResponseStatus = PolicyResponseStatus.ACTION_ADVISED;
+ PolicyConfigStatus policyConfigStatus = PolicyConfigStatus.CONFIG_RETRIEVED;
+ PolicyType type = PolicyType.JSON;
+ Map<String, String> property = new HashMap<String, String>();
+ PolicyDecision policyDecision = PolicyDecision.PERMIT;
+
+ PDPResponse response = new PDPResponse();
+
+ response.setStatus(message, policyResponseStatus, policyConfigStatus);
+ response.setConfig(config);
+ assertEquals(config, response.getConfig());
+ response.setType(type);
+ assertEquals(type, response.getType());
+ response.setPolicyConfigStatus(policyConfigStatus);
+ assertEquals(policyConfigStatus, response.getPolicyConfigStatus());
+ response.setPolicyConfigMessage(message);
+ assertEquals(message, response.getPolicyConfigMessage());
+ response.setProperty(property);
+ assertEquals(property, response.getProperty());
+ response.setPolicyName(policyName);
+ assertEquals(policyName, response.getPolicyName());
+ response.setPolicyVersion(policyVersion);
+ assertEquals(policyVersion, response.getPolicyVersion());
+ response.setMatchingConditions(property);
+ assertEquals(property, response.getMatchingConditions());
+ response.setResponseAttributes(property);
+ assertEquals(property, response.getResponseAttributes());
+ response.setPolicyResponseStatus(policyResponseStatus);
+ assertEquals(policyResponseStatus, response.getPolicyResponseStatus());
+ response.setDecision(policyDecision);
+ assertEquals(policyDecision, response.getDecision());
+ response.setDetails(message);
+ assertEquals(message, response.getDetails());
+ response.setActionAdvised(property);
+ assertEquals(property, response.getActionAdvised());
+ response.setActionTaken(property);
+ assertEquals(property, response.getActionTaken());
+ response.setRequestAttributes(property);
+ assertEquals(property, response.getRequestAttributes());
+ response.setPolicyResponseMessage(message);
+ assertEquals(message, response.getPolicyResponseMessage());
+ }
+}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java
index 8867a7828..23e47f418 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyServiceTest.java
@@ -50,7 +50,7 @@ public class BRMSParamPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
@@ -80,7 +80,7 @@ public class BRMSParamPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java
index de884b349..c21bc9c77 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyServiceTest.java
@@ -47,7 +47,7 @@ public class ClosedLoopFaultPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
@@ -69,7 +69,7 @@ public class ClosedLoopFaultPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java
index 19bb279e6..99dc67742 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyServiceTest.java
@@ -47,7 +47,7 @@ public class ClosedLoopPMPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
@@ -69,7 +69,7 @@ public class ClosedLoopPMPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java
index 0fcb0027c..fe0668115 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyServiceTest.java
@@ -49,7 +49,7 @@ public class DecisionPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyClass(PolicyClass.Decision);
@@ -94,7 +94,7 @@ public class DecisionPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java
index 4343a5060..ccedd7553 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyServiceTest.java
@@ -46,7 +46,7 @@ public class FirewallPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); //required
@@ -67,7 +67,7 @@ public class FirewallPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java
index a9301e728..e460a853b 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyServiceTest.java
@@ -47,7 +47,7 @@ public class MicroServicesPolicyServiceTest {
String succeeded = prop.getProperty("xacml.rest.pap.url");
List<String> paps = Arrays.asList(succeeded.split(","));
PAPServices.setPaps(paps);
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
@@ -69,7 +69,7 @@ public class MicroServicesPolicyServiceTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java
index 9d1d13910..93fde841d 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java
@@ -40,7 +40,7 @@ public class PAPServicesTest {
@Before
public void setUp() throws Exception {
- PAPServices.junit = true;
+ PAPServices.setJunit(true);
Properties prop = new Properties();
prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
String succeeded = prop.getProperty("xacml.rest.pap.url");
@@ -53,7 +53,7 @@ public class PAPServicesTest {
@After
public void tearDown() throws Exception {
PAPServices.setPaps(null);
- PAPServices.junit = false;
+ PAPServices.setJunit(false);
}
@Test