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();
  }
 public void open(File file) {
   try {
     ShapeResolver resolver = importer.importJson(file);
     ShapeResolver resolverWithoutGateways = resolver.clone();
     importer.removeGatewaysFrom(resolverWithoutGateways);
     DirectedGraph<String, String> graph = importer.buildGraph(resolver);
     DirectedGraph<String, String> graphWithoutGateways =
         importer.buildGraph(resolverWithoutGateways);
     System.out.println(graphWithoutGateways);
     DocumentController controller = new DocumentController();
     Container component = controller.getView();
     mainFrame.addTab("Titel einf�gen", component);
     DYNOEvent dynoEvent =
         new DYNOEvent(resolver, resolverWithoutGateways, graph, graphWithoutGateways, component);
     manager.documentOpened(dynoEvent);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 4
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));
  }
Exemplo n.º 5
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));
  }
Exemplo n.º 6
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));
  }
Exemplo n.º 7
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);
  }
Exemplo n.º 8
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));
  }
Exemplo n.º 9
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\""));
  }
Exemplo n.º 10
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();
  }
  /**
   * Displays the Create Discussion page for a HTTP Get, or creates a Discussion Thread for a HTTP
   * Post
   *
   * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET -
   * Requires a groupId and threadName request parameter for a POST - Requires a document request
   * part for a POST
   *
   * @param req The HTTP Request
   * @param res The HTTP Response
   */
  public void createDiscussionAction(HttpServletRequest req, HttpServletResponse res) {
    // Ensure there is a cookie for the session user
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<>();

    if (req.getMethod() == HttpMethod.Get) {
      viewData.put("title", "Create Discussion");
      viewData.put("groupId", req.getParameter("groupId"));

      view(req, res, "/views/group/CreateDiscussion.jsp", viewData);
      return;
    } else if (req.getMethod() == HttpMethod.Post) {
      // save discussion
      GroupManager groupMan = new GroupManager();
      DiscussionThread thread = new DiscussionThread();
      int groupId = Integer.parseInt(req.getParameter("groupId"));
      thread.setGroupId(groupId);
      thread.setGroup(groupMan.get(groupId));
      thread.setThreadName(req.getParameter("threadName"));

      DiscussionManager dm = new DiscussionManager();
      dm.createDiscussion(thread);

      try {
        Part documentPart = req.getPart("document");

        // if we have a document to upload
        if (documentPart.getSize() > 0) {
          String uuid = DocumentController.saveDocument(this.getServletContext(), documentPart);
          Document doc = new Document();
          doc.setDocumentName(getFileName(documentPart));
          doc.setDocumentPath(uuid);
          doc.setVersionNumber(1);
          doc.setThreadId(thread.getId());
          doc.setGroupId(thread.getGroupId());

          DocumentManager docMan = new DocumentManager();
          docMan.createDocument(doc);

          // Get uploading User
          HttpSession session = req.getSession();
          Session userSession = (Session) session.getAttribute("userSession");
          User uploader = userSession.getUser();

          // Create a notification to all in the group
          NotificationManager notificationMan = new NotificationManager();
          groupMan = new GroupManager();
          List<User> groupUsers = groupMan.getGroupUsers(groupId);

          for (User u : groupUsers) {
            Notification notification =
                new Notification(
                    u.getId(),
                    u,
                    groupId,
                    null,
                    "User " + uploader.getFullName() + " has uploaded a document",
                    "/document/document?documentId=" + doc.getId());

            notificationMan.createNotification(notification);
          }
        }
      } catch (Exception e) {
        logger.log(Level.SEVERE, "Document save error", e);
      }

      redirectToLocal(req, res, "/group/discussion/?threadId=" + thread.getId());
      return;
    }
    httpNotFound(req, res);
  }
Exemplo n.º 12
0
 @Override
 @ModelAttribute
 public void addModelInfo(ModelMap model, HttpServletRequest request) {
   super.addModelInfo(model, request);
 }