summaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-03-26 21:39:45 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-26 21:39:45 +0000
commita65d684a684105c39a64181bbd44f1debb80fb06 (patch)
tree57311bb28988a777b990fc2776bfc5dc53a0fc35 /ONAP-PDP-REST
parentcc7dca9a21765dca0ba336f27659a3852f6a15d9 (diff)
parentb6d9063e06ab8cdf2d97fc75810792659344e4a8 (diff)
Merge "New Optimization Policy"
Diffstat (limited to 'ONAP-PDP-REST')
-rw-r--r--ONAP-PDP-REST/config/policyLogger.properties44
-rw-r--r--ONAP-PDP-REST/config/xacml.pip.properties10
-rw-r--r--ONAP-PDP-REST/config/xacml.policy.properties7
-rw-r--r--ONAP-PDP-REST/config_testing/xacml.policy.properties0
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java6
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java3
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java2
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java3
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java110
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java6
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java3
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java25
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java18
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java91
14 files changed, 271 insertions, 57 deletions
diff --git a/ONAP-PDP-REST/config/policyLogger.properties b/ONAP-PDP-REST/config/policyLogger.properties
deleted file mode 100644
index a04f4eef8..000000000
--- a/ONAP-PDP-REST/config/policyLogger.properties
+++ /dev/null
@@ -1,44 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# ONAP-PDP-REST
-# ================================================================================
-# Copyright (C) 2017 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=========================================================
-###
-
-################################### Set concurrentHashMap and timer info #######################
-#Timer initial delay and the delay between in milliseconds before task is to be execute.
-timer.delay.time=1000
-#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions.
-check.interval= 30000
-#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds.
-event.expired.time=86400
-#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed
-#to remove all expired records from this concurrentHashMap.
-concurrentHashMap.limit=5000
-#Size of the concurrentHashMap - when its size drops to this point, stop the Timer
-stop.check.point=2500
-################################### Set logging format #############################################
-# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println
-logger.type=EELF
-#################################### Set level for EELF or SYSTEMOUT logging ##################################
-# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all
-debugLogger.level=INFO
-# Set level for metrics file. Set OFF to disable; set ON to enable
-metricsLogger.level=ON
-# Set level for error file. Set OFF to disable; set ON to enable
-error.level=ON
-# Set level for audit file. Set OFF to disable; set ON to enable
-audit.level=ON
diff --git a/ONAP-PDP-REST/config/xacml.pip.properties b/ONAP-PDP-REST/config/xacml.pip.properties
index 2286b5dc1..0ded40999 100644
--- a/ONAP-PDP-REST/config/xacml.pip.properties
+++ b/ONAP-PDP-REST/config/xacml.pip.properties
@@ -1,3 +1,9 @@
#
-#Wed May 31 15:42:12 EDT 2017
-
+#Mon Mar 19 19:20:17 UTC 2018
+historydb.name=operationHistoryDB
+AAF.description=AAFEngine to communicate with AAF to take decisions
+historydb.issuer=org\:onap\:xacml\:guard\:historydb
+AAF.classname=org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine
+AAF.name=AAFEngine
+historydb.classname=org.onap.policy.xacml.std.pip.engines.OperationHistoryEngine
+xacml.pip.engines=historydb,AAF
diff --git a/ONAP-PDP-REST/config/xacml.policy.properties b/ONAP-PDP-REST/config/xacml.policy.properties
index 5c884ed8b..1090a5e5c 100644
--- a/ONAP-PDP-REST/config/xacml.policy.properties
+++ b/ONAP-PDP-REST/config/xacml.policy.properties
@@ -1,4 +1,7 @@
#
-#Wed May 31 15:42:12 EDT 2017
+#Mon Mar 19 19:20:17 UTC 2018
xacml.referencedPolicies=
-xacml.rootPolicies=
+Mike.Config_OOF_testMatchingConfigs.1.xml.url=http\://localhost\:8070/pap/?id\=Mike.Config_OOF_testMatchingConfigs.1.xml
+xacml.rootPolicies=Mike.Config_OOF_testMatchingConfigs.1.xml
+Mike.Config_OOF_testMatchingConfigs.1.xml.name=Mike.Config_OOF_testMatchingConfigs
+Mike.Config_OOF_testMatchingConfigs.1.xml.file=/media/sf_SourceTree/gerrit-pe/engine/ONAP-PDP-REST/config/Mike.Config_OOF_testMatchingConfigs.1.xml
diff --git a/ONAP-PDP-REST/config_testing/xacml.policy.properties b/ONAP-PDP-REST/config_testing/xacml.policy.properties
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/ONAP-PDP-REST/config_testing/xacml.policy.properties
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
index 62b850370..f2cc16b1f 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
@@ -176,6 +176,12 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService
// Get Result.
response = microServicesPolicyService.getResult(updateFlag);
break;
+ case Optimization:
+ OptimizationPolicyService optimizationPolicyService = new OptimizationPolicyService(policyName, policyScope, policyParameters, date);
+
+ // Get Result
+ response = optimizationPolicyService.getResult(updateFlag);
+ break;
default:
message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " Invalid Config Type Present";
LOGGER.error(message);
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
index 144d3a48d..c9ecee86b 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
@@ -236,6 +236,9 @@ public class DeletePolicyService {
} else if ("MicroService".equalsIgnoreCase(policyType)) {
clientScope = "ConfigMS";
filePrefix = "Config_MS_";
+ } else if ("Optimization".equalsIgnoreCase(policyType)) {
+ clientScope = "ConfigOptimization";
+ filePrefix = "Config_OOF_";
}else if ("BRMS_RAW".equalsIgnoreCase(policyType)) {
clientScope = "ConfigBrmsRaw";
filePrefix = "Config_BRMS_Raw_";
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
index 6e6badf6a..1744aa8ae 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
@@ -173,6 +173,8 @@ public class GetConfigService {
return PolicyConfigType.ClosedLoop_PM;
} else if(name.startsWith("Config_MS_")) {
return PolicyConfigType.MicroService;
+ } else if(name.startsWith("Config_OOF_")) {
+ return PolicyConfigType.Optimization;
} else if(name.startsWith("Config_")) {
return PolicyConfigType.Base;
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
index 9b86204e0..152e84ccf 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
@@ -222,6 +222,9 @@ public class GetDictionaryService {
case "MicroServiceModels":
jsonString = jsonString.replace("microServiceModelsDictionaryDatas", "DictionaryDatas");
break;
+ case "OptimizationModels":
+ jsonString = jsonString.replace("optmizationModelsDictionaryDatas", "DictionaryDatas");
+ break;
case "PolicyScopeService":
jsonString = jsonString.replace("psServiceDictionaryDatas", "DictionaryDatas");
break;
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java
new file mode 100644
index 000000000..61038d955
--- /dev/null
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PDP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pdp.rest.api.services;
+
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import org.onap.policy.api.PolicyException;
+import org.onap.policy.api.PolicyParameters;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.pdp.rest.api.utils.PolicyApiUtils;
+import org.onap.policy.xacml.api.XACMLErrorConstants;
+import org.onap.policy.xacml.std.pap.StdPAPPolicy;
+
+/**
+ * Optimization Policy implementation.
+ *
+ * @version 0.1
+ */
+public class OptimizationPolicyService{
+ private static final Logger LOGGER = FlexLogger.getLogger(OptimizationPolicyService.class.getName());
+
+ private PAPServices papServices = null;
+ private PolicyParameters policyParameters = null;
+ private String message = null;
+ private String policyName = null;
+ private String policyScope = null;
+ private String date = null;
+
+ public OptimizationPolicyService(String policyName, String policyScope, PolicyParameters policyParameters, String date) {
+ this.policyParameters = policyParameters;
+ this.policyName = policyName;
+ this.policyScope = policyScope;
+ this.date = date;
+ papServices = new PAPServices();
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getResult(boolean updateFlag) throws PolicyException{
+ String response = null;
+ String operation = null;
+
+ if (updateFlag){
+ operation = "update";
+ } else {
+ operation = "create";
+ }
+
+ // get values and attributes from the JsonObject
+ String servicModel = null;
+ String policyDescription=null;
+ String priority=null;
+ String version=null;
+
+ String onapName = policyParameters.getOnapName();
+ JsonObject optimizationAttributes = null;
+ try{
+ optimizationAttributes = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody());
+ } catch(JsonException| IllegalStateException e){
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody();
+ LOGGER.error("Error while parsing JSON body for MicroService Policy creation. ", e);
+ return null;
+ }
+
+ if (optimizationAttributes.get("service")!=null){
+ servicModel = optimizationAttributes.get("service").toString().replace("\"", "");
+ }
+ if(optimizationAttributes.containsKey("description")){
+ policyDescription = optimizationAttributes.get("description").toString().replace("\"", "");
+ }
+ if(optimizationAttributes.containsKey("priority")){
+ priority = optimizationAttributes.get("priority").toString().replace("\"", "");
+ }
+ if(optimizationAttributes.containsKey("version")){
+ version = optimizationAttributes.get("version").toString().replace("\"", "");
+ }
+
+ // Create Policy Object
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Optimization", policyName, policyDescription, onapName,
+ null, servicModel, null, null, optimizationAttributes.toString(), priority,
+ version, updateFlag, policyScope, 0, policyParameters.getRiskLevel(),
+ policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date);
+
+ // Send JSON Object to PAP
+ response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"},
+ policyParameters.getRequestID(), "ConfigOptimization");
+ LOGGER.info("Response: " + response);
+ return response;
+ }
+}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java
index d0649d78a..f7c1cc578 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java
@@ -110,7 +110,8 @@ public class PolicyEngineImportService {
String fileName = file.getOriginalFilename();
switch (importParameters.getServiceType()){
case MICROSERVICE:
- if (fileName.endsWith(".xmi") || fileName.endsWith(".zip")){
+ case OPTIMIZATION:
+ if (fileName.endsWith(".yml") || fileName.endsWith(".xmi") || fileName.endsWith(".zip")){
try {
targetStream = new BufferedInputStream(file.getInputStream());
} catch (IOException e) {
@@ -164,7 +165,8 @@ public class PolicyEngineImportService {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing service Type value.";
return false;
}
- if(importParameters.getServiceType().equals(IMPORT_TYPE.MICROSERVICE) && (importParameters.getVersion()==null || importParameters.getVersion().trim().isEmpty())){
+ if((IMPORT_TYPE.MICROSERVICE.equals(importParameters.getServiceType()) || IMPORT_TYPE.OPTIMIZATION.equals(importParameters.getServiceType()))
+ && (importParameters.getVersion()==null || importParameters.getVersion().trim().isEmpty())){
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing version value.";
return false;
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
index a3d18b3e6..7ab17e0d0 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
@@ -176,6 +176,9 @@ public class PushPolicyService {
} else if ("MicroService".equalsIgnoreCase(policyType)) {
clientScope = "ConfigMS";
filePrefix = "Config_MS_";
+ } else if ("Optimization".equalsIgnoreCase(policyType)) {
+ clientScope = "ConfigOptimization";
+ filePrefix = "Config_OOF_";
} else if ("BRMS_RAW".equalsIgnoreCase(policyType)) {
clientScope = "ConfigBrmsRaw";
filePrefix = "Config_BRMS_Raw_";
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java
index 8d5312705..5f20dfb85 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,24 +20,39 @@
package org.onap.policy.pdp.rest.api.services;
import static org.junit.Assert.assertEquals;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
import org.junit.Test;
-import org.onap.policy.api.PolicyException;
import org.onap.policy.api.PolicyParameters;
public class BRMSRawPolicyServiceTest {
@Test
- public void testRaw() throws PolicyException {
+ 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(service.getValidation(), false);
- assertEquals(service.getMessage(), "PE300 - Data Issue: No Rule Body given");
+ assertEquals(false, service.getValidation());
+ assertEquals("PE300 - Data Issue: No Rule Body given", service.getMessage());
// Restore the original system property
if (oldProperty != null) {
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java
index 389d9bfc1..16f5a4732 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyServiceTest.java
@@ -20,13 +20,27 @@
package org.onap.policy.pdp.rest.api.services;
import static org.junit.Assert.assertEquals;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
import org.junit.Test;
-import org.onap.policy.api.PolicyException;
import org.onap.policy.api.PolicyParameters;
public class ConfigPolicyServiceTest {
@Test
- public void testRaw() throws PolicyException {
+ public void testRaw() throws FileNotFoundException, IOException {
+ Properties prop = new Properties();
+ prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
+ String succeeded = prop.getProperty("xacml.rest.pap.url");
+ List<String> paps = Arrays.asList(succeeded.split(","));
+ PAPServices.setPaps(paps);
+ PAPServices.setJunit(true);
+
String systemKey = "xacml.properties";
String testVal = "testVal";
PolicyParameters testParams = new PolicyParameters();
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java
new file mode 100644
index 000000000..79ca2e646
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyServiceTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pdp.rest.api.services;
+
+import static org.junit.Assert.*;
+
+import java.io.FileInputStream;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.api.PolicyConfigType;
+import org.onap.policy.api.PolicyException;
+import org.onap.policy.api.PolicyParameters;
+
+public class OptimizationPolicyServiceTest {
+
+ OptimizationPolicyService service = null;
+
+ @Before
+ public void setUp() throws Exception {
+ Properties prop = new Properties();
+ prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
+ String succeeded = prop.getProperty("xacml.rest.pap.url");
+ List<String> paps = Arrays.asList(succeeded.split(","));
+ PAPServices.setPaps(paps);
+ PAPServices.setJunit(true);
+ prop.clear();
+
+ PolicyParameters policyParameters = new PolicyParameters();
+ policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
+ policyParameters.setPolicyName("Test.testOOFPolicy");
+ policyParameters.setOnapName("OOF");
+ policyParameters.setRequestID(UUID.randomUUID());
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ policyParameters.setGuard(true);
+ policyParameters.setRiskLevel("5");
+ policyParameters.setRiskType("TEST");
+ policyParameters.setConfigBody("{\"optimization\":\"test\"}");
+ String policyName = "testOOFPolicy";
+ String policyScope = "Test";
+ service = new OptimizationPolicyService(policyName, policyScope, policyParameters, date.toString());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testOptimizationPolicyService() {
+ assertNotNull(service);
+ }
+
+ @Test
+ public final void testGetMessage() {
+ String message = service.getMessage();
+ assertNull(message);
+ }
+
+ @Test
+ public final void testGetResult() throws PolicyException {
+ String result = service.getResult(false);
+ assertEquals("success",result);
+ }
+
+}