Пример #1
0
  private Request mockRequest(String httpMethod, String path) {
    Request request = mock(Request.class);
    when(request.getMethod()).thenReturn(httpMethod);
    when(request.getPath()).thenReturn(path);

    return request;
  }
Пример #2
0
  @Test
  public void should304WithCorrectIfModifiedSinceHeader() throws Exception {
    String dateString = "Wed, 09 Apr 2008 23:55:38 GMT";
    SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
    Date d = format.parse(dateString);

    Asset asset = new Asset(null, "test.css", "text/css", 34, d.getTime());
    AssetLoader assetLoader = mock(AssetLoader.class);
    when(assetLoader.load("test.css")).thenReturn(asset);

    StaticMiddleware middleware = new StaticMiddleware(assetLoader, "assets");

    Request request = mockRequest("get", "/assets/test.css");
    when(request.getHeader("If-Modified-Since")).thenReturn(dateString);

    Response response = mock(Response.class);

    middleware.handle(request, response, mock(MiddlewareChain.class));
    verify(response).status(Response.NOT_MODIFIED);
  }