@Test public void shouldSendSeparateRequestsForEveryTenSMS() { expect(contextService.getMotechService()).andReturn(motechService); expect(motechService.getAllFacilities()).andReturn(Collections.<Facility>emptyList()); expect(motechService.getAllLanguages()).andReturn(Collections.<MessageLanguage>emptyList()); WebBulkMessage message = new WebBulkMessage(); message.setRecipients("0123456788,0123456789,0123456788,0123456789,0123456788,0123456789,0123456788,0123456789,0123456788,0123456789,0123456789"); message.setContent("Hello World"); expect(messageService.sendMessage("Hello%2BWorld", "0123456788,0123456789,0123456788,0123456789,0123456788,0123456789,0123456788,0123456789,0123456788,0123456789")).andReturn(MessageStatus.DELIVERED); expect(messageService.sendMessage("Hello%2BWorld", "0123456789")).andReturn(MessageStatus.DELIVERED); replay(messageService, contextService, motechService); ModelAndView modelAndView = controller.send(message); verify(messageService, contextService, motechService); assertEquals("/module/motechmodule/sms", modelAndView.getViewName()); WebResponse response = (WebResponse) modelAndView.getModelMap().get("response"); assertTrue(response.getSuccess()); }
@RequestMapping(value = VIEW, method = RequestMethod.POST) public ModelAndView send(@ModelAttribute WebBulkMessage bulkMessage) { String recipients = bulkMessage.getRecipients(); String[] individualRecipients = recipients.split(","); MessageStatus statusOfAllBatches = MessageStatus.REJECTED; int i = 0; for (i = 0; i < (individualRecipients.length) / 10; i++) { String[] tenRecipients = Arrays.copyOfRange(individualRecipients, i * 10 , (i * 10) + 10); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, tenRecipients); } int leftOutRecipientsStartingIndex = i * 10; String[] remainingRecipients = Arrays.copyOfRange(individualRecipients, leftOutRecipientsStartingIndex, individualRecipients.length); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, remainingRecipients); ModelAndView modelAndView = new ModelAndView(VIEW); bulkMessage.setRecipients(recipients); WebResponse response = createResponse(statusOfAllBatches, bulkMessage); modelAndView.addObject("response", response); bulkMessage.setRecipients(""); bulkMessage.setContent(""); modelAndView.addObject("bulkMessage", bulkMessage); locationSerializer.populateJavascriptMaps(modelAndView.getModelMap()); return modelAndView; }
SMSController { @RequestMapping(value = VIEW, method = RequestMethod.POST) public ModelAndView send(@ModelAttribute WebBulkMessage bulkMessage) { String recipients = bulkMessage.getRecipients(); String[] individualRecipients = recipients.split(","); MessageStatus statusOfAllBatches = MessageStatus.REJECTED; int i = 0; for (i = 0; i < (individualRecipients.length) / 10; i++) { String[] tenRecipients = Arrays.copyOfRange(individualRecipients, i * 10 , (i * 10) + 10); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, tenRecipients); } int leftOutRecipientsStartingIndex = i * 10; String[] remainingRecipients = Arrays.copyOfRange(individualRecipients, leftOutRecipientsStartingIndex, individualRecipients.length); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, remainingRecipients); ModelAndView modelAndView = new ModelAndView(VIEW); bulkMessage.setRecipients(recipients); WebResponse response = createResponse(statusOfAllBatches, bulkMessage); modelAndView.addObject("response", response); bulkMessage.setRecipients(""); bulkMessage.setContent(""); modelAndView.addObject("bulkMessage", bulkMessage); locationSerializer.populateJavascriptMaps(modelAndView.getModelMap()); return modelAndView; } }
SMSController { @RequestMapping(value = VIEW, method = RequestMethod.POST) public ModelAndView send(@ModelAttribute WebBulkMessage bulkMessage) { String recipients = bulkMessage.getRecipients(); String[] individualRecipients = recipients.split(","); MessageStatus statusOfAllBatches = MessageStatus.REJECTED; int i = 0; for (i = 0; i < (individualRecipients.length) / 10; i++) { String[] tenRecipients = Arrays.copyOfRange(individualRecipients, i * 10 , (i * 10) + 10); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, tenRecipients); } int leftOutRecipientsStartingIndex = i * 10; String[] remainingRecipients = Arrays.copyOfRange(individualRecipients, leftOutRecipientsStartingIndex, individualRecipients.length); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, remainingRecipients); ModelAndView modelAndView = new ModelAndView(VIEW); bulkMessage.setRecipients(recipients); WebResponse response = createResponse(statusOfAllBatches, bulkMessage); modelAndView.addObject("response", response); bulkMessage.setRecipients(""); bulkMessage.setContent(""); modelAndView.addObject("bulkMessage", bulkMessage); locationSerializer.populateJavascriptMaps(modelAndView.getModelMap()); return modelAndView; }  }
SMSController { @RequestMapping(value = VIEW, method = RequestMethod.POST) public ModelAndView send(@ModelAttribute WebBulkMessage bulkMessage) { String recipients = bulkMessage.getRecipients(); String[] individualRecipients = recipients.split(","); MessageStatus statusOfAllBatches = MessageStatus.REJECTED; int i = 0; for (i = 0; i < (individualRecipients.length) / 10; i++) { String[] tenRecipients = Arrays.copyOfRange(individualRecipients, i * 10 , (i * 10) + 10); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, tenRecipients); } int leftOutRecipientsStartingIndex = i * 10; String[] remainingRecipients = Arrays.copyOfRange(individualRecipients, leftOutRecipientsStartingIndex, individualRecipients.length); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, remainingRecipients); ModelAndView modelAndView = new ModelAndView(VIEW); bulkMessage.setRecipients(recipients); WebResponse response = createResponse(statusOfAllBatches, bulkMessage); modelAndView.addObject("response", response); bulkMessage.setRecipients(""); bulkMessage.setContent(""); modelAndView.addObject("bulkMessage", bulkMessage); locationSerializer.populateJavascriptMaps(modelAndView.getModelMap()); return modelAndView; }  @RequestMapping(value = VIEW, method = RequestMethod.GET) ModelAndView render(); void setLocationSerializer(JSONLocationSerializer locationSerializer); @RequestMapping(value = VIEW, method = RequestMethod.POST) ModelAndView send(@ModelAttribute WebBulkMessage bulkMessage); void setMessageService(MessageService messageService); }
SMSController { @RequestMapping(value = VIEW, method = RequestMethod.POST) public ModelAndView send(@ModelAttribute WebBulkMessage bulkMessage) { String recipients = bulkMessage.getRecipients(); String[] individualRecipients = recipients.split(","); MessageStatus statusOfAllBatches = MessageStatus.REJECTED; int i = 0; for (i = 0; i < (individualRecipients.length) / 10; i++) { String[] tenRecipients = Arrays.copyOfRange(individualRecipients, i * 10 , (i * 10) + 10); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, tenRecipients); } int leftOutRecipientsStartingIndex = i * 10; String[] remainingRecipients = Arrays.copyOfRange(individualRecipients, leftOutRecipientsStartingIndex, individualRecipients.length); statusOfAllBatches = sendMessageToAllRecipients(bulkMessage, remainingRecipients); ModelAndView modelAndView = new ModelAndView(VIEW); bulkMessage.setRecipients(recipients); WebResponse response = createResponse(statusOfAllBatches, bulkMessage); modelAndView.addObject("response", response); bulkMessage.setRecipients(""); bulkMessage.setContent(""); modelAndView.addObject("bulkMessage", bulkMessage); locationSerializer.populateJavascriptMaps(modelAndView.getModelMap()); return modelAndView; }  @RequestMapping(value = VIEW, method = RequestMethod.GET) ModelAndView render(); void setLocationSerializer(JSONLocationSerializer locationSerializer); @RequestMapping(value = VIEW, method = RequestMethod.POST) ModelAndView send(@ModelAttribute WebBulkMessage bulkMessage); void setMessageService(MessageService messageService);  }