aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java76
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java405
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java9
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopLoggerTest.java15
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopPublisherTest.java25
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java23
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java573
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java658
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java40
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java4
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java22
-rw-r--r--controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml14
12 files changed, 838 insertions, 1026 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index b82a5f8e5..57df6b3f4 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -24,13 +24,19 @@ import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Set;
import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.aai.AaiGetVnfResponse;
import org.onap.policy.aai.AaiGetVserverResponse;
@@ -90,6 +96,16 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager.class);
private static final long serialVersionUID = -1216568161322872641L;
+
+ private static final Set<String> VALID_TARGETS;
+
+ static {
+ VALID_TARGETS = Collections.unmodifiableSet(new HashSet<>(
+ Arrays.asList(VM_NAME, VNF_NAME, VSERVER_VSERVER_NAME,
+ GENERIC_VNF_VNF_ID, GENERIC_VNF_VNF_NAME)
+ .stream().map(String::toLowerCase).collect(Collectors.toList())));
+ }
+
public final String closedLoopControlName;
private final UUID requestId;
@@ -308,18 +324,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
* @throws ControlLoopException if an error occurs
*/
public VirtualControlLoopNotification isControlLoopFinal() throws ControlLoopException {
- //
- // Check if they activated us
- //
- if (!this.isActivated) {
- throw new ControlLoopException("ControlLoopEventManager MUST be activated first.");
- }
- //
- // Make sure we are expecting this call.
- //
- if (this.onset == null) {
- throw new ControlLoopException("No onset event for ControlLoopEventManager.");
- }
+ validateFinalControlLoop();
//
// Ok, start creating the notification
//
@@ -374,14 +379,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return notification;
}
- /**
- * Process the control loop.
- *
- * @return a ControlLoopOperationManager
- * @throws ControlLoopException if an error occurs
- * @throws AaiException if an error occurs retrieving information from A&AI
- */
- public ControlLoopOperationManager processControlLoop() throws ControlLoopException, AaiException {
+ private void validateFinalControlLoop() throws ControlLoopException {
//
// Check if they activated us
//
@@ -394,6 +392,17 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (this.onset == null) {
throw new ControlLoopException("No onset event for ControlLoopEventManager.");
}
+ }
+
+ /**
+ * Process the control loop.
+ *
+ * @return a ControlLoopOperationManager
+ * @throws ControlLoopException if an error occurs
+ * @throws AaiException if an error occurs retrieving information from A&AI
+ */
+ public ControlLoopOperationManager processControlLoop() throws ControlLoopException, AaiException {
+ validateFinalControlLoop();
//
// Is there a current operation?
//
@@ -692,12 +701,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
* @throws ControlLoopException if an error occurs
*/
public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
- if (event.getClosedLoopEventStatus() == null
- || (event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET
- && event.getClosedLoopEventStatus() != ControlLoopEventStatus.ABATED)) {
- throw new ControlLoopException("Invalid value in closedLoopEventStatus");
- }
- if (event.getClosedLoopControlName() == null || event.getClosedLoopControlName().length() < 1) {
+ validateStatus(event);
+ if (StringUtils.isBlank(event.getClosedLoopControlName())) {
throw new ControlLoopException("No control loop name");
}
if (event.getRequestId() == null) {
@@ -706,14 +711,23 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) {
return;
}
- if (event.getTarget() == null || event.getTarget().length() < 1) {
+ if (StringUtils.isBlank(event.getTarget())) {
throw new ControlLoopException("No target field");
- } else if (!VM_NAME.equalsIgnoreCase(event.getTarget()) && !VNF_NAME.equalsIgnoreCase(event.getTarget())
- && !VSERVER_VSERVER_NAME.equalsIgnoreCase(event.getTarget())
- && !GENERIC_VNF_VNF_ID.equalsIgnoreCase(event.getTarget())
- && !GENERIC_VNF_VNF_NAME.equalsIgnoreCase(event.getTarget())) {
+ } else if (!VALID_TARGETS.contains(event.getTarget().toLowerCase())) {
throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
}
+ validateAaiData(event);
+ }
+
+ private void validateStatus(VirtualControlLoopEvent event) throws ControlLoopException {
+ if (event.getClosedLoopEventStatus() == null
+ || (event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET
+ && event.getClosedLoopEventStatus() != ControlLoopEventStatus.ABATED)) {
+ throw new ControlLoopException("Invalid value in closedLoopEventStatus");
+ }
+ }
+
+ private void validateAaiData(VirtualControlLoopEvent event) throws ControlLoopException {
if (event.getAai() == null) {
throw new ControlLoopException("AAI is null");
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index 3ff5c260e..006899efe 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -62,6 +62,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ControlLoopOperationManager implements Serializable {
+ private static final String SUCCESS_MSG = " Success";
+ private static final String FAILED_MSG = " Failed";
+ private static final String AAI_CUSTOM_QUERY = "aai.customQuery";
private static final long serialVersionUID = -3773199283624595410L;
private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManager.class);
@@ -110,28 +113,7 @@ public class ControlLoopOperationManager implements Serializable {
//
switch (policy.getActor()) {
case "APPC":
- if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
- /*
- * The target vnf-id may not be the same as the source vnf-id specified in the yaml, the target
- * vnf-id is retrieved by a named query to A&AI.
- */
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- GenericVnf genvnf = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset)
- .getGenericVnfByModelInvariantId(policy.getTarget().getResourceID());
- if (genvnf == null) {
- logger.info("Target entity could not be found");
- throw new AaiException("Target vnf-id could not be found");
- }
- this.targetEntity = genvnf.getVnfId();
-
- } else {
- this.targetEntity =
- AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(),
- this.targetEntity, PolicyEngine.manager.getEnvironmentProperty("aai.url"),
- PolicyEngine.manager.getEnvironmentProperty("aai.username"),
- PolicyEngine.manager.getEnvironmentProperty("aai.password"));
- }
- }
+ initAppc(onset, policy);
break;
case "SO":
break;
@@ -147,6 +129,32 @@ public class ControlLoopOperationManager implements Serializable {
}
+ private void initAppc(ControlLoopEvent onset, Policy policy) throws AaiException {
+ if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
+ /*
+ * The target vnf-id may not be the same as the source vnf-id specified in the yaml, the target
+ * vnf-id is retrieved by a named query to A&AI.
+ */
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ GenericVnf genvnf = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset)
+ .getGenericVnfByModelInvariantId(policy.getTarget().getResourceID());
+ if (genvnf == null) {
+ logger.info("Target entity could not be found");
+ throw new AaiException("Target vnf-id could not be found");
+ }
+ this.targetEntity = genvnf.getVnfId();
+
+ } else {
+ this.targetEntity =
+ AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(),
+ this.targetEntity, PolicyEngine.manager.getEnvironmentProperty("aai.url"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.username"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.password"));
+ }
+ }
+ }
+
+
public ControlLoopEventManager getEventManager() {
return eventManager;
}
@@ -218,72 +226,48 @@ public class ControlLoopOperationManager implements Serializable {
throw new ControlLoopException("PNF target is not supported");
case VM:
case VNF:
- VirtualControlLoopEvent virtualOnset = (VirtualControlLoopEvent) this.onset;
- if (this.onset.getTarget().equalsIgnoreCase(VSERVER_VSERVER_NAME)) {
- return virtualOnset.getAai().get(VSERVER_VSERVER_NAME);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_ID)) {
- return virtualOnset.getAai().get(GENERIC_VNF_VNF_ID);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_NAME)) {
- /*
- * If the onset is enriched with the vnf-id, we don't need an A&AI response
- */
- if (virtualOnset.getAai().containsKey(GENERIC_VNF_VNF_ID)) {
- return virtualOnset.getAai().get(GENERIC_VNF_VNF_ID);
- }
-
- /*
- * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event
- * manager's A&AI GET query
- */
- String vnfId;
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf()
- .getVnfId();
- } else {
- vnfId = this.eventManager.getVnfResponse().getVnfId();
- }
- if (vnfId == null) {
- throw new AaiException("No vnf-id found");
- }
- return vnfId;
- }
- throw new ControlLoopException("Target does not match target type");
+ return getVfModuleTarget();
case VFMODULE:
- VirtualControlLoopEvent virtualOnsetEvent = (VirtualControlLoopEvent) this.onset;
- if (this.onset.getTarget().equalsIgnoreCase(VSERVER_VSERVER_NAME)) {
- return virtualOnsetEvent.getAai().get(VSERVER_VSERVER_NAME);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_ID)) {
- return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_NAME)) {
- /*
- * If the onset is enriched with the vnf-id, we don't need an A&AI response
- */
- if (virtualOnsetEvent.getAai().containsKey(GENERIC_VNF_VNF_ID)) {
- return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
- }
-
- /*
- * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event
- * manager's A&AI GET query
- */
- String vnfId;
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf()
- .getVnfId();
- } else {
- vnfId = this.eventManager.getVnfResponse().getVnfId();
- }
- if (vnfId == null) {
- throw new AaiException("No vnf-id found");
- }
- return vnfId;
- }
- throw new ControlLoopException("Target does not match target type");
+ return getVfModuleTarget();
default:
throw new ControlLoopException("The target type is not supported");
}
}
+
+ private String getVfModuleTarget() throws AaiException, ControlLoopException {
+ VirtualControlLoopEvent virtualOnsetEvent = (VirtualControlLoopEvent) this.onset;
+ if (this.onset.getTarget().equalsIgnoreCase(VSERVER_VSERVER_NAME)) {
+ return virtualOnsetEvent.getAai().get(VSERVER_VSERVER_NAME);
+ } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_ID)) {
+ return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
+ } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_NAME)) {
+ /*
+ * If the onset is enriched with the vnf-id, we don't need an A&AI response
+ */
+ if (virtualOnsetEvent.getAai().containsKey(GENERIC_VNF_VNF_ID)) {
+ return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
+ }
+
+ /*
+ * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event
+ * manager's A&AI GET query
+ */
+ String vnfId;
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf()
+ .getVnfId();
+ } else {
+ vnfId = this.eventManager.getVnfResponse().getVnfId();
+ }
+ if (vnfId == null) {
+ throw new AaiException("No vnf-id found");
+ }
+ return vnfId;
+ }
+ throw new ControlLoopException("Target does not match target type");
+ }
+
/**
* Start an operation.
*
@@ -311,88 +295,113 @@ public class ControlLoopOperationManager implements Serializable {
//
switch (policy.getActor()) {
case "APPC":
- /*
- * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an LCMRequest is
- * constructed.
- */
- this.currentOperation = operation;
- if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
- this.operationRequest = AppcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy, this.targetEntity);
- } else {
- this.operationRequest = AppcLcmActorServiceProvider.constructRequest(
- (VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.targetEntity);
- }
- //
- // Save the operation
- //
-
- return operationRequest;
+ return startAppcOperation(onset, operation);
case "SO":
- SoActorServiceProvider soActorSp = new SoActorServiceProvider();
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- this.operationRequest =
- soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, operation.clOperation,
- this.policy, eventManager.getCqResponse((VirtualControlLoopEvent) onset));
- } else {
- this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy, eventManager.getNqVserverFromAai());
- }
-
- // Save the operation
- this.currentOperation = operation;
-
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
-
- return operationRequest;
+ return startSoOperation(onset, operation);
case "VFC":
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- this.operationRequest = VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy,
- eventManager.getCqResponse((VirtualControlLoopEvent) onset));
- } else {
- this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy, this.eventManager.getVnfResponse(),
- PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
- }
- this.currentOperation = operation;
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
- return operationRequest;
+ return startVfcOperation(onset, operation);
case "SDNR":
- /*
- * If the recipe is ModifyConfig or ModifyConfigANR, a SDNR request is constructed.
- */
- this.currentOperation = operation;
- this.operationRequest = SdnrActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy);
- //
- // Save the operation
- //
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
-
- return operationRequest;
+ return startSdnrOperation(onset, operation);
case "SDNC":
- SdncActorServiceProvider provider = new SdncActorServiceProvider();
- this.operationRequest =
- provider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy);
- this.currentOperation = operation;
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
- return operationRequest;
+ return startSdncOperation(onset, operation);
default:
throw new ControlLoopException("invalid actor " + policy.getActor() + " on policy");
}
}
+
+ private Object startAppcOperation(ControlLoopEvent onset, Operation operation) {
+ /*
+ * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an LCMRequest is
+ * constructed.
+ */
+ this.currentOperation = operation;
+ if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
+ this.operationRequest = AppcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy, this.targetEntity);
+ } else {
+ this.operationRequest = AppcLcmActorServiceProvider.constructRequest(
+ (VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.targetEntity);
+ }
+ //
+ // Save the operation
+ //
+
+ return operationRequest;
+ }
+
+
+ private Object startSoOperation(ControlLoopEvent onset, Operation operation) throws AaiException {
+ SoActorServiceProvider soActorSp = new SoActorServiceProvider();
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ this.operationRequest =
+ soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, operation.clOperation,
+ this.policy, eventManager.getCqResponse((VirtualControlLoopEvent) onset));
+ } else {
+ this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy, eventManager.getNqVserverFromAai());
+ }
+
+ // Save the operation
+ this.currentOperation = operation;
+
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+
+ return operationRequest;
+ }
+
+
+ private Object startVfcOperation(ControlLoopEvent onset, Operation operation) throws AaiException {
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ this.operationRequest = VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy,
+ eventManager.getCqResponse((VirtualControlLoopEvent) onset));
+ } else {
+ this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy, this.eventManager.getVnfResponse(),
+ PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
+ PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
+ PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
+ }
+ this.currentOperation = operation;
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+ return operationRequest;
+ }
+
+
+ private Object startSdnrOperation(ControlLoopEvent onset, Operation operation) {
+ /*
+ * If the recipe is ModifyConfig or ModifyConfigANR, a SDNR request is constructed.
+ */
+ this.currentOperation = operation;
+ this.operationRequest = SdnrActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy);
+ //
+ // Save the operation
+ //
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+
+ return operationRequest;
+ }
+
+
+ private Object startSdncOperation(ControlLoopEvent onset, Operation operation) {
+ SdncActorServiceProvider provider = new SdncActorServiceProvider();
+ this.operationRequest =
+ provider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy);
+ this.currentOperation = operation;
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+ return operationRequest;
+ }
+
/**
* Handle a response.
*
@@ -448,15 +457,10 @@ public class ControlLoopOperationManager implements Serializable {
//
// Determine which subrequestID (ie. attempt)
//
- Integer operationAttempt = null;
- try {
- operationAttempt = Integer.parseInt(appcResponse.getCommonHeader().getSubRequestId());
- } catch (NumberFormatException e) {
- //
- // We cannot tell what happened if this doesn't exist
- //
+ Integer operationAttempt = getSubRequestId(appcResponse);
+ if (operationAttempt == null) {
this.completeOperation(operationAttempt, "Policy was unable to parse APP-C SubRequestID (it was null).",
- PolicyResult.FAILURE_EXCEPTION);
+ PolicyResult.FAILURE_EXCEPTION);
return PolicyResult.FAILURE_EXCEPTION;
}
//
@@ -483,6 +487,12 @@ public class ControlLoopOperationManager implements Serializable {
PolicyResult.FAILURE_EXCEPTION);
return PolicyResult.FAILURE_EXCEPTION;
}
+
+ return onResponse(appcResponse, operationAttempt, code);
+ }
+
+
+ private PolicyResult onResponse(Response appcResponse, Integer operationAttempt, ResponseCode code) {
//
// Ok, let's figure out what APP-C's response is
//
@@ -502,30 +512,21 @@ public class ControlLoopOperationManager implements Serializable {
//
this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(),
PolicyResult.FAILURE_EXCEPTION);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.FAILURE_EXCEPTION;
+ return getTimeoutResult(PolicyResult.FAILURE_EXCEPTION);
case SUCCESS:
//
//
//
this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(),
PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ return getTimeoutResult(PolicyResult.SUCCESS);
case FAILURE:
//
//
//
this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(),
PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.FAILURE;
+ return getTimeoutResult(PolicyResult.FAILURE);
default:
return null;
}
@@ -546,6 +547,7 @@ public class ControlLoopOperationManager implements Serializable {
if (operationAttempt == null) {
this.completeOperation(operationAttempt, "Policy was unable to parse APP-C SubRequestID (it was null).",
PolicyResult.FAILURE_EXCEPTION);
+ return PolicyResult.FAILURE_EXCEPTION;
}
/*
@@ -579,6 +581,7 @@ public class ControlLoopOperationManager implements Serializable {
if (operationAttempt == null) {
this.completeOperation(operationAttempt, "Policy was unable to parse SDNR SubRequestID.",
PolicyResult.FAILURE_EXCEPTION);
+ return PolicyResult.FAILURE_EXCEPTION;
}
/*
@@ -610,22 +613,16 @@ public class ControlLoopOperationManager implements Serializable {
//
// Consider it as success
//
- this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + " Success",
+ this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + SUCCESS_MSG,
PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ return getTimeoutResult(PolicyResult.SUCCESS);
default:
//
// Consider it as failure
//
- this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + " Failed",
+ this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + FAILED_MSG,
PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.FAILURE;
+ return getTimeoutResult(PolicyResult.FAILURE);
}
}
@@ -640,17 +637,14 @@ public class ControlLoopOperationManager implements Serializable {
//
// Consider it as success
//
- this.completeOperation(this.attempts, " Success", PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ this.completeOperation(this.attempts, SUCCESS_MSG, PolicyResult.SUCCESS);
+ return getTimeoutResult(PolicyResult.SUCCESS);
} else {
//
// Consider it as failure
//
- this.completeOperation(this.attempts, " Failed", PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
+ this.completeOperation(this.attempts, FAILED_MSG, PolicyResult.FAILURE);
+ if (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult)) {
return null;
}
// increment operation attempts for retries
@@ -670,17 +664,14 @@ public class ControlLoopOperationManager implements Serializable {
//
// Consider it as success
//
- this.completeOperation(this.attempts, " Success", PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ this.completeOperation(this.attempts, SUCCESS_MSG, PolicyResult.SUCCESS);
+ return getTimeoutResult(PolicyResult.SUCCESS);
} else {
//
// Consider it as failure
//
- this.completeOperation(this.attempts, " Failed", PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
+ this.completeOperation(this.attempts, FAILED_MSG, PolicyResult.FAILURE);
+ if (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult)) {
return null;
}
// increment operation attempts for retries
@@ -689,6 +680,22 @@ public class ControlLoopOperationManager implements Serializable {
}
}
+ private PolicyResult getTimeoutResult(PolicyResult result) {
+ return (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult) ? null : result);
+ }
+
+
+ private Integer getSubRequestId(Response appcResponse) {
+ try {
+ return Integer.valueOf(appcResponse.getCommonHeader().getSubRequestId());
+ } catch (NumberFormatException e) {
+ //
+ // We cannot tell what happened if this doesn't exist
+ //
+ return null;
+ }
+ }
+
/**
* Get the operation timeout.
*
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
index f06ea34dc..e33b260f9 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
@@ -3,6 +3,7 @@
* eventmanager
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
@@ -28,12 +29,14 @@ import org.junit.Test;
public class ControlLoopExceptionTest {
+ private static final String IN_OZ = "In Oz";
+
@Test
public void testControlLoopException() {
assertNotNull(new ControlLoopException());
- assertNotNull(new ControlLoopException("In Oz"));
+ assertNotNull(new ControlLoopException(IN_OZ));
assertNotNull(new ControlLoopException(new IOException()));
- assertNotNull(new ControlLoopException("In Oz", new IOException()));
- assertNotNull(new ControlLoopException("In Oz", new IOException(), false, false));
+ assertNotNull(new ControlLoopException(IN_OZ, new IOException()));
+ assertNotNull(new ControlLoopException(IN_OZ, new IOException(), false, false));
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopLoggerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopLoggerTest.java
index 4e2719075..35e4d534f 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopLoggerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopLoggerTest.java
@@ -8,9 +8,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,9 +21,8 @@
package org.onap.policy.controlloop;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import org.junit.Test;
import org.onap.policy.controlloop.impl.ControlLoopLoggerStdOutImpl;
@@ -38,11 +37,7 @@ public class ControlLoopLoggerTest {
logger.metrics("a metric", "and another", " and another");
logger.metrics(Double.valueOf(3));
- try {
- new ControlLoopLogger.Factory().buildLogger("java.lang.String");
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("Cannot load class java.lang.String as a control loop logger", e.getMessage());
- }
+ assertThatThrownBy(() -> new ControlLoopLogger.Factory().buildLogger("java.lang.String"))
+ .hasMessage("Cannot load class java.lang.String as a control loop logger");
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopPublisherTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopPublisherTest.java
index 77a3d643f..42b721ec1 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopPublisherTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopPublisherTest.java
@@ -8,9 +8,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,9 +21,8 @@
package org.onap.policy.controlloop;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import org.junit.Test;
import org.onap.policy.controlloop.impl.ControlLoopPublisherJUnitImpl;
@@ -35,19 +34,11 @@ public class ControlLoopPublisherTest {
new ControlLoopPublisher.Factory().buildLogger(ControlLoopPublisherJUnitImpl.class.getName());
assertNotNull(publisher);
- try {
- publisher.publish(Double.valueOf(3));
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("publish() method is not implemented on "
- + "org.onap.policy.controlloop.impl.ControlLoopPublisherJUnitImpl", e.getMessage());
- }
+ assertThatThrownBy(() -> publisher.publish(Double.valueOf(3)))
+ .hasMessage("publish() method is not implemented on "
+ + "org.onap.policy.controlloop.impl.ControlLoopPublisherJUnitImpl");
- try {
- new ControlLoopPublisher.Factory().buildLogger("java.lang.String");
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("Cannot load class java.lang.String as a control loop publisher", e.getMessage());
- }
+ assertThatThrownBy(() -> new ControlLoopPublisher.Factory().buildLogger("java.lang.String"))
+ .hasMessage("Cannot load class java.lang.String as a control loop publisher");
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
index 39077e3b3..9534f938a 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* util
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,14 +20,11 @@
package org.onap.policy.controlloop;
-import static org.junit.Assert.fail;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-
import org.apache.commons.io.IOUtils;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.yaml.snakeyaml.Yaml;
@@ -45,13 +42,18 @@ public final class SupportUtil {
}
}
+ private SupportUtil() {
+ // do nothing
+ }
+
/**
* Load yaml into a Pair object.
- *
+ *
* @param testFile the yaml file
* @return a Pair
+ * @throws IOException if the file cannot be read
*/
- public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
+ public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) throws IOException {
try (InputStream is = new FileInputStream(new File(testFile))) {
String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
//
@@ -59,11 +61,8 @@ public final class SupportUtil {
//
Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
Object obj = yaml.load(contents);
- return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
+ return new Pair<>((ControlLoopPolicy) obj, contents);
}
- return null;
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index beea88d82..3a4b27770 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -20,12 +20,12 @@
package org.onap.policy.controlloop.eventmanager;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
@@ -71,16 +71,37 @@ import org.onap.policy.guard.PolicyGuard;
import org.onap.policy.guard.PolicyGuard.LockResult;
import org.onap.policy.guard.TargetLock;
import org.powermock.reflect.Whitebox;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class ControlLoopEventManagerTest {
+ private static final String PROCESS_VSERVER_RESPONSE = "processVServerResponse";
+ private static final String ONSET_ONE = "onsetOne";
+ private static final String VSERVER_NAME = "vserver.vserver-name";
+ private static final String TEST_YAML = "src/test/resources/test.yaml";
+ private static final String SERVICE_TYPE = "service-subscription.service-type";
+ private static final String SERVICE_INSTANCE_NAME = "service-instance.service-instance-name";
+ private static final String SERVICE_INSTANCE_ID = "service-instance.service-instance-id";
+ private static final String SERVICE_INSTANCE = "service-instance";
+ private static final String VNF_NAME_TEXT = "lll_vnf_010317";
+ private static final String SERVICE_INSTANCE_NAME_TEXT = "lll_svc_010317";
+ private static final String VNF_NAME = "generic-vnf.vnf-name";
+ private static final String VNF_ID = "generic-vnf.vnf-id";
+ private static final String SERVICE_INSTANCE_UUID = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
+ private static final String MSO_CUSTOMER_ID = "customer.global-customer-id";
+ private static final String AAI_USERNAME = "aai.username";
+ private static final String AAI_URL = "aai.url";
+ private static final String AAI_PASS = "aai.password";
+ private static final String TWO_ONSET_TEST = "TwoOnsetTest";
+ private static final String MSO_1610_ST = "MSO_1610_ST";
+ private static final String MSO_DEV_SERVICE_TYPE = "MSO-dev-service-type";
+ private static final String VNF_UUID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
+ private static final String AAI_SERVICE_SUBSCRIPTION_URI =
+ "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription";
+ private static final String MSO_SERVICE_INSTANCE_URI = "/MSO-dev-service-type/service-instances/service-instance/";
+
private static final String PROCESS_VNF_RESPONSE_METHOD_NAME = "processVnfResponse";
private static final String INVALID_URL = "http://localhost:9999";
- private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManagerTest.class);
-
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -91,15 +112,12 @@ public class ControlLoopEventManagerTest {
* Set up test class.
*/
@BeforeClass
- public static void setUpSimulator() {
- try {
- org.onap.policy.simulators.Util.buildAaiSim();
- } catch (Exception e) {
- fail(e.getMessage());
- }
- PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
- PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+ public static void setUpSimulator() throws Exception {
+ org.onap.policy.simulators.Util.buildAaiSim();
+
+ PolicyEngine.manager.setEnvironmentProperty(AAI_USERNAME, "AAI");
+ PolicyEngine.manager.setEnvironmentProperty(AAI_PASS, "AAI");
+ PolicyEngine.manager.setEnvironmentProperty(AAI_URL, "http://localhost:6666");
}
@AfterClass
@@ -120,113 +138,70 @@ public class ControlLoopEventManagerTest {
onset.setAai(new HashMap<String, String>());
onset.getAai().put("cloud-region.identity-url", "foo");
onset.getAai().put("vserver.selflink", "bar");
- onset.getAai().put("generic-vnf.vnf-id", "83f674e8-7555-44d7-9a39-bdc3770b0491");
+ onset.getAai().put(VNF_ID, VNF_UUID);
onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+ PolicyEngine.manager.setEnvironmentProperty(AAI_URL, "http://localhost:6666");
}
@Test
- public void testAaiVnfInfo() {
- final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml("src/test/resources/test.yaml");
+ public void testAaiVnfInfo() throws IOException {
+ final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML);
onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName());
- try {
- AaiGetVnfResponse response = getQueryByVnfId2(
- PolicyEngine.manager.getEnvironmentProperty("aai.url")
- + "/aai/v11/network/generic-vnfs/generic-vnf/",
- PolicyEngine.manager.getEnvironmentProperty("aai.username"),
- PolicyEngine.manager.getEnvironmentProperty("aai.password"), UUID.randomUUID(),
- "5e49ca06-2972-4532-9ed4-6d071588d792");
- assertNotNull(response);
- logger.info("testAAIVnfInfo test result is " + (response == null ? "null" : "not null"));
- } catch (Exception e) {
- logger.error("testAAIVnfInfo Exception: ", e);
- fail(e.getMessage());
- }
+ AaiGetVnfResponse response = getQueryByVnfId2();
+ assertNotNull(response);
}
@Test
- public void testAaiVnfInfo2() {
- final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml("src/test/resources/test.yaml");
+ public void testAaiVnfInfo2() throws IOException {
+ final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML);
onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName());
- try {
- AaiGetVnfResponse response = getQueryByVnfName2(
- PolicyEngine.manager.getEnvironmentProperty("aai.url")
- + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=",
- PolicyEngine.manager.getEnvironmentProperty("aai.username"),
- PolicyEngine.manager.getEnvironmentProperty("aai.password"), UUID.randomUUID(), "lll_vnf_010317");
- assertNotNull(response);
- logger.info("testAAIVnfInfo2 test result is " + (response == null ? "null" : "not null"));
- } catch (Exception e) {
- logger.error("testAAIVnfInfo2 Exception: ", e);
- fail(e.getMessage());
- }
+ AaiGetVnfResponse response = getQueryByVnfName2();
+ assertNotNull(response);
}
@Test
- public void testAaiVserver() {
- final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml("src/test/resources/test.yaml");
+ public void testAaiVserver() throws IOException {
+ final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML);
onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName());
- try {
- AaiGetVserverResponse response = getQueryByVserverName2(
- PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/nodes/vservers?vserver-name=",
- PolicyEngine.manager.getEnvironmentProperty("aai.username"),
- PolicyEngine.manager.getEnvironmentProperty("aai.password"), UUID.randomUUID(),
- "USMSO1SX7NJ0103UJZZ01-vjunos0");
- assertNotNull(response);
- logger.info("testAAIVserver test result is " + (response == null ? "null" : "not null"));
- } catch (Exception e) {
- logger.error("testAAIVserver Exception: ", e);
- fail(e.getMessage());
- }
+ AaiGetVserverResponse response = getQueryByVserverName2();
+ assertNotNull(response);
}
@Test
- public void abatementCheckEventSyntaxTest() {
+ public void abatementCheckEventSyntaxTest() throws ControlLoopException {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName("abatementAAI");
event.setRequestId(UUID.randomUUID());
- event.setTarget("generic-vnf.vnf-id");
+ event.setTarget(VNF_ID);
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
ControlLoopEventManager manager = makeManager(event);
assertNull(manager.getVnfResponse());
assertNull(manager.getVserverResponse());
- try {
- manager.checkEventSyntax(event);
- } catch (ControlLoopException e) {
- logger.debug("ControlLoopException in abatemetCheckEventSyntaxTest: " + e.getMessage());
- e.printStackTrace();
- fail("Exception in check event syntax");
- }
+ manager.checkEventSyntax(event);
assertNull(manager.getVnfResponse());
assertNull(manager.getVserverResponse());
event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "abatementTest");
- try {
- manager.checkEventSyntax(event);
- } catch (ControlLoopException e) {
- logger.debug("ControlLoopException in abatemetCheckEventSyntaxTest: " + e.getMessage());
- e.printStackTrace();
- fail("Exception in check event syntax");
- }
+ event.getAai().put(VNF_NAME, "abatementTest");
+ manager.checkEventSyntax(event);
assertNull(manager.getVnfResponse());
assertNull(manager.getVserverResponse());
}
@Test
- public void subsequentOnsetTest() throws IOException {
+ public void subsequentOnsetTest() throws Exception {
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName("TwoOnsetTest");
+ event.setClosedLoopControlName(TWO_ONSET_TEST);
event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
+ event.setTarget(VNF_ID);
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ event.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(event);
VirtualControlLoopNotification notification = manager.activate(event);
@@ -235,12 +210,7 @@ public class ControlLoopEventManagerTest {
assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
ControlLoopEventManager.NewEventStatus status = null;
- try {
- status = manager.onNewEvent(event);
- } catch (AaiException e) {
- logger.warn(e.toString());
- fail("A&AI Query Failed");
- }
+ status = manager.onNewEvent(event);
assertNotNull(status);
assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status);
@@ -249,21 +219,16 @@ public class ControlLoopEventManagerTest {
assertNull(manager.getVserverResponse());
VirtualControlLoopEvent event2 = new VirtualControlLoopEvent();
- event2.setClosedLoopControlName("TwoOnsetTest");
+ event2.setClosedLoopControlName(TWO_ONSET_TEST);
event2.setRequestId(requestId);
- event2.setTarget("generic-vnf.vnf-id");
+ event2.setTarget(VNF_ID);
event2.setClosedLoopAlarmStart(Instant.now());
event2.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event2.setAai(new HashMap<>());
- event2.getAai().put("generic-vnf.vnf-name", "onsetTwo");
+ event2.getAai().put(VNF_NAME, "onsetTwo");
- try {
- status = manager.onNewEvent(event2);
- } catch (AaiException e) {
- logger.warn(e.toString());
- fail("A&AI Query Failed");
- }
+ status = manager.onNewEvent(event2);
assertEquals(ControlLoopEventManager.NewEventStatus.SUBSEQUENT_ONSET, status);
AaiGetVnfResponse response2 = manager.getVnfResponse();
assertNotNull(response2);
@@ -275,12 +240,11 @@ public class ControlLoopEventManagerTest {
/**
* Simulate a response.
*/
- public static AaiGetVnfResponse getQueryByVnfId2(String urlGet, String username, String password, UUID requestId,
- String key) {
+ public static AaiGetVnfResponse getQueryByVnfId2() {
AaiGetVnfResponse response = new AaiGetVnfResponse();
- response.setVnfId("83f674e8-7555-44d7-9a39-bdc3770b0491");
- response.setVnfName("lll_vnf_010317");
+ response.setVnfId(VNF_UUID);
+ response.setVnfName(VNF_NAME_TEXT);
response.setVnfType("Basa-122216-Service/VidVsamp12BaseVolume 1");
response.setServiceId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
response.setOrchestrationStatus("Created");
@@ -293,28 +257,28 @@ public class ControlLoopEventManagerTest {
final Relationship relationship = new Relationship();
RelationshipData relationshipDataItem = new RelationshipData();
- relationshipDataItem.setRelationshipKey("customer.global-customer-id");
- relationshipDataItem.setRelationshipValue("MSO_1610_ST");
+ relationshipDataItem.setRelationshipKey(MSO_CUSTOMER_ID);
+ relationshipDataItem.setRelationshipValue(MSO_1610_ST);
relationship.getRelationshipData().add(relationshipDataItem);
- relationshipDataItem.setRelationshipKey("service-subscription.service-type");
- relationshipDataItem.setRelationshipValue("MSO-dev-service-type");
+ relationshipDataItem.setRelationshipKey(SERVICE_TYPE);
+ relationshipDataItem.setRelationshipValue(MSO_DEV_SERVICE_TYPE);
relationship.getRelationshipData().add(relationshipDataItem);
- relationshipDataItem.setRelationshipKey("service-instance.service-instance-id");
- relationshipDataItem.setRelationshipValue("e1e9c97c-02c0-4919-9b4c-eb5d5ef68970");
+ relationshipDataItem.setRelationshipKey(SERVICE_INSTANCE_ID);
+ relationshipDataItem.setRelationshipValue(SERVICE_INSTANCE_UUID);
relationship.getRelationshipData().add(relationshipDataItem);
RelatedToProperty item = new RelatedToProperty();
- item.setPropertyKey("service-instance.service-instance-name");
- item.setPropertyValue("lll_svc_010317");
+ item.setPropertyKey(SERVICE_INSTANCE_NAME);
+ item.setPropertyValue(SERVICE_INSTANCE_NAME_TEXT);
relationship.getRelatedToProperty().add(item);
- relationship.setRelatedTo("service-instance");
+ relationship.setRelatedTo(SERVICE_INSTANCE);
relationship.setRelatedLink(
- "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription"
- + "/MSO-dev-service-type/service-instances/service-instance/"
- + "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970");
+ AAI_SERVICE_SUBSCRIPTION_URI
+ + MSO_SERVICE_INSTANCE_URI
+ + SERVICE_INSTANCE_UUID);
relationshipList.getRelationships().add(relationship);
response.setRelationshipList(relationshipList);
@@ -325,12 +289,11 @@ public class ControlLoopEventManagerTest {
/**
* Simulate a response.
*/
- public static AaiGetVnfResponse getQueryByVnfName2(String urlGet, String username, String password, UUID requestId,
- String key) {
+ public static AaiGetVnfResponse getQueryByVnfName2() {
AaiGetVnfResponse response = new AaiGetVnfResponse();
- response.setVnfId("83f674e8-7555-44d7-9a39-bdc3770b0491");
- response.setVnfName("lll_vnf_010317");
+ response.setVnfId(VNF_UUID);
+ response.setVnfName(VNF_NAME_TEXT);
response.setVnfType("Basa-122216-Service/VidVsamp12BaseVolume 1");
response.setServiceId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
response.setOrchestrationStatus("Created");
@@ -343,28 +306,28 @@ public class ControlLoopEventManagerTest {
final Relationship relationship = new Relationship();
RelationshipData relationshipDataItem = new RelationshipData();
- relationshipDataItem.setRelationshipKey("customer.global-customer-id");
- relationshipDataItem.setRelationshipValue("MSO_1610_ST");
+ relationshipDataItem.setRelationshipKey(MSO_CUSTOMER_ID);
+ relationshipDataItem.setRelationshipValue(MSO_1610_ST);
relationship.getRelationshipData().add(relationshipDataItem);
- relationshipDataItem.setRelationshipKey("service-subscription.service-type");
- relationshipDataItem.setRelationshipValue("MSO-dev-service-type");
+ relationshipDataItem.setRelationshipKey(SERVICE_TYPE);
+ relationshipDataItem.setRelationshipValue(MSO_DEV_SERVICE_TYPE);
relationship.getRelationshipData().add(relationshipDataItem);
- relationshipDataItem.setRelationshipKey("service-instance.service-instance-id");
- relationshipDataItem.setRelationshipValue("e1e9c97c-02c0-4919-9b4c-eb5d5ef68970");
+ relationshipDataItem.setRelationshipKey(SERVICE_INSTANCE_ID);
+ relationshipDataItem.setRelationshipValue(SERVICE_INSTANCE_UUID);
relationship.getRelationshipData().add(relationshipDataItem);
RelatedToProperty item = new RelatedToProperty();
- item.setPropertyKey("service-instance.service-instance-name");
- item.setPropertyValue("lll_svc_010317");
+ item.setPropertyKey(SERVICE_INSTANCE_NAME);
+ item.setPropertyValue(SERVICE_INSTANCE_NAME_TEXT);
relationship.getRelatedToProperty().add(item);
- relationship.setRelatedTo("service-instance");
+ relationship.setRelatedTo(SERVICE_INSTANCE);
relationship.setRelatedLink(
- "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription"
- + "/MSO-dev-service-type/service-instances/service-instance/"
- + "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970");
+ AAI_SERVICE_SUBSCRIPTION_URI
+ + MSO_SERVICE_INSTANCE_URI
+ + SERVICE_INSTANCE_UUID);
relationshipList.getRelationships().add(relationship);
response.setRelationshipList(relationshipList);
@@ -375,8 +338,7 @@ public class ControlLoopEventManagerTest {
/**
* Simulate a response.
*/
- public static AaiGetVserverResponse getQueryByVserverName2(String urlGet, String username, String password,
- UUID requestId, String key) {
+ public static AaiGetVserverResponse getQueryByVserverName2() {
final AaiGetVserverResponse response = new AaiGetVserverResponse();
AaiNqVServer svr = new AaiNqVServer();
@@ -394,28 +356,28 @@ public class ControlLoopEventManagerTest {
final Relationship relationship = new Relationship();
RelationshipData relationshipDataItem = new RelationshipData();
- relationshipDataItem.setRelationshipKey("customer.global-customer-id");
- relationshipDataItem.setRelationshipValue("MSO_1610_ST");
+ relationshipDataItem.setRelationshipKey(MSO_CUSTOMER_ID);
+ relationshipDataItem.setRelationshipValue(MSO_1610_ST);
relationship.getRelationshipData().add(relationshipDataItem);
- relationshipDataItem.setRelationshipKey("service-subscription.service-type");
- relationshipDataItem.setRelationshipValue("MSO-dev-service-type");
+ relationshipDataItem.setRelationshipKey(SERVICE_TYPE);
+ relationshipDataItem.setRelationshipValue(MSO_DEV_SERVICE_TYPE);
relationship.getRelationshipData().add(relationshipDataItem);
- relationshipDataItem.setRelationshipKey("service-instance.service-instance-id");
- relationshipDataItem.setRelationshipValue("e1e9c97c-02c0-4919-9b4c-eb5d5ef68970");
+ relationshipDataItem.setRelationshipKey(SERVICE_INSTANCE_ID);
+ relationshipDataItem.setRelationshipValue(SERVICE_INSTANCE_UUID);
relationship.getRelationshipData().add(relationshipDataItem);
RelatedToProperty item = new RelatedToProperty();
- item.setPropertyKey("service-instance.service-instance-name");
- item.setPropertyValue("lll_svc_010317");
+ item.setPropertyKey(SERVICE_INSTANCE_NAME);
+ item.setPropertyValue(SERVICE_INSTANCE_NAME_TEXT);
relationship.getRelatedToProperty().add(item);
- relationship.setRelatedTo("service-instance");
+ relationship.setRelatedTo(SERVICE_INSTANCE);
relationship.setRelatedLink(
- "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription"
- + "/MSO-dev-service-type/service-instances/service-instance/"
- + "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970");
+ AAI_SERVICE_SUBSCRIPTION_URI
+ + MSO_SERVICE_INSTANCE_URI
+ + SERVICE_INSTANCE_UUID);
relationshipList.getRelationships().add(relationship);
svr.setRelationshipList(relationshipList);
@@ -463,13 +425,13 @@ public class ControlLoopEventManagerTest {
public void testAlreadyActivated() {
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName("TwoOnsetTest");
+ event.setClosedLoopControlName(TWO_ONSET_TEST);
event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
+ event.setTarget(VNF_ID);
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ event.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(event);
manager.setActivated(true);
@@ -479,7 +441,7 @@ public class ControlLoopEventManagerTest {
@Test
public void testActivationYaml() throws IOException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
InputStream isBad = new FileInputStream(new File("src/test/resources/notutf8.yaml"));
@@ -487,13 +449,13 @@ public class ControlLoopEventManagerTest {
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName("TwoOnsetTest");
+ event.setClosedLoopControlName(TWO_ONSET_TEST);
event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
+ event.setTarget(VNF_ID);
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ event.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(event);
@@ -523,35 +485,28 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testControlLoopFinal() throws ControlLoopException, IOException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ public void testControlLoopFinal() throws Exception {
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName("TwoOnsetTest");
+ event.setClosedLoopControlName(TWO_ONSET_TEST);
event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
+ event.setTarget(VNF_ID);
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ event.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(event);
- try {
- manager.isControlLoopFinal();
- fail("test should throw an exception here");
- } catch (ControlLoopException e) {
- assertEquals("ControlLoopEventManager MUST be activated first.", e.getMessage());
- }
+ ControlLoopEventManager manager2 = manager;
+ assertThatThrownBy(manager2::isControlLoopFinal).isInstanceOf(ControlLoopException.class)
+ .hasMessage("ControlLoopEventManager MUST be activated first.");
manager.setActivated(true);
- try {
- manager.isControlLoopFinal();
- fail("test should throw an exception here");
- } catch (ControlLoopException e) {
- assertEquals("No onset event for ControlLoopEventManager.", e.getMessage());
- }
+ assertThatThrownBy(manager2::isControlLoopFinal).isInstanceOf(ControlLoopException.class)
+ .hasMessage("No onset event for ControlLoopEventManager.");
manager.setActivated(false);
VirtualControlLoopNotification notification = manager.activate(yamlString, event);
@@ -596,35 +551,28 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testProcessControlLoop() throws ControlLoopException, IOException, AaiException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ public void testProcessControlLoop() throws Exception {
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName("TwoOnsetTest");
+ event.setClosedLoopControlName(TWO_ONSET_TEST);
event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
+ event.setTarget(VNF_ID);
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ event.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(event);
- try {
- manager.processControlLoop();
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("ControlLoopEventManager MUST be activated first.", e.getMessage());
- }
+ ControlLoopEventManager manager2 = manager;
+ assertThatThrownBy(manager2::processControlLoop).isInstanceOf(ControlLoopException.class)
+ .hasMessage("ControlLoopEventManager MUST be activated first.");
manager.setActivated(true);
- try {
- manager.processControlLoop();
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("No onset event for ControlLoopEventManager.", e.getMessage());
- }
+ assertThatThrownBy(manager2::processControlLoop).isInstanceOf(ControlLoopException.class)
+ .hasMessage("No onset event for ControlLoopEventManager.");
manager.setActivated(false);
VirtualControlLoopNotification notification = manager.activate(yamlString, event);
@@ -639,12 +587,9 @@ public class ControlLoopEventManagerTest {
manager = Serializer.roundTrip(manager);
// Test operation in progress
- try {
- manager.processControlLoop();
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("Already working an Operation, do not call this method.", e.getMessage());
- }
+ ControlLoopEventManager manager3 = manager;
+ assertThatThrownBy(manager3::processControlLoop).isInstanceOf(ControlLoopException.class)
+ .hasMessage("Already working an Operation, do not call this method.");
manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
notification = manager.activate(yamlString, event);
@@ -657,12 +602,9 @@ public class ControlLoopEventManagerTest {
assertEquals(ControlLoopNotificationType.FINAL_FAILURE, clfNotification.getNotification());
// Test operation completed
- try {
- manager.processControlLoop();
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("Control Loop is in FINAL state, do not call this method.", e.getMessage());
- }
+ ControlLoopEventManager manager4 = manager;
+ assertThatThrownBy(manager4::processControlLoop).isInstanceOf(ControlLoopException.class)
+ .hasMessage("Control Loop is in FINAL state, do not call this method.");
manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
notification = manager.activate(yamlString, event);
@@ -671,59 +613,45 @@ public class ControlLoopEventManagerTest {
manager.getProcessor().nextPolicyForResult(PolicyResult.FAILURE);
// Test operation with no next policy defined
- try {
- manager.processControlLoop();
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("The target type is null", e.getMessage());
- }
+ ControlLoopEventManager manager5 = manager;
+ assertThatThrownBy(manager5::processControlLoop).isInstanceOf(ControlLoopException.class)
+ .hasMessage("The target type is null");
}
@Test
- public void testFinishOperation() throws IOException, ControlLoopException, AaiException {
+ public void testFinishOperation() throws Exception {
InputStream is = new FileInputStream(new File("src/test/resources/testSOactor.yaml"));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- InputStream isStd = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream isStd = new FileInputStream(new File(TEST_YAML));
final String yamlStringStd = IOUtils.toString(isStd, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName("TwoOnsetTest");
+ event.setClosedLoopControlName(TWO_ONSET_TEST);
event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
+ event.setTarget(VNF_ID);
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-id", "onsetOne");
+ event.getAai().put(VNF_ID, ONSET_ONE);
ControlLoopEventManager manager = makeManager(event);
- try {
- manager.finishOperation(null);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("No operation to finish.", e.getMessage());
- }
+ ControlLoopEventManager manager2 = manager;
+ assertThatThrownBy(() -> manager2.finishOperation(null)).isInstanceOf(ControlLoopException.class)
+ .hasMessage("No operation to finish.");
manager.setActivated(true);
- try {
- manager.finishOperation(null);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("No operation to finish.", e.getMessage());
- }
+ assertThatThrownBy(() -> manager2.finishOperation(null)).isInstanceOf(ControlLoopException.class)
+ .hasMessage("No operation to finish.");
manager.setActivated(false);
VirtualControlLoopNotification notification = manager.activate(yamlString, event);
assertNotNull(notification);
assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
- try {
- manager.lockCurrentOperation();
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("Do not have a current operation.", e.getMessage());
- }
+ assertThatThrownBy(manager2::lockCurrentOperation).isInstanceOf(ControlLoopException.class)
+ .hasMessage("Do not have a current operation.");
assertNull(manager.unlockCurrentOperation());
@@ -769,28 +697,28 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testOnNewEvent() throws IOException, AaiException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ public void testOnNewEvent() throws Exception {
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
VirtualControlLoopEvent abatedEvent = new VirtualControlLoopEvent();
- abatedEvent.setClosedLoopControlName("TwoOnsetTest");
+ abatedEvent.setClosedLoopControlName(TWO_ONSET_TEST);
abatedEvent.setRequestId(requestId);
- abatedEvent.setTarget("generic-vnf.vnf-id");
+ abatedEvent.setTarget(VNF_ID);
abatedEvent.setClosedLoopAlarmStart(Instant.now());
abatedEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
abatedEvent.setAai(new HashMap<>());
- abatedEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ abatedEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(onsetEvent);
VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
@@ -828,7 +756,7 @@ public class ControlLoopEventManagerTest {
checkSyntaxEvent.setClosedLoopControlName("");
assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
- checkSyntaxEvent.setClosedLoopControlName("TwoOnsetTest");
+ checkSyntaxEvent.setClosedLoopControlName(TWO_ONSET_TEST);
assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
checkSyntaxEvent.setRequestId(null);
@@ -861,13 +789,13 @@ public class ControlLoopEventManagerTest {
checkSyntaxEvent.setTarget("VNF_NAME");
assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
- checkSyntaxEvent.setTarget("vserver.vserver-name");
+ checkSyntaxEvent.setTarget(VSERVER_NAME);
assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
- checkSyntaxEvent.setTarget("generic-vnf.vnf-id");
+ checkSyntaxEvent.setTarget(VNF_ID);
assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
- checkSyntaxEvent.setTarget("generic-vnf.vnf-name");
+ checkSyntaxEvent.setTarget(VNF_NAME);
assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
checkSyntaxEvent.setAai(null);
@@ -876,30 +804,30 @@ public class ControlLoopEventManagerTest {
checkSyntaxEvent.setAai(new HashMap<>());
assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
- checkSyntaxEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ checkSyntaxEvent.getAai().put(VNF_NAME, ONSET_ONE);
assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, manager.onNewEvent(abatedEvent));
- checkSyntaxEvent.getAai().put("vserver.vserver-name", "onsetOne");
+ checkSyntaxEvent.getAai().put(VSERVER_NAME, ONSET_ONE);
assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, manager.onNewEvent(abatedEvent));
- checkSyntaxEvent.getAai().put("generic-vnf.vnf-id", "onsetOne");
+ checkSyntaxEvent.getAai().put(VNF_ID, ONSET_ONE);
assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, manager.onNewEvent(abatedEvent));
}
@Test
public void testControlLoopTimeout() throws IOException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(onsetEvent);
assertTrue(0 == manager.getControlLoopTimeout(null));
@@ -909,7 +837,7 @@ public class ControlLoopEventManagerTest {
assertNotNull(notification);
assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
- assertTrue(60 == manager.getControlLoopTimeout(null));
+ assertEquals(60, manager.getControlLoopTimeout(null));
}
@Test
@@ -919,13 +847,13 @@ public class ControlLoopEventManagerTest {
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(onsetEvent);
@@ -944,13 +872,13 @@ public class ControlLoopEventManagerTest {
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager = makeManager(onsetEvent);
@@ -964,43 +892,28 @@ public class ControlLoopEventManagerTest {
@Test
public void testQueryAai_AlreadyDisabled() throws AaiException {
- ControlLoopEventManager mgr = null;
-
- try {
- onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString());
- onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS,
- ControlLoopEventManager.PROV_STATUS_ACTIVE);
-
- mgr = makeManager(onset);
- mgr.queryAai(onset);
+ onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString());
+ onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE);
- fail("missing exception");
+ ControlLoopEventManager mgr = makeManager(onset);
- } catch (AaiException expected) {
- assertEquals("is-closed-loop-disabled is set to true on VServer or VNF", expected.getMessage());
- assertNull(mgr.getVnfResponse());
- assertNull(mgr.getVserverResponse());
- }
+ assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class)
+ .hasMessage("is-closed-loop-disabled is set to true on VServer or VNF");
+ assertNull(mgr.getVnfResponse());
+ assertNull(mgr.getVserverResponse());
}
@Test
public void testQueryAai_AlreadyInactive() throws AaiException {
- ControlLoopEventManager mgr = null;
-
- try {
- onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString());
- onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, "not-active2");
+ onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString());
+ onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, "not-active2");
- mgr = makeManager(onset);
- mgr.queryAai(onset);
+ ControlLoopEventManager mgr = makeManager(onset);
- fail("missing exception");
-
- } catch (AaiException expected) {
- assertEquals("prov-status is not ACTIVE on VServer or VNF", expected.getMessage());
- assertNull(mgr.getVnfResponse());
- assertNull(mgr.getVserverResponse());
- }
+ assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class)
+ .hasMessage("prov-status is not ACTIVE on VServer or VNF");
+ assertNull(mgr.getVnfResponse());
+ assertNull(mgr.getVserverResponse());
}
@Test
@@ -1046,33 +959,24 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testQueryAai_QueryVnfById_Disabled() throws AaiException {
- ControlLoopEventManager mgr = null;
+ public void testQueryAai_QueryVnfById_Disabled() {
+ onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_VNF_ID, "disableClosedLoop");
- try {
- onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_VNF_ID, "disableClosedLoop");
+ ControlLoopEventManager mgr = makeManager(onset);
- mgr = makeManager(onset);
- mgr.queryAai(onset);
+ assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class)
+ .hasMessage("is-closed-loop-disabled is set to true (query by vnf-id)");
- fail("missing exception");
-
- } catch (AaiException expected) {
- assertEquals("is-closed-loop-disabled is set to true (query by vnf-id)", expected.getMessage());
-
- assertNotNull(mgr.getVnfResponse());
- assertNull(mgr.getVserverResponse());
- }
+ assertNotNull(mgr.getVnfResponse());
+ assertNull(mgr.getVserverResponse());
}
@Test
public void testQueryAai_QueryVserver() throws AaiException {
- ControlLoopEventManager mgr = null;
-
onset.getAai().remove(ControlLoopEventManager.GENERIC_VNF_VNF_ID);
onset.getAai().put(ControlLoopEventManager.VSERVER_VSERVER_NAME, "AVserver");
- mgr = makeManager(onset);
+ ControlLoopEventManager mgr = makeManager(onset);
mgr.queryAai(onset);
assertNull(mgr.getVnfResponse());
@@ -1088,30 +992,23 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testQueryAai_QueryVserver_Disabled() throws AaiException {
- ControlLoopEventManager mgr = null;
-
- try {
- onset.getAai().remove(ControlLoopEventManager.GENERIC_VNF_VNF_ID);
- onset.getAai().put(ControlLoopEventManager.VSERVER_VSERVER_NAME, "disableClosedLoop");
-
- mgr = makeManager(onset);
- mgr.queryAai(onset);
+ public void testQueryAai_QueryVserver_Disabled() {
+ onset.getAai().remove(ControlLoopEventManager.GENERIC_VNF_VNF_ID);
+ onset.getAai().put(ControlLoopEventManager.VSERVER_VSERVER_NAME, "disableClosedLoop");
- fail("missing exception");
+ ControlLoopEventManager mgr = makeManager(onset);
- } catch (AaiException expected) {
- assertEquals("is-closed-loop-disabled is set to true (query by vserver-name)", expected.getMessage());
+ assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class)
+ .hasMessage("is-closed-loop-disabled is set to true (query by vserver-name)");
- assertNull(mgr.getVnfResponse());
- assertNotNull(mgr.getVserverResponse());
- }
+ assertNull(mgr.getVnfResponse());
+ assertNotNull(mgr.getVserverResponse());
}
@Test(expected = AaiException.class)
public void testQueryAai_QueryException() throws AaiException {
// Force AAI errors
- PolicyEngine.manager.setEnvironmentProperty("aai.url", INVALID_URL);
+ PolicyEngine.manager.setEnvironmentProperty(AAI_URL, INVALID_URL);
makeManager(onset).queryAai(onset);
}
@@ -1178,7 +1075,7 @@ public class ControlLoopEventManagerTest {
svr.setIsClosedLoopDisabled(false);
svr.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE);
- Whitebox.invokeMethod(ControlLoopEventManager.class, "processVServerResponse", resp);
+ Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp);
}
@Test
@@ -1187,7 +1084,7 @@ public class ControlLoopEventManagerTest {
thrown.expectMessage("AAI Response is null (query by vserver-name)");
AaiGetVserverResponse resp = null;
- Whitebox.invokeMethod(ControlLoopEventManager.class, "processVServerResponse", resp);
+ Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp);
}
@Test
@@ -1205,7 +1102,7 @@ public class ControlLoopEventManagerTest {
svr.setIsClosedLoopDisabled(false);
svr.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE);
- Whitebox.invokeMethod(ControlLoopEventManager.class, "processVServerResponse", resp);
+ Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp);
}
@Test
@@ -1219,7 +1116,7 @@ public class ControlLoopEventManagerTest {
svr.setIsClosedLoopDisabled(true);
svr.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE);
- Whitebox.invokeMethod(ControlLoopEventManager.class, "processVServerResponse", resp);
+ Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp);
}
@Test
@@ -1233,7 +1130,7 @@ public class ControlLoopEventManagerTest {
svr.setIsClosedLoopDisabled(false);
svr.setProvStatus("inactive1");
- Whitebox.invokeMethod(ControlLoopEventManager.class, "processVServerResponse", resp);
+ Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp);
}
@Test
@@ -1310,7 +1207,7 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testGetNqVserverFromAai() throws Exception {
+ public void testGetNqVserverFromAai() {
// empty vserver name
ControlLoopEventManager manager = makeManager(onset);
@@ -1334,7 +1231,7 @@ public class ControlLoopEventManagerTest {
// Force AAI error
- PolicyEngine.manager.setEnvironmentProperty("aai.url", INVALID_URL);
+ PolicyEngine.manager.setEnvironmentProperty(AAI_URL, INVALID_URL);
// re-create manager
manager = makeManager(onset);
@@ -1343,36 +1240,22 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testGetCqResponseEmptyVserver() {
- try {
- ControlLoopEventManager mgr = null;
- mgr = makeManager(onset);
- mgr.queryAai(onset);
- mgr.getCqResponse(onset);
- fail();
-
-
- } catch (AaiException e) {
- logger.error("testGetCqResponse Exception: ", e);
- assertEquals(e.getMessage(), "Vserver name is missing");
- }
+ public void testGetCqResponseEmptyVserver() throws AaiException {
+ ControlLoopEventManager mgr = makeManager(onset);
+ mgr.queryAai(onset);
+
+ assertThatThrownBy(() -> mgr.getCqResponse(onset)).isInstanceOf(AaiException.class)
+ .hasMessage("Vserver name is missing");
}
@Test
- public void testGetCqResponse() {
- try {
- ControlLoopEventManager mgr = null;
- mgr = makeManager(onset);
- mgr.queryAai(onset);
- onset.getAai().put("vserver.vserver-name", "sample");
- AaiCqResponse aaiCqResponse = mgr.getCqResponse(onset);
- assertNotNull(aaiCqResponse);
-
-
- } catch (Exception e) {
- logger.error("testGetCqResponse Exception: ", e);
- fail(e.getMessage());
- }
+ public void testGetCqResponse() throws AaiException {
+ ControlLoopEventManager mgr = makeManager(onset);
+ mgr.queryAai(onset);
+ onset.getAai().put(VSERVER_NAME, "sample");
+
+ AaiCqResponse aaiCqResponse = mgr.getCqResponse(onset);
+ assertNotNull(aaiCqResponse);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
index 568f8bcd4..835b4ac82 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
@@ -20,12 +20,12 @@
package org.onap.policy.controlloop.eventmanager;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
@@ -37,8 +37,6 @@ import java.util.HashMap;
import java.util.UUID;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
-import javax.persistence.NoResultException;
-import javax.persistence.NonUniqueResultException;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.apache.commons.io.IOUtils;
@@ -79,6 +77,21 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ControlLoopOperationManagerTest {
+ private static final String VSERVER_NAME = "vserver.vserver-name";
+ private static final String TEST_YAML = "src/test/resources/test.yaml";
+ private static final String ONSET_ONE = "onsetOne";
+ private static final String VNF_NAME = "generic-vnf.vnf-name";
+ private static final String VNF_ID = "generic-vnf.vnf-id";
+ private static final String TWO_ONSET_TEST = "TwoOnsetTest";
+ private static final String OPER_MSG = "The Wizard Escaped";
+ private static final String OZ_VNF = "OzVNF";
+ private static final String OPERATIONS_HISTORY_PU_TEST = "OperationsHistoryPUTest";
+ private static final String OPERATIONS_HISTORY_PU = "OperationsHistoryPU";
+ private static final String DOROTHY = "Dorothy";
+ private static final String APPC_FAILURE_REASON = "AppC failed for some reason";
+ private static final String ACCEPT = "ACCEPT";
+
+
private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManagerTest.class);
@@ -87,11 +100,11 @@ public class ControlLoopOperationManagerTest {
static {
onset = new VirtualControlLoopEvent();
onset.setRequestId(UUID.randomUUID());
- onset.setTarget("generic-vnf.vnf-name");
+ onset.setTarget(VNF_NAME);
onset.setTargetType(ControlLoopTargetType.VNF);
onset.setClosedLoopAlarmStart(Instant.now());
onset.setAai(new HashMap<>());
- onset.getAai().put("generic-vnf.vnf-name", "testTriggerSource");
+ onset.getAai().put(VNF_NAME, "testTriggerSource");
onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
/* Set environment properties */
@@ -109,14 +122,7 @@ public class ControlLoopOperationManagerTest {
String sql = "select count(*) as count from operationshistory";
Query nq = em.createNativeQuery(sql);
- int numEvents = -1;
- try {
- numEvents = ((Number) nq.getSingleResult()).intValue();
- } catch (NoResultException | NonUniqueResultException ex) {
- logger.error("getCountFromDb threw: ", ex);
- fail(ex.getMessage());
- }
- return numEvents;
+ return ((Number) nq.getSingleResult()).intValue();
}
@@ -124,16 +130,12 @@ public class ControlLoopOperationManagerTest {
* Set up test class.
*/
@BeforeClass
- public static void setUp() {
+ public static void setUp() throws Exception {
- try {
- org.onap.policy.simulators.Util.buildAaiSim();
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ org.onap.policy.simulators.Util.buildAaiSim();
// Set PU
- System.setProperty("OperationsHistoryPU", "OperationsHistoryPUTest");
+ System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST);
// Enter dummy props to avoid nullPointerException
PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, "a");
@@ -141,7 +143,7 @@ public class ControlLoopOperationManagerTest {
PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "c");
// Connect to in-mem db
- emf = Persistence.createEntityManagerFactory("OperationsHistoryPUTest");
+ emf = Persistence.createEntityManagerFactory(OPERATIONS_HISTORY_PU_TEST);
em = emf.createEntityManager();
}
@@ -157,232 +159,214 @@ public class ControlLoopOperationManagerTest {
}
@Test
- public void testRetriesFail() {
+ public void testRetriesFail() throws Exception {
//
// Load up the policy
//
- final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml("src/test/resources/test.yaml");
+ final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML);
onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName());
- try {
- //
- // Create a processor
- //
- final ControlLoopProcessor processor = new ControlLoopProcessor(pair.value);
- //
- // create the manager
- //
- ControlLoopEventManager eventManager =
- new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId());
- VirtualControlLoopNotification notification = eventManager.activate(onset);
-
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- ControlLoopEventManager.NewEventStatus status = null;
- try {
- status = eventManager.onNewEvent(onset);
- } catch (AaiException e) {
- logger.warn(e.toString());
- fail("A&AI Query Failed");
- }
- assertNotNull(status);
- assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status);
-
- ControlLoopOperationManager manager =
- new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
- logger.debug("{}", manager);
- //
- //
- //
- assertFalse(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- //
- // Start
- //
- Object request = manager.startOperation(onset);
- logger.debug("{}", manager);
- assertNotNull(request);
- assertTrue(request instanceof LcmRequestWrapper);
- LcmRequestWrapper dmaapRequest = (LcmRequestWrapper) request;
- LcmRequest appcRequest = dmaapRequest.getBody();
- assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("1"));
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Accept
- //
- LcmResponseWrapper dmaapResponse = new LcmResponseWrapper();
- LcmResponse appcResponse = new LcmResponse(appcRequest);
- appcResponse.getStatus().setCode(100);
- appcResponse.getStatus().setMessage("ACCEPT");
- dmaapResponse.setBody(appcResponse);
- //
- //
- //
- PolicyResult result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertTrue(result == null);
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Now we are going to Fail it
- //
- appcResponse = new LcmResponse(appcRequest);
- appcResponse.getStatus().setCode(401);
- appcResponse.getStatus().setMessage("AppC failed for some reason");
- dmaapResponse.setBody(appcResponse);
- result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertTrue(result.equals(PolicyResult.FAILURE));
- assertFalse(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- //
- // Retry it
- //
- request = manager.startOperation(onset);
- logger.debug("{}", manager);
- assertNotNull(request);
- assertTrue(request instanceof LcmRequestWrapper);
- dmaapRequest = (LcmRequestWrapper) request;
- appcRequest = dmaapRequest.getBody();
- assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("2"));
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- //
- //
- appcResponse = new LcmResponse(appcRequest);
- logger.debug("{}", manager);
- appcResponse.getStatus().setCode(100);
- appcResponse.getStatus().setMessage("ACCEPT");
- dmaapResponse.setBody(appcResponse);
- //
- //
- //
- result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertTrue(result == null);
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Now we are going to Fail it
- //
- appcResponse = new LcmResponse(appcRequest);
- appcResponse.getStatus().setCode(401);
- appcResponse.getStatus().setMessage("AppC failed for some reason");
- dmaapResponse.setBody(appcResponse);
- result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertTrue(result.equals(PolicyResult.FAILURE));
- //
- // Should be complete now
- //
- assertTrue(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- assertNotNull(manager.getOperationResult());
- assertTrue(manager.getOperationResult().equals(PolicyResult.FAILURE_RETRIES));
- assertTrue(manager.getHistory().size() == 2);
- } catch (ControlLoopException | AaiException e) {
- fail(e.getMessage());
- }
+
+ //
+ // Create a processor
+ //
+ final ControlLoopProcessor processor = new ControlLoopProcessor(pair.value);
+ //
+ // create the manager
+ //
+ ControlLoopEventManager eventManager =
+ new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId());
+ VirtualControlLoopNotification notification = eventManager.activate(onset);
+
+ assertNotNull(notification);
+ assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
+
+ ControlLoopEventManager.NewEventStatus status = eventManager.onNewEvent(onset);
+ assertNotNull(status);
+ assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status);
+
+ ControlLoopOperationManager manager =
+ new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
+ logger.debug("{}", manager);
+ //
+ //
+ //
+ assertFalse(manager.isOperationComplete());
+ assertFalse(manager.isOperationRunning());
+ //
+ // Start
+ //
+ Object request = manager.startOperation(onset);
+ logger.debug("{}", manager);
+ assertNotNull(request);
+ assertTrue(request instanceof LcmRequestWrapper);
+ LcmRequestWrapper dmaapRequest = (LcmRequestWrapper) request;
+ LcmRequest appcRequest = dmaapRequest.getBody();
+ assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("1"));
+ assertFalse(manager.isOperationComplete());
+ assertTrue(manager.isOperationRunning());
+ //
+ // Accept
+ //
+ LcmResponseWrapper dmaapResponse = new LcmResponseWrapper();
+ LcmResponse appcResponse = new LcmResponse(appcRequest);
+ appcResponse.getStatus().setCode(100);
+ appcResponse.getStatus().setMessage(ACCEPT);
+ dmaapResponse.setBody(appcResponse);
+ //
+ //
+ //
+ PolicyResult result = manager.onResponse(dmaapResponse);
+ logger.debug("{}", manager);
+ assertTrue(result == null);
+ assertFalse(manager.isOperationComplete());
+ assertTrue(manager.isOperationRunning());
+ //
+ // Now we are going to Fail it
+ //
+ appcResponse = new LcmResponse(appcRequest);
+ appcResponse.getStatus().setCode(401);
+ appcResponse.getStatus().setMessage(APPC_FAILURE_REASON);
+ dmaapResponse.setBody(appcResponse);
+ result = manager.onResponse(dmaapResponse);
+ logger.debug("{}", manager);
+ assertTrue(result.equals(PolicyResult.FAILURE));
+ assertFalse(manager.isOperationComplete());
+ assertFalse(manager.isOperationRunning());
+ //
+ // Retry it
+ //
+ request = manager.startOperation(onset);
+ logger.debug("{}", manager);
+ assertNotNull(request);
+ assertTrue(request instanceof LcmRequestWrapper);
+ dmaapRequest = (LcmRequestWrapper) request;
+ appcRequest = dmaapRequest.getBody();
+ assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("2"));
+ assertFalse(manager.isOperationComplete());
+ assertTrue(manager.isOperationRunning());
+ //
+ //
+ //
+ appcResponse = new LcmResponse(appcRequest);
+ logger.debug("{}", manager);
+ appcResponse.getStatus().setCode(100);
+ appcResponse.getStatus().setMessage(ACCEPT);
+ dmaapResponse.setBody(appcResponse);
+ //
+ //
+ //
+ result = manager.onResponse(dmaapResponse);
+ logger.debug("{}", manager);
+ assertTrue(result == null);
+ assertFalse(manager.isOperationComplete());
+ assertTrue(manager.isOperationRunning());
+ //
+ // Now we are going to Fail it
+ //
+ appcResponse = new LcmResponse(appcRequest);
+ appcResponse.getStatus().setCode(401);
+ appcResponse.getStatus().setMessage(APPC_FAILURE_REASON);
+ dmaapResponse.setBody(appcResponse);
+ result = manager.onResponse(dmaapResponse);
+ logger.debug("{}", manager);
+ assertTrue(result.equals(PolicyResult.FAILURE));
+ //
+ // Should be complete now
+ //
+ assertTrue(manager.isOperationComplete());
+ assertFalse(manager.isOperationRunning());
+ assertNotNull(manager.getOperationResult());
+ assertTrue(manager.getOperationResult().equals(PolicyResult.FAILURE_RETRIES));
+ assertTrue(manager.getHistory().size() == 2);
}
@Test
- public void testTimeout() {
+ public void testTimeout() throws Exception {
//
// Load up the policy
//
- final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml("src/test/resources/test.yaml");
+ final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML);
onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName());
- try {
- //
- // Create a processor
- //
- final ControlLoopProcessor processor = new ControlLoopProcessor(pair.value);
- //
- // create the manager
- //
- ControlLoopEventManager eventManager =
- new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId());
- VirtualControlLoopNotification notification = eventManager.activate(onset);
-
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- ControlLoopEventManager.NewEventStatus status = null;
- try {
- status = eventManager.onNewEvent(onset);
- } catch (AaiException e) {
- logger.warn(e.toString());
- fail("A&AI Query Failed");
- }
- assertNotNull(status);
- assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status);
-
- ControlLoopOperationManager manager =
- new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
- //
- //
- //
- logger.debug("{}", manager);
- assertFalse(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- //
- // Start
- //
- Object request = manager.startOperation(onset);
- logger.debug("{}", manager);
- assertNotNull(request);
- assertTrue((request) instanceof LcmRequestWrapper);
- LcmRequestWrapper dmaapRequest = (LcmRequestWrapper) request;
- LcmRequest appcRequest = dmaapRequest.getBody();
- assertTrue((appcRequest).getCommonHeader().getSubRequestId().contentEquals("1"));
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Accept
- //
- LcmResponseWrapper dmaapResponse = new LcmResponseWrapper();
- LcmResponse appcResponse = new LcmResponse(appcRequest);
- dmaapResponse.setBody(appcResponse);
- appcResponse.getStatus().setCode(100);
- appcResponse.getStatus().setMessage("ACCEPT");
- //
- //
- //
- PolicyResult result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertTrue(result == null);
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Now we are going to simulate Timeout
- //
- manager.setOperationHasTimedOut();
- logger.debug("{}", manager);
- assertTrue(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- assertTrue(manager.getHistory().size() == 1);
- assertTrue(manager.getOperationResult().equals(PolicyResult.FAILURE_TIMEOUT));
- //
- // Now we are going to Fail the previous request
- //
- appcResponse = new LcmResponse(appcRequest);
- appcResponse.getStatus().setCode(401);
- appcResponse.getStatus().setMessage("AppC failed for some reason");
- dmaapResponse.setBody(appcResponse);
- result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- //
- //
- //
- assertTrue(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- assertTrue(manager.getHistory().size() == 1);
- assertTrue(manager.getOperationResult().equals(PolicyResult.FAILURE_TIMEOUT));
- } catch (ControlLoopException | AaiException e) {
- fail(e.getMessage());
- }
+
+ //
+ // Create a processor
+ //
+ final ControlLoopProcessor processor = new ControlLoopProcessor(pair.value);
+ //
+ // create the manager
+ //
+ ControlLoopEventManager eventManager =
+ new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId());
+ VirtualControlLoopNotification notification = eventManager.activate(onset);
+
+ assertNotNull(notification);
+ assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
+
+ ControlLoopEventManager.NewEventStatus status = eventManager.onNewEvent(onset);
+ assertNotNull(status);
+ assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status);
+
+ ControlLoopOperationManager manager =
+ new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
+ //
+ //
+ //
+ logger.debug("{}", manager);
+ assertFalse(manager.isOperationComplete());
+ assertFalse(manager.isOperationRunning());
+ //
+ // Start
+ //
+ Object request = manager.startOperation(onset);
+ logger.debug("{}", manager);
+ assertNotNull(request);
+ assertTrue((request) instanceof LcmRequestWrapper);
+ LcmRequestWrapper dmaapRequest = (LcmRequestWrapper) request;
+ LcmRequest appcRequest = dmaapRequest.getBody();
+ assertTrue((appcRequest).getCommonHeader().getSubRequestId().contentEquals("1"));
+ assertFalse(manager.isOperationComplete());
+ assertTrue(manager.isOperationRunning());
+ //
+ // Accept
+ //
+ LcmResponseWrapper dmaapResponse = new LcmResponseWrapper();
+ LcmResponse appcResponse = new LcmResponse(appcRequest);
+ dmaapResponse.setBody(appcResponse);
+ appcResponse.getStatus().setCode(100);
+ appcResponse.getStatus().setMessage(ACCEPT);
+ //
+ //
+ //
+ PolicyResult result = manager.onResponse(dmaapResponse);
+ logger.debug("{}", manager);
+ assertTrue(result == null);
+ assertFalse(manager.isOperationComplete());
+ assertTrue(manager.isOperationRunning());
+ //
+ // Now we are going to simulate Timeout
+ //
+ manager.setOperationHasTimedOut();
+ logger.debug("{}", manager);
+ assertTrue(manager.isOperationComplete());
+ assertFalse(manager.isOperationRunning());
+ assertTrue(manager.getHistory().size() == 1);
+ assertTrue(manager.getOperationResult().equals(PolicyResult.FAILURE_TIMEOUT));
+ //
+ // Now we are going to Fail the previous request
+ //
+ appcResponse = new LcmResponse(appcRequest);
+ appcResponse.getStatus().setCode(401);
+ appcResponse.getStatus().setMessage(APPC_FAILURE_REASON);
+ dmaapResponse.setBody(appcResponse);
+ manager.onResponse(dmaapResponse);
+ logger.debug("{}", manager);
+ //
+ //
+ //
+ assertTrue(manager.isOperationComplete());
+ assertFalse(manager.isOperationRunning());
+ assertTrue(manager.getHistory().size() == 1);
+ assertTrue(manager.getOperationResult().equals(PolicyResult.FAILURE_TIMEOUT));
}
@Test
@@ -392,13 +376,13 @@ public class ControlLoopOperationManagerTest {
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager =
new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
@@ -425,80 +409,55 @@ public class ControlLoopOperationManagerTest {
final Target savedTarget = policy.getTarget();
policy.setTarget(null);
- try {
- clom.getTarget(policy);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("The target is null", e.getMessage());
- }
+ assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("The target is null");
policy.setTarget(new Target());
- try {
- clom.getTarget(policy);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("The target type is null", e.getMessage());
- }
+ assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("The target type is null");
policy.setTarget(savedTarget);
policy.getTarget().setType(TargetType.PNF);
- try {
- clom.getTarget(policy);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("PNF target is not supported", e.getMessage());
- }
+ assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("PNF target is not supported");
onsetEvent.setTarget("Oz");
- onsetEvent.getAai().remove("generic-vnf.vnf-name");
- onsetEvent.getAai().remove("generic-vnf.vnf-id");
- onsetEvent.getAai().remove("vserver.vserver-name");
+ onsetEvent.getAai().remove(VNF_NAME);
+ onsetEvent.getAai().remove(VNF_ID);
+ onsetEvent.getAai().remove(VSERVER_NAME);
policy.getTarget().setType(TargetType.VNF);
- try {
- clom.getTarget(policy);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("Target does not match target type", e.getMessage());
- }
+ assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("Target does not match target type");
- onsetEvent.setTarget("vserver.vserver-name");
- onsetEvent.getAai().put("vserver.vserver-name", "OzVServer");
+ onsetEvent.setTarget(VSERVER_NAME);
+ onsetEvent.getAai().put(VSERVER_NAME, "OzVServer");
assertEquals("OzVServer", clom.getTarget(policy));
- onsetEvent.getAai().remove("vserver.vserver-name");
- onsetEvent.setTarget("generic-vnf.vnf-id");
- onsetEvent.getAai().put("generic-vnf.vnf-id", "OzVNF");
- assertEquals("OzVNF", clom.getTarget(policy));
+ onsetEvent.getAai().remove(VSERVER_NAME);
+ onsetEvent.setTarget(VNF_ID);
+ onsetEvent.getAai().put(VNF_ID, OZ_VNF);
+ assertEquals(OZ_VNF, clom.getTarget(policy));
- onsetEvent.setTarget("generic-vnf.vnf-name");
- assertEquals("OzVNF", clom.getTarget(policy));
+ onsetEvent.setTarget(VNF_NAME);
+ assertEquals(OZ_VNF, clom.getTarget(policy));
manager.onNewEvent(onsetEvent);
- onsetEvent.getAai().remove("generic-vnf.vnf-id");
+ onsetEvent.getAai().remove(VNF_ID);
manager.getVnfResponse();
if (!Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- clom.getEventManager().getVnfResponse().setVnfId("generic-vnf.vnf-id");
- assertEquals("generic-vnf.vnf-id", clom.getTarget(policy));
+ clom.getEventManager().getVnfResponse().setVnfId(VNF_ID);
+ assertEquals(VNF_ID, clom.getTarget(policy));
}
policy.getTarget().setType(TargetType.VFC);
- try {
- clom.getTarget(policy);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("The target type is not supported", e.getMessage());
- }
+ assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("The target type is not supported");
assertEquals(Integer.valueOf(20), clom.getOperationTimeout());
assertEquals("20s", clom.getOperationTimeoutString(100));
assertEquals(null, clom.getOperationMessage());
- assertEquals(null, clom.getOperationMessage("The Wizard Escaped"));
+ assertEquals(null, clom.getOperationMessage(OPER_MSG));
clom.startOperation(onsetEvent);
@@ -506,8 +465,8 @@ public class ControlLoopOperationManagerTest {
clom.getOperationMessage());
assertEquals(
"actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1, Guard result: "
- + "The Wizard Escaped",
- clom.getOperationMessage("The Wizard Escaped"));
+ + OPER_MSG,
+ clom.getOperationMessage(OPER_MSG));
assertEquals("actor=SO,operation=Restart,tar", clom.getOperationHistory().substring(0, 30));
@@ -517,18 +476,18 @@ public class ControlLoopOperationManagerTest {
@Test
public void testConstructor() throws IOException, ControlLoopException, AaiException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager =
new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
@@ -542,12 +501,8 @@ public class ControlLoopOperationManagerTest {
policy.setRecipe("ModifyConfig");
policy.getTarget().setResourceID(UUID.randomUUID().toString());
- try {
- new ControlLoopOperationManager(onsetEvent, policy, manager);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("Target vnf-id could not be found", e.getMessage());
- }
+ assertThatThrownBy(() -> new ControlLoopOperationManager(onsetEvent, policy, manager))
+ .hasMessage("Target vnf-id could not be found");
policy.getTarget().setResourceID("82194af1-3c2c-485a-8f44-420e22a9eaa4");
clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
@@ -562,29 +517,25 @@ public class ControlLoopOperationManagerTest {
clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
assertNotNull(clom);
- policy.setActor("Dorothy");
- try {
- new ControlLoopOperationManager(onsetEvent, policy, manager);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("ControlLoopEventManager: policy has an unknown actor.", e.getMessage());
- }
+ policy.setActor(DOROTHY);
+ assertThatThrownBy(() -> new ControlLoopOperationManager(onsetEvent, policy, manager))
+ .hasMessage("ControlLoopEventManager: policy has an unknown actor.");
}
@Test
public void testStartOperation() throws IOException, ControlLoopException, AaiException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager =
new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
@@ -597,13 +548,9 @@ public class ControlLoopOperationManagerTest {
assertNotNull(clom);
clom.startOperation(onsetEvent);
-
- try {
- clom.startOperation(onsetEvent);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("current operation is not null (an operation is already running)", e.getMessage());
- }
+ ControlLoopOperationManager clom2 = clom;
+ assertThatThrownBy(() -> clom2.startOperation(onsetEvent))
+ .hasMessage("current operation is not null (an operation is already running)");
clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
assertNotNull(clom);
@@ -619,12 +566,9 @@ public class ControlLoopOperationManagerTest {
clom.startOperation(onsetEvent);
clom.setOperationHasTimedOut();
assertTrue(clom.isOperationComplete());
- try {
- clom.startOperation(onsetEvent);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("current operation failed and retries are not allowed", e.getMessage());
- }
+ ControlLoopOperationManager clom3 = clom;
+ assertThatThrownBy(() -> clom3.startOperation(onsetEvent))
+ .hasMessage("current operation failed and retries are not allowed");
policy.setRetry(0);
clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
@@ -632,12 +576,9 @@ public class ControlLoopOperationManagerTest {
clom.startOperation(onsetEvent);
clom.setOperationHasTimedOut();
assertTrue(clom.isOperationComplete());
- try {
- clom.startOperation(onsetEvent);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("current operation failed and retries are not allowed", e.getMessage());
- }
+ ControlLoopOperationManager clom4 = clom;
+ assertThatThrownBy(() -> clom4.startOperation(onsetEvent))
+ .hasMessage("current operation failed and retries are not allowed");
policy.setRetry(1);
clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
@@ -647,12 +588,9 @@ public class ControlLoopOperationManagerTest {
clom.startOperation(onsetEvent);
clom.setOperationHasTimedOut();
assertTrue(clom.isOperationComplete());
- try {
- clom.startOperation(onsetEvent);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("current oepration has failed after 2 retries", e.getMessage());
- }
+ ControlLoopOperationManager clom5 = clom;
+ assertThatThrownBy(() -> clom5.startOperation(onsetEvent))
+ .hasMessage("current oepration has failed after 2 retries");
clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
assertNotNull(clom);
@@ -667,28 +605,25 @@ public class ControlLoopOperationManagerTest {
clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
assertNotNull(clom);
policy.setActor("Oz");
- try {
- clom.startOperation(onsetEvent);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("invalid actor Oz on policy", e.getMessage());
- }
+ ControlLoopOperationManager clom6 = clom;
+ assertThatThrownBy(() -> clom6.startOperation(onsetEvent))
+ .hasMessage("invalid actor Oz on policy");
}
@Test
public void testOnResponse() throws IOException, ControlLoopException, AaiException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager =
new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
@@ -770,18 +705,18 @@ public class ControlLoopOperationManagerTest {
@Test
public void testCompleteOperation() throws ControlLoopException, AaiException, IOException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager =
new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
@@ -801,34 +736,32 @@ public class ControlLoopOperationManagerTest {
PolicyEngine.manager.setEnvironmentProperty("guard.disabled", "false");
PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL,
"http://somewhere.over.the.rainbow");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "Dorothy");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY);
PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto");
assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
- System.setProperty("OperationsHistoryPU", "OperationsHistoryPUTest");
+ System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST);
assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
}
@Test
- public void testCommitAbatement() throws ControlLoopException, AaiException, IOException {
+ public void testCommitAbatement() throws Exception {
String yamlString = null;
- try (InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"))) {
+ try (InputStream is = new FileInputStream(new File(TEST_YAML))) {
yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- } catch (Exception e) {
- fail(e.getMessage());
}
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager =
new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
@@ -850,23 +783,24 @@ public class ControlLoopOperationManagerTest {
int numEventsAfter = getCount();
logger.info("numEventsAfter={}", numEventsAfter);
- assertEquals(1, numEventsAfter - numEventsBefore);
+ int diff = numEventsAfter - numEventsBefore;
+ assertEquals(1, diff);
}
@Test
public void testSerialization() throws Exception {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ InputStream is = new FileInputStream(new File(TEST_YAML));
final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setTarget(VNF_ID);
onsetEvent.setClosedLoopAlarmStart(Instant.now());
onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+ onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
ControlLoopEventManager manager =
new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
@@ -891,7 +825,7 @@ public class ControlLoopOperationManagerTest {
PolicyEngine.manager.setEnvironmentProperty("guard.disabled", "false");
PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL,
"http://somewhere.over.the.rainbow");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "Dorothy");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY);
PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto");
assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
@@ -903,7 +837,7 @@ public class ControlLoopOperationManagerTest {
assertFalse(clom.isOperationRunning());
assertEquals(1, clom.getHistory().size());
- System.setProperty("OperationsHistoryPU", "OperationsHistoryPUTest");
+ System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST);
assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
clom = Serializer.roundTrip(clom);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
index 2a6dc7bbd..84fe44914 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* unit test
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,17 +20,15 @@
package org.onap.policy.controlloop.processor;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.onap.policy.controlloop.ControlLoopException;
@@ -56,13 +54,8 @@ public class ControlLoopProcessorTest {
InputStream is = new FileInputStream(new File("src/test/resources/string.yaml"));
String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- try {
- new ControlLoopProcessor(yamlString);
- fail("test should thrown an exception");
- } catch (Exception e) {
- assertEquals("Cannot create property=string for JavaBean=ControlLoopPolicy",
- e.getMessage().substring(0, 60));
- }
+ assertThatThrownBy(() -> new ControlLoopProcessor(yamlString))
+ .hasMessageStartingWith("Cannot create property=string for JavaBean=ControlLoopPolicy");
}
@Test
@@ -73,12 +66,8 @@ public class ControlLoopProcessorTest {
ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
assertNull(clProcessor.getCurrentPolicy());
- try {
- clProcessor.nextPolicyForResult(PolicyResult.SUCCESS);
- fail("test shold throw an exception here");
- } catch (ControlLoopException e) {
- assertEquals("There is no current policy to determine where to go to.", e.getMessage());
- }
+ assertThatThrownBy(() -> clProcessor.nextPolicyForResult(PolicyResult.SUCCESS))
+ .hasMessageStartingWith("There is no current policy to determine where to go to.");
}
@Test
@@ -87,13 +76,8 @@ public class ControlLoopProcessorTest {
String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
-
- try {
- clProcessor.getCurrentPolicy();
- fail("test shold throw an exception here");
- } catch (ControlLoopException e) {
- assertEquals("There are no policies defined.", e.getMessage());
- }
+ assertThatThrownBy(clProcessor::getCurrentPolicy)
+ .hasMessage("There are no policies defined.");
}
@Test
@@ -128,7 +112,7 @@ public class ControlLoopProcessorTest {
/**
* Test policies in the given yaml following the successfull path.
- *
+ *
* @param yaml yaml containing the policies to test
* @throws ControlLoopException if an error occurs
*/
@@ -150,7 +134,7 @@ public class ControlLoopProcessorTest {
/**
* Test policies in the given yaml following the failure path.
- *
+ *
* @param yaml yaml containing the policies to test
* @throws ControlLoopException if an error occurs
*/
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
index 72e51bae9..47907d9c3 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
@@ -22,12 +22,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import org.junit.Test;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.controlloop.params.ControlLoopParams;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -35,7 +33,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
public class ControlLoopUtilsTest {
@Test
- public void toControlLoopParams() throws IOException, CoderException {
+ public void toControlLoopParams() throws Exception {
String policy =
new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-operational-restart.json")));
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java
index dcf3e6c95..cc5302f61 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java
@@ -3,6 +3,7 @@
* eventmanager
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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,40 +35,43 @@ import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.drools.impl.PolicyEngineJUnitImpl;
public class DroolsPolicyEngineTest {
+ private static final String TOPIC = "TheWizardOfOz";
+ private static final String OMNI_BUS = "OmniBus";
+
@Test
public void testDroolsPolicyEngine() {
PolicyEngineJUnitImpl pe = new PolicyEngineJUnitImpl();
assertNotNull(pe);
pe.addListener(new TestPolicyEngineListener());
- pe.notifyListeners("TheWizardOfOz");
+ pe.notifyListeners(TOPIC);
- pe.subscribe("OmniBus", "TheWizardOfOz");
+ pe.subscribe(OMNI_BUS, TOPIC);
- pe.deliver("OmniBus", "TheWizardOfOz", "Dorothy");
+ pe.deliver(OMNI_BUS, TOPIC, "Dorothy");
- pe.subscribe("OmniBus", "TheWizardOfOz");
- pe.subscribe("OmniBus", "ThisTopicDoesNotExist");
+ pe.subscribe(OMNI_BUS, TOPIC);
+ pe.subscribe(OMNI_BUS, "ThisTopicDoesNotExist");
ControlLoopNotification notification = new VirtualControlLoopNotification();
- pe.deliver("OmniBus", "TheWizardOfOz", notification);
+ pe.deliver(OMNI_BUS, TOPIC, notification);
Request request = new Request();
request.setCommonHeader(new CommonHeader());
request.getCommonHeader().setSubRequestId("12321");
- pe.deliver("OmniBus", "TheWizardOfOz", request);
+ pe.deliver(OMNI_BUS, TOPIC, request);
LcmRequestWrapper lcmRw = new LcmRequestWrapper();
lcmRw.setBody(new LcmRequest());
lcmRw.getBody().setCommonHeader(new LcmCommonHeader());
lcmRw.getBody().getCommonHeader().setSubRequestId("54321");
- pe.deliver("OmniBus", "TheWizardOfOz", lcmRw);
+ pe.deliver(OMNI_BUS, TOPIC, lcmRw);
}
private class TestPolicyEngineListener implements PolicyEngineListener {
@Override
public void newEventNotification(String topic) {
- assertEquals("TheWizardOfOz", topic);
+ assertEquals(TOPIC, topic);
}
}
}
diff --git a/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml
index e1aa93f51..07dafecbb 100644
--- a/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml
+++ b/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml
@@ -18,25 +18,25 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
<!-- In-mem DB for junit -->
- <persistence-unit name="OperationsHistoryPUTest"
- transaction-type="RESOURCE_LOCAL">
+ <persistence-unit name="OperationsHistoryPUTest" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>org.onap.policy.database.operationshistory.Dbao</class>
+ <class>org.onap.policy.database.operationshistory.Dbao</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.logging.level" value="FINE" />
- <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE" />
<property name="javax.persistence.jdbc.user" value="policy" />
<property name="javax.persistence.jdbc.password" value="P01icY" />
- <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
- <property name="javax.persistence.schema-generation.create-source" value="metadata"/>
+ <property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
+ <property name="javax.persistence.schema-generation.create-source" value="metadata" />
</properties>
</persistence-unit>