001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test;
008:
009: import junit.framework.TestCase;
010:
011: /**
012: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
013: */
014: public class CallerSideAdviceTest extends TestCase {
015: private static String s_logString = "";
016:
017: public CallerSideAdviceTest(String name) {
018: super (name);
019: }
020:
021: public void testAroundAdvicedMemberMethod() {
022: s_logString = "";
023: try {
024: CallerSideTestHelper helper = new CallerSideTestHelper();
025: helper.invokeMemberMethodAround("a", "b");
026: helper.invokeMemberMethodAround("a", "b", "c");
027: assertEquals("before after before after ", s_logString);
028: } catch (Exception e) {
029: e.printStackTrace();
030: fail();
031: }
032:
033: // AW-163: same JIT JP reused
034: s_logString = "";
035: try {
036: CallerSideTestHelper helper = new CallerSideTestHelper();
037: helper.invokeMemberMethodAround("a", "b", "c");
038: assertEquals("before after ", s_logString);
039: } catch (Exception e) {
040: e.printStackTrace();
041: fail();
042: }
043: }
044:
045: public void testAroundAdvicedStaticMethod() {
046: s_logString = "";
047: try {
048: CallerSideTestHelper helper = new CallerSideTestHelper();
049: helper.invokeStaticMethodAround();
050: assertEquals("before after ", s_logString);
051: } catch (Exception e) {
052: fail();
053: }
054: }
055:
056: public void testAroundAdvicedStaticMethodPrimitiveType() {
057: s_logString = "";
058: try {
059: CallerSideTestHelper helper = new CallerSideTestHelper();
060: int res = helper.invokeStaticMethodAroundPrimitiveType();
061: assertEquals("before after ", s_logString);
062: assertEquals(res, 3);
063: } catch (Exception e) {
064: fail();
065: }
066: }
067:
068: public void testAroundAdvicedMemberMethodPrimitiveType() {
069: s_logString = "";
070: try {
071: CallerSideTestHelper helper = new CallerSideTestHelper();
072: int res = helper.invokeMemberMethodAroundPrimitiveType();
073: assertEquals("before after ", s_logString);
074: assertEquals(res, 2);
075: } catch (Exception e) {
076: fail();
077: }
078: }
079:
080: public void testAroundAdvicedMemberMethodVoidType() {
081: s_logString = "";
082: try {
083: CallerSideTestHelper helper = new CallerSideTestHelper();
084: helper.invokeMemberMethodAroundVoidType();
085: assertEquals("before after ", s_logString);
086: } catch (Exception e) {
087: fail();
088: }
089: }
090:
091: public void testPreAdvicedMemberMethod() {
092: s_logString = "";
093: try {
094: CallerSideTestHelper helper = new CallerSideTestHelper();
095: helper.invokeMemberMethodPre();
096: assertEquals("pre1 pre2 ", s_logString);
097: } catch (Exception e) {
098: fail();
099: }
100: }
101:
102: public void testPostAdvicedMemberMethod() {
103: s_logString = "";
104: try {
105: CallerSideTestHelper helper = new CallerSideTestHelper();
106: helper.invokeMemberMethodPost();
107: assertEquals("post2 post1 ", s_logString);
108: } catch (Exception e) {
109: fail();
110: }
111: }
112:
113: public void testPrePostAdvicedMemberMethod() {
114: s_logString = "";
115: try {
116: CallerSideTestHelper helper = new CallerSideTestHelper();
117: helper.invokeMemberMethodPrePost();
118: assertEquals("pre1 pre2 post2 post1 ", s_logString);
119: } catch (Exception e) {
120: fail();
121: }
122: }
123:
124: public void testPreAdvicedStaticMethod() {
125: s_logString = "";
126: try {
127: CallerSideTestHelper.invokeStaticMethodPre();
128: assertEquals("pre1 pre2 ", s_logString);
129: } catch (Exception e) {
130: fail();
131: }
132: }
133:
134: public void testPostAdvicedStaticMethod() {
135: s_logString = "";
136: try {
137: CallerSideTestHelper.invokeStaticMethodPost();
138: assertEquals("post2 post1 ", s_logString);
139: } catch (Exception e) {
140: fail();
141: }
142: }
143:
144: public void testPrePostAdvicedStaticMethod() {
145: s_logString = "";
146: try {
147: CallerSideTestHelper.invokeStaticMethodPrePost();
148: assertEquals("pre1 pre2 post2 post1 ", s_logString);
149: } catch (Exception e) {
150: fail();
151: }
152: }
153:
154: public static void main(String[] args) {
155: junit.textui.TestRunner.run(suite());
156: }
157:
158: public static junit.framework.Test suite() {
159: return new junit.framework.TestSuite(CallerSideAdviceTest.class);
160: }
161:
162: // ==== methods to test ====
163: public static void log(final String wasHere) {
164: s_logString += wasHere;
165: }
166:
167: public void setFieldPreAdviced() {
168: }
169: }
|