summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java11
-rw-r--r--src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java103
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java82
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java46
-rw-r--r--src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java12
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java128
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatterTest.java35
-rw-r--r--src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java13
-rw-r--r--src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java16
-rw-r--r--src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java38
11 files changed, 233 insertions, 255 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
index ddadb55c..39377d4a 100644
--- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
@@ -19,7 +19,7 @@
* ============LICENSE_END============================================
* Modifications copyright (c) 2018 Nokia
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.client;
@@ -55,14 +55,11 @@ public class OperationalPolicyDelegate {
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private final PolicyClient policyClient;
private final ClampProperties refProp;
- private final OperationalPolicyAttributesConstructor attributesConstructor;
@Autowired
- public OperationalPolicyDelegate(PolicyClient policyClient, ClampProperties refProp,
- OperationalPolicyAttributesConstructor attributesConstructor) {
+ public OperationalPolicyDelegate(PolicyClient policyClient, ClampProperties refProp) {
this.policyClient = policyClient;
this.refProp = refProp;
- this.attributesConstructor = attributesConstructor;
}
/**
@@ -82,8 +79,8 @@ public class OperationalPolicyDelegate {
Policy policy = prop.getType(Policy.class);
if (policy.isFound()) {
for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
- Map<AttributeType, Map<String, String>> attributes = attributesConstructor.formatAttributes(refProp,
- prop, prop.getType(Policy.class).getId(), policyChain);
+ Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor.formatAttributes(refProp,
+ prop, prop.getType(Policy.class).getId(), policyChain);
responseMessage = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId());
}
if (responseMessage != null) {
diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
index 08cfba14..87299935 100644
--- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
@@ -18,7 +18,7 @@
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.client;
@@ -43,7 +43,7 @@ import org.springframework.stereotype.Component;
public class OperationalPolicyDeleteDelegate {
protected static final EELFLogger logger = EELFManager.getInstance()
- .getLogger(OperationalPolicyDeleteDelegate.class);
+ .getLogger(OperationalPolicyDeleteDelegate.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
@Autowired
private PolicyClient policyClient;
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java
index 09f98f19..c28f700b 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java
@@ -28,45 +28,40 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.model.properties.PolicyChain;
import org.onap.clamp.clds.model.properties.PolicyItem;
import org.onap.policy.api.AttributeType;
import org.onap.policy.controlloop.policy.builder.BuilderException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.Map;
-@Component
public class OperationalPolicyAttributesConstructor {
private static final EELFLogger logger = EELFManager.getInstance()
- .getLogger(OperationalPolicyAttributesConstructor.class);
- static final String TEMPLATE_NAME = "templateName";
- static final String CLOSED_LOOP_CONTROL_NAME = "closedLoopControlName";
- static final String NOTIFICATION_TOPIC = "notificationTopic";
- static final String OPERATION_TOPIC = "operationTopic";
- static final String CONTROL_LOOP_YAML = "controlLoopYaml";
- static final String CONTROLLER = "controller";
- static final String RECIPE = "Recipe";
- static final String MAX_RETRIES = "MaxRetries";
- static final String RETRY_TIME_LIMIT = "RetryTimeLimit";
- static final String RESOURCE_ID = "ResourceId";
- static final String RECIPE_TOPIC = "RecipeTopic";
- private OperationalPolicyYamlFormatter policyYamlFormatter;
-
- @Autowired
- protected OperationalPolicyAttributesConstructor(OperationalPolicyYamlFormatter policyYamlFormatter) {
- this.policyYamlFormatter = policyYamlFormatter;
+ .getLogger(OperationalPolicyAttributesConstructor.class);
+ public static final String TEMPLATE_NAME = "templateName";
+ public static final String CLOSED_LOOP_CONTROL_NAME = "closedLoopControlName";
+ public static final String NOTIFICATION_TOPIC = "notificationTopic";
+ public static final String OPERATION_TOPIC = "operationTopic";
+ public static final String CONTROL_LOOP_YAML = "controlLoopYaml";
+ public static final String CONTROLLER = "controller";
+ public static final String RECIPE = "Recipe";
+ public static final String MAX_RETRIES = "MaxRetries";
+ public static final String RETRY_TIME_LIMIT = "RetryTimeLimit";
+ public static final String RESOURCE_ID = "ResourceId";
+ public static final String RECIPE_TOPIC = "RecipeTopic";
+
+ private OperationalPolicyAttributesConstructor() {
}
- public Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp,
- ModelProperties modelProperties,
- String modelElementId, PolicyChain policyChain)
+ public static Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp,
+ ModelProperties modelProperties,
+ String modelElementId, PolicyChain policyChain)
throws BuilderException, UnsupportedEncodingException {
modelProperties.setCurrentModelElementId(modelElementId);
modelProperties.setPolicyUniqueId(policyChain.getPolicyId());
@@ -74,14 +69,14 @@ public class OperationalPolicyAttributesConstructor {
String globalService = modelProperties.getGlobal().getService();
Map<String, String> ruleAttributes = prepareRuleAttributes(refProp, modelProperties, modelElementId,
- policyChain, globalService);
+ policyChain, globalService);
Map<String, String> matchingAttributes = prepareMatchingAttributes(refProp, globalService);
return createAttributesMap(matchingAttributes, ruleAttributes);
}
- private Map<String, String> prepareRuleAttributes(ClampProperties clampProperties, ModelProperties modelProperties,
- String modelElementId, PolicyChain policyChain, String globalService)
+ private static Map<String, String> prepareRuleAttributes(ClampProperties clampProperties, ModelProperties modelProperties,
+ String modelElementId, PolicyChain policyChain, String globalService)
throws BuilderException, UnsupportedEncodingException {
logger.info("Preparing rule attributes...");
String templateName = clampProperties.getStringValue("op.templateName", globalService);
@@ -94,13 +89,13 @@ public class OperationalPolicyAttributesConstructor {
ruleAttributes.put(NOTIFICATION_TOPIC, notificationTopic);
ImmutableMap<String, String> attributes = createRuleAttributesFromPolicy(clampProperties, modelProperties,
- modelElementId, policyChain, globalService, operationTopic);
+ modelElementId, policyChain, globalService, operationTopic);
ruleAttributes.putAll(attributes);
logger.info("Prepared: " + ruleAttributes);
return ruleAttributes;
}
- private Map<String, String> prepareMatchingAttributes(ClampProperties refProp, String globalService) {
+ private static Map<String, String> prepareMatchingAttributes(ClampProperties refProp, String globalService) {
logger.info("Preparing matching attributes...");
String controller = refProp.getStringValue("op.controller", globalService);
Map<String, String> matchingAttributes = new HashMap<>();
@@ -109,50 +104,50 @@ public class OperationalPolicyAttributesConstructor {
return matchingAttributes;
}
- private Map<AttributeType, Map<String, String>> createAttributesMap(Map<String, String> matchingAttributes,
- Map<String, String> ruleAttributes) {
+ private static Map<AttributeType, Map<String, String>> createAttributesMap(Map<String, String> matchingAttributes,
+ Map<String, String> ruleAttributes) {
Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.RULE, ruleAttributes);
attributes.put(AttributeType.MATCHING, matchingAttributes);
return attributes;
}
- private ImmutableMap<String, String> createRuleAttributesFromPolicy(ClampProperties refProp, ModelProperties modelProperties,
- String modelElementId, PolicyChain policyChain,
- String globalService, String operationTopic)
+ private static ImmutableMap<String, String> createRuleAttributesFromPolicy(ClampProperties refProp, ModelProperties modelProperties,
+ String modelElementId, PolicyChain policyChain,
+ String globalService, String operationTopic)
throws BuilderException, UnsupportedEncodingException {
if (Strings.isNullOrEmpty(operationTopic)) {
// if no operationTopic, then don't format yaml - use first policy
String recipeTopic = refProp.getStringValue("op.recipeTopic", globalService);
return createRuleAttributesFromPolicyItem(
- policyChain.getPolicyItems().get(0), recipeTopic);
+ policyChain.getPolicyItems().get(0), recipeTopic);
} else {
return createRuleAttributesFromPolicyChain(policyChain, modelProperties,
- modelElementId, operationTopic);
+ modelElementId, operationTopic);
}
}
- private ImmutableMap<String, String> createRuleAttributesFromPolicyItem(PolicyItem policyItem, String recipeTopic) {
+ private static ImmutableMap<String, String> createRuleAttributesFromPolicyItem(PolicyItem policyItem, String recipeTopic) {
logger.info("recipeTopic=" + recipeTopic);
return ImmutableMap.<String, String>builder()
- .put(RECIPE_TOPIC, recipeTopic)
- .put(RECIPE, policyItem.getRecipe())
- .put(MAX_RETRIES, String.valueOf(policyItem.getMaxRetries()))
- .put(RETRY_TIME_LIMIT, String.valueOf(policyItem.getRetryTimeLimit()))
- .put(RESOURCE_ID, String.valueOf(policyItem.getTargetResourceId()))
- .build();
+ .put(RECIPE_TOPIC, recipeTopic)
+ .put(RECIPE, policyItem.getRecipe())
+ .put(MAX_RETRIES, String.valueOf(policyItem.getMaxRetries()))
+ .put(RETRY_TIME_LIMIT, String.valueOf(policyItem.getRetryTimeLimit()))
+ .put(RESOURCE_ID, String.valueOf(policyItem.getTargetResourceId()))
+ .build();
}
- private ImmutableMap<String, String> createRuleAttributesFromPolicyChain(PolicyChain policyChain,
- ModelProperties modelProperties,
- String modelElementId,
- String operationTopic)
+ private static ImmutableMap<String, String> createRuleAttributesFromPolicyChain(PolicyChain policyChain,
+ ModelProperties modelProperties,
+ String modelElementId,
+ String operationTopic)
throws BuilderException, UnsupportedEncodingException {
logger.info("operationTopic=" + operationTopic);
- String yaml = policyYamlFormatter.formatYaml(modelProperties, modelElementId, policyChain);
+ String yaml = OperationalPolicyYamlFormatter.formatYaml(modelProperties, modelElementId, policyChain);
return ImmutableMap.<String, String>builder()
- .put(OPERATION_TOPIC, operationTopic)
- .put(CONTROL_LOOP_YAML, yaml)
- .build();
+ .put(OPERATION_TOPIC, operationTopic)
+ .put(CONTROL_LOOP_YAML, yaml)
+ .build();
}
} \ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java
index 550c4dcc..1fc36082 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java
@@ -25,6 +25,17 @@ package org.onap.clamp.clds.client.req.policy;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.BadRequestException;
+
import org.onap.clamp.clds.model.properties.Global;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.model.properties.PolicyChain;
@@ -40,24 +51,43 @@ import org.onap.policy.controlloop.policy.builder.Results;
import org.onap.policy.sdc.Resource;
import org.onap.policy.sdc.ResourceType;
import org.onap.policy.sdc.Service;
-import org.springframework.stereotype.Component;
-import javax.ws.rs.BadRequestException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-@Component
-class OperationalPolicyYamlFormatter {
+public class OperationalPolicyYamlFormatter {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyYamlFormatter.class);
+ protected OperationalPolicyYamlFormatter() {
+ }
+ /**
+ * Format Operational OpenLoop Policy yaml.
+ *
+ * @param prop
+ * @param modelElementId
+ * @param policyChain
+ * @return
+ * @throws BuilderException
+ * @throws UnsupportedEncodingException
+ */
+ public static String formatOpenLoopYaml(ModelProperties prop, String modelElementId,
+ PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
+ // get property objects
+ Global global = prop.getGlobal();
+ prop.setCurrentModelElementId(modelElementId);
+ prop.setPolicyUniqueId(policyChain.getPolicyId());
+ // convert values to SDC objects
+ Service service = new Service(global.getService());
+ Resource[] vfResources = convertToResources(global.getResourceVf(), ResourceType.VF);
+ // create builder
+ ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(prop.getControlName(),
+ policyChain.getTimeout(), service, vfResources);
+ // builder.setTriggerPolicy(refProp.getStringValue("op.openloop.policy"));
+ // Build the specification
+ Results results = builder.buildSpecification();
+ validate(results);
+ return URLEncoder.encode(results.getSpecification(), "UTF-8");
+ }
- String formatYaml(ModelProperties prop, String modelElementId,
- PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
+ public static String formatYaml(ModelProperties prop, String modelElementId,
+ PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
// get property objects
Global global = prop.getGlobal();
prop.setCurrentModelElementId(modelElementId);
@@ -68,10 +98,10 @@ class OperationalPolicyYamlFormatter {
Resource[] vfcResources = convertToResources(global.getResourceVfc(), ResourceType.VFC);
// create builder
ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(prop.getControlName(),
- policyChain.getTimeout(), service, vfResources);
+ policyChain.getTimeout(), service, vfResources);
builder.addResource(vfcResources);
// process each policy
- Map<String, Policy> policyObjMap = new HashMap<String, Policy>();
+ Map<String, Policy> policyObjMap = new HashMap<>();
List<PolicyItem> policyItemList = orderParentFirst(policyChain.getPolicyItems());
for (PolicyItem policyItem : policyItemList) {
String policyName = policyItem.getRecipe() + " Policy";
@@ -87,16 +117,16 @@ class OperationalPolicyYamlFormatter {
Policy policyObj;
if (policyItemList.indexOf(policyItem) == 0) {
String policyDescription = policyItem.getRecipe()
- + " Policy - the trigger (no parent) policy - created by CLDS";
+ + " Policy - the trigger (no parent) policy - created by CLDS";
policyObj = builder.setTriggerPolicy(policyName, policyDescription, actor, target,
- policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit());
+ policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit());
} else {
Policy parentPolicyObj = policyObjMap.get(policyItem.getParentPolicy());
String policyDescription = policyItem.getRecipe() + " Policy - triggered conditionally by "
- + parentPolicyObj.getName() + " - created by CLDS";
+ + parentPolicyObj.getName() + " - created by CLDS";
policyObj = builder.setPolicyForPolicyResult(policyName, policyDescription, actor, target,
- policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit(),
- parentPolicyObj.getId(), convertToPolicyResults(policyItem.getParentPolicyConditions()));
+ policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit(),
+ parentPolicyObj.getId(), convertToPolicyResults(policyItem.getParentPolicyConditions()));
logger.info("policyObj.id=" + policyObj.getId() + "; parentPolicyObj.id=" + parentPolicyObj.getId());
}
policyObjMap.put(policyItem.getId(), policyObj);
@@ -107,7 +137,7 @@ class OperationalPolicyYamlFormatter {
return URLEncoder.encode(results.getSpecification(), "UTF-8");
}
- private List<PolicyItem> orderParentFirst(List<PolicyItem> inOrigList) {
+ protected static List<PolicyItem> orderParentFirst(List<PolicyItem> inOrigList) {
List<PolicyItem> inList = new ArrayList<>();
inList.addAll(inOrigList);
List<PolicyItem> outList = new ArrayList<>();
@@ -129,7 +159,7 @@ class OperationalPolicyYamlFormatter {
if (parent == null || parent.length() == 0) {
if (!outList.isEmpty()) {
throw new BadRequestException(
- "Operation Policy validation problem: more than one trigger policy");
+ "Operation Policy validation problem: more than one trigger policy");
} else {
outList.add(inItem);
inListItr.remove();
@@ -151,7 +181,7 @@ class OperationalPolicyYamlFormatter {
return outList;
}
- private void validate(Results results) {
+ protected static void validate(Results results) {
if (results.isValid()) {
logger.info("results.getSpecification()=" + results.getSpecification());
} else {
@@ -167,14 +197,14 @@ class OperationalPolicyYamlFormatter {
}
- Resource[] convertToResources(List<String> stringList, ResourceType resourceType) {
+ protected static Resource[] convertToResources(List<String> stringList, ResourceType resourceType) {
if (stringList == null || stringList.isEmpty()) {
return new Resource[0];
}
return stringList.stream().map(stringElem -> new Resource(stringElem, resourceType)).toArray(Resource[]::new);
}
- PolicyResult[] convertToPolicyResults(List<String> prList) {
+ protected static PolicyResult[] convertToPolicyResults(List<String> prList) {
if (prList == null || prList.isEmpty()) {
return new PolicyResult[0];
}
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
index cc97a7ce..cd387b3c 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
@@ -18,7 +18,7 @@
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.client.req.policy;
@@ -26,11 +26,8 @@ package org.onap.clamp.clds.client.req.policy;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -46,7 +43,6 @@ import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.DeletePolicyCondition;
import org.onap.policy.api.DeletePolicyParameters;
import org.onap.policy.api.PolicyChangeResponse;
-import org.onap.policy.api.PolicyConfig;
import org.onap.policy.api.PolicyConfigException;
import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyEngine;
@@ -95,7 +91,7 @@ public class PolicyClient {
* @return The response message of policy
*/
public String sendBrmsPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
- String policyRequestUuid) {
+ String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
// Set Policy Type(Mandatory)
policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
@@ -160,7 +156,7 @@ public class PolicyClient {
* @return The answer from policy call
*/
public String sendBasePolicyInOther(String configBody, String configPolicyName, ModelProperties prop,
- String policyRequestUuid) {
+ String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
// Set Policy Type
policyParameters.setPolicyConfigType(PolicyConfigType.Base);
@@ -181,7 +177,7 @@ public class PolicyClient {
/**
* Perform send of Microservice policy in OTHER type.
- *
+ *
* @param configBody
* The config policy string body
* @param prop
@@ -224,8 +220,7 @@ public class PolicyClient {
String responseMessage = "";
Date startTime = new Date();
try {
- List<Integer> versions = getVersions(policyNamePrefix, prop);
- if (versions.isEmpty()) {
+ if (!checkPolicyExists(policyNamePrefix, prop)) {
LoggingUtils.setTargetContext("Policy", "createPolicy");
logger.info("Attempting to create policy for action=" + prop.getActionCd());
response = getPolicyEngine().createPolicy(policyParameters);
@@ -313,8 +308,8 @@ public class PolicyClient {
}
/**
- * Use Get Config Policy API to retrieve the versions for a policy. Return
- * versions in sorted order. Return empty list if none found.
+ * Use list Policy API to retrieve the policy. Return true if policy exists
+ * otherwise return false.
*
* @param policyNamePrefix
* The Policy Name Prefix
@@ -324,8 +319,8 @@ public class PolicyClient {
* @throws PolicyConfigException
* In case of issues with policy engine
*/
- protected List<Integer> getVersions(String policyNamePrefix, ModelProperties prop) throws PolicyConfigException {
- ArrayList<Integer> versions = new ArrayList<>();
+ protected boolean checkPolicyExists(String policyNamePrefix, ModelProperties prop) throws PolicyConfigException {
+ boolean policyexists = false;
ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
String policyName = "";
if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
@@ -336,27 +331,20 @@ public class PolicyClient {
logger.info("Search in Policy Engine for policyName=" + policyName);
configRequestParameters.setPolicyName(policyName);
try {
- Collection<PolicyConfig> response = getPolicyEngine().getConfig(configRequestParameters);
- for (PolicyConfig policyConfig : response) {
- if (policyConfig.getPolicyVersion() != null) {
- Integer version = Integer.valueOf(policyConfig.getPolicyVersion());
- versions.add(version);
- } else {
- logger.warn("Policy version was null, unable to convert it to Integer");
- }
+ Collection<String> response = getPolicyEngine().listConfig(configRequestParameters);
+ if (response != null && !response.isEmpty()) {
+ policyexists = true;
}
- Collections.sort(versions);
- logger.info("Policy versions.size()=" + versions.size());
} catch (PolicyConfigException e) {
// just print warning - if no policy version found
logger.warn("policy not found...policy name - " + policyName, e);
}
- return versions;
+ return policyexists;
}
/**
* This method create a new policy engine.
- *
+ *
* @return A new policy engine
*/
private synchronized PolicyEngine getPolicyEngine() {
@@ -381,8 +369,7 @@ public class PolicyClient {
String deletePolicyResponse = "";
try {
String policyNamePrefix = refProp.getStringValue(POLICY_MS_NAME_PREFIX_PROPERTY_NAME);
- List<Integer> versions = getVersions(policyNamePrefix, prop);
- if (!versions.isEmpty()) {
+ if (checkPolicyExists(policyNamePrefix, prop)) {
String policyType = refProp.getStringValue(POLICY_MSTYPE_PROPERTY_NAME);
deletePolicyResponse = deletePolicy(prop, policyType);
}
@@ -415,8 +402,7 @@ public class PolicyClient {
String deletePolicyResponse = "";
try {
String policyNamePrefix = refProp.getStringValue(POLICY_OP_NAME_PREFIX_PROPERTY_NAME);
- List<Integer> versions = getVersions(policyNamePrefix, prop);
- if (!versions.isEmpty()) {
+ if (checkPolicyExists(policyNamePrefix, prop)) {
String policyType = refProp.getStringValue(POLICY_OP_TYPE_PROPERTY_NAME);
deletePolicyResponse = deletePolicy(prop, policyType);
}
diff --git a/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java b/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java
index 6e3e8659..7caba41f 100644
--- a/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java
+++ b/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java
@@ -66,6 +66,7 @@ public class PolicyItem implements Cloneable {
private String targetResourceId;
private String recipeInfo;
private String recipeLevel;
+ private String recipeInput;
private Map<String, String> recipePayload;
private String oapRop;
private String oapLimit;
@@ -76,7 +77,7 @@ public class PolicyItem implements Cloneable {
* @param node
* @throws IOException
*/
- public PolicyItem(JsonNode node) throws IOException {
+ public PolicyItem(JsonNode node) throws IOException {
id = AbstractModelElement.getValueByName(node, "_id");
recipe = AbstractModelElement.getValueByName(node, "recipe");
maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
@@ -89,11 +90,10 @@ public class PolicyItem implements Cloneable {
}
recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo");
recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel");
- String payload = AbstractModelElement.getValueByName(node, "recipeInput");
-
+ recipeInput = AbstractModelElement.getValueByName(node, "recipeInput");
+ String payload = AbstractModelElement.getValueByName(node, "recipePayload");
if (payload != null && !payload.isEmpty()) {
- //recipePayload = JacksonUtils.getObjectMapperInstance().convertValue(payload, Map.class);
recipePayload = JacksonUtils.getObjectMapperInstance().readValue(payload, new TypeReference<Map<String, String>>(){});
}
oapRop = AbstractModelElement.getValueByName(node, "oapRop");
@@ -215,6 +215,10 @@ public class PolicyItem implements Cloneable {
return recipeLevel;
}
+ public String getRecipeInput() {
+ return recipeInput;
+ }
+
public Map<String, String> getRecipePayload() {
return recipePayload;
}
diff --git a/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java
index c257ec3f..a6a209a1 100644
--- a/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java
+++ b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java
@@ -26,6 +26,11 @@ package org.onap.clamp.clds.client.req.policy;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
+
+import java.io.IOException;
+import java.net.URLDecoder;
+import java.util.Map;
+
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
@@ -43,121 +48,98 @@ import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.controlloop.policy.builder.BuilderException;
import org.yaml.snakeyaml.Yaml;
-import java.io.IOException;
-import java.net.URLDecoder;
-import java.util.Map;
-
public class OperationalPolicyAttributesConstructorTest {
private static final String CONTROL_NAME = "ClosedLoop-d4629aee-970f-11e8-86c9-02552dda865e";
private ModelProperties modelProperties;
private PolicyChain policyChain;
- private OperationalPolicyYamlFormatter operationalPolicyYamlFormatter = new OperationalPolicyYamlFormatter();
- private OperationalPolicyAttributesConstructor operationalPolicyAttributesConstructor =
- new OperationalPolicyAttributesConstructor(operationalPolicyYamlFormatter);
-
@Before
public void setUp() throws Exception {
String modelProp = ResourceFileUtil
- .getResourceAsString("example/model-properties/policy/modelBpmnProperties.json");
- modelProperties = new ModelProperties("CLAMPDemoVFW_v1_0_3af8daec-6f10-4027-a3540",
- CONTROL_NAME, "PUT", false, "{}", modelProp);
+ .getResourceAsString("example/model-properties/policy/modelBpmnProperties.json");
+ modelProperties = new ModelProperties("CLAMPDemoVFW_v1_0_3af8daec-6f10-4027-a3540", CONTROL_NAME, "PUT", false,
+ "{}", modelProp);
policyChain = readPolicyChainFromResources();
}
-
@Test
public void shouldFormatRequestAttributes() throws IOException, BuilderException {
// given
ClampProperties mockClampProperties = createMockClampProperties(ImmutableMap.<String, String>builder()
- .put("op.templateName", "ClosedLoopControlName")
- .put("op.notificationTopic", "POLICY-CL-MGT")
- .put("op.controller", "amsterdam")
- .put("op.recipeTopic", "APPC")
- .build());
-
- //when
- Map<AttributeType, Map<String, String>> requestAttributes
- = operationalPolicyAttributesConstructor.formatAttributes(mockClampProperties, modelProperties,
- "789875c1-e788-432f-9a76-eac8ed889734", policyChain);
- //then
+ .put("op.templateName", "ClosedLoopControlName").put("op.notificationTopic", "POLICY-CL-MGT")
+ .put("op.controller", "amsterdam").put("op.recipeTopic", "APPC").build());
+
+ // when
+ Map<AttributeType, Map<String, String>> requestAttributes = OperationalPolicyAttributesConstructor
+ .formatAttributes(mockClampProperties, modelProperties, "789875c1-e788-432f-9a76-eac8ed889734",
+ policyChain);
+ // then
Assertions.assertThat(requestAttributes).containsKeys(AttributeType.MATCHING, AttributeType.RULE);
Assertions.assertThat(requestAttributes.get(AttributeType.MATCHING))
- .contains(Assertions.entry(OperationalPolicyAttributesConstructor.CONTROLLER, "amsterdam"));
+ .contains(Assertions.entry(OperationalPolicyAttributesConstructor.CONTROLLER, "amsterdam"));
Map<String, String> ruleParameters = requestAttributes.get(AttributeType.RULE);
Assertions.assertThat(ruleParameters).containsExactly(
- Assertions.entry(OperationalPolicyAttributesConstructor.MAX_RETRIES, "3"),
- Assertions.entry(OperationalPolicyAttributesConstructor.TEMPLATE_NAME, "ClosedLoopControlName"),
- Assertions.entry(OperationalPolicyAttributesConstructor.NOTIFICATION_TOPIC, "POLICY-CL-MGT"),
- Assertions.entry(OperationalPolicyAttributesConstructor.RECIPE_TOPIC, "APPC"),
- Assertions.entry(OperationalPolicyAttributesConstructor.RECIPE, "healthCheck"),
- Assertions.entry(OperationalPolicyAttributesConstructor.RESOURCE_ID,
- "cdb69724-57d5-4a22-b96c-4c345150fd0e"),
- Assertions.entry(OperationalPolicyAttributesConstructor.RETRY_TIME_LIMIT, "180"),
- Assertions.entry(OperationalPolicyAttributesConstructor.CLOSED_LOOP_CONTROL_NAME, CONTROL_NAME + "_1")
- );
+ Assertions.entry(OperationalPolicyAttributesConstructor.MAX_RETRIES, "3"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.TEMPLATE_NAME, "ClosedLoopControlName"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.NOTIFICATION_TOPIC, "POLICY-CL-MGT"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.RECIPE_TOPIC, "APPC"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.RECIPE, "healthCheck"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.RESOURCE_ID,
+ "cdb69724-57d5-4a22-b96c-4c345150fd0e"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.RETRY_TIME_LIMIT, "180"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.CLOSED_LOOP_CONTROL_NAME, CONTROL_NAME + "_1"));
}
@Test
public void shouldFormatRequestAttributesWithProperControlLoopYaml() throws IOException, BuilderException {
- //given
- ClampProperties mockClampProperties = createMockClampProperties(ImmutableMap.<String, String>builder()
- .put("op.templateName", "ClosedLoopControlName")
- .put("op.operationTopic", "APPP-CL")
- .put("op.notificationTopic", "POLICY-CL-MGT")
- .put("op.controller", "amsterdam")
- .put("op.recipeTopic", "APPC")
- .build());
+ // given
+ ClampProperties mockClampProperties = createMockClampProperties(
+ ImmutableMap.<String, String>builder().put("op.templateName", "ClosedLoopControlName")
+ .put("op.operationTopic", "APPP-CL").put("op.notificationTopic", "POLICY-CL-MGT")
+ .put("op.controller", "amsterdam").put("op.recipeTopic", "APPC").build());
Policy expectedPolicy = new Policy("6f76ad0b-ea9d-4a92-8d7d-6a6367ce2c77", "healthCheck Policy",
- "healthCheck Policy - the trigger (no parent) policy - created by CLDS", "APPC",
- null, new Target(TargetType.VM, "cdb69724-57d5-4a22-b96c-4c345150fd0e"),
- "healthCheck", 3, 180);
-
- //when
- Map<AttributeType, Map<String, String>> requestAttributes = operationalPolicyAttributesConstructor
- .formatAttributes(mockClampProperties, modelProperties,
- "789875c1-e788-432f-9a76-eac8ed889734", policyChain);
-
- //then
- Assertions.assertThat(requestAttributes)
- .containsKeys(AttributeType.MATCHING, AttributeType.RULE);
- Assertions.assertThat(requestAttributes
- .get(AttributeType.MATCHING))
- .contains(Assertions.entry("controller", "amsterdam"));
+ "healthCheck Policy - the trigger (no parent) policy - created by CLDS", "APPC", null,
+ new Target(TargetType.VM, "cdb69724-57d5-4a22-b96c-4c345150fd0e"), "healthCheck", 3, 180);
+
+ // when
+ Map<AttributeType, Map<String, String>> requestAttributes = OperationalPolicyAttributesConstructor
+ .formatAttributes(mockClampProperties, modelProperties, "789875c1-e788-432f-9a76-eac8ed889734",
+ policyChain);
+
+ // then
+ Assertions.assertThat(requestAttributes).containsKeys(AttributeType.MATCHING, AttributeType.RULE);
+ Assertions.assertThat(requestAttributes.get(AttributeType.MATCHING))
+ .contains(Assertions.entry("controller", "amsterdam"));
Map<String, String> ruleParameters = requestAttributes.get(AttributeType.RULE);
Assertions.assertThat(ruleParameters).contains(
- Assertions.entry(OperationalPolicyAttributesConstructor.OPERATION_TOPIC, "APPP-CL"),
- Assertions.entry(OperationalPolicyAttributesConstructor.TEMPLATE_NAME, "ClosedLoopControlName"),
- Assertions.entry(OperationalPolicyAttributesConstructor.NOTIFICATION_TOPIC, "POLICY-CL-MGT"),
- Assertions.entry(OperationalPolicyAttributesConstructor.CLOSED_LOOP_CONTROL_NAME, CONTROL_NAME + "_1")
- );
-
- String controlLoopYaml = URLDecoder.decode(
- ruleParameters.get(OperationalPolicyAttributesConstructor.CONTROL_LOOP_YAML), "UTF-8");
+ Assertions.entry(OperationalPolicyAttributesConstructor.OPERATION_TOPIC, "APPP-CL"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.TEMPLATE_NAME, "ClosedLoopControlName"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.NOTIFICATION_TOPIC, "POLICY-CL-MGT"),
+ Assertions.entry(OperationalPolicyAttributesConstructor.CLOSED_LOOP_CONTROL_NAME, CONTROL_NAME + "_1"));
+
+ String controlLoopYaml = URLDecoder
+ .decode(ruleParameters.get(OperationalPolicyAttributesConstructor.CONTROL_LOOP_YAML), "UTF-8");
ControlLoopPolicy controlLoopPolicy = new Yaml().load(controlLoopYaml);
Assertions.assertThat(controlLoopPolicy.getControlLoop().getControlLoopName()).isEqualTo(CONTROL_NAME);
- Assertions.assertThat(controlLoopPolicy.getPolicies())
- .usingElementComparatorIgnoringFields("id")
- .containsExactly(expectedPolicy);
+ Assertions.assertThat(controlLoopPolicy.getPolicies()).usingElementComparatorIgnoringFields("id")
+ .containsExactly(expectedPolicy);
}
-
private ClampProperties createMockClampProperties(ImmutableMap<String, String> propertiesMap) {
ClampProperties props = Mockito.mock(ClampProperties.class);
- propertiesMap.forEach((property, value) ->
- Mockito.when(props.getStringValue(Matchers.matches(property), Matchers.any())).thenReturn(value)
- );
+ propertiesMap.forEach((property, value) -> Mockito
+ .when(props.getStringValue(Matchers.matches(property), Matchers.any())).thenReturn(value));
return props;
}
private PolicyChain readPolicyChainFromResources() throws IOException {
String policyChainText = ResourceFileUtil
- .getResourceAsString("example/operational-policy/json-policy-chain.json");
+ .getResourceAsString("example/operational-policy/json-policy-chain.json");
JsonNode policyChainNode = new ObjectMapper().readTree(policyChainText);
return new PolicyChain(policyChainNode);
}
diff --git a/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatterTest.java b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatterTest.java
index 046d7394..662beb2b 100644
--- a/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatterTest.java
+++ b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatterTest.java
@@ -35,37 +35,30 @@ import org.onap.policy.sdc.ResourceType;
public class OperationalPolicyYamlFormatterTest {
- private OperationalPolicyYamlFormatter policyYamlFormatter = new OperationalPolicyYamlFormatter();
-
@Test
- public void shouldConvertGivenStringsToResourceObjects()
- throws SecurityException,
- IllegalArgumentException {
+ public void shouldConvertGivenStringsToResourceObjects() throws SecurityException, IllegalArgumentException {
- //given
+ // given
List<String> stringList = Arrays.asList("test1", "test2", "test3", "test4");
- //when
- Resource[] resources = policyYamlFormatter.convertToResources(stringList, ResourceType.VF);
+ // when
+ Resource[] resources = OperationalPolicyYamlFormatter.convertToResources(stringList, ResourceType.VF);
- //then
- Assertions.assertThat(resources).extracting(Resource::getResourceName)
- .containsExactly("test1", "test2", "test3", "test4");
+ // then
+ Assertions.assertThat(resources).extracting(Resource::getResourceName).containsExactly("test1", "test2",
+ "test3", "test4");
}
@Test
- public void shouldConvertGivenStringsToPolicyResults()
- throws SecurityException,
- IllegalArgumentException {
- //given
+ public void shouldConvertGivenStringsToPolicyResults() throws SecurityException, IllegalArgumentException {
+ // given
List<String> stringList = Arrays.asList("FAILURE", "SUCCESS", "FAILURE_GUARD", "FAILURE_TIMEOUT");
- //when
- PolicyResult[] policyResults = policyYamlFormatter.convertToPolicyResults(stringList);
+ // when
+ PolicyResult[] policyResults = OperationalPolicyYamlFormatter.convertToPolicyResults(stringList);
- //then
- Assertions.assertThat(policyResults)
- .containsExactly(PolicyResult.FAILURE, PolicyResult.SUCCESS,
- PolicyResult.FAILURE_GUARD, PolicyResult.FAILURE_TIMEOUT);
+ // then
+ Assertions.assertThat(policyResults).containsExactly(PolicyResult.FAILURE, PolicyResult.SUCCESS,
+ PolicyResult.FAILURE_GUARD, PolicyResult.FAILURE_TIMEOUT);
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java
index ad58ea1e..344641a7 100644
--- a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java
@@ -19,7 +19,7 @@
* ============LICENSE_END============================================
* Modifications copyright (c) 2018 Nokia
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.it;
@@ -56,21 +56,18 @@ public class OperationPolicyReqItCase {
@Autowired
private ClampProperties refProp;
- @Autowired
- private OperationalPolicyAttributesConstructor operationalPolicyAttributesConstructor;
-
@Test
public void formatAttributesTest() throws IOException, BuilderException {
String modelBpmnProp = ResourceFileUtil
- .getResourceAsString("example/model-properties/policy/modelBpmnProperties.json");
+ .getResourceAsString("example/model-properties/policy/modelBpmnProperties.json");
String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/policy/modelBpmn.json");
ModelProperties modelProperties = new ModelProperties("testModel", "controlNameTest", CldsEvent.ACTION_SUBMIT,
- true, modelBpmn, modelBpmnProp);
+ true, modelBpmn, modelBpmnProp);
List<Map<AttributeType, Map<String, String>>> attributes = new ArrayList<>();
if (modelProperties.getType(Policy.class).isFound()) {
for (PolicyChain policyChain : modelProperties.getType(Policy.class).getPolicyChains()) {
- attributes.add(operationalPolicyAttributesConstructor.formatAttributes(refProp, modelProperties,
- modelProperties.getType(Policy.class).getId(), policyChain));
+ attributes.add(OperationalPolicyAttributesConstructor.formatAttributes(refProp, modelProperties,
+ modelProperties.getType(Policy.class).getId(), policyChain));
}
}
assertFalse(attributes.isEmpty());
diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
index 2400d4ab..59fad9a6 100644
--- a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
@@ -19,7 +19,7 @@
* ============LICENSE_END============================================
* Modifications copyright (c) 2018 Nokia
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.it;
@@ -66,8 +66,6 @@ public class PolicyClientItCase {
private ClampProperties refProp;
@Autowired
private PolicyClient policyClient;
- @Autowired
- private OperationalPolicyAttributesConstructor operationalPolicyAttributesConstructor;
String modelProp;
String modelBpmnProp;
@@ -91,8 +89,8 @@ public class PolicyClientItCase {
if (policy.isFound()) {
for (PolicyChain policyChain : policy.getPolicyChains()) {
String operationalPolicyRequestUuid = UUID.randomUUID().toString();
- Map<AttributeType, Map<String, String>> attributes = operationalPolicyAttributesConstructor
- .formatAttributes(refProp, prop, policy.getId(), policyChain);
+ Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor
+ .formatAttributes(refProp, prop, policy.getId(), policyChain);
policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid);
}
}
@@ -166,14 +164,14 @@ public class PolicyClientItCase {
assertNotNull(policyConfiguration.getNotificationUebServers());
assertEquals(8, policyConfiguration.getProperties().size());
assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PDP_URL1))
- .contains("/pdp/ , testpdp, alpha123"));
+ .contains("/pdp/ , testpdp, alpha123"));
assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PDP_URL2))
- .contains("/pdp/ , testpdp, alpha123"));
+ .contains("/pdp/ , testpdp, alpha123"));
assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PAP_URL))
- .contains("/pap/ , testpap, alpha123"));
+ .contains("/pap/ , testpap, alpha123"));
assertEquals("websocket", policyConfiguration.getProperties().get(PolicyConfiguration.NOTIFICATION_TYPE));
assertEquals("localhost",
- policyConfiguration.getProperties().get(PolicyConfiguration.NOTIFICATION_UEB_SERVERS));
+ policyConfiguration.getProperties().get(PolicyConfiguration.NOTIFICATION_UEB_SERVERS));
assertEquals("python", policyConfiguration.getProperties().get(PolicyConfiguration.CLIENT_ID));
assertEquals("dGVzdA==", policyConfiguration.getProperties().get(PolicyConfiguration.CLIENT_KEY));
assertEquals("DEVL", policyConfiguration.getProperties().get(PolicyConfiguration.ENVIRONMENT));
diff --git a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
index 751d7040..295ccc59 100644
--- a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
+++ b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
@@ -18,7 +18,7 @@
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.model.prop;
@@ -52,10 +52,10 @@ public class ModelPropertiesTest {
@Test
public void testTcaModelDecoding() throws IOException {
String modelBpmnProp = ResourceFileUtil
- .getResourceAsString("example/model-properties/tca/modelBpmnProperties.json");
+ .getResourceAsString("example/model-properties/tca/modelBpmnProperties.json");
String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json");
ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
- modelBpmnProp);
+ modelBpmnProp);
Policy policy = prop.getType(Policy.class);
assertTrue(policy.isFound());
assertEquals(1, policy.getPolicyChains().size());
@@ -76,23 +76,21 @@ public class ModelPropertiesTest {
assertEquals(2, tca.getTcaItem().getTcaThresholds().size());
assertEquals("ABATED", tca.getTcaItem().getTcaThresholds().get(0).getClosedLoopEventStatus());
assertEquals("$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
- tca.getTcaItem().getTcaThresholds().get(0).getFieldPath());
+ tca.getTcaItem().getTcaThresholds().get(0).getFieldPath());
assertEquals("LESS_OR_EQUAL", tca.getTcaItem().getTcaThresholds().get(0).getOperator());
assertEquals(Integer.valueOf(123), tca.getTcaItem().getTcaThresholds().get(0).getThreshold());
assertEquals("ONSET", tca.getTcaItem().getTcaThresholds().get(1).getClosedLoopEventStatus());
assertEquals("$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
- tca.getTcaItem().getTcaThresholds().get(1).getFieldPath());
+ tca.getTcaItem().getTcaThresholds().get(1).getFieldPath());
assertEquals("GREATER_OR_EQUAL", tca.getTcaItem().getTcaThresholds().get(1).getOperator());
assertEquals(Integer.valueOf(123), tca.getTcaItem().getTcaThresholds().get(1).getThreshold());
// Test global prop
assertEquals("vnfRecipe", prop.getGlobal().getActionSet());
assertEquals("4cc5b45a-1f63-4194-8100-cd8e14248c92", prop.getGlobal().getService());
- assertTrue(Arrays.equals(new String[] {
- "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad"
- }, prop.getGlobal().getResourceVf().toArray()));
- assertTrue(Arrays.equals(new String[] {
- "SNDGCA64", "ALPRGAED", "LSLEILAA", "MDTWNJC1"
- }, prop.getGlobal().getLocation().toArray()));
+ assertTrue(Arrays.equals(new String[] { "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad" },
+ prop.getGlobal().getResourceVf().toArray()));
+ assertTrue(Arrays.equals(new String[] { "SNDGCA64", "ALPRGAED", "LSLEILAA", "MDTWNJC1" },
+ prop.getGlobal().getLocation().toArray()));
assertEquals("value1", prop.getGlobal().getDeployParameters().get("input1").asText());
assertEquals("value2", prop.getGlobal().getDeployParameters().get("input2").asText());
}
@@ -100,10 +98,10 @@ public class ModelPropertiesTest {
@Test
public void testHolmesModelDecoding() throws IOException {
String modelBpmnProp = ResourceFileUtil
- .getResourceAsString("example/model-properties/holmes/modelBpmnProperties.json");
+ .getResourceAsString("example/model-properties/holmes/modelBpmnProperties.json");
String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/holmes/modelBpmn.json");
ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
- modelBpmnProp);
+ modelBpmnProp);
Policy policy = prop.getType(Policy.class);
assertTrue(policy.isFound());
assertEquals(1, policy.getPolicyChains().size());
@@ -122,12 +120,10 @@ public class ModelPropertiesTest {
// Test global prop
assertEquals("vnfRecipe", prop.getGlobal().getActionSet());
assertEquals("4cc5b45a-1f63-4194-8100-cd8e14248c92", prop.getGlobal().getService());
- assertTrue(Arrays.equals(new String[] {
- "f5213e3a-9191-4362-93b5-b67f8d770e44"
- }, prop.getGlobal().getResourceVf().toArray()));
- assertTrue(Arrays.equals(new String[] {
- "SNDGCA64", "ALPRGAED", "LSLEILAA", "MDTWNJC1"
- }, prop.getGlobal().getLocation().toArray()));
+ assertTrue(Arrays.equals(new String[] { "f5213e3a-9191-4362-93b5-b67f8d770e44" },
+ prop.getGlobal().getResourceVf().toArray()));
+ assertTrue(Arrays.equals(new String[] { "SNDGCA64", "ALPRGAED", "LSLEILAA", "MDTWNJC1" },
+ prop.getGlobal().getLocation().toArray()));
assertEquals("value1", prop.getGlobal().getDeployParameters().get("input1").asText());
assertEquals("value2", prop.getGlobal().getDeployParameters().get("input2").asText());
}
@@ -135,8 +131,8 @@ public class ModelPropertiesTest {
@Test
public void testGetVf() throws IOException {
CldsModel cldsModel = new CldsModel();
- cldsModel.setPropText(
- ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json"));
+ cldsModel
+ .setPropText(ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json"));
assertEquals("023a3f0d-1161-45ff-b4cf-8918a8ccf3ad", ModelProperties.getVf(cldsModel));
}
} \ No newline at end of file