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.openejb.assembler.classic;
17:
18: import junit.framework.TestCase;
19:
20: import java.util.ArrayList;
21: import java.util.Collections;
22: import java.util.List;
23:
24: /**
25: * @version $Rev: 638255 $ $Date: 2008-03-18 01:02:11 -0700 $
26: */
27: public class MethodTransactionInfoComparatorTest extends TestCase {
28:
29: public void testOrdering() throws Exception {
30:
31: ArrayList<MethodTransactionInfo> expected = new ArrayList<MethodTransactionInfo>();
32:
33: MethodTransactionInfo info = null;
34: MethodInfo method = null;
35:
36: // Package Interceptors (aka Default Interceptors) ///////////////
37: info = add(expected, new MethodTransactionInfo());
38: info.transAttribute = "Required";
39: method = new MethodInfo();
40: method.ejbName = "*";
41: method.className = "*";
42: info.methods.add(method);
43:
44: // Class Interceptors ////////////////////////////////////////////
45: info = add(expected, new MethodTransactionInfo());
46: info.transAttribute = "Required";
47: method = new MethodInfo();
48: method.ejbName = "PingEJB";
49: method.className = "*";
50: method.methodName = "*";
51: info.methods.add(method);
52:
53: // Method Interceptors (no params) ///////////////////////////////
54: info = add(expected, new MethodTransactionInfo());
55: info.transAttribute = "Required";
56: method = new MethodInfo();
57: method.ejbName = "PingEJB";
58: method.className = "*";
59: method.methodName = "ping";
60: info.methods.add(method);
61:
62: // Method Interceptors (params) ///////////////////////////////
63: info = add(expected, new MethodTransactionInfo());
64: info.transAttribute = "Required";
65: method = new MethodInfo();
66: method.ejbName = "PingEJB";
67: method.className = "*";
68: method.methodName = "ping";
69: method.methodParams = new ArrayList<String>();
70: method.methodParams.add("java.lang.String");
71: info.methods.add(method);
72:
73: ArrayList<MethodTransactionInfo> actual = new ArrayList<MethodTransactionInfo>(
74: expected);
75: Collections.shuffle(actual);
76: Collections
77: .sort(
78: actual,
79: new MethodTransactionBuilder.MethodTransactionComparator());
80:
81: for (int i = 0; i < actual.size(); i++) {
82: MethodTransactionInfo a = actual.get(i);
83: MethodTransactionInfo e = expected.get(i);
84: assertSame(e, a);
85: }
86: }
87:
88: private MethodTransactionInfo add(List list,
89: MethodTransactionInfo bindingInfo) {
90: list.add(bindingInfo);
91: return bindingInfo;
92: }
93: }
|