1 22 package org.jboss.test.aop.declare; 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 27 import org.jboss.test.aop.AOPTestWithSetup; 28 import org.jboss.test.aop.declare.businesslayer.BusinessObject; 29 30 import junit.framework.Test; 31 import junit.framework.TestSuite; 32 import junit.textui.TestRunner; 33 34 39 public class DeclareTestCase extends AOPTestWithSetup 40 { 41 public static void main(String [] args) 42 { 43 TestRunner.run(suite()); 44 } 45 46 public static Test suite() 47 { 48 TestSuite suite = new TestSuite("DotInPointcutNameTester"); 49 suite.addTestSuite(DeclareTestCase.class); 50 return suite; 51 } 52 53 public DeclareTestCase(String name) 54 { 55 super(name); 56 } 57 58 public void testLoadtimeDeclare()throws Exception 59 { 60 System.out.println("*** testLoadTimeDeclare"); 61 SystemOutDecorator out = null; 62 try 63 { 64 out = SystemOutDecorator.initialise(); 65 BusinessObject bo = new BusinessObject(); 66 bo.createVehicles(); 67 ArrayList expected = getExpectedWarnings(); 68 ArrayList actual = out.getWarnings(); 69 compareWarnings(expected, actual); 70 } 71 finally 72 { 73 out.kill(); 74 } 75 } 76 77 private ArrayList getExpectedWarnings() 78 { 79 ArrayList list = new ArrayList (); 81 list.add("WARNING:declare-warningcondition'(call(*org.jboss.test.aop.declare.businesslayer.*->*(..))ORcall(org.jboss.test.aop.declare.businesslayer.*->new(..)))ANDwithin(org.jboss.test.aop.declare.datalayer.*)'wasbrokenforconstructorcall:org.jboss.test.aop.declare.datalayer.Truck.new(Ljava/lang/String;)Vcallsorg.jboss.test.aop.declare.businesslayer.BusinessObject.new()VThisisanexpectedwarning:Cannotcallbusinesslayerfromdatalayer."); 82 list.add("WARNING:declare-warningcondition'(call(*org.jboss.test.aop.declare.businesslayer.*->*(..))ORcall(org.jboss.test.aop.declare.businesslayer.*->new(..)))ANDwithin(org.jboss.test.aop.declare.datalayer.*)'wasbrokenformethodcall:org.jboss.test.aop.declare.datalayer.Truck.new(Ljava/lang/String;)Vcallsorg.jboss.test.aop.declare.businesslayer.BusinessObject.someMethod()VThisisanexpectedwarning:Cannotcallbusinesslayerfromdatalayer."); 83 list.add("WARNING:declare-warningcondition'(call(*org.jboss.test.aop.declare.businesslayer.*->*(..))ORcall(org.jboss.test.aop.declare.businesslayer.*->new(..)))ANDwithin(org.jboss.test.aop.declare.datalayer.*)'wasbrokenforconstructorcall:org.jboss.test.aop.declare.datalayer.Car.badMethod()Vcallsorg.jboss.test.aop.declare.businesslayer.BusinessObject.new()VThisisanexpectedwarning:Cannotcallbusinesslayerfromdatalayer."); 84 list.add("WARNING:declare-warningcondition'(call(*org.jboss.test.aop.declare.businesslayer.*->*(..))ORcall(org.jboss.test.aop.declare.businesslayer.*->new(..)))ANDwithin(org.jboss.test.aop.declare.datalayer.*)'wasbrokenformethodcall:org.jboss.test.aop.declare.datalayer.Car.badMethod()Vcallsorg.jboss.test.aop.declare.businesslayer.BusinessObject.someMethod()VThisisanexpectedwarning:Cannotcallbusinesslayerfromdatalayer."); 85 86 list.add("WARNING:declare-warningcondition'class($instanceof{org.jboss.test.aop.declare.datalayer.Vehicle})AND!has(*->new(java.lang.String))'wasbrokenforclassorg.jboss.test.aop.declare.datalayer.CarThisisanexpectedwarning:CARshouldbementionedinmsg"); 87 list.add("WARNING:declare-warningcondition'!class(org.jboss.test.aop.declare.datalayer.Vehicle)ANDclass($instanceof{org.jboss.test.aop.declare.datalayer.Vehicle})AND!hasfield(org.jboss.test.aop.declare.Logger*->logger)'wasbrokenforclassorg.jboss.test.aop.declare.datalayer.FourWheelerThisisanexpectedwarning:FOURWHEELERshouldbementionedinmsg"); 88 list.add("WARNING:declare-warningcondition'class($instanceof{org.jboss.test.aop.declare.datalayer.Vehicle})AND!has(publicboolean*->accept(org.jboss.test.aop.declare.datalayer.MyVisitor))'wasbrokenforclassorg.jboss.test.aop.declare.datalayer.TruckThisisanexpectedwarning:TRUCKshouldbementionedinmsg"); 89 90 list.add("WARNING:declare-warningcondition'call(*org.jboss.test.aop.declare.businesslayer.*->*(..))ANDwithincode(*org.jboss.test.aop.declare.datalayer.Car->badMethod())'wasbrokenformethodcall:org.jboss.test.aop.declare.datalayer.Car.badMethod()Vcallsorg.jboss.test.aop.declare.businesslayer.BusinessObject.someMethod()VThisisanexpectedwarning:CannotcallbusinesslayerfromCar.badMethod()"); 91 92 return list; 93 } 94 95 private void compareWarnings(ArrayList expected, ArrayList actual) 96 { 97 for (Iterator ex = expected.iterator() ; ex.hasNext() ; ) 98 { 99 String want = (String )ex.next(); 100 for (Iterator ac = actual.iterator() ; ac.hasNext() ; ) 101 { 102 String have = (String )ac.next(); 103 if (have.equals(want)) 104 { 105 ex.remove(); 106 ac.remove(); 107 } 108 } 109 } 110 111 if (actual.size() > 0 || expected.size() > 0) 112 { 113 StringBuffer sb = new StringBuffer (); 114 if (actual.size() > 0) 115 { 116 sb.append("These warnings were raised but not expected\n"); 117 for (Iterator it = actual.iterator() ; it.hasNext() ; ) 118 { 119 sb.append((String )it.next() + "\n"); 120 } 121 } 122 if (expected.size() > 0) 123 { 124 sb.append("These warnings were expected but not raised\n"); 125 for (Iterator it = expected.iterator() ; it.hasNext() ; ) 126 { 127 sb.append((String )it.next() + "\n"); 128 } 129 } 130 131 throw new RuntimeException (sb.toString()); 132 } 133 134 } 135 } 136 | Popular Tags |