use of org.springframework.beans.PropertyAccessor in project spring-boot by spring-projects.
the class DeviceDelegatingViewResolverAutoConfigurationTests method overrideTabletSuffix.
@Test
public void overrideTabletSuffix() throws Exception {
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor("spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.tabletSuffix:.tab");
assertThat(accessor.getPropertyValue("tabletSuffix")).isEqualTo(".tab");
}
use of org.springframework.beans.PropertyAccessor in project spring-boot by spring-projects.
the class DeviceDelegatingViewResolverAutoConfigurationTests method overrideMobileSuffix.
@Test
public void overrideMobileSuffix() throws Exception {
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor("spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.mobileSuffix:.mob");
assertThat(accessor.getPropertyValue("mobileSuffix")).isEqualTo(".mob");
}
use of org.springframework.beans.PropertyAccessor in project syndesis by syndesisio.
the class UniquePropertyValidator method isValid.
@Override
public boolean isValid(final WithId<?> value, final ConstraintValidatorContext context) {
if (value == null) {
return true;
}
final PropertyAccessor bean = new BeanWrapperImpl(value);
final String propertyValue = String.valueOf(bean.getPropertyValue(property));
@SuppressWarnings({ "rawtypes", "unchecked" }) final Class<WithId> modelClass = (Class) value.getKind().modelClass;
@SuppressWarnings("unchecked") final Set<String> ids = dataManager.fetchIdsByPropertyValue(modelClass, property, propertyValue);
final boolean isUnique = ids.isEmpty() || value.getId().map(id -> ids.contains(id)).orElse(false);
if (!isUnique) {
if (ids.stream().allMatch(id -> consideredValidByException(modelClass, id))) {
return true;
}
context.disableDefaultConstraintViolation();
context.unwrap(HibernateConstraintValidatorContext.class).addExpressionVariable("nonUnique", propertyValue).buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()).addPropertyNode(property).addConstraintViolation();
}
return isUnique;
}
Aggregations