001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.aop.bean;
023:
024: import org.jboss.aop.Advised;
025:
026: /**
027: *
028: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
029: * @version $Revision: 57211 $
030: */
031: public class CallingPOJO {
032: POJO pojo;
033: NonadvisedPOJO nonpojo;
034:
035: public CallingPOJO() {
036: CallerInterceptor.called = false;
037: pojo = new POJO();
038: if (!CallerInterceptor.called) {
039: throw new RuntimeException(
040: "constructor caller interceptor didn't work from within constructor");
041: }
042: CallerInterceptor.called = false;
043: pojo.someMethod();
044: if (!CallerInterceptor.called) {
045: throw new RuntimeException("caller interceptor didn't work");
046: }
047: CallerInterceptor.called = false;
048: nonpojo = new NonadvisedPOJO("helloworld");
049: if (!CallerInterceptor.called) {
050: throw new RuntimeException(
051: "constructor caller interceptor didn't work");
052: }
053: CallerInterceptor.called = false;
054: nonpojo.remoteTest();
055: if (!CallerInterceptor.called) {
056: throw new RuntimeException("caller interceptor didn't work");
057: }
058: if (nonpojo instanceof Advised) {
059: throw new RuntimeException(
060: "nonpojo is Advised when it shouldn't be");
061: }
062: }
063:
064: /**
065: * This method should be a caller pointcut
066: */
067: public void callSomeMethod() {
068: CallerInterceptor.called = false;
069: pojo = new POJO();
070: if (!CallerInterceptor.called) {
071: throw new RuntimeException(
072: "constructor caller interceptor didn't work within method");
073: }
074: CallerInterceptor.called = false;
075: pojo.someMethod();
076: if (!CallerInterceptor.called) {
077: throw new RuntimeException("caller interceptor didn't work");
078: }
079: }
080:
081: /**
082: * This method should not be a caller pointcut
083: */
084: public void nocallSomeMethod() {
085: CallerInterceptor.called = false;
086: pojo = new POJO();
087: if (CallerInterceptor.called) {
088: throw new RuntimeException(
089: "constructor caller interceptor didn't work, interceptor was invoked when it shouldn't have been");
090: }
091: pojo.someMethod();
092: if (CallerInterceptor.called) {
093: throw new RuntimeException(
094: "caller interceptor didn't work, caller interceptor was invoked when it shouldn't have been");
095: }
096: }
097:
098: public void callUnadvised() {
099: CallerInterceptor.called = false;
100: nonpojo = new NonadvisedPOJO("helloworld");
101: if (!CallerInterceptor.called) {
102: throw new RuntimeException(
103: "consturctor caller interceptor didn't work");
104: }
105: CallerInterceptor.called = false;
106: nonpojo.remoteTest();
107: if (!CallerInterceptor.called) {
108: throw new RuntimeException("caller interceptor didn't work");
109: }
110: if (nonpojo instanceof Advised) {
111: throw new RuntimeException(
112: "nonpojo is Advised when it shouldn't be");
113: }
114: }
115:
116: }
|