@Test public void testExecute() { System.out.println("execute"); String requesterPhone = "000000000000"; IncomingMessage message = new IncomingMessageImpl(); String expResult = "An unexpected error occurred! Please try again."; IncomingMessageFormImpl msgForm = new IncomingMessageFormImpl(); msgForm.setMessageFormStatus(IncMessageFormStatus.VALID); IncomingMessageFormDefinitionImpl formDefn = new IncomingMessageFormDefinitionImpl(); formDefn.setType(IncMessageFormDefinitionType.ENCOUNTER); mockFormDao = createMock(IncomingMessageFormDAO.class); mockSessDao = createMock(IncomingMessageSessionDAO.class); mockRespDao = createMock(IncomingMessageResponseDAO.class); mockValidator = createMock(IncomingMessageFormValidator.class); mockFormDefDao = createMock(IncomingMessageFormDefinitionDAO.class); instance.setFormValidator(mockValidator); expect( applicationContext.getBean("incomingMessageSession", IncomingMessageSession.class) ).andReturn(new IncomingMessageSessionImpl()); expect( mockParser.getFormCode((String) anyObject()) ).andReturn("GENERAL"); expect( applicationContext.getBean("incomingMessageSessionDAO", IncomingMessageSessionDAO.class) ).andReturn(mockSessDao); expectLastCall(); expect( mockSessDao.save((IncomingMessageSession) anyObject()) ).andReturn(null); expectLastCall(); expect( applicationContext.getBean("incomingMessageFormDefinitionDAO", IncomingMessageFormDefinitionDAO.class) ).andReturn(mockFormDefDao); expect( mockFormDefDao.getByCode((String) anyObject()) ).andReturn(formDefn); expect( applicationContext.getBean("incomingMessageForm", IncomingMessageForm.class) ).andReturn(msgForm); expect( mockParser.getParams((String)anyObject()) ).andReturn(new HashMap<String,IncomingMessageFormParameter>()); expect( applicationContext.getBean("incomingMessageFormDAO", IncomingMessageFormDAO.class) ).andReturn(mockFormDao); expectLastCall(); expect( mockFormDao.save((IncomingMessageSession) anyObject()) ).andReturn(null); expectLastCall(); expect( mockValidator.validate((IncomingMessageForm)anyObject(), (String)anyObject()) ).andReturn(IncMessageFormStatus.VALID); expect( applicationContext.getBean("incomingMessageResponse", IncomingMessageResponse.class) ).andReturn(new IncomingMessageResponseImpl()); expect( applicationContext.getBean("incomingMessageResponseDAO", IncomingMessageResponseDAO.class) ).andReturn(mockRespDao); expectLastCall(); expect( mockRespDao.save((IncomingMessageResponse) anyObject()) ).andReturn(null); expectLastCall(); expect( applicationContext.getBean("incomingMessageSessionDAO", IncomingMessageSessionDAO.class) ).andReturn(mockSessDao); expectLastCall(); expect( mockSessDao.save((IncomingMessageSession) anyObject()) ).andReturn(null); expectLastCall(); replay(applicationContext, mockParser,mockSessDao,mockFormDefDao,mockFormDao, mockValidator, mockRespDao); IncomingMessageResponse result = instance.execute(message, requesterPhone); verify(applicationContext, mockParser,mockSessDao,mockFormDefDao,mockFormDao, mockValidator, mockRespDao); assertNotNull(result); assertEquals(expResult, result.getContent()); }
public IncomingMessageResponse execute(IncomingMessage message, String requesterPhone) { IncomingMessageResponse response; String wsResponse = null; logger.info("Initializing session"); IncomingMessageSession imSession = initializeSession(message, requesterPhone); logger.info("Generating form"); IncomingMessageForm form = initializeForm(message, imSession.getFormCode()); if (form == null) { response = (IncomingMessageResponse) applicationContext.getBean("incomingMessageResponse", IncomingMessageResponse.class); response.setContent("Errors: Unknown Form!\n\n'Type' parameter missing or invalid."); response.setIncomingMessage(message); response.setDateCreated(new Date()); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } else { logger.info("Validating form"); IncMessageFormStatus result = formValidator.validate(form, requesterPhone); if(result == IncMessageFormStatus.VALID) wsResponse = formProcessor.processForm(form); message.setIncomingMessageForm(form); response = prepareResponse(message, wsResponse); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } logger.info("Saving request"); message.setIncomingMessageResponse(response); message.setMessageStatus(IncMessageStatus.PROCESSED); message.setLastModified(new Date()); imSession.setDateEnded(new Date()); imSession.setMessageSessionStatus(IncMessageSessionStatus.ENDED); if(message.getIncomingMessageForm() != null && message.getIncomingMessageForm().getIncomingMsgFormParameters().containsKey(getSenderFieldName())) imSession.setRequesterPhone(message.getIncomingMessageForm().getIncomingMsgFormParameters().get(getSenderFieldName()).getValue()); IncomingMessageSessionDAO sessionDao = (IncomingMessageSessionDAO) applicationContext.getBean("incomingMessageSessionDAO", IncomingMessageSessionDAO.class); try { sessionDao.save(imSession); } catch (Exception ex) { logger.error("Error finalizing incoming message session", ex); } return response; }
FormCommandAction implements CommandAction, ApplicationContextAware { public IncomingMessageResponse execute(IncomingMessage message, String requesterPhone) { IncomingMessageResponse response; String wsResponse = null; logger.info("Initializing session"); IncomingMessageSession imSession = initializeSession(message, requesterPhone); logger.info("Generating form"); IncomingMessageForm form = initializeForm(message, imSession.getFormCode()); if (form == null) { response = (IncomingMessageResponse) applicationContext.getBean("incomingMessageResponse", IncomingMessageResponse.class); response.setContent("Errors: Unknown Form!\n\n'Type' parameter missing or invalid."); response.setIncomingMessage(message); response.setDateCreated(new Date()); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } else { logger.info("Validating form"); IncMessageFormStatus result = formValidator.validate(form, requesterPhone); if(result == IncMessageFormStatus.VALID) wsResponse = formProcessor.processForm(form); message.setIncomingMessageForm(form); response = prepareResponse(message, wsResponse); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } logger.info("Saving request"); message.setIncomingMessageResponse(response); message.setMessageStatus(IncMessageStatus.PROCESSED); message.setLastModified(new Date()); imSession.setDateEnded(new Date()); imSession.setMessageSessionStatus(IncMessageSessionStatus.ENDED); if(message.getIncomingMessageForm() != null && message.getIncomingMessageForm().getIncomingMsgFormParameters().containsKey(getSenderFieldName())) imSession.setRequesterPhone(message.getIncomingMessageForm().getIncomingMsgFormParameters().get(getSenderFieldName()).getValue()); IncomingMessageSessionDAO sessionDao = (IncomingMessageSessionDAO) applicationContext.getBean("incomingMessageSessionDAO", IncomingMessageSessionDAO.class); try { sessionDao.save(imSession); } catch (Exception ex) { logger.error("Error finalizing incoming message session", ex); } return response; } }
FormCommandAction implements CommandAction, ApplicationContextAware { public IncomingMessageResponse execute(IncomingMessage message, String requesterPhone) { IncomingMessageResponse response; String wsResponse = null; logger.info("Initializing session"); IncomingMessageSession imSession = initializeSession(message, requesterPhone); logger.info("Generating form"); IncomingMessageForm form = initializeForm(message, imSession.getFormCode()); if (form == null) { response = (IncomingMessageResponse) applicationContext.getBean("incomingMessageResponse", IncomingMessageResponse.class); response.setContent("Errors: Unknown Form!\n\n'Type' parameter missing or invalid."); response.setIncomingMessage(message); response.setDateCreated(new Date()); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } else { logger.info("Validating form"); IncMessageFormStatus result = formValidator.validate(form, requesterPhone); if(result == IncMessageFormStatus.VALID) wsResponse = formProcessor.processForm(form); message.setIncomingMessageForm(form); response = prepareResponse(message, wsResponse); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } logger.info("Saving request"); message.setIncomingMessageResponse(response); message.setMessageStatus(IncMessageStatus.PROCESSED); message.setLastModified(new Date()); imSession.setDateEnded(new Date()); imSession.setMessageSessionStatus(IncMessageSessionStatus.ENDED); if(message.getIncomingMessageForm() != null && message.getIncomingMessageForm().getIncomingMsgFormParameters().containsKey(getSenderFieldName())) imSession.setRequesterPhone(message.getIncomingMessageForm().getIncomingMsgFormParameters().get(getSenderFieldName()).getValue()); IncomingMessageSessionDAO sessionDao = (IncomingMessageSessionDAO) applicationContext.getBean("incomingMessageSessionDAO", IncomingMessageSessionDAO.class); try { sessionDao.save(imSession); } catch (Exception ex) { logger.error("Error finalizing incoming message session", ex); } return response; }  }
FormCommandAction implements CommandAction, ApplicationContextAware { public IncomingMessageResponse execute(IncomingMessage message, String requesterPhone) { IncomingMessageResponse response; String wsResponse = null; logger.info("Initializing session"); IncomingMessageSession imSession = initializeSession(message, requesterPhone); logger.info("Generating form"); IncomingMessageForm form = initializeForm(message, imSession.getFormCode()); if (form == null) { response = (IncomingMessageResponse) applicationContext.getBean("incomingMessageResponse", IncomingMessageResponse.class); response.setContent("Errors: Unknown Form!\n\n'Type' parameter missing or invalid."); response.setIncomingMessage(message); response.setDateCreated(new Date()); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } else { logger.info("Validating form"); IncMessageFormStatus result = formValidator.validate(form, requesterPhone); if(result == IncMessageFormStatus.VALID) wsResponse = formProcessor.processForm(form); message.setIncomingMessageForm(form); response = prepareResponse(message, wsResponse); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } logger.info("Saving request"); message.setIncomingMessageResponse(response); message.setMessageStatus(IncMessageStatus.PROCESSED); message.setLastModified(new Date()); imSession.setDateEnded(new Date()); imSession.setMessageSessionStatus(IncMessageSessionStatus.ENDED); if(message.getIncomingMessageForm() != null && message.getIncomingMessageForm().getIncomingMsgFormParameters().containsKey(getSenderFieldName())) imSession.setRequesterPhone(message.getIncomingMessageForm().getIncomingMsgFormParameters().get(getSenderFieldName()).getValue()); IncomingMessageSessionDAO sessionDao = (IncomingMessageSessionDAO) applicationContext.getBean("incomingMessageSessionDAO", IncomingMessageSessionDAO.class); try { sessionDao.save(imSession); } catch (Exception ex) { logger.error("Error finalizing incoming message session", ex); } return response; }  IncomingMessageResponse execute(IncomingMessage message, String requesterPhone); IncomingMessageSession initializeSession(IncomingMessage message, String requesterPhone); IncomingMessageForm initializeForm(IncomingMessage message, String formCode); IncomingMessageResponse prepareResponse(IncomingMessage message, String wsResponse); IncomingMessageParser getParser(); void setParser(IncomingMessageParser parser); IncomingMessageFormValidator getFormValidator(); void setFormValidator(IncomingMessageFormValidator formValidator); void setFormProcessor(FormProcessor formProcessor); String getSenderFieldName(); void setSenderFieldName(String senderFieldName); void setApplicationContext(ApplicationContext applicationContext); }
FormCommandAction implements CommandAction, ApplicationContextAware { public IncomingMessageResponse execute(IncomingMessage message, String requesterPhone) { IncomingMessageResponse response; String wsResponse = null; logger.info("Initializing session"); IncomingMessageSession imSession = initializeSession(message, requesterPhone); logger.info("Generating form"); IncomingMessageForm form = initializeForm(message, imSession.getFormCode()); if (form == null) { response = (IncomingMessageResponse) applicationContext.getBean("incomingMessageResponse", IncomingMessageResponse.class); response.setContent("Errors: Unknown Form!\n\n'Type' parameter missing or invalid."); response.setIncomingMessage(message); response.setDateCreated(new Date()); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } else { logger.info("Validating form"); IncMessageFormStatus result = formValidator.validate(form, requesterPhone); if(result == IncMessageFormStatus.VALID) wsResponse = formProcessor.processForm(form); message.setIncomingMessageForm(form); response = prepareResponse(message, wsResponse); response.setMessageResponseStatus(IncMessageResponseStatus.SENT); } logger.info("Saving request"); message.setIncomingMessageResponse(response); message.setMessageStatus(IncMessageStatus.PROCESSED); message.setLastModified(new Date()); imSession.setDateEnded(new Date()); imSession.setMessageSessionStatus(IncMessageSessionStatus.ENDED); if(message.getIncomingMessageForm() != null && message.getIncomingMessageForm().getIncomingMsgFormParameters().containsKey(getSenderFieldName())) imSession.setRequesterPhone(message.getIncomingMessageForm().getIncomingMsgFormParameters().get(getSenderFieldName()).getValue()); IncomingMessageSessionDAO sessionDao = (IncomingMessageSessionDAO) applicationContext.getBean("incomingMessageSessionDAO", IncomingMessageSessionDAO.class); try { sessionDao.save(imSession); } catch (Exception ex) { logger.error("Error finalizing incoming message session", ex); } return response; }  IncomingMessageResponse execute(IncomingMessage message, String requesterPhone); IncomingMessageSession initializeSession(IncomingMessage message, String requesterPhone); IncomingMessageForm initializeForm(IncomingMessage message, String formCode); IncomingMessageResponse prepareResponse(IncomingMessage message, String wsResponse); IncomingMessageParser getParser(); void setParser(IncomingMessageParser parser); IncomingMessageFormValidator getFormValidator(); void setFormValidator(IncomingMessageFormValidator formValidator); void setFormProcessor(FormProcessor formProcessor); String getSenderFieldName(); void setSenderFieldName(String senderFieldName); void setApplicationContext(ApplicationContext applicationContext);  }