@BeforeMethod
 public void setUp() {
   initMocks(this);
   userContactsService = new TransactionalUserContactsService(userContactsDao, userService);
   user = new JCUser(USERNAME, EMAIL, PASSWORD);
   when(userService.getCurrentUser()).thenReturn(user);
 }
 @BeforeMethod
 public void init() {
   initMocks(this);
   topicFetchService = new TransactionalTopicFetchService(topicDao, userService, searchDao);
   user = new JCUser("username", "*****@*****.**", "password");
   when(userService.getCurrentUser()).thenReturn(user);
 }
 @BeforeMethod
 public void init() {
   MockitoAnnotations.initMocks(this);
   Mockito.when(userService.getCurrentUser())
       .thenReturn(new JCUser("username", "email", userCurrentPassword));
   validator = new ChangedPasswordValidator(userService, encryptionService);
   //
   editUserProfileDto.setCurrentUserPassword(userCurrentPassword);
   editUserProfileDto.setNewUserPassword(userNewPassword);
 }
 @Override
 public void toggleSubscription(SubscriptionAwareEntity entityToSubscribe) {
   JCUser current = userService.getCurrentUser();
   if (entityToSubscribe.getSubscribers().contains(current)) {
     entityToSubscribe.getSubscribers().remove(current);
   } else {
     entityToSubscribe.getSubscribers().add(current);
   }
   saveChanges(entityToSubscribe);
 }
 /** {@inheritDoc} */
 @Override
 public void toggleBranchSubscription(Branch branch) {
   JCUser current = userService.getCurrentUser();
   if (branch.getSubscribers().contains(current)) {
     branch.getSubscribers().remove(current);
   } else {
     branch.getSubscribers().add(current);
   }
   branchDao.update(branch);
 }
 /** {@inheritDoc} */
 @Override
 public void toggleTopicSubscription(Topic topic) {
   JCUser current = userService.getCurrentUser();
   if (topic.userSubscribed(current)) {
     topic.getSubscribers().remove(current);
   } else {
     topic.getSubscribers().add(current);
   }
   topicDao.update(topic);
 }
Exemplo n.º 7
0
 /** {@inheritDoc} */
 @Override
 public boolean isValid(String value, ConstraintValidatorContext context) {
   if (value == null) {
     // null emails checks are out of scope, pls use separate annotation for that
     return true;
   }
   JCUser user = userService.getCurrentUser();
   if (user.getEmail().equals(value)) {
     return true; // no changes in an email, that's ok
   } else {
     User found = userDao.getByEmail(value);
     return found == null;
   }
 }
  @Test
  public void testGetUnansweredTopics() {
    int pageNumber = 1;
    int pageSize = 20;
    List<Topic> expectedList = Collections.nCopies(2, new Topic(user, "title"));
    Page<Topic> expectedPage = new PageImpl<Topic>(expectedList);
    when(topicDao.getUnansweredTopics(Matchers.<JCommunePageRequest>any(), eq(user)))
        .thenReturn(expectedPage);
    user.setPageSize(pageSize);
    when(userService.getCurrentUser()).thenReturn(user);

    Page<Topic> actualPage = topicFetchService.getUnansweredTopics(pageNumber);
    assertNotNull(actualPage);
    assertEquals(actualPage, expectedPage);
  }
  @Test
  public void testGetTopics() {
    int pageSize = 50;
    Branch branch = createBranch();
    Page<Topic> expectedPage = new PageImpl<Topic>(Collections.<Topic>emptyList());

    JCUser currentUser = new JCUser("current", null, null);
    currentUser.setPageSize(pageSize);
    when(userService.getCurrentUser()).thenReturn(currentUser);
    when(topicDao.getTopics(Matchers.any(Branch.class), Matchers.any(JCommunePageRequest.class)))
        .thenReturn(expectedPage);

    Page<Topic> actualPage = topicFetchService.getTopics(branch, pageSize, true);

    assertEquals(
        actualPage, expectedPage, "Service returned incorrect data for one page of topics");
    verify(topicDao).getTopics(Matchers.any(Branch.class), Matchers.any(JCommunePageRequest.class));
  }
Exemplo n.º 10
0
 private Topic createCodeReviewWithLockHandling(Topic topic, TopicDto topicDto)
     throws NotFoundException {
   for (int i = 0; i < UserController.LOGIN_TRIES_AFTER_LOCK; i++) {
     try {
       return topicModificationService.createTopic(topic, topicDto.getBodyText());
     } catch (HibernateOptimisticLockingFailureException e) {
     }
   }
   try {
     return topicModificationService.createTopic(topic, topicDto.getBodyText());
   } catch (HibernateOptimisticLockingFailureException e) {
     LOGGER.error(
         "User has been optimistically locked and can't be reread {} times. Username: {}",
         UserController.LOGIN_TRIES_AFTER_LOCK,
         userService.getCurrentUser().getUsername());
     throw e;
   }
 }
  @Test
  public void testGetAllTopicsPastLastDay() throws NotFoundException {
    int pageNumber = 1;
    int pageSize = 20;
    List<Topic> expectedList = Collections.nCopies(2, new Topic(user, "title"));
    Page<Topic> expectedPage = new PageImpl<Topic>(expectedList);
    when(topicDao.getTopicsUpdatedSince(
            Matchers.<DateTime>any(), Matchers.<JCommunePageRequest>any(), eq(user)))
        .thenReturn(expectedPage);
    user.setPageSize(pageSize);
    when(userService.getCurrentUser()).thenReturn(user);

    Page<Topic> actualPage = topicFetchService.getRecentTopics(pageNumber);

    assertNotNull(actualPage);
    assertEquals(expectedPage, actualPage);
    verify(topicDao)
        .getTopicsUpdatedSince(
            Matchers.<DateTime>any(), Matchers.<JCommunePageRequest>any(), eq(user));
  }