001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.assembler.classic;
017:
018: import junit.framework.TestCase;
019:
020: import java.rmi.RemoteException;
021: import java.util.Arrays;
022: import java.util.List;
023:
024: /**
025: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
026: */
027: public class ProxyInterfaceResolverTest extends TestCase {
028: public void test() throws Exception {
029: Class smoothie;
030: List<Class> ingredients;
031:
032: // No remotes
033: smoothie = implement(Mango.class, Lime.class, Lemon.class);
034: ingredients = resolve(smoothie, Mango.class, Lime.class,
035: Lemon.class);
036: assertEquals(3, ingredients.size());
037: assertTrue(ingredients.contains(Mango.class));
038: assertTrue(ingredients.contains(Lime.class));
039: assertTrue(ingredients.contains(Lemon.class));
040:
041: // All remotes
042: smoothie = implement(Cherry.class, Honey.class, Grape.class);
043: ingredients = resolve(smoothie, Cherry.class, Honey.class,
044: Grape.class);
045: assertEquals(3, ingredients.size());
046: assertTrue(ingredients.contains(Cherry.class));
047: assertTrue(ingredients.contains(Grape.class));
048: assertTrue(ingredients.contains(Honey.class));
049:
050: // mixed remote and non-remote, no conflicts
051: smoothie = implement(Banana.class, Honey.class, Creme.class);
052: ingredients = resolve(smoothie, Banana.class, Honey.class,
053: Creme.class);
054: assertEquals(3, ingredients.size());
055: assertTrue(ingredients.contains(Banana.class));
056: assertTrue(ingredients.contains(Honey.class));
057: assertTrue(ingredients.contains(Creme.class));
058:
059: // mixed remote and non-remote, conflicts (cherry, grape)
060: smoothie = implement(Mango.class, Banana.class, Creme.class,
061: Honey.class, Cherry.class, Grape.class);
062: ingredients = resolve(smoothie, Mango.class, Banana.class,
063: Creme.class, Honey.class, Cherry.class, Grape.class);
064: assertEquals(4, ingredients.size());
065: assertTrue(ingredients.contains(Mango.class));
066: assertTrue(ingredients.contains(Banana.class));
067: assertTrue(ingredients.contains(Creme.class));
068: assertTrue(ingredients.contains(Honey.class));
069:
070: // mixed remote and non-remote, conflicts (mango, banana)
071: smoothie = implement(Cherry.class, Mango.class, Banana.class,
072: Creme.class, Honey.class, Grape.class);
073: ingredients = resolve(smoothie, Cherry.class, Mango.class,
074: Banana.class, Creme.class, Honey.class, Grape.class);
075: assertEquals(4, ingredients.size());
076: assertTrue(ingredients.contains(Cherry.class));
077: assertTrue(ingredients.contains(Grape.class));
078: assertTrue(ingredients.contains(Creme.class));
079: assertTrue(ingredients.contains(Honey.class));
080: }
081:
082: public List<Class> resolve(Class impl, Class mainInterface,
083: Class... interfaces) {
084: return ProxyInterfaceResolver.getInterfaces(impl,
085: mainInterface, Arrays.asList(interfaces));
086: }
087:
088: public Class implement(Class<?>... interfaces) {
089: return java.lang.reflect.Proxy.getProxyClass(this .getClass()
090: .getClassLoader(), interfaces);
091: }
092:
093: public interface Mango {
094: void exist() throws RoundException, GreenException;
095:
096: void mango();
097: }
098:
099: public interface Lime {
100: void exist() throws RoundException, GreenException;
101:
102: void lime();
103: }
104:
105: public interface Lemon {
106: void exist() throws RoundException, YellowException;
107:
108: void lemon();
109: }
110:
111: public interface Banana {
112: void exist() throws LongException, YellowException;
113:
114: void banana();
115: }
116:
117: public interface Creme {
118: void thiken();
119: }
120:
121: public interface Cherry extends java.rmi.Remote {
122: void exist() throws RoundException, RemoteException;
123:
124: void cherry() throws RemoteException;
125: }
126:
127: public interface Grape extends java.rmi.Remote {
128: void exist() throws RoundException, RemoteException;
129:
130: void grape() throws RemoteException;
131: }
132:
133: public interface Honey extends java.rmi.Remote {
134: void sweeten() throws RemoteException;
135: }
136:
137: //--------------//
138: public static class RoundException extends Exception {
139: }
140:
141: public static class GreenException extends Exception {
142: }
143:
144: public static class YellowException extends Exception {
145: }
146:
147: public static class LongException extends Exception {
148: }
149:
150: }
|