Lines 38-47
import static org.junit.Assert.assertEquals;
Link Here
|
38 |
import static org.junit.Assert.assertNotNull; |
38 |
import static org.junit.Assert.assertNotNull; |
39 |
import static org.junit.Assert.assertNull; |
39 |
import static org.junit.Assert.assertNull; |
40 |
import static org.junit.Assert.assertTrue; |
40 |
import static org.junit.Assert.assertTrue; |
|
|
41 |
import static org.junit.Assert.fail; |
41 |
|
42 |
|
42 |
import org.junit.Test; |
43 |
import org.junit.Test; |
43 |
|
44 |
import org.apache.catalina.Host; |
44 |
import org.apache.catalina.core.StandardContext; |
45 |
import org.apache.catalina.core.StandardContext; |
|
|
46 |
import org.apache.catalina.core.StandardHost; |
47 |
import org.apache.catalina.ha.context.ReplicatedContext; |
45 |
import org.apache.tomcat.util.buf.ByteChunk; |
48 |
import org.apache.tomcat.util.buf.ByteChunk; |
46 |
import org.apache.tomcat.util.descriptor.web.ContextEnvironment; |
49 |
import org.apache.tomcat.util.descriptor.web.ContextEnvironment; |
47 |
import org.apache.tomcat.util.descriptor.web.ContextResourceLink; |
50 |
import org.apache.tomcat.util.descriptor.web.ContextResourceLink; |
Lines 417-420
public class TestTomcat extends TomcatBaseTest {
Link Here
|
417 |
|
420 |
|
418 |
assertEquals("WAR_CONTEXT", context.getSessionCookieName()); |
421 |
assertEquals("WAR_CONTEXT", context.getSessionCookieName()); |
419 |
} |
422 |
} |
|
|
423 |
|
424 |
@Test |
425 |
public void testGetDefaultContextPerAddWebapp() { |
426 |
Tomcat tomcat = getTomcatInstance(); |
427 |
|
428 |
File appFile = new File("test/deployment/context.war"); |
429 |
org.apache.catalina.Context context = tomcat.addWebapp(null, |
430 |
"/test", appFile.getAbsolutePath()); |
431 |
|
432 |
assertEquals(StandardContext.class.getName(), context.getClass() |
433 |
.getName()); |
434 |
} |
435 |
|
436 |
@Test |
437 |
public void testGetBrokenContextPerAddWepapp() { |
438 |
Tomcat tomcat = getTomcatInstance(); |
439 |
Host host = tomcat.getHost(); |
440 |
if (host instanceof StandardHost) { |
441 |
((StandardHost) host).setContextClass("InvalidContextClassName"); |
442 |
} |
443 |
|
444 |
try { |
445 |
File appFile = new File("test/deployment/context.war"); |
446 |
tomcat.addWebapp(null, "/test", appFile.getAbsolutePath()); |
447 |
fail(); |
448 |
} catch (IllegalArgumentException e) { |
449 |
// OK |
450 |
} |
451 |
} |
452 |
|
453 |
@Test |
454 |
public void testGetCustomContextPerAddWebappWithNullHost() { |
455 |
Tomcat tomcat = getTomcatInstance(); |
456 |
Host host = tomcat.getHost(); |
457 |
if (host instanceof StandardHost) { |
458 |
((StandardHost) host).setContextClass(ReplicatedContext.class |
459 |
.getName()); |
460 |
} |
461 |
|
462 |
File appFile = new File("test/deployment/context.war"); |
463 |
org.apache.catalina.Context context = tomcat.addWebapp(null, "/test", |
464 |
appFile.getAbsolutePath()); |
465 |
|
466 |
assertEquals(ReplicatedContext.class.getName(), context.getClass() |
467 |
.getName()); |
468 |
} |
469 |
|
470 |
@Test |
471 |
public void testGetCustomContextPerAddWebappWithHost() { |
472 |
Tomcat tomcat = getTomcatInstance(); |
473 |
Host host = tomcat.getHost(); |
474 |
if (host instanceof StandardHost) { |
475 |
((StandardHost) host).setContextClass(ReplicatedContext.class |
476 |
.getName()); |
477 |
} |
478 |
|
479 |
File appFile = new File("test/deployment/context.war"); |
480 |
org.apache.catalina.Context context = tomcat.addWebapp(host, "/test", |
481 |
appFile.getAbsolutePath()); |
482 |
|
483 |
assertEquals(ReplicatedContext.class.getName(), context.getClass() |
484 |
.getName()); |
485 |
} |
486 |
|
487 |
@Test |
488 |
public void testGetDefaultContextPerAddContext() { |
489 |
Tomcat tomcat = getTomcatInstance(); |
490 |
|
491 |
// No file system docBase required |
492 |
org.apache.catalina.Context ctx = tomcat.addContext(null, "", null); |
493 |
assertEquals(StandardContext.class.getName(), ctx.getClass().getName()); |
494 |
} |
495 |
|
496 |
@Test |
497 |
public void testGetBrokenContextPerAddContext() { |
498 |
Tomcat tomcat = getTomcatInstance(); |
499 |
Host host = tomcat.getHost(); |
500 |
if (host instanceof StandardHost) { |
501 |
((StandardHost) host).setContextClass("InvalidContextClassName"); |
502 |
} |
503 |
|
504 |
// No file system docBase required |
505 |
try { |
506 |
tomcat.addContext(null, "", null); |
507 |
fail(); |
508 |
} catch (IllegalArgumentException e) { |
509 |
// OK |
510 |
} |
511 |
} |
512 |
|
513 |
@Test |
514 |
public void testGetCustomContextPerAddContextWithHost() { |
515 |
Tomcat tomcat = getTomcatInstance(); |
516 |
Host host = tomcat.getHost(); |
517 |
if (host instanceof StandardHost) { |
518 |
((StandardHost) host).setContextClass(ReplicatedContext.class |
519 |
.getName()); |
520 |
} |
521 |
|
522 |
// No file system docBase required |
523 |
org.apache.catalina.Context ctx = tomcat.addContext(host, "", null); |
524 |
assertEquals(ReplicatedContext.class.getName(), ctx.getClass() |
525 |
.getName()); |
526 |
} |
527 |
|
420 |
} |
528 |
} |
421 |
- |
|
|