@Test public void shouldRunTemplateParameterSelectSqlAndSetValues() { final Template t = new Template(); TemplateParameter tpWithSelectSql = new TemplateParameter(); final String selectSql = "select name from something"; tpWithSelectSql.setSelectSql(selectSql); TemplateParameter tpNoSelectSql = new TemplateParameter(); t.setParameters(asList(tpWithSelectSql, tpNoSelectSql)); final long id = 1L; final List<String> selectValues = asList("first", "second"); when(templateMapper.getLWById(id)).thenReturn(t); when(templateMapper.runSelectSql(selectSql)).thenReturn(selectValues); Template tRet = templateRepository.getLWById(id); assertThat(tRet, is(notNullValue())); verify(templateMapper, atLeastOnce()).runSelectSql(selectSql); assertThat(tRet.getParameters().size(), is(2)); assertThat(tpWithSelectSql.getSelectValues(), is(selectValues)); assertThat(tpNoSelectSql.getSelectValues().size(), is(0)); }
public Template getLWById(Long id) { Template t = mapper.getLWById(id); if(t == null) return null; for(TemplateParameter tp : t.getParameters()) { if(isBlank(tp.getSelectSql()) == false) { logger.debug("Template Parameter " + t.getName() + " has select sql: " + tp.getSelectSql()); List<String> selectValues = mapper.runSelectSql(tp.getSelectSql()); logger.debug("Template Parameter " + t.getName() + " select values: " + selectValues); tp.setSelectValues(selectValues); } } return t; }
TemplateRepository { public Template getLWById(Long id) { Template t = mapper.getLWById(id); if(t == null) return null; for(TemplateParameter tp : t.getParameters()) { if(isBlank(tp.getSelectSql()) == false) { logger.debug("Template Parameter " + t.getName() + " has select sql: " + tp.getSelectSql()); List<String> selectValues = mapper.runSelectSql(tp.getSelectSql()); logger.debug("Template Parameter " + t.getName() + " select values: " + selectValues); tp.setSelectValues(selectValues); } } return t; } }
TemplateRepository { public Template getLWById(Long id) { Template t = mapper.getLWById(id); if(t == null) return null; for(TemplateParameter tp : t.getParameters()) { if(isBlank(tp.getSelectSql()) == false) { logger.debug("Template Parameter " + t.getName() + " has select sql: " + tp.getSelectSql()); List<String> selectValues = mapper.runSelectSql(tp.getSelectSql()); logger.debug("Template Parameter " + t.getName() + " select values: " + selectValues); tp.setSelectValues(selectValues); } } return t; }  }
TemplateRepository { public Template getLWById(Long id) { Template t = mapper.getLWById(id); if(t == null) return null; for(TemplateParameter tp : t.getParameters()) { if(isBlank(tp.getSelectSql()) == false) { logger.debug("Template Parameter " + t.getName() + " has select sql: " + tp.getSelectSql()); List<String> selectValues = mapper.runSelectSql(tp.getSelectSql()); logger.debug("Template Parameter " + t.getName() + " select values: " + selectValues); tp.setSelectValues(selectValues); } } return t; }  void insertWithParameters(Template template); List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id); }
TemplateRepository { public Template getLWById(Long id) { Template t = mapper.getLWById(id); if(t == null) return null; for(TemplateParameter tp : t.getParameters()) { if(isBlank(tp.getSelectSql()) == false) { logger.debug("Template Parameter " + t.getName() + " has select sql: " + tp.getSelectSql()); List<String> selectValues = mapper.runSelectSql(tp.getSelectSql()); logger.debug("Template Parameter " + t.getName() + " select values: " + selectValues); tp.setSelectValues(selectValues); } } return t; }  void insertWithParameters(Template template); List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id);  }