aboutsummaryrefslogtreecommitdiffstats
path: root/policy-utils/src/main/java/org
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-09-17 14:19:51 +0100
committerAdheli Tavares <adheli.tavares@est.tech>2024-09-20 09:06:21 +0000
commitc274fd4a91bdbd86d8fc719f12834133adc6584d (patch)
tree29a4ab0b7304666c7b36f1371c28e9c6807120db /policy-utils/src/main/java/org
parentc13387e348160c181584141f6a5861c9d7b7ddb3 (diff)
Increase code coverage in policy-core and policy-utils
Issue-ID: POLICY-5068 Change-Id: I598b674fd623ff56c2e7b0316c114e7c270c2b3f Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'policy-utils/src/main/java/org')
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java4
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java27
2 files changed, 11 insertions, 20 deletions
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java b/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java
index 01ff58f5..c2755211 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -134,8 +135,7 @@ public class Metric {
}
if (endTime != null && startTime != null) {
- this.elapsedTime =
- Duration.between(startTime, endTime).toMillis();
+ this.elapsedTime = Duration.between(startTime, endTime).toMillis();
return;
}
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java b/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java
index 84c81cf0..27dfee49 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java
@@ -31,7 +31,6 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,7 +69,7 @@ public class DomainMaker {
return false;
}
- return validators.get(policyType).isConformant(json);
+ return getValidator(policyType).isConformant(json);
}
/**
@@ -94,7 +93,7 @@ public class DomainMaker {
}
try {
- return validators.get(policyType).encode(domainPolicy) != null;
+ return getValidator(policyType).encode(domainPolicy) != null;
} catch (CoderException e) {
logger.info("policy {}:{} is not conformant", policyType, domainPolicy.getClass().getName(), e);
return false;
@@ -116,7 +115,7 @@ public class DomainMaker {
}
try {
- validators.get(policy.getTypeIdentifier()).conformance(rawPolicy);
+ getValidator(policy.getTypeIdentifier()).conformance(rawPolicy);
} catch (CoderException e) {
logger.error("policy {}:{}:{} is not conformant",
policy.getTypeIdentifier(), policy.getName(), policy.getVersion(), e);
@@ -137,7 +136,7 @@ public class DomainMaker {
}
try {
- validators.get(policyType).encode(domainPolicy);
+ getValidator(policyType).encode(domainPolicy);
} catch (CoderException e) {
logger.error("policy {}:{} is not conformant", policyType, domainPolicy.getClass().getName(), e);
return false;
@@ -190,29 +189,21 @@ public class DomainMaker {
public <T> T convertTo(@NonNull ToscaConceptIdentifier policyType, @NonNull String json, @NonNull Class<T> clazz)
throws CoderException {
if (isRegistered(policyType)) {
- return validators.get(policyType).decode(json, clazz);
+ return getValidator(policyType).decode(json, clazz);
} else {
return nonValCoder.decode(json, clazz);
}
}
- /**
- * Converts a Tosca Policy Type specification to a domain-specific json specification.
- */
- public String convertToSchema(@NonNull ToscaPolicyType policyType) {
- //
- // TODO: // NOSONAR
- // 1. Convert Tosca Policy Type definition schema to suitable json schema.
- // 2. Call registerValidator to register
- throw new UnsupportedOperationException("schema generation from policy type is not supported");
- }
-
public boolean isRegistered(@NonNull ToscaConceptIdentifier policyType) {
return validators.containsKey(policyType) || registerValidator(policyType);
}
+ private StandardValCoder getValidator(ToscaConceptIdentifier policyType) {
+ return validators.get(policyType);
+ }
- private String serialize(@NonNull ToscaPolicy policy) {
+ private String serialize(ToscaPolicy policy) {
String rawPolicy = null;
try {
rawPolicy = nonValCoder.encode(policy);