org.apache.tomcat.unittest.TesterServletContext Java Examples

The following examples show how to use org.apache.tomcat.unittest.TesterServletContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testSpecExample3() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/a/{var}/c").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/c").build();
    ServerEndpointConfig configC = ServerEndpointConfig.Builder.create(
            Object.class, "/a/{var1}/{var2}").build();

    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
    sc.addEndpoint(configC);

    Assert.assertEquals(configB, sc.findMapping("/a/b/c").getConfig());
    Assert.assertEquals(configA, sc.findMapping("/a/d/c").getConfig());
    Assert.assertEquals(configC, sc.findMapping("/a/x/y").getConfig());
}
 
Example #2
Source File: TestWsServerContainer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: TestWsServerContainer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpecExample3() throws Exception {
    WsServerContainer sc =
            new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/a/{var}/c").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/c").build();
    ServerEndpointConfig configC = ServerEndpointConfig.Builder.create(
            Object.class, "/a/{var1}/{var2}").build();

    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
    sc.addEndpoint(configC);

    Assert.assertEquals(configB, sc.findMapping("/a/b/c").getConfig());
    Assert.assertEquals(configA, sc.findMapping("/a/d/c").getConfig());
    Assert.assertEquals(configC, sc.findMapping("/a/x/y").getConfig());
}
 
Example #4
Source File: TestWsServerContainer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: TestWsServerContainer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpecExample3() throws Exception {
    WsServerContainer sc =
            new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/a/{var}/c").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/c").build();
    ServerEndpointConfig configC = ServerEndpointConfig.Builder.create(
            Object.class, "/a/{var1}/{var2}").build();

    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
    sc.addEndpoint(configC);

    Assert.assertEquals(configB, sc.findMapping("/a/b/c").getConfig());
    Assert.assertEquals(configA, sc.findMapping("/a/d/c").getConfig());
    Assert.assertEquals(configC, sc.findMapping("/a/x/y").getConfig());
}
 
Example #6
Source File: TestDigestAuthenticator.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void bug54521() throws LifecycleException {
    DigestAuthenticator digestAuthenticator = new DigestAuthenticator();
    TesterContext context = new TesterContext();
    context.setServletContext(new TesterServletContext());
    digestAuthenticator.setContainer(context);
    digestAuthenticator.start();
    Request request = new TesterRequest();
    final int count = 1000;

    Set<String> nonces = new HashSet<>();

    for (int i = 0; i < count; i++) {
        nonces.add(digestAuthenticator.generateNonce(request));
    }

    Assert.assertEquals(count,  nonces.size());
}
 
Example #7
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths02() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/{var}").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/{var}").build();

    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
}
 
Example #8
Source File: TestWsServerContainer.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: TestWsServerContainer.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_02() throws Exception {
    WsServerContainer sc =
            new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/{var}").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/{var}").build();

    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
}
 
Example #10
Source File: TestWsServerContainer.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: TestWsServerContainer.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example #13
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths01() 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);
}
 
Example #14
Source File: TestWsServerContainer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: TestWsServerContainer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_02() throws Exception {
    WsServerContainer sc =
            new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/{var}").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
            Object.class, "/a/b/{var}").build();

    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
}
 
Example #16
Source File: TestWsServerContainer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #17
Source File: TestWsServerContainer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #18
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths03() 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);
}
 
Example #19
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths24() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/foo/{a}").build();

    sc.addEndpoint(PojoTemplate.class, true);
    sc.addEndpoint(configA);
}
 
Example #20
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths23() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            PojoTemplate.class, "/foo/{a}").build();

    sc.addEndpoint(PojoTemplate.class);
    sc.addEndpoint(configA);
}
 
Example #21
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testDuplicatePaths22() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            PojoTemplate.class, "/foo/{a}").build();

    sc.addEndpoint(PojoTemplate.class, true);
    sc.addEndpoint(configA);

    Assert.assertNotEquals(configA, sc.findMapping("/foo/{a}").getConfig());
}
 
Example #22
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths21() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            PojoTemplate.class, "/foo/{a}").build();

    sc.addEndpoint(configA, false);
    sc.addEndpoint(PojoTemplate.class, true);
}
 
Example #23
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths14() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Object.class, "/foo").build();

    sc.addEndpoint(Pojo.class, true);
    sc.addEndpoint(configA);
}
 
Example #24
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths13() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Pojo.class, "/foo").build();

    sc.addEndpoint(Pojo.class);
    sc.addEndpoint(configA);
}
 
Example #25
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testDuplicatePaths12() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Pojo.class, "/foo").build();

    sc.addEndpoint(Pojo.class, true);
    sc.addEndpoint(configA);

    Assert.assertNotEquals(configA, sc.findMapping("/foo").getConfig());
}
 
Example #26
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected = DeploymentException.class)
public void testDuplicatePaths11() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());

    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
            Pojo.class, "/foo").build();

    sc.addEndpoint(configA, false);
    sc.addEndpoint(Pojo.class, true);
}
 
Example #27
Source File: TestWsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testDuplicatePaths04() 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());
}
 
Example #28
Source File: TestStandardJarScanner.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testWebappClassPath() {
    Assume.assumeFalse("No URLClassLoader with Java 9", JreCompat.isJre9Available());

    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());
    }
}