コード例 #1
0
  /* Tests if service errors if the path should not be exposed.
   */
  @Test
  public final void testService_pathNotServed() throws Exception {

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletConfig config = new MockServletConfig();

    ContentModuleServlet servlet = new ContentModuleServlet(cache);
    servlet.init(config);

    request.setServletPath("/com/globant/katari/jsmodule/view/notserved/a.png");
    request.setMethod("GET");
    servlet.service(request, response);

    assertThat(response.getStatus(), is(404));
  }
コード例 #2
0
  /* Tests if service correctly dispatches the request for a bundled
   * file which was cached.
   */
  @Test
  public final void testService_bundlePathFile() throws Exception {

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletConfig config = new MockServletConfig();

    String content = "var testFunction;";
    expect(cache.findContent("md5_hash_key.js")).andReturn(content);
    replay(cache);

    ContentModuleServlet servlet = new ContentModuleServlet(cache);
    servlet.init(config);

    request.setServletPath("/com/globant/katari/jsmodule/bundle/md5_hash_key.js");
    request.setMethod("GET");
    servlet.service(request, response);

    assertThat(response.getStatus(), is(200));
    assertThat(response.getContentType(), is("text/javascript"));
    assertThat(response.getContentAsString(), is(content));

    verify(cache);
  }