Search in sources :

Example 11 with Application

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();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) URL(java.net.URL) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) Application(org.apache.knox.gateway.topology.Application) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Aggregations

Application (org.apache.knox.gateway.topology.Application)11 Topology (org.apache.knox.gateway.topology.Topology)7 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 File (java.io.File)3 URL (java.net.URL)3 Service (org.apache.knox.gateway.topology.Service)3 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)2 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)2 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)2 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)2 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)2 Document (org.w3c.dom.Document)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1