I'm trying to mock an HTTPServletRequest data on my development GAE server. I'm running Eclipse Plugin 1.3.7
I've tried to do this:
package com.FOO.madservice.servlet.mock;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static org.mockito.Mockito.*;
@SuppressWarnings("serial")
public class BAR2ServletMock extends HttpServlet {
...
protected HttpServletRequest requestFilter(HttpServletRequest req) {
HttpServletRequest servletRequest = spy(req);
doReturn("gzip, deflate").when(servletRequest).getHeader("header-name-goes-here");
doReturn("174.30.216.4").when(servletRequest).getRemoteAddr();
return servletRequest;
}
...
}
Running the following gives exception:
java.lang.NoClassDefFoundError: sun.reflect.ReflectionFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
Any ideas on how to disable class while list checking on GAE development server or perhaps using a different mocking library that works with GAE?
Thanks, Maxim.
I doubt that you'll be able to get around this on the GAE.
The GAE is compliant with the Java Servlet Standard, so you could probably test out your program by installed a standard Java Servlet Container such as Tomcat.
Also, doesn't object mocking require reflection, by definition of "mocking"? The GAE whitelist is absolutely enforced, and you will not be able to get around it. To deploy on the app engine, there is no way to use the full reflection API (some classes are supported, however).