@SuppressWarnings("unchecked") @Test public void testProcessRequest() throws DuplicateMessageException { System.out.println("processRequest"); String message = "Type=EditPatient\nCHPSID=123\nPatientRegNum=123"; String requesterPhone = "000000000000"; String expResult = "Form entry cancelled"; Map<String, CommandAction> caMap = new HashMap<String, CommandAction>(); caMap.put("TYPE", mockCmdAxn); instance.setCmdActionMap(caMap); IncomingMessage inMsg = new IncomingMessageImpl(); inMsg.setIncomingMessageForm(new IncomingMessageFormImpl()); inMsg.getIncomingMessageForm().setIncomingMsgFormDefinition(new IncomingMessageFormDefinitionImpl()); inMsg.getIncomingMessageForm().getIncomingMsgFormDefinition().setSendResponse(false); IncomingMessageResponseImpl response = new IncomingMessageResponseImpl(); response.setContent(expResult); expect(mockCore.createIncomingMessageDAO()).andReturn(mockMsgDao); expect( mockCore.createIncomingMessageResponse() ).andReturn(new IncomingMessageResponseImpl()); expect(mockRegistry.registerMessage(message)).andReturn(inMsg); expect(mockMsgDao.save(inMsg)).andReturn(inMsg); expect( mockParser.getCommand((String)anyObject()) ).andReturn("Type"); expect( mockCmdAxn.execute((IncomingMessage) anyObject(), (String) anyObject()) ).andReturn(response); replay(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); IncomingMessageResponse result = instance.processRequest(message, requesterPhone, false); verify(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); assertEquals(expResult, result.getContent()); reset(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); inMsg.setContent(message); inMsg.getIncomingMessageForm().getIncomingMsgFormDefinition().setDuplicatable(Duplicatable.DISALLOWED); inMsg.getIncomingMessageForm().setMessageFormStatus(IncMessageFormStatus.SERVER_VALID); expect(mockRegistry.registerMessage(message)).andThrow( new DuplicateMessageException()); expect( mockCore.createIncomingMessageResponse() ).andReturn(new IncomingMessageResponseImpl()); expect(mockCore.createIncomingMessageDAO()).andReturn(mockMsgDao); replay(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); result = instance.processRequest(message, requesterPhone, false); verify(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); assertEquals(instance.getFormProcessSuccess(), result.getContent()); reset(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); inMsg.setContent(message); inMsg.setMessageStatus(IncMessageStatus.PROCESSING); expect(mockRegistry.registerMessage(message)).andThrow( new DuplicateProcessingException()); expect( mockCore.createIncomingMessageResponse() ).andReturn(new IncomingMessageResponseImpl()); expect(mockCore.createIncomingMessageDAO()).andReturn(mockMsgDao); replay(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); result = instance.processRequest(message, requesterPhone, false); verify(mockParser, mockCore, mockMsgDao, mockImp, mockCmdAxn, mockRegistry); String uploadResponse = result.getContent(); assertTrue(uploadResponse.startsWith("Error:") && uploadResponse.contains("try again")); }
@SuppressWarnings("unchecked") public IncomingMessageResponse processRequest(String message, String requesterPhone, boolean isDemo) { IncomingMessageDAO<IncomingMessage> msgDao = coreManager.createIncomingMessageDAO(); IncomingMessageResponse response = coreManager.createIncomingMessageResponse(); IncomingMessage inMsg = null; try { inMsg = messageRegistry.registerMessage(message); } catch (DuplicateProcessingException dpe) { logger.info("duplicate form in process, returning wait message"); response.setContent("Error: Duplicate in progress, please try again."); return response; } catch (DuplicateMessageException e) { logger.warn("duplicate form:\n" + message); response.setContent(formProcessSuccess); return response; } msgDao.save(inMsg); String cmd = parser.getCommand(message); CommandAction action = cmdActionMap.get(cmd.toUpperCase()); if (action == null) { response.setContent("Error: Unknown Form!\nPlease check the name of the form."); return response; } response = action.execute(inMsg, requesterPhone); if (inMsg.getIncomingMessageForm() != null && inMsg.getIncomingMessageForm().getIncomingMsgFormDefinition().getSendResponse() && inMsg.getIncomingMessageForm().getMessageFormStatus() == IncMessageFormStatus.SERVER_VALID) { sendResponse(response.getContent(), response.getIncomingMessage().getIncomingMsgSession().getRequesterPhone()); } return response; }
IMPServiceImpl implements IMPService { @SuppressWarnings("unchecked") public IncomingMessageResponse processRequest(String message, String requesterPhone, boolean isDemo) { IncomingMessageDAO<IncomingMessage> msgDao = coreManager.createIncomingMessageDAO(); IncomingMessageResponse response = coreManager.createIncomingMessageResponse(); IncomingMessage inMsg = null; try { inMsg = messageRegistry.registerMessage(message); } catch (DuplicateProcessingException dpe) { logger.info("duplicate form in process, returning wait message"); response.setContent("Error: Duplicate in progress, please try again."); return response; } catch (DuplicateMessageException e) { logger.warn("duplicate form:\n" + message); response.setContent(formProcessSuccess); return response; } msgDao.save(inMsg); String cmd = parser.getCommand(message); CommandAction action = cmdActionMap.get(cmd.toUpperCase()); if (action == null) { response.setContent("Error: Unknown Form!\nPlease check the name of the form."); return response; } response = action.execute(inMsg, requesterPhone); if (inMsg.getIncomingMessageForm() != null && inMsg.getIncomingMessageForm().getIncomingMsgFormDefinition().getSendResponse() && inMsg.getIncomingMessageForm().getMessageFormStatus() == IncMessageFormStatus.SERVER_VALID) { sendResponse(response.getContent(), response.getIncomingMessage().getIncomingMsgSession().getRequesterPhone()); } return response; } }
IMPServiceImpl implements IMPService { @SuppressWarnings("unchecked") public IncomingMessageResponse processRequest(String message, String requesterPhone, boolean isDemo) { IncomingMessageDAO<IncomingMessage> msgDao = coreManager.createIncomingMessageDAO(); IncomingMessageResponse response = coreManager.createIncomingMessageResponse(); IncomingMessage inMsg = null; try { inMsg = messageRegistry.registerMessage(message); } catch (DuplicateProcessingException dpe) { logger.info("duplicate form in process, returning wait message"); response.setContent("Error: Duplicate in progress, please try again."); return response; } catch (DuplicateMessageException e) { logger.warn("duplicate form:\n" + message); response.setContent(formProcessSuccess); return response; } msgDao.save(inMsg); String cmd = parser.getCommand(message); CommandAction action = cmdActionMap.get(cmd.toUpperCase()); if (action == null) { response.setContent("Error: Unknown Form!\nPlease check the name of the form."); return response; } response = action.execute(inMsg, requesterPhone); if (inMsg.getIncomingMessageForm() != null && inMsg.getIncomingMessageForm().getIncomingMsgFormDefinition().getSendResponse() && inMsg.getIncomingMessageForm().getMessageFormStatus() == IncMessageFormStatus.SERVER_VALID) { sendResponse(response.getContent(), response.getIncomingMessage().getIncomingMsgSession().getRequesterPhone()); } return response; }  }
IMPServiceImpl implements IMPService { @SuppressWarnings("unchecked") public IncomingMessageResponse processRequest(String message, String requesterPhone, boolean isDemo) { IncomingMessageDAO<IncomingMessage> msgDao = coreManager.createIncomingMessageDAO(); IncomingMessageResponse response = coreManager.createIncomingMessageResponse(); IncomingMessage inMsg = null; try { inMsg = messageRegistry.registerMessage(message); } catch (DuplicateProcessingException dpe) { logger.info("duplicate form in process, returning wait message"); response.setContent("Error: Duplicate in progress, please try again."); return response; } catch (DuplicateMessageException e) { logger.warn("duplicate form:\n" + message); response.setContent(formProcessSuccess); return response; } msgDao.save(inMsg); String cmd = parser.getCommand(message); CommandAction action = cmdActionMap.get(cmd.toUpperCase()); if (action == null) { response.setContent("Error: Unknown Form!\nPlease check the name of the form."); return response; } response = action.execute(inMsg, requesterPhone); if (inMsg.getIncomingMessageForm() != null && inMsg.getIncomingMessageForm().getIncomingMsgFormDefinition().getSendResponse() && inMsg.getIncomingMessageForm().getMessageFormStatus() == IncMessageFormStatus.SERVER_VALID) { sendResponse(response.getContent(), response.getIncomingMessage().getIncomingMsgSession().getRequesterPhone()); } return response; }  @SuppressWarnings("unchecked") IncomingMessageResponse processRequest(String message, String requesterPhone, boolean isDemo); String processRequest(String message); ArrayList<String> processXForms(ArrayList<String> xForms); String processXForm(String xForm); String formatPhoneNumber(
            String requesterPhone); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); IncomingMessageParser getParser(); void setParser(IncomingMessageParser parser); Map<String, CommandAction> getCmdActionMap(); void setCmdActionMap(Map<String, CommandAction> cmdActionMap); IMPManager getImpManager(); void setImpManager(IMPManager impManager); IncomingMessageXMLParser getXmlParser(); void setXmlParser(IncomingMessageXMLParser xmlParser); String getFormProcessSuccess(); void setFormProcessSuccess(String formProcessSuccess); void setOmiManager(OMIManager omiManager); void setMaxConcat(int maxConcat); void setCharsPerSMS(int charsPerSMS); void setConcatAllowance(int concatAllowance); void setMaxSMS(int maxSMS); void setLocalNumberExpression(String localNumberExpression); void setDefaultCountryCode(String defaultCountryCode); void setMessageRegistry(MessageRegistry messageRegistry); }
IMPServiceImpl implements IMPService { @SuppressWarnings("unchecked") public IncomingMessageResponse processRequest(String message, String requesterPhone, boolean isDemo) { IncomingMessageDAO<IncomingMessage> msgDao = coreManager.createIncomingMessageDAO(); IncomingMessageResponse response = coreManager.createIncomingMessageResponse(); IncomingMessage inMsg = null; try { inMsg = messageRegistry.registerMessage(message); } catch (DuplicateProcessingException dpe) { logger.info("duplicate form in process, returning wait message"); response.setContent("Error: Duplicate in progress, please try again."); return response; } catch (DuplicateMessageException e) { logger.warn("duplicate form:\n" + message); response.setContent(formProcessSuccess); return response; } msgDao.save(inMsg); String cmd = parser.getCommand(message); CommandAction action = cmdActionMap.get(cmd.toUpperCase()); if (action == null) { response.setContent("Error: Unknown Form!\nPlease check the name of the form."); return response; } response = action.execute(inMsg, requesterPhone); if (inMsg.getIncomingMessageForm() != null && inMsg.getIncomingMessageForm().getIncomingMsgFormDefinition().getSendResponse() && inMsg.getIncomingMessageForm().getMessageFormStatus() == IncMessageFormStatus.SERVER_VALID) { sendResponse(response.getContent(), response.getIncomingMessage().getIncomingMsgSession().getRequesterPhone()); } return response; }  @SuppressWarnings("unchecked") IncomingMessageResponse processRequest(String message, String requesterPhone, boolean isDemo); String processRequest(String message); ArrayList<String> processXForms(ArrayList<String> xForms); String processXForm(String xForm); String formatPhoneNumber(
            String requesterPhone); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); IncomingMessageParser getParser(); void setParser(IncomingMessageParser parser); Map<String, CommandAction> getCmdActionMap(); void setCmdActionMap(Map<String, CommandAction> cmdActionMap); IMPManager getImpManager(); void setImpManager(IMPManager impManager); IncomingMessageXMLParser getXmlParser(); void setXmlParser(IncomingMessageXMLParser xmlParser); String getFormProcessSuccess(); void setFormProcessSuccess(String formProcessSuccess); void setOmiManager(OMIManager omiManager); void setMaxConcat(int maxConcat); void setCharsPerSMS(int charsPerSMS); void setConcatAllowance(int concatAllowance); void setMaxSMS(int maxSMS); void setLocalNumberExpression(String localNumberExpression); void setDefaultCountryCode(String defaultCountryCode); void setMessageRegistry(MessageRegistry messageRegistry);  }