Note that there are some explanatory texts on larger screens.

plurals
  1. POEasyMock object for unit testing involving scope="request" bean
    primarykey
    data
    text
    <p>I am trying to add some Unit Testing to some of our companies code. Yes, I know it should already be there, but not everyone seems to have the same view of unit testing that I do.</p> <p>However, I have come against a bit of a stopper for me. Admittedly, my Java, Spring and Unit Testing knowledge are not all that they should be. My problem is this though:</p> <p>I have added a unit test to my code, which tests a class. This class includes a bean which has scope="request", and when it tries to instantiate the bean it throws an exception:</p> <p><code>java.lang.IllegalStateException: No Scope registered for scope 'request'</code></p> <p>I believe this is because I don't have a HttpServletRequest object, but I don't know how to create a mock one of these and also I don't know how, once created, to add this Mock Object to the unit test so that it resolves this problem.</p> <p>Below is a cut down version of the code involved, which I believe includes all of the details that are part of this problem.</p> <p>How can I get this to work?</p> <pre><code>@Test public void handleRequest() { try { Message&lt;?&gt; outMessage = (Message&lt;?&gt;) response.handleRequest(map); } catch (Exception e) { assertNotNull(e); } outMessage.getPayload().toString()); } public class upddResponse extends AbstractResponseTransform { @SuppressWarnings("unchecked") public Message&lt;?&gt; handleRequest(Map&lt;String, Message&lt;?&gt;&gt; messages) throws Exception { super.addEnvironmentDetails(serviceResponseDocument.getServiceResponse()); } public abstract class AbstractResponseTransform implements ResponseTransform, ApplicationContextAware { private ApplicationContext applicationContext; private MCSResponseAggregator mcsResponseAggregator; public ServiceResponseType addEnvironmentDetails(ServiceResponseType serviceResponse) throws Exception { try { mcsResponseAggregator = (MCSResponseAggregator) applicationContext .getBean("mcsResponseAggregator"); } catch (Exception ex) { } } } public interface ResponseTransform extends Transform { public Message&lt;?&gt; handleRequest(Map&lt;String, Message&lt;?&gt;&gt; messages) throws Exception; } &lt;bean id="mcsResponseAggregator" class="com.company.aggregator.MCSResponseAggregator" scope="request" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload