Java 类javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext 实例源码

项目:nexus-public    文件:ConstraintViolationFactory.java   
@Override
public boolean isValid(final HelperBean bean, final ConstraintValidatorContext context) {
  context.disableDefaultConstraintViolation();

  // build a custom property path
  ConstraintViolationBuilder builder = context.buildConstraintViolationWithTemplate(bean.getMessage());
  NodeBuilderCustomizableContext nodeBuilder = null;
  for (String part : bean.getPath().split("\\.")) {
    if (nodeBuilder == null) {
      nodeBuilder = builder.addPropertyNode(part);
    }
    else {
      nodeBuilder = nodeBuilder.addPropertyNode(part);
    }
  }
  if (nodeBuilder != null) {
    nodeBuilder.addConstraintViolation();
  }

  return false;
}
项目:syndesis    文件:UniquePropertyValidatorTest.java   
@Test
public void shouldAscertainPropertyUniqueness() {
    final HibernateConstraintValidatorContext context = mock(HibernateConstraintValidatorContext.class);
    when(context.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(context);
    when(context.addExpressionVariable(eq("nonUnique"), anyString())).thenReturn(context);
    when(context.getDefaultConstraintMessageTemplate()).thenReturn("template");
    final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(context.buildConstraintViolationWithTemplate("template")).thenReturn(builder);
    when(builder.addPropertyNode(anyString())).thenReturn(mock(NodeBuilderCustomizableContext.class));

    assertThat(validator.isValid(connection, context)).isEqualTo(validity);
}
项目:syndesis-rest    文件:UniquePropertyValidatorTest.java   
@Test
public void shouldAscertainPropertyUniqueness() {
    final HibernateConstraintValidatorContext context = mock(HibernateConstraintValidatorContext.class);
    when(context.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(context);
    when(context.addExpressionVariable(eq("nonUnique"), anyString())).thenReturn(context);
    when(context.getDefaultConstraintMessageTemplate()).thenReturn("template");
    final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(context.buildConstraintViolationWithTemplate("template")).thenReturn(builder);
    when(builder.addPropertyNode(anyString())).thenReturn(mock(NodeBuilderCustomizableContext.class));

    assertThat(validator.isValid(connection, context)).isEqualTo(validity);
}
项目:opencucina    文件:UsernameValidatorTest.java   
/**
 * JAVADOC Method Level Comments
 */
public void testInvalid() {
    UsernameValidator validator = new UsernameValidator();
    ValidUsername vu = mock(ValidUsername.class);

    when(vu.message()).thenReturn("Oops");
    validator.initialize(vu);

    UsernameValidatingPlugin plugin = mock(UsernameValidatingPlugin.class);

    when(plugin.isValid("username")).thenReturn(false);

    // TODO autowire plugin
    ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);
    ConstraintViolationBuilder cvb = mock(ConstraintViolationBuilder.class);

    when(context.buildConstraintViolationWithTemplate("Oops")).thenReturn(cvb);

    NodeBuilderCustomizableContext nbdc = mock(NodeBuilderCustomizableContext.class);

    when(cvb.addPropertyNode("username")).thenReturn(nbdc);
    when(nbdc.addConstraintViolation()).thenReturn(context);
    assertFalse("Should be unique", validator.isValid("username", context));
    verify(context).buildConstraintViolationWithTemplate("Oops");
    verify(nbdc).addConstraintViolation();
    verify(context).disableDefaultConstraintViolation();
}
项目:unique-validator    文件:UniqueValidatorTest.java   
@Test
public void test() {
    final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);
    final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    final NodeBuilderCustomizableContext node = mock(NodeBuilderCustomizableContext.class);
    when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(builder);
    when(builder.addPropertyNode(anyString())).thenReturn(node);
    mockCountToReturn(2l);
    final ConstraintValidator<Unique, Object> validator = new UniqueValidator();
    final Unique annotation = Model2.class.getAnnotation(Unique.class);
    validator.initialize(annotation);
    assertFalse(validator.isValid("somevalue", context));
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext addPropertyNode(final String pname) {
  this.context.basePath.addPropertyNode(pname);
  return new NodeBuilderCustomizableContextImpl(this, this.messageTemplate,
      this.context.basePath);
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext addNode(final String name) {
  this.path.addPropertyNode(name);
  return new NodeBuilderCustomizableContextImpl(this.parent, this.messageTemplate, this.path);
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext addPropertyNode(final String pname) {
  this.path.addPropertyNode(pname);
  return new NodeBuilderCustomizableContextImpl(this.parent, this.messageTemplate, this.path);
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext inContainer(final Class<?> containerClass,
    final Integer typeArgumentIndex) {
  throw new UnsupportedOperationException(
      "GWT Validation does not support inContainer(Class, Integer).");
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext addNode(final String name) {
  this.path.addPropertyNode(name);
  return new NodeBuilderCustomizableContextImpl(this.parent, this.messageTemplate, this.path);
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext addPropertyNode(final String pname) {
  this.path.addPropertyNode(pname);
  return new NodeBuilderCustomizableContextImpl(this.parent, this.messageTemplate, this.path);
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext addNode(final String name) {
  this.path.addPropertyNode(name);
  return new NodeBuilderCustomizableContextImpl(this.parent, this.messageTemplate, this.path);
}
项目:gwt-bean-validators    文件:ConstraintValidatorContextImpl.java   
@Override
public NodeBuilderCustomizableContext addPropertyNode(final String pname) {
  this.path.addPropertyNode(pname);
  return new NodeBuilderCustomizableContextImpl(this.parent, this.messageTemplate, this.path);
}