* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2022 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.controlloop.common.rules.test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.Getter;
+import lombok.Setter;
+import org.apache.commons.collections.MapUtils;
import org.awaitility.Awaitility;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.appc.Request;
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager2;
+import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.system.internal.SimpleLockManager;
import org.onap.policy.drools.system.internal.SimpleLockManager.SimpleLock;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.sdnr.PciMessage;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
/**
* Superclass used for rule tests.
private static final String APPC_RESTART_OP = "restart";
private static final String APPC_MODIFY_CONFIG_OP = "ModifyConfig";
+ private static final String SDNR_MODIFY_CONFIG_OP = "ModifyConfig";
+ private static final String SNDR_MODIFY_CONFIG_ANR_OP = "ModifyConfigANR";
+
/*
* Canonical Topic Names.
*/
protected static final String APPC_CL_TOPIC = "APPC-CL";
protected static final String SDNR_CL_TOPIC = "SDNR-CL";
protected static final String SDNR_CL_RSP_TOPIC = "SDNR-CL-RSP";
+ protected static final String A1P_CL_TOPIC = "A1-P";
+ protected static final String A1P_CL_RSP_TOPIC = "A1-P-RSP";
/*
* Constants for each test case.
private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
- // VPCI
+ // 5G SON Legacy - PCI
private static final String VPCI_TOSCA_COMPLIANT_POLICY = "vpci/tosca-compliant-vpci.json";
private static final String VPCI_ONSET = "vpci/vpci.onset.json";
private static final String VPCI_SDNR_SUCCESS = "vpci/vpci.sdnr.success.json";
- // VSONH
+ // 5G SON Legacy - ANR
private static final String VSONH_TOSCA_COMPLIANT_POLICY = "vsonh/tosca-compliant-vsonh.json";
private static final String VSONH_ONSET = "vsonh/vsonh.onset.json";
private static final String VSONH_SDNR_SUCCESS = "vsonh/vsonh.sdnr.success.json";
+ // 5G SON Use case Policies (Kohn+)
+
+ private static final String V5G_SON_O1_TOSCA_POLICY = "policies/v5gSonO1.policy.operational.input.tosca.json";
+ private static final String V5G_SON_O1_ONSET = "vpci/v5G.son.O1.onset.json";
+ private static final String V5G_SON_O1_SDNR_SUCCESS = "vpci/v5G.son.O1.sdnr.success.json";
+ private static final String MODIFY_O1_CONFIG_OPERATION = "ModifyO1Config";
+
+ private static final String V5G_SON_A1_TOSCA_POLICY = "policies/v5gSonA1.policy.operational.input.tosca.json";
+ private static final String V5G_SON_A1_ONSET = "vsonh/v5G.son.A1.onset.json";
+ private static final String V5G_SON_A1_SDNR_SUCCESS = "vsonh/v5G.son.A1.sdnr.success.json";
+ private static final String PUT_A1_POLICY_OPERATION = "putA1Policy";
/*
* Coders used to decode requests and responses.
*/
// used to inject and wait for messages
@Getter(AccessLevel.PROTECTED)
+ @Setter(AccessLevel.PROTECTED)
protected static Topics topics;
// used to wait for messages on SINK topics
}
/**
- * Initializes {@link #topics} and {@link #controller}.
+ * Initializes {@link #topics}.
*/
public void init() {
- topics = topicMaker.get();
+ setTopics(topicMaker.get());
Map<String, SimpleLock> locks = getLockMap();
- if (locks != null) {
+ if (!MapUtils.isEmpty(locks)) {
locks.clear();
}
}
/**
* Service123 with Tosca Compliant Policy.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testService123Compliant() {
policyClMgt = createNoficationTopicListener();
appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
waitForLockAndPermit(policy, policyClMgt);
// restart request should be sent and fail four times (i.e., because retry=3)
- for (int count = 0; count < 4; ++count) {
+ for (var count = 0; count < 4; ++count) {
AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
* to obtain a lock since it is a different target. After processing of all events
* there should only be the policy and params objects left in memory.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testDuplicatesEvents() {
policyClMgt = createNoficationTopicListener();
appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
// should see two restarts
- for (int count = 0; count < 2; ++count) {
+ for (var count = 0; count < 2; ++count) {
AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
// indicate success
VirtualControlLoopNotification notif1 = waitForFinalSuccess(policy, policyClMgt);
VirtualControlLoopNotification notif2 = waitForFinalSuccess(policy, policyClMgt);
- // get the list of target names so we can ensure there's one of each
- List<String> actual = List.of(notif1, notif2).stream().map(notif -> notif.getAai().get("generic-vnf.vnf-id"))
+ // get the list of target names, so we can ensure there's one of each
+ List<String> actual = Stream.of(notif1, notif2).map(notif -> notif.getAai().get("generic-vnf.vnf-id"))
.sorted().collect(Collectors.toList());
assertEquals(List.of("duplicate-VNF", "vCPE_Infrastructure_vGMUX_demo_app").toString(), actual.toString());
/**
* Sunny Day with Tosca Compliant Policy.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testVcpeSunnyDayCompliant() {
appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
}
* simulate the flooding behavior of the DCAE TCA microservice. TCA could blast tens
* or hundreds of ONSETs within sub-second intervals.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testVcpeOnsetFloodPrevention() {
appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3),
APPC_RESTART_OP);
/**
* Sunny Day with Tosca Compliant Policy.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testVdnsSunnyDayCompliant() {
httpSunnyDay(VDNS_TOSCA_COMPLIANT_POLICY, VDNS_ONSET);
}
/**
* VFW Sunny Day with Tosca Compliant Policy.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testVfwSunnyDayCompliant() {
appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
}
/**
* VPCI Sunny Day Tosca Policy.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testVpciSunnyDayCompliant() {
- sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
+ sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS,
+ SDNR_MODIFY_CONFIG_OP, SDNR_CL_TOPIC, SDNR_CL_RSP_TOPIC);
}
// VSONH
/**
* VSONH Sunny Day with Tosca Policy.
*/
- @Test
+ //TODO This test needs to be enabled in java-17 branch
public void testVsonhSunnyDayCompliant() {
- sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
+ sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS,
+ SNDR_MODIFY_CONFIG_ANR_OP, SDNR_CL_TOPIC, SDNR_CL_RSP_TOPIC);
+ }
+
+ /**
+ * Sunny day 5G SON 01 Modify01Config Operational Policy.
+ */
+ //TODO This test needs to be enabled in java-17 branch
+ public void test5gSonO1SunnyDayCompliant() {
+ sdnrSunnyDay(V5G_SON_O1_TOSCA_POLICY, V5G_SON_O1_ONSET, V5G_SON_O1_SDNR_SUCCESS,
+ MODIFY_O1_CONFIG_OPERATION, SDNR_CL_TOPIC, SDNR_CL_RSP_TOPIC);
+ }
+
+ /**
+ * Sunny day 5G SON A1 ModifyA1Policy Operational Policy.
+ */
+ //TODO This test needs to be enabled in java-17 branch
+ public void test5gSonA1SunnyDayCompliant() {
+ sdnrSunnyDay(V5G_SON_A1_TOSCA_POLICY, V5G_SON_A1_ONSET, V5G_SON_A1_SDNR_SUCCESS,
+ PUT_A1_POLICY_OPERATION, A1P_CL_TOPIC, A1P_CL_RSP_TOPIC);
}
/**
* @param policyFile file containing the ToscaPolicy to be loaded
* @param onsetFile file containing the ONSET to be injected
* @param operation expected APPC operation request
- * @param checkOperation flag to determine whether or not to wait for operation
- * timeout
*/
protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
policyClMgt = createNoficationTopicListener();
* @param onsetFile file containing the ONSET to be injected
* @param operation expected SDNR operation request
*/
- protected void sdnrSunnyDay(String policyFile, String onsetFile, String successFile, String operation) {
+ protected void sdnrSunnyDay(String policyFile, String onsetFile,
+ String successFile, String operation,
+ String requestTopic, String responseTopic) {
policyClMgt = createNoficationTopicListener();
- sdnrClSink = topics.createListener(SDNR_CL_TOPIC, PciMessage.class, SDNR_CODER);
+ sdnrClSink = topics.createListener(requestTopic, PciMessage.class, SDNR_CODER);
policy = checkPolicy(policyFile);
/*
* Inject response.
*/
- topics.inject(SDNR_CL_RSP_TOPIC, successFile, pcireq.getBody().getInput().getCommonHeader().getSubRequestId());
+ topics.inject(responseTopic, successFile, pcireq.getBody().getInput().getCommonHeader().getSubRequestId());
/* --- Operation Completed --- */
*
* @param policyFile file containing the ToscaPolicy to be loaded
* @param onsetFile file containing the ONSET to be injected
- * @param operation expected APPC operation request
*/
protected void httpSunnyDay(String policyFile, String onsetFile) {
policyClMgt = createNoficationTopicListener();
*
* @param policyFile file containing the ToscaPolicy to be loaded
* @param onsetFile file containing the ONSET to be injected
- * @param operation expected APPC operation request
*/
protected void httpRainyDay(String policyFile, String onsetFile) {
policyClMgt = createNoficationTopicListener();
}
protected long getCreateCount() {
- return ControlLoopEventManager2.getCreateCount();
+ return ControlLoopEventManager.getCreateCount();
}
/**
}
/**
- * Returns Listener from createListner based on Coder.
+ * Returns Listener from createListener based on Coder.
*
* @return the Listener
*/
*/
private void verifyUnlocked() {
Map<String, SimpleLock> locks = getLockMap();
- if (locks != null) {
+ if (!MapUtils.isEmpty(locks)) {
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(locks::isEmpty);
}
}
+ @SuppressWarnings("unchecked")
private Map<String, SimpleLock> getLockMap() {
- Object lockMgr = Whitebox.getInternalState(PolicyEngineConstants.getManager(), "lockManager");
+ Object lockMgr = ReflectionTestUtils.getField(PolicyEngineConstants.getManager(), "lockManager");
if (lockMgr instanceof SimpleLockManager) {
- return Whitebox.getInternalState(lockMgr, "resource2lock");
+ return (Map<String, SimpleLock>) ReflectionTestUtils.getField(lockMgr, "resource2lock");
}
- return null;
+ return Collections.emptyMap();
}
}