コード例 #1
0
 @Test
 public void testVerifyVotesRejectsMissingCategory() {
   assertFalse(1 == firstEvent.getVoteCategories().size());
   List<Long> voteList = Lists.newArrayList();
   voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
   try {
     voteService.verifyVotes(firstEvent, voteList);
     fail("should not succeed");
   } catch (Exception e) {
     assertTrue(e.getMessage().contains("Invalid voting"));
   }
 }
コード例 #2
0
  @Test
  public void testVerifyVotesRejectsVotesForOtherEvent() {
    assertEquals(2, firstEvent.getVoteCategories().size());

    List<Long> voteList = Lists.newArrayList();
    voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    voteList.add(secondEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    try {
      voteService.verifyVotes(firstEvent, voteList);
      fail("should not succeed");
    } catch (Exception e) {
      assertTrue(e.getMessage().contains("Must vote in all categories"));
    }
  }
コード例 #3
0
  @Test
  public void testVoteEventDoesntExist() {
    Event e = new Event(null, null, "", "", EventType.PUBLIC, DateTime.now(), DateTime.now());
    e.setId((long) 10000);

    List<Long> voteList = Lists.newArrayList();
    voteList.add((long) 1);
    try {
      voteService.verifyVotes(e, voteList);
      fail("should not succeed");
    } catch (Exception e1) {
      assertTrue(e1.getMessage() != null);
    }
  }
コード例 #4
0
  @Test
  public void testVerifyVotes() {
    assertEquals(2, firstEvent.getVoteCategories().size());

    List<Long> voteList = Lists.newArrayList();
    voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    voteList.add(firstEvent.getVoteCategories().get(1).getVoteOptions().get(0).getId());

    try {
      voteService.verifyVotes(firstEvent, voteList);
      return;
    } catch (Exception e) {
      // ignore
    }
    fail("should not succeed");
  }
コード例 #5
0
  @Test
  public void testRepeatCategoriesRejectsAll() {
    List<Long> voteList = Lists.newArrayList();
    // repeat all categories or one category
    voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    voteList.add(firstEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());
    voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(1).getId());
    voteList.add(firstEvent.getVoteCategories().get(1).getVoteOptions().get(0).getId());

    try {
      voteService.addVotes(firstEvent, voteList, voter);
      fail("should not succeed");
    } catch (Exception e) {
      assertTrue(e.getMessage().contains("Invalid voting"));
    }
  }
コード例 #6
0
  /**
   * Validate event update.
   *
   * @param event the event
   * @throws ValidationException the validation exception
   */
  public static void validateEventUpdate(final Event event) throws ValidationException {
    final ValidationException validationException = new ValidationException();

    try {
      validateEventCreation(event);
    } catch (final ValidationException e) {
      validationException.addAllMessages(e.getErrorMessages());
    }

    if (event.getStartTime() != null && DateTime.now().isAfter(event.getStartTime())) {
      validationException.addMessage("Can not update event after start time");
    }

    if (validationException.hasErrorMessages()) {
      throw validationException;
    }
  }
コード例 #7
0
  @Test
  public void testValidUserPrivateEvent() throws Exception {
    privateEvent.addEventUser(voter);

    List<Long> voteList = Lists.newArrayList();
    voteList.add(privateEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    voteList.add(privateEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());

    voteService.addVotes(privateEvent, voteList, voter);

    VoteOption vo1o1 =
        voteOptionDao.find(privateEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    VoteOption vo2o1 =
        voteOptionDao.find(privateEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());

    assertTrue(vo1o1.getVotes().size() == 1);
    assertTrue(vo2o1.getVotes().size() == 1);
  }
コード例 #8
0
  @Test
  public void testVerifyAddVoteRecordsVote() throws Exception {
    // test firstEvent, secondEvent
    List<Long> voteList = Lists.newArrayList();
    voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    voteList.add(firstEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());
    voteService.addVotes(firstEvent, voteList, voter);

    // eventDao.update(secondEvent);

    VoteOption vo1o1 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    VoteOption vo2o1 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());

    assertTrue(vo1o1.getVotes().size() == 1);
    assertTrue(vo2o1.getVotes().size() == 1);
  }
コード例 #9
0
  @Test
  public void testInvalidUserPrivateEvent() throws Exception {

    try {
      List<Long> voteList = Lists.newArrayList();
      voteList.add(privateEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
      voteList.add(privateEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());

      voteService.addVotes(privateEvent, voteList, voter);

      VoteOption vo1o1 =
          voteOptionDao.find(
              privateEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
      VoteOption vo2o1 =
          voteOptionDao.find(
              privateEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());

      assertTrue(vo1o1.getVotes().size() == 1);
      assertTrue(vo2o1.getVotes().size() == 1);

    } catch (Exception e) {
      assertTrue(e.getMessage().contains("Invalid event for user"));
    }
  }
コード例 #10
0
  @Test
  public void testVerifyAddVoteReplacesExistingVote() throws Exception {
    List<Long> voteList = Lists.newArrayList();
    voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    voteList.add(firstEvent.getVoteCategories().get(1).getVoteOptions().get(0).getId());
    voteService.addVotes(firstEvent, voteList, voter);
    // eventDao.update(firstEvent);

    VoteOption vo1o1 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    VoteOption vo2o1 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(1).getVoteOptions().get(0).getId());

    assertTrue(vo1o1.getVotes().size() == 1);
    assertTrue(vo2o1.getVotes().size() == 1);

    voteList.clear();

    voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(1).getId());
    voteList.add(firstEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());

    voteService.addVotes(firstEvent, voteList, voter);

    vo1o1 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId());
    vo2o1 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(1).getVoteOptions().get(0).getId());
    VoteOption vo1o2 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(0).getVoteOptions().get(1).getId());
    VoteOption vo2o2 =
        voteOptionDao.find(firstEvent.getVoteCategories().get(1).getVoteOptions().get(1).getId());

    assertTrue(vo1o1.getVotes().size() == 0);
    assertTrue(vo2o1.getVotes().size() == 0);
    assertTrue(vo1o2.getVotes().size() == 1);
    assertTrue(vo2o2.getVotes().size() == 1);
  }
コード例 #11
0
  /**
   * Validate event creation.
   *
   * @param event the event
   * @throws ValidationException the validation exception
   */
  public static void validateEventCreation(final Event event) throws ValidationException {

    if (event == null) {
      return;
    }

    final ValidationException validationException = new ValidationException();

    if (StringUtils.isEmpty(StringUtils.trimToEmpty(event.getName()))) {
      validationException.addMessage("Event must have a name.");
    }

    if (event.getEventType() == null) {
      validationException.addMessage("EventType can not be empty.");
    }

    if (event.getStartTime() == null) {
      validationException.addMessage("Start date must be supplied.");
    }

    if (event.getEndTime() == null) {
      validationException.addMessage("End date must be supplied.");
    }

    if (event.getStartTime() != null
        && event.getEndTime() != null
        && (!event.getStartTime().isBefore(event.getEndTime()))) {
      validationException.addMessage("Start date must be before end date.");
    }

    if (event.getVoteCategories() == null || event.getVoteCategories().isEmpty()) {
      validationException.addMessage("At least one voting category must be supplied.");
    } else {

      for (final VoteCategory category : event.getVoteCategories()) {
        try {
          validateVoteCategory(category);
        } catch (final ValidationException e) {
          validationException.addAllMessages(e.getErrorMessages());
        }
      }
    }

    if (validationException.hasErrorMessages()) {
      throw validationException;
    }
  }