JEEHttpActionAdapter implements HttpActionAdapter { @Override public Object adapt(final HttpAction action, final WebContext context) { if (action != null) { int code = action.getCode(); final HttpServletResponse response = ((JEEContext) context).getNativeResponse(); if (code < 400) { response.setStatus(code); } else { try { response.sendError(code); } catch (final IOException e) { throw new TechnicalException(e); } } if (action instanceof WithLocationAction) { final WithLocationAction withLocationAction = (WithLocationAction) action; context.setResponseHeader(HttpConstants.LOCATION_HEADER, withLocationAction.getLocation()); } else if (action instanceof WithContentAction) { final WithContentAction withContentAction = (WithContentAction) action; final String content = withContentAction.getContent(); if (content != null) { try { response.getWriter().write(content); } catch (final IOException e) { throw new TechnicalException(e); } } } return null; } throw new TechnicalException("No action provided"); }  @Override Object adapt(final HttpAction action, final WebContext context); static final JEEHttpActionAdapter INSTANCE; }
@Test(expected = TechnicalException.class) public void testNullAction() { JEEHttpActionAdapter.INSTANCE.adapt(null, context); }
@Test public void testActionWithLocation() { JEEHttpActionAdapter.INSTANCE.adapt(new FoundAction(PAC4J_URL), context); verify(response).setStatus(302); verify(context).setResponseHeader(HttpConstants.LOCATION_HEADER, PAC4J_URL); }
@Test public void testError500() throws IOException { JEEHttpActionAdapter.INSTANCE.adapt(new StatusAction(500), context); verify(response).sendError(500); }
@Test public void testActionWithContent() { JEEHttpActionAdapter.INSTANCE.adapt(new OkAction(VALUE), context); verify(response).setStatus(200); verify(writer).write(VALUE); }