I have a series of test cases using Spring Jdbc
, Database Rider
, and H2
— with Java 17.x
. Everything works fine, but I can't find a way to represent a byte array in the YAML configuration file :/
This is what I have:
@Getter
@Builder
public final class Category {
...
private byte[] picture;
}
public class CategoryJdbc implements ICategoryJdbc {
private static final RowMapper<Category> ROW_MAPPER = (rs, rowNum) -> Category.builder()
...
.picture(rs.getBytes("picture"))
.build();
private final NamedParameterJdbcTemplate template;
@Override
@Transactional(readOnly = true)
public Optional<Category> findById(final Long primaryKey) {
final var result = template.queryForObject(queries.getProperty("find-category-by-identifier"),
new MapSqlParameterSource("id", primaryKey), ROW_MAPPER);
return Optional.ofNullable(result);
}
}
@DBRider
@ExtendWith(SpringExtension.class)
class CategoryJdbcTest {
@Autowired
private ICategoryJdbc jdbc;
@Test
@DataSet("categories.yml")
void findById_WhenEntityExists() {
Assertions.assertThat(jdbc.findById(1L)).hasValueSatisfying(it -> {
Assertions.assertThat(it.getId()).isEqualTo(1);
Assertions.assertThat(it.getName()).isEqualTo("Beverages");
Assertions.assertThat(it.getDescription()).isEqualTo("Soft drinks, coffees, teas, beers, and ales");
Assertions.assertThat(it.getPicture())
.isEqualTo(new byte[] { 0x4c, 0x6f, 72, 65, 0x6d, 20, 69, 70, 73, 75, 0x6d });
});
}
}
categories:
- id: 1
name: "Beverages"
description: "Soft drinks, coffees, teas, beers, and ales"
picture: \x4c6f72656d20697073756d # Lorem ipsum
For testing, I converted
Lorem ipsum
to a bytes array:4c 6f 72 65 6d 20 69 70 73 75 6d
.
Does anyone knows how to represent the same in the YAML file, in such way that rs.getBytes("picture")
interprets it correctly?
I've tested this with the built-in H2
binary data types as well — because bytea
is built-in a PostgreSQL
data type, but looks like it works as well in H2
, even though I don't see it listed in H2
's website.