Package by.stub.javax.servlet.http

Examples of by.stub.javax.servlet.http.HttpServletResponseWithGetStatus


   public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
      ConsoleUtils.logIncomingRequest(request);

      baseRequest.setHandled(true);

      final HttpServletResponseWithGetStatus wrapper = new HttpServletResponseWithGetStatus(response);
      wrapper.setContentType(MimeTypes.TEXT_HTML_UTF_8);
      wrapper.setStatus(HttpStatus.OK_200);
      wrapper.setHeader(HttpHeaders.SERVER, HandlerUtils.constructHeaderServerName());
      wrapper.setHeader(HttpHeaders.DATE, new Date().toString());
      wrapper.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate"); // HTTP 1.1.
      wrapper.setHeader(HttpHeaders.PRAGMA, "no-cache"); // HTTP 1.0.
      wrapper.setDateHeader(HttpHeaders.EXPIRES, 0);

      final AdminResponseHandlingStrategy strategyStubResponse = AdminResponseHandlingStrategyFactory.getStrategy(request);
      try {
         strategyStubResponse.handle(request, wrapper, stubbedDataManager);
      } catch (final Exception ex) {
View Full Code Here


   @Override
   public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {

      baseRequest.setHandled(true);

      final HttpServletResponseWithGetStatus wrapper = new HttpServletResponseWithGetStatus(response);
      HandlerUtils.setResponseMainHeaders(wrapper);
      wrapper.setContentType(MimeTypes.TEXT_PLAIN_UTF_8);
      wrapper.setStatus(HttpStatus.OK_200);

      try {
         if (request.getRequestURI().contains("stats/check")) {
            wrapper.getWriter().println(!stubbedDataManager.getResourceStats().isEmpty());
         } else {
            ConsoleUtils.logIncomingRequest(request);
            final String htmlPopup = String.format(POPUP_STATS_HTML_TEMPLATE, stubbedDataManager.getResourceStatsAsCsv());
            wrapper.getWriter().println(htmlPopup);
            ConsoleUtils.logOutgoingResponse(request.getRequestURI(), wrapper);
         }
      } catch (final Exception ex) {
         HandlerUtils.configureErrorResponse(wrapper, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString());
      }
View Full Code Here

   @Test
   public void shouldVerifyBehaviourWhenHandlingRedirectResponseWithoutLatency() throws Exception {

      final PrintWriter mockPrintWriter = Mockito.mock(PrintWriter.class);
      final HttpServletResponseWithGetStatus mockHttpServletResponse = Mockito.mock(HttpServletResponseWithGetStatus.class);

      when(mockStubResponse.getStatus()).thenReturn("301");
      when(mockHttpServletResponse.getWriter()).thenReturn(mockPrintWriter);

      redirectResponseStubResponseHandlingStrategy.handle(mockHttpServletResponse, mockAssertionRequest);

      verify(mockHttpServletResponse, times(1)).setStatus(HttpStatus.MOVED_PERMANENTLY_301);
      verify(mockHttpServletResponse, times(1)).setStatus(Integer.parseInt(mockStubResponse.getStatus()));
View Full Code Here

   @Test
   public void shouldVerifyBehaviourWhenHandlingRedirectResponseWithLatency() throws Exception {

      final PrintWriter mockPrintWriter = Mockito.mock(PrintWriter.class);
      final HttpServletResponseWithGetStatus mockHttpServletResponse = Mockito.mock(HttpServletResponseWithGetStatus.class);

      when(mockStubResponse.getStatus()).thenReturn("301");
      when(mockHttpServletResponse.getWriter()).thenReturn(mockPrintWriter);
      when(mockStubResponse.getLatency()).thenReturn("100");

      redirectResponseStubResponseHandlingStrategy.handle(mockHttpServletResponse, mockAssertionRequest);

      verify(mockHttpServletResponse, times(1)).setStatus(HttpStatus.MOVED_PERMANENTLY_301);
View Full Code Here

   }

   @Test
   public void shouldVerifyBehaviourWhenHandlingDefaultResponseWithoutLatency() throws Exception {

      final HttpServletResponseWithGetStatus mockHttpServletResponse = Mockito.mock(HttpServletResponseWithGetStatus.class);

      when(mockStubResponse.getStatus()).thenReturn("200");
      when(mockStubResponse.getResponseBodyAsBytes()).thenReturn(new byte[]{});
      Mockito.when(mockHttpServletResponse.getOutputStream()).thenReturn(new ServletOutputStream() {

         @Override
         public void write(final int i) throws IOException {

         }
View Full Code Here

   }

   @Test
   public void shouldVerifyBehaviourWhenHandlingDefaultResponseWithLatency() throws Exception {

      final HttpServletResponseWithGetStatus mockHttpServletResponse = Mockito.mock(HttpServletResponseWithGetStatus.class);

      when(mockStubResponse.getStatus()).thenReturn("200");
      when(mockStubResponse.getResponseBodyAsBytes()).thenReturn(new byte[]{});
      when(mockStubResponse.getLatency()).thenReturn("100");

      Mockito.when(mockHttpServletResponse.getOutputStream()).thenReturn(new ServletOutputStream() {

         @Override
         public void write(final int i) throws IOException {

         }
View Full Code Here

   @Test
   public void shouldCheckLatencyDelayWhenHandlingDefaultResponseWithLatency() throws Exception {

      final PrintWriter mockPrintWriter = Mockito.mock(PrintWriter.class);
      final HttpServletResponseWithGetStatus mockHttpServletResponse = Mockito.mock(HttpServletResponseWithGetStatus.class);

      when(mockStubResponse.getStatus()).thenReturn("200");
      when(mockHttpServletResponse.getWriter()).thenReturn(mockPrintWriter);
      when(mockStubResponse.getResponseBodyAsBytes()).thenReturn(someResultsMessage.getBytes(StringUtils.UTF_8));
      when(mockStubResponse.getLatency()).thenReturn("100");
      Mockito.when(mockHttpServletResponse.getOutputStream()).thenReturn(new ServletOutputStream() {

         @Override
         public void write(final int i) throws IOException {

         }
View Full Code Here

      baseRequest.setHandled(true);

      final StubRequest assertionStubRequest = StubRequest.createFromHttpServletRequest(request);
      final StubResponse foundStubResponse = dataStore.findStubResponseFor(assertionStubRequest);
      final StubResponseHandlingStrategy strategyStubResponse = StubsResponseHandlingStrategyFactory.getStrategy(foundStubResponse);
      final HttpServletResponseWithGetStatus wrapper = new HttpServletResponseWithGetStatus(response);

      try {
         strategyStubResponse.handle(wrapper, assertionStubRequest);
      } catch (final Exception ex) {
         HandlerUtils.configureErrorResponse(response, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString());
View Full Code Here

      );
      ANSITerminal.incoming(logMessage);
   }

   public static void logOutgoingResponse(final HttpServletRequest request, final HttpServletResponse response, final String source) {
      final HttpServletResponseWithGetStatus wrapper = new HttpServletResponseWithGetStatus(response);

      final int status = wrapper.getStatus();

      final String logMessage = String.format("[%s] <- %s [%s]%s %s",
         getTime(),
         status,
         source,
View Full Code Here

   @Override
   public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
      ConsoleUtils.logIncomingRequest(request);

      final HttpServletResponseWithGetStatus wrapper = new HttpServletResponseWithGetStatus(response);

      baseRequest.setHandled(true);
      wrapper.setContentType(MimeTypes.TEXT_HTML_UTF_8);
      wrapper.setStatus(HttpStatus.OK_200);
      wrapper.setHeader(HttpHeaders.SERVER, HandlerUtils.constructHeaderServerName());

      try {
         wrapper.getWriter().println(getConfigDataPresentation());
      } catch (final Exception ex) {
         HandlerUtils.configureErrorResponse(wrapper, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString());
      }

      ConsoleUtils.logOutgoingResponse(request.getRequestURI(), wrapper);
View Full Code Here

TOP

Related Classes of by.stub.javax.servlet.http.HttpServletResponseWithGetStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.