/** Testing validator with a correct pojo. Expect: nothing happens. */
  @Test
  public void testValidatorPojoOk() throws InterceptorException {
    final AttributeConstraintModel constraint = new AttributeConstraintModel();
    constraint.setAnnotation(Past.class);
    constraint.setTarget(PojoOne.class);
    constraint.setQualifier("pojoOnePrivate");

    replay(modelService);
    typeValidator.onValidate(constraint, null);
    attrValidator.onValidate(constraint, null);
    verify(modelService);
  }
  /** Testing validator with an itemmodel which is ok. Expect: nothing. */
  @Test
  public void testValidatorItemModelOK() throws InterceptorException {
    final AttributeConstraintModel constraint = new AttributeConstraintModel();
    constraint.setAnnotation(NotEmpty.class);
    constraint.setDescriptor(prodModCodeAD);
    constraint.setType(prodModCT);
    constraint.setTarget(ProductModel.class);
    constraint.setQualifier("code");

    expect(modelService.getModelTypeClass(ProductModel.class)).andReturn(Product.class);

    replay(modelService);
    typeValidator.onValidate(constraint, null);
    attrValidator.onValidate(constraint, null);
    verify(modelService);
  }
  /** Testing validator with incorrect pojo. Expect: exception */
  @Test
  public void testValidatorPojoFails() throws InterceptorException {
    final AttributeConstraintModel constraint = new AttributeConstraintModel();
    constraint.setAnnotation(Past.class);
    constraint.setTarget(PojoOne.class);
    constraint.setQualifier("one");

    replay(modelService);
    typeValidator.onValidate(constraint, null);
    verify(modelService);

    try {
      attrValidator.onValidate(constraint, null);
      fail("There was no InterceptorException");
    } catch (final InterceptorException e) {
      assertTrue(e.getMessage().contains("Unable to find method"));
    } catch (final Exception e) {
      fail("unexpected exception: " + e);
    }
  }
  /**
   * Testing preparer, descriptor is set, other attributes filled with dummy data. Expect:
   * descriptor overwrites all other fields.
   */
  @Test
  public void testPreparerWithAttributeDescriptorOnly() throws InterceptorException {
    final AttributeConstraintModel constraint = new AttributeConstraintModel();
    constraint.setDescriptor(prodModCodeAD);
    constraint.setAnnotation(Min.class);
    constraint.setType(new ComposedTypeModel());
    constraint.setTarget(LanguageModel.class);
    constraint.setQualifier("xxx");

    final ProductModel productModel = new ProductModel();
    expect(modelService.create(prodModCT.getCode())).andReturn(productModel);
    modelService.detach(productModel);
    expectLastCall();

    replay(modelService);
    preparer.onPrepare(constraint, null);
    verify(modelService);

    assertEquals(ProductModel.class, constraint.getTarget());
    assertEquals(prodModCT, constraint.getType());
    assertEquals(Min.class, constraint.getAnnotation());
    assertEquals("code", constraint.getQualifier());
  }