Exemplo n.º 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();
  }
Exemplo n.º 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();
  }