From 6f9976df27dccb2dcaedeb9106166f62a435b050 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Mon, 13 Aug 2018 13:24:59 -0400 Subject: Resolve checkstyle formatting This submission is mostly focused on 120 spacing, missing spaces, rearranged imports, newlines before package and a few other items. Will have to submit further reviews to finish this. Issue-ID: POLICY-883 Change-Id: I772a2077ac97a0cb929810d8afadd2f415fae17b Signed-off-by: Pamela Dragosh --- .../controlloop/compiler/CompilerException.java | 30 +- .../controlloop/compiler/ControlLoopCompiler.java | 155 ++++--- .../compiler/ControlLoopCompilerCallback.java | 12 +- .../guard/compiler/ControlLoopGuardCompiler.java | 21 +- .../policy/controlloop/policy/FinalResult.java | 7 +- .../org/onap/policy/controlloop/policy/Policy.java | 63 +-- .../policy/builder/BuilderException.java | 13 +- .../policy/controlloop/policy/builder/Message.java | 10 +- .../policy/controlloop/policy/builder/Results.java | 14 +- .../policy/builder/impl/MessageImpl.java | 38 +- .../policy/builder/impl/ResultsImpl.java | 54 +-- .../controlloop/policy/guard/Constraint.java | 13 +- .../controlloop/policy/guard/GuardPolicy.java | 35 +- .../guard/builder/ControlLoopGuardBuilder.java | 17 +- .../builder/impl/ControlLoopGuardBuilderImpl.java | 7 +- .../compiler/CompilerExceptionTest.java | 13 +- .../compiler/ControlLoopCompilerTest.java | 312 +++++++------- .../compiler/ControlLoopGuardCompilerTest.java | 134 +++--- .../controlloop/policy/ControlLoopPolicyTest.java | 149 +++---- .../policy/OperationsAccumulateParamsTest.java | 182 ++++---- .../controlloop/policy/guard/ConstraintTest.java | 437 +++++++++---------- .../policy/guard/ControlLoopGuardBuilderTest.java | 23 +- .../policy/guard/ControlLoopGuardTest.java | 237 ++++++----- .../controlloop/policy/guard/GuardPolicyTest.java | 473 +++++++++++---------- 24 files changed, 1276 insertions(+), 1173 deletions(-) (limited to 'controlloop/common/policy-yaml') diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/CompilerException.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/CompilerException.java index 8a1fc3edd..d2b8d2b8d 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/CompilerException.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/CompilerException.java @@ -22,25 +22,25 @@ package org.onap.policy.controlloop.compiler; public class CompilerException extends Exception { - private static final long serialVersionUID = -7262217239867898601L; + private static final long serialVersionUID = -7262217239867898601L; - public CompilerException() { - } + public CompilerException() { + } - public CompilerException(String message) { - super(message); - } + public CompilerException(String message) { + super(message); + } - public CompilerException(Throwable cause) { - super(cause); - } + public CompilerException(Throwable cause) { + super(cause); + } - public CompilerException(String message, Throwable cause) { - super(message, cause); - } + public CompilerException(String message, Throwable cause) { + super(message, cause); + } - public CompilerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } + public CompilerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java index 0aa6f2a79..b088af78a 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java @@ -20,6 +20,9 @@ package org.onap.policy.controlloop.compiler; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + import java.io.InputStream; import java.io.Serializable; import java.util.Collections; @@ -43,15 +46,14 @@ import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -public class ControlLoopCompiler implements Serializable{ +public class ControlLoopCompiler implements Serializable { private static final String OPERATION_POLICY = "Operation Policy "; - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopCompiler.class.getName()); - public static ControlLoopPolicy compile(ControlLoopPolicy policy, ControlLoopCompilerCallback callback) throws CompilerException { + public static ControlLoopPolicy compile(ControlLoopPolicy policy, + ControlLoopCompilerCallback callback) throws CompilerException { // // Ensure the control loop is sane // @@ -64,7 +66,8 @@ public class ControlLoopCompiler implements Serializable{ return policy; } - public static ControlLoopPolicy compile(InputStream yamlSpecification, ControlLoopCompilerCallback callback) throws CompilerException { + public static ControlLoopPolicy compile(InputStream yamlSpecification, + ControlLoopCompilerCallback callback) throws CompilerException { Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class)); Object obj = yaml.load(yamlSpecification); if (obj == null) { @@ -76,12 +79,14 @@ public class ControlLoopCompiler implements Serializable{ return ControlLoopCompiler.compile((ControlLoopPolicy) obj, callback); } - private static void validateControlLoop(ControlLoop controlLoop, ControlLoopCompilerCallback callback) throws CompilerException { + private static void validateControlLoop(ControlLoop controlLoop, + ControlLoopCompilerCallback callback) throws CompilerException { if (controlLoop == null && callback != null) { callback.onError("controlLoop cannot be null"); } if (controlLoop!=null){ - if ((controlLoop.getControlLoopName() == null || controlLoop.getControlLoopName().length() < 1) && callback != null) { + if ((controlLoop.getControlLoopName() == null || controlLoop.getControlLoopName().length() < 1) + && callback != null) { callback.onError("Missing controlLoopName"); } if ((!controlLoop.getVersion().contentEquals(ControlLoop.getVERSION())) && callback != null) { @@ -93,18 +98,20 @@ public class ControlLoopCompiler implements Serializable{ } } - private static void validatePolicies(ControlLoopPolicy policy, ControlLoopCompilerCallback callback) throws CompilerException { + private static void validatePolicies(ControlLoopPolicy policy, + ControlLoopCompilerCallback callback) throws CompilerException { if (policy == null) { throw new CompilerException("policy cannot be null"); } if (policy.getPolicies() == null) { callback.onWarning("controlLoop is an open loop."); - } - else{ + } else { // // For this version we can use a directed multigraph, in the future we may not be able to // - DirectedGraph graph = new DirectedMultigraph<>(new ClassBasedEdgeFactory(LabeledEdge.class)); + DirectedGraph graph = + new DirectedMultigraph<>(new ClassBasedEdgeFactory(LabeledEdge.class)); // // Check to see if the trigger Event is for OpenLoop, we do so by // attempting to create a FinalResult object from it. If its a policy id, this should @@ -134,7 +141,8 @@ public class ControlLoopCompiler implements Serializable{ FinalResultNodeWrapper finalFailure = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE); FinalResultNodeWrapper finalFailureTimeout = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_TIMEOUT); FinalResultNodeWrapper finalFailureRetries = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_RETRIES); - FinalResultNodeWrapper finalFailureException = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_EXCEPTION); + FinalResultNodeWrapper finalFailureException = + new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_EXCEPTION); FinalResultNodeWrapper finalFailureGuard = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_GUARD); graph.addVertex(finalSuccess); graph.addVertex(finalFailure); @@ -157,38 +165,47 @@ public class ControlLoopCompiler implements Serializable{ if (node == null) { continue; } - addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getSuccess(), finalSuccess, PolicyResult.SUCCESS, node); - addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure(), finalFailure, PolicyResult.FAILURE, node); - addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_timeout(), finalFailureTimeout, PolicyResult.FAILURE_TIMEOUT, node); - addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_retries(), finalFailureRetries, PolicyResult.FAILURE_RETRIES, node); - addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_exception(), finalFailureException, PolicyResult.FAILURE_EXCEPTION, node); - addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_guard(), finalFailureGuard, PolicyResult.FAILURE_GUARD, node); + addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getSuccess(), finalSuccess, + PolicyResult.SUCCESS, node); + addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure(), finalFailure, + PolicyResult.FAILURE, node); + addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_timeout(), finalFailureTimeout, + PolicyResult.FAILURE_TIMEOUT, node); + addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_retries(), finalFailureRetries, + PolicyResult.FAILURE_RETRIES, node); + addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_exception(), finalFailureException, + PolicyResult.FAILURE_EXCEPTION, node); + addEdge(graph, mapNodes, operPolicy.getId(), operPolicy.getFailure_guard(), finalFailureGuard, + PolicyResult.FAILURE_GUARD, node); } validateNodesAndEdges(graph, callback); } } - private static void validateOpenLoopPolicy(ControlLoopPolicy policy, FinalResult triggerResult, ControlLoopCompilerCallback callback) throws CompilerException{ + private static void validateOpenLoopPolicy(ControlLoopPolicy policy, FinalResult triggerResult, + ControlLoopCompilerCallback callback) throws CompilerException { // // Ensure they didn't use some other FinalResult code // if (triggerResult != FinalResult.FINAL_OPENLOOP) { - throw new CompilerException("Unexpected Final Result for trigger_policy, should only be " + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); + throw new CompilerException("Unexpected Final Result for trigger_policy, should only be " + + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); } // // They really shouldn't have any policies attached. // - if ((policy.getPolicies() != null || policy.getPolicies().isEmpty())&& callback != null ) { + if ((policy.getPolicies() != null || policy.getPolicies().isEmpty()) && callback != null ) { callback.onWarning("Open Loop policy contains policies. The policies will never be invoked."); } } - private static void validatePoliciesContainTriggerPolicyAndCombinedTimeoutIsOk(ControlLoopPolicy policy, ControlLoopCompilerCallback callback) throws CompilerException{ + private static void validatePoliciesContainTriggerPolicyAndCombinedTimeoutIsOk(ControlLoopPolicy policy, + ControlLoopCompilerCallback callback) throws CompilerException { int sum = 0; boolean triggerPolicyFound = false; for (Policy operPolicy : policy.getPolicies()) { sum += operPolicy.getTimeout().intValue(); - if (policy.getControlLoop().getTrigger_policy().equals(operPolicy.getId())){ + if (policy.getControlLoop().getTrigger_policy().equals(operPolicy.getId())) { triggerPolicyFound = true; } } @@ -196,13 +213,15 @@ public class ControlLoopCompiler implements Serializable{ callback.onError("controlLoop overall timeout is less than the sum of operational policy timeouts."); } - if (!triggerPolicyFound){ - throw new CompilerException("Unexpected value for trigger_policy, should only be " + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); + if (!triggerPolicyFound) { + throw new CompilerException("Unexpected value for trigger_policy, should only be " + + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); } } private static Map addPoliciesAsNodes(ControlLoopPolicy policy, - DirectedGraph graph, TriggerNodeWrapper triggerNode, ControlLoopCompilerCallback callback){ + DirectedGraph graph, TriggerNodeWrapper triggerNode, + ControlLoopCompilerCallback callback) { Map mapNodes = new HashMap<>(); for (Policy operPolicy : policy.getPolicies()) { // @@ -234,22 +253,27 @@ public class ControlLoopCompiler implements Serializable{ return mapNodes; } - private static void addEdge(DirectedGraph graph, Map mapNodes, String policyId, String connectedPolicy, - FinalResultNodeWrapper finalResultNodeWrapper, PolicyResult policyResult, NodeWrapper node) throws CompilerException{ + private static void addEdge(DirectedGraph graph, Map mapNodes, + String policyId, String connectedPolicy, + FinalResultNodeWrapper finalResultNodeWrapper, + PolicyResult policyResult, NodeWrapper node) throws CompilerException { FinalResult finalResult = FinalResult.toResult(finalResultNodeWrapper.getID()); if (FinalResult.isResult(connectedPolicy, finalResult)) { - graph.addEdge(node, finalResultNodeWrapper, new LabeledEdge(node, finalResultNodeWrapper, new FinalResultEdgeWrapper(finalResult))); + graph.addEdge(node, finalResultNodeWrapper, new LabeledEdge(node, finalResultNodeWrapper, + new FinalResultEdgeWrapper(finalResult))); } else { PolicyNodeWrapper toNode = findPolicyNode(mapNodes, connectedPolicy); if (toNode == null) { - throw new CompilerException(OPERATION_POLICY + policyId + " is connected to unknown policy " + connectedPolicy); + throw new CompilerException(OPERATION_POLICY + policyId + " is connected to unknown policy " + + connectedPolicy); } else { graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(policyResult))); } } } - private static void validateNodesAndEdges(DirectedGraph graph, ControlLoopCompilerCallback callback) throws CompilerException{ + private static void validateNodesAndEdges(DirectedGraph graph, + ControlLoopCompilerCallback callback) throws CompilerException { for (NodeWrapper node : graph.vertexSet()) { if (node instanceof TriggerNodeWrapper) { validateTriggerNodeWrapper(graph, node); @@ -258,13 +282,14 @@ public class ControlLoopCompiler implements Serializable{ } else if (node instanceof PolicyNodeWrapper) { validatePolicyNodeWrapper(graph, node, callback); } - for (LabeledEdge edge : graph.outgoingEdgesOf(node)){ + for (LabeledEdge edge : graph.outgoingEdgesOf(node)) { LOGGER.info(edge.from.getID() + " invokes " + edge.to.getID() + " upon " + edge.edge.getID()); } } } - private static void validateTriggerNodeWrapper(DirectedGraph graph, NodeWrapper node) throws CompilerException{ + private static void validateTriggerNodeWrapper(DirectedGraph graph, + NodeWrapper node) throws CompilerException { if (LOGGER.isDebugEnabled()) { LOGGER.info("Trigger Node {}", node.toString()); } @@ -282,7 +307,8 @@ public class ControlLoopCompiler implements Serializable{ } } - private static void validateFinalResultNodeWrapper(DirectedGraph graph, NodeWrapper node) throws CompilerException{ + private static void validateFinalResultNodeWrapper(DirectedGraph graph, + NodeWrapper node) throws CompilerException { if (LOGGER.isDebugEnabled()) { LOGGER.info("FinalResult Node {}", node.toString()); } @@ -294,7 +320,8 @@ public class ControlLoopCompiler implements Serializable{ } } - private static void validatePolicyNodeWrapper(DirectedGraph graph, NodeWrapper node, ControlLoopCompilerCallback callback) throws CompilerException{ + private static void validatePolicyNodeWrapper(DirectedGraph graph, + NodeWrapper node, ControlLoopCompilerCallback callback) throws CompilerException { if (LOGGER.isDebugEnabled()) { LOGGER.info("Policy Node {}", node.toString()); } @@ -383,13 +410,23 @@ public class ControlLoopCompiler implements Serializable{ // ImmutableMap> recipes = new ImmutableMap.Builder>() .put("APPC", ImmutableList.of("Restart", "Rebuild", "Migrate", "ModifyConfig")) - .put("AOTS", ImmutableList.of("checkMaintenanceWindow", "checkENodeBTicketHours", "checkEquipmentStatus", "checkEimStatus", "checkEquipmentMaintenance")) + .put("AOTS", ImmutableList.of("checkMaintenanceWindow", + "checkENodeBTicketHours", + "checkEquipmentStatus", + "checkEimStatus", + "checkEquipmentMaintenance")) .put("MSO", ImmutableList.of("VF Module Create")) - .put("SDNO", ImmutableList.of("health-diagnostic-type", "health-diagnostic", "health-diagnostic-history", "health-diagnostic-commands", "health-diagnostic-aes")) + .put("SDNO", ImmutableList.of("health-diagnostic-type", + "health-diagnostic", + "health-diagnostic-history", + "health-diagnostic-commands", + "health-diagnostic-aes")) .put("SDNR", ImmutableList.of("Restart", "Reboot")) .build(); // - if (operPolicy.getRecipe() != null && (!recipes.getOrDefault(operPolicy.getActor(), Collections.emptyList()).contains(operPolicy.getRecipe()))) { + if (operPolicy.getRecipe() != null + && (!recipes.getOrDefault(operPolicy.getActor(), + Collections.emptyList()).contains(operPolicy.getRecipe()))) { if (callback != null) { callback.onError("Policy recipe is invalid"); } @@ -406,7 +443,10 @@ public class ControlLoopCompiler implements Serializable{ } isOk = false; } - if (operPolicy.getTarget() != null && operPolicy.getTarget().getType() != TargetType.VM && operPolicy.getTarget().getType() != TargetType.VFC && operPolicy.getTarget().getType() != TargetType.PNF) { + if (operPolicy.getTarget() != null + && operPolicy.getTarget().getType() != TargetType.VM + && operPolicy.getTarget().getType() != TargetType.VFC + && operPolicy.getTarget().getType() != TargetType.PNF) { if (callback != null) { callback.onError("Policy target is invalid"); } @@ -428,9 +468,10 @@ public class ControlLoopCompiler implements Serializable{ return isOk; } - private static boolean isSuccessPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback){ + private static boolean isSuccessPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) { boolean isOk = true; - if (FinalResult.toResult(operPolicy.getSuccess()) != null && !operPolicy.getSuccess().equals(FinalResult.FINAL_SUCCESS.toString())) { + if (FinalResult.toResult(operPolicy.getSuccess()) != null + && !operPolicy.getSuccess().equals(FinalResult.FINAL_SUCCESS.toString())) { if (callback != null) { callback.onError("Policy success is neither another policy nor FINAL_SUCCESS"); } @@ -439,9 +480,10 @@ public class ControlLoopCompiler implements Serializable{ return isOk; } - private static boolean isFailurePolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback){ + private static boolean isFailurePolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) { boolean isOk = true; - if (FinalResult.toResult(operPolicy.getFailure()) != null && !operPolicy.getFailure().equals(FinalResult.FINAL_FAILURE.toString())) { + if (FinalResult.toResult(operPolicy.getFailure()) != null + && !operPolicy.getFailure().equals(FinalResult.FINAL_FAILURE.toString())) { if (callback != null) { callback.onError("Policy failure is neither another policy nor FINAL_FAILURE"); } @@ -450,9 +492,10 @@ public class ControlLoopCompiler implements Serializable{ return isOk; } - private static boolean isFailureRetriesPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback){ + private static boolean isFailureRetriesPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) { boolean isOk = true; - if (FinalResult.toResult(operPolicy.getFailure_retries()) != null && !operPolicy.getFailure_retries().equals(FinalResult.FINAL_FAILURE_RETRIES.toString())) { + if (FinalResult.toResult(operPolicy.getFailure_retries()) != null + && !operPolicy.getFailure_retries().equals(FinalResult.FINAL_FAILURE_RETRIES.toString())) { if (callback != null) { callback.onError("Policy failure retries is neither another policy nor FINAL_FAILURE_RETRIES"); } @@ -461,9 +504,10 @@ public class ControlLoopCompiler implements Serializable{ return isOk; } - private static boolean isFailureTimeoutPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback){ + private static boolean isFailureTimeoutPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) { boolean isOk = true; - if (FinalResult.toResult(operPolicy.getFailure_timeout()) != null && !operPolicy.getFailure_timeout().equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString())) { + if (FinalResult.toResult(operPolicy.getFailure_timeout()) != null + && !operPolicy.getFailure_timeout().equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString())) { if (callback != null) { callback.onError("Policy failure timeout is neither another policy nor FINAL_FAILURE_TIMEOUT"); } @@ -472,9 +516,10 @@ public class ControlLoopCompiler implements Serializable{ return isOk; } - private static boolean isFailureExceptionPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback){ + private static boolean isFailureExceptionPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) { boolean isOk = true; - if (FinalResult.toResult(operPolicy.getFailure_exception()) != null && !operPolicy.getFailure_exception().equals(FinalResult.FINAL_FAILURE_EXCEPTION.toString())) { + if (FinalResult.toResult(operPolicy.getFailure_exception()) != null + && !operPolicy.getFailure_exception().equals(FinalResult.FINAL_FAILURE_EXCEPTION.toString())) { if (callback != null) { callback.onError("Policy failure exception is neither another policy nor FINAL_FAILURE_EXCEPTION"); } @@ -483,9 +528,10 @@ public class ControlLoopCompiler implements Serializable{ return isOk; } - private static boolean isFailureGuardPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback){ + private static boolean isFailureGuardPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) { boolean isOk = true; - if (FinalResult.toResult(operPolicy.getFailure_guard()) != null && !operPolicy.getFailure_guard().equals(FinalResult.FINAL_FAILURE_GUARD.toString())) { + if (FinalResult.toResult(operPolicy.getFailure_guard()) != null + && !operPolicy.getFailure_guard().equals(FinalResult.FINAL_FAILURE_GUARD.toString())) { if (callback != null) { callback.onError("Policy failure guard is neither another policy nor FINAL_FAILURE_GUARD"); } @@ -504,7 +550,7 @@ public class ControlLoopCompiler implements Serializable{ } @FunctionalInterface - private interface NodeWrapper extends Serializable{ + private interface NodeWrapper extends Serializable { public String getID(); } @@ -567,7 +613,7 @@ public class ControlLoopCompiler implements Serializable{ } @FunctionalInterface - private interface EdgeWrapper extends Serializable{ + private interface EdgeWrapper extends Serializable { public String getID(); } @@ -617,6 +663,7 @@ public class ControlLoopCompiler implements Serializable{ private static class FinalResultEdgeWrapper implements EdgeWrapper { private static final long serialVersionUID = -1486381946896779840L; private FinalResult finalResult; + public FinalResultEdgeWrapper(FinalResult result) { this.finalResult = result; } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerCallback.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerCallback.java index e07b77640..bdbc68167 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerCallback.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerCallback.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,9 @@ package org.onap.policy.controlloop.compiler; public interface ControlLoopCompilerCallback { - - public boolean onWarning(String message); - - public boolean onError(String message); - + + public boolean onWarning(String message); + + public boolean onError(String message); + } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java index 34c97e350..2897fde26 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,13 +37,14 @@ import org.yaml.snakeyaml.constructor.Constructor; public class ControlLoopGuardCompiler { private static final String GUARD_POLICIES_SHOULD_NOT_BE_NULL = "Guard policies should not be null"; - private static final String GUARD_POLICY = "Guard policy "; + private static final String GUARD_POLICY = "Guard policy "; - private ControlLoopGuardCompiler(){ + private ControlLoopGuardCompiler(){ // Private Constructor } - public static ControlLoopGuard compile(ControlLoopGuard cLGuard, ControlLoopCompilerCallback callback) throws CompilerException { + public static ControlLoopGuard compile(ControlLoopGuard cLGuard, + ControlLoopCompilerCallback callback) throws CompilerException { // // Ensure ControlLoopGuard has at least one guard policies // @@ -60,7 +61,8 @@ public class ControlLoopGuardCompiler { return cLGuard; } - public static ControlLoopGuard compile(InputStream yamlSpecification, ControlLoopCompilerCallback callback) throws CompilerException { + public static ControlLoopGuard compile(InputStream yamlSpecification, + ControlLoopCompilerCallback callback) throws CompilerException { Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class)); Object obj = yaml.load(yamlSpecification); if (obj == null) { @@ -72,7 +74,8 @@ public class ControlLoopGuardCompiler { return ControlLoopGuardCompiler.compile((ControlLoopGuard) obj, callback); } - private static void validateControlLoopGuard(ControlLoopGuard cLGuard, ControlLoopCompilerCallback callback) throws CompilerException { + private static void validateControlLoopGuard(ControlLoopGuard cLGuard, + ControlLoopCompilerCallback callback) throws CompilerException { if (cLGuard == null) { if (callback != null) { callback.onError("ControlLoop Guard cannot be null"); @@ -91,7 +94,8 @@ public class ControlLoopGuardCompiler { } } - private static void validateGuardPolicies(List policies, ControlLoopCompilerCallback callback) throws CompilerException { + private static void validateGuardPolicies(List policies, + ControlLoopCompilerCallback callback) throws CompilerException { if (policies == null) { if (callback != null) { callback.onError(GUARD_POLICIES_SHOULD_NOT_BE_NULL); @@ -118,7 +122,8 @@ public class ControlLoopGuardCompiler { } } - private static void validateConstraints(List policies, ControlLoopCompilerCallback callback) throws CompilerException { + private static void validateConstraints(List policies, + ControlLoopCompilerCallback callback) throws CompilerException { if (policies == null) { if (callback != null) { callback.onError(GUARD_POLICIES_SHOULD_NOT_BE_NULL); diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java index 1b312ea5a..b9fdc2e6d 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,8 @@ public enum FinalResult { */ FINAL_OPENLOOP("Final_OpenLoop"), /** - * The Control Loop Policy failed in its last Operation Policy. NOTE: Previous Operation Policies may have been successful. + * The Control Loop Policy failed in its last Operation Policy. + * NOTE: Previous Operation Policies may have been successful. */ FINAL_FAILURE("Final_Failure"), /** @@ -46,7 +47,7 @@ public enum FinalResult { */ FINAL_FAILURE_EXCEPTION("Final_Failure_Exception"), /** - * The Control Loop Policy failed due to guard denied + * The Control Loop Policy failed due to guard denied. */ FINAL_FAILURE_GUARD("Final_Failure_Guard") ; diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java index eed6c7c39..4e0a0c99b 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -190,13 +190,15 @@ public class Policy { } } - public Policy(String name, String actor, String recipe, Map payload, Target target, Integer retries, Integer timeout) { + public Policy(String name, String actor, String recipe, Map payload, Target target, + Integer retries, Integer timeout) { this(name, actor, recipe, payload, target); this.retry = retries; this.timeout = timeout; } - public Policy(String id, String name, String description, String actor, Map payload, Target target, String recipe, Integer retries, Integer timeout) { + public Policy(String id, String name, String description, String actor, Map payload, + Target target, String recipe, Integer retries, Integer timeout) { this(name, actor, recipe, payload, target, retries, timeout); this.id = id; this.description = description; @@ -224,15 +226,17 @@ public class Policy { } public boolean isValid() { - return id==null || name==null || actor==null|| recipe==null || target==null; + return id == null || name == null || actor == null || recipe == null || target == null; } @Override public String toString() { return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", actor=" + actor + ", recipe=" - + recipe + ", payload=" + payload + ", target=" + target + ", operationsAccumulateParams=" + operationsAccumulateParams + ", retry=" + retry + ", timeout=" + timeout + + recipe + ", payload=" + payload + ", target=" + target + ", operationsAccumulateParams=" + + operationsAccumulateParams + ", retry=" + retry + ", timeout=" + timeout + ", success=" + success + ", failure=" + failure + ", failure_retries=" + failureRetries - + ", failure_timeout=" + failureTimeout + ", failure_exception=" + failureException + ", failure_guard=" + failureGuard + "]"; + + ", failure_timeout=" + failureTimeout + ", failure_exception=" + failureException + + ", failure_guard=" + failureGuard + "]"; } @Override @@ -257,42 +261,45 @@ public class Policy { return result; } - private int addHashCodeForField(int hashCode, Object field){ + private int addHashCodeForField(int hashCode, Object field) { final int prime = 31; - return prime * hashCode + ((field == null) ? 0 : field.hashCode()); + return prime * hashCode + ((field == null) ? 0 : field.hashCode()); } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Policy other = (Policy) obj; return equalsMayBeNull(actor, other.actor) - && equalsMayBeNull(description, other.description) - && equalsMayBeNull(failure, other.failure) - && equalsMayBeNull(failureException, other.failureException) - && equalsMayBeNull(failureGuard, other.failureGuard) - && equalsMayBeNull(failureRetries, other.failureRetries) - && equalsMayBeNull(id, other.id) - && equalsMayBeNull(name, other.name) - && equalsMayBeNull(payload, other.payload) - && equalsMayBeNull(recipe, other.recipe) - && equalsMayBeNull(retry, other.retry) - && equalsMayBeNull(success, other.success) - && equalsMayBeNull(operationsAccumulateParams, other.operationsAccumulateParams) - && equalsMayBeNull(target, other.target) - && equalsMayBeNull(timeout, other.timeout); + && equalsMayBeNull(description, other.description) + && equalsMayBeNull(failure, other.failure) + && equalsMayBeNull(failureException, other.failureException) + && equalsMayBeNull(failureGuard, other.failureGuard) + && equalsMayBeNull(failureRetries, other.failureRetries) + && equalsMayBeNull(id, other.id) + && equalsMayBeNull(name, other.name) + && equalsMayBeNull(payload, other.payload) + && equalsMayBeNull(recipe, other.recipe) + && equalsMayBeNull(retry, other.retry) + && equalsMayBeNull(success, other.success) + && equalsMayBeNull(operationsAccumulateParams, other.operationsAccumulateParams) + && equalsMayBeNull(target, other.target) + && equalsMayBeNull(timeout, other.timeout); } - private boolean equalsMayBeNull(final Object obj1, final Object obj2){ - if ( obj1 == null ) { + private boolean equalsMayBeNull(final Object obj1, final Object obj2) { + if ( obj1 == null ) { return obj2 == null; } - return obj1.equals(obj2); + return obj1.equals(obj2); } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java index 5fc8ffb6e..618678e9c 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,10 @@ package org.onap.policy.controlloop.policy.builder; public class BuilderException extends Exception { - public BuilderException(String string) { - super(string); - } + public BuilderException(String string) { + super(string); + } - /** - * - */ - private static final long serialVersionUID = 610064813684337895L; + private static final long serialVersionUID = 610064813684337895L; } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Message.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Message.java index e620276b0..3a71c6d26 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Message.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Message.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,9 @@ package org.onap.policy.controlloop.policy.builder; public interface Message { - - public String getMessage(); - - public MessageLevel getLevel(); + + public String getMessage(); + + public MessageLevel getLevel(); } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Results.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Results.java index fa309cc1f..9ad89c7cf 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Results.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/Results.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,11 @@ package org.onap.policy.controlloop.policy.builder; import java.util.List; public interface Results { - - public List getMessages(); - - public String getSpecification(); - - public boolean isValid(); + + public List getMessages(); + + public String getSpecification(); + + public boolean isValid(); } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/MessageImpl.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/MessageImpl.java index 45de842f9..22244e09b 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/MessageImpl.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/MessageImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,23 +24,23 @@ import org.onap.policy.controlloop.policy.builder.Message; import org.onap.policy.controlloop.policy.builder.MessageLevel; public class MessageImpl implements Message { - - private String message; - private MessageLevel level; - - public MessageImpl(String message, MessageLevel level) { - this.message = message; - this.level = level; - } - - @Override - public String getMessage() { - return message; - } - - @Override - public MessageLevel getLevel() { - return level; - } + + private String message; + private MessageLevel level; + + public MessageImpl(String message, MessageLevel level) { + this.message = message; + this.level = level; + } + + @Override + public String getMessage() { + return message; + } + + @Override + public MessageLevel getLevel() { + return level; + } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ResultsImpl.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ResultsImpl.java index 78d28ef38..f9a9a474f 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ResultsImpl.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ResultsImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,30 +27,30 @@ import org.onap.policy.controlloop.policy.builder.Message; import org.onap.policy.controlloop.policy.builder.Results; public class ResultsImpl implements Results { - - private String specification; - private List messages = new LinkedList<>(); - - @Override - public List getMessages() { - return messages; - } - - @Override - public String getSpecification() { - return specification; - } - - @Override - public boolean isValid() { - return (this.specification != null); - } - - public void addMessage(Message message) { - this.messages.add(message); - } - - public void setSpecification(String spec) { - this.specification = spec; - } + + private String specification; + private List messages = new LinkedList<>(); + + @Override + public List getMessages() { + return messages; + } + + @Override + public String getSpecification() { + return specification; + } + + @Override + public boolean isValid() { + return (this.specification != null); + } + + public void addMessage(Message message) { + this.messages.add(message); + } + + public void setSpecification(String spec) { + this.specification = spec; + } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java index 3ebf7013e..e53f3e40f 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,12 +99,13 @@ public class Constraint { } } - public Constraint(Integer freqLimitPerTarget, Map timeWindow, Map activeTimeRange, List blacklist) { + public Constraint(Integer freqLimitPerTarget, Map timeWindow, Map activeTimeRange, + List blacklist) { this(freqLimitPerTarget, timeWindow); if (activeTimeRange != null) { this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange); } - if(blacklist!=null){ + if(blacklist != null){ this.blacklist = new LinkedList<>(blacklist); } } @@ -119,12 +120,14 @@ public class Constraint { } public boolean isValid() { - return ((freqLimitPerTarget == null && timeWindow != null)|| (timeWindow == null && freqLimitPerTarget != null))? false : true; + return ((freqLimitPerTarget == null && timeWindow != null) + || (timeWindow == null && freqLimitPerTarget != null)) ? false : true; } @Override public String toString() { - return "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window=" + timeWindow + ", active_time_range=" + activeTimeRange + ", blacklist=" + blacklist + "]"; + return "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window=" + + timeWindow + ", active_time_range=" + activeTimeRange + ", blacklist=" + blacklist + "]"; } @Override diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java index c45014c3c..759a0533d 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,12 +98,14 @@ public class GuardPolicy { } } - public GuardPolicy(String name, String description, MatchParameters matchParameters, List limitConstraints) { + public GuardPolicy(String name, String description, MatchParameters matchParameters, + List limitConstraints) { this(name, matchParameters, limitConstraints); this.description = description; } - public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, List limitConstraints) { + public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, + List limitConstraints) { this(name, description, matchParameters, limitConstraints); this.id = id; } @@ -119,13 +121,13 @@ public class GuardPolicy { } public boolean isValid() { - return (id==null || name ==null)? false : true; + return (id == null || name == null) ? false : true; } @Override public String toString() { return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters=" - +matchParameters + ", limitConstraints=" + limitConstraints + "]"; + + matchParameters + ", limitConstraints=" + limitConstraints + "]"; } @Override @@ -142,24 +144,27 @@ public class GuardPolicy { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } GuardPolicy other = (GuardPolicy) obj; return equalsMayBeNull(description, other.description) - && equalsMayBeNull(id, other.id) - && equalsMayBeNull(name, other.name) - && equalsMayBeNull(limitConstraints, other.limitConstraints) - && equalsMayBeNull(matchParameters, other.matchParameters); + && equalsMayBeNull(id, other.id) + && equalsMayBeNull(name, other.name) + && equalsMayBeNull(limitConstraints, other.limitConstraints) + && equalsMayBeNull(matchParameters, other.matchParameters); } - private boolean equalsMayBeNull(final Object obj1, final Object obj2){ - if ( obj1 == null ) { + private boolean equalsMayBeNull(final Object obj1, final Object obj2) { + if ( obj1 == null ) { return obj2 == null; } - return obj1.equals(obj2); + return obj1.equals(obj2); } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java index d521624fd..77651dcbf 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,15 +93,17 @@ public interface ControlLoopGuardBuilder { public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException; /** - * Simply return a copy of control loop guard + * Simply return a copy of control loop guard. * * @return ControlLoopGuard */ public ControlLoopGuard getControlLoopGuard(); /** - * This will compile and build the YAML specification for the Control Loop Guard. Please iterate the Results object for details. - * The Results object will contains warnings and errors. If the specification compiled successfully, you will be able to retrieve the + * This will compile and build the YAML specification for the Control Loop Guard. + * Please iterate the Results object for details. + * The Results object will contains warnings and errors. + * If the specification compiled successfully, you will be able to retrieve the * YAML. * * @return Results @@ -118,10 +120,13 @@ public interface ControlLoopGuardBuilder { //Do Nothing Private Constructor. } /** - * @param guard + * Build the control loop guard. + * + * @param guard the guard * @return ControlLoopGuardBuilder object */ - public static ControlLoopGuardBuilder buildControlLoopGuard (Guard guard) { + + public static ControlLoopGuardBuilder buildControlLoopGuard(Guard guard) { return new ControlLoopGuardBuilderImpl(guard); diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java index a431a0bfe..b4d251e7f 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,9 @@ import org.yaml.snakeyaml.Yaml; public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { private static final String NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID = "No existing guard policy matching the id: "; - private static final String THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL = "The id of target guard policy must not be null"; - private static Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderImpl.class.getName()); + private static final String THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL = + "The id of target guard policy must not be null"; + private static Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderImpl.class.getName()); private ControlLoopGuard cLGuard; public ControlLoopGuardBuilderImpl(Guard guard) { diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java index 0ec882fef..d48336b3d 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java @@ -15,16 +15,17 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.controlloop.compiler; import org.junit.Test; import org.onap.policy.common.utils.test.ExceptionsTester; -public class CompilerExceptionTest extends ExceptionsTester{ - - @Test - public void test() throws Exception { - test(CompilerException.class); - } +public class CompilerExceptionTest extends ExceptionsTester { + + @Test + public void test() throws Exception { + test(CompilerException.class); + } } diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java index 048aef270..b69343862 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml unit test * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,162 +37,174 @@ import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.FinalResult; public class ControlLoopCompilerTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void testTest() throws Exception { - List expectedOnErrorMessages = new ArrayList<>(); - expectedOnErrorMessages.add("Operational Policy has an bad ID"); - expectedOnErrorMessages.add("Policy id is set to a PolicyResult SUCCESS"); - expectedOnErrorMessages.add("Policy id is set to a FinalResult FINAL_SUCCESS"); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void testTest() throws Exception { + List expectedOnErrorMessages = new ArrayList<>(); + expectedOnErrorMessages.add("Operational Policy has an bad ID"); + expectedOnErrorMessages.add("Policy id is set to a PolicyResult SUCCESS"); + expectedOnErrorMessages.add("Policy id is set to a FinalResult FINAL_SUCCESS"); expectedOnErrorMessages.add("Policy actor is null"); - expectedOnErrorMessages.add("Policy actor is invalid"); - expectedOnErrorMessages.add("Policy recipe is null"); - expectedOnErrorMessages.add("Policy recipe is invalid"); + expectedOnErrorMessages.add("Policy actor is invalid"); + expectedOnErrorMessages.add("Policy recipe is null"); + expectedOnErrorMessages.add("Policy recipe is invalid"); expectedOnErrorMessages.add("Policy recipe is invalid"); expectedOnErrorMessages.add("Policy recipe is invalid"); - expectedOnErrorMessages.add("Policy target is null"); - expectedOnErrorMessages.add("Policy target is invalid"); - expectedOnErrorMessages.add("Policy success is neither another policy nor FINAL_SUCCESS"); - expectedOnErrorMessages.add("Policy failure is neither another policy nor FINAL_FAILURE"); - expectedOnErrorMessages.add("Policy failure retries is neither another policy nor FINAL_FAILURE_RETRIES"); - expectedOnErrorMessages.add("Policy failure timeout is neither another policy nor FINAL_FAILURE_TIMEOUT"); - expectedOnErrorMessages.add("Policy failure exception is neither another policy nor FINAL_FAILURE_EXCEPTION"); - expectedOnErrorMessages.add("Policy failure guard is neither another policy nor FINAL_FAILURE_GUARD"); + expectedOnErrorMessages.add("Policy target is null"); + expectedOnErrorMessages.add("Policy target is invalid"); + expectedOnErrorMessages.add("Policy success is neither another policy nor FINAL_SUCCESS"); + expectedOnErrorMessages.add("Policy failure is neither another policy nor FINAL_FAILURE"); + expectedOnErrorMessages.add("Policy failure retries is neither another policy nor FINAL_FAILURE_RETRIES"); + expectedOnErrorMessages.add("Policy failure timeout is neither another policy nor FINAL_FAILURE_TIMEOUT"); + expectedOnErrorMessages.add("Policy failure exception is neither another policy nor FINAL_FAILURE_EXCEPTION"); + expectedOnErrorMessages.add("Policy failure guard is neither another policy nor FINAL_FAILURE_GUARD"); expectedOnErrorMessages.add("Unsupported version for this compiler"); expectedOnErrorMessages.add("controlLoop overall timeout is less than the sum of operational policy timeouts."); - - TestControlLoopCompilerCallback testControlLoopCompilerCallback = new TestControlLoopCompilerCallback(expectedOnErrorMessages); - ControlLoopPolicy controlLoopPolicy = this.test("src/test/resources/v1.0.0/test.yaml", testControlLoopCompilerCallback); - assertEquals(22, controlLoopPolicy.getPolicies().size()); - assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived()); - } - - @Test - public void testSuccessConnectedToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); - this.test("src/test/resources/v1.0.0/bad_policy_success_connected_to_unknown_policy.yaml"); - } - - @Test - public void testFailureConnectedToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); - this.test("src/test/resources/v1.0.0/bad_policy_failure_connected_to_unknown_policy.yaml"); - } - - @Test - public void testFailureTimeoutToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); - this.test("src/test/resources/v1.0.0/bad_policy_failure_timeout_connected_to_unknown_policy.yaml"); - } - - @Test - public void testFailureRetriesToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); - this.test("src/test/resources/v1.0.0/bad_policy_failure_retries_connected_to_unknown_policy.yaml"); - } - - @Test - public void testFailureExceptionToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); - this.test("src/test/resources/v1.0.0/bad_policy_failure_exception_connected_to_unknown_policy.yaml"); - } - - @Test - public void testFailureGuardToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); - this.test("src/test/resources/v1.0.0/bad_policy_failure_guard_connected_to_unknown_policy.yaml"); - } - - @Test - public void testInvalidTriggerPolicyId() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Unexpected value for trigger_policy, should only be " + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); - this.test("src/test/resources/v1.0.0/bad_trigger_1.yaml"); - } - - @Test - public void testNoTriggerPolicyId() throws Exception { - expectedException.expect(CompilerException.class); - this.test("src/test/resources/v1.0.0/bad_trigger_no_trigger_id.yaml"); - } - - @Test - public void testNoControlLoopName() throws Exception { - List expectedOnErrorMessages = new ArrayList<>(); + + TestControlLoopCompilerCallback testControlLoopCompilerCallback = + new TestControlLoopCompilerCallback(expectedOnErrorMessages); + ControlLoopPolicy controlLoopPolicy = this.test("src/test/resources/v1.0.0/test.yaml", + testControlLoopCompilerCallback); + assertEquals(22, controlLoopPolicy.getPolicies().size()); + assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived()); + } + + @Test + public void testSuccessConnectedToUnknownPolicy() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); + this.test("src/test/resources/v1.0.0/bad_policy_success_connected_to_unknown_policy.yaml"); + } + + @Test + public void testFailureConnectedToUnknownPolicy() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); + this.test("src/test/resources/v1.0.0/bad_policy_failure_connected_to_unknown_policy.yaml"); + } + + @Test + public void testFailureTimeoutToUnknownPolicy() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); + this.test("src/test/resources/v1.0.0/bad_policy_failure_timeout_connected_to_unknown_policy.yaml"); + } + + @Test + public void testFailureRetriesToUnknownPolicy() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); + this.test("src/test/resources/v1.0.0/bad_policy_failure_retries_connected_to_unknown_policy.yaml"); + } + + @Test + public void testFailureExceptionToUnknownPolicy() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); + this.test("src/test/resources/v1.0.0/bad_policy_failure_exception_connected_to_unknown_policy.yaml"); + } + + @Test + public void testFailureGuardToUnknownPolicy() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"); + this.test("src/test/resources/v1.0.0/bad_policy_failure_guard_connected_to_unknown_policy.yaml"); + } + + @Test + public void testInvalidTriggerPolicyId() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Unexpected value for trigger_policy, should only be " + + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); + this.test("src/test/resources/v1.0.0/bad_trigger_1.yaml"); + } + + @Test + public void testNoTriggerPolicyId() throws Exception { + expectedException.expect(CompilerException.class); + this.test("src/test/resources/v1.0.0/bad_trigger_no_trigger_id.yaml"); + } + + @Test + public void testNoControlLoopName() throws Exception { + List expectedOnErrorMessages = new ArrayList<>(); expectedOnErrorMessages.add("Missing controlLoopName"); expectedOnErrorMessages.add("Unsupported version for this compiler"); - TestControlLoopCompilerCallback testControlLoopCompilerCallback = new TestControlLoopCompilerCallback(expectedOnErrorMessages); - this.test("src/test/resources/v1.0.0/bad_control_loop_no_control_loop_name.yaml", testControlLoopCompilerCallback); - assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived()); - } - - @Test - public void testInvalidFinalResult() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Unexpected Final Result for trigger_policy, should only be FINAL_OPENLOOP or a valid Policy ID"); - this.test("src/test/resources/v1.0.0/bad_trigger_2.yaml"); - } - - @Test - public void testCompileEmptyFile() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Could not parse yaml specification."); - this.test("src/test/resources/v1.0.0/empty.yaml"); - } - - public ControlLoopPolicy test(String testFile) throws Exception { - return test(testFile, null); - } - - public ControlLoopPolicy test(String testFile, ControlLoopCompilerCallback controlLoopCompilerCallback) throws Exception { - try (InputStream is = new FileInputStream(new File(testFile))) { - return ControlLoopCompiler.compile(is, controlLoopCompilerCallback); - } catch (FileNotFoundException e) { - fail(e.getMessage()); - } catch (IOException e) { - fail(e.getMessage()); - } catch (Exception e) { - throw e; - } - return null; - } - - class TestControlLoopCompilerCallback implements ControlLoopCompilerCallback{ - - private List expectedOnErrorMessages; - - public TestControlLoopCompilerCallback(List expectedOnErrorMessages){ - this.expectedOnErrorMessages = expectedOnErrorMessages; - } - - @Override - public boolean onWarning(String message) { - return true; - } - - @Override - public boolean onError(String message) { - if (!expectedOnErrorMessages.remove(message)){ - fail("Unexpected onError message: " + message); - } - return true; - } - - public boolean areAllExpectedOnErrorsReceived(){ - return expectedOnErrorMessages.size() == 0; - } - - }; + TestControlLoopCompilerCallback testControlLoopCompilerCallback = + new TestControlLoopCompilerCallback(expectedOnErrorMessages); + this.test("src/test/resources/v1.0.0/bad_control_loop_no_control_loop_name.yaml", + testControlLoopCompilerCallback); + assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived()); + } -} + @Test + public void testInvalidFinalResult() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage( + "Unexpected Final Result for trigger_policy, should only be FINAL_OPENLOOP or a valid Policy ID"); + this.test("src/test/resources/v1.0.0/bad_trigger_2.yaml"); + } + + @Test + public void testCompileEmptyFile() throws Exception { + expectedException.expect(CompilerException.class); + expectedException.expectMessage("Could not parse yaml specification."); + this.test("src/test/resources/v1.0.0/empty.yaml"); + } + + public ControlLoopPolicy test(String testFile) throws Exception { + return test(testFile, null); + } + + public ControlLoopPolicy test(String testFile, + ControlLoopCompilerCallback controlLoopCompilerCallback) throws Exception { + try (InputStream is = new FileInputStream(new File(testFile))) { + return ControlLoopCompiler.compile(is, controlLoopCompilerCallback); + } catch (FileNotFoundException e) { + fail(e.getMessage()); + } catch (IOException e) { + fail(e.getMessage()); + } catch (Exception e) { + throw e; + } + return null; + } + + class TestControlLoopCompilerCallback implements ControlLoopCompilerCallback { + private List expectedOnErrorMessages; + public TestControlLoopCompilerCallback(List expectedOnErrorMessages) { + this.expectedOnErrorMessages = expectedOnErrorMessages; + } + + @Override + public boolean onWarning(String message) { + return true; + } + + @Override + public boolean onError(String message) { + if (!expectedOnErrorMessages.remove(message)) { + fail("Unexpected onError message: " + message); + } + return true; + } + + public boolean areAllExpectedOnErrorsReceived() { + return expectedOnErrorMessages.size() == 0; + } + + } + +} diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java index f381aa207..54c4eccff 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml unit test * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,70 +34,70 @@ import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler; public class ControlLoopGuardCompilerTest { - @Test - public void testTest1() { - try { - this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml"); - } catch (Exception e) { - fail(e.getMessage()); - } - } - - @Test - public void testTest2() { - try { - this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml"); - } catch (Exception e) { - fail(e.getMessage()); - } - } - - @Test - public void testBad1() { - try { - this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testBad2() { - try { - this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testBad3() { - try { - this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testBad4() { - try { - this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void test(String testFile) throws Exception { - try (InputStream is = new FileInputStream(new File(testFile))) { - ControlLoopGuardCompiler.compile(is, null); - } catch (FileNotFoundException e) { - fail(e.getMessage()); - } catch (IOException e) { - fail(e.getMessage()); - } catch (Exception e) { - throw e; - } - } - + @Test + public void testTest1() { + try { + this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml"); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @Test + public void testTest2() { + try { + this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml"); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @Test + public void testBad1() { + try { + this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testBad2() { + try { + this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testBad3() { + try { + this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testBad4() { + try { + this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void test(String testFile) throws Exception { + try (InputStream is = new FileInputStream(new File(testFile))) { + ControlLoopGuardCompiler.compile(is, null); + } catch (FileNotFoundException e) { + fail(e.getMessage()); + } catch (IOException e) { + fail(e.getMessage()); + } catch (Exception e) { + throw e; + } + } + } diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java index b847009cc..6212b17f4 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml unit test * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,83 +38,84 @@ import org.yaml.snakeyaml.constructor.Constructor; public class ControlLoopPolicyTest { - private static final Logger logger = LoggerFactory.getLogger(ControlLoopPolicyTest.class); - @Test - public void test() { - this.test("src/test/resources/v1.0.0/policy_Test.yaml"); - } - - @Test - public void testvService1() { - this.test("src/test/resources/v1.0.0/policy_vService.yaml"); - } + private static final Logger logger = LoggerFactory.getLogger(ControlLoopPolicyTest.class); + + @Test + public void test() { + this.test("src/test/resources/v1.0.0/policy_Test.yaml"); + } - @Test - public void testOpenLoop() { - this.test("src/test/resources/v1.0.0/policy_OpenLoop.yaml"); - } + @Test + public void testvService1() { + this.test("src/test/resources/v1.0.0/policy_vService.yaml"); + } - @Test - public void testvDNS() { - this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vDNS.yaml"); - } + @Test + public void testOpenLoop() { + this.test("src/test/resources/v1.0.0/policy_OpenLoop.yaml"); + } - @Test - public void testvFirewall() { - // Chenfei to fix this. -// this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml"); - } + @Test + public void testvDNS() { + this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vDNS.yaml"); + } - @Test - public void testvCPE() { - this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_vCPE.yaml"); - } + @Test + public void testvFirewall() { + // Chenfei to fix this. + // this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml"); + } - @Test - public void testVOLTE() { - this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_VOLTE.yaml"); - } + @Test + public void testvCPE() { + this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_vCPE.yaml"); + } - public void test(String testFile) { - try (InputStream is = new FileInputStream(new File(testFile))) { - // - // Read the yaml into our Java Object - // - Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class)); - Object obj = yaml.load(is); - assertNotNull(obj); - assertTrue(obj instanceof ControlLoopPolicy); - dump(obj); - // - // Now dump it to a yaml string - // - DumperOptions options = new DumperOptions(); - options.setDefaultFlowStyle(FlowStyle.BLOCK); - options.setPrettyFlow(true); - yaml = new Yaml(options); - String dumpedYaml = yaml.dump(obj); - logger.debug(dumpedYaml); - // - // Read that string back into our java object - // - Object newObject = yaml.load(dumpedYaml); - dump(newObject); - assertNotNull(newObject); - assertTrue(newObject instanceof ControlLoopPolicy); - // - // Have to comment it out tentatively since it causes junit to fail. - // Seems we cannot use assertEquals here. Need advice. - // - //assertEquals(newObject, obj); - } catch (FileNotFoundException e) { - fail(e.getLocalizedMessage()); - } catch (IOException e) { - fail(e.getLocalizedMessage()); - } - } - - public void dump(Object obj) { - logger.debug("Dumping ", obj.getClass().getCanonicalName()); - logger.debug("{}", obj); - } + @Test + public void testVOLTE() { + this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_VOLTE.yaml"); + } + + public void test(String testFile) { + try (InputStream is = new FileInputStream(new File(testFile))) { + // + // Read the yaml into our Java Object + // + Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class)); + Object obj = yaml.load(is); + assertNotNull(obj); + assertTrue(obj instanceof ControlLoopPolicy); + dump(obj); + // + // Now dump it to a yaml string + // + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(FlowStyle.BLOCK); + options.setPrettyFlow(true); + yaml = new Yaml(options); + String dumpedYaml = yaml.dump(obj); + logger.debug(dumpedYaml); + // + // Read that string back into our java object + // + Object newObject = yaml.load(dumpedYaml); + dump(newObject); + assertNotNull(newObject); + assertTrue(newObject instanceof ControlLoopPolicy); + // + // Have to comment it out tentatively since it causes junit to fail. + // Seems we cannot use assertEquals here. Need advice. + // + //assertEquals(newObject, obj); + } catch (FileNotFoundException e) { + fail(e.getLocalizedMessage()); + } catch (IOException e) { + fail(e.getLocalizedMessage()); + } + } + + public void dump(Object obj) { + logger.debug("Dumping ", obj.getClass().getCanonicalName()); + logger.debug("{}", obj); + } } diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/OperationsAccumulateParamsTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/OperationsAccumulateParamsTest.java index 5d627a906..adf85af3a 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/OperationsAccumulateParamsTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/OperationsAccumulateParamsTest.java @@ -15,6 +15,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.controlloop.policy; import static org.junit.Assert.*; @@ -23,94 +24,97 @@ import org.junit.Test; public class OperationsAccumulateParamsTest { - @Test - public void testConstructor() { - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); - assertNull(operationsAccumulateParams.getPeriod()); - assertNull(operationsAccumulateParams.getLimit()); - } - - @Test - public void testConstructorOperationsAccumulateParams() { - String period = "15m"; - Integer limit = 10; - OperationsAccumulateParams operationsAccumulateParams1 = new OperationsAccumulateParams(period, limit); - OperationsAccumulateParams operationsAccumulateParams2 = new OperationsAccumulateParams(operationsAccumulateParams1); - assertEquals(period, operationsAccumulateParams1.getPeriod()); - assertEquals(limit, operationsAccumulateParams2.getLimit()); - } - - @Test - public void testOperationsAccumulateParamsStringInteger() { - String period = "15m"; - Integer limit = 10; - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit); - assertEquals(period, operationsAccumulateParams.getPeriod()); - assertEquals(limit, operationsAccumulateParams.getLimit()); - } - - @Test - public void testSetAndGetPeriod() { - String period = "15m"; - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); - operationsAccumulateParams.setPeriod(period); - assertEquals(period, operationsAccumulateParams.getPeriod()); - } - - @Test - public void testSetLimit() { - Integer limit = 10; - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); - operationsAccumulateParams.setLimit(limit); - assertEquals(limit, operationsAccumulateParams.getLimit()); } - - @Test - public void testToString() { - String period = "15m"; - Integer limit = 10; - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit); - assertEquals("OperationsAccumulateParams [period=15m, limit=10]", operationsAccumulateParams.toString()); - } - - @Test - public void testEqualsAndHashCode() { - String period = "15m"; - Integer limit = 10; - OperationsAccumulateParams operationsAccumulateParams1 = new OperationsAccumulateParams(); - OperationsAccumulateParams operationsAccumulateParams2 = new OperationsAccumulateParams(); - - assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2)); - - operationsAccumulateParams1.setPeriod(period); - assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2)); - operationsAccumulateParams2.setPeriod(period); - assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2)); - assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode()); - - operationsAccumulateParams1.setLimit(limit);; - assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2)); - operationsAccumulateParams2.setLimit(limit); - assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2)); - assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode()); - } - - - @Test - public void testEqualsSameObject(){ - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); - assertTrue(operationsAccumulateParams.equals(operationsAccumulateParams)); - } - - @Test - public void testEqualsNull(){ - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); - assertFalse(operationsAccumulateParams.equals(null)); - } - - @Test - public void testEqualsInstanceOfDiffClass(){ - OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); - assertFalse(operationsAccumulateParams.equals("")); - } + @Test + public void testConstructor() { + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); + assertNull(operationsAccumulateParams.getPeriod()); + assertNull(operationsAccumulateParams.getLimit()); + } + + @Test + public void testConstructorOperationsAccumulateParams() { + String period = "15m"; + Integer limit = 10; + OperationsAccumulateParams operationsAccumulateParams1 = + new OperationsAccumulateParams(period, limit); + OperationsAccumulateParams operationsAccumulateParams2 = + new OperationsAccumulateParams(operationsAccumulateParams1); + assertEquals(period, operationsAccumulateParams1.getPeriod()); + assertEquals(limit, operationsAccumulateParams2.getLimit()); + } + + @Test + public void testOperationsAccumulateParamsStringInteger() { + String period = "15m"; + Integer limit = 10; + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit); + assertEquals(period, operationsAccumulateParams.getPeriod()); + assertEquals(limit, operationsAccumulateParams.getLimit()); + } + + @Test + public void testSetAndGetPeriod() { + String period = "15m"; + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); + operationsAccumulateParams.setPeriod(period); + assertEquals(period, operationsAccumulateParams.getPeriod()); + } + + @Test + public void testSetLimit() { + Integer limit = 10; + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); + operationsAccumulateParams.setLimit(limit); + assertEquals(limit, operationsAccumulateParams.getLimit()); + } + + @Test + public void testToString() { + String period = "15m"; + Integer limit = 10; + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit); + assertEquals("OperationsAccumulateParams [period=15m, limit=10]", operationsAccumulateParams.toString()); + } + + @Test + public void testEqualsAndHashCode() { + String period = "15m"; + Integer limit = 10; + OperationsAccumulateParams operationsAccumulateParams1 = new OperationsAccumulateParams(); + OperationsAccumulateParams operationsAccumulateParams2 = new OperationsAccumulateParams(); + + assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2)); + + operationsAccumulateParams1.setPeriod(period); + assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2)); + operationsAccumulateParams2.setPeriod(period); + assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2)); + assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode()); + + operationsAccumulateParams1.setLimit(limit);; + assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2)); + operationsAccumulateParams2.setLimit(limit); + assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2)); + assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode()); + } + + + @Test + public void testEqualsSameObject() { + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); + assertTrue(operationsAccumulateParams.equals(operationsAccumulateParams)); + } + + @Test + public void testEqualsNull() { + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); + assertFalse(operationsAccumulateParams.equals(null)); + } + + @Test + public void testEqualsInstanceOfDiffClass() { + OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(); + assertFalse(operationsAccumulateParams.equals("")); + } } diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java index d0aa2e675..14e46b6bf 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java @@ -15,6 +15,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.controlloop.policy.guard; import static org.junit.Assert.*; @@ -28,222 +29,224 @@ import org.junit.Test; public class ConstraintTest { - @Test - public void testConstraint() { - Constraint constraint = new Constraint(); - - assertNull(constraint.getFreq_limit_per_target()); - assertNull(constraint.getTime_window()); - assertNull(constraint.getActive_time_range()); - assertNull(constraint.getBlacklist()); - } - - @Test - public void testGetAndSetFreq_limit_per_target() { - Integer freqLimitPerTarget = 10; - Constraint constraint = new Constraint(); - constraint.setFreq_limit_per_target(freqLimitPerTarget); - assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); - } - - @Test - public void testGetAndSetTime_window() { - Map timeWindow = new HashMap<>(); - timeWindow.put("timeWindowKey", "timeWindowValue"); - Constraint constraint = new Constraint(); - constraint.setTime_window(timeWindow); - assertEquals(timeWindow, constraint.getTime_window()); - } - - @Test - public void testGetAndSetActive_time_range() { - Map activeTimeRange = new HashMap<>(); - activeTimeRange.put("timeWindowKey", "timeWindowValue"); - Constraint constraint = new Constraint(); - constraint.setActive_time_range(activeTimeRange);; - assertEquals(activeTimeRange, constraint.getActive_time_range()); - } - - @Test - public void testGetAndSetBlacklist() { - List blacklist = new ArrayList<>(); - blacklist.add("blacklist item"); - Constraint constraint = new Constraint(); - constraint.setBlacklist(blacklist); - assertEquals(blacklist, constraint.getBlacklist()); - } - - @Test - public void testConstraintIntegerMapOfStringString() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - - Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow); - - assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); - assertEquals(timeWindow, constraint.getTime_window()); - assertNull(constraint.getActive_time_range()); - assertNull(constraint.getBlacklist()); - } - - @Test - public void testConstraintListOfString() { - List blacklist = new ArrayList<>(); - blacklist.add("blacklist item"); - Constraint constraint = new Constraint(blacklist); - - assertNull(constraint.getFreq_limit_per_target()); - assertNull(constraint.getTime_window()); - assertNull(constraint.getActive_time_range()); - assertEquals(blacklist, constraint.getBlacklist()); - } - - @Test - public void testConstraintIntegerMapOfStringStringListOfString() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - List blacklist = new ArrayList<>(); - blacklist.add("blacklist item"); - Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, blacklist); - - assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); - assertEquals(timeWindow, constraint.getTime_window()); - assertNull(constraint.getActive_time_range()); - assertEquals(blacklist, constraint.getBlacklist()); - } - - @Test - public void testConstraintIntegerMapOfStringStringMapOfStringString() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - Map activeTimeRange = new HashMap<>(); - activeTimeRange.put("timeWindowKey", "timeWindowValue"); - Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange); - - assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); - assertEquals(timeWindow, constraint.getTime_window()); - assertEquals(activeTimeRange, constraint.getActive_time_range()); - assertNull(constraint.getBlacklist()); - - } - - @Test - public void testConstraintIntegerMapOfStringStringMapOfStringStringListOfString() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - Map activeTimeRange = new HashMap<>(); - activeTimeRange.put("timeWindowKey", "timeWindowValue"); - List blacklist = new ArrayList<>(); - blacklist.add("blacklist item"); - Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist); - - assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); - assertEquals(timeWindow, constraint.getTime_window()); - assertEquals(activeTimeRange, constraint.getActive_time_range()); - assertEquals(blacklist, constraint.getBlacklist()); - } - - @Test - public void testConstraintConstraint() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - Map activeTimeRange = new HashMap<>(); - activeTimeRange.put("timeWindowKey", "timeWindowValue"); - List blacklist = new ArrayList<>(); - blacklist.add("blacklist item"); - Constraint constraint1 = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist); - Constraint constraint2 = new Constraint(constraint1); - - assertEquals(freqLimitPerTarget, constraint2.getFreq_limit_per_target()); - assertEquals(timeWindow, constraint2.getTime_window()); - assertEquals(activeTimeRange, constraint2.getActive_time_range()); - assertEquals(blacklist, constraint2.getBlacklist()); - } - - @Test - public void testIsValid() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - - Constraint constraint = new Constraint(); - assertTrue(constraint.isValid()); - - constraint.setFreq_limit_per_target(freqLimitPerTarget); - assertFalse(constraint.isValid()); - - constraint.setTime_window(timeWindow); - assertTrue(constraint.isValid()); - - constraint.setFreq_limit_per_target(null); - assertFalse(constraint.isValid()); - } - - @Test - public void testToString() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - Map activeTimeRange = new HashMap<>(); - activeTimeRange.put("timeWindowKey", "timeWindowValue"); - List blacklist = new ArrayList<>(); - blacklist.add("blacklist item"); - Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist); - - assertEquals(constraint.toString(), "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window=" + timeWindow + ", active_time_range=" + activeTimeRange + ", blacklist=" + blacklist + "]"); - } - - @Test - public void testEquals() { - Integer freqLimitPerTarget = 10; - Map timeWindow = new HashMap<>(); - Map activeTimeRange = new HashMap<>(); - List blacklist = new ArrayList<>(); - blacklist.add("blacklist item"); - - Constraint constraint1 = new Constraint(); - Constraint constraint2 = new Constraint(); - assertTrue(constraint1.equals(constraint2)); - - constraint1.setFreq_limit_per_target(freqLimitPerTarget); - assertFalse(constraint1.equals(constraint2)); - constraint2.setFreq_limit_per_target(freqLimitPerTarget); - assertTrue(constraint1.equals(constraint2)); - assertEquals(constraint1.hashCode(), constraint2.hashCode()); - - constraint1.setTime_window(timeWindow); - assertFalse(constraint1.equals(constraint2)); - constraint2.setTime_window(timeWindow); - assertTrue(constraint1.equals(constraint2)); - assertEquals(constraint1.hashCode(), constraint2.hashCode()); - - constraint1.setActive_time_range(activeTimeRange); - assertFalse(constraint1.equals(constraint2)); - constraint2.setActive_time_range(activeTimeRange); - assertTrue(constraint1.equals(constraint2)); - assertEquals(constraint1.hashCode(), constraint2.hashCode()); - - constraint1.setBlacklist(blacklist); - assertFalse(constraint1.equals(constraint2)); - constraint2.setBlacklist(blacklist); - assertTrue(constraint1.equals(constraint2)); - assertEquals(constraint1.hashCode(), constraint2.hashCode()); - } - - @Test - public void testEqualsSameObject(){ - Constraint constraint = new Constraint(); - assertTrue(constraint.equals(constraint)); - } - - @Test - public void testEqualsNull(){ - Constraint constraint = new Constraint(); - assertFalse(constraint.equals(null)); - } - - @Test - public void testEqualsInstanceOfDiffClass(){ - Constraint constraint = new Constraint(); - assertFalse(constraint.equals("")); - } + @Test + public void testConstraint() { + Constraint constraint = new Constraint(); + + assertNull(constraint.getFreq_limit_per_target()); + assertNull(constraint.getTime_window()); + assertNull(constraint.getActive_time_range()); + assertNull(constraint.getBlacklist()); + } + + @Test + public void testGetAndSetFreq_limit_per_target() { + Integer freqLimitPerTarget = 10; + Constraint constraint = new Constraint(); + constraint.setFreq_limit_per_target(freqLimitPerTarget); + assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); + } + + @Test + public void testGetAndSetTime_window() { + Map timeWindow = new HashMap<>(); + timeWindow.put("timeWindowKey", "timeWindowValue"); + Constraint constraint = new Constraint(); + constraint.setTime_window(timeWindow); + assertEquals(timeWindow, constraint.getTime_window()); + } + + @Test + public void testGetAndSetActive_time_range() { + Map activeTimeRange = new HashMap<>(); + activeTimeRange.put("timeWindowKey", "timeWindowValue"); + Constraint constraint = new Constraint(); + constraint.setActive_time_range(activeTimeRange);; + assertEquals(activeTimeRange, constraint.getActive_time_range()); + } + + @Test + public void testGetAndSetBlacklist() { + List blacklist = new ArrayList<>(); + blacklist.add("blacklist item"); + Constraint constraint = new Constraint(); + constraint.setBlacklist(blacklist); + assertEquals(blacklist, constraint.getBlacklist()); + } + + @Test + public void testConstraintIntegerMapOfStringString() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + + Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow); + + assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); + assertEquals(timeWindow, constraint.getTime_window()); + assertNull(constraint.getActive_time_range()); + assertNull(constraint.getBlacklist()); + } + + @Test + public void testConstraintListOfString() { + List blacklist = new ArrayList<>(); + blacklist.add("blacklist item"); + Constraint constraint = new Constraint(blacklist); + + assertNull(constraint.getFreq_limit_per_target()); + assertNull(constraint.getTime_window()); + assertNull(constraint.getActive_time_range()); + assertEquals(blacklist, constraint.getBlacklist()); + } + + @Test + public void testConstraintIntegerMapOfStringStringListOfString() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + List blacklist = new ArrayList<>(); + blacklist.add("blacklist item"); + Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, blacklist); + + assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); + assertEquals(timeWindow, constraint.getTime_window()); + assertNull(constraint.getActive_time_range()); + assertEquals(blacklist, constraint.getBlacklist()); + } + + @Test + public void testConstraintIntegerMapOfStringStringMapOfStringString() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + Map activeTimeRange = new HashMap<>(); + activeTimeRange.put("timeWindowKey", "timeWindowValue"); + Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange); + + assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); + assertEquals(timeWindow, constraint.getTime_window()); + assertEquals(activeTimeRange, constraint.getActive_time_range()); + assertNull(constraint.getBlacklist()); + + } + + @Test + public void testConstraintIntegerMapOfStringStringMapOfStringStringListOfString() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + Map activeTimeRange = new HashMap<>(); + activeTimeRange.put("timeWindowKey", "timeWindowValue"); + List blacklist = new ArrayList<>(); + blacklist.add("blacklist item"); + Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist); + + assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target()); + assertEquals(timeWindow, constraint.getTime_window()); + assertEquals(activeTimeRange, constraint.getActive_time_range()); + assertEquals(blacklist, constraint.getBlacklist()); + } + + @Test + public void testConstraintConstraint() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + Map activeTimeRange = new HashMap<>(); + activeTimeRange.put("timeWindowKey", "timeWindowValue"); + List blacklist = new ArrayList<>(); + blacklist.add("blacklist item"); + Constraint constraint1 = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist); + Constraint constraint2 = new Constraint(constraint1); + + assertEquals(freqLimitPerTarget, constraint2.getFreq_limit_per_target()); + assertEquals(timeWindow, constraint2.getTime_window()); + assertEquals(activeTimeRange, constraint2.getActive_time_range()); + assertEquals(blacklist, constraint2.getBlacklist()); + } + + @Test + public void testIsValid() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + + Constraint constraint = new Constraint(); + assertTrue(constraint.isValid()); + + constraint.setFreq_limit_per_target(freqLimitPerTarget); + assertFalse(constraint.isValid()); + + constraint.setTime_window(timeWindow); + assertTrue(constraint.isValid()); + + constraint.setFreq_limit_per_target(null); + assertFalse(constraint.isValid()); + } + + @Test + public void testToString() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + Map activeTimeRange = new HashMap<>(); + activeTimeRange.put("timeWindowKey", "timeWindowValue"); + List blacklist = new ArrayList<>(); + blacklist.add("blacklist item"); + Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist); + + assertEquals(constraint.toString(), "Constraint [freq_limit_per_target=" + freqLimitPerTarget + + ", time_window=" + timeWindow + ", active_time_range=" + activeTimeRange + + ", blacklist=" + blacklist + "]"); + } + + @Test + public void testEquals() { + Integer freqLimitPerTarget = 10; + Map timeWindow = new HashMap<>(); + Map activeTimeRange = new HashMap<>(); + List blacklist = new ArrayList<>(); + blacklist.add("blacklist item"); + + Constraint constraint1 = new Constraint(); + Constraint constraint2 = new Constraint(); + assertTrue(constraint1.equals(constraint2)); + + constraint1.setFreq_limit_per_target(freqLimitPerTarget); + assertFalse(constraint1.equals(constraint2)); + constraint2.setFreq_limit_per_target(freqLimitPerTarget); + assertTrue(constraint1.equals(constraint2)); + assertEquals(constraint1.hashCode(), constraint2.hashCode()); + + constraint1.setTime_window(timeWindow); + assertFalse(constraint1.equals(constraint2)); + constraint2.setTime_window(timeWindow); + assertTrue(constraint1.equals(constraint2)); + assertEquals(constraint1.hashCode(), constraint2.hashCode()); + + constraint1.setActive_time_range(activeTimeRange); + assertFalse(constraint1.equals(constraint2)); + constraint2.setActive_time_range(activeTimeRange); + assertTrue(constraint1.equals(constraint2)); + assertEquals(constraint1.hashCode(), constraint2.hashCode()); + + constraint1.setBlacklist(blacklist); + assertFalse(constraint1.equals(constraint2)); + constraint2.setBlacklist(blacklist); + assertTrue(constraint1.equals(constraint2)); + assertEquals(constraint1.hashCode(), constraint2.hashCode()); + } + + @Test + public void testEqualsSameObject() { + Constraint constraint = new Constraint(); + assertTrue(constraint.equals(constraint)); + } + + @Test + public void testEqualsNull() { + Constraint constraint = new Constraint(); + assertFalse(constraint.equals(null)); + } + + @Test + public void testEqualsInstanceOfDiffClass() { + Constraint constraint = new Constraint(); + assertFalse(constraint.equals("")); + } } diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java index 36cf34e5f..45e9c4202 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml unit test * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,8 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; public class ControlLoopGuardBuilderTest { - private static final Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderTest.class); + private static final Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderTest.class); + @Test public void testControlLoopGuard() { try { @@ -60,7 +61,8 @@ public class ControlLoopGuardBuilderTest { Results results = builder.buildSpecification(); boolean no_guard_policies = false; for (Message m : results.getMessages()) { - if (m.getMessage().equals("ControlLoop Guard should have at least one guard policies") && m.getLevel() == MessageLevel.ERROR) { + if (m.getMessage().equals("ControlLoop Guard should have at least one guard policies") + && m.getLevel() == MessageLevel.ERROR) { no_guard_policies = true; break; } @@ -83,7 +85,8 @@ public class ControlLoopGuardBuilderTest { results = builder.buildSpecification(); boolean no_constraint = false; for (Message m : results.getMessages()) { - if (m.getMessage().equals("Guard policy guardpolicy1 does not have any limit constraint") && m.getLevel() == MessageLevel.ERROR) { + if (m.getMessage().equals("Guard policy guardpolicy1 does not have any limit constraint") + && m.getLevel() == MessageLevel.ERROR) { no_constraint = true; break; } @@ -113,7 +116,8 @@ public class ControlLoopGuardBuilderTest { results = builder.buildSpecification(); boolean duplicate_constraint = false; for (Message m : results.getMessages()) { - if (m.getMessage().equals("Guard policy guardpolicy1 has duplicate limit constraints") && m.getLevel() == MessageLevel.WARNING) { + if (m.getMessage().equals("Guard policy guardpolicy1 has duplicate limit constraints") + && m.getLevel() == MessageLevel.WARNING) { duplicate_constraint = true; break; } @@ -134,7 +138,8 @@ public class ControlLoopGuardBuilderTest { results = builder.buildSpecification(); boolean duplicate_guard_policy = false; for (Message m : results.getMessages()) { - if (m.getMessage().equals("There are duplicate guard policies") && m.getLevel() == MessageLevel.WARNING) { + if (m.getMessage().equals("There are duplicate guard policies") + && m.getLevel() == MessageLevel.WARNING) { duplicate_guard_policy = true; break; } @@ -178,12 +183,14 @@ public class ControlLoopGuardBuilderTest { // // Now we're going to try to use the builder to build this. // - ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(guardTobuild.getGuard()); + ControlLoopGuardBuilder builder = + ControlLoopGuardBuilder.Factory.buildControlLoopGuard(guardTobuild.getGuard()); // // Add guard policy // if (guardTobuild.getGuards() != null) { - builder = builder.addGuardPolicy(guardTobuild.getGuards().toArray(new GuardPolicy[guardTobuild.getGuards().size()])); + builder = builder.addGuardPolicy(guardTobuild.getGuards().toArray( + new GuardPolicy[guardTobuild.getGuards().size()])); } // // Build the specification diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java index 711997dac..81c76c76a 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml unit test * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,121 +39,122 @@ import org.yaml.snakeyaml.constructor.Constructor; public class ControlLoopGuardTest { - private static final Logger logger = LoggerFactory.getLogger(ControlLoopGuardTest.class); - @Test - public void testGuardvDNS() { - this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml"); - } - - @Test - public void testGuardvUSP() { - this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml"); - } - - @Test - public void testConstructorControlLoopGuard(){ - Guard guard1 = new Guard(); - GuardPolicy guardPolicy1 = new GuardPolicy(); - GuardPolicy guardPolicy2 = new GuardPolicy(); - LinkedList guardPolicies = new LinkedList<>(); - guardPolicies.add(guardPolicy1); - guardPolicies.add(guardPolicy2); - - ControlLoopGuard controlLoopGuard1 = new ControlLoopGuard(); - controlLoopGuard1.setGuard(guard1); - controlLoopGuard1.setGuards(guardPolicies); - ControlLoopGuard controlLoopGuard2 = new ControlLoopGuard(controlLoopGuard1); - - assertEquals(guard1, controlLoopGuard2.getGuard()); - assertEquals(guardPolicies, controlLoopGuard2.getGuards()); - } - - @Test - public void testEqualsAndHashCode(){ - Guard guard1 = new Guard(); - GuardPolicy guardPolicy1 = new GuardPolicy(); - GuardPolicy guardPolicy2 = new GuardPolicy(); - LinkedList guardPolicies = new LinkedList<>(); - guardPolicies.add(guardPolicy1); - guardPolicies.add(guardPolicy2); - - ControlLoopGuard controlLoopGuard1 = new ControlLoopGuard(); - ControlLoopGuard controlLoopGuard2 = new ControlLoopGuard(); - - assertTrue(controlLoopGuard1.equals(controlLoopGuard2)); - assertEquals(controlLoopGuard1.hashCode(), controlLoopGuard2.hashCode()); - - controlLoopGuard1.setGuard(guard1); - assertFalse(controlLoopGuard1.equals(controlLoopGuard2)); - controlLoopGuard2.setGuard(guard1); - assertTrue(controlLoopGuard1.equals(controlLoopGuard2)); - assertEquals(controlLoopGuard1.hashCode(), controlLoopGuard2.hashCode()); - - controlLoopGuard1.setGuards(guardPolicies); - assertFalse(controlLoopGuard1.equals(controlLoopGuard2)); - controlLoopGuard2.setGuards(guardPolicies); - assertTrue(controlLoopGuard1.equals(controlLoopGuard2)); - assertEquals(controlLoopGuard1.hashCode(), controlLoopGuard2.hashCode()); - } - - @Test - public void testEqualsSameObject(){ - ControlLoopGuard controlLoopGuard = new ControlLoopGuard(); - assertTrue(controlLoopGuard.equals(controlLoopGuard)); - } - - @Test - public void testEqualsNull(){ - ControlLoopGuard controlLoopGuard = new ControlLoopGuard(); - assertFalse(controlLoopGuard.equals(null)); - } - - @Test - public void testEqualsInstanceOfDiffClass(){ - ControlLoopGuard controlLoopGuard = new ControlLoopGuard(); - assertFalse(controlLoopGuard.equals("")); - } - - public void test(String testFile) { - try (InputStream is = new FileInputStream(new File(testFile))) { - // - // Read the yaml into our Java Object - // - Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class)); - Object obj = yaml.load(is); - assertNotNull(obj); - assertTrue(obj instanceof ControlLoopGuard); - dump(obj); - // - // Now dump it to a yaml string - // - DumperOptions options = new DumperOptions(); - options.setDefaultFlowStyle(FlowStyle.BLOCK); - options.setPrettyFlow(true); - yaml = new Yaml(options); - String dumpedYaml = yaml.dump(obj); - logger.debug(dumpedYaml); - // - // Read that string back into our java object - // - Object newObject = yaml.load(dumpedYaml); - dump(newObject); - assertNotNull(newObject); - assertTrue(newObject instanceof ControlLoopGuard); - // - // Have to comment it out tentatively since it causes junit to fail. - // Seems we cannot use assertEquals here. Need advice. - // - //assertEquals(newObject, obj); - } catch (FileNotFoundException e) { - fail(e.getLocalizedMessage()); - } catch (IOException e) { - fail(e.getLocalizedMessage()); - } - } - - public void dump(Object obj) { - logger.debug("Dumping {}", obj.getClass().getCanonicalName()); - logger.debug("{}", obj); - } + private static final Logger logger = LoggerFactory.getLogger(ControlLoopGuardTest.class); + + @Test + public void testGuardvDNS() { + this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml"); + } + + @Test + public void testGuardvUSP() { + this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml"); + } + + @Test + public void testConstructorControlLoopGuard(){ + Guard guard1 = new Guard(); + GuardPolicy guardPolicy1 = new GuardPolicy(); + GuardPolicy guardPolicy2 = new GuardPolicy(); + LinkedList guardPolicies = new LinkedList<>(); + guardPolicies.add(guardPolicy1); + guardPolicies.add(guardPolicy2); + + ControlLoopGuard controlLoopGuard1 = new ControlLoopGuard(); + controlLoopGuard1.setGuard(guard1); + controlLoopGuard1.setGuards(guardPolicies); + ControlLoopGuard controlLoopGuard2 = new ControlLoopGuard(controlLoopGuard1); + + assertEquals(guard1, controlLoopGuard2.getGuard()); + assertEquals(guardPolicies, controlLoopGuard2.getGuards()); + } + + @Test + public void testEqualsAndHashCode() { + Guard guard1 = new Guard(); + GuardPolicy guardPolicy1 = new GuardPolicy(); + GuardPolicy guardPolicy2 = new GuardPolicy(); + LinkedList guardPolicies = new LinkedList<>(); + guardPolicies.add(guardPolicy1); + guardPolicies.add(guardPolicy2); + + ControlLoopGuard controlLoopGuard1 = new ControlLoopGuard(); + ControlLoopGuard controlLoopGuard2 = new ControlLoopGuard(); + + assertTrue(controlLoopGuard1.equals(controlLoopGuard2)); + assertEquals(controlLoopGuard1.hashCode(), controlLoopGuard2.hashCode()); + + controlLoopGuard1.setGuard(guard1); + assertFalse(controlLoopGuard1.equals(controlLoopGuard2)); + controlLoopGuard2.setGuard(guard1); + assertTrue(controlLoopGuard1.equals(controlLoopGuard2)); + assertEquals(controlLoopGuard1.hashCode(), controlLoopGuard2.hashCode()); + + controlLoopGuard1.setGuards(guardPolicies); + assertFalse(controlLoopGuard1.equals(controlLoopGuard2)); + controlLoopGuard2.setGuards(guardPolicies); + assertTrue(controlLoopGuard1.equals(controlLoopGuard2)); + assertEquals(controlLoopGuard1.hashCode(), controlLoopGuard2.hashCode()); + } + + @Test + public void testEqualsSameObject() { + ControlLoopGuard controlLoopGuard = new ControlLoopGuard(); + assertTrue(controlLoopGuard.equals(controlLoopGuard)); + } + + @Test + public void testEqualsNull() { + ControlLoopGuard controlLoopGuard = new ControlLoopGuard(); + assertFalse(controlLoopGuard.equals(null)); + } + + @Test + public void testEqualsInstanceOfDiffClass() { + ControlLoopGuard controlLoopGuard = new ControlLoopGuard(); + assertFalse(controlLoopGuard.equals("")); + } + + public void test(String testFile) { + try (InputStream is = new FileInputStream(new File(testFile))) { + // + // Read the yaml into our Java Object + // + Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class)); + Object obj = yaml.load(is); + assertNotNull(obj); + assertTrue(obj instanceof ControlLoopGuard); + dump(obj); + // + // Now dump it to a yaml string + // + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(FlowStyle.BLOCK); + options.setPrettyFlow(true); + yaml = new Yaml(options); + String dumpedYaml = yaml.dump(obj); + logger.debug(dumpedYaml); + // + // Read that string back into our java object + // + Object newObject = yaml.load(dumpedYaml); + dump(newObject); + assertNotNull(newObject); + assertTrue(newObject instanceof ControlLoopGuard); + // + // Have to comment it out tentatively since it causes junit to fail. + // Seems we cannot use assertEquals here. Need advice. + // + //assertEquals(newObject, obj); + } catch (FileNotFoundException e) { + fail(e.getLocalizedMessage()); + } catch (IOException e) { + fail(e.getLocalizedMessage()); + } + } + + public void dump(Object obj) { + logger.debug("Dumping {}", obj.getClass().getCanonicalName()); + logger.debug("{}", obj); + } } diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java index 3bf801d57..d80fecf2b 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java @@ -15,6 +15,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.controlloop.policy.guard; import static org.junit.Assert.assertEquals; @@ -29,239 +30,241 @@ import java.util.List; import org.junit.Test; public class GuardPolicyTest { - - @Test - public void testConstructor(){ - GuardPolicy guardPolicy = new GuardPolicy(); - - assertNotNull(guardPolicy.getId()); - assertNull(guardPolicy.getName()); - assertNull(guardPolicy.getDescription()); - assertNull(guardPolicy.getMatch_parameters()); - assertNull(guardPolicy.getLimit_constraints()); - } - - @Test - public void testConstructorString(){ - String id = "guard id"; - GuardPolicy guardPolicy = new GuardPolicy(id); - - assertEquals(id, guardPolicy.getId()); - assertNull(guardPolicy.getName()); - assertNull(guardPolicy.getDescription()); - assertNull(guardPolicy.getMatch_parameters()); - assertNull(guardPolicy.getLimit_constraints()); - } - - @Test - public void testConstructorStringStringStringMatchParameters(){ - String id = "guard id"; - String name = "guard name"; - String description = "guard description"; - MatchParameters matchParameters = new MatchParameters(); - List limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - GuardPolicy guardPolicy = new GuardPolicy(id, name, description, matchParameters); - - assertNotNull(guardPolicy.getId()); - assertEquals(name, guardPolicy.getName()); - assertEquals(description, guardPolicy.getDescription()); - assertEquals(matchParameters, guardPolicy.getMatch_parameters()); - assertNull(guardPolicy.getLimit_constraints()); - } - - @Test - public void testConstructorStringMatchParametersList(){ - String name = "guard name"; - MatchParameters matchParameters = new MatchParameters(); - List limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - GuardPolicy guardPolicy = new GuardPolicy(name, matchParameters, limitConstraints); - - assertNotNull(guardPolicy.getId()); - assertEquals(name, guardPolicy.getName()); - assertNull(guardPolicy.getDescription()); - assertEquals(matchParameters, guardPolicy.getMatch_parameters()); - assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); - } - - @Test - public void testConstructorStringStringMatchParametersList(){ - String name = "guard name"; - String description = "guard description"; - MatchParameters matchParameters = new MatchParameters(); - List limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - GuardPolicy guardPolicy = new GuardPolicy(name, description, matchParameters, limitConstraints); - - assertNotNull(guardPolicy.getId()); - assertEquals(name, guardPolicy.getName()); - assertEquals(description, guardPolicy.getDescription()); - assertEquals(matchParameters, guardPolicy.getMatch_parameters()); - assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); - } - - @Test - public void testConstructorStringStringStringMatchParametersList(){ - String id = "guard id"; - String name = "guard name"; - String description = "guard description"; - MatchParameters matchParameters = new MatchParameters(); - List limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - GuardPolicy guardPolicy = new GuardPolicy(id, name, description, matchParameters, limitConstraints); - - assertEquals(id, guardPolicy.getId()); - assertEquals(name, guardPolicy.getName()); - assertEquals(description, guardPolicy.getDescription()); - assertEquals(matchParameters, guardPolicy.getMatch_parameters()); - assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); - } - - @Test - public void testConstructorGuardPolicy(){ - String id = "guard id"; - String name = "guard name"; - String description = "guard description"; - MatchParameters matchParameters = new MatchParameters(); - List limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - GuardPolicy guardPolicy1 = new GuardPolicy(id, name, description, matchParameters, limitConstraints); - - GuardPolicy guardPolicy2 = new GuardPolicy(guardPolicy1); - - - assertEquals(id, guardPolicy2.getId()); - assertEquals(name, guardPolicy2.getName()); - assertEquals(description, guardPolicy2.getDescription()); - assertEquals(matchParameters, guardPolicy2.getMatch_parameters()); - assertEquals(limitConstraints, guardPolicy2.getLimit_constraints()); - } - - @Test - public void testSetAndGetId(){ - String id = "guard id"; - GuardPolicy guardPolicy = new GuardPolicy(); - guardPolicy.setId(id); - assertEquals(id, guardPolicy.getId()); - } - - @Test - public void testSetAndGetName(){ - String name = "guard name"; - GuardPolicy guardPolicy = new GuardPolicy(); - guardPolicy.setName(name); - assertEquals(name, guardPolicy.getName()); - } - - @Test - public void testSetAndGetDescription(){ - String description = "guard description"; - GuardPolicy guardPolicy = new GuardPolicy(); - guardPolicy.setDescription(description); - assertEquals(description, guardPolicy.getDescription()); - } - - @Test - public void testSetAndGetMatchParameters(){ - MatchParameters matchParameters = new MatchParameters(); - GuardPolicy guardPolicy = new GuardPolicy(); - guardPolicy.setMatch_parameters(matchParameters); - assertEquals(matchParameters, guardPolicy.getMatch_parameters()); - } - - @Test - public void testSetAndGetLimitConstraints(){ - LinkedList limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - GuardPolicy guardPolicy = new GuardPolicy(); - guardPolicy.setLimit_constraints(limitConstraints); - assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); - } - - @Test - public void testIsValid(){ - GuardPolicy guardPolicy = new GuardPolicy(); - assertFalse(guardPolicy.isValid()); - - guardPolicy.setName("guard name"); - assertTrue(guardPolicy.isValid()); - - guardPolicy.setId(null); - assertFalse(guardPolicy.isValid()); - } - - @Test - public void testToString(){ - String id = "guard id"; - String name = "guard name"; - String description = "guard description"; - MatchParameters matchParameters = new MatchParameters(); - List limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - GuardPolicy guardPolicy = new GuardPolicy(id, name, description, matchParameters, limitConstraints); - - assertEquals(guardPolicy.toString(), "Policy [id=guard id, name=guard name, description=guard description, " - + "match_parameters=MatchParameters [controlLoopName=null, actor=null, recipe=null, targets=null], " - + "limitConstraints=[Constraint [freq_limit_per_target=null, time_window=null, active_time_range=null, blacklist=null]]]", guardPolicy.toString()); - } - - @Test - public void testEquals(){ - String id = "guard id"; - String name = "guard name"; - String description = "guard description"; - GuardPolicy guardPolicy1 = new GuardPolicy(id); - GuardPolicy guardPolicy2 = new GuardPolicy(); - assertFalse(guardPolicy1.equals(guardPolicy2)); - - guardPolicy2.setId(id); - assertTrue(guardPolicy1.equals(guardPolicy2)); - assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); - - guardPolicy1.setName(name); - assertFalse(guardPolicy1.equals(guardPolicy2)); - guardPolicy2.setName(name); - assertTrue(guardPolicy1.equals(guardPolicy2)); - assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); - - guardPolicy1.setDescription(description); - assertFalse(guardPolicy1.equals(guardPolicy2)); - guardPolicy2.setDescription(description); - assertTrue(guardPolicy1.equals(guardPolicy2)); - assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); - - MatchParameters matchParameters = new MatchParameters(); - guardPolicy1.setMatch_parameters(matchParameters); - assertFalse(guardPolicy1.equals(guardPolicy2)); - guardPolicy2.setMatch_parameters(matchParameters); - assertTrue(guardPolicy1.equals(guardPolicy2)); - assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); - - LinkedList limitConstraints = new LinkedList<>(); - limitConstraints.add(new Constraint()); - guardPolicy1.setLimit_constraints(limitConstraints); - assertFalse(guardPolicy1.equals(guardPolicy2)); - guardPolicy2.setLimit_constraints(limitConstraints); - assertTrue(guardPolicy1.equals(guardPolicy2)); - assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); - } - - @Test - public void testEqualsSameObject(){ - GuardPolicy guardPolicy = new GuardPolicy(); - assertTrue(guardPolicy.equals(guardPolicy)); - } - - @Test - public void testEqualsNull(){ - GuardPolicy guardPolicy = new GuardPolicy(); - assertFalse(guardPolicy.equals(null)); - } - - @Test - public void testEqualsInstanceOfDiffClass(){ - GuardPolicy guardPolicy = new GuardPolicy(); - assertFalse(guardPolicy.equals("")); - } + + @Test + public void testConstructor() { + GuardPolicy guardPolicy = new GuardPolicy(); + + assertNotNull(guardPolicy.getId()); + assertNull(guardPolicy.getName()); + assertNull(guardPolicy.getDescription()); + assertNull(guardPolicy.getMatch_parameters()); + assertNull(guardPolicy.getLimit_constraints()); + } + + @Test + public void testConstructorString() { + String id = "guard id"; + GuardPolicy guardPolicy = new GuardPolicy(id); + + assertEquals(id, guardPolicy.getId()); + assertNull(guardPolicy.getName()); + assertNull(guardPolicy.getDescription()); + assertNull(guardPolicy.getMatch_parameters()); + assertNull(guardPolicy.getLimit_constraints()); + } + + @Test + public void testConstructorStringStringStringMatchParameters() { + String id = "guard id"; + String name = "guard name"; + String description = "guard description"; + MatchParameters matchParameters = new MatchParameters(); + List limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + GuardPolicy guardPolicy = new GuardPolicy(id, name, description, matchParameters); + + assertNotNull(guardPolicy.getId()); + assertEquals(name, guardPolicy.getName()); + assertEquals(description, guardPolicy.getDescription()); + assertEquals(matchParameters, guardPolicy.getMatch_parameters()); + assertNull(guardPolicy.getLimit_constraints()); + } + + @Test + public void testConstructorStringMatchParametersList() { + String name = "guard name"; + MatchParameters matchParameters = new MatchParameters(); + List limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + GuardPolicy guardPolicy = new GuardPolicy(name, matchParameters, limitConstraints); + + assertNotNull(guardPolicy.getId()); + assertEquals(name, guardPolicy.getName()); + assertNull(guardPolicy.getDescription()); + assertEquals(matchParameters, guardPolicy.getMatch_parameters()); + assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); + } + + @Test + public void testConstructorStringStringMatchParametersList() { + String name = "guard name"; + String description = "guard description"; + MatchParameters matchParameters = new MatchParameters(); + List limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + GuardPolicy guardPolicy = new GuardPolicy(name, description, matchParameters, limitConstraints); + + assertNotNull(guardPolicy.getId()); + assertEquals(name, guardPolicy.getName()); + assertEquals(description, guardPolicy.getDescription()); + assertEquals(matchParameters, guardPolicy.getMatch_parameters()); + assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); + } + + @Test + public void testConstructorStringStringStringMatchParametersList() { + String id = "guard id"; + String name = "guard name"; + String description = "guard description"; + MatchParameters matchParameters = new MatchParameters(); + List limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + GuardPolicy guardPolicy = new GuardPolicy(id, name, description, matchParameters, limitConstraints); + + assertEquals(id, guardPolicy.getId()); + assertEquals(name, guardPolicy.getName()); + assertEquals(description, guardPolicy.getDescription()); + assertEquals(matchParameters, guardPolicy.getMatch_parameters()); + assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); + } + + @Test + public void testConstructorGuardPolicy() { + String id = "guard id"; + String name = "guard name"; + String description = "guard description"; + MatchParameters matchParameters = new MatchParameters(); + List limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + GuardPolicy guardPolicy1 = new GuardPolicy(id, name, description, matchParameters, limitConstraints); + + GuardPolicy guardPolicy2 = new GuardPolicy(guardPolicy1); + + + assertEquals(id, guardPolicy2.getId()); + assertEquals(name, guardPolicy2.getName()); + assertEquals(description, guardPolicy2.getDescription()); + assertEquals(matchParameters, guardPolicy2.getMatch_parameters()); + assertEquals(limitConstraints, guardPolicy2.getLimit_constraints()); + } + + @Test + public void testSetAndGetId() { + String id = "guard id"; + GuardPolicy guardPolicy = new GuardPolicy(); + guardPolicy.setId(id); + assertEquals(id, guardPolicy.getId()); + } + + @Test + public void testSetAndGetName() { + String name = "guard name"; + GuardPolicy guardPolicy = new GuardPolicy(); + guardPolicy.setName(name); + assertEquals(name, guardPolicy.getName()); + } + + @Test + public void testSetAndGetDescription() { + String description = "guard description"; + GuardPolicy guardPolicy = new GuardPolicy(); + guardPolicy.setDescription(description); + assertEquals(description, guardPolicy.getDescription()); + } + + @Test + public void testSetAndGetMatchParameters() { + MatchParameters matchParameters = new MatchParameters(); + GuardPolicy guardPolicy = new GuardPolicy(); + guardPolicy.setMatch_parameters(matchParameters); + assertEquals(matchParameters, guardPolicy.getMatch_parameters()); + } + + @Test + public void testSetAndGetLimitConstraints() { + LinkedList limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + GuardPolicy guardPolicy = new GuardPolicy(); + guardPolicy.setLimit_constraints(limitConstraints); + assertEquals(limitConstraints, guardPolicy.getLimit_constraints()); + } + + @Test + public void testIsValid() { + GuardPolicy guardPolicy = new GuardPolicy(); + assertFalse(guardPolicy.isValid()); + + guardPolicy.setName("guard name"); + assertTrue(guardPolicy.isValid()); + + guardPolicy.setId(null); + assertFalse(guardPolicy.isValid()); + } + + @Test + public void testToString() { + String id = "guard id"; + String name = "guard name"; + String description = "guard description"; + MatchParameters matchParameters = new MatchParameters(); + List limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + GuardPolicy guardPolicy = new GuardPolicy(id, name, description, matchParameters, limitConstraints); + + assertEquals(guardPolicy.toString(), "Policy [id=guard id, name=guard name, description=guard description, " + + "match_parameters=MatchParameters [controlLoopName=null, actor=null, recipe=null, targets=null], " + + "limitConstraints=[Constraint [freq_limit_per_target=null, time_window=null, active_time_range=null," + + " blacklist=null]]]", + guardPolicy.toString()); + } + + @Test + public void testEquals() { + String id = "guard id"; + String name = "guard name"; + String description = "guard description"; + GuardPolicy guardPolicy1 = new GuardPolicy(id); + GuardPolicy guardPolicy2 = new GuardPolicy(); + assertFalse(guardPolicy1.equals(guardPolicy2)); + + guardPolicy2.setId(id); + assertTrue(guardPolicy1.equals(guardPolicy2)); + assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); + + guardPolicy1.setName(name); + assertFalse(guardPolicy1.equals(guardPolicy2)); + guardPolicy2.setName(name); + assertTrue(guardPolicy1.equals(guardPolicy2)); + assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); + + guardPolicy1.setDescription(description); + assertFalse(guardPolicy1.equals(guardPolicy2)); + guardPolicy2.setDescription(description); + assertTrue(guardPolicy1.equals(guardPolicy2)); + assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); + + MatchParameters matchParameters = new MatchParameters(); + guardPolicy1.setMatch_parameters(matchParameters); + assertFalse(guardPolicy1.equals(guardPolicy2)); + guardPolicy2.setMatch_parameters(matchParameters); + assertTrue(guardPolicy1.equals(guardPolicy2)); + assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); + + LinkedList limitConstraints = new LinkedList<>(); + limitConstraints.add(new Constraint()); + guardPolicy1.setLimit_constraints(limitConstraints); + assertFalse(guardPolicy1.equals(guardPolicy2)); + guardPolicy2.setLimit_constraints(limitConstraints); + assertTrue(guardPolicy1.equals(guardPolicy2)); + assertEquals(guardPolicy1.hashCode(), guardPolicy2.hashCode()); + } + + @Test + public void testEqualsSameObject() { + GuardPolicy guardPolicy = new GuardPolicy(); + assertTrue(guardPolicy.equals(guardPolicy)); + } + + @Test + public void testEqualsNull() { + GuardPolicy guardPolicy = new GuardPolicy(); + assertFalse(guardPolicy.equals(null)); + } + + @Test + public void testEqualsInstanceOfDiffClass() { + GuardPolicy guardPolicy = new GuardPolicy(); + assertFalse(guardPolicy.equals("")); + } } -- cgit 1.2.3-korg