@Test public void testBindErrorNotWritableWithPrefix() throws Exception { VanillaTarget target = new VanillaTarget(); BindingResult result = bind(target, "spam: bar\n" + "vanilla.value: 123", "vanilla"); assertEquals(0, result.getErrorCount()); assertEquals(123, target.getValue()); }
@Test public void testOnlyTopLevelFields() throws Exception { VanillaTarget target = new VanillaTarget(); RelaxedDataBinder binder = getBinder(target, null); binder.setIgnoreUnknownFields(false); binder.setIgnoreNestedProperties(true); BindingResult result = bind(binder, target, "foo: bar\n" + "value: 123\n" + "nested.bar: spam"); assertEquals(123, target.getValue()); assertEquals("bar", target.getFoo()); assertEquals(0, result.getErrorCount()); }
@Test public void testAllowedFields() throws Exception { VanillaTarget target = new VanillaTarget(); RelaxedDataBinder binder = getBinder(target, null); binder.setAllowedFields("foo"); binder.setIgnoreUnknownFields(false); BindingResult result = bind(binder, target, "foo: bar\n" + "value: 123\n" + "bar: spam"); assertEquals(0, target.getValue()); assertEquals("bar", target.getFoo()); assertEquals(0, result.getErrorCount()); }
@Test public void testBindNumber() throws Exception { VanillaTarget target = new VanillaTarget(); bind(target, "foo: bar\n" + "value: 123"); assertEquals(123, target.getValue()); }