Пример #1
0
  @Test
  public void getTheDocumentContentExpectNotFound()
      throws DocumentNotFoundException, DocumentNotInStoreException, UnsupportedEncodingException {

    MockHttpServletResponse response = new MockHttpServletResponse();
    long expectedDocumentId = 2L;
    when(documentService.findPhysicalDocument(expectedDocumentId))
        .thenThrow(new DocumentNotFoundException(expectedDocumentId));
    controller.getDocument(expectedDocumentId, response);
    assertThat(response.getStatus(), is(SC_NOT_FOUND));
  }
Пример #2
0
  @Test
  public void getTheDocumentContentExpectNotFound3()
      throws DocumentNotFoundException, DocumentNotInStoreException, IOException {

    HttpServletResponse response = mock(HttpServletResponse.class);
    when(response.getOutputStream()).thenThrow(new IOException());
    long expectedDocumentId = 2L;
    when(documentService.findPhysicalDocument(expectedDocumentId))
        .thenReturn(new PhysicalDocument());
    controller.getDocument(expectedDocumentId, response);

    verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
  }
Пример #3
0
  @Test
  public void getTheDocumentContentCausesAccessDenied()
      throws DocumentNotFoundException, DocumentNotInStoreException, UnsupportedEncodingException {

    MockHttpServletResponse response = new MockHttpServletResponse();

    PhysicalDocument physicalDocument =
        new PhysicalDocument(new DocumentClass("hhh"), "hello".getBytes(), null, "hello.txt");
    physicalDocument.setMimeType("aaa/bbb");
    when(documentService.findPhysicalDocument(1L)).thenThrow(new AccessDeniedException("YOLO"));

    controller.getDocument(1L, response);

    assertThat(response.getStatus(), is(SC_FORBIDDEN));
  }
Пример #4
0
  @Test
  public void getTheDocumentContent()
      throws DocumentNotFoundException, DocumentNotInStoreException, UnsupportedEncodingException {

    MockHttpServletResponse response = new MockHttpServletResponse();

    PhysicalDocument physicalDocument =
        new PhysicalDocument(new DocumentClass("hhh"), "hello".getBytes(), null, "hello.txt");
    physicalDocument.setMimeType("aaa/bbb");
    when(documentService.findPhysicalDocument(1L)).thenReturn(physicalDocument);

    controller.getDocument(1L, response);

    assertThat(response.getStatus(), is(SC_OK));
    assertThat(response.getContentAsString(), is("hello"));
    assertThat(response.getContentType(), is("aaa/bbb"));
    assertThat(response.getHeader("Content-Disposition"), is("inline; filename=\"hello.txt\""));
  }