1 8 package test.deployment; 9 10 import junit.framework.TestCase; 11 import org.codehaus.aspectwerkz.transform.inlining.deployer.Deployer; 12 import org.codehaus.aspectwerkz.transform.inlining.deployer.DeploymentHandle; 13 import org.codehaus.aspectwerkz.definition.DeploymentScope; 14 import org.codehaus.aspectwerkz.definition.SystemDefinition; 15 import org.codehaus.aspectwerkz.definition.SystemDefinitionContainer; 16 17 24 public class DeployerTest extends TestCase { 25 private static String s_logString = ""; 26 27 public DeployerTest(String name) { 28 super(name); 29 } 30 31 public void testDeployUndeployUsingPreparedPointcut() { 32 s_logString = ""; 33 34 deployUndeployUsingPreparedPointcut(); 35 assertEquals("deployUndeployUsingPreparedPointcut ", s_logString); 36 s_logString = ""; 37 38 SystemDefinition def = SystemDefinitionContainer.getDefinitionFor( 39 Thread.currentThread().getContextClassLoader(), "tests" 40 ); 41 DeploymentScope deploymentScope = def.getDeploymentScope("deployUndeployUsingPreparedPointcut"); 42 43 Deployer.deploy(AnnDefAspect.class, deploymentScope); 44 45 deployUndeployUsingPreparedPointcut(); 46 assertEquals("before deployUndeployUsingPreparedPointcut after ", s_logString); 47 s_logString = ""; 48 49 Deployer.undeploy(AnnDefAspect.class); 50 51 deployUndeployUsingPreparedPointcut(); 52 assertEquals("deployUndeployUsingPreparedPointcut ", s_logString); 53 } 54 55 public void testDeployUndeployUsingHandle() { 56 s_logString = ""; 57 58 deployUndeployUsingHandle(); 59 assertEquals("deployUndeployUsingHandle ", s_logString); 60 s_logString = ""; 61 62 SystemDefinition def = SystemDefinitionContainer.getDefinitionFor( 63 Thread.currentThread().getContextClassLoader(), "tests" 64 ); 65 DeploymentScope deploymentScope = def.getDeploymentScope("deployUndeployUsingHandle"); 66 DeploymentHandle handle = Deployer.deploy(AnnDefAspect.class, deploymentScope); 67 68 deployUndeployUsingHandle(); 69 assertEquals("before deployUndeployUsingHandle after ", s_logString); 70 s_logString = ""; 71 72 Deployer.undeploy(handle); 73 74 deployUndeployUsingHandle(); 75 assertEquals("deployUndeployUsingHandle ", s_logString); 76 } 77 78 public void testDeployUndeployUsingXmlDef() { 79 s_logString = ""; 80 81 deployUndeployUsingXmlDef(); 82 assertEquals("deployUndeployUsingXmlDef ", s_logString); 83 s_logString = ""; 84 85 SystemDefinition def = SystemDefinitionContainer.getDefinitionFor( 86 Thread.currentThread().getContextClassLoader(), "tests" 87 ); 88 DeploymentScope deploymentScope = def.getDeploymentScope("deployUndeployUsingXmlDef"); 89 90 String aspectXmlDef = 91 "<aspect class=\"test.deployment.XmlDefAspect\">" + 92 "<pointcut name=\"pc\" expression=\"execution(void test.deployment.DeployerTest.deployUndeployUsingXmlDef())\"/>" + 93 "<advice name=\"advice\" type=\"around\" bind-to=\"pc\"/>" + 94 "</aspect>"; 95 Deployer.deploy(XmlDefAspect.class, aspectXmlDef, deploymentScope); 96 97 deployUndeployUsingXmlDef(); 98 assertEquals("before deployUndeployUsingXmlDef after ", s_logString); 99 s_logString = ""; 100 101 Deployer.undeploy(XmlDefAspect.class); 102 103 deployUndeployUsingXmlDef(); 104 assertEquals("deployUndeployUsingXmlDef ", s_logString); 105 } 106 107 private void deployUndeployUsingHandle() { 108 log("deployUndeployUsingHandle "); 109 } 110 111 private void deployUndeployUsingPreparedPointcut() { 112 log("deployUndeployUsingPreparedPointcut "); 113 } 114 115 private void deployUndeployUsingXmlDef() { 116 log("deployUndeployUsingXmlDef "); 117 } 118 119 public static void main(String [] args) { 120 junit.textui.TestRunner.run(suite()); 121 } 122 123 public static junit.framework.Test suite() { 124 return new junit.framework.TestSuite(DeployerTest.class); 125 } 126 127 public static void log(final String wasHere) { 128 s_logString += wasHere; 129 } 130 } 131 | Popular Tags |