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.superbiz.interceptors;
017:
018: import java.util.Properties;
019: import java.util.List;
020: import java.util.ArrayList;
021:
022: import javax.naming.Context;
023: import javax.naming.InitialContext;
024:
025: import junit.framework.TestCase;
026:
027: import org.junit.After;
028: import org.junit.Before;
029: import org.junit.Test;
030:
031: /**
032: * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
033: */
034: public class FullyInterceptedTest extends TestCase {
035:
036: private InitialContext initCtx;
037:
038: @Before
039: public void setUp() throws Exception {
040: Properties properties = new Properties();
041: properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
042: "org.apache.openejb.client.LocalInitialContextFactory");
043: properties.setProperty("openejb.deployments.classpath.include",
044: ".*interceptors/target/classes.*");
045:
046: initCtx = new InitialContext(properties);
047: }
048:
049: @Test
050: public void testBusinessMethod() throws Exception {
051:
052: FullyIntercepted fullyIntercepted = (FullyIntercepted) initCtx
053: .lookup("FullyInterceptedBeanLocal");
054:
055: assert fullyIntercepted != null;
056:
057: List<String> expected = new ArrayList<String>();
058: expected.add("DefaultInterceptorOne");
059: expected.add("DefaultInterceptorTwo");
060: expected.add("ClassLevelInterceptorSuperClassOne");
061: expected.add("ClassLevelInterceptorSuperClassTwo");
062: expected.add("ClassLevelInterceptorOne");
063: expected.add("ClassLevelInterceptorTwo");
064: expected.add("MethodLevelInterceptorOne");
065: expected.add("MethodLevelInterceptorTwo");
066: expected.add("beanClassBusinessMethodInterceptor");
067: expected.add("businessMethod");
068:
069: List<String> actual = fullyIntercepted.businessMethod();
070: assert expected.equals(actual) : "Expected " + expected
071: + ", but got " + actual;
072: }
073:
074: @Test
075: public void testMethodWithDefaultInterceptorsExcluded()
076: throws Exception {
077:
078: FullyIntercepted fullyIntercepted = (FullyIntercepted) initCtx
079: .lookup("FullyInterceptedBeanLocal");
080:
081: assert fullyIntercepted != null;
082:
083: List<String> expected = new ArrayList<String>();
084: expected.add("ClassLevelInterceptorSuperClassOne");
085: expected.add("ClassLevelInterceptorSuperClassTwo");
086: expected.add("ClassLevelInterceptorOne");
087: expected.add("ClassLevelInterceptorTwo");
088: expected.add("MethodLevelInterceptorOne");
089: expected.add("MethodLevelInterceptorTwo");
090: expected.add("beanClassBusinessMethodInterceptor");
091: expected.add("methodWithDefaultInterceptorsExcluded");
092:
093: List<String> actual = fullyIntercepted
094: .methodWithDefaultInterceptorsExcluded();
095: assert expected.equals(actual) : "Expected " + expected
096: + ", but got " + actual;
097: }
098:
099: @After
100: public void tearDown() throws Exception {
101: initCtx.close();
102: }
103: }
|