* ============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.awaitility.Awaitility.await;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.FileNotFoundException;
import org.kie.api.runtime.KieSession;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.logging.LoggerUtils;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.util.KieUtils;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
pdpdRepo.setConfigurationDir("src/test/resources/config");
try {
- File kmoduleFile = new File(resourceDir + "/META-INF/kmodule.xml");
- File pomFile = new File("src/test/resources/" + controllerName + ".pom");
- String resourceDir2 = resourceDir + "/org/onap/policy/controlloop/";
- File ruleFile = new File(resourceDir + File.separator + controllerName + ".drl");
+ var kmoduleFile = new File(resourceDir + "/META-INF/kmodule.xml");
+ var pomFile = new File("src/test/resources/" + controllerName + ".pom");
+ var resourceDir2 = resourceDir + "/org/onap/policy/controlloop/";
+ var ruleFile = new File(resourceDir + File.separator + controllerName + ".drl");
List<File> ruleFiles = Collections.singletonList(ruleFile);
installArtifact(kmoduleFile, pomFile, resourceDir2, ruleFiles);
}
private ToscaPolicy getPolicyFromTemplate(String resourcePath, String policyName) throws CoderException {
- String policyJson = ResourceUtils.getResourceAsString(resourcePath);
+ var policyJson = ResourceUtils.getResourceAsString(resourcePath);
if (policyJson == null) {
throw new CoderException(new FileNotFoundException(resourcePath));
}
* Get policy from file.
*/
public static ToscaPolicy getPolicyFromFile(String policyPath) throws CoderException {
- String policyJson = ResourceUtils.getResourceAsString(policyPath);
+ var policyJson = ResourceUtils.getResourceAsString(policyPath);
if (policyJson == null) {
throw new CoderException(new FileNotFoundException(policyPath));
}
+ if (policyPath.startsWith("policies/")) {
+ // using policy/models examples where policies are wrapped with the ToscaServiceTemplate
+ // for API component provisioning
+ logger.info("retrieving policy from policy models examples");
+ ToscaServiceTemplate template = coder.decode(policyJson, ToscaServiceTemplate.class);
+ if (template.getToscaTopologyTemplate().getPolicies().size() == 1) {
+ return template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+ }
+ }
+
return coder.decode(policyJson, ToscaPolicy.class);
}
* Sets up overall logging.
*/
private void setupLogging() {
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "WARN");
- LoggerUtil.setLevel("org.eclipse.jetty", "WARN");
- LoggerUtil.setLevel("org.onap.policy.controlloop", "INFO");
- LoggerUtil.setLevel("network", "INFO");
+ LoggerUtils.setLevel(LoggerUtils.ROOT_LOGGER, "WARN");
+ LoggerUtils.setLevel("org.eclipse.jetty", "WARN");
+ LoggerUtils.setLevel("org.onap.policy.controlloop", "INFO");
+ LoggerUtils.setLevel("network", "INFO");
}
/**
* Sets up Drools Logging for events of interest.
*/
private void setupDroolsLogging() {
- KieSession session = getKieSession();
+ var session = getKieSession();
session.addEventListener(new RuleListenerLogger());
session.addEventListener(new AgendaListenerLogger());