diff options
Diffstat (limited to 'controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java')
-rw-r--r-- | controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java | 132 |
1 files changed, 79 insertions, 53 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java index a4e8bef65..ab57fdf86 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java @@ -53,7 +53,6 @@ import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; - public final class SupportUtil { private static final String OPSHISTPUPROP = "OperationsHistoryPU"; @@ -155,11 +154,12 @@ public final class SupportUtil { * @return the Kie session * @throws IOException if the container cannot be built */ - public static KieSession buildContainer(String droolsTemplate, String closedLoopControlName, String policyScope, - String policyName, String policyVersion, String yamlSpecification) throws IOException { + public static KieSession buildContainer(String droolsTemplate, String closedLoopControlName, + String policyScope, String policyName, String policyVersion, String yamlSpecification) + throws IOException { - RuleSpec spec = new RuleSpec(droolsTemplate, closedLoopControlName, policyScope, policyName, policyVersion, - yamlSpecification); + RuleSpec spec = new RuleSpec(droolsTemplate, closedLoopControlName, policyScope, policyName, + policyVersion, yamlSpecification); return buildContainer(policyVersion, new RuleSpec[] {spec}); } @@ -172,7 +172,8 @@ public final class SupportUtil { * @return the Kie session * @throws IOException if the container cannot be built */ - public static KieSession buildContainer(String policyVersion, RuleSpec[] specifications) throws IOException { + public static KieSession buildContainer(String policyVersion, RuleSpec[] specifications) + throws IOException { // // Get our Drools Kie factory // @@ -196,7 +197,8 @@ public final class SupportUtil { * @param specifications new rule specifications * @throws IOException if the container cannot be built */ - public static void updateContainer(String policyVersion, RuleSpec[] specifications) throws IOException { + public static void updateContainer(String policyVersion, RuleSpec[] specifications) + throws IOException { ReleaseId releaseId = buildPolicy(policyVersion, specifications); logger.debug(releaseId.toString()); @@ -211,20 +213,22 @@ public final class SupportUtil { * @return the release * @throws IOException if the container cannot be built */ - private static ReleaseId buildPolicy(String policyVersion, RuleSpec[] specifications) throws IOException { + private static ReleaseId buildPolicy(String policyVersion, RuleSpec[] specifications) + throws IOException { // // Generate our drools rule from our template // KieFileSystem kfs = kieServices.newKieFileSystem(); ReleaseId releaseId = kieServices.getRepository().getDefaultReleaseId(); - releaseId = kieServices.newReleaseId(releaseId.getGroupId(), releaseId.getArtifactId(), policyVersion); + releaseId = kieServices.newReleaseId(releaseId.getGroupId(), releaseId.getArtifactId(), + policyVersion); kfs.generateAndWritePomXML(releaseId); for (RuleSpec spec : specifications) { String drlContents = spec.generateRules(); kfs.write("src/main/resources/" + spec.policyName + ".drl", - kieServices.getResources().newByteArrayResource(drlContents.getBytes())); + kieServices.getResources().newByteArrayResource(drlContents.getBytes())); } // @@ -247,97 +251,119 @@ public final class SupportUtil { private static KieSession setupSession(KieSession kieSession) { - // // Create XACML Guard policy from YAML - // We prepare 4 Guards. Notice that Rebuilds recipe has two Guards (for checking policy combining algorithm) + // We prepare 4 Guards. Notice that Rebuilds recipe has two Guards (for checking policy + // combining algorithm) // - PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_restart.yaml", - "src/main/resources/frequency_limiter_template.xml", - "src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml"); - - PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild.yaml", - "src/main/resources/frequency_limiter_template.xml", - "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml"); - - PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml", - "src/main/resources/frequency_limiter_template.xml", - "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml"); - - PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_migrate.yaml", - "src/main/resources/frequency_limiter_template.xml", - "src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml"); - - PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml", - "src/main/resources/frequency_limiter_template.xml", - "src/test/resources/xacml/autogenerated_frequency_limiter_modifyconfig.xml"); + PolicyGuardYamlToXacml.fromYamlToXacml( + "src/test/resources/yaml/policy_guard_appc_restart.yaml", + "src/main/resources/frequency_limiter_template.xml", + "src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml"); + + PolicyGuardYamlToXacml.fromYamlToXacml( + "src/test/resources/yaml/policy_guard_appc_rebuild.yaml", + "src/main/resources/frequency_limiter_template.xml", + "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml"); + + PolicyGuardYamlToXacml.fromYamlToXacml( + "src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml", + "src/main/resources/frequency_limiter_template.xml", + "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml"); + + PolicyGuardYamlToXacml.fromYamlToXacml( + "src/test/resources/yaml/policy_guard_appc_migrate.yaml", + "src/main/resources/frequency_limiter_template.xml", + "src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml"); + + PolicyGuardYamlToXacml.fromYamlToXacml( + "src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml", + "src/main/resources/frequency_limiter_template.xml", + "src/test/resources/xacml/autogenerated_frequency_limiter_modifyconfig.xml"); PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist( - "src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml", - "src/main/resources/blacklist_template.xml", - "src/test/resources/xacml/autogenerated_blacklist.xml"); + "src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml", + "src/main/resources/blacklist_template.xml", + "src/test/resources/xacml/autogenerated_blacklist.xml"); // // Creating an embedded XACML PDP // - System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml/xacml_guard.properties"); + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, + "src/test/resources/xacml/xacml_guard.properties"); return kieSession; } /** - * Set the A&AI properties. + * Set the A&AI properties. */ public static void setAaiProps() { - PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", "http://localhost:6666"); + PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", + "http://localhost:6666"); PolicyEngineConstants.getManager().setEnvironmentProperty("aai.username", "AAI"); PolicyEngineConstants.getManager().setEnvironmentProperty("aai.password", "AAI"); } /** - * Set the SO properties. + * Set the SO properties. */ public static void setSoProps() { - PolicyEngineConstants.getManager().setEnvironmentProperty("so.url", "http://localhost:6667"); + PolicyEngineConstants.getManager().setEnvironmentProperty("so.url", + "http://localhost:6667"); PolicyEngineConstants.getManager().setEnvironmentProperty("so.username", "SO"); PolicyEngineConstants.getManager().setEnvironmentProperty("so.password", "SO"); } /** - * Set the SDNC properties. + * Set the SDNC properties. */ public static void setSdncProps() { - PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.url", "http://localhost:6670/restconf/operations"); + PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.url", + "http://localhost:6670/restconf/operations"); PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.username", "sdnc"); PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.password", "sdnc"); } /** - * Set the Guard properties. + * Set the Guard properties. */ public static void setGuardProps() { /* * Guard PDP-x connection Properties */ - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, - "http://localhost:6669/policy/pdpx/v1/decision"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, - "false"); + PolicyEngineConstants.getManager().setEnvironmentProperty( + org.onap.policy.guard.Util.PROP_GUARD_URL, + "http://localhost:6669/policy/pdpx/v1/decision"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false"); + } + + /** + * Sets the value of customQuery Environment property. + * + * @param value of the custom query boolean. + */ + public static void setCustomQuery(String value) { + PolicyEngineConstants.getManager().setEnvironmentProperty("aai.customQuery", value); } /** - * Set the VFC properties. + * Set the VFC properties. */ public static void setVfcProps() { - PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.url", "http://localhost:6668/api/nslcm/v1"); + PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.url", + "http://localhost:6668/api/nslcm/v1"); PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.username", "VFC"); PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.password", "VFC"); } /** - * Set the operation history properties. + * Set the operation history properties. */ public static void setPuProp() { System.setProperty(OPSHISTPUPROP, "OperationsHistoryPUTest"); @@ -364,8 +390,8 @@ public final class SupportUtil { * @param policyVersion policy version * @param yamlSpecification incoming yaml specification */ - public RuleSpec(String droolsTemplate, String closedLoopControlName, String policyScope, String policyName, - String policyVersion, String yamlSpecification) { + public RuleSpec(String droolsTemplate, String closedLoopControlName, String policyScope, + String policyName, String policyVersion, String yamlSpecification) { this.droolsTemplate = droolsTemplate; this.closedLoopControlName = closedLoopControlName; |