001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.deployment;
008:
009: import junit.framework.TestCase;
010: import org.codehaus.aspectwerkz.transform.inlining.deployer.Deployer;
011: import org.codehaus.aspectwerkz.transform.inlining.deployer.DeploymentHandle;
012: import org.codehaus.aspectwerkz.definition.DeploymentScope;
013: import org.codehaus.aspectwerkz.definition.SystemDefinition;
014: import org.codehaus.aspectwerkz.definition.SystemDefinitionContainer;
015:
016: /**
017: * TODO add more tests, tests that can make things break, evil tests
018: * <p/>
019: * TODO tests for all pointcut types
020: *
021: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
022: */
023: public class DeployerTest extends TestCase {
024: private static String s_logString = "";
025:
026: public DeployerTest(String name) {
027: super (name);
028: }
029:
030: public void testDeployUndeployUsingPreparedPointcut() {
031: s_logString = "";
032:
033: deployUndeployUsingPreparedPointcut();
034: assertEquals("deployUndeployUsingPreparedPointcut ",
035: s_logString);
036: s_logString = "";
037:
038: SystemDefinition def = SystemDefinitionContainer
039: .getDefinitionFor(Thread.currentThread()
040: .getContextClassLoader(), "tests");
041: DeploymentScope deploymentScope = def
042: .getDeploymentScope("deployUndeployUsingPreparedPointcut");
043:
044: Deployer.deploy(AnnDefAspect.class, deploymentScope);
045:
046: deployUndeployUsingPreparedPointcut();
047: assertEquals(
048: "before deployUndeployUsingPreparedPointcut after ",
049: s_logString);
050: s_logString = "";
051:
052: Deployer.undeploy(AnnDefAspect.class);
053:
054: deployUndeployUsingPreparedPointcut();
055: assertEquals("deployUndeployUsingPreparedPointcut ",
056: s_logString);
057: }
058:
059: public void testDeployUndeployUsingHandle() {
060: s_logString = "";
061:
062: deployUndeployUsingHandle();
063: assertEquals("deployUndeployUsingHandle ", s_logString);
064: s_logString = "";
065:
066: SystemDefinition def = SystemDefinitionContainer
067: .getDefinitionFor(Thread.currentThread()
068: .getContextClassLoader(), "tests");
069: DeploymentScope deploymentScope = def
070: .getDeploymentScope("deployUndeployUsingHandle");
071: DeploymentHandle handle = Deployer.deploy(AnnDefAspect.class,
072: deploymentScope);
073:
074: deployUndeployUsingHandle();
075: assertEquals("before deployUndeployUsingHandle after ",
076: s_logString);
077: s_logString = "";
078:
079: Deployer.undeploy(handle);
080:
081: deployUndeployUsingHandle();
082: assertEquals("deployUndeployUsingHandle ", s_logString);
083: }
084:
085: public void testDeployUndeployUsingXmlDef() {
086: s_logString = "";
087:
088: deployUndeployUsingXmlDef();
089: assertEquals("deployUndeployUsingXmlDef ", s_logString);
090: s_logString = "";
091:
092: SystemDefinition def = SystemDefinitionContainer
093: .getDefinitionFor(Thread.currentThread()
094: .getContextClassLoader(), "tests");
095: DeploymentScope deploymentScope = def
096: .getDeploymentScope("deployUndeployUsingXmlDef");
097:
098: String aspectXmlDef = "<aspect class=\"test.deployment.XmlDefAspect\">"
099: + "<pointcut name=\"pc\" expression=\"execution(void test.deployment.DeployerTest.deployUndeployUsingXmlDef())\"/>"
100: + "<advice name=\"advice\" type=\"around\" bind-to=\"pc\"/>"
101: + "</aspect>";
102: Deployer.deploy(XmlDefAspect.class, aspectXmlDef,
103: deploymentScope);
104:
105: deployUndeployUsingXmlDef();
106: assertEquals("before deployUndeployUsingXmlDef after ",
107: s_logString);
108: s_logString = "";
109:
110: Deployer.undeploy(XmlDefAspect.class);
111:
112: deployUndeployUsingXmlDef();
113: assertEquals("deployUndeployUsingXmlDef ", s_logString);
114: }
115:
116: private void deployUndeployUsingHandle() {
117: log("deployUndeployUsingHandle ");
118: }
119:
120: private void deployUndeployUsingPreparedPointcut() {
121: log("deployUndeployUsingPreparedPointcut ");
122: }
123:
124: private void deployUndeployUsingXmlDef() {
125: log("deployUndeployUsingXmlDef ");
126: }
127:
128: public static void main(String[] args) {
129: junit.textui.TestRunner.run(suite());
130: }
131:
132: public static junit.framework.Test suite() {
133: return new junit.framework.TestSuite(DeployerTest.class);
134: }
135:
136: public static void log(final String wasHere) {
137: s_logString += wasHere;
138: }
139: }
|