AspectWrapper CHALFOUN Pierre et BUIST Éric. Overview Introduction – what and why In a nutshell...
-
Upload
clare-manning -
Category
Documents
-
view
213 -
download
0
Transcript of AspectWrapper CHALFOUN Pierre et BUIST Éric. Overview Introduction – what and why In a nutshell...
AspectWrapperAspectWrapperCHALFOUN Pierre et BUIST ÉricCHALFOUN Pierre et BUIST Éric
OverviewOverview
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 – 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
IntroductionIntroduction
Problematic – in two wordsTesting
A pain in the … “you know where” Nevertheless … important ! Nevertheless … tedious and time consuming Please, do automate !
Problematic – in two wordsTesting
A pain in the … “you know where” Nevertheless … important ! Nevertheless … tedious and time consuming Please, do automate !
IntroductionIn a nutshellOur approachDemoConclusion
Aspect-oriented programming Crosscutting … How can you test that ? Composition impact on code Specifications are required when modeling
( UML )
Aspect-oriented programming Crosscutting … How can you test that ? Composition impact on code Specifications are required when modeling
( UML )
IntroductionIntroduction
Problematic – in one wordSpecification-based automatic testing of
aspect-oriented programs
Problematic – in one wordSpecification-based automatic testing of
aspect-oriented programs
IntroductionIn a nutshellOur approachDemoConclusion
IntroductionIntroduction
Motivation : an illustrated versionMotivation : an illustrated version
Modeling Modeling aspectsaspects Test dataTest data
report
Generating oraclesGenerating oracles
Running oraclesRunning oracles
IntroductionIn a nutshellOur approachDemoConclusion
- In a nutshell - Testing Framework- In a nutshell - Testing Framework
Test runnersAutomate executionReport results
Test oraclesHow to perform the test
Test data – domain specificTwo approaches
Specification-based (black box)Program-based (white box)
Test runnersAutomate executionReport results
Test oraclesHow to perform the test
Test data – domain specificTwo approaches
Specification-based (black box)Program-based (white box)
IntroductionIn a nutshellOur approachDemoConclusion
- In a nutshell –Aspect Modeling 1/2
- In a nutshell –Aspect Modeling 1/2
Aspect-UML – Mostefaoui et Vachon 2005Language independentValidate aspect compositionAspect defined by stereotype « Aspect »Pointcut defined by stereotype
« PointCut »Constraints are written in OCLCannot model inter-type declarations
Aspect-UML – Mostefaoui et Vachon 2005Language independentValidate aspect compositionAspect defined by stereotype « Aspect »Pointcut defined by stereotype
« PointCut »Constraints are written in OCLCannot model inter-type declarations
IntroductionIn a nutshellOur approachDemoConclusion
- In a nutshell –Aspect Modeling 2/2
- In a nutshell –Aspect Modeling 2/2
Aspect-UML – Mostefaoui et Vachon 2005Aspect-UML – Mostefaoui et Vachon 2005
IntroductionIn a nutshellOur approachDemoConclusion
OCL constraint for the opDrop OCL constraint for the opDrop adviceadvicecontext Billing : :opDrop
inv : connection=cinv : c.getTime() !=Nullpost : c.getCaller.getCharge() >= c.getCaller.getCharge()@pre
- In a nutshell –Dresden : OCL to Java- In a nutshell –Dresden : OCL to Java
Dresden – Dresden University Group 2005Parses OCL constraints in UML diagramsApplicable only to Java and OOPLong series of try and catch
Dresden – Dresden University Group 2005Parses OCL constraints in UML diagramsApplicable only to Java and OOPLong 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; } }/**
IntroductionIn a nutshellOur approachDemoConclusion
- In a nutshell –aUnit 1/2- In a nutshell –aUnit 1/2
aUnit – Russ Miles 2005aUnit – 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 explicitlyCode manually the JoinPointOne advice = 1 stepGet all the steps together and sort themExecute each step in turn
Idea : calling an advice explicitlyCode manually the JoinPointOne advice = 1 stepGet all the steps together and sort themExecute each step in turn
IntroductionIn a nutshellOur approachDemoConclusion
- In a nutshell –aUnit 2/2- In a nutshell –aUnit 2/2
IntroductionIn a nutshellOur approachDemoConclusion
- Our approach - Aspect-UML to AspectJ- 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
Extending the mapping between UML and Java 1 « Aspect » = 1 java file
Annotation AdviceName for the advice Attaching OCL constraints with annotations
IntroductionIn a nutshellOur approachDemoConclusion
/* 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); }
- Our approach - OCL annotation to Java - 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
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
IntroductionIn a nutshellOur approachDemoConclusion
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…OclBoolean check$adv$pre$opDrop (telecom.Connection conn) { return tudresden…OclBoolean.TRUE; }
- Our approach - aUnit Revisited 1/2- Our approach - aUnit Revisited 1/2
Extending aUnit to support method calls : re-implement TestStep and subclass
Extending aUnit to support method calls : re-implement TestStep and subclass
IntroductionIn a nutshellOur approachDemoConclusion
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(); } }}
- Our approach - aUnit Revisited 2/2- Our approach - aUnit Revisited 2/2
Usage example Usage example
IntroductionIn a nutshellOur approachDemoConclusion
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 contributionMockApplication_Test mockTest = new MockApplication(mock);Method checkPost = mockTest.getClass().getMethod(“check$adv$pre$opDrop”,…);CheckMethodTestStep checkStep = new MethodTestStep(mock,checkPost,args,…);steps[1] = checkStep;
DemoOCL annotation to JavaDemoOCL annotation to Java
IntroductionIn a nutshellOur approachDemoConclusion
DemoaUnit in actionDemoaUnit in action
IntroductionIn a nutshellOur approachDemoConclusion
ConclusionConclusion
Our contribution – missing piece of the puzzle Our contribution – missing piece of the puzzle
IntroductionIn a nutshellOur approachDemoConclusion
Modeling Modeling aspectsaspects
Generating oraclesGenerating oracles Running oraclesRunning oracles
Extend the mapping
between UML and Java
Extend the Dresden
tool
Extend the aUnit tool
ConclusionConclusion
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
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
IntroductionIn a nutshellOur approachDemoConclusion
Thank YouThank You AspectWrapperCHALFOUN Pierre & BUIST Eric