KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * JBoss, Home of Professional Open Source.
3 * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4 * as indicated by the @author tags. See the copyright.txt file in the
5 * distribution for a 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 java.util.HashMap JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32
33 import org.jboss.test.JBossTestCase;
34
35 /**
36  * Test to see if things get deployed/undeployed correctly using the new deployers
37  *
38  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
39  * @version $Revision: 1.1 $
40  */

41 public class DeployersInitialTestCase extends JBossTestCase
42 {
43    final static ObjectName JavaDoc DEPLOYER_MONITOR;
44    static
45    {
46       try
47       {
48          DEPLOYER_MONITOR = new ObjectName JavaDoc("jboss.aop:service=DeployerMonitor");
49       }
50       catch (Exception JavaDoc e)
51       {
52          // AutoGenerated
53
throw new RuntimeException JavaDoc(e);
54       }
55    }
56
57    public DeployersInitialTestCase(String JavaDoc name)
58    {
59       super(name);
60    }
61    
62    public void testAddXMLBindings() throws Exception JavaDoc
63    {
64       Map JavaDoc<String JavaDoc, String JavaDoc> initialBindings = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
65       Map JavaDoc<String JavaDoc, String JavaDoc> initialDefinitiona = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
66       
67       try
68       {
69          deploy("aop-deployertest-xml.aop");
70
71          Map JavaDoc<String JavaDoc, String JavaDoc> deployedBindings = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
72          Map JavaDoc<String JavaDoc, String JavaDoc> deployedDefinitiona = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
73          
74          Map JavaDoc<String JavaDoc, String JavaDoc> newBindings = getInEndOnly(initialBindings, deployedBindings);
75          assertEquals("Wrong number of new bindings", 2, newBindings.size());
76          
77          Map JavaDoc<String JavaDoc, String JavaDoc> newDefinitions = getInEndOnly(initialDefinitiona, deployedDefinitiona);
78          assertEquals("Wrong number of new aspect definitions", 4, newDefinitions.size());
79          
80          HashSet JavaDoc<String JavaDoc> bindings = new HashSet JavaDoc<String JavaDoc>();
81          bindings.addAll(newBindings.values());
82          assertTrue("Could not find 'execution(* org.jboss.test.aop.deployers.xml.POJO->someMethod())'", bindings.remove("execution(* org.jboss.test.aop.deployers.xml.POJO->someMethod())"));
83          assertTrue("Could not find 'execution(void org.jboss.test.aop.deployers.xml.POJO->someMethod())'", bindings.remove("execution(void org.jboss.test.aop.deployers.xml.POJO->someMethod())"));
84          
85          String JavaDoc name = "someinterceptor";
86          String JavaDoc clazz = newDefinitions.get(name);
87          assertNotNull("No clazz found for " + name, clazz);
88          assertEquals("Wrong clazz for " + name, "org.jboss.test.aop.deployers.xml.SomeInterceptor", clazz);
89          newDefinitions.remove(name);
90          
91          name = "someaspect";
92          clazz = newDefinitions.get(name);
93          assertNotNull("No clazz found for " + name, clazz);
94          assertEquals("Wrong clazz for " + name, "org.jboss.test.aop.deployers.xml.SomeAspect", clazz);
95          newDefinitions.remove(name);
96          
97          assertEquals(2, newDefinitions.size());
98          
99          HashSet JavaDoc<String JavaDoc> definitions = new HashSet JavaDoc<String JavaDoc>();
100          definitions.addAll(newDefinitions.values());
101          assertTrue("Could not find 'org.jboss.test.aop.deployers.xml.SomeInterceptor'", definitions.remove("org.jboss.test.aop.deployers.xml.SomeInterceptor"));
102          assertTrue("Could not find 'org.jboss.test.aop.deployers.xml.SomeAspect'", definitions.remove("org.jboss.test.aop.deployers.xml.SomeAspect"));
103
104          getServer().invoke(DEPLOYER_MONITOR, "invokeXmlPOJO", new Object JavaDoc[0], new String JavaDoc[0]);
105          
106       }
107       catch(Exception JavaDoc e)
108       {
109          throw e;
110       }
111       finally
112       {
113          undeploy("aop-deployertest-xml.aop");
114       }
115       
116       Map JavaDoc<String JavaDoc, String JavaDoc> finalBindings = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
117       Map JavaDoc<String JavaDoc, String JavaDoc> finalAspectDefinitiona = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
118       
119       compareSame(initialBindings, finalBindings);
120       compareSame(initialDefinitiona, finalAspectDefinitiona);
121    }
122    
123    public void testAddAnnotationBindings() throws Exception JavaDoc
124    {
125       Map JavaDoc<String JavaDoc, String JavaDoc> initialBindings = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
126       Map JavaDoc<String JavaDoc, String JavaDoc> initialDefinitiona = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
127
128       try
129       {
130          deploy("aop-deployertest-annotations.aop");
131          Map JavaDoc<String JavaDoc, String JavaDoc> deployedBindings = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
132          Map JavaDoc<String JavaDoc, String JavaDoc> deployedDefinitiona = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
133          
134          Map JavaDoc<String JavaDoc, String JavaDoc> newBindings = getInEndOnly(initialBindings, deployedBindings);
135          assertEquals("Wrong number of new bindings", 2, newBindings.size());
136          
137          Map JavaDoc<String JavaDoc, String JavaDoc> newDefinitions = getInEndOnly(initialDefinitiona, deployedDefinitiona);
138          assertEquals("Wrong number of new aspect definitions", 2, newDefinitions.size());
139          
140          HashSet JavaDoc<String JavaDoc> bindings = new HashSet JavaDoc<String JavaDoc>();
141          bindings.addAll(newBindings.values());
142          assertTrue("Could not find 'execution(* org.jboss.test.aop.deployers.annotations.POJO->someMethod())'", bindings.remove("execution(* org.jboss.test.aop.deployers.annotations.POJO->someMethod())"));
143          assertTrue("Could not find 'execution(void org.jboss.test.aop.deployers.annotations.POJO->someMethod())'", bindings.remove("execution(void org.jboss.test.aop.deployers.annotations.POJO->someMethod())"));
144
145          HashSet JavaDoc<String JavaDoc> definitions = new HashSet JavaDoc<String JavaDoc>();
146          definitions.addAll(newDefinitions.values());
147          assertTrue("Could not find 'org.jboss.test.aop.deployers.annotations.SomeInterceptor'", definitions.remove("org.jboss.test.aop.deployers.annotations.SomeInterceptor"));
148          assertTrue("Could not find 'org.jboss.test.aop.deployers.annotations.SomeAspect'", definitions.remove("org.jboss.test.aop.deployers.annotations.SomeAspect"));
149
150          getServer().invoke(DEPLOYER_MONITOR, "invokeAnnotationPOJO", new Object JavaDoc[0], new String JavaDoc[0]);
151       }
152       catch(Exception JavaDoc e)
153       {
154          throw e;
155       }
156       finally
157       {
158          undeploy("aop-deployertest-annotations.aop");
159       }
160       
161       Map JavaDoc<String JavaDoc, String JavaDoc> finalBindings = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
162       Map JavaDoc<String JavaDoc, String JavaDoc> finalAspectDefinitiona = (Map JavaDoc<String JavaDoc, String JavaDoc>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
163       
164       compareSame(initialBindings, finalBindings);
165       compareSame(initialDefinitiona, finalAspectDefinitiona);
166    }
167    
168    private static void compareSame(Map JavaDoc<String JavaDoc, String JavaDoc> initial, Map JavaDoc<String JavaDoc, String JavaDoc> end) throws Exception JavaDoc
169    {
170       assertEquals("Length was not same", initial.size(), end.size());
171       
172       for (String JavaDoc key : end.keySet())
173       {
174          String JavaDoc initialValue = initial.get(key);
175          assertNotNull("Value for " + key + " was null", initialValue);
176          assertEquals("Values should be the same", initialValue, end.get(key));
177       }
178    }
179    
180    private static Map JavaDoc<String JavaDoc, String JavaDoc> getInEndOnly(Map JavaDoc<String JavaDoc, String JavaDoc> initial, Map JavaDoc<String JavaDoc, String JavaDoc> end) throws Exception JavaDoc
181    {
182       HashMap JavaDoc<String JavaDoc, String JavaDoc> endOnly = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
183       
184       for (String JavaDoc key : end.keySet())
185       {
186          if (initial.get(key) == null)
187          {
188             endOnly.put(key, end.get(key));
189          }
190       }
191       
192       return endOnly;
193    }
194    
195    public static Test suite() throws Exception JavaDoc
196    {
197       TestSuite suite = new TestSuite();
198       suite.addTest(new TestSuite(DeployersInitialTestCase.class));
199
200       AOPTestSetup setup = new AOPTestSetup(suite, "aop-deployertest.sar");
201       return setup;
202    }
203 }
204
Popular Tags