@Test public void shouldThrowOnMismatchedColumnsStrictMatch() throws Exception { ctx.getConfig(ReflectionMappers.class).setStrictMatching(true); mockColumns("longField", "misspelledField"); assertThatThrownBy(() -> mapper.map(resultSet, ctx)).isInstanceOf(IllegalArgumentException.class); }
@Test public void shouldThrowOnMismatchedColumnsStrictMatch() throws Exception { ctx.getConfig(ReflectionMappers.class).setStrictMatching(true); mockColumns("longField", "misspelledField"); assertThatThrownBy(() -> mapper.map(resultSet, ctx)).isInstanceOf(IllegalArgumentException.class); }
@Test public void nestedPrefixParametersStrict() { Handle handle = dbRule.getSharedHandle(); handle.getConfig(ReflectionMappers.class).setStrictMatching(true); handle.registerRowMapper(ConstructorMapper.factory(NestedPrefixBean.class)); assertThat(handle .createQuery("select i nested_i, s nested_s from bean") .mapTo(NestedPrefixBean.class) .findOnly()) .extracting("nested.s", "nested.i") .containsExactly("3", 2); assertThatThrownBy(() -> handle .createQuery("select i nested_i, s nested_s, 1 as other from bean") .mapTo(NestedPrefixBean.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match parameters for columns: [other]"); assertThatThrownBy(() -> handle .createQuery("select i nested_i, s nested_s, 1 as nested_other from bean") .mapTo(NestedPrefixBean.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match parameters for columns: [nested_other]"); }
@Test public void testNestedStrict() { Handle handle = dbRule.getSharedHandle(); handle.getConfig(ReflectionMappers.class).setStrictMatching(true); handle.registerRowMapper(BeanMapper.factory(NestedBean.class)); handle.execute("insert into something (id, name) values (1, 'foo')"); assertThat(handle .createQuery("select id, name from something") .mapTo(NestedBean.class) .findOnly()) .extracting("nested.id", "nested.name") .containsExactly(1, "foo"); assertThatThrownBy(() -> handle .createQuery("select id, name, 1 as other from something") .mapTo(NestedBean.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match properties for columns: [other]"); }
@Test public void testNestedPrefixStrict() { Handle handle = dbRule.getSharedHandle(); handle.getConfig(ReflectionMappers.class).setStrictMatching(true); handle.registerRowMapper(BeanMapper.factory(NestedPrefixBean.class)); handle.execute("insert into something (id, name, integerValue) values (1, 'foo', 5)"); // three, sir! assertThat(handle .createQuery("select id nested_id, name nested_name, integerValue from something") .mapTo(NestedPrefixBean.class) .findOnly()) .extracting("nested.id", "nested.name", "integerValue") .containsExactly(1, "foo", 5); assertThatThrownBy(() -> handle .createQuery("select id nested_id, name nested_name, 1 as other from something") .mapTo(NestedPrefixBean.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match properties for columns: [other]"); assertThatThrownBy(() -> handle .createQuery("select id nested_id, name nested_name, 1 as nested_other from something") .mapTo(NestedPrefixBean.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match properties for columns: [nested_other]"); }
@Test public void testNestedPrefixStrict() { Handle handle = dbRule.getSharedHandle(); handle.getConfig(ReflectionMappers.class).setStrictMatching(true); handle.registerRowMapper(FieldMapper.factory(NestedPrefixThing.class)); handle.execute("insert into something (id, name, integerValue) values (1, 'foo', 5)"); // three, sir! assertThat(handle .createQuery("select id nested_id, name nested_name, integerValue from something") .mapTo(NestedPrefixThing.class) .findOnly()) .extracting("nested.i", "nested.s", "integerValue") .containsExactly(1, "foo", 5); assertThatThrownBy(() -> handle .createQuery("select id nested_id, name nested_name, 1 as other from something") .mapTo(NestedPrefixThing.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match fields for columns: [other]"); assertThatThrownBy(() -> handle .createQuery("select id nested_id, name nested_name, 1 as nested_other from something") .mapTo(NestedPrefixThing.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match fields for columns: [nested_other]"); }
@Test public void testNestedStrict() { Handle handle = dbRule.getSharedHandle(); handle.getConfig(ReflectionMappers.class).setStrictMatching(true); handle.registerRowMapper(FieldMapper.factory(NestedThing.class)); handle.execute("insert into something (id, name) values (1, 'foo')"); assertThat(handle .registerRowMapper(FieldMapper.factory(NestedThing.class)) .select("select id, name from something") .mapTo(NestedThing.class) .findOnly()) .extracting("nested.i", "nested.s") .containsExactly(1, "foo"); assertThatThrownBy(() -> handle .createQuery("select id, name, 1 as other from something") .mapTo(NestedThing.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match fields for columns: [other]"); }
@Test public void nestedParametersStrict() { Handle handle = dbRule.getSharedHandle(); handle.getConfig(ReflectionMappers.class).setStrictMatching(true); handle.registerRowMapper(ConstructorMapper.factory(NestedBean.class)); assertThat(dbRule.getSharedHandle() .registerRowMapper(ConstructorMapper.factory(NestedBean.class)) .select("select s, i from bean") .mapTo(NestedBean.class) .findOnly()) .extracting("nested.s", "nested.i") .containsExactly("3", 2); assertThatThrownBy(() -> handle .createQuery("select s, i, 1 as other from bean") .mapTo(NestedBean.class) .findOnly()) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("could not match parameters for columns: [other]"); }