<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=rherrick" rel="nofollow">Rick Herrick</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-1439?redirect=false" rel="nofollow">SPR-1439</a></strong> and commented</p>
<p dir="auto">Our system is a mish-mash of various mailing systems, including sendmail, JavaMail, KanaMail, and some others.  I'd like to be able to collect all of these different message types in a list and do a batch send.  The problem is that the base MailSender.send() method takes a SimpleMailMessage class instead of the base MailMessage interface.  The problem is that I'm also submitting MimeMailMessages, which don't extend SimpleMailMessage.  So I can't just pass in a generic MailMessage object (which could be a SimpleMailMessage or a MimeMailMessage or one of the other MailMessage-derived types I've created) into send().</p>
<p dir="auto">This is obviously done because MailMessage doesn't have any getter methods and these are necessary.  I'd suggest adding the getters to the base MailMessage interface.  That lets generic sender and message code work on these base methods, while letting us develop the necessary code to support special functionality elsewhere.  So the two steps I'm suggesting are:</p>
<ol dir="auto">
<li>Add getters to MailMessage interface.</li>
<li>Change the send() methods in MailSender to take MailMessage instead of SimpleMailMessage.</li>
</ol>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398066116" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6711" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6711/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6711">#6711</a> MailSender should use interface instead of class SimpleMailMessage (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=den.orlov" rel="nofollow">Den Orlov</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5079?redirect=false" rel="nofollow">SPR-5079</a></strong> and commented</p>
<h4 dir="auto">Background</h4>
<p dir="auto">I have integration tests that:</p>
<ol dir="auto">
<li>put some test data into database using Hibernate</li>
<li>wait some time, so DB stored procedures triggered by scheduler will process my data</li>
<li>retrieve from db some data and check its correctness, again using Hibernate</li>
</ol>
<p dir="auto">When I used Spring's "JUnit 3.8 legacy support" all of these three steps were organized in one test method using the protected <code class="notranslate">endTransaction()</code> and <code class="notranslate">startNewTransaction()</code> methods in <code class="notranslate">AbstractTransactionalSpringContextTests</code> between steps <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="586320" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/1" data-hovercard-type="pull_request" data-hovercard-url="/spring-projects/spring-framework/pull/1/hovercard" href="https://github.com/spring-projects/spring-framework/pull/1">#1</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1575150" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/2" data-hovercard-type="pull_request" data-hovercard-url="/spring-projects/spring-framework/pull/2/hovercard" href="https://github.com/spring-projects/spring-framework/pull/2">#2</a>.</p>
<hr>
<h4 dir="auto">Status Quo</h4>
<p dir="auto">Now I am migrating my code to use the <em>Spring TestContext Framework</em> (TCF), but it doesn't provide support for programmatically  starting or stopping the test-managed transaction.</p>
<hr>
<h4 dir="auto">Deliverables</h4>
<p dir="auto">The term <em>test-manged</em> means a transaction managed by the TCF, either declaratively or programmatically.</p>
<p dir="auto">See also "<em>Design Considerations</em>" below.</p>
<ol class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Introduce a mechanism in the TCF that supports the following features:
<ol class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> end the current test-managed transaction</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> start a new test-managed transaction</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> configure the current test-managed transaction to be <em>committed</em> once the test completes</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> configure the current test-managed transaction to be <em>rolled back</em> once the test completes</li>
</ol>
</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Refactor <code class="notranslate">TransactionalTestExecutionListener</code> to use this new mechanism internally.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Consider introducing a JUnit <code class="notranslate">TestRule</code> that simplifies the programming model (e.g., by delegating to the proposed <code class="notranslate">TestTransaction</code> façade).</li>
</ol>
<hr>
<h4 dir="auto">Design Considerations</h4>
<p dir="auto">Introduce a <code class="notranslate">TestTransaction</code> class that acts as a <em>façade</em> to the functionality previously available in <code class="notranslate">TransactionalTestExecutionListener</code>. For example, <code class="notranslate">TestTransaction</code> could define methods that could provide the following API:</p>
<ul dir="auto">
<li><code class="notranslate">TestTransaction.start()</code></li>
<li><code class="notranslate">TestTransaction.end()</code></li>
<li><code class="notranslate">TestTransaction.rollback(boolean)</code></li>
</ul>
<h5 dir="auto">Options for Interacting with the Test Transaction</h5>
<h6 dir="auto">Dependency Injection of TestTransaction</h6>
<p dir="auto">Ideally, we would like to be able to have the <code class="notranslate">TestTransaction</code> injected into our test instance. However, since the <code class="notranslate">DependencyInjectionTestExecutionListener</code> must come before the <code class="notranslate">TransactionalTestExecutionListener</code> in the chain of listeners, dependency injection would only be possible by introducing yet another "transactional" <code class="notranslate">TestExecutionListener</code> that creates a proxy bean or bean of type <code class="notranslate">ObjectFactory</code> in the <code class="notranslate">ApplicationContext</code>. Such a <em>proxy</em> bean would serve as a placeholder for dependency injection into the test instance, and the <code class="notranslate">TransactionalTestExecutionListener</code> could later set a value either directly in the proxy/<code class="notranslate">ObjectFactory</code> or via a <code class="notranslate">ThreadLocal</code>.</p>
<p dir="auto">But we would like to avoid having two (2) <code class="notranslate">TestExecutionListener</code> implementations for transactional support. Plus, the placeholder-bean approach could present more problems than it solves.</p>
<h6 dir="auto">Dependency Injection of TestContext</h6>
<p dir="auto">A second option would be to inject the <code class="notranslate">TestContext</code> into test instances (see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112117" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12947" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12947/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12947">#12947</a>) and provide access to the <code class="notranslate">TestTransaction</code> as an attribute (note that <code class="notranslate">TestContext</code> implements <code class="notranslate">AttributeAccessor</code>), but this would open up use of the <code class="notranslate">TestContext</code> within test classes (i.e., no longer limited to the <code class="notranslate">TestExecutionListener</code> API). In addition, developers would be forced to navigate the <code class="notranslate">TestContext</code> to obtain the <code class="notranslate">TestTransaction</code>, thus making the programming model less intuitive.</p>
<h6 dir="auto">Purely ThreadLocal Approach</h6>
<p dir="auto">The final option is to follow a purely <code class="notranslate">ThreadLocal</code>-based approach with <code class="notranslate">TestTransaction</code> encapsulating the details and providing static methods instead of instance methods.</p>
<hr>
<h4 dir="auto">Related Resources</h4>
<ul dir="auto">
<li><a href="http://springframework.cvs.sourceforge.net/viewvc/springframework/spring/tiger/mock/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java?r1=1.11&amp;r2=1.12" rel="nofollow">Diff for TransactionalTestExecutionListener</a>. This commit introduced caching of the <code class="notranslate">TransactionContext</code> keyed by <code class="notranslate">Method</code> and removed the previous support for the <code class="notranslate">transactionFlaggedForCommit</code> functionality.
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398086830" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9315" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9315/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9315">#9315</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398086086" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9218" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9218/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9218">#9218</a></li>
</ul>
</li>
</ul>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.6</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398169541" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/16558" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/16558/hovercard" href="https://github.com/spring-projects/spring-framework/issues/16558">#16558</a> Document programmatic test transaction management support (<em><strong>"is depended on by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398095939" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10548" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10548/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10548">#10548</a> Provide support in TestContext framework equivalent to AbstractTransactionalSpringContextTests (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398086830" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9315" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9315/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9315">#9315</a> TransactionalTestExecutionListener uses cached TransactionManager (TM), even after ApplicationContext that created the TM has been marked 'dirty' and closed.</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112117" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12947" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12947/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12947">#12947</a> Introduce autowiring support for the current TestContext</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398086086" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9218" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9218/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9218">#9218</a> Transactional JUnit test with timeout does not create a transaction</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/bdceaa481bfeff2785676ada7b75d03635c19a0d/hovercard" href="https://github.com/spring-projects/spring-framework/commit/bdceaa481bfeff2785676ada7b75d03635c19a0d"><tt>bdceaa4</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/f667e43ca2fc3ffdc4f80fa604fb798b22b64dad/hovercard" href="https://github.com/spring-projects/spring-framework/commit/f667e43ca2fc3ffdc4f80fa604fb798b22b64dad"><tt>f667e43</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/90f0d14c8e441d52b5a5cb2c56c15e4d57592065/hovercard" href="https://github.com/spring-projects/spring-framework/commit/90f0d14c8e441d52b5a5cb2c56c15e4d57592065"><tt>90f0d14</tt></a></p>
<p dir="auto">30 votes, 22 watchers</p>