use of com.sun.jersey.spi.spring.container.servlet.SpringServlet in project pentaho-platform by pentaho.
the class JAXRSServletTest method serviceTest.
@Test
public void serviceTest() {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getMethod()).thenReturn("POST");
try {
Mockito.doNothing().when((SpringServlet) jaxrsServlet).service(request, response);
jaxrsServlet.service(request, response);
verify((SpringServlet) jaxrsServlet).service(eq(request), eq(response));
when(request.getMethod()).thenReturn(JAXRSServlet.GET);
String MIME_TYPE = "MIME_TYPE";
String NOT_MIME_TYPE = "NOT_MIME_TYPE";
when(request.getHeader(JAXRSServlet.ACCEPT)).thenReturn(NOT_MIME_TYPE);
when(request.getParameter(JAXRSServlet.MIME_TYPE)).thenReturn(null);
final AtomicBoolean fail = new AtomicBoolean(false);
checkMime(request, response, MIME_TYPE, fail);
assertFalse("Mime type was incorrectly changed", fail.get());
when(request.getParameter(JAXRSServlet.MIME_TYPE)).thenReturn(JAXRSServlet.MIME_TYPE);
checkMime(request, response, NOT_MIME_TYPE, fail);
assertFalse("Mime type was incorrectly changed", fail.get());
} catch (ServletException e) {
e.printStackTrace();
fail("ServletException appeared");
} catch (IOException e) {
e.printStackTrace();
fail("IOException appeared");
}
}
use of com.sun.jersey.spi.spring.container.servlet.SpringServlet in project pentaho-platform by pentaho.
the class JAXRSServletTest method serviceTestWriter.
@Test
public void serviceTestWriter() throws ServletException {
callSuperIterate.set(true);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ResourceConfig resourceConfig = mock(ResourceConfig.class);
String contextPath = "/context";
String servletPath = "/servlet";
StringBuffer requestUrl = new StringBuffer(contextPath + servletPath + URL);
ServletConfig servletConfig = mock(ServletConfig.class);
WebServletConfig webServletConfig = mock(WebServletConfig.class);
ServletContext servletContext = mock(ServletContext.class);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
String[] beans = {};
HashSet<Class> classes = new HashSet<>();
classes.add(ResourseClass.class);
when(request.getMethod()).thenReturn("POST");
when(request.getRequestURL()).thenReturn(requestUrl);
when(request.getRequestURI()).thenReturn(URL);
when(request.getContextPath()).thenReturn(contextPath);
when(request.getServletPath()).thenReturn(servletPath);
doReturn(webServletConfig).when(jaxrsServlet).createWebConfig(jaxrsServlet);
doReturn(servletConfig).when(jaxrsServlet).getServletConfig();
doReturn(context).when(jaxrsServlet).getContext();
doReturn(beans).when(context).getBeanNamesForType((Class<?>) any());
doReturn(Collections.emptyEnumeration()).when(webServletConfig).getInitParameterNames();
doReturn(null).when(servletContext).getAttribute("javax.enterprise.inject.spi.BeanManager");
doReturn(servletContext).when(webServletConfig).getServletContext();
doReturn(resourceConfig).when(webServletConfig).getDefaultResourceConfig(any());
doReturn(classes).when(resourceConfig).getRootResourceClasses();
doReturn(context).when(jaxrsServlet).getAppContext();
doReturn(Collections.emptyEnumeration()).when(request).getHeaderNames();
try {
jaxrsServlet.init();
jaxrsServlet.service(request, response);
verify((SpringServlet) jaxrsServlet).service(eq(request), eq(response));
verify(response).setStatus(404, "Not Found");
jaxrsServlet.setBackWardSendErrorCompatible(true);
jaxrsServlet.service(request, response);
verify(response, never()).setStatus(404);
verify(response, never()).sendError(404);
} catch (ServletException e) {
e.printStackTrace();
fail("ServletException appeared");
} catch (IOException e) {
e.printStackTrace();
fail("IOException appeared");
}
}
Aggregations