@Test public void testSendScheduledMessages() { System.out.println("sendScheduledMessages"); GatewayRequest messageDetails = new GatewayRequestImpl(); messageDetails.setDateFrom(new Date()); messageDetails.setMessage("a message for testing"); messageDetails.setDateTo(new Date()); messageDetails.setRecipientsNumber("000000000000"); messageDetails.setGatewayRequestDetails(mockGatewayRequestDetails); List<GatewayRequest> messages = new ArrayList<GatewayRequest>(); messages.add(messageDetails); expect( mockCache.getMessagesByStatusAndSchedule((MStatus) anyObject(), (Date) anyObject()) ).andReturn(messages); expect( mockWorker.sendMessage((GatewayRequest) anyObject()) ).andReturn(null); replay(mockCore, mockCache, mockWorker); instance.sendScheduledMessages(); verify(mockCore, mockCache, mockWorker); }
@Transactional(readOnly = true) public void sendScheduledMessages() { logger.info("Fetching cached GatewayRequests"); List<GatewayRequest> scheduledMessages = cache.getMessagesByStatusAndSchedule(MStatus.SCHEDULED, new Date()); if (scheduledMessages != null && scheduledMessages.size() > 0) { logger.info("Sending messages"); for (GatewayRequest message : scheduledMessages) { try { sendTransactionalMessage(message); } catch (Exception e) { logger.error("SMS message sending error: ", e); } } logger.info("Sending completed successfully"); } else { logger.info("No scheduled messages Found"); } }
SMSMessagingServiceImpl implements MobileMessagingService { @Transactional(readOnly = true) public void sendScheduledMessages() { logger.info("Fetching cached GatewayRequests"); List<GatewayRequest> scheduledMessages = cache.getMessagesByStatusAndSchedule(MStatus.SCHEDULED, new Date()); if (scheduledMessages != null && scheduledMessages.size() > 0) { logger.info("Sending messages"); for (GatewayRequest message : scheduledMessages) { try { sendTransactionalMessage(message); } catch (Exception e) { logger.error("SMS message sending error: ", e); } } logger.info("Sending completed successfully"); } else { logger.info("No scheduled messages Found"); } } }
SMSMessagingServiceImpl implements MobileMessagingService { @Transactional(readOnly = true) public void sendScheduledMessages() { logger.info("Fetching cached GatewayRequests"); List<GatewayRequest> scheduledMessages = cache.getMessagesByStatusAndSchedule(MStatus.SCHEDULED, new Date()); if (scheduledMessages != null && scheduledMessages.size() > 0) { logger.info("Sending messages"); for (GatewayRequest message : scheduledMessages) { try { sendTransactionalMessage(message); } catch (Exception e) { logger.error("SMS message sending error: ", e); } } logger.info("Sending completed successfully"); } else { logger.info("No scheduled messages Found"); } }  }
SMSMessagingServiceImpl implements MobileMessagingService { @Transactional(readOnly = true) public void sendScheduledMessages() { logger.info("Fetching cached GatewayRequests"); List<GatewayRequest> scheduledMessages = cache.getMessagesByStatusAndSchedule(MStatus.SCHEDULED, new Date()); if (scheduledMessages != null && scheduledMessages.size() > 0) { logger.info("Sending messages"); for (GatewayRequest message : scheduledMessages) { try { sendTransactionalMessage(message); } catch (Exception e) { logger.error("SMS message sending error: ", e); } } logger.info("Sending completed successfully"); } else { logger.info("No scheduled messages Found"); } }  @Transactional void scheduleMessage(GatewayRequest gatewayRequest); @Transactional void scheduleMessage(GatewayRequestDetails gatewayRequestDetails); @Transactional void scheduleTransactionalMessage(GatewayRequest gatewayRequest); @Transactional(readOnly = true) void sendScheduledMessages(); Map<Boolean, Set<GatewayResponse>> sendTransactionalMessage(GatewayRequest gatewayRequest); @Transactional Map<Boolean, Set<GatewayResponse>> sendMessage(GatewayRequest gatewayRequest); @Transactional(readOnly = true) void updateMessageStatuses(); CacheService getCache(); void setCache(CacheService cache); GatewayManager getGatewayManager(); void setGatewayManager(GatewayManager gatewayManager); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); SMSMessagingServiceWorker getWorker(); void setWorker(SMSMessagingServiceWorker worker); }
SMSMessagingServiceImpl implements MobileMessagingService { @Transactional(readOnly = true) public void sendScheduledMessages() { logger.info("Fetching cached GatewayRequests"); List<GatewayRequest> scheduledMessages = cache.getMessagesByStatusAndSchedule(MStatus.SCHEDULED, new Date()); if (scheduledMessages != null && scheduledMessages.size() > 0) { logger.info("Sending messages"); for (GatewayRequest message : scheduledMessages) { try { sendTransactionalMessage(message); } catch (Exception e) { logger.error("SMS message sending error: ", e); } } logger.info("Sending completed successfully"); } else { logger.info("No scheduled messages Found"); } }  @Transactional void scheduleMessage(GatewayRequest gatewayRequest); @Transactional void scheduleMessage(GatewayRequestDetails gatewayRequestDetails); @Transactional void scheduleTransactionalMessage(GatewayRequest gatewayRequest); @Transactional(readOnly = true) void sendScheduledMessages(); Map<Boolean, Set<GatewayResponse>> sendTransactionalMessage(GatewayRequest gatewayRequest); @Transactional Map<Boolean, Set<GatewayResponse>> sendMessage(GatewayRequest gatewayRequest); @Transactional(readOnly = true) void updateMessageStatuses(); CacheService getCache(); void setCache(CacheService cache); GatewayManager getGatewayManager(); void setGatewayManager(GatewayManager gatewayManager); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); SMSMessagingServiceWorker getWorker(); void setWorker(SMSMessagingServiceWorker worker);  }