@Test public void testExecute() throws MessagingException, IOException { final Map data = mockery.mock(Map.class); final TransactionStatus transaction = mockery.mock(TransactionStatus.class); final States state = mockery.states("trans").startsAs("none"); final String content = "This is the content"; final Serializable params = mockery.mock(Serializable.class, "params"); final UserActionRequest selection = new UserActionRequest(ACTION_NAME, null, params); mockery.checking(new Expectations() { { allowing(message).getFrom(); will(returnValue(new Address[] { new InternetAddress(SENDER_ADDRESS) })); allowing(message).getRecipients(RecipientType.TO); will(returnValue(new Address[] { new InternetAddress("system+" + TOKEN + AT_DOMAIN) })); allowing(tokenEncoder).couldBeToken(TOKEN); will(returnValue(true)); oneOf(transactionMgr).getTransaction(with(any(TransactionDefinition.class))); when(state.is("none")); will(returnValue(transaction)); then(state.is("in")); allowing(personIdByEmailDao).execute(SENDER_ADDRESS); when(state.is("in")); will(returnValue(PERSON_ID)); allowing(userKeyByIdDao).execute(PERSON_ID); when(state.is("in")); will(returnValue(KEY)); allowing(personDao).execute(PERSON_ID); when(state.is("in")); will(returnValue(person)); oneOf(transactionMgr).commit(transaction); when(state.is("in")); then(state.is("none")); oneOf(tokenEncoder).decode(TOKEN, KEY); will(returnValue(TOKEN_CONTENT)); oneOf(tokenContentFormatter).parse(TOKEN_CONTENT); will(returnValue(data)); allowing(messageContentExtractor).extract(message); will(returnValue(content)); oneOf(actionSelector).select(data, content, person); will(returnValue(selection)); allowing(beanFactory).getBean(ACTION_NAME); will(returnValue(serviceAction)); oneOf(serviceActionController).execute(with(new EasyMatcher<ServiceActionContext>() { @Override protected boolean isMatch(final ServiceActionContext inTestObject) { return ACTION_NAME.equals(inTestObject.getActionId()) && params == inTestObject.getParams(); } }), with(same(serviceAction))); } }); boolean result = sut.execute(message, responseMessages); mockery.assertIsSatisfied(); assertTrue(result); }
public boolean execute(final Message message, final List<Message> inResponseMessages) throws MessagingException, IOException { String token = getToken(message); if (token == null) { return false; } String fromAddress = getFromAddress(message); DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("TokenAddressMessageAuthenticator"); transDef.setReadOnly(false); TransactionStatus transStatus = transactionMgr.getTransaction(transDef); byte[] key; Long personId; PersonModelView person; try { personId = personIdByEmailDao.execute(fromAddress); key = userKeyByIdDao.execute(personId); person = personDao.execute(personId); } finally { transactionMgr.commit(transStatus); } Map<String, Long> tokenData = getTokenData(token, key); String content = messageContentExtractor.extract(message); UserActionRequest actionSelection = actionSelector.select(tokenData, content, person); executeAction(message, actionSelection, person, inResponseMessages); return true; }
MessageProcessor { public boolean execute(final Message message, final List<Message> inResponseMessages) throws MessagingException, IOException { String token = getToken(message); if (token == null) { return false; } String fromAddress = getFromAddress(message); DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("TokenAddressMessageAuthenticator"); transDef.setReadOnly(false); TransactionStatus transStatus = transactionMgr.getTransaction(transDef); byte[] key; Long personId; PersonModelView person; try { personId = personIdByEmailDao.execute(fromAddress); key = userKeyByIdDao.execute(personId); person = personDao.execute(personId); } finally { transactionMgr.commit(transStatus); } Map<String, Long> tokenData = getTokenData(token, key); String content = messageContentExtractor.extract(message); UserActionRequest actionSelection = actionSelector.select(tokenData, content, person); executeAction(message, actionSelection, person, inResponseMessages); return true; } }
MessageProcessor { public boolean execute(final Message message, final List<Message> inResponseMessages) throws MessagingException, IOException { String token = getToken(message); if (token == null) { return false; } String fromAddress = getFromAddress(message); DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("TokenAddressMessageAuthenticator"); transDef.setReadOnly(false); TransactionStatus transStatus = transactionMgr.getTransaction(transDef); byte[] key; Long personId; PersonModelView person; try { personId = personIdByEmailDao.execute(fromAddress); key = userKeyByIdDao.execute(personId); person = personDao.execute(personId); } finally { transactionMgr.commit(transStatus); } Map<String, Long> tokenData = getTokenData(token, key); String content = messageContentExtractor.extract(message); UserActionRequest actionSelection = actionSelector.select(tokenData, content, person); executeAction(message, actionSelection, person, inResponseMessages); return true; } MessageProcessor(final MessageContentExtractor inMessageContentExtractor,
            final ActionSelectorFactory inActionSelector, final ActionController inServiceActionController,
            final BeanFactory inBeanFactory, final TokenEncoder inTokenEncoder,
            final TokenContentFormatter inTokenContentFormatter, final PlatformTransactionManager inTransactionMgr,
            final DomainMapper<String, Long> inPersonIdByEmailDao, final DomainMapper<Long, byte[]> inUserKeyByIdDao,
            final DomainMapper<Long, PersonModelView> inPersonDao, final MessageReplier inMessageReplier,
            final String inRequiredToAddress); }
MessageProcessor { public boolean execute(final Message message, final List<Message> inResponseMessages) throws MessagingException, IOException { String token = getToken(message); if (token == null) { return false; } String fromAddress = getFromAddress(message); DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("TokenAddressMessageAuthenticator"); transDef.setReadOnly(false); TransactionStatus transStatus = transactionMgr.getTransaction(transDef); byte[] key; Long personId; PersonModelView person; try { personId = personIdByEmailDao.execute(fromAddress); key = userKeyByIdDao.execute(personId); person = personDao.execute(personId); } finally { transactionMgr.commit(transStatus); } Map<String, Long> tokenData = getTokenData(token, key); String content = messageContentExtractor.extract(message); UserActionRequest actionSelection = actionSelector.select(tokenData, content, person); executeAction(message, actionSelection, person, inResponseMessages); return true; } MessageProcessor(final MessageContentExtractor inMessageContentExtractor,
            final ActionSelectorFactory inActionSelector, final ActionController inServiceActionController,
            final BeanFactory inBeanFactory, final TokenEncoder inTokenEncoder,
            final TokenContentFormatter inTokenContentFormatter, final PlatformTransactionManager inTransactionMgr,
            final DomainMapper<String, Long> inPersonIdByEmailDao, final DomainMapper<Long, byte[]> inUserKeyByIdDao,
            final DomainMapper<Long, PersonModelView> inPersonDao, final MessageReplier inMessageReplier,
            final String inRequiredToAddress); boolean execute(final Message message, final List<Message> inResponseMessages); }
MessageProcessor { public boolean execute(final Message message, final List<Message> inResponseMessages) throws MessagingException, IOException { String token = getToken(message); if (token == null) { return false; } String fromAddress = getFromAddress(message); DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("TokenAddressMessageAuthenticator"); transDef.setReadOnly(false); TransactionStatus transStatus = transactionMgr.getTransaction(transDef); byte[] key; Long personId; PersonModelView person; try { personId = personIdByEmailDao.execute(fromAddress); key = userKeyByIdDao.execute(personId); person = personDao.execute(personId); } finally { transactionMgr.commit(transStatus); } Map<String, Long> tokenData = getTokenData(token, key); String content = messageContentExtractor.extract(message); UserActionRequest actionSelection = actionSelector.select(tokenData, content, person); executeAction(message, actionSelection, person, inResponseMessages); return true; } MessageProcessor(final MessageContentExtractor inMessageContentExtractor,
            final ActionSelectorFactory inActionSelector, final ActionController inServiceActionController,
            final BeanFactory inBeanFactory, final TokenEncoder inTokenEncoder,
            final TokenContentFormatter inTokenContentFormatter, final PlatformTransactionManager inTransactionMgr,
            final DomainMapper<String, Long> inPersonIdByEmailDao, final DomainMapper<Long, byte[]> inUserKeyByIdDao,
            final DomainMapper<Long, PersonModelView> inPersonDao, final MessageReplier inMessageReplier,
            final String inRequiredToAddress); boolean execute(final Message message, final List<Message> inResponseMessages);  }