use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactoryFuncTest method testDeploymentWithServicesAndApplications.
@Test(timeout = MEDIUM_TIMEOUT)
public void testDeploymentWithServicesAndApplications() 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;
topology.setName("test-cluster");
Service service = new Service();
service.setRole("WEBHDFS");
service.addUrl("http://localhost:50070/test-service-url");
topology.addService(service);
app = new Application();
app.setName("minimal-test-app");
app.addUrl("/minimal-test-app-path-one");
topology.addApplication(app);
app.setName("minimal-test-app");
app.addUrl("/minimal-test-app-path-two");
topology.addApplication(app);
EnterpriseArchive archive = DeploymentFactory.createDeployment(config, topology);
assertThat(archive, notNullValue());
Document doc;
org.jboss.shrinkwrap.api.Node node;
node = archive.get("META-INF/topology.xml");
assertThat("Find META-INF/topology.xml", node, notNullValue());
doc = XmlUtils.readXml(node.getAsset().openStream());
assertThat("Parse META-INF/topology.xml", doc, notNullValue());
node = archive.get("%2F");
assertThat("Find %2F", node, notNullValue());
node = archive.get("%2F/WEB-INF/gateway.xml");
assertThat("Find %2F/WEB-INF/gateway.xml", node, notNullValue());
doc = XmlUtils.readXml(node.getAsset().openStream());
assertThat("Parse %2F/WEB-INF/gateway.xml", doc, notNullValue());
WebArchive war = archive.getAsType(WebArchive.class, "%2Fminimal-test-app-path-one");
assertThat("Find %2Fminimal-test-app-path-one", war, notNullValue());
node = war.get("/WEB-INF/gateway.xml");
assertThat("Find %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", node, notNullValue());
doc = XmlUtils.readXml(node.getAsset().openStream());
assertThat("Parse %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", doc, notNullValue());
war = archive.getAsType(WebArchive.class, "%2Fminimal-test-app-path-two");
assertThat("Find %2Fminimal-test-app-path-two", war, notNullValue());
node = war.get("/WEB-INF/gateway.xml");
assertThat("Find %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", node, notNullValue());
doc = XmlUtils.readXml(node.getAsset().openStream());
assertThat("Parse %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", doc, notNullValue());
LOG_EXIT();
}
Aggregations