/** * Apply given property values to the target object. * <p>Default implementation applies all of the supplied property * values as bean property values. By default, unknown fields will * be ignored. * @param mpvs the property values to be bound (can be modified) * @see #getTarget * @see #getPropertyAccessor * @see #isIgnoreUnknownFields * @see #getBindingErrorProcessor * @see BindingErrorProcessor#processPropertyAccessException */ protected void applyPropertyValues(MutablePropertyValues mpvs) { try { // Bind request parameters onto target object. getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields()); } catch (PropertyBatchUpdateException ex) { // Use bind error processor to create FieldErrors. for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) { getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult()); } } }
public void xtestTypeMismatch() { try { getBeanFactory().getBean("typeMismatch"); fail("Shouldn't succeed with type mismatch"); } catch (BeanCreationException wex) { assertEquals("typeMismatch", wex.getBeanName()); assertTrue(wex.getCause() instanceof PropertyBatchUpdateException); PropertyBatchUpdateException ex = (PropertyBatchUpdateException) wex.getCause(); // Further tests assertTrue("Has one error ", ex.getExceptionCount() == 1); assertTrue("Error is for field age", ex.getPropertyAccessException("age") != null); assertTrue("We have rejected age in exception", ex.getPropertyAccessException("age").getPropertyChangeEvent().getNewValue().equals("34x")); } }
@Test public void shouldFailDueToMissingAccessTokenUrl() { exception.expectCause(instanceOf(PropertyBatchUpdateException.class)); exception.expectCause(hasFeature("exception", PropertyBatchUpdateException::getPropertyAccessExceptions, hasItemInArray(hasFeature("cause", Throwables::getRootCause, hasFeature("message", Throwable::getMessage, compose(containsString("rest.oauth.access-token-url")).and( containsString("ACCESS_TOKEN_URL"))))))); new SpringApplicationBuilder(TestConfiguration.class) .profiles("default") .build() .run(); }