示例#1
0
  @Test
  public void editDocumentWithParams2() throws DocumentNotFoundException {

    final DocumentReference documentReference =
        newDocumentReference("hello.txt")
            .withDocumentClass("test")
            .withIndex("name", "Wangler")
            .build();

    when(documentService.findDocumentReference(1L)).thenReturn(documentReference);

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("firstname", "Silvio");
    final ModelAndView modelAndView = controller.editDocument(1L, request);

    assertThat(modelAndView.getViewName(), is("import.successful"));
    assertThat(modelAndView.getModel().size(), is(1));
    assertThat(modelAndView.getModel().containsKey("doc"), is(true));
    final DocumentReference doc = (DocumentReference) modelAndView.getModel().get("doc");
    assertThat(doc, is(documentReference));
    assertThat(
        doc.getIndices().get(new TranslatableKey("name")).getValue().toString(), is("Wangler"));

    InOrder order = inOrder(documentService);

    order.verify(documentService).findDocumentReference(1L);
    order.verify(documentService, never()).updateIndices(documentReference);
    order.verifyNoMoreInteractions();
  }
示例#2
0
  @Test
  @SuppressWarnings("unchecked")
  public void edit() throws Exception {

    final DocumentClass documentClass = new DocumentClass("hello");
    final DocumentReference documentReference =
        newDocumentReference("hello.txt").withDocumentClass(documentClass).build();

    when(documentService.findDocumentReference(1L)).thenReturn(documentReference);
    SortedSet<Attribute> attributes = new TreeSet<>();
    attributes.add(new Attribute("a", false, AttributeDataType.CURRENCY));
    attributes.add(new Attribute("b", false, AttributeDataType.STRING));
    when(documentService.findAttributes(documentClass)).thenReturn(attributes);

    final ModelAndView modelAndView = controller.editDocument(1L);

    assertThat(modelAndView.getViewName(), is("edit.doc"));
    assertThat(modelAndView.getModel().size(), is(2));
    assertThat(modelAndView.getModel().containsKey("doc"), is(true));
    assertThat((DocumentReference) modelAndView.getModel().get("doc"), is(documentReference));
    assertThat(modelAndView.getModel().containsKey("attributes"), is(true));
    assertThat(((SortedSet<Attribute>) modelAndView.getModel().get("attributes")).size(), is(2));

    InOrder order = inOrder(documentService);
    order.verify(documentService).findDocumentReference(1L);
    order.verify(documentService).findAttributes(documentReference.getDocumentClass());
    order.verifyNoMoreInteractions();
  }
示例#3
0
  @Test
  public void editDocumentWhenThrowsException() throws Exception {

    when(documentService.findDocumentReference(1L)).thenThrow(new DocumentNotFoundException(1L));

    final ModelAndView modelAndView = controller.editDocument(1L, new MockHttpServletRequest());

    assertThat(modelAndView.getViewName(), is("modification.doc.failed"));
    assertThat(modelAndView.getModel().isEmpty(), is(true));
  }
示例#4
0
  @Test
  public void editWhenThrowsException() throws Exception {

    when(documentService.findDocumentReference(1L)).thenThrow(new DocumentNotFoundException(1L));

    final ModelAndView modelAndView = controller.editDocument(1L);

    assertThat(modelAndView.getViewName(), is("edit.doc"));
    assertThat(modelAndView.getModel().isEmpty(), is(true));
  }
示例#5
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));
  }
示例#6
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);
  }
示例#7
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));
  }
示例#8
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\""));
  }
示例#9
0
  @Test
  public void editDocument() throws DocumentNotFoundException {

    final DocumentReference documentReference =
        newDocumentReference("hello.txt").withDocumentClass("test").build();

    when(documentService.findDocumentReference(1L)).thenReturn(documentReference);

    final ModelAndView modelAndView = controller.editDocument(1L, new MockHttpServletRequest());

    assertThat(modelAndView.getViewName(), is("import.successful"));
    assertThat(modelAndView.getModel().size(), is(1));
    assertThat(modelAndView.getModel().containsKey("doc"), is(true));
    assertThat((DocumentReference) modelAndView.getModel().get("doc"), is(documentReference));

    InOrder order = inOrder(documentService);

    order.verify(documentService).findDocumentReference(1L);
    order.verifyNoMoreInteractions();
  }