Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RES: RES: [aspectj-users] How to?

Thanks Ramnivas! It's working now. 

-----Mensagem original-----
De: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx]
Em nome de Ramnivas Laddad
Enviada em: terça-feira, 14 de setembro de 2004 00:11
Para: aspectj-users@xxxxxxxxxxx
Assunto: Re: RES: [aspectj-users] How to?

Adre,

Here is the aspect that does work; some parenthesis weren't correctly placed
in my original solution. You should refactor the testsFlow() pointcut to
make it more understandable.

package analizer;

import pdv.*;
import junit.framework.TestCase;

public aspect DepedenceAnalizer {
 
  pointcut testsFlow(TestCase testCase) :
      execution(EspecificacaoProduto
CatalogoProdutos.getEspecificacao(int)) &&
      cflow((execution (* junit.framework.TestCase+.test*())) &&
      this(testCase));
  
  before(TestCase testCase) : testsFlow(testCase) {
    System.out.println(testCase.getClass());
  }
}

For getting the test method name, you will want to advice 
TestCase+.test*(), and store away the thisJoinPointStaticPart somewhere
(preferable in a ThreadLocal -- but since testing happens from a single
thread, a static variable somewhere, say in the aspect, may be sufficient).
Then use that variable in advice to CatalogoProdutos.getEspecificacao(int).

-Ramnivas

===
Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com



André Dantas Rocha wrote:

>Thanks Ramnivas,
>
>But still not working... Now, my pointcut picks nothing...
>
>My program is attached (Eclipse project).
>
>PDVTest.testeEntrarItem() calls PDV.entrarItem(int,int) that calls
>CatalogoProdutos.getEspecificacao(int) that must me intercepted.
>
>In addition it possible to get the caller 'test' method too? (in this 
>case
>testeEntrarItem)
>
>Thanks,
>
>André
>
>
>
>-----Mensagem original-----
>De: aspectj-users-admin@xxxxxxxxxxx 
>[mailto:aspectj-users-admin@xxxxxxxxxxx]
>Em nome de Ramnivas Laddad
>Enviada em: segunda-feira, 13 de setembro de 2004 22:07
>Para: aspectj-users@xxxxxxxxxxx
>Assunto: Re: [aspectj-users] How to?
>
>Use the following aspect:
>
>public aspect Analizer {
>  pointcut testsFlow(TestCase testCase) :
>      call(* MyClass.myMethod(..)) &&
>      cflow(execution (* junit.framework.TestCase+.test*()) && 
>this(testCase));
>  
>  before(TestCase testCase) : testsFlow(testCase) {
>    System.out.println(testCase.getClass());
>  }
>}
>
>And you have just used the wormhole design pattern!
>
>-Ramnivas
>
>===
>Ramnivas Laddad,
>Author, AspectJ in Action
>http://ramnivas.com
>
>
>
>André Dantas Rocha wrote:
>
>  
>
>>Hi,
>> 
>>I'd like to print the TestCase name from witch myMethod is called (not 
>>directly, but in the TestCase control-flow).
>>Is it possible via pointcut declaration? my code is shown below... 
>> 
>>public class MyClass {
>>  void xx() { myMethod(); }
>>  void myMethod() {...}
>>}
>> 
>>public void testM() {
>>  new MyClass().xx();
>>}
>> 
>>public aspect Analizer {
>>  pointcut testsFlow() :
>>      call(* MyClass.myMethod(..)) &&
>>      cflow(execution (* junit.framework.TestCase+.test*()));
>>  
>>  before() : testsFlow() {
>>    System.out.println(thisJoinPoint); // not working, must print 
>>"testM"...
>>  }
>>}
>> 
>>Thanks,
>> 
>>André
>>    
>>
>
>_______________________________________________
>aspectj-users mailing list
>aspectj-users@xxxxxxxxxxx
>http://dev.eclipse.org/mailman/listinfo/aspectj-users
>  
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top