Search in sources :

Example 1 with UrlRewriteRulesDescriptorImpl

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);
}
Also used : DeploymentContext(org.apache.knox.gateway.deploy.DeploymentContext) UrlRewriteRulesDescriptorImpl(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRulesDescriptorImpl) HashMap(java.util.HashMap) HostmapFunctionDescriptor(org.apache.knox.gateway.hostmap.api.HostmapFunctionDescriptor) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Node(org.jboss.shrinkwrap.api.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Provider(org.apache.knox.gateway.topology.Provider) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 DeploymentContext (org.apache.knox.gateway.deploy.DeploymentContext)1 UrlRewriteRulesDescriptorImpl (org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRulesDescriptorImpl)1 HostmapFunctionDescriptor (org.apache.knox.gateway.hostmap.api.HostmapFunctionDescriptor)1 Provider (org.apache.knox.gateway.topology.Provider)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Node (org.jboss.shrinkwrap.api.Node)1 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)1 Test (org.junit.Test)1