Search in sources :

Example 11 with UrlRewriteFilterBufferDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor in project knox by apache.

the class XmlFilterReaderTest method testSimpleBuffered.

// @Test
// public void testSimpleScoped() throws IOException, ParserConfigurationException, XMLStreamException {
// UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
// UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter( "filter-1" );
// UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent( "text/xml" );
// 
// String inputXml = "<root/>";
// StringReader inputReader = new StringReader( inputXml );
// XmlStaxFilterReader filterReader = new NoopXmlFilterReader( inputReader );
// String outputHtml = new String( IOUtils.toCharArray( filterReader ) );
// assertThat( the( outputHtml ), hasXPath( "/root" ) );
// }
@Test
public void testSimpleBuffered() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor scopeConfig = contentConfig.addBuffer("/root");
    String input = "<root/>";
    // System.out.println( "INPUT=" + input );
    StringReader inputReader = new StringReader(input);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    String output = new String(IOUtils.toCharArray(filterReader));
    // System.out.println( "OUTPUT=" + output );
    assertThat(the(output), hasXPath("/root"));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 12 with UrlRewriteFilterBufferDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor in project knox by apache.

the class XmlFilterReaderTest method testBufferedApplyForAttributes.

@Test
public void testBufferedApplyForAttributes() throws Exception {
    InputStream stream = TestUtils.getResourceStream(this.getClass(), "properties-attributes.xml");
    String input = IOUtils.toString(stream, Charset.forName("UTF-8"));
    // System.out.println( "INPUT=" + input );
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor bufferconfig = contentConfig.addBuffer("/properties/property");
    UrlRewriteFilterApplyDescriptor applyConfig = bufferconfig.addApply("@value", "test-rule-2");
    // UrlRewriteRulesDescriptorFactory.store( rulesConfig, "xml", new PrintWriter( System.out ) );
    XmlFilterReader filter = new TestXmlFilterReader(new StringReader(input), contentConfig);
    String output = IOUtils.toString(filter);
    // System.out.println( "OUTPUT=" + output );
    assertThat(the(output), hasXPath("/properties/property[1]/@name", equalTo("test-name-1")));
    assertThat(the(output), hasXPath("/properties/property[1]/@value", equalTo("attr:test-rule-2{test-value-1}")));
    assertThat(the(output), hasXPath("/properties/property[2]/@name", equalTo("test-name-2")));
    assertThat(the(output), hasXPath("/properties/property[2]/@value", equalTo("attr:test-rule-2{test-value-2}")));
    assertThat(the(output), hasXPath("/properties/property[3]/@name", equalTo("test-name-3")));
    assertThat(the(output), hasXPath("/properties/property[3]/@value", equalTo("attr:test-rule-2{test-value-3}")));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) InputStream(java.io.InputStream) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterApplyDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 13 with UrlRewriteFilterBufferDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor in project knox by apache.

the class XmlFilterReaderTest method testBufferedDetectApplyForElements.

@Test
public void testBufferedDetectApplyForElements() throws Exception {
    InputStream stream = TestUtils.getResourceStream(this.getClass(), "properties-elements.xml");
    String input = IOUtils.toString(stream, Charset.forName("UTF-8"));
    // System.out.println( "INPUT=" + input );
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor bufferConfig = contentConfig.addBuffer("/properties/property");
    UrlRewriteFilterDetectDescriptor detectConfig = bufferConfig.addDetect("name", "test-name-2");
    UrlRewriteFilterApplyDescriptor applyConfig = detectConfig.addApply("value", "test-rule-2");
    // UrlRewriteRulesDescriptorFactory.store( rulesConfig, "xml", new PrintWriter( System.out ) );
    XmlFilterReader filter = new TestXmlFilterReader(new StringReader(input), contentConfig);
    String output = IOUtils.toString(filter);
    // System.out.println( "OUTPUT=" + output );
    assertThat(the(output), hasXPath("/properties/property[1]/name/text()", equalTo("test-name-1")));
    assertThat(the(output), hasXPath("/properties/property[1]/value/text()", equalTo("test-value-1")));
    assertThat(the(output), hasXPath("/properties/property[2]/name/text()", equalTo("test-name-2")));
    assertThat(the(output), hasXPath("/properties/property[2]/value/text()", equalTo("text:test-rule-2{test-value-2}")));
    assertThat(the(output), hasXPath("/properties/property[3]/name/text()", equalTo("test-name-3")));
    assertThat(the(output), hasXPath("/properties/property[3]/value/text()", equalTo("test-value-3")));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) InputStream(java.io.InputStream) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterApplyDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) UrlRewriteFilterDetectDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor) Test(org.junit.Test)

Example 14 with UrlRewriteFilterBufferDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor in project knox by apache.

the class XmlFilterReaderTest method testSimpleTextNodeBuffered.

@Test
public void testSimpleTextNodeBuffered() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor scopeConfig = contentConfig.addBuffer("/root");
    String inputXml = "<root>text</root>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    // System.out.println( outputHtml );
    assertThat(the(outputHtml), hasXPath("/root/text()", equalTo("text")));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Aggregations

UrlRewriteFilterBufferDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor)14 StringReader (java.io.StringReader)11 UrlRewriteFilterContentDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)11 UrlRewriteFilterDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor)11 UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Test (org.junit.Test)11 UrlRewriteFilterApplyDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor)8 InputStream (java.io.InputStream)7 UrlRewriteFilterDetectDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor)3 UrlRewriteFilterPathDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor)2 EndElement (javax.xml.stream.events.EndElement)1 StartElement (javax.xml.stream.events.StartElement)1 UrlRewriteFilterGroupDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterGroupDescriptor)1 UrlRewriteFilterScopeDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterScopeDescriptor)1 JsonPath (org.apache.knox.gateway.util.JsonPath)1 Element (org.w3c.dom.Element)1