use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_novars.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_novars() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("novars");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setTemplate("Hello World");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{}");
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("Hello World", policy.getDescription());
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_blacklist.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_blacklist() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("blacklist");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setTemplate("Requests that originate from the set of @{ipList.size()} configured IP address(es) will be denied access to the managed API.");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{ \"ipList\" : [ \"127.0.0.1\", \"192.168.1.10\" ] }");
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("Requests that originate from the set of 2 configured IP address(es) will be denied access to the managed API.", policy.getDescription());
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_nested2.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_nested2() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("nested2");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setTemplate("@{messages.index[0].value} @{messages.index[1].value}");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{ \"messages\" : { \"index\" : [ { \"id\" : \"first\", \"value\" : \"Hello\" }, { \"id\" : \"second\", \"value\" : \"World\" } ] } }");
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("Hello World", policy.getDescription());
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_nested.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_nested() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("nested");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setTemplate("@{messages.messageOne}");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{ \"messages\" : { \"messageOne\" : \"Hello World\" } }");
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("Hello World", policy.getDescription());
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_missingvar.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_missingvar() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("missingvar");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setTemplate("Template includes a missing var: @{missingVar}");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{}");
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("Template includes a missing var: null", policy.getDescription());
}
Aggregations