10 Replies Latest reply on Nov 3, 2004 8:54 PM by ad-rocha

    Introduction

       

      "ad-rocha" wrote:

      I have some test cases implemented using JUnit, so these classes (Test1, Test2)
      extends TestCase. I've created a new class (MyTestCase) that extends and modify
      TestCase default implementation, adding new fields and methods.


      Compiling with AspectJ I can force my test cases to extends MyTestCase instead
      TestCase and perform the new behavior...

      Andrea


      Hi!

      I've compared two approaches and I think it is impossible to realize your
      UseCase with JBossAOP.

      Comparing to AspectJ in field of introductions JBossAOP is quite weak.
      It is "..% pure Java" and that's the reason.

      As I understood your case, you want some of your test cases to have different
      behaviour by not extending plain TestCase, but your custom MyTestCase, with
      custom 'setUp' and 'tearDown' methods for database connection initialization
      for example.

      AspetJ will simply put yout MyTestCase class between YourTestCase and TestCase
      in class hierarchy. This way you can use 'setUp()' method in YourTestCase and
      override it in MyTestCase.setUp().

      With JBossAOP mixins it is not possible to achieve exact the same situation
      because of problem with:
      Caused by: java.lang.Exception: Mixin syntax.Base of pointcut
      file:/jboss-aop.xml0 is trying to apply an already existing method setUp for
      class syntax.Pojo


      When speaking about introductions: can someone give some answer why do we
      really need "100% pure Java" in JBossAOP?

      I know about this requirement of loading classes without compiling under JBoss AS.
      But anyway, in the end they have to be compiled by 'javac' compiler..
      So, if there would exist 'jbossaopc' instead of 'javac' (similar to aspectj),
      then there is no problem... or am I missing sth?

      Regards,
      Tomasz

        • 1. Re: Introduction
          kabirkhan

          Hi,

          You cannot force a class to extend another, but you can use a mixin class.

          Cheers,

          Kabir

          • 2. Re: Introduction

            Hi Kabir,

            I have 3 classe (A, B and C). B extends A and C extends A. I'd like to make C extends B...

            Is there a way to do it using JBoos AOP?

            Thanks,

            André

            • 3. Re: Introduction
              kabirkhan

              Hmm, sounds horrible :-) Do you have a proper use-case for this, or are you just playing around to see what the capablilities are?

              If you mean you want to make C extend B instead of A, that is not possible. JBoss AOP does not introduce any new keywords into the Java language, all instrumentation is done on properly compiled Java classes.

              Mixins and interface introductions work, because there is no compile time checking of interfaces. i.e you could define classes:

              public class MyClass
              {
              }
              
              public class MySubClass extends MyClass
              {
              }
              
              public class RandomClass
              {
              }
              


              The following will compile in normal Java (before any aop takes place)
              AnyInterfaceYouLike if1 = (AnyInterfaceYouLike)new MyClass();
              AnyInterfaceYouLike if2 = (AnyInterfaceYouLike)new MySubClass();
              AnyInterfaceYouLike if3 = (AnyInterfaceYouLike)RandomClass();
              Serializable ser = (Serialiable)MyClass();
              //etc.
              


              For subclasses this will work:
              MyClass clazz = new MySubClass();
              MyClass clazz2 = (MyClass)new MySubClass();
              


              But this will give a compiletime error:

              MyClass clazz = new RandomClass();
              MyClass clazz2 = (MyClass)new RandomClass();
              


              So in your case, before instrumentation,
              C c = new C();
              A a = c; //Will work
              B b = c;//Will not work
              


              Depending on your needs it might be possble to do what you want with a mixin, but hard to say without more info.


              Cheers,

              Kabir


              • 4. Re: Introduction

                Hi Kabir,

                I'm migrating from AspectJ to JBoss AOP and my implementation use this approach.

                I have some test cases implemented using JUnit, so these classes (Test1, Test2) extends TestCase. I've created a new class (MyTestCase) that extends and modify TestCase default implementation, adding new fields and methods.

                Compiling with AspectJ I can force my test cases to extends MyTestCase instead TestCase and perform the new behavior...

                André


                • 5. Re: Introduction

                   

                  "ad-rocha" wrote:

                  I have some test cases implemented using JUnit, so these classes (Test1, Test2)
                  extends TestCase. I've created a new class (MyTestCase) that extends and modify
                  TestCase default implementation, adding new fields and methods.


                  Compiling with AspectJ I can force my test cases to extends MyTestCase instead
                  TestCase and perform the new behavior...

                  Andrea


                  Hi!

                  I've compared two approaches and I think it is impossible to realize your
                  UseCase with JBossAOP.

                  Comparing to AspectJ in field of introductions JBossAOP is quite weak.
                  It is "..% pure Java" and that's the reason.

                  As I understood your case, you want some of your test cases to have different
                  behaviour by not extending plain TestCase, but your custom MyTestCase, with
                  custom 'setUp' and 'tearDown' methods for database connection initialization
                  for example.

                  AspetJ will simply put yout MyTestCase class between YourTestCase and TestCase
                  in class hierarchy. This way you can use 'setUp()' method in YourTestCase and
                  override it in MyTestCase.setUp().

                  With JBossAOP mixins it is not possible to achieve exact the same situation
                  because of problem with:
                  Caused by: java.lang.Exception: Mixin syntax.Base of pointcut
                  file:/jboss-aop.xml0 is trying to apply an already existing method setUp for
                  class syntax.Pojo


                  When speaking about introductions: can someone give some answer why do we
                  really need "100% pure Java" in JBossAOP?

                  I know about this requirement of loading classes without compiling under JBoss AS.
                  But anyway, in the end they have to be compiled by 'javac' compiler..
                  So, if there would exist 'jbossaopc' instead of 'javac' (similar to aspectj),
                  then there is no problem... or am I missing sth?

                  Regards,
                  Tomasz

                  • 6. Re: Introduction
                    bill.burke

                    I see the usecase for this. It would be trivial to implement, but let's argue on the correct syntax and contract.

                    <extends expr="org.MyTestCase" from="test.MySuperClass"/>
                    


                    The rules are that MySuperClass must extend the class MyTestCase extends.

                    Anything else?



                    • 7. Re: Introduction

                      Bill,

                      In my opinion the sintax is ok (very useful to me!). My question is: "MySuperClass must extend the class MyTestCase extends" is a JBoss AOP limitation or just a implementation choice?

                      Andre

                      • 8. Re: Introduction
                        bill.burke

                        FYI, this isn't implemented, just discussing how to implement...

                        What do you think the semantics should be? And what does AspectJ support in this regard?

                        Thanks,

                        Bill

                        • 9. Re: Introduction
                          bill.burke

                          I should say: What do you WANT the semantics to be, since this is your feature request :-)

                          Bill

                          • 10. Re: Introduction

                            Thanks for your attention Bill,

                            AspectJ sintax is something like this:

                            public aspect Inheritance {
                             declare parents: (junit.framework.TestCase+ && !junit.framework.TestCase && !test.CustomTestCase) extends test.CustomTestCase;
                            }


                            that means "classes that extends TestCase and not equals to TestCase and not equals to CustomTestCase will extends CustomTestCase"

                            In JBoss I would like a construction like this:
                            <extends expr="ER" from="test.CustomTestCase"/>


                            where ER is a regular expression describing the classes, so I can use a pattern to modify many classes...

                            Is it possible?

                            Andre