SimpleJdbcRepository implements JdbcRepository { @Override public JdbcParameter getParameterMetadata(QueryRunner runner, String parameterName) { JdbcParameter parameter = parameterDAO.getParameter(runner, parameterName); if (parameter != null) { List<Level> levels = new ArrayList<Level>(levelDAO.getLevels(runner, parameter.getId())); parameter.setLevels(levels); } return parameter; } SimpleJdbcRepository(JdbcConfig configuration, ParameterDAO parameterDAO, LevelDAO levelDAO, ParameterEntryDAO parameterEntryDAO); @Override long createParameter(QueryRunner runner, Parameter parameter); @Override boolean parameterExists(QueryRunner runner, String parameterName); @Override JdbcParameter getParameter(QueryRunner runner, String parameterName); @Override JdbcParameter getParameterMetadata(QueryRunner runner, String parameterName); @Override Set<String> listParameterNames(); @Override List<String> listParameterNames(ParameterFilter filter); @Override Set<ParameterEntry> getParameterEntries(QueryRunner runner, String parameterName); @Override List<Long> writeParameterEntries(QueryRunner runner, String parameterName, Iterable<ParameterEntry> entries); @Override void deleteParameter(QueryRunner runner, String parameterName); @Override void updateParameter(QueryRunner runner, String parameterName, Parameter parameter); @Override long addLevel(QueryRunner runner, String parameterName, Level level); @Override void updateLevel(QueryRunner runner, long levelId, Level level); @Override void reorderLevels(QueryRunner runner, long[] orderedLevelIds); @Override void deleteLevel(QueryRunner queryRunner, String parameterName, long levelId); @Override List<ParameterEntry> getEntries(QueryRunner runner, List<Long> ids); @Override List<ParameterEntry> listEntries(QueryRunner runner, String parameterName, ParameterEntriesFilter filter); @Override long addParameterEntry(QueryRunner runner, String parameterName, ParameterEntry entry); @Override void updateParameterEntry(QueryRunner runner, long entryId, ParameterEntry entry); @Override void deleteParameterEntry(QueryRunner runner, long entryId); @Override void deleteParameterEntries(QueryRunner runner, Iterable<Long> entriesIds); @Override void deleteParameterEntries(QueryRunner runner, String parameterName);  }
@Test public void shouldReturnParameterMetadataWithoutEntries() { database().withParameter("parameter").withParameterEntries("parameter", 5) .withLevels("parameter", 4).build(); SimpleJdbcRepository repository = get(SimpleJdbcRepository.class); QueryRunner runner = queryRunner(); Parameter metadata = repository.getParameterMetadata(runner, "parameter"); runner.close(); assertThat(metadata).hasName("parameter").hasLevels(4).hasNoEntries(); }
@Test public void shouldReturnNullWhenParameterNotFound() { SimpleJdbcRepository repository = get(SimpleJdbcRepository.class); QueryRunner runner = queryRunner(); Parameter metadata = repository.getParameterMetadata(runner, "unknownParameter"); runner.close(); assertThat(metadata).isNull(); }