final SuggestedStreamsRequest request = new SuggestedStreamsRequest(personId, 10);
final PrincipalActionContext actionContext = context.mock(PrincipalActionContext.class);
final Principal principal = context.mock(Principal.class);
final StreamDiscoverListsDTO result = new StreamDiscoverListsDTO();
people.add(new PersonModelView(1L, "a", "foo", "bar", null, "", 100, new Date(), 1L));
people.add(new PersonModelView(2L, "b", "foo", "bar", null, "", 900, new Date(), 2L)); // 3
people.add(new PersonModelView(3L, "c", "foo", "bar", null, "", 200, new Date(), 3L));
people.add(new PersonModelView(4L, "d", "foo", "bar", null, "", 800, new Date(), 4L)); // 5
people.add(new PersonModelView(5L, "e", "foo", "bar", null, "", 300, new Date(), 5L)); // 9
people.add(new PersonModelView(6L, "f", "foo", "bar", null, "", 200, new Date(), 6L));
people.add(new PersonModelView(7L, "g", "foo", "bar", null, "", 700, new Date(), 7L)); // 7
people.get(4).setAccountLocked(true);
groups.add(new DomainGroupModelView(8L, "h", "foobar", 50L, new Date(), 8L));
groups.add(new DomainGroupModelView(9L, "i", "foobar", 250L, new Date(), 9L)); // 10
groups.add(new DomainGroupModelView(10L, "j", "foobar", 200L, new Date(), 10L));
groups.add(new DomainGroupModelView(11L, "k", "foobar", 300L, new Date(), 11L)); // 8
groups.add(new DomainGroupModelView(12L, "l", "foobar", 700L, new Date(), 12L)); // 6
groups.add(new DomainGroupModelView(13L, "m", "foobar", 900L, new Date(), 13L)); // 2
groups.add(new DomainGroupModelView(14L, "n", "foobar", 800L, new Date(), 14L)); // 4
groups.add(new DomainGroupModelView(15L, "o", "foobar", 950L, new Date(), 15L)); // 1
// displayInfoSettables.addAll(result.getFeaturedStreams());
// displayInfoSettables.addAll(result.getMostFollowedStreams());
// displayInfoSettables.addAll(result.getMostRecentStreams());
// displayInfoSettables.addAll(result.getMostViewedStreams());
// displayInfoSettables.addAll(result.getSuggestedStreams());
// displayInfoSettables.addAll(result.getMostActiveStreams().getResultsSublist());
FeaturedStreamDTO featured = new FeaturedStreamDTO(111L, "", 111L, ScopeType.RESOURCE, "", 111L);
result.setFeaturedStreams(Collections.singletonList(featured));
result.setMostFollowedStreams(Collections.singletonList((StreamDTO) people.get(0)));
result.setMostRecentStreams(Collections.singletonList((StreamDTO) people.get(0)));
result.setMostViewedStreams(Collections.singletonList((StreamDTO) people.get(2)));
result.setMostActiveStreams(new SublistWithResultCount<StreamDTO>(Collections.singletonList((StreamDTO) groups
.get(0)), 3L));
final List<DisplayInfoSettable> combinedList = new ArrayList<DisplayInfoSettable>();
// featured list
combinedList.add(featured);
// most followed
combinedList.add(people.get(0));
// most recent
combinedList.add(people.get(0));
// most viewed
combinedList.add(people.get(2));
// suggestions
combinedList.add(groups.get(7));
combinedList.add(groups.get(5));
combinedList.add(people.get(1));
combinedList.add(groups.get(6));
combinedList.add(people.get(3));
combinedList.add(groups.get(4));
combinedList.add(people.get(6));
combinedList.add(groups.get(3));
combinedList.add(people.get(4));
combinedList.add(groups.get(1));
// most active
combinedList.add(groups.get(0));
if (displayInfoSettableDataPopulator == null)
{
throw new RuntimeException("WTH?");
}
final List<PersonModelView> peopleFetched = Arrays.asList(people.get(0), people.get(1), people.get(3),
people.get(4), people.get(6));
// final Set<Long> peopleIdsToFetch = new HashSet<Long>(Arrays.asList(1L, 2L, 4L, 5L, 7L));
final List<Long> peopleIdsToFetch = Arrays.asList(1L, 2L, 3L, 4L, 5L, 7L);
context.checking(new Expectations()
{
{
oneOf(actionContext).getPrincipal();
will(returnValue(principal));
oneOf(principal).getId();
will(returnValue(personId));
oneOf(suggestedPersonMapper).execute(with(IsEqualInternally.equalInternally(request)));
will(returnValue(people));
oneOf(suggestedGroupMapper).execute(with(IsEqualInternally.equalInternally(request)));
will(returnValue(groups));
oneOf(streamDiscoveryListsMapper).execute(null);
will(returnValue(result));
oneOf(displayInfoSettableDataPopulator).execute(with(IsEqualInternally.equalInternally(combinedList)));
will(returnValue(combinedList));
oneOf(followerStatusPopulator).execute(with(personId), with(combinedList),
with(FollowerStatus.NOTFOLLOWING));
will(returnValue(combinedList));
oneOf(getPersonModelViewsByIdsDAO).execute(with(new EasyMatcher<List<Long>>()
{
@Override
protected boolean isMatch(final List<Long> t)
{
boolean isMatch = t.size() == peopleIdsToFetch.size() && t.containsAll(peopleIdsToFetch);
return isMatch;
}
}));
will(returnValue(peopleFetched));
}
});
Assert.assertSame(result, sut.execute(actionContext));
List<StreamDTO> suggestions = result.getSuggestedStreams();
Assert.assertEquals(9, suggestions.size());
Assert.assertEquals(15, suggestions.get(0).getId());
Assert.assertEquals(13, suggestions.get(1).getId());