@Test public void testDoPostNormal() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(request.getInputStream()).andReturn(postContentStream); expect(request.getMethod()).andReturn(POST_METHOD); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andReturn(new HttpResponse(RESPONSE_BODY)); replay(); servlet.doPost(request, recorder); verify(); assertResponseOk(HttpResponse.SC_OK, RESPONSE_BODY); }
@Test public void testDoPostNormal() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(request.getInputStream()).andReturn(postContentStream); expect(request.getMethod()).andReturn(POST_METHOD); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andReturn(new HttpResponse(RESPONSE_BODY)); replay(); servlet.doPost(request, recorder); verify(); assertResponseOk(HttpResponse.SC_OK, RESPONSE_BODY); }
@Test public void testDoPostHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andReturn(HttpResponse.notFound()); expect(request.getMethod()).andReturn(POST_METHOD); expect(request.getInputStream()).andReturn(postContentStream); replay(); servlet.doPost(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoPostHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andReturn(HttpResponse.notFound()); expect(request.getMethod()).andReturn(POST_METHOD); expect(request.getInputStream()).andReturn(postContentStream); replay(); servlet.doPost(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoPostException() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(request.getInputStream()).andReturn(postContentStream); expect(request.getMethod()).andReturn(POST_METHOD); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doPost(request, recorder); verify(); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }
@Test public void testDoPostException() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(request.getInputStream()).andReturn(postContentStream); expect(request.getMethod()).andReturn(POST_METHOD); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doPost(request, recorder); verify(); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }