@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)); }
@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\"")); }