01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.jetty6.deployment;
17:
18: import junit.framework.TestCase;
19: import org.apache.geronimo.xbeans.javaee.ServletType;
20:
21: /**
22: * @version $Rev: 482336 $ $Date: 2006-12-04 12:12:19 -0800 (Mon, 04 Dec 2006) $
23: */
24: public class StartupOrderComparatorTest extends TestCase {
25:
26: private final JettyModuleBuilder.StartupOrderComparator c = new JettyModuleBuilder.StartupOrderComparator();
27:
28: public void testNoOrders() throws Exception {
29: ServletType s1 = makeServletType("a", -1);
30: ServletType s2 = makeServletType("b", -1);
31: ServletType s3 = makeServletType("c", -1);
32: checkOrdering(s1, s2, s3);
33: }
34:
35: public void testIdenticalOrders() throws Exception {
36: ServletType s1 = makeServletType("a", 1);
37: ServletType s2 = makeServletType("b", 1);
38: ServletType s3 = makeServletType("c", 1);
39: checkOrdering(s1, s2, s3);
40: }
41:
42: public void testDistinctOrders() throws Exception {
43: ServletType s1 = makeServletType("c", 1);
44: ServletType s2 = makeServletType("b", 2);
45: ServletType s3 = makeServletType("a", 3);
46: checkOrdering(s1, s2, s3);
47: }
48:
49: public void testMixedOrders1() throws Exception {
50: ServletType s1 = makeServletType("c", 1);
51: ServletType s2 = makeServletType("b", 2);
52: ServletType s3 = makeServletType("a", -1);
53: checkOrdering(s1, s2, s3);
54: }
55:
56: public void testMixedOrders2() throws Exception {
57: ServletType s1 = makeServletType("c", 1);
58: ServletType s2 = makeServletType("a", -1);
59: ServletType s3 = makeServletType("b", -1);
60: checkOrdering(s1, s2, s3);
61: }
62:
63: private void checkOrdering(ServletType s1, ServletType s2,
64: 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 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: }
|