1 22 package org.jboss.test.aop.test; 23 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import java.util.Map ; 27 28 import javax.management.ObjectName ; 29 30 import junit.framework.Test; 31 import junit.framework.TestSuite; 32 33 import org.jboss.test.JBossTestCase; 34 35 41 public class DeployersInitialTestCase extends JBossTestCase 42 { 43 final static ObjectName DEPLOYER_MONITOR; 44 static 45 { 46 try 47 { 48 DEPLOYER_MONITOR = new ObjectName ("jboss.aop:service=DeployerMonitor"); 49 } 50 catch (Exception e) 51 { 52 throw new RuntimeException (e); 54 } 55 } 56 57 public DeployersInitialTestCase(String name) 58 { 59 super(name); 60 } 61 62 public void testAddXMLBindings() throws Exception 63 { 64 Map <String , String > initialBindings = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings"); 65 Map <String , String > initialDefinitiona = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions"); 66 67 try 68 { 69 deploy("aop-deployertest-xml.aop"); 70 71 Map <String , String > deployedBindings = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings"); 72 Map <String , String > deployedDefinitiona = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions"); 73 74 Map <String , String > newBindings = getInEndOnly(initialBindings, deployedBindings); 75 assertEquals("Wrong number of new bindings", 2, newBindings.size()); 76 77 Map <String , String > newDefinitions = getInEndOnly(initialDefinitiona, deployedDefinitiona); 78 assertEquals("Wrong number of new aspect definitions", 4, newDefinitions.size()); 79 80 HashSet <String > bindings = new HashSet <String >(); 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 name = "someinterceptor"; 86 String 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 <String > definitions = new HashSet <String >(); 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 [0], new String [0]); 105 106 } 107 catch(Exception e) 108 { 109 throw e; 110 } 111 finally 112 { 113 undeploy("aop-deployertest-xml.aop"); 114 } 115 116 Map <String , String > finalBindings = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings"); 117 Map <String , String > finalAspectDefinitiona = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions"); 118 119 compareSame(initialBindings, finalBindings); 120 compareSame(initialDefinitiona, finalAspectDefinitiona); 121 } 122 123 public void testAddAnnotationBindings() throws Exception 124 { 125 Map <String , String > initialBindings = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings"); 126 Map <String , String > initialDefinitiona = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions"); 127 128 try 129 { 130 deploy("aop-deployertest-annotations.aop"); 131 Map <String , String > deployedBindings = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings"); 132 Map <String , String > deployedDefinitiona = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions"); 133 134 Map <String , String > newBindings = getInEndOnly(initialBindings, deployedBindings); 135 assertEquals("Wrong number of new bindings", 2, newBindings.size()); 136 137 Map <String , String > newDefinitions = getInEndOnly(initialDefinitiona, deployedDefinitiona); 138 assertEquals("Wrong number of new aspect definitions", 2, newDefinitions.size()); 139 140 HashSet <String > bindings = new HashSet <String >(); 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 <String > definitions = new HashSet <String >(); 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 [0], new String [0]); 151 } 152 catch(Exception e) 153 { 154 throw e; 155 } 156 finally 157 { 158 undeploy("aop-deployertest-annotations.aop"); 159 } 160 161 Map <String , String > finalBindings = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings"); 162 Map <String , String > finalAspectDefinitiona = (Map <String , String >)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions"); 163 164 compareSame(initialBindings, finalBindings); 165 compareSame(initialDefinitiona, finalAspectDefinitiona); 166 } 167 168 private static void compareSame(Map <String , String > initial, Map <String , String > end) throws Exception 169 { 170 assertEquals("Length was not same", initial.size(), end.size()); 171 172 for (String key : end.keySet()) 173 { 174 String 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 <String , String > getInEndOnly(Map <String , String > initial, Map <String , String > end) throws Exception 181 { 182 HashMap <String , String > endOnly = new HashMap <String , String >(); 183 184 for (String 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 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 |