@Transactional
@Test
public void testAddRecommendation() {
UserAccount user = userAccountRepo.findUserAccount(userId);
Restaurant rest = restaurantRepository.findRestaurant(22L);
user.rate(rest, 3, "Pretty Good");
em.flush();
UserAccount updatedUser = userAccountRepo.findUserAccount(userId);
Assert.assertNotNull("should have found something" ,updatedUser);
List<Recommendation> recommendations = new ArrayList<Recommendation>();
for (Recommendation r : updatedUser.getRecommendations()) {
recommendations.add(r);
}
Assert.assertEquals("user should now have correct number of recommendations", 1, recommendations.size());
Recommendation r = recommendations.get(0);
Assert.assertEquals("recommendation should have correct rating", 3, r.getStars());
Assert.assertEquals("recommendation should have correct comment", "Pretty Good", r.getComment());
final Restaurant restaurant = r.getRestaurant();
Assert.assertEquals("recommendation should have correct restaurant id", new Long(22), restaurant.getId());
Assert.assertEquals("recommendation should have correct restaurant name", "Subway Sandwiches & Salads", restaurant.getName());
}