Search in sources :

Example 6 with TesterServletContext

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

the class TestDigestAuthenticator method bug54521.

@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());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) TesterRequest(org.apache.tomcat.unittest.TesterRequest) Request(org.apache.catalina.connector.Request) TesterRequest(org.apache.tomcat.unittest.TesterRequest) TesterContext(org.apache.tomcat.unittest.TesterContext) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) HashSet(java.util.HashSet) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 7 with TesterServletContext

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

the class FileStoreTest method setup.

@BeforeClass
public static void setup() {
    TesterContext testerContext = new TesterContext();
    testerContext.setServletContext(new TesterServletContext());
    manager.setContext(testerContext);
    fileStore = new FileStore();
    fileStore.setManager(manager);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) TesterContext(org.apache.tomcat.unittest.TesterContext) BeforeClass(org.junit.BeforeClass)

Example 8 with TesterServletContext

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

the class TestStandardJarScanner method skipsInvalidClasspathURLNoFilePartNoFileScheme.

/**
 * Tomcat should ignore URLs which do not have a file part and do not use the file scheme.
 */
@Test
public void skipsInvalidClasspathURLNoFilePartNoFileScheme() {
    StandardJarScanner scanner = new StandardJarScanner();
    LoggingCallback callback = new LoggingCallback();
    TesterServletContext context = new TesterServletContext() {

        @Override
        public ClassLoader getClassLoader() {
            URLClassLoader urlClassLoader;
            try {
                urlClassLoader = new URLClassLoader(new URL[] { new URL("http://felix.extensions:9/") });
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
            return urlClassLoader;
        }
    };
    scanner.scan(JarScanType.PLUGGABILITY, context, callback);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) MalformedURLException(java.net.MalformedURLException) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 9 with TesterServletContext

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

the class TestWsServerContainer method testDuplicatePaths13.

/*
     * POJO programmatic followed by programmatic duplicate.
     */
@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);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 10 with TesterServletContext

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

the class TestWsServerContainer method testDuplicatePaths01.

@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);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(jakarta.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