Search in sources :

Example 1 with UrlRewriteCheckDescriptor

use of org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptor in project knox by apache.

the class XmlUrlRewriteRulesExporterTest method testCheckStep.

@Test
public void testCheckStep() throws Exception {
    UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteRuleDescriptor rule = rules.addRule("test-rule");
    UrlRewriteCheckDescriptor step = rule.addStep("check");
    step.operation("test-operation").input("test-input").value("test-value").flow("all");
    StringWriter writer = new StringWriter();
    UrlRewriteRulesDescriptorFactory.store(rules, "xml", writer);
    String str = writer.toString();
    // System.out.println( str );
    Source xml = XmlConverters.the(str);
    assertThat(xml, XmlMatchers.hasXPath("/rules"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule"));
    assertThat(xml, XmlMatchers.hasXPath("count(/rules/rule)", is("1")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@name", is("test-rule")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/@oper", is("test-operation")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/@input", is("test-input")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/@value", is("test-value")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/@flow", is("ALL")));
}
Also used : UrlRewriteRuleDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor) StringWriter(java.io.StringWriter) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) UrlRewriteCheckDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptor) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 2 with UrlRewriteCheckDescriptor

use of org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptor in project knox by apache.

the class XmlUrlRewriteRulesExporterTest method testNestedStep.

@Test
public void testNestedStep() throws Exception {
    UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteRuleDescriptor rule = rules.addRule("test-rule");
    UrlRewriteMatchDescriptor match = rule.addStep("match");
    UrlRewriteMatchDescriptor matchMatch = match.addStep("match");
    UrlRewriteCheckDescriptor matchCheck = match.addStep("check");
    UrlRewriteControlDescriptor matchControl = match.addStep("control");
    UrlRewriteActionDescriptor matchRewrite = match.addStep("rewrite");
    UrlRewriteCheckDescriptor check = rule.addStep("check");
    UrlRewriteMatchDescriptor checkMatch = check.addStep("match");
    UrlRewriteCheckDescriptor checkCheck = check.addStep("check");
    UrlRewriteControlDescriptor checkControl = check.addStep("control");
    UrlRewriteActionDescriptor checkRewrite = check.addStep("rewrite");
    UrlRewriteControlDescriptor control = rule.addStep("control");
    UrlRewriteMatchDescriptor controlMatch = control.addStep("match");
    UrlRewriteCheckDescriptor controlCheck = control.addStep("check");
    UrlRewriteControlDescriptor controlControl = control.addStep("control");
    UrlRewriteActionDescriptor controlRewrite = control.addStep("rewrite");
    UrlRewriteActionDescriptor rewrite = rule.addStep("rewrite");
    StringWriter writer = new StringWriter();
    UrlRewriteRulesDescriptorFactory.store(rules, "xml", writer);
    String str = writer.toString();
    // System.out.println( str );
    Source xml = XmlConverters.the(str);
    assertThat(xml, XmlMatchers.hasXPath("/rules"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule"));
    assertThat(xml, XmlMatchers.hasXPath("count(/rules/rule)", is("1")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@name", is("test-rule")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/rewrite"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/rewrite"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/rewrite"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/rewrite"));
}
Also used : UrlRewriteMatchDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor) UrlRewriteRuleDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor) StringWriter(java.io.StringWriter) UrlRewriteControlDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteControlDescriptor) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) UrlRewriteActionDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteActionDescriptor) UrlRewriteCheckDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptor) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

StringWriter (java.io.StringWriter)2 Source (javax.xml.transform.Source)2 UrlRewriteRuleDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor)2 UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)2 UrlRewriteCheckDescriptor (org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptor)2 Test (org.junit.Test)2 UrlRewriteActionDescriptor (org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteActionDescriptor)1 UrlRewriteControlDescriptor (org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteControlDescriptor)1 UrlRewriteMatchDescriptor (org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor)1