File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
main/java/com/cosium/hal_mock_mvc
test/java/com/cosium/hal_mock_mvc Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,9 @@ private ValidatedFormProperty<?> validate(
197197 FormProperty <?> property , PropertyValidationOption ... validationOptions ) throws Exception {
198198 Set <PropertyValidationOption > validationOptionSet =
199199 Optional .ofNullable (validationOptions ).map (Set ::of ).orElse (Set .of ());
200+ if (validationOptionSet .contains (PropertyValidationOption .Immediate .DO_NOT_FAIL_IF_NOT_VALID )) {
201+ return ValidatedFormProperty .markAsValid (property );
202+ }
200203 TemplatePropertyRepresentation representation =
201204 template .representation ().propertyByName ().get (property .name ());
202205 if (representation == null ) {
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ enum Immediate implements PropertyValidationOption {
99 /** Do not fail if writing to a property not declared by the template */
1010 DO_NOT_FAIL_IF_NOT_DECLARED ,
1111 /** Do not fail if writing to a property declared as read-only by the template */
12- DO_NOT_FAIL_IF_DECLARED_READ_ONLY
12+ DO_NOT_FAIL_IF_DECLARED_READ_ONLY ,
13+ /** Do not fail if writing invalid value to a property */
14+ DO_NOT_FAIL_IF_NOT_VALID ,
1315 }
1416}
Original file line number Diff line number Diff line change 77import static org .springframework .hateoas .server .mvc .WebMvcLinkBuilder .methodOn ;
88import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
99
10+ import com .cosium .hal_mock_mvc .PropertyValidationOption .Immediate ;
1011import com .fasterxml .jackson .jr .ob .JSON ;
1112import com .jayway .jsonpath .DocumentContext ;
1213import com .jayway .jsonpath .JsonPath ;
@@ -1843,6 +1844,40 @@ void test39() throws Exception {
18431844 .doesNotThrowAnyException ();
18441845 }
18451846
1847+ @ Test
1848+ @ DisplayName ("User can force an invalid property" )
1849+ void test40 () throws Exception {
1850+ myController .getResponseToSend =
1851+ JSON .std
1852+ .composeString ()
1853+ .startObject ()
1854+ .startObjectField ("_links" )
1855+ .startObjectField ("self" )
1856+ .put ("href" , "http://localhost/form-test:put" )
1857+ .end ()
1858+ .end ()
1859+ .startObjectField ("_templates" )
1860+ .startObjectField ("default" )
1861+ .put ("method" , "PUT" )
1862+ .startArrayField ("properties" )
1863+ .end ()
1864+ .end ()
1865+ .end ()
1866+ .end ()
1867+ .finish ();
1868+
1869+ Form form =
1870+ HalMockMvc .builder (mockMvc )
1871+ .baseUri (linkTo (methodOn (MyController .class ).get ()).toUri ())
1872+ .build ()
1873+ .follow ()
1874+ .templates ()
1875+ .byKey ("default" )
1876+ .createForm ();
1877+ assertThatCode (() -> form .withString ("foo" , "foo" , Immediate .DO_NOT_FAIL_IF_NOT_VALID ))
1878+ .doesNotThrowAnyException ();
1879+ }
1880+
18461881 @ Controller
18471882 public static class MyController {
18481883
You can’t perform that action at this time.
0 commit comments