Esempio n. 1
0
        private static T getAnnotation <T>(ProcessEngine processEngine, Type testClass, string methodName, Type annotationClass) where T : Annotation
        {
            annotationClass = typeof(T);
            System.Reflection.MethodInfo method = null;
            T annotation = null;

            try
            {
                method     = getMethod(testClass, methodName);
                annotation = method.getAnnotation(annotationClass);
            }
            catch (Exception)
            {
                // - ignore if we cannot access the method
                // - just try again with the class
                // => can for example be the case for parameterized tests where methodName does not correspond to the actual method name
                //    (note that method-level annotations still work in this
                //     scenario due to Description#getAnnotation in annotationRequiredHistoryLevelCheck)
            }

            // if not found on method, try on class level
            if (annotation == null)
            {
                annotation = testClass.getAnnotation(annotationClass);
            }
            return(annotation);
        }
Esempio n. 2
0
        private static string NameOf(System.Reflection.MethodInfo method)
        {
            Name name = method.getAnnotation(typeof(Name));

            if (name != null)
            {
                return(name.value());
            }
            return(method.Name);
        }
Esempio n. 3
0
        public static string ExtractMessage(System.Reflection.MethodInfo method)
        {
            string     message;
            Documented annotation = method.getAnnotation(typeof(Documented));

            if (annotation != null && !"".Equals(annotation.value()))
            {
                message = annotation.value();
            }
            else
            {
                message = method.Name;
            }
            return(message);
        }
Esempio n. 4
0
            public override object Invoke(object proxy, System.Reflection.MethodInfo method, object[] args)
            {
                string message = DocumentedUtils.extractFormattedMessage(method, args);

                if (method.getAnnotation(typeof(ConsistencyReport_Warning)) == null)
                {
                    Errors++;
                    Report.error(message);
                }
                else
                {
                    Warnings++;
                    Report.warning(message);
                }
                return(null);
            }
Esempio n. 5
0
            /// <summary>
            /// Invoked when an inconsistency is encountered.
            /// </summary>
            /// <param name="args"> array of the items referenced from this record with which it is inconsistent. </param>
            public override object Invoke(object proxy, System.Reflection.MethodInfo method, object[] args)
            {
                string message = DocumentedUtils.extractMessage(method);

                if (method.getAnnotation(typeof(ConsistencyReport_Warning)) == null)
                {
                    Errors++;
                    args = GetRealRecords(args);
                    LogError(message, args);
                }
                else
                {
                    Warnings++;
                    args = GetRealRecords(args);
                    LogWarning(message, args);
                }
                Monitor.reported(Factory.type(), method.Name, message);
                InconsistencyReported();
                return(null);
            }
Esempio n. 6
0
        public override PluginPoint CreateFrom(ServerPlugin plugin, System.Reflection.MethodInfo method, Type discovery)
        {
            ResultConverter result = ResultConverter.Get(method.GenericReturnType);

            Type[]          types           = method.GenericParameterTypes;
            Annotation[][]  annotations     = method.ParameterAnnotations;
            SourceExtractor sourceExtractor = null;

            DataExtractor[] extractors = new DataExtractor[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                Description description = null;
                Parameter   param       = null;
                Source      source      = null;
                foreach (Annotation annotation in annotations[i])
                {
                    if (annotation is Description)
                    {
                        description = ( Description )annotation;
                    }
                    else if (annotation is Parameter)
                    {
                        param = ( Parameter )annotation;
                    }
                    else if (annotation is Source)
                    {
                        source = ( Source )annotation;
                    }
                }
                if (param != null && source != null)
                {
                    throw new System.InvalidOperationException(string.Format("Method parameter {0:D} of {1} cannot be retrieved as both Parameter and Source", Convert.ToInt32(i), method));
                }
                else if (source != null)
                {
                    if (types[i] != discovery)
                    {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                        throw new System.InvalidOperationException("Source parameter type (" + types[i] + ") must equal the discovery type (" + discovery.FullName + ").");
                    }
                    if (sourceExtractor != null)
                    {
                        throw new System.InvalidOperationException("Server Extension methods may have at most one Source parameter.");
                    }
                    extractors[i] = sourceExtractor = new SourceExtractor(source, description);
                }
                else if (param != null)
                {
                    extractors[i] = ParameterExtractor(types[i], param, description);
                }
                else
                {
                    throw new System.InvalidOperationException("Parameters of Server Extension methods must be annotated as either Source or Parameter.");
                }
            }
            return(new PluginMethod(NameOf(method), discovery, plugin, result, method, extractors, method.getAnnotation(typeof(Description))));
        }
Esempio n. 7
0
        public static string annotationDeploymentSetUp(ProcessEngine processEngine, Type testClass, string methodName, Deployment deploymentAnnotation)
        {
            string deploymentId = null;

            System.Reflection.MethodInfo method = null;
            bool onMethod = true;

            try
            {
                method = getMethod(testClass, methodName);
            }
            catch (Exception)
            {
                if (deploymentAnnotation == null)
                {
                    // we have neither the annotation, nor can look it up from the method
                    return(null);
                }
            }

            if (deploymentAnnotation == null)
            {
                deploymentAnnotation = method.getAnnotation(typeof(Deployment));
            }
            // if not found on method, try on class level
            if (deploymentAnnotation == null)
            {
                onMethod = false;
                Type lookForAnnotationClass = testClass;
                while (lookForAnnotationClass != typeof(object))
                {
                    deploymentAnnotation = lookForAnnotationClass.getAnnotation(typeof(Deployment));
                    if (deploymentAnnotation != null)
                    {
                        testClass = lookForAnnotationClass;
                        break;
                    }
                    lookForAnnotationClass = lookForAnnotationClass.BaseType;
                }
            }

            if (deploymentAnnotation != null)
            {
                LOG.debug("annotation @Deployment creates deployment for {}.{}", ClassNameUtil.getClassNameWithoutPackage(testClass), methodName);
                string[] resources = deploymentAnnotation.resources();
                if (resources.Length == 0 && method != null)
                {
                    string name     = onMethod ? method.Name : null;
                    string resource = getBpmnProcessDefinitionResource(testClass, name);
                    resources = new string[] { resource };
                }

                DeploymentBuilder deploymentBuilder = processEngine.RepositoryService.createDeployment().name(ClassNameUtil.getClassNameWithoutPackage(testClass) + "." + methodName);

                foreach (string resource in resources)
                {
                    deploymentBuilder.addClasspathResource(resource);
                }

                deploymentId = deploymentBuilder.deploy().Id;
            }

            return(deploymentId);
        }