ActionDAOMysqlImpl extends AbstractTableCreatingDroppingDAOImpl implements ActionDAO { public List<RatingVO<Integer, Integer>> getRatings(int tenantId, TIntSet itemTypeIds, int userId) { Object[] args = new Object[]{tenantId, userId}; String query = QUERY_RATINGS.replace("@@@", generateItemTypeInClause(itemTypeIds)); return getJdbcTemplate().query(query, args, ARGT_RATINGS, ROWMAPPER_RATING); } ActionDAOMysqlImpl(DataSource dataSource, SqlScriptService sqlScriptService); void setActionDAO(final org.easyrec.store.dao.core.ActionDAO actionDAO); int generateActions(int tenantId, TIntSet itemTypeIds, int actionTypeId, Date since); List<RatingVO<Integer, Integer>> getRatings(int tenantId, TIntSet itemTypeIds,
                                                                         int userId); List<Integer> getUsers(int tenantId, TIntSet itemTypeIds, Date since); int insertAction(ActionVO<Integer, Integer> action); int insertActions(List<ActionVO<Integer, Integer>> actions); @Override String getDefaultTableName(); @Override String getTableCreatingSQLScriptName(); static final int[] ARGT_NEWEST; }
@Test public void getRatings_shouldReturnAllRatingsOfUser() { TIntSet itemTypeIds = new TIntHashSet(new int[]{1}); List<RatingVO<Integer, Integer>> ratings = actionDAO.getRatings(1, itemTypeIds, 1); assertThat(ratings.size(), is(4)); assertThat(ratings, hasItem(equalTo(createRating(1, 1, 1, "2007-04-15 12:11:00.0")))); assertThat(ratings, hasItem(equalTo(createRating(2, 1, 2, "2007-04-15 12:12:00.0")))); assertThat(ratings, hasItem(equalTo(createRating(3, 1, 3, "2007-04-15 12:13:00.0")))); assertThat(ratings, hasItem(equalTo(createRating(4, 1, 4, "2007-04-15 12:14:00.0")))); ratings = actionDAO.getRatings(1, itemTypeIds, 2); assertThat(ratings.size(), is(1)); assertThat(ratings, hasItem(equalTo(createRating(7, 2, 7, "2007-04-15 12:17:00.0")))); }
@Test public void getRatings_shouldReturnAllRatingsWithMultipleItemtypes() { TIntSet itemTypeIds = new TIntHashSet(new int[]{1, 2}); List<RatingVO<Integer, Integer>> ratings = actionDAO.getRatings(1, itemTypeIds, 1); assertThat(ratings.size(), is(5)); assertThat(ratings, hasItem(equalTo(createRating(1, 1, 1, "2007-04-15 12:11:00.0")))); assertThat(ratings, hasItem(equalTo(createRating(2, 1, 2, "2007-04-15 12:12:00.0")))); assertThat(ratings, hasItem(equalTo(createRating(3, 1, 3, "2007-04-15 12:13:00.0")))); assertThat(ratings, hasItem(equalTo(createRating(4, 1, 4, "2007-04-15 12:14:00.0")))); RatingVO<Integer, Integer> ratingOfOtherItemType = createRating(1, 1, 1, "2007-04-15 12:14:30.0"); ratingOfOtherItemType.getItem().setType(2); assertThat(ratings, hasItem(equalTo(ratingOfOtherItemType))); }