Package com.nurkiewicz.jdbcrepository.repositories

Examples of com.nurkiewicz.jdbcrepository.repositories.CommentWithUser


  }

  @Test
  public void shouldGenerateKey() throws Exception {
    //given
    final CommentWithUser comment = new CommentWithUser(someUser, "Some content", SOME_TIMESTAMP, 0);

    //when
    repository.save(comment);

    //then
    assertThat(comment.getId()).isNotNull();
  }
View Full Code Here


  }

  @Test
  public void shouldReturnCommentWithUserAttached() throws Exception {
    //given
    final CommentWithUser comment = new CommentWithUser(someUser, "Some content", SOME_TIMESTAMP, 0);

    //when
    repository.save(comment);

    //then
    final CommentWithUser foundComment = repository.findOne(comment.getId());
    assertThat(foundComment).isEqualTo(new CommentWithUser(comment.getId(), someUser, "Some content", SOME_TIMESTAMP, 0));
  }
View Full Code Here

  }

  @Test
  public void shouldReturnMultipleCommentsAttachedToTheSameUser() throws Exception {
    //given
    final CommentWithUser first = repository.save(new CommentWithUser(someUser, "First comment", SOME_TIMESTAMP, 3));
    final CommentWithUser second = repository.save(new CommentWithUser(someUser, "Second comment", SOME_TIMESTAMP, 2));
    final CommentWithUser third = repository.save(new CommentWithUser(someUser, "Third comment", SOME_TIMESTAMP, 1));

    //when
    final List<CommentWithUser> all = repository.findAll(new Sort("favourite_count"));

    //then
View Full Code Here

    //given
    final User firstUser = userRepository.save(new User("First user", SOME_DATE, 10, false));
    final User secondUser = userRepository.save(new User("Second user", SOME_DATE, 20, false));
    final User thirdUser = userRepository.save(new User("Third user", SOME_DATE, 30, false));

    final CommentWithUser first = repository.save(new CommentWithUser(firstUser, "First comment", SOME_TIMESTAMP, 3));
    final CommentWithUser second = repository.save(new CommentWithUser(secondUser, "Second comment", SOME_TIMESTAMP, 2));
    final CommentWithUser third = repository.save(new CommentWithUser(thirdUser, "Third comment", SOME_TIMESTAMP, 1));

    //when
    final List<CommentWithUser> all = repository.findAll(new Sort(DESC, "favourite_count"));

    //then
View Full Code Here

  }

  @Test
  public void shouldReturnOnlyFirstPageWithUsers() throws Exception {
    //given
    final CommentWithUser first = repository.save(new CommentWithUser(someUser, "First comment", SOME_TIMESTAMP, 3));
    final CommentWithUser second = repository.save(new CommentWithUser(someUser, "Second comment", SOME_TIMESTAMP, 2));
    repository.save(new CommentWithUser(someUser, "Third comment", SOME_TIMESTAMP, 1));

    //when
    final Page<CommentWithUser> page = repository.findAll(new PageRequest(0, 2, ASC, "contents"));

    //then
View Full Code Here

  }

  @Test
  public void shouldReturnOnlySecondPageWithUsers() throws Exception {
    //given
    repository.save(new CommentWithUser(someUser, "First comment", SOME_TIMESTAMP, 3));
    repository.save(new CommentWithUser(someUser, "Second comment", SOME_TIMESTAMP, 2));
    final CommentWithUser third = repository.save(new CommentWithUser(someUser, "Third comment", SOME_TIMESTAMP, 1));

    //when
    final Page<CommentWithUser> page = repository.findAll(new PageRequest(1, 2, ASC, "contents"));

    //then
View Full Code Here

  }

  @Test
  public void shouldDeleteCommentWithoutDeletingUser() throws Exception {
    //given
    final CommentWithUser comment = repository.save(new CommentWithUser(someUser, "First comment", SOME_TIMESTAMP, 3));

    //when
    repository.delete(comment);

    //then
View Full Code Here

  @Test
  public void shouldUpdateCommentByAttachingDifferentUser() throws Exception {
    //given
    final User firstUser = userRepository.save(new User("First user", SOME_DATE, 10, false));
    final CommentWithUser comment = repository.save(new CommentWithUser(someUser, "First comment", SOME_TIMESTAMP, 3));

    //when
    comment.setUser(firstUser);
    repository.save(comment);

    //then
    assertThat(repository.count()).isEqualTo(1);
    final CommentWithUser foundComment = repository.findOne(comment.getId());
    assertThat(foundComment.getUser()).isEqualTo(firstUser);
  }
View Full Code Here

  }

  @Test
  public void shouldDeleteAllCommentsWithoutDeletingUsers() throws Exception {
    //given
    final CommentWithUser first = repository.save(new CommentWithUser(someUser, "First comment", SOME_TIMESTAMP, 3));
    final CommentWithUser second = repository.save(new CommentWithUser(someUser, "Second comment", SOME_TIMESTAMP, 2));
    final CommentWithUser third = repository.save(new CommentWithUser(someUser, "Third comment", SOME_TIMESTAMP, 1));

    //when
    repository.deleteAll();

    //then
View Full Code Here

TOP

Related Classes of com.nurkiewicz.jdbcrepository.repositories.CommentWithUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.