AutonomiccsSystemVmTemplateJdbcDao extends JdbcDaoSupport { protected boolean executeTemplateQueryAndRetrieveBoolean(String templateName, String sql) { Integer numberOfRegister = getJdbcTemplate().queryForObject(sql, new Object[] {templateName}, Integer.class); if (numberOfRegister > 1) { throw new CloudRuntimeException(String.format("More than one template with name [%s]", templateName)); } return BooleanUtils.toBoolean(numberOfRegister); }  boolean isTemplateRegistered(String templateName); boolean isTemplateRegisteredAndReady(String autonomiccsSystemVmTemplateName); long searchAutonomiccsSystemVmTemplateIdForHypervisor(String autonomiccsSystemVmTemplateName);  }
@Test public void executeTemplateQueryAndRetrieveBooleanTest() { Mockito.when(jdbcTemplate.queryForObject(Mockito.eq(sqlIsTemplateRegistered), Mockito.any(Object[].class), Mockito.eq(Integer.class))).thenReturn(new Integer(1)); boolean result = spy.executeTemplateQueryAndRetrieveBoolean("templateName", sqlIsTemplateRegistered); Mockito.verify(jdbcTemplate).queryForObject(Mockito.eq(sqlIsTemplateRegistered), Mockito.any(Object[].class), Mockito.eq(Integer.class)); Assert.assertTrue(result); }
@Test(expected = CloudRuntimeException.class) public void executeTemplateQueryAndRetrieveBooleanTestWithCloudRuntimeException() { Mockito.when(jdbcTemplate.queryForObject(Mockito.eq(sqlIsTemplateRegistered), Mockito.any(Object[].class), Mockito.eq(Integer.class))).thenReturn(new Integer(2)); spy.executeTemplateQueryAndRetrieveBoolean("templateName", sqlIsTemplateRegistered); Mockito.verify(jdbcTemplate).queryForObject(Mockito.eq(sqlIsTemplateRegistered), Mockito.any(Object[].class), Mockito.eq(Integer.class)); }