public void InvalidAspectForAssignable() { AspectParser parser = CreateParser( "aspect XPTO for [ assignableFrom() ] \r\n" + "end"); EngineConfiguration conf = parser.Parse(); }
public void GenerateAspectWithIncludes() { AspectParser parser = CreateParser( "import XPTO " + "import XY in My.Assembly " + " " + " aspect McBrother for MyType in MyAssembly " + " include \"key\"" + " include MyType in MyAssembly" + " end" + " "); EngineConfiguration conf = parser.Parse(); XmlTreeVisitor visitor = new XmlTreeVisitor(); visitor.Visit(conf); String content = visitor.Document.InnerXml; Assert.AreEqual("<configuration>" + "<import namespace=\"XPTO\" />" + "<import namespace=\"XY\" assembly=\"My.Assembly\" />" + "<aspect name=\"McBrother\"><for>" + "<singletype type=\"MyType\" refTypeEnum=\"Type\" assembly=\"MyAssembly\" />" + "</for>" + "<mixin type=\"key\" refTypeEnum=\"Link\" />" + "<mixin type=\"MyType\" refTypeEnum=\"Type\" assembly=\"MyAssembly\" />" + "</aspect></configuration>", content); }
public void GenerateAspectWithPointcuts() { AspectParser parser = CreateParser( "import XPTO " + "import XY in My.Assembly " + " " + " aspect McBrother for MyType in MyAssembly " + " " + " pointcut method(*)" + " advice(MyType)" + " end" + " " + " end" + " "); EngineConfiguration conf = parser.Parse(); XmlTreeVisitor visitor = new XmlTreeVisitor(); visitor.Visit(conf); String content = visitor.Document.InnerXml; Assert.AreEqual("<configuration>" + "<import namespace=\"XPTO\" />" + "<import namespace=\"XY\" assembly=\"My.Assembly\" />" + "<aspect name=\"McBrother\">" + "<for><singletype type=\"MyType\" refTypeEnum=\"Type\" assembly=\"MyAssembly\" />" + "</for>" + "<pointcut symbol=\"Method\"><signature>(*)</signature>" + "<interceptor type=\"MyType\" refTypeEnum=\"Type\" />" + "</pointcut></aspect></configuration>", content); }
public void ParsingAspectWithAFewMixinDeclarations() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + "" + " include MyNamespace.Type1 in MyAssembly1 " + " include MyNamespace.Type2 in MyAssembly2 " + " include MyNamespace.Type3 in MyAssembly3 " + "" + "" + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; Assert.AreEqual(3, def.Mixins.Count); MixinDefinition typeName = def.Mixins[0]; Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType); Assert.AreEqual("MyNamespace.Type1", typeName.TypeReference.TypeName); Assert.AreEqual("MyAssembly1", typeName.TypeReference.AssemblyReference.AssemblyName); typeName = def.Mixins[1]; Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType); Assert.AreEqual("MyNamespace.Type2", typeName.TypeReference.TypeName); Assert.AreEqual("MyAssembly2", typeName.TypeReference.AssemblyReference.AssemblyName); typeName = def.Mixins[2]; Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType); Assert.AreEqual("MyNamespace.Type3", typeName.TypeReference.TypeName); Assert.AreEqual("MyAssembly3", typeName.TypeReference.AssemblyReference.AssemblyName); }
public void ParsingInvalidInterceptorDeclarations() { try { AspectParser parser = CreateParser( "interceptors \r\n" + "[" + " key1 : Namespace.Interceptor in MyAssembly" + "]"); parser.Parse(); Assert.Fail("Invalid language content"); } catch (Exception) { // Excepted } try { AspectParser parser = CreateParser( "interceptors \r\n" + "[" + " \"key1\" : Namespace.Interceptor in MyAssembly" + ""); parser.Parse(); Assert.Fail("Invalid language content"); } catch (Exception) { // Excepted } }
public void ParsingInvalidMixinsDeclarations() { try { AspectParser parser = CreateParser( "mixins \r\n" + "[" + " key1 : Namespace.CustomerMixin1 in MyAssembly" + "]"); parser.Parse(); Assert.Fail("Invalid language content"); } catch (Exception) { // Excepted } try { AspectParser parser = CreateParser( "mixins \r\n" + "[" + " \"key1\" : Namespace.CustomerMixin1 in MyAssembly" + ""); parser.Parse(); Assert.Fail("Invalid language content"); } catch (Exception) { // Excepted } }
public void InvalidAspectForCustomMatcher() { AspectParser parser = CreateParser( "aspect XPTO for [ customMatcher() ] \r\n" + "end"); EngineConfiguration conf = parser.Parse(); }
public void GenerateGlobalMixinsAndInterceptors() { AspectParser parser = CreateParser( "import XPTO " + "import XY in My.Assembly " + " " + " interceptors [ \"key\" : MyType in MyAssembly; \"key2\" : MyTypeThatMustBeResolved ] " + " mixins [ \"key\" : MyType in MyAssembly; \"key2\" : MyTypeThatMustBeResolved ] " + " " + " " + " "); EngineConfiguration conf = parser.Parse(); XmlTreeVisitor visitor = new XmlTreeVisitor(); visitor.Visit(conf); String content = visitor.Document.InnerXml; Assert.AreEqual("<configuration>" + "<import namespace=\"XPTO\" />" + "<import namespace=\"XY\" assembly=\"My.Assembly\" />" + "<mixins><mixin key=\"key\" type=\"MyType\" refTypeEnum=\"Type\" assembly=\"MyAssembly\" />" + "<mixin key=\"key2\" type=\"MyTypeThatMustBeResolved\" refTypeEnum=\"Type\" />" + "</mixins><interceptors>" + "<interceptor key=\"key\" type=\"MyType\" refTypeEnum=\"Type\" assembly=\"MyAssembly\" />" + "<interceptor key=\"key2\" type=\"MyTypeThatMustBeResolved\" refTypeEnum=\"Type\" />" + "</interceptors></configuration>", content); }
public void ParsingInvalidAspectEmptyDeclaration() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + ""); parser.Parse(); }
public void ParsingInvalidPointcutDeclaration() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut method|propertyread|property(*)" + " end" + " " + "end"); parser.Parse(); }
public void ParsingImportDeclarations() { AspectParser parser = CreateParser("import my.ns.name"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Imports); Assert.AreEqual(1, conf.Imports.Count); ImportDirective import = conf.Imports[0]; Assert.IsNotNull(import); Assert.AreEqual("my.ns.name", import.Namespace); }
public void ParsingSimpleImportDeclarations() { AspectParser parser = CreateParser("import my\r\nimport two"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Imports); Assert.AreEqual(2, conf.Imports.Count); ImportDirective import = conf.Imports[0]; Assert.IsNotNull(import); Assert.AreEqual("my", import.Namespace); import = conf.Imports[1]; Assert.IsNotNull(import); Assert.AreEqual("two", import.Namespace); }
public void ParsingAspectForAssignable() { AspectParser parser = CreateParser( "aspect XPTO for [ assignableFrom(Customer) ] \r\n" + "end"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Aspects); Assert.AreEqual(1, conf.Aspects.Count); AspectDefinition def = conf.Aspects[0]; Assert.IsNotNull(def); Assert.AreEqual("XPTO", def.Name); Assert.AreEqual(TargetStrategyEnum.Assignable, def.TargetType.TargetStrategy); Assert.AreEqual("Customer", def.TargetType.AssignType.TypeName); }
public void ParsingAspectEmptyDeclaration() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + "end"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Aspects); Assert.AreEqual(1, conf.Aspects.Count); AspectDefinition def = conf.Aspects[0]; Assert.IsNotNull(def); Assert.AreEqual("XPTO", def.Name); Assert.AreEqual("MyNamespace.MyType", def.TargetType.SingleType.TypeName); Assert.AreEqual(TargetStrategyEnum.SingleType, def.TargetType.TargetStrategy); }
public void ParsingAspectEmptyDeclarationWithFullType() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType in My.New.Assembly \r\n" + "end"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Aspects); Assert.AreEqual(1, conf.Aspects.Count); AspectDefinition def = conf.Aspects[0]; Assert.IsNotNull(def); Assert.AreEqual("XPTO", def.Name); Assert.AreEqual("MyNamespace.MyType", def.TargetType.SingleType.TypeName); Assert.AreEqual("My.New.Assembly", def.TargetType.SingleType.AssemblyReference.AssemblyName); }
public void ParsingAspectForCustomMatcher() { AspectParser parser = CreateParser( "aspect XPTO for [ customMatcher(MyMatcher) ] \r\n" + "end"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Aspects); Assert.AreEqual(1, conf.Aspects.Count); AspectDefinition def = conf.Aspects[0]; Assert.IsNotNull(def); Assert.AreEqual("XPTO", def.Name); Assert.AreEqual(TargetStrategyEnum.Custom, def.TargetType.TargetStrategy); Assert.AreEqual("MyMatcher", def.TargetType.CustomMatcherType.TypeName); }
public void GenerateImports() { AspectParser parser = CreateParser( "import XPTO " + "import XY in My.Assembly "); EngineConfiguration conf = parser.Parse(); XmlTreeVisitor visitor = new XmlTreeVisitor(); visitor.Visit(conf); String content = visitor.Document.InnerXml; Assert.AreEqual("<configuration>" + "<import namespace=\"XPTO\" />" + "<import namespace=\"XY\" assembly=\"My.Assembly\" />" + "</configuration>", content); }
protected void DoParsing(string method, string access, string type, string name, string param1) { string allparams; if (param1 != null) { allparams = "(" + param1 + ")"; } else { allparams = string.Empty; } AspectParser parser = CreateParser(string.Format( "aspect XPTO for MyNamespace.MyType \n\n" + " pointcut {0}({1} {2} {3}{4}) \n" + " advice(My.NS.Interceptor in My.Assembly ) \n" + " end \n" + "end", method, access, type, name, allparams)); string s = string.Format("{0}({1} {2} {3}{4})", method, access, type, name, allparams); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pc = def.PointCuts[0]; if (name == "*") { name = ".*"; } Assert.AreEqual(string.Format("({0} {1} {2}({3}))", access == "" ? "*" : access, type, name, param1 == null ? "" : param1), pc.Method.ToString()); Assert.AreEqual(method == "method", ((pc.Flags & PointCutFlags.Method) != 0), "method check: " + s); Assert.AreEqual(access == "*" || access == "", pc.Method.AllAccess, "AllAccess: " + s); Assert.AreEqual(type == "*", pc.Method.AllRetTypes, "AllRetTypes: " + s); Assert.AreEqual(name, pc.Method.MethodName, "MethodName: " + s); Assert.AreEqual(access == "" ? "*" : access, pc.Method.Access, "Access: " + s); Assert.AreEqual(type, pc.Method.RetType, "RetType: " + s); if (param1 == null || param1.Length == 0) { Assert.AreEqual(0, pc.Method.Arguments.Length, "No Params: " + s); } else { Assert.AreEqual(1, pc.Method.Arguments.Length, "1 Param: " + s); Assert.AreEqual(param1, pc.Method.Arguments[0], "Param: " + s); } }
public void ParsingAspectForNamespace() { AspectParser parser = CreateParser( "aspect XPTO for [ my.namespace.types ] \r\n" + "end"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Aspects); Assert.AreEqual(1, conf.Aspects.Count); AspectDefinition def = conf.Aspects[0]; Assert.IsNotNull(def); Assert.AreEqual("XPTO", def.Name); Assert.AreEqual(TargetStrategyEnum.Namespace, def.TargetType.TargetStrategy); Assert.AreEqual("my.namespace.types", def.TargetType.NamespaceRoot); Assert.IsFalse(def.TargetType.IncludeSubNamespace); }
public void ParsingMethodAndPropertyWritePointcutDeclaration() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut method|propertywrite(*)" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; Assert.AreEqual(1, def.PointCuts.Count); PointCutDefinition pointcut = def.PointCuts[0]; Assert.IsNotNull(pointcut); Assert.AreEqual(PointCutFlags.PropertyWrite | PointCutFlags.Method, pointcut.Flags); Assert.AreEqual(AllMethodSignature.Instance, pointcut.Method); }
protected EngineConfiguration ParseContents() { AspectLanguageLexer lexer = new AspectLanguageLexer(_reader); AspectParser parser = new AspectParser(lexer); try { return(parser.Parse()); } catch (antlr.RecognitionException e) { int line = e.getLine(); int startColumn = e.getColumn(); String filename = e.getFilename(); LexicalInfo info = new LexicalInfo(filename, line, startColumn, -1); throw new BuilderException(info, e.Message); } }
public void ParsingPointcutDeclarationForPropertyNameNoArguments() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut property(* Name)" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(PointCutFlags.Property, pointcut.Flags); Assert.AreEqual("Name", pointcut.Method.MethodName); Assert.AreEqual(0, pointcut.Method.Arguments.Length); Assert.IsTrue(pointcut.Method.AllRetTypes); Assert.IsTrue(!pointcut.Method.AllArguments); }
public void ParsingPointcutDeclarationForMethodWithRegExp() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut method(* DoS.*(*))" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(PointCutFlags.Method, pointcut.Flags); Assert.AreEqual("DoS.*", pointcut.Method.MethodName); Assert.AreEqual(1, pointcut.Method.Arguments.Length); Assert.IsTrue(pointcut.Method.AllRetTypes); Assert.IsTrue(pointcut.Method.AllArguments); }
public void ParsingMixinDeclaration() { AspectParser parser = CreateParser( "mixins \r\n" + "[" + "\"customer\" : CustomerMixin" + "]"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Mixins); Assert.AreEqual(1, conf.Mixins.Count); MixinEntryDefinition def = conf.Mixins[0]; Assert.IsNotNull(def); Assert.AreEqual("customer", def.Key); Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType); Assert.AreEqual("CustomerMixin", def.TypeReference.TypeName); }
public void ParsingAspectWithMixinRefDeclaration() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + "" + " include \"customer\"" + "" + "" + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; Assert.AreEqual(1, def.Mixins.Count); MixinDefinition typeName = def.Mixins[0]; Assert.AreEqual(TargetTypeEnum.Link, typeName.TypeReference.TargetType); Assert.AreEqual("customer", typeName.TypeReference.LinkRef); }
public void ParsingInterceptorDeclaration() { AspectParser parser = CreateParser( "interceptors \r\n" + "[" + "\"customer\" : Interceptor" + "]"); EngineConfiguration conf = parser.Parse(); Assert.IsNotNull(conf); Assert.IsNotNull(conf.Interceptors); Assert.AreEqual(1, conf.Interceptors.Count); InterceptorEntryDefinition def = conf.Interceptors[0]; Assert.IsNotNull(def); Assert.AreEqual("customer", def.Key); Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType); Assert.AreEqual("Interceptor", def.TypeReference.TypeName); }
public void ParsingInterceptorRefForProperty() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut property(* Name)" + " advice(\"logger\")" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(1, pointcut.Advices.Count); InterceptorDefinition adv = pointcut.Advices[0]; Assert.IsNotNull(adv); Assert.AreEqual("logger", adv.TypeReference.LinkRef); }
public void ParsingAspectWithSingleMixinDeclaration() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + "" + " include MyNamespace.Type in MyAssembly " + "" + "" + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; Assert.AreEqual(1, def.Mixins.Count); MixinDefinition typeName = def.Mixins[0]; Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType); Assert.AreEqual("MyNamespace.Type", typeName.TypeReference.TypeName); Assert.AreEqual("MyAssembly", typeName.TypeReference.AssemblyReference.AssemblyName); }
public void ParsingInterceptorTypeForProperty() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut property(* Name)" + " advice( My.NS.Interceptor in My.Assembly )" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(1, pointcut.Advices.Count); InterceptorDefinition adv = pointcut.Advices[0]; Assert.IsNotNull(adv); Assert.AreEqual(TargetTypeEnum.Type, adv.TypeReference.TargetType); Assert.AreEqual("My.NS.Interceptor", adv.TypeReference.TypeName); Assert.AreEqual("My.Assembly", adv.TypeReference.AssemblyReference.AssemblyName); }
public void ParsingPointcutDeclarationForMethodDoSomethingWithTwoArgumentsAndRegEx() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut method(int DoSomething(string, *))" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(PointCutFlags.Method, pointcut.Flags); Assert.AreEqual("DoSomething", pointcut.Method.MethodName); Assert.AreEqual(2, pointcut.Method.Arguments.Length); Assert.IsTrue(!pointcut.Method.AllRetTypes); Assert.AreEqual("int", pointcut.Method.RetType); Assert.IsTrue(!pointcut.Method.AllArguments); Assert.AreEqual("string", pointcut.Method.Arguments[0]); Assert.AreEqual("*", pointcut.Method.Arguments[1]); }