use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRulesDescriptorImpl in project knox by apache.
the class HostmapDeploymentContributorTest method testDeployment.
@Test
public void testDeployment() throws IOException {
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test-acrhive");
UrlRewriteRulesDescriptorImpl rewriteRules = new UrlRewriteRulesDescriptorImpl();
Map<String, String> providerParams = new HashMap<>();
providerParams.put("test-host-external", "test-host-internal");
Provider provider = new Provider();
provider.setEnabled(true);
provider.setName("hostmap");
provider.setParams(providerParams);
DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
EasyMock.expect(context.getDescriptor("rewrite")).andReturn(rewriteRules).anyTimes();
EasyMock.expect(context.getWebArchive()).andReturn(webArchive).anyTimes();
EasyMock.replay(context);
HostmapDeploymentContributor contributor = new HostmapDeploymentContributor();
assertThat(contributor.getRole(), is("hostmap"));
assertThat(contributor.getName(), is("static"));
// Just make sure it doesn't blow up.
contributor.contributeFilter(null, null, null, null, null);
// Just make sure it doesn't blow up.
contributor.initializeContribution(context);
contributor.contributeProvider(context, provider);
HostmapFunctionDescriptor funcDesc = rewriteRules.getFunction("hostmap");
assertThat(funcDesc.config(), is("/WEB-INF/hostmap.txt"));
Node node = webArchive.get("/WEB-INF/hostmap.txt");
String asset = IOUtils.toString(node.getAsset().openStream());
assertThat(asset, containsString("test-host-external=test-host-internal"));
// Just make sure it doesn't blow up.
contributor.finalizeContribution(context);
}
Aggregations