use of com.baeldung.models.Tweet in project tutorials by eugenp.
the class DummyContentUtil method generateDummyTweets.
public static final List<Tweet> generateDummyTweets(List<AppUser> users) {
List<Tweet> tweets = new ArrayList<>();
Random random = new Random();
IntStream.range(0, 9).sequential().forEach(i -> {
Tweet twt = new Tweet(String.format("Tweet %d", i), users.get(random.nextInt(users.size())).getUsername());
twt.getLikes().addAll(users.subList(0, random.nextInt(users.size())).stream().map(AppUser::getUsername).collect(Collectors.toSet()));
tweets.add(twt);
});
return tweets;
}
use of com.baeldung.models.Tweet in project tutorials by eugenp.
the class SpringDataWithSecurityTest method givenAppUser_whenLoginSuccessful_shouldReadMyPagedTweets.
@Test
public void givenAppUser_whenLoginSuccessful_shouldReadMyPagedTweets() {
AppUser appUser = userRepository.findByUsername("lionel@messi.com");
Authentication auth = new UsernamePasswordAuthenticationToken(new AppUserPrincipal(appUser), null, DummyContentUtil.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(auth);
Page<Tweet> page = null;
do {
page = tweetRepository.getMyTweetsAndTheOnesILiked(new PageRequest(page != null ? page.getNumber() + 1 : 0, 5));
for (Tweet twt : page.getContent()) {
isTrue((twt.getOwner() == appUser.getUsername()) || (twt.getLikes().contains(appUser.getUsername())), "I do not have any Tweets");
}
} while (page.hasNext());
}
Aggregations