UrlRewriteProcessor processor = new UrlRewriteProcessor();
UrlRewriteRulesDescriptor config = UrlRewriteRulesDescriptorFactory.load(
"xml", getTestResourceReader( "rewrite-with-same-rules.xml", "UTF-8" ) );
processor.initialize( environment, config );
Template inputUrl = Parser.parse( "scheme://input-mock-host:42/test-input-path" );
Template outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, null );
assertThat( "Expect rewrite to produce a new URL",
outputUrl, notNullValue() );
// Should always pick the first one.
assertThat(
"Expect rewrite to contain the correct path.",
outputUrl.toString(), is( "output-mock-scheme-1://output-mock-host-1:42/test-input-path" ) );
inputUrl = Parser.parse( "mock-scheme://input-mock-host:42/no-query" );
outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, null );
assertThat(
"Expect rewrite to contain the correct path.",
outputUrl.toString(), is( "mock-scheme://output-mock-host-3:42/no-query" ) );
outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, "test-rule-4" );
assertThat(
"Expect rewrite to contain the correct path.",
outputUrl.toString(), is( "mock-scheme://output-mock-host-4:42/no-query" ) );
processor.destroy();
}