Search in sources :

Example 11 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class DynamicEndpointTest method setup.

@BeforeClass
public static void setup() throws Exception {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(DynamicEndpointTest.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(DynamicEndpointTest.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServlet(Servlets.servlet("upgrade", DoUpgradeServlet.class).addMapping("/*")).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {

        @Override
        public void ready(ServerWebSocketContainer container) {
            deployment = container;
        }
    })).setDeploymentName("servletContext.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 12 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class SuspendResumeTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(TestMessagesReceivedInOrder.class.getClassLoader()).setContextPath("/").setResourceManager(new TestResourceLoader(TestMessagesReceivedInOrder.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {

        @Override
        public void ready(ServerWebSocketContainer c) {
            serverContainer = c;
        }
    }).addEndpoint(SuspendResumeEndpoint.class)).setDeploymentName("servletContext.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", manager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 13 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class WelcomeFileSecurityTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(WelcomeFileSecurityTestCase.class)).addWelcomePages("doesnotexist.html", "index.html", "default").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("BASIC", "Test Realm")).addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/path/default")).addSecurityConstraint(new SecurityConstraint().addRoleAllowed("role1").addWebResourceCollection(new WebResourceCollection().addUrlPattern("/index.html")));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) ServletSecurityInfo(io.undertow.servlet.api.ServletSecurityInfo) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletPathMappingTestCase(io.undertow.servlet.test.path.ServletPathMappingTestCase) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Example 14 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class ServletMetricsHandlerTestCase method testMetrics.

@Test
public void testMetrics() throws Exception {
    final TestMetricsCollector metricsCollector = new TestMetricsCollector();
    CompletionLatchHandler completionLatchHandler;
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DefaultServletTestCase.class));
    builder.addServlet(new ServletInfo("MetricTestServlet", MetricTestServlet.class).addMapping("/path/default"));
    builder.addFilter(new FilterInfo("Filter", HelloFilter.class));
    builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST);
    builder.setMetricsCollector(metricsCollector);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(completionLatchHandler = new CompletionLatchHandler(root));
    HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/path/default");
    TestHttpClient client = new TestHttpClient();
    try {
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric"));
        completionLatchHandler.await();
        completionLatchHandler.reset();
        MetricsHandler.MetricResult metrics = metricsCollector.getMetrics("MetricTestServlet");
        Assert.assertEquals(1, metrics.getTotalRequests());
        Assert.assertTrue(metrics.getMaxRequestTime() > 0);
        Assert.assertEquals(metrics.getMinRequestTime(), metrics.getMaxRequestTime());
        Assert.assertEquals(metrics.getMaxRequestTime(), metrics.getTotalRequestTime());
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric"));
        completionLatchHandler.await();
        completionLatchHandler.reset();
        metrics = metricsCollector.getMetrics("MetricTestServlet");
        Assert.assertEquals(2, metrics.getTotalRequests());
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : HelloFilter(io.undertow.servlet.test.defaultservlet.HelloFilter) DefaultServletTestCase(io.undertow.servlet.test.defaultservlet.DefaultServletTestCase) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) CompletionLatchHandler(io.undertow.util.CompletionLatchHandler) HttpGet(org.apache.http.client.methods.HttpGet) PathHandler(io.undertow.server.handlers.PathHandler) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) MetricsHandler(io.undertow.server.handlers.MetricsHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) Test(org.junit.Test)

Example 15 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class WelcomeFileTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(WelcomeFileTestCase.class)).addWelcomePages("doesnotexist.html", "index.html", "default", "servletPath/servletFile.xhtml").addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("/path/default")).addServlet(new ServletInfo("ServletPath", PathTestServlet.class).addMapping("/foo/servletPath/*")).addFilter(new FilterInfo("Filter", NoOpFilter.class)).addFilterUrlMapping("Filter", "/*", DispatcherType.REQUEST).addFilterUrlMapping("Filter", "/", DispatcherType.REQUEST);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext2").setDeploymentName("servletContext2.war").setResourceManager(new TestResourceLoader(WelcomeFileTestCase.class)).addWelcomePages("doesnotexist.html", "index.do").addServlet(new ServletInfo("*.do", PathTestServlet.class).addMapping("*.do"));
    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) PathTestServlet(io.undertow.servlet.test.util.PathTestServlet) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) ServletPathMappingTestCase(io.undertow.servlet.test.path.ServletPathMappingTestCase) BeforeClass(org.junit.BeforeClass)

Aggregations

DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)17 DeploymentManager (io.undertow.servlet.api.DeploymentManager)17 ServletContainer (io.undertow.servlet.api.ServletContainer)17 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 BeforeClass (org.junit.BeforeClass)16 PathHandler (io.undertow.server.handlers.PathHandler)11 ServletInfo (io.undertow.servlet.api.ServletInfo)11 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)6 FilterInfo (io.undertow.servlet.api.FilterInfo)5 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)5 ServletPathMappingTestCase (io.undertow.servlet.test.path.ServletPathMappingTestCase)3 LoginConfig (io.undertow.servlet.api.LoginConfig)2 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)2 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)2 MessageFilter (io.undertow.servlet.test.util.MessageFilter)2 MessageServlet (io.undertow.servlet.test.util.MessageServlet)2 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)1 MetricsHandler (io.undertow.server.handlers.MetricsHandler)1 AccessLogHandler (io.undertow.server.handlers.accesslog.AccessLogHandler)1 DefaultServletConfig (io.undertow.servlet.api.DefaultServletConfig)1