Search in sources :

Example 51 with Topology

use of org.apache.knox.gateway.topology.Topology 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)

Example 52 with Topology

use of org.apache.knox.gateway.topology.Topology in project knox by apache.

the class DeploymentFactoryFuncTest method testInvalidGenericProviderDeploymentContributor.

@Test(timeout = LONG_TIMEOUT)
public void testInvalidGenericProviderDeploymentContributor() throws ParserConfigurationException, SAXException, IOException, TransformerException {
    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();
    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-cluster");
    Service service = new Service();
    service.setRole("WEBHDFS");
    service.addUrl("http://localhost:50070/test-service-url");
    topology.addService(service);
    Provider provider = new Provider();
    provider.setRole("authentication");
    provider.setName("generic");
    provider.setEnabled(true);
    // = new ProviderParam();
    Param param;
    // Missing filter param.
    // param.setName( "filter" );
    // param.setValue( "org.opensource.ExistingFilter" );
    // provider.addParam( param );
    param = new Param();
    param.setName("test-param-name");
    param.setValue("test-param-value");
    provider.addParam(param);
    topology.addProvider(provider);
    Enumeration<Appender> appenders = NoOpAppender.setUp();
    try {
        DeploymentFactory.createDeployment(config, topology);
        fail("Should have throws IllegalArgumentException");
    } catch (DeploymentException e) {
    // Expected.
    } finally {
        NoOpAppender.tearDown(appenders);
    }
    LOG_EXIT();
}
Also used : NoOpAppender(org.apache.knox.test.log.NoOpAppender) Appender(org.apache.log4j.Appender) HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) Provider(org.apache.knox.gateway.topology.Provider) Param(org.apache.knox.gateway.topology.Param) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Aggregations

Topology (org.apache.knox.gateway.topology.Topology)52 Test (org.junit.Test)36 HashMap (java.util.HashMap)23 Service (org.apache.knox.gateway.topology.Service)22 File (java.io.File)20 Provider (org.apache.knox.gateway.topology.Provider)20 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)17 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)10 DeploymentContext (org.apache.knox.gateway.deploy.DeploymentContext)9 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)9 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)9 IOException (java.io.IOException)8 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)8 URL (java.net.URL)7 TopologyService (org.apache.knox.gateway.services.topology.TopologyService)7 Application (org.apache.knox.gateway.topology.Application)7 Param (org.apache.knox.gateway.topology.Param)7 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)7 Document (org.w3c.dom.Document)7 Digester (org.apache.commons.digester3.Digester)6