From: Kabir K. <kk...@jb...> - 2006-07-10 15:00:30
|
User: kkhan Date: 06/07/10 11:00:24 Added: src/test/org/jboss/test/aop/jdk15annotateddeclare SystemOutDecorator.java DeclareAspect.java AnnotatedDeclareTestCase.java POJO.java Log: Make a start migrating to jboss retro Revision Changes Path 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15annotateddeclare/SystemOutDecorator.java Index: SystemOutDecorator.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15annotateddeclare; import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; /** * Wraps calls to System.out.println(String), and stores all Strings beginning * with "WARNING:" * * @author <a href="mailto:kab...@jb...">Kabir Khan</a> * @version $Revision: 1.1 $ */ public class SystemOutDecorator extends PrintStream { static PrintStream sysout = null; ArrayList warnings = new ArrayList(); public SystemOutDecorator(OutputStream out) { super(out); sysout = System.out; } public ArrayList getWarnings() { return warnings; } public void println(String msg) { super.println(msg); if (msg.startsWith("WARNING:")) { System.out.println(">>>>>"); super.println(msg); System.out.println("<<<<<"); warnings.add(msg); } } public static SystemOutDecorator initialise() { SystemOutDecorator sys = new SystemOutDecorator(System.out); System.setOut(sys); return sys; } public void kill() { System.setOut(sysout); } String getRidOfAllWhiteSpace(String msg) { StringBuffer sb = new StringBuffer(); for (int i = 0 ; i < msg.length() ; i++) { char ch = msg.charAt(i); if (ch != '\n' && ch != '\t' && ch != ' ' && ch != '\r') { sb.append(ch); } } return sb.toString(); } } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15annotateddeclare/DeclareAspect.java Index: DeclareAspect.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15annotateddeclare; import org.jboss.aop.pointcut.Pointcut; import org.jboss.aop.Aspect; import org.jboss.aop.DeclareError; import org.jboss.aop.DeclareWarning; /** * * @author <a href="mailto:kab...@jb...">Kabir Khan</a> * @version $Revision: 1.1 $ */ @Aspect (scope=org.jboss.aop.advice.Scope.PER_VM) public class DeclareAspect { @DeclareError (expr="call(* org.jboss.test.aop.jdk15annotated.declare.POJO->someMethod()) AND withincode(* org.jboss.test.aop.jdk15annotated.declare.POJO->otherMethod())", msg="Should not happen") Pointcut error; @DeclareWarning (expr="call(* org.jboss.test.aop.jdk15annotated.declare.POJO->otherMethod()) AND withincode(* org.jboss.test.aop.jdk15annotated.declare.POJO->someMethod())", msg="Expected annotated warning") Pointcut warning; } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15annotateddeclare/AnnotatedDeclareTestCase.java Index: AnnotatedDeclareTestCase.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15annotateddeclare; import java.util.ArrayList; import org.jboss.test.aop.AOPTestWithSetup; import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner; /** * * @author <a href="mailto:kab...@jb...">Kabir Khan</a> * @version $Revision: 1.1 $ */ public class AnnotatedDeclareTestCase extends AOPTestWithSetup { SystemOutDecorator out = null; public static void main(String[] args) { TestRunner.run(suite()); } public static Test suite() { TestSuite suite = new TestSuite("AnnotatedDeclareTestCase"); suite.addTestSuite(AnnotatedDeclareTestCase.class); return suite; } public AnnotatedDeclareTestCase(String name) { super(name); } protected void setUp() throws Exception { out = SystemOutDecorator.initialise(); super.setUp(); } public void testLoadtimeAnnotatedDeclare()throws Exception { System.out.println("*** testLoadtimeAnnotatedDeclare"); POJO pojo = new POJO(); pojo.someMethod(); ArrayList actual = out.getWarnings(); assertEquals("Wrong number of warnings generated", 1, actual.size()); String s = (String)actual.get(0); assertTrue("Warning does not end with the expected \"Expected annotated warning\"", s.endsWith("Expected annotated warning\n")); } } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15annotateddeclare/POJO.java Index: POJO.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15annotateddeclare; /** * * @author <a href="mailto:kab...@jb...">Kabir Khan</a> * @version $Revision: 1.1 $ */ public class POJO { void someMethod() { otherMethod(); } void otherMethod() { } } |