Search in sources :

Example 16 with TesterServletContext

use of org.apache.tomcat.unittest.TesterServletContext in project tomcat by apache.

the class TestWsServerContainer method testDuplicatePaths_04.

@Test
public void testDuplicatePaths_04() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/{var1}/{var2}").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var2}").build();
    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
    Assert.assertEquals(configA, sc.findMapping("/a/x/y").getConfig());
    Assert.assertEquals(configB, sc.findMapping("/a/b/y").getConfig());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 17 with TesterServletContext

use of org.apache.tomcat.unittest.TesterServletContext in project tomcat by apache.

the class TestWsServerContainer method testDuplicatePaths_01.

@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_01() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/b/c").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/c").build();
    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 18 with TesterServletContext

use of org.apache.tomcat.unittest.TesterServletContext in project tomcat by apache.

the class TestStandardJarScanner method testWebappClassPath.

@Test
public void testWebappClassPath() {
    StandardJarScanner scanner = new StandardJarScanner();
    scanner.setScanClassPath(true);
    // When running the test on Java 9, one or more URLs to jimage files may
    // be returned. By setting the scanAllFiles option, a callback will be
    // generated for these files which in turn will mean the number of URLs
    // and the number of call backs will agree and this test will pass.
    // There is a TODO in StandardJarScanner to add 'proper' Java 9 support.
    scanner.setScanAllFiles(true);
    LoggingCallback callback = new LoggingCallback();
    scanner.scan(JarScanType.PLUGGABILITY, new TesterServletContext(), callback);
    List<String> callbacks = callback.getCallbacks();
    ClassLoader cl = TesterServletContext.class.getClassLoader();
    if (cl instanceof URLClassLoader) {
        URL[] urls = ((URLClassLoader) cl).getURLs();
        int size;
        if (urls == null) {
            size = 0;
        } else {
            size = urls.length;
        }
        // Some JREs (Gump) construct a class path that includes JARs that
        // reference additional JARs via the Class-Path attribute of the
        // Manifest. These JARs are not returned in ClassLoader.getURLs().
        // Therefore, this test looks for at least as many JARs as there are
        // URLs but it can't check for an exact match.
        Assert.assertTrue("[" + callbacks.size() + "] callbacks but expected at least [" + size + "]", callbacks.size() >= size);
    } else {
        Assert.fail("Unexpected class loader type: " + cl.getClass().getName());
    }
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 19 with TesterServletContext

use of org.apache.tomcat.unittest.TesterServletContext in project tomcat70 by apache.

the class TestWsServerContainer method testDuplicatePaths_03.

@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_03() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var1}").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var2}").build();
    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 20 with TesterServletContext

use of org.apache.tomcat.unittest.TesterServletContext in project tomcat70 by apache.

the class TestWsServerContainer method testSpecExample4.

@Test
public void testSpecExample4() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/{var1}/d").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/b/{var2}").build();
    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
    Assert.assertEquals(configB, sc.findMapping("/b/d").getConfig());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Aggregations

TesterServletContext (org.apache.tomcat.unittest.TesterServletContext)28 Test (org.junit.Test)27 WebSocketBaseTest (org.apache.tomcat.websocket.WebSocketBaseTest)24 ServerEndpointConfig (jakarta.websocket.server.ServerEndpointConfig)14 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)10 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 TesterContext (org.apache.tomcat.unittest.TesterContext)2 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 Request (org.apache.catalina.connector.Request)1 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)1 TesterRequest (org.apache.tomcat.unittest.TesterRequest)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1 BeforeClass (org.junit.BeforeClass)1