use of org.apache.knox.gateway.filter.XForwardedHeaderFilter in project knox by apache.
the class DeploymentFactoryFuncTest method testDeploymentWithApplication.
@Test(timeout = MEDIUM_TIMEOUT)
public void testDeploymentWithApplication() throws Exception {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
URL serviceUrl = TestUtils.getResourceUrl(DeploymentFactoryFuncTest.class, "test-apps/minimal-test-app/service.xml");
File serviceFile = new File(serviceUrl.toURI());
File appsDir = serviceFile.getParentFile().getParentFile();
((GatewayTestConfig) config).setGatewayApplicationsDir(appsDir.getAbsolutePath());
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-topology");
Application app;
app = new Application();
app.setName("minimal-test-app");
app.addUrl("/minimal-test-app-path");
topology.addApplication(app);
EnterpriseArchive archive = DeploymentFactory.createDeployment(config, topology);
assertThat(archive, notNullValue());
Document doc;
doc = XmlUtils.readXml(archive.get("META-INF/topology.xml").getAsset().openStream());
assertThat(doc, notNullValue());
doc = XmlUtils.readXml(archive.get("%2Fminimal-test-app-path/WEB-INF/gateway.xml").getAsset().openStream());
assertThat(doc, notNullValue());
// dump( doc );
assertThat(doc, hasXPath("/gateway/resource/pattern", equalTo("/**?**")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/role", equalTo("xforwardedheaders")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/name", equalTo("XForwardedHeaderFilter")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/class", equalTo(XForwardedHeaderFilter.class.getName())));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/role", equalTo("rewrite")));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/name", equalTo("url-rewrite")));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/class", equalTo(UrlRewriteServletFilter.class.getName())));
LOG_EXIT();
}
Aggregations