Upgrade Java 17 in policy-drools-apps
[policy/drools-applications.git] / controlloop / common / rules-test / src / main / java / org / onap / policy / controlloop / common / rules / test / Rules.java
index 09eb58d..8272205 100644 (file)
@@ -2,7 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020-2021 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.
@@ -21,9 +22,9 @@
 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;
@@ -232,6 +233,16 @@ public class Rules {
             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);
     }