@Test public void subscribeDigestMailTest(){ when(jdbcTemplate.update(anyString(), anyString())).thenReturn(1); notificationImpl. subscribeDigestMail("test@mail.com"); when(jdbcTemplate.update(anyString(), anyString())).thenReturn(2); notificationImpl. subscribeDigestMail("test@mail.com"); }
@Override public Map<String, Object> subscribeDigestMail(String mailId) { String sql = "SELECT subscriptionValue AS subscriptionValue FROM PacmanSubscriptions WHERE emailId = ?"; String updateOrInsertQuery ; Object[] parameters; Date date = new Date(); Boolean isUnsubscriptedAlready = jdbcTemplate.query(sql, new Object[]{mailId}, new ResultSetExtractor<Boolean>() { @Override public Boolean extractData(ResultSet rs) { try { return rs.next() ? rs.getBoolean("subscriptionValue") : null; } catch (SQLException e) { Log.error(e.getMessage()); return null; } } }); if(isUnsubscriptedAlready != null) { updateOrInsertQuery="UPDATE PacmanSubscriptions SET emailId=?, subscriptionValue=?, modifiedDate=? WHERE emailId=?"; parameters = new Object[] {mailId, true, date, mailId}; } else { updateOrInsertQuery="INSERT INTO PacmanSubscriptions (emailId, subscriptionValue, createdDate, modifiedDate) VALUES (?,?,?,?)"; parameters = new Object[] {mailId, true, date, date}; } int status = jdbcTemplate.update(updateOrInsertQuery, parameters); Map<String, Object> response = Maps.newHashMap(); if(status==1) { response.put(STATUS, true); response.put(MESSAGE_KEY, "You have successfully subscribed"); } else { response.put(STATUS, false); response.put(MESSAGE_KEY, "Subscription Failed!!!"); } return response; }
NotificationServiceImpl implements NotificationService,Constants { @Override public Map<String, Object> subscribeDigestMail(String mailId) { String sql = "SELECT subscriptionValue AS subscriptionValue FROM PacmanSubscriptions WHERE emailId = ?"; String updateOrInsertQuery ; Object[] parameters; Date date = new Date(); Boolean isUnsubscriptedAlready = jdbcTemplate.query(sql, new Object[]{mailId}, new ResultSetExtractor<Boolean>() { @Override public Boolean extractData(ResultSet rs) { try { return rs.next() ? rs.getBoolean("subscriptionValue") : null; } catch (SQLException e) { Log.error(e.getMessage()); return null; } } }); if(isUnsubscriptedAlready != null) { updateOrInsertQuery="UPDATE PacmanSubscriptions SET emailId=?, subscriptionValue=?, modifiedDate=? WHERE emailId=?"; parameters = new Object[] {mailId, true, date, mailId}; } else { updateOrInsertQuery="INSERT INTO PacmanSubscriptions (emailId, subscriptionValue, createdDate, modifiedDate) VALUES (?,?,?,?)"; parameters = new Object[] {mailId, true, date, date}; } int status = jdbcTemplate.update(updateOrInsertQuery, parameters); Map<String, Object> response = Maps.newHashMap(); if(status==1) { response.put(STATUS, true); response.put(MESSAGE_KEY, "You have successfully subscribed"); } else { response.put(STATUS, false); response.put(MESSAGE_KEY, "Subscription Failed!!!"); } return response; } }
NotificationServiceImpl implements NotificationService,Constants { @Override public Map<String, Object> subscribeDigestMail(String mailId) { String sql = "SELECT subscriptionValue AS subscriptionValue FROM PacmanSubscriptions WHERE emailId = ?"; String updateOrInsertQuery ; Object[] parameters; Date date = new Date(); Boolean isUnsubscriptedAlready = jdbcTemplate.query(sql, new Object[]{mailId}, new ResultSetExtractor<Boolean>() { @Override public Boolean extractData(ResultSet rs) { try { return rs.next() ? rs.getBoolean("subscriptionValue") : null; } catch (SQLException e) { Log.error(e.getMessage()); return null; } } }); if(isUnsubscriptedAlready != null) { updateOrInsertQuery="UPDATE PacmanSubscriptions SET emailId=?, subscriptionValue=?, modifiedDate=? WHERE emailId=?"; parameters = new Object[] {mailId, true, date, mailId}; } else { updateOrInsertQuery="INSERT INTO PacmanSubscriptions (emailId, subscriptionValue, createdDate, modifiedDate) VALUES (?,?,?,?)"; parameters = new Object[] {mailId, true, date, date}; } int status = jdbcTemplate.update(updateOrInsertQuery, parameters); Map<String, Object> response = Maps.newHashMap(); if(status==1) { response.put(STATUS, true); response.put(MESSAGE_KEY, "You have successfully subscribed"); } else { response.put(STATUS, false); response.put(MESSAGE_KEY, "Subscription Failed!!!"); } return response; }  }
NotificationServiceImpl implements NotificationService,Constants { @Override public Map<String, Object> subscribeDigestMail(String mailId) { String sql = "SELECT subscriptionValue AS subscriptionValue FROM PacmanSubscriptions WHERE emailId = ?"; String updateOrInsertQuery ; Object[] parameters; Date date = new Date(); Boolean isUnsubscriptedAlready = jdbcTemplate.query(sql, new Object[]{mailId}, new ResultSetExtractor<Boolean>() { @Override public Boolean extractData(ResultSet rs) { try { return rs.next() ? rs.getBoolean("subscriptionValue") : null; } catch (SQLException e) { Log.error(e.getMessage()); return null; } } }); if(isUnsubscriptedAlready != null) { updateOrInsertQuery="UPDATE PacmanSubscriptions SET emailId=?, subscriptionValue=?, modifiedDate=? WHERE emailId=?"; parameters = new Object[] {mailId, true, date, mailId}; } else { updateOrInsertQuery="INSERT INTO PacmanSubscriptions (emailId, subscriptionValue, createdDate, modifiedDate) VALUES (?,?,?,?)"; parameters = new Object[] {mailId, true, date, date}; } int status = jdbcTemplate.update(updateOrInsertQuery, parameters); Map<String, Object> response = Maps.newHashMap(); if(status==1) { response.put(STATUS, true); response.put(MESSAGE_KEY, "You have successfully subscribed"); } else { response.put(STATUS, false); response.put(MESSAGE_KEY, "Subscription Failed!!!"); } return response; }  @Override List<Map<String, Object>> getApiRoles(String serviceProject, String environment); Map<String,Object> getDeviceDetails(String deviceId); @Override List<Map<String,Object>> getAllAssetGroupOwnerEmailDetails(); @Override Map<String, Object> unsubscribeDigestMail(final String mailId); @Override Map<String, Object> subscribeDigestMail(String mailId); }
NotificationServiceImpl implements NotificationService,Constants { @Override public Map<String, Object> subscribeDigestMail(String mailId) { String sql = "SELECT subscriptionValue AS subscriptionValue FROM PacmanSubscriptions WHERE emailId = ?"; String updateOrInsertQuery ; Object[] parameters; Date date = new Date(); Boolean isUnsubscriptedAlready = jdbcTemplate.query(sql, new Object[]{mailId}, new ResultSetExtractor<Boolean>() { @Override public Boolean extractData(ResultSet rs) { try { return rs.next() ? rs.getBoolean("subscriptionValue") : null; } catch (SQLException e) { Log.error(e.getMessage()); return null; } } }); if(isUnsubscriptedAlready != null) { updateOrInsertQuery="UPDATE PacmanSubscriptions SET emailId=?, subscriptionValue=?, modifiedDate=? WHERE emailId=?"; parameters = new Object[] {mailId, true, date, mailId}; } else { updateOrInsertQuery="INSERT INTO PacmanSubscriptions (emailId, subscriptionValue, createdDate, modifiedDate) VALUES (?,?,?,?)"; parameters = new Object[] {mailId, true, date, date}; } int status = jdbcTemplate.update(updateOrInsertQuery, parameters); Map<String, Object> response = Maps.newHashMap(); if(status==1) { response.put(STATUS, true); response.put(MESSAGE_KEY, "You have successfully subscribed"); } else { response.put(STATUS, false); response.put(MESSAGE_KEY, "Subscription Failed!!!"); } return response; }  @Override List<Map<String, Object>> getApiRoles(String serviceProject, String environment); Map<String,Object> getDeviceDetails(String deviceId); @Override List<Map<String,Object>> getAllAssetGroupOwnerEmailDetails(); @Override Map<String, Object> unsubscribeDigestMail(final String mailId); @Override Map<String, Object> subscribeDigestMail(String mailId);  }