当前位置: 首页>>代码示例>>Java>>正文


Java ConstraintViolationBuilder类代码示例

本文整理汇总了Java中javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder的典型用法代码示例。如果您正苦于以下问题:Java ConstraintViolationBuilder类的具体用法?Java ConstraintViolationBuilder怎么用?Java ConstraintViolationBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConstraintViolationBuilder类属于javax.validation.ConstraintValidatorContext包,在下文中一共展示了ConstraintViolationBuilder类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isValid

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@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;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:22,代码来源:ConstraintViolationFactory.java

示例2: shouldAscertainPropertyUniqueness

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@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);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:13,代码来源:UniquePropertyValidatorTest.java

示例3: testInvalid

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:30,代码来源:UsernameValidatorTest.java

示例4: checkPositiveValue

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
protected ConstraintViolationBuilder checkPositiveValue(BigDecimal value, String message, ConstraintValidatorContext ctx) {
	ConstraintViolationBuilder result = null;
	if (value != null && value.compareTo(BigDecimal.ZERO) < 0) {
		result = ctx.buildConstraintViolationWithTemplate(message);
	}
	return result;
}
 
开发者ID:labcabrera,项目名称:lab-insurance,代码行数:8,代码来源:AbstractValidator.java

示例5: checkNullValue

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
protected ConstraintViolationBuilder checkNullValue(Object entity, String message, ConstraintValidatorContext ctx) {
	ConstraintViolationBuilder result = null;
	if (entity != null) {
		result = ctx.buildConstraintViolationWithTemplate(message);
	}
	return result;
}
 
开发者ID:labcabrera,项目名称:lab-insurance,代码行数:8,代码来源:AbstractValidator.java

示例6: checkNotNullValue

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
protected ConstraintViolationBuilder checkNotNullValue(Object entity, String message, ConstraintValidatorContext ctx) {
	ConstraintViolationBuilder result = null;
	if (entity == null) {
		result = ctx.buildConstraintViolationWithTemplate(message);
	}
	return result;
}
 
开发者ID:labcabrera,项目名称:lab-insurance,代码行数:8,代码来源:AbstractValidator.java

示例7: isValid

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@Override
public boolean isValid(Order order, ConstraintValidatorContext ctx) {
	if (order.getProcessInfo() == null) {
		order.setProcessInfo(new OrderProcessInfo());
	}
	List<ConstraintViolationBuilder> errors = new ArrayList<ConstraintViolationBuilder>();
	addIfNotNull(errors, checkNotNullValue(order.getDates(), "order.validation.missingDates", ctx));
	addIfNotNull(errors, checkNotNullValue(order.getType(), "order.validation.missingType", ctx));
	if (order.getDates() != null) {
		addIfNotNull(errors, checkNotNullValue(order.getDates().getEffective(), "order.validation.missingEffectiveDate", ctx));
	}
	if (order.getType() != null) {
		switch (order.getType()) {
		case ADDITIONAL_PAYMENT:
		case INITIAL_PAYMENT:
		case REGULAR_PAYMENT:
			validatePayment(order, ctx, errors);
			break;
		default:
			break;
		}
	}
	if (errors.isEmpty()) {
		return true;
	} else {
		for (ConstraintViolationBuilder i : errors) {
			i.addConstraintViolation();
		}
		return false;
	}
}
 
开发者ID:labcabrera,项目名称:lab-insurance,代码行数:32,代码来源:OrderValidator.java

示例8: test

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@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));
}
 
开发者ID:clairton,项目名称:unique-validator,代码行数:14,代码来源:UniqueValidatorTest.java

示例9: getConstraintViolationBuilder

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
ConstraintViolationBuilder getConstraintViolationBuilder() {
    return new ConstraintValidatorContextImpl(
            Collections.emptyList(), null,
            PathImpl.createRootPath(),
            new DummyConstraintDescriptor()
    ).buildConstraintViolationWithTemplate("dummytemplate");
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:8,代码来源:AbstractValidatorTest.java

示例10: destinationExistsPolicyFail

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@Test
public void destinationExistsPolicyFail() throws IOException {
    ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);
    ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(builder);
    SetMetadataParameters params = new SetMetadataParameters();
    params.setOutput(new FileTaskOutput(folder.newFile()));
    params.setExistingOutputPolicy(ExistingOutputPolicy.FAIL);
    assertFalse(victim.isValid(params, context));
    verify(context).buildConstraintViolationWithTemplate(contains("File destination already exists"));
}
 
开发者ID:torakiki,项目名称:sejda,代码行数:12,代码来源:SingleOutputValidatorTest.java

示例11: destinationExistsPolicySkip

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@Test
public void destinationExistsPolicySkip() throws IOException {
    ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);
    ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(builder);
    SetMetadataParameters params = new SetMetadataParameters();
    params.setOutput(new FileTaskOutput(folder.newFile()));
    params.setExistingOutputPolicy(ExistingOutputPolicy.SKIP);
    assertFalse(victim.isValid(params, context));
    verify(context).buildConstraintViolationWithTemplate(contains("File destination already exists"));
}
 
开发者ID:torakiki,项目名称:sejda,代码行数:12,代码来源:SingleOutputValidatorTest.java

示例12: testInvalidValue

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@Test
public void testInvalidValue() {
    ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);
    ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(builder);
    NodeBuilderDefinedContext nodeBuilderContext = mock(NodeBuilderDefinedContext.class);
    when(builder.addNode(anyString())).thenReturn(nodeBuilderContext);
    when(params.getVersion()).thenReturn(PdfVersion.VERSION_1_2);
    when(params.getMinRequiredPdfVersion()).thenReturn(PdfVersion.VERSION_1_5);
    assertFalse(victim.isValid(params, context));
    verify(context).buildConstraintViolationWithTemplate(anyString());
}
 
开发者ID:torakiki,项目名称:sejda,代码行数:13,代码来源:PdfVersionValidatorTest.java

示例13: isValid

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
@Override
public boolean isValid(MarketOrder entity, ConstraintValidatorContext ctx) {
	List<ConstraintViolationBuilder> errors = new ArrayList<ConstraintViolationBuilder>();
	if (entity.getSource() == MarketOrderSource.AMOUNT
			&& (entity.getGrossAmount() == null || entity.getGrossAmount().equals(BigDecimal.ZERO))) {
		errors.add(ctx.buildConstraintViolationWithTemplate("marketOrder.validation.missingAmount"));
	}
	else if (entity.getSource() == MarketOrderSource.UNITS
			&& (entity.getUnits() == null || entity.getUnits().equals(BigDecimal.ZERO))) {
		errors.add(ctx.buildConstraintViolationWithTemplate("marketOrder.validation.missingUnits"));
	}
	addIfNotNull(errors,
			checkPositiveValue(entity.getGrossAmount(), "marketOrder.validation.negativeGrossAmount", ctx));
	addIfNotNull(errors,
			checkPositiveValue(entity.getNetAmount(), "marketOrder.validation.negativeNetAmount", ctx));
	addIfNotNull(errors, checkPositiveValue(entity.getUnits(), "marketOrder.validation.negativeUnits", ctx));
	addIfNotNull(errors, checkPositiveValue(entity.getNav(), "marketOrder.validation.negativeNav", ctx));
	// Comprobamos la integridad de las fechas y los estados
	if (entity.getCurrentState() != null && entity.getDates() != null) {
		MarketOrder.States state = MarketOrder.States.valueOf(entity.getCurrentState().getCode());
		switch (state) {
		case INITIAL:
			addIfNotNull(errors, checkNullValue(entity.getDates().getProcessed(),
					Validation.StateInitialWithProcessedDate, ctx));
			addIfNotNull(errors, checkNullValue(entity.getDates().getValued(),
					"marketOrder.validation.stateInitialWithValuedDate", ctx));
			addIfNotNull(errors, checkNullValue(entity.getDates().getAccounted(),
					"marketOrder.validation.stateInitialWithAcountedDate", ctx));
			break;
		case PROCESSED:
			addIfNotNull(errors, checkNullValue(entity.getDates().getProcessed(),
					"marketOrder.validation.stateInitialWithProcessedDate", ctx));
			addIfNotNull(errors, checkNullValue(entity.getDates().getValued(),
					"marketOrder.validation.stateInitialWithValuedDate", ctx));
			addIfNotNull(errors, checkNullValue(entity.getDates().getAccounted(),
					"marketOrder.validation.stateInitialWithAcountedDate", ctx));
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getProcessed(),
					"marketOrder.validation.stateProcessedWithoutProcessedDate", ctx));
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getValueDate(),
					"marketOrder.validation.stateProcessedWithoutValueDate", ctx));
			addIfNotNull(errors, checkNullValue(entity.getDates().getAccounted(),
					"marketOrder.validation.stateProcessedWithAcountedDate", ctx));
			addIfNotNull(errors, checkNullValue(entity.getDates().getValued(),
					"marketOrder.validation.stateProcessedWithValuedDate", ctx));
			break;
		case VALUED:
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getProcessed(),
					"marketOrder.validation.stateValuedWithoutProcessedDate", ctx));
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getValueDate(),
					"marketOrder.validation.stateValuedWithoutValueDate", ctx));
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getValued(),
					"marketOrder.validation.stateValuedWithoutValuedDate", ctx));
			addIfNotNull(errors, checkNullValue(entity.getDates().getAccounted(),
					"marketOrder.validation.stateValuedWithAccountedDate", ctx));
			break;
		case ACCOUNTED:
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getProcessed(),
					"marketOrder.validation.stateAccountedWithoutProcessedDate", ctx));
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getValueDate(),
					"marketOrder.validation.stateAccountedWithoutValueDate", ctx));
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getValued(),
					"marketOrder.validation.stateAccountedWithoutValued", ctx));
			addIfNotNull(errors, checkNotNullValue(entity.getDates().getAccounted(),
					"marketOrder.validation.stateAccountedWithoutAccountedDate", ctx));
			break;
		default:
			break;
		}
	}
	if (errors.isEmpty()) {
		return true;
	}
	else {
		for (ConstraintViolationBuilder builder : errors) {
			builder.addConstraintViolation();

		}
		return false;
	}
}
 
开发者ID:labcabrera,项目名称:lab-insurance,代码行数:81,代码来源:MarketOrderValidator.java

示例14: validatePayment

import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; //导入依赖的package包/类
private void validatePayment(Order order, ConstraintValidatorContext ctx, List<ConstraintViolationBuilder> errors) {
	if (order.getBuyDistribution() == null || order.getBuyDistribution().isEmpty()) {
		errors.add(ctx.buildConstraintViolationWithTemplate("order.validation.missingBuyDistribution"));
	}
}
 
开发者ID:labcabrera,项目名称:lab-insurance,代码行数:6,代码来源:OrderValidator.java


注:本文中的javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。