Search in sources :

Example 11 with PropertyAccessor

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");
}
Also used : PropertyAccessor(org.springframework.beans.PropertyAccessor) Test(org.junit.Test)

Example 12 with PropertyAccessor

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");
}
Also used : PropertyAccessor(org.springframework.beans.PropertyAccessor) Test(org.junit.Test)

Example 13 with PropertyAccessor

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;
}
Also used : WithId(io.syndesis.common.model.WithId) PropertyAccessor(org.springframework.beans.PropertyAccessor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Aggregations

PropertyAccessor (org.springframework.beans.PropertyAccessor)13 Test (org.junit.Test)9 URI (java.net.URI)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 HttpMethod (org.springframework.http.HttpMethod)2 ResponseEntity (org.springframework.http.ResponseEntity)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 RestTemplate (org.springframework.web.client.RestTemplate)2 RequestAttributes (org.springframework.web.context.request.RequestAttributes)2 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)2 HasId (org.summerb.approaches.jdbccrud.api.dto.HasId)2 Ref (org.summerb.approaches.jdbccrud.api.dto.relations.Ref)2 WithId (io.syndesis.common.model.WithId)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1