KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > deployment > StartupOrderComparatorTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.jetty6.deployment;
18
19 import junit.framework.TestCase;
20 import org.apache.geronimo.xbeans.javaee.ServletType;
21
22 /**
23  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
24  */

25 public class StartupOrderComparatorTest extends TestCase {
26
27     private final JettyModuleBuilder.StartupOrderComparator c = new JettyModuleBuilder.StartupOrderComparator();
28
29     public void testNoOrders() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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         //symmetric
66
assertTrue(c.compare(s1, s2) < 0);
67         assertTrue(c.compare(s2, s1) > 0);
68         //reflexive
69
assertTrue(c.compare(s1, s1) == 0);
70         //transitive
71
assertTrue(c.compare(s2, s3) < 0);
72         assertTrue(c.compare(s1, s3) < 0);
73     }
74
75     private ServletType makeServletType(String JavaDoc 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