Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring with Aspectj Load-time weaving, aspect not executing in Integration test
    primarykey
    data
    text
    <p>So I am trying to do some integration testing of existing code and need to mock out a private method return. So I figured I would give AspectJ LTW a try and weave in Around advice to the private methods and have the advice execute the pointcut ignore the response and then send on my own response.</p> <p>I executing this via a jUnit test. I am forking the execution so I can pass in the javaagent.</p> <pre><code> &lt;target name="test-integration" depends="compile-test"&gt; &lt;echo message="========================================" /&gt; &lt;echo message=" Executing target test-integration" /&gt; &lt;echo message="========================================" /&gt; &lt;delete dir="${test.report.dir}" failonerror="false" /&gt; &lt;mkdir dir="${test.report.dir}" /&gt; &lt;junit printsummary="yes" fork="yes" haltonfailure="yes" haltonerror="yes" showoutput="yes" &gt; &lt;jvmarg value="-javaagent:${spring.instrument.jar}" /&gt; &lt;classpath&gt; &lt;pathelement location="${classes.test.dir}" /&gt; &lt;pathelement location="${classes.dir}" /&gt; &lt;path refid="test.run.classpath" /&gt; &lt;path refid="compile.classpath" /&gt; &lt;pathelement location="${test.resources}" /&gt; &lt;/classpath&gt; &lt;formatter type="plain" /&gt; &lt;batchtest fork="yes" todir="${test.report.dir}"&gt; &lt;fileset dir="${classes.test.dir}"&gt; &lt;include name="com/test/integrationtest/*IntegrationTest*" /&gt; &lt;exclude name="**/*$*" /&gt; &lt;/fileset&gt; &lt;/batchtest&gt; &lt;/junit&gt; &lt;/target&gt; </code></pre> <p>And have setup the aop.xml file</p> <pre><code>&lt;aspectj&gt; &lt;weaver options="-verbose"&gt; &lt;include within="com.services.*" /&gt; &lt;dump within="com.services.*"/&gt; &lt;/weaver&gt; &lt;aspects&gt; &lt;aspect name="com.test.integrationtest.MockMethodReturnIntercepter" /&gt; &lt;/aspects&gt; </code></pre> <p></p> <p>And the log that is generated makes it look like everything is going fine.</p> <blockquote> <p>[junit] INFO [main] (DefaultContextLoadTimeWeaver.java:73) - Found Spring's JVM agent for instrumentation [junit] [AppClassLoader@12360be0] info AspectJ Weaver Version 1.6.11 built on Tuesday Mar 15, 2011 at 15:31:04 GMT [junit] [AppClassLoader@12360be0] info register classloader sun.misc.Launcher$AppClassLoader@12360be0 [junit] [AppClassLoader@12360be0] info using configuration file:/C:/dev/EntSvc/workspaces/Default/Master/jars/org.springframework.aspects-3.0.5.RELEASE.jar!/META-INF/aop.xml [junit] [AppClassLoader@12360be0] info using configuration /C:/dev/EntSvc/workspaces/Default/Monitors/test/resources/META-INF/aop.xml [junit] [AppClassLoader@12360be0] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect [junit] [AppClassLoader@12360be0] info register aspect org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect [junit] [AppClassLoader@12360be0] info register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect [junit] [AppClassLoader@12360be0] info register aspect com.test.integrationtest.MockMethodReturnIntercepter [junit] [AppClassLoader@12360be0] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified</p> </blockquote> <p>But nothing seems to come of it during execution, as I see no logging or the result from my Aspect</p> <pre><code>@Aspect public class MockMethodReturnIntercepter { private final Log log = LogFactory.getLog(getClass()); private Object returnVal; @Around("methodsToMockReturn()") public Object mockMethodReturn(ProceedingJoinPoint pjp) throws Throwable { log.info("mockMethodReturn(ProceedingJoinPoint pjp)"); // Go ahead and let it do whatever it was trying to do but just modify the return value pjp.proceed(); log.info("mockMethodReturn(ProceedingJoinPoint pjp) RETURNING:" + returnVal); return "QM_H3385R1"; } public Object getReturnVal() { return returnVal; } public void setReturnVal(Object returnVal) { this.returnVal = returnVal; } @Pointcut("execution(private * com.services.common.integration.MessageSenderDaoImpl.*(..))") public void methodsToMockReturn() { } </code></pre> <p>}</p> <p>And as you can see I am picking a specific class to weave the advice into and just picked its private methods to mock the response for.</p> <p>And then last but not least I have added </p> <pre><code>&lt;context:load-time-weaver/&gt; </code></pre> <p>To the first context file being loaded into the ClassPathXmlApplicationContext</p> <p>Anyone have any thoughts? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload