@Test public void testSendMessage(){ System.out.println("sendMessage"); MessageRequest msgReq1 = new MessageRequestImpl(); msgReq1.setDateFrom(new Date()); msgReq1.setDateTo(new Date()); msgReq1.setId(19000000001l); msgReq1.setTryNumber(1); msgReq1.setMessageType(MessageType.TEXT); msgReq1.setRecipientName("Tester"); msgReq1.setRecipientNumber("000000000000"); msgReq1.setStatus(MStatus.QUEUED); GatewayRequestImpl gwReq = new GatewayRequestImpl(); gwReq.setGatewayRequestDetails(new GatewayRequestDetailsImpl()); HashMap<Boolean, Set<GatewayResponse>> respMap = new HashMap<Boolean, Set<GatewayResponse>>(); respMap.put(new Boolean(true), new HashSet<GatewayResponse>()); expect( mockCore.createLanguageDAO() ).andReturn(mockLangDao); expect( mockLangDao.getByCode((String) anyObject()) ).andReturn(new LanguageImpl()); expect( mockCore.createMessageRequestDAO() ).andReturn(mockRequestDao); expectLastCall(); expect( mockRequestDao.save((MessageRequest) anyObject()) ).andReturn(new MessageRequestImpl()); expect( mockStore.constructMessage((MessageRequest) anyObject(), (Language) anyObject()) ).andReturn(gwReq); expect( mockOMP.createMessagingService() ).andReturn(mockMobileMessagingService); expect( mockMobileMessagingService.sendMessage((GatewayRequest) anyObject() ) ).andReturn(respMap); expectLastCall(); expect( mockRequestDao.save((MessageRequest) anyObject()) ).andReturn(new MessageRequestImpl()); expectLastCall(); replay(mockStore, mockOMP, mockMobileMessagingService, mockCore, mockRequestDao); instance.sendMessage(msgReq1); verify(mockStore, mockOMP, mockMobileMessagingService, mockCore, mockRequestDao); }
public MessageStatus sendMessage(MessageRequest message) { if ((message.getRecipientNumber() == null || message.getRecipientNumber().isEmpty()) && !ContactNumberType.PUBLIC.toString().equals(message.getPhoneNumberType())) { return MessageStatus.REJECTED; } Language defaultLanguage = coreManager.createLanguageDAO().getByCode(defaultLang); if (message.getLanguage() == null) { message.setLanguage(defaultLanguage); } MessageRequestDAO messageRequestDAO = coreManager.createMessageRequestDAO(); message.setStatus(MStatus.QUEUED); messageRequestDAO.save(message); logger.debug("Constructing GatewayRequest..."); GatewayRequest gwReq = storeManager.constructMessage(message, defaultLanguage); message.setGatewayRequestDetails(null); logger.debug("Initializing OMP MobileMessagingService..."); MobileMessagingService msgSvc = ompManager.createMessagingService(); logger.info("Sending GatewayRequest..."); Map<Boolean, Set<GatewayResponse>> responses = msgSvc.sendMessage(gwReq); Boolean falseBool = false; if (responses.containsKey(falseBool)) { Set<GatewayResponse> resps = responses.get(falseBool); for (GatewayResponse gp : resps) { statHandler.handleStatus(gp); } } logger.info("Updating MessageRequest..."); message.setGatewayRequestDetails(gwReq.getGatewayRequestDetails()); message.setDateProcessed(new Date()); message.setStatus(MStatus.PENDING); logger.debug(message); messageRequestDAO.save(message); logger.info("Messages sent successfully"); return MessageStatus.valueOf(message.getStatus().toString()); }
OMIServiceImpl implements OMIService { public MessageStatus sendMessage(MessageRequest message) { if ((message.getRecipientNumber() == null || message.getRecipientNumber().isEmpty()) && !ContactNumberType.PUBLIC.toString().equals(message.getPhoneNumberType())) { return MessageStatus.REJECTED; } Language defaultLanguage = coreManager.createLanguageDAO().getByCode(defaultLang); if (message.getLanguage() == null) { message.setLanguage(defaultLanguage); } MessageRequestDAO messageRequestDAO = coreManager.createMessageRequestDAO(); message.setStatus(MStatus.QUEUED); messageRequestDAO.save(message); logger.debug("Constructing GatewayRequest..."); GatewayRequest gwReq = storeManager.constructMessage(message, defaultLanguage); message.setGatewayRequestDetails(null); logger.debug("Initializing OMP MobileMessagingService..."); MobileMessagingService msgSvc = ompManager.createMessagingService(); logger.info("Sending GatewayRequest..."); Map<Boolean, Set<GatewayResponse>> responses = msgSvc.sendMessage(gwReq); Boolean falseBool = false; if (responses.containsKey(falseBool)) { Set<GatewayResponse> resps = responses.get(falseBool); for (GatewayResponse gp : resps) { statHandler.handleStatus(gp); } } logger.info("Updating MessageRequest..."); message.setGatewayRequestDetails(gwReq.getGatewayRequestDetails()); message.setDateProcessed(new Date()); message.setStatus(MStatus.PENDING); logger.debug(message); messageRequestDAO.save(message); logger.info("Messages sent successfully"); return MessageStatus.valueOf(message.getStatus().toString()); } }
OMIServiceImpl implements OMIService { public MessageStatus sendMessage(MessageRequest message) { if ((message.getRecipientNumber() == null || message.getRecipientNumber().isEmpty()) && !ContactNumberType.PUBLIC.toString().equals(message.getPhoneNumberType())) { return MessageStatus.REJECTED; } Language defaultLanguage = coreManager.createLanguageDAO().getByCode(defaultLang); if (message.getLanguage() == null) { message.setLanguage(defaultLanguage); } MessageRequestDAO messageRequestDAO = coreManager.createMessageRequestDAO(); message.setStatus(MStatus.QUEUED); messageRequestDAO.save(message); logger.debug("Constructing GatewayRequest..."); GatewayRequest gwReq = storeManager.constructMessage(message, defaultLanguage); message.setGatewayRequestDetails(null); logger.debug("Initializing OMP MobileMessagingService..."); MobileMessagingService msgSvc = ompManager.createMessagingService(); logger.info("Sending GatewayRequest..."); Map<Boolean, Set<GatewayResponse>> responses = msgSvc.sendMessage(gwReq); Boolean falseBool = false; if (responses.containsKey(falseBool)) { Set<GatewayResponse> resps = responses.get(falseBool); for (GatewayResponse gp : resps) { statHandler.handleStatus(gp); } } logger.info("Updating MessageRequest..."); message.setGatewayRequestDetails(gwReq.getGatewayRequestDetails()); message.setDateProcessed(new Date()); message.setStatus(MStatus.PENDING); logger.debug(message); messageRequestDAO.save(message); logger.info("Messages sent successfully"); return MessageStatus.valueOf(message.getStatus().toString()); } OMIServiceImpl(); }
OMIServiceImpl implements OMIService { public MessageStatus sendMessage(MessageRequest message) { if ((message.getRecipientNumber() == null || message.getRecipientNumber().isEmpty()) && !ContactNumberType.PUBLIC.toString().equals(message.getPhoneNumberType())) { return MessageStatus.REJECTED; } Language defaultLanguage = coreManager.createLanguageDAO().getByCode(defaultLang); if (message.getLanguage() == null) { message.setLanguage(defaultLanguage); } MessageRequestDAO messageRequestDAO = coreManager.createMessageRequestDAO(); message.setStatus(MStatus.QUEUED); messageRequestDAO.save(message); logger.debug("Constructing GatewayRequest..."); GatewayRequest gwReq = storeManager.constructMessage(message, defaultLanguage); message.setGatewayRequestDetails(null); logger.debug("Initializing OMP MobileMessagingService..."); MobileMessagingService msgSvc = ompManager.createMessagingService(); logger.info("Sending GatewayRequest..."); Map<Boolean, Set<GatewayResponse>> responses = msgSvc.sendMessage(gwReq); Boolean falseBool = false; if (responses.containsKey(falseBool)) { Set<GatewayResponse> resps = responses.get(falseBool); for (GatewayResponse gp : resps) { statHandler.handleStatus(gp); } } logger.info("Updating MessageRequest..."); message.setGatewayRequestDetails(gwReq.getGatewayRequestDetails()); message.setDateProcessed(new Date()); message.setStatus(MStatus.PENDING); logger.debug(message); messageRequestDAO.save(message); logger.info("Messages sent successfully"); return MessageStatus.valueOf(message.getStatus().toString()); } OMIServiceImpl(); MessageStatus savePatientMessageRequest(String messageId,
                                                   NameValuePair[] personalInfo,
                                                   String patientNumber,
                                                   ContactNumberType patientNumberType,
                                                   String langCode,
                                                   MediaType mediaType,
                                                   Long notificationType,
                                                   Date startDate,
                                                   Date endDate,
                                                   String recipientId); MessageStatus saveCHPSMessageRequest(String messageId, NameValuePair[] personalInfo, String workerNumber, Patient[] patientList, String langCode, MediaType messageType, Long notificationType, Date startDate, Date endDate); MessageStatus sendMessage(MessageRequest message); MessageStatus sendMessage(MessageRequest message, String content); MessageStatus sendMessage(String content, String recipient); MessageStatus scheduleMessage(String content, String recipient); MessageStatus scheduleMessage(MessageRequest message, String content); MessageStatus sendDefaulterMessage(String messageId, String workerNumber, Care[] cares,
                                              CareMessageGroupingStrategy groupingStrategy,
                                              MediaType messageType, Date startDate, Date endDate); MessageStatus sendDeliveriesMessage(String messageId, String workerNumber, Patient[] patients, String deliveryStatus, MediaType messageType, Date startDate, Date endDate); MessageStatus sendUpcomingCaresMessage(String messageId, String workerNumber, Patient patient, MediaType messageType, Date startDate, Date endDate); MessageStatus sendBulkCaresMessage(String messageId, String workerNumber, Care[] cares,
                                              CareMessageGroupingStrategy groupingStrategy,
                                              MediaType messageType, Date startDate, Date endDate); @Transactional(readOnly = true) void processMessageRequests(); void processMessageRequest(MessageRequest message, Language defaultLanguage); @Transactional(readOnly = true) void processMessageRetries(); void processMessageRetry(MessageRequest message); @Transactional(readOnly = true) void processMessageResponses(); void processMessageResponse(GatewayResponse response); MessageStoreManager getStoreManager(); void setStoreManager(MessageStoreManager storeManager); OMPManager getOmpManager(); void setOmpManager(OMPManager ompManager); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); StatusHandler getStatHandler(); void setStatHandler(StatusHandler statHandler); String getDefaultLang(); void setDefaultLang(String defaultLang); int getMaxTries(); void setMaxTries(int maxRetries); void setOmiManager(OMIManager omiManager); OMIServiceWorker getWorker(); void setWorker(OMIServiceWorker worker); }
OMIServiceImpl implements OMIService { public MessageStatus sendMessage(MessageRequest message) { if ((message.getRecipientNumber() == null || message.getRecipientNumber().isEmpty()) && !ContactNumberType.PUBLIC.toString().equals(message.getPhoneNumberType())) { return MessageStatus.REJECTED; } Language defaultLanguage = coreManager.createLanguageDAO().getByCode(defaultLang); if (message.getLanguage() == null) { message.setLanguage(defaultLanguage); } MessageRequestDAO messageRequestDAO = coreManager.createMessageRequestDAO(); message.setStatus(MStatus.QUEUED); messageRequestDAO.save(message); logger.debug("Constructing GatewayRequest..."); GatewayRequest gwReq = storeManager.constructMessage(message, defaultLanguage); message.setGatewayRequestDetails(null); logger.debug("Initializing OMP MobileMessagingService..."); MobileMessagingService msgSvc = ompManager.createMessagingService(); logger.info("Sending GatewayRequest..."); Map<Boolean, Set<GatewayResponse>> responses = msgSvc.sendMessage(gwReq); Boolean falseBool = false; if (responses.containsKey(falseBool)) { Set<GatewayResponse> resps = responses.get(falseBool); for (GatewayResponse gp : resps) { statHandler.handleStatus(gp); } } logger.info("Updating MessageRequest..."); message.setGatewayRequestDetails(gwReq.getGatewayRequestDetails()); message.setDateProcessed(new Date()); message.setStatus(MStatus.PENDING); logger.debug(message); messageRequestDAO.save(message); logger.info("Messages sent successfully"); return MessageStatus.valueOf(message.getStatus().toString()); } OMIServiceImpl(); MessageStatus savePatientMessageRequest(String messageId,
                                                   NameValuePair[] personalInfo,
                                                   String patientNumber,
                                                   ContactNumberType patientNumberType,
                                                   String langCode,
                                                   MediaType mediaType,
                                                   Long notificationType,
                                                   Date startDate,
                                                   Date endDate,
                                                   String recipientId); MessageStatus saveCHPSMessageRequest(String messageId, NameValuePair[] personalInfo, String workerNumber, Patient[] patientList, String langCode, MediaType messageType, Long notificationType, Date startDate, Date endDate); MessageStatus sendMessage(MessageRequest message); MessageStatus sendMessage(MessageRequest message, String content); MessageStatus sendMessage(String content, String recipient); MessageStatus scheduleMessage(String content, String recipient); MessageStatus scheduleMessage(MessageRequest message, String content); MessageStatus sendDefaulterMessage(String messageId, String workerNumber, Care[] cares,
                                              CareMessageGroupingStrategy groupingStrategy,
                                              MediaType messageType, Date startDate, Date endDate); MessageStatus sendDeliveriesMessage(String messageId, String workerNumber, Patient[] patients, String deliveryStatus, MediaType messageType, Date startDate, Date endDate); MessageStatus sendUpcomingCaresMessage(String messageId, String workerNumber, Patient patient, MediaType messageType, Date startDate, Date endDate); MessageStatus sendBulkCaresMessage(String messageId, String workerNumber, Care[] cares,
                                              CareMessageGroupingStrategy groupingStrategy,
                                              MediaType messageType, Date startDate, Date endDate); @Transactional(readOnly = true) void processMessageRequests(); void processMessageRequest(MessageRequest message, Language defaultLanguage); @Transactional(readOnly = true) void processMessageRetries(); void processMessageRetry(MessageRequest message); @Transactional(readOnly = true) void processMessageResponses(); void processMessageResponse(GatewayResponse response); MessageStoreManager getStoreManager(); void setStoreManager(MessageStoreManager storeManager); OMPManager getOmpManager(); void setOmpManager(OMPManager ompManager); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); StatusHandler getStatHandler(); void setStatHandler(StatusHandler statHandler); String getDefaultLang(); void setDefaultLang(String defaultLang); int getMaxTries(); void setMaxTries(int maxRetries); void setOmiManager(OMIManager omiManager); OMIServiceWorker getWorker(); void setWorker(OMIServiceWorker worker);  }