Well, of course, you could make your field with default access, or you can add some boilerplate setter, or you could fancy whipping up a utility using reflection, but spring-test has already thought of that.
Let's say you want to test your DonkeyController:
This is how you can easily set the private field donkeyDAO, without changes in the class under test:
ReflectionTestUtils is in spring-test:
Friday, March 28, 2014
Saturday, January 25, 2014
Just a quick example of using simple username/password authentication for a Spring RestTemplate Client-> Spring MVC Rest JSON service.
The idea is:
The idea is:
- Client fires a http request using Spring's RestTemplate
- The request is intercepted on the client side by Spring's ClientHttpRequestInterceptor
- The interceptor adds authentication headers to the http request before passing it on to the server
- The server side has a javax.servlet.Filter which looks at the request headers
- If the filter finds the headers injected by the client's interceptor and the header's values are correct (username/password correct) - the filter passes the request onto the server side logic for regular processing (chain.doFilter)
- If the Filter does not find the http headers or they have incorrect values, the filter writes "Unauthorized" to the http response.