use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor 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")));
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor 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")));
}
Aggregations