KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > test > AOPClassLoaderHookTestSetup


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.aop.test;
23
24 import javax.management.ObjectName JavaDoc;
25 import javax.management.Attribute JavaDoc;
26
27 import junit.framework.TestSuite;
28 import org.jboss.test.JBossTestSetup;
29
30 /** A test setup wrapper that enables the AspectManager transformation mode
31  * on setUp and disables it on tearDown.
32  *
33  * For use with either the -javaagent or -Xbootclasspath switches
34  *
35  * @author Scott.Stark@jboss.org
36  * @version $Revision$
37  */

38 public class AOPClassLoaderHookTestSetup extends JBossTestSetup
39 {
40    public static String JavaDoc ASPECT_MANAGER_NAME = "jboss.aop:service=AspectManager";
41
42    private String JavaDoc[] jars;
43
44    // Create an initializer for the test suite
45
public AOPClassLoaderHookTestSetup(TestSuite suite, String JavaDoc jar) throws Exception JavaDoc
46    {
47       super(suite);
48       this.jars = jar.split(",");
49    }
50
51    protected void setUp() throws Exception JavaDoc
52    {
53       super.setUp();
54       ObjectName JavaDoc aspectManager = new ObjectName JavaDoc(ASPECT_MANAGER_NAME);
55       Attribute JavaDoc enableTransformer = new Attribute JavaDoc("EnableLoadtimeWeaving", Boolean.TRUE);
56       getServer().setAttribute(aspectManager, enableTransformer);
57 // Attribute verbose = new Attribute("Verbose", Boolean.TRUE);
58
// getServer().setAttribute(aspectManager, verbose);
59
try
60       {
61          for (int i = 0 ; i < jars.length ; i++)
62          {
63             String JavaDoc jar = jars[i].trim();
64             redeploy(jar);
65          }
66       }
67       catch(Exception JavaDoc e)
68       {
69          // Reset the EnableTransformer to false
70
try
71          {
72             enableTransformer = new Attribute JavaDoc("EnableLoadtimeWeaving", Boolean.FALSE);
73             getServer().setAttribute(aspectManager, enableTransformer);
74 // verbose = new Attribute("Verbose", Boolean.TRUE);
75
// getServer().setAttribute(aspectManager, verbose);
76
}
77          catch(Exception JavaDoc ex)
78          {
79             getLog().error("Failed to set EnableLoadtimeWeaving to false", ex);
80          }
81          throw e;
82       }
83    }
84    protected void tearDown() throws Exception JavaDoc
85    {
86       Exception JavaDoc undeployException = null;
87       for (int i = 0 ; i < jars.length ; i++)
88       {
89          try
90          {
91             String JavaDoc jar = jars[i].trim();
92             undeploy(jar);
93          }
94          catch(Exception JavaDoc e)
95          {
96             undeployException = e;
97          }
98       }
99       ObjectName JavaDoc aspectManager = new ObjectName JavaDoc(ASPECT_MANAGER_NAME);
100       Attribute JavaDoc enableTransformer = new Attribute JavaDoc("EnableLoadtimeWeaving", Boolean.FALSE);
101       getServer().setAttribute(aspectManager, enableTransformer);
102       if( undeployException != null )
103          throw undeployException;
104       super.tearDown();
105    }
106 }
107
Popular Tags