1 17 package org.apache.geronimo.jetty6.deployment; 18 19 import junit.framework.TestCase; 20 import org.apache.geronimo.xbeans.javaee.ServletType; 21 22 25 public class StartupOrderComparatorTest extends TestCase { 26 27 private final JettyModuleBuilder.StartupOrderComparator c = new JettyModuleBuilder.StartupOrderComparator(); 28 29 public void testNoOrders() throws Exception { 30 ServletType s1 = makeServletType("a", -1); 31 ServletType s2 = makeServletType("b", -1); 32 ServletType s3 = makeServletType("c", -1); 33 checkOrdering(s1, s2, s3); 34 } 35 36 public void testIdenticalOrders() throws Exception { 37 ServletType s1 = makeServletType("a", 1); 38 ServletType s2 = makeServletType("b", 1); 39 ServletType s3 = makeServletType("c", 1); 40 checkOrdering(s1, s2, s3); 41 } 42 43 public void testDistinctOrders() throws Exception { 44 ServletType s1 = makeServletType("c", 1); 45 ServletType s2 = makeServletType("b", 2); 46 ServletType s3 = makeServletType("a", 3); 47 checkOrdering(s1, s2, s3); 48 } 49 50 public void testMixedOrders1() throws Exception { 51 ServletType s1 = makeServletType("c", 1); 52 ServletType s2 = makeServletType("b", 2); 53 ServletType s3 = makeServletType("a", -1); 54 checkOrdering(s1, s2, s3); 55 } 56 57 public void testMixedOrders2() throws Exception { 58 ServletType s1 = makeServletType("c", 1); 59 ServletType s2 = makeServletType("a", -1); 60 ServletType s3 = makeServletType("b", -1); 61 checkOrdering(s1, s2, s3); 62 } 63 64 private void checkOrdering(ServletType s1, ServletType s2, ServletType s3) { 65 assertTrue(c.compare(s1, s2) < 0); 67 assertTrue(c.compare(s2, s1) > 0); 68 assertTrue(c.compare(s1, s1) == 0); 70 assertTrue(c.compare(s2, s3) < 0); 72 assertTrue(c.compare(s1, s3) < 0); 73 } 74 75 private ServletType makeServletType(String servletName, int order) { 76 ServletType s1 = ServletType.Factory.newInstance(); 77 s1.addNewServletName().setStringValue(servletName); 78 if (order > -1) { 79 s1.setLoadOnStartup(Integer.valueOf(order)); 80 } 81 return s1; 82 } 83 } 84 | Popular Tags |