Testing Custom Validators

2015-12-18 Thread Devin Fisher
I'm trying to create some tests for some Validators that I'm creating. But
I can't figure out an easy way to create MockValidationContext. I don't
want to create the whole environment that I would for Processors.

I looked
at 
nifi/nifi-commons/nifi-processor-utilities/src/test/java/org/apache/nifi/processor/util/TestStandardValidators.java
and it looks that it just uses Mockito to mock it.

So, is that the recommended way to do it. Will that allow me to control the
ValidationContext?

Also, not sure if asking two questions in one email is allowed, what is the
subject parameter in the validate method?

Devin


Re: Testing Custom Validators

2015-12-18 Thread Devin Fisher
Thanks, I'm guessing that subject is not to0 important to the validation
workflow but provides useful info for the user in the context of the
property that they are setting.

The validator I'm writing is not using the context so it should be fine. If
I need to do more I guess I'll figure out how the mock the rest then.

Devin

On Fri, Dec 18, 2015 at 1:16 PM, Mark Payne  wrote:

> Devin,
>
> Mockito should be find for most cases. If you validator itself is calling
> into the ValidationContext, for instance to create a new PropertyValue
> object, then you may need to mock out some methods. Otherwise, it should
> be fine.
>
> When validate() is called, it is given the 'input' (which is the value to
> valid) and the 'subject' (which is a description of what is being
> validated).
> So generally, the 'subject' is the name of the Property that is being
> validated.
>
> Thanks
> -Mark
>
> > On Dec 18, 2015, at 3:11 PM, Devin Fisher <
> devin.fis...@perfectsearchcorp.com> wrote:
> >
> > I'm trying to create some tests for some Validators that I'm creating.
> But
> > I can't figure out an easy way to create MockValidationContext. I don't
> > want to create the whole environment that I would for Processors.
> >
> > I looked
> > at
> nifi/nifi-commons/nifi-processor-utilities/src/test/java/org/apache/nifi/processor/util/TestStandardValidators.java
> > and it looks that it just uses Mockito to mock it.
> >
> > So, is that the recommended way to do it. Will that allow me to control
> the
> > ValidationContext?
> >
> > Also, not sure if asking two questions in one email is allowed, what is
> the
> > subject parameter in the validate method?
> >
> > Devin
>
>