200 likes | 290 Views
AspectWrapper. CHALFOUN Pierre et BUIST Éric. Overview. Introduction – what and why In a nutshell – main components Our approach – how we did it Demo – a taste of things to come Conclusion – “wrap” things up. Introduction In a nutshell Our approach Demo Conclusion. Introduction.
E N D
AspectWrapper CHALFOUN Pierre et BUIST Éric
Overview • Introduction – what and why • In a nutshell – main components • Our approach – how we did it • Demo – a taste of things to come • Conclusion – “wrap” things up
Introduction In a nutshell Our approach Demo Conclusion Introduction • Problematic – in two words • Testing • A pain in the … “you know where” • Nevertheless … important ! • Nevertheless … tedious and time consuming • Please, do automate ! • Aspect-oriented programming • Crosscutting … How can you test that ? • Composition impact on code • Specifications are required when modeling ( UML )
Introduction In a nutshell Our approach Demo Conclusion Introduction • Problematic – in one word • Specification-based automatic testing of aspect-oriented programs
Running oracles Modeling aspects Test data Generating oracles report Introduction In a nutshell Our approach Demo Conclusion Introduction • Motivation : an illustrated version
Introduction In a nutshell Our approach Demo Conclusion - In a nutshell - Testing Framework • Test runners • Automate execution • Report results • Test oracles • How to perform the test • Test data – domain specific • Two approaches • Specification-based (black box) • Program-based (white box)
Introduction In a nutshell Our approach Demo Conclusion - In a nutshell –Aspect Modeling 1/2 • Aspect-UML – Mostefaoui et Vachon 2005 • Language independent • Validate aspect composition • Aspect defined by stereotype « Aspect » • Pointcut defined by stereotype « PointCut » • Constraints are written in OCL • Cannot model inter-type declarations
Introduction In a nutshell Our approach Demo Conclusion - In a nutshell –Aspect Modeling 2/2 • Aspect-UML – Mostefaoui et Vachon 2005 OCL constraint for the opDrop advice context Billing : :opDrop inv : connection=c inv : c.getTime() !=Null post : c.getCaller.getCharge() >= c.getCaller.getCharge()@pre
Introduction In a nutshell Our approach Demo Conclusion - In a nutshell –Dresden : OCL to Java • Dresden – Dresden University Group 2005 • Parses OCL constraints in UML diagrams • Applicable only to Java and OOP • Long series of try and catch /** A wrapper for injection. Generated automatically, DO NOT CHANGE! @author ocl_injector @see #Person(tudresden.ocl.injection.lib.WrapperDummy) */ public Person(){ this((tudresden.ocl.injection.lib.WrapperDummy)null); try{ tudresden.ocl.injection.ocl.lib.Invariant.checking_flag=true; tudresden.ocl.injection.ocl.lib.Invariant.checkVacantInvariants(); }finally{ tudresden.ocl.injection.ocl.lib.Invariant.checking_flag=false; } }/**
Introduction In a nutshell Our approach Demo Conclusion - In a nutshell –aUnit 1/2 • aUnit – Russ Miles 2005 “ Similar to how JUnit provides unit testing for Java, aUnit will provide mechanisms by which developers can test their aspects in isolation in support of Test Driven Development.” – Russ Miles 2004 • Idea : calling an advice explicitly • Code manually the JoinPoint • One advice = 1 step • Get all the steps together and sort them • Execute each step in turn
Introduction In a nutshell Our approach Demo Conclusion - In a nutshell –aUnit 2/2
Introduction In a nutshell Our approach Demo Conclusion - Our approach - Aspect-UML to AspectJ • Extending the mapping between UML and Java • 1 « Aspect » = 1 java file • Annotation AdviceName for the advice • Attaching OCL constraints with annotations /* When timing stops, calculate and add the charge from the * connection time */ @AdviceName("opDrop") @OclPostcondition(value="getPayer(conn).totalCharge >= "+ " getPayer(conn).totalCharge@pre") after(Connection conn): Timing.endTiming(conn) { long time = Timing.aspectOf().getTimer(conn).getTime(); long rate = conn.callRate(); long cost = rate * time; getPayer(conn).addCharge(cost); }
Introduction In a nutshell Our approach Demo Conclusion - Our approach - OCL annotation to Java • Extending Dresden to take advice into account • OCL is converted to JAVA in a class_Test.java file • Each constraint has an associated non-static method public void prep$adv$opDrop (telecom.Connection conn) { […] final tudresden…OclInteger tudOclNode13= tudresden…toOclInteger(tudOclNode12.getFeature("totalCharge")); final tudresden…OclAnyImpl tudOclNode14= tudresden…toOclAnyImpl(tudOclNode11.getFeature("getPayer", tudOclParam1)); tudOclNode15=tudresden…toOclInteger(tudOclNode14. getFeature("totalCharge")); final tudresden…OclBoolean tudOclNode16= tudOclNode13.isGreaterEqual(tudOclNode15); } public tudresden…OclBooleancheck$adv$pre$opDrop (telecom.Connection conn) { return tudresden…OclBoolean.TRUE; }
Introduction In a nutshell Our approach Demo Conclusion - Our approach - aUnit Revisited 1/2 • Extending aUnit to support method calls : re-implement TestStep and subclass public class MethodTestStep implements TestStep { protected Object testedObject; protected Method testedMethod; protected Object[] arguments; protected Object returnValue; protected List results = new ArrayList(); […] } public class CheckMethodTestStep Extends MethodTestStep { […] public void runStep() throws TestFailException { super.runStep(); OclBoolean oclBoolean = (OclBoolean)getResults().get (0); if (oclBoolean.isFalse()) { throw new TestFailException(); } } }
Introduction In a nutshell Our approach Demo Conclusion - Our approach - aUnit Revisited 2/2 • Usage example TestStep[] steps = new TestStep[2]; MockApplication mock = new MockApplication(); Class[] paramTypes = { int.class }; Method barMethod = mock.getClass().getMethod("bar", paramTypes); JoinPoint.StaticPart staticPart = Factory.makeEncSJP(barMethod); Object[] args = { 10 }; JoinPoint joinPoint = Factory.makeJP(staticPart, mock, mock, args); JoinPointContext context = new JoinPointContext(joinPoint); String adviceSelectorExpression = "id3"; TestStep Step1 = TestStepFactory.createControlledTestStep( (AspectObject) AfterAdviceExampleAspect.aspectOf(), context, adviceSelectorExpression); steps[0] = Step1; // our contribution MockApplication_TestmockTest = new MockApplication(mock); Method checkPost = mockTest.getClass().getMethod(“check$adv$pre$opDrop”,…); CheckMethodTestStep checkStep = new MethodTestStep(mock,checkPost,args,…); steps[1] = checkStep;
Introduction In a nutshell Our approach Demo Conclusion DemoOCL annotation to Java
Introduction In a nutshell Our approach Demo Conclusion DemoaUnit in action
Running oracles Modeling aspects Generating oracles Introduction In a nutshell Our approach Demo Conclusion Conclusion • Our contribution – missing piece of the puzzle Extend the Dresden tool Extend the aUnit tool Extend the mapping between UML and Java
Introduction In a nutshell Our approach Demo Conclusion Conclusion • Related Work • Theme/UML • ArgoUML (Dresden toolbox) • JAOUT (JML) • Future Work • Fully implement the framework and adapt to future releases of aUnit, Dresden and AspectJ 5 • Propose extensions to Aspect-UML to model module interaction via new OCL constraints
Thank You AspectWrapper CHALFOUN Pierre & BUIST Eric