EmailTemplateDaoImpl implements EmailTemplateDao { @Override public String getTemplate(String templateName) { List<String> idList = new ArrayList<>(); if (StringUtils.isBlank(templateName)) { idList.add(DEFAULT_EMAIL_TEMPLATE_NAME); } else { idList.add(templateName); } Response response = getCassandraOperation().getRecordsByPrimaryKeys( JsonKey.SUNBIRD, EMAIL_TEMPLATE, idList, JsonKey.NAME); List<Map<String, Object>> emailTemplateList = (List<Map<String, Object>>) response.get(JsonKey.RESPONSE); Map<String, Object> map = Collections.emptyMap(); if (CollectionUtils.isNotEmpty(emailTemplateList)) { map = emailTemplateList.get(0); } return (String) map.get(TEMPLATE); }  static EmailTemplateDao getInstance(); @Override String getTemplate(String templateName);  }
@Test public void testGetTemplateWithBlankTemplateName(){ List<String> idList = new ArrayList<>(); idList.add(DEFAULT_EMAIL_TEMPLATE_NAME); Response response = new Response(); List<Map<String, Object>> orgList =new ArrayList<>(); Map<String,Object>map=new HashMap<>(); orgList.add(map); response.put(JsonKey.RESPONSE,orgList); when(cassandraOperation.getRecordsByPrimaryKeys(JsonKey.SUNBIRD, EMAIL_TEMPLATE, idList, JsonKey.NAME)).thenReturn(response); String resp=emailTemplateDao.getTemplate(StringUtils.EMPTY); Assert.assertEquals(null,resp); }
@Test public void testGetTemplateWithTemplateName(){ List<String> idList = new ArrayList<>(); idList.add("Sunbird_email_template"); Response response = new Response(); List<Map<String, Object>> orgList =new ArrayList<>(); Map<String,Object>map=new HashMap<>(); map.put(TEMPLATE,"Course is Been completed"); orgList.add(map); response.put(JsonKey.RESPONSE,orgList); when(cassandraOperation.getRecordsByPrimaryKeys(JsonKey.SUNBIRD, EMAIL_TEMPLATE, idList, JsonKey.NAME)).thenReturn(response); String resp=emailTemplateDao.getTemplate("Sunbird_email_template"); Assert.assertEquals("Course is Been completed",resp); }