Ejemplo n.º 1
0
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testGetEventsForProject() {
    Project project1 = projectService.read(1L);
    Project project3 = projectService.read(3L);

    Page<ProjectEvent> eventsForProject1 =
        projectEventService.getEventsForProject(project1, new PageRequest(0, 10));
    Page<ProjectEvent> eventsForProject2 =
        projectEventService.getEventsForProject(project3, new PageRequest(0, 10));

    assertEquals(0L, eventsForProject1.getTotalElements());
    assertEquals(1L, eventsForProject2.getTotalElements());

    ProjectEvent event2 = eventsForProject2.iterator().next();

    assertEquals(project3, event2.getProject());
  }
Ejemplo n.º 2
0
  @WithMockUser(username = "******", password = "******", roles = "USER")
  @Test
  public void testGetEventsForIndividualUser() {
    User user1 = userService.read(1L);

    Page<ProjectEvent> events1 =
        projectEventService.getEventsForUser(user1, new PageRequest(0, 10));

    assertEquals(1L, events1.getTotalElements());
  }
Ejemplo n.º 3
0
  /**
   * Return a list of events for all projects
   *
   * @param model Model attribute for returned view
   * @param size Number of events to show
   * @return Name of the events view
   */
  @RequestMapping("/all")
  public String getAllRecentEvents(
      Model model, @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer size) {
    Page<ProjectEvent> list = eventService.list(0, size, Direction.DESC, "createdDate");

    List<Map<String, Object>> eventInfo = buildEventsListFromPage(list);

    model.addAttribute("events", eventInfo);

    return EVENTS_VIEW;
  }
Ejemplo n.º 4
0
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testGetEmptyEventsAfterDate() throws ParseException {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date beginning = formatter.parse("2013-07-18 15:00:00");

    User user = userService.read(3L);

    List<ProjectEvent> events = projectEventService.getEventsForUserAfterDate(user, beginning);

    assertTrue("no events should be found", events.isEmpty());
  }
Ejemplo n.º 5
0
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testGetEventsForUser() {
    User user1 = userService.read(1L);
    User user2 = userService.read(2L);
    User user3 = userService.read(3L);

    Page<ProjectEvent> events1 =
        projectEventService.getEventsForUser(user1, new PageRequest(0, 10));
    Page<ProjectEvent> events2 =
        projectEventService.getEventsForUser(user2, new PageRequest(0, 10));
    Page<ProjectEvent> events3 =
        projectEventService.getEventsForUser(user3, new PageRequest(0, 10));

    assertEquals(1L, events1.getTotalElements());
    assertEquals(0L, events2.getTotalElements());
    assertEquals(1L, events3.getTotalElements());

    ProjectEvent event1 = events1.iterator().next();
    ProjectEvent event3 = events3.iterator().next();
    assertEquals(event1, event3);
  }
Ejemplo n.º 6
0
  /**
   * Get recent {@link ProjectEvent}s for the given {@link Project}
   *
   * @param projectId The ID of the {@link Project} to get events for
   * @param model Model for the view. Contains a list named "events". This will be a map which will
   *     contain "name" which is the name of the view fragment to use, and "event" which is a
   *     reference to the event itself
   * @param size Number of events to show
   * @return The name of the events view
   */
  @RequestMapping("/project/{projectId}")
  public String getRecentEventsForProject(
      @PathVariable Long projectId,
      Model model,
      @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer size) {
    Project project = projectService.read(projectId);

    Page<ProjectEvent> events =
        eventService.getEventsForProject(
            project, new PageRequest(0, size, Direction.DESC, "createdDate"));
    List<Map<String, Object>> eventInfo = buildEventsListFromPage(events);

    model.addAttribute("events", eventInfo);

    return EVENTS_VIEW;
  }
Ejemplo n.º 7
0
  /**
   * Get recent {@link ProjectEvent}s for the currently logged in user
   *
   * @param model Model for the view. Contains a list named "events". This will be a map which will
   *     contain "name" which is the name of the view fragment to use, and "event" which is a
   *     reference to the event itself
   * @param principal currently logged in principal
   * @param size Number of events to show
   * @return The name of the events view
   */
  @RequestMapping("/current_user")
  public String getRecentEventsForUser(
      Model model,
      Principal principal,
      @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer size) {
    String userName = principal.getName();
    User user = userService.getUserByUsername(userName);

    Page<ProjectEvent> events =
        eventService.getEventsForUser(
            user, new PageRequest(0, size, Direction.DESC, "createdDate"));
    List<Map<String, Object>> eventInfo = buildEventsListFromPage(events);

    model.addAttribute("events", eventInfo);

    return EVENTS_VIEW;
  }
Ejemplo n.º 8
0
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testUpdateProjectUser() throws ProjectWithoutOwnerException {
    Project project = projectService.read(1L);
    User user = userService.read(1L);

    projectService.updateUserProjectRole(project, user, ProjectRole.PROJECT_USER);

    Page<ProjectEvent> eventsForProject =
        projectEventService.getEventsForProject(project, new PageRequest(0, 10));

    assertEquals(1, eventsForProject.getTotalElements());
    ProjectEvent event = eventsForProject.iterator().next();

    assertTrue(event instanceof UserRoleSetProjectEvent);
    UserRoleSetProjectEvent userEvent = (UserRoleSetProjectEvent) event;
    assertEquals(project, userEvent.getProject());
    assertEquals(user, userEvent.getUser());
  }
Ejemplo n.º 9
0
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testErrorThrownNoEvent() {
    Project project = projectService.read(1L);

    Sample sample = sampleService.read(1L);

    try {
      projectService.addSampleToProject(project, sample);
      fail("EntityExistsException should have been thrown");
    } catch (EntityExistsException ex) {
      // it's all good
    }

    Page<ProjectEvent> eventsForProject =
        projectEventService.getEventsForProject(project, new PageRequest(0, 10));

    assertEquals("No event should be created", 0, eventsForProject.getTotalElements());
  }
Ejemplo n.º 10
0
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testAddProjectSample() {
    Project project = projectService.read(1L);

    Sample sample = sampleService.read(2L);

    projectService.addSampleToProject(project, sample);

    Page<ProjectEvent> eventsForProject =
        projectEventService.getEventsForProject(project, new PageRequest(0, 10));

    assertEquals(1, eventsForProject.getTotalElements());
    ProjectEvent event = eventsForProject.iterator().next();

    assertTrue(event instanceof SampleAddedProjectEvent);
    SampleAddedProjectEvent userEvent = (SampleAddedProjectEvent) event;
    assertEquals(project, userEvent.getProject());
    assertEquals(sample, userEvent.getSample());
  }