@Test public void testExecute() { final Long personId = 5L; final List<PersonModelView> people = new ArrayList<PersonModelView>(); final List<DomainGroupModelView> groups = new ArrayList<DomainGroupModelView>(); 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)); 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)); people.add(new PersonModelView(5L, "e", "foo", "bar", null, "", 300, new Date(), 5L)); 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)); 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)); groups.add(new DomainGroupModelView(10L, "j", "foobar", 200L, new Date(), 10L)); groups.add(new DomainGroupModelView(11L, "k", "foobar", 300L, new Date(), 11L)); groups.add(new DomainGroupModelView(12L, "l", "foobar", 700L, new Date(), 12L)); groups.add(new DomainGroupModelView(13L, "m", "foobar", 900L, new Date(), 13L)); groups.add(new DomainGroupModelView(14L, "n", "foobar", 800L, new Date(), 14L)); groups.add(new DomainGroupModelView(15L, "o", "foobar", 950L, new Date(), 15L)); 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>(); combinedList.add(featured); combinedList.add(people.get(0)); combinedList.add(people.get(0)); combinedList.add(people.get(2)); 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)); 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 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()); Assert.assertEquals(2, suggestions.get(2).getId()); Assert.assertEquals(14, suggestions.get(3).getId()); Assert.assertEquals(4, suggestions.get(4).getId()); Assert.assertEquals(12, suggestions.get(5).getId()); Assert.assertEquals(7, suggestions.get(6).getId()); Assert.assertEquals(11, suggestions.get(7).getId()); Assert.assertEquals(9, suggestions.get(8).getId()); context.assertIsSatisfied(); }
@Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long personId = inActionContext.getPrincipal().getId(); log.info("BEGIN getting the lists of streams that apply to all users."); StreamDiscoverListsDTO result = streamDiscoveryListsMapper.execute(null); log.info("END getting the lists of streams that apply to all users."); log.info("BEGIN getting the list of suggested streams for user " + personId); getSuggestionsForPerson(personId, result); log.info("END getting the list of suggested streams for user " + personId); List<DisplayInfoSettable> displayInfoSettables = new ArrayList<DisplayInfoSettable>(); 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()); Set<Long> allowedPeople = getAllowedPeopleList(displayInfoSettables); filterList(result.getFeaturedStreams(), allowedPeople); filterList(result.getMostFollowedStreams(), allowedPeople); filterList(result.getMostRecentStreams(), allowedPeople); filterList(result.getMostViewedStreams(), allowedPeople); filterList(result.getSuggestedStreams(), allowedPeople); int oldCount = result.getMostActiveStreams().getResultsSublist().size(); filterList(result.getMostActiveStreams().getResultsSublist(), allowedPeople); result.getMostActiveStreams().setTotalResultsCount( result.getMostActiveStreams().getTotalResultsCount() - (oldCount - result.getMostActiveStreams().getResultsSublist().size())); log.info("BEGIN setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); displayInfoSettableDataPopulator.execute(displayInfoSettables); log.info("END setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); log.info("BEGIN setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); followerStatusPopulator.execute(personId, displayInfoSettables, FollowerStatus.NOTFOLLOWING); log.info("END setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); return result; }
GetStreamDiscoverListsDTOExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long personId = inActionContext.getPrincipal().getId(); log.info("BEGIN getting the lists of streams that apply to all users."); StreamDiscoverListsDTO result = streamDiscoveryListsMapper.execute(null); log.info("END getting the lists of streams that apply to all users."); log.info("BEGIN getting the list of suggested streams for user " + personId); getSuggestionsForPerson(personId, result); log.info("END getting the list of suggested streams for user " + personId); List<DisplayInfoSettable> displayInfoSettables = new ArrayList<DisplayInfoSettable>(); 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()); Set<Long> allowedPeople = getAllowedPeopleList(displayInfoSettables); filterList(result.getFeaturedStreams(), allowedPeople); filterList(result.getMostFollowedStreams(), allowedPeople); filterList(result.getMostRecentStreams(), allowedPeople); filterList(result.getMostViewedStreams(), allowedPeople); filterList(result.getSuggestedStreams(), allowedPeople); int oldCount = result.getMostActiveStreams().getResultsSublist().size(); filterList(result.getMostActiveStreams().getResultsSublist(), allowedPeople); result.getMostActiveStreams().setTotalResultsCount( result.getMostActiveStreams().getTotalResultsCount() - (oldCount - result.getMostActiveStreams().getResultsSublist().size())); log.info("BEGIN setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); displayInfoSettableDataPopulator.execute(displayInfoSettables); log.info("END setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); log.info("BEGIN setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); followerStatusPopulator.execute(personId, displayInfoSettables, FollowerStatus.NOTFOLLOWING); log.info("END setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); return result; } }
GetStreamDiscoverListsDTOExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long personId = inActionContext.getPrincipal().getId(); log.info("BEGIN getting the lists of streams that apply to all users."); StreamDiscoverListsDTO result = streamDiscoveryListsMapper.execute(null); log.info("END getting the lists of streams that apply to all users."); log.info("BEGIN getting the list of suggested streams for user " + personId); getSuggestionsForPerson(personId, result); log.info("END getting the list of suggested streams for user " + personId); List<DisplayInfoSettable> displayInfoSettables = new ArrayList<DisplayInfoSettable>(); 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()); Set<Long> allowedPeople = getAllowedPeopleList(displayInfoSettables); filterList(result.getFeaturedStreams(), allowedPeople); filterList(result.getMostFollowedStreams(), allowedPeople); filterList(result.getMostRecentStreams(), allowedPeople); filterList(result.getMostViewedStreams(), allowedPeople); filterList(result.getSuggestedStreams(), allowedPeople); int oldCount = result.getMostActiveStreams().getResultsSublist().size(); filterList(result.getMostActiveStreams().getResultsSublist(), allowedPeople); result.getMostActiveStreams().setTotalResultsCount( result.getMostActiveStreams().getTotalResultsCount() - (oldCount - result.getMostActiveStreams().getResultsSublist().size())); log.info("BEGIN setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); displayInfoSettableDataPopulator.execute(displayInfoSettables); log.info("END setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); log.info("BEGIN setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); followerStatusPopulator.execute(personId, displayInfoSettables, FollowerStatus.NOTFOLLOWING); log.info("END setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); return result; } GetStreamDiscoverListsDTOExecution(
            final DomainMapper<SuggestedStreamsRequest, List<PersonModelView>> inSuggestedPersonMapper,
            final DomainMapper<SuggestedStreamsRequest, List<DomainGroupModelView>> inSuggestedGroupMapper,
            final int inSuggestionCount,
            final DomainMapper<Serializable, StreamDiscoverListsDTO> inStreamDiscoveryListsMapper,
            final DisplayInfoSettableDataPopulator inDisplayInfoSettableDataPopulator,
            final FollowerStatusPopulator<DisplayInfoSettable> inFollowerStatusPopulator,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPersonModelViewsByIdsDAO); }
GetStreamDiscoverListsDTOExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long personId = inActionContext.getPrincipal().getId(); log.info("BEGIN getting the lists of streams that apply to all users."); StreamDiscoverListsDTO result = streamDiscoveryListsMapper.execute(null); log.info("END getting the lists of streams that apply to all users."); log.info("BEGIN getting the list of suggested streams for user " + personId); getSuggestionsForPerson(personId, result); log.info("END getting the list of suggested streams for user " + personId); List<DisplayInfoSettable> displayInfoSettables = new ArrayList<DisplayInfoSettable>(); 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()); Set<Long> allowedPeople = getAllowedPeopleList(displayInfoSettables); filterList(result.getFeaturedStreams(), allowedPeople); filterList(result.getMostFollowedStreams(), allowedPeople); filterList(result.getMostRecentStreams(), allowedPeople); filterList(result.getMostViewedStreams(), allowedPeople); filterList(result.getSuggestedStreams(), allowedPeople); int oldCount = result.getMostActiveStreams().getResultsSublist().size(); filterList(result.getMostActiveStreams().getResultsSublist(), allowedPeople); result.getMostActiveStreams().setTotalResultsCount( result.getMostActiveStreams().getTotalResultsCount() - (oldCount - result.getMostActiveStreams().getResultsSublist().size())); log.info("BEGIN setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); displayInfoSettableDataPopulator.execute(displayInfoSettables); log.info("END setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); log.info("BEGIN setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); followerStatusPopulator.execute(personId, displayInfoSettables, FollowerStatus.NOTFOLLOWING); log.info("END setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); return result; } GetStreamDiscoverListsDTOExecution(
            final DomainMapper<SuggestedStreamsRequest, List<PersonModelView>> inSuggestedPersonMapper,
            final DomainMapper<SuggestedStreamsRequest, List<DomainGroupModelView>> inSuggestedGroupMapper,
            final int inSuggestionCount,
            final DomainMapper<Serializable, StreamDiscoverListsDTO> inStreamDiscoveryListsMapper,
            final DisplayInfoSettableDataPopulator inDisplayInfoSettableDataPopulator,
            final FollowerStatusPopulator<DisplayInfoSettable> inFollowerStatusPopulator,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPersonModelViewsByIdsDAO); @Override Serializable execute(final PrincipalActionContext inActionContext); }
GetStreamDiscoverListsDTOExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long personId = inActionContext.getPrincipal().getId(); log.info("BEGIN getting the lists of streams that apply to all users."); StreamDiscoverListsDTO result = streamDiscoveryListsMapper.execute(null); log.info("END getting the lists of streams that apply to all users."); log.info("BEGIN getting the list of suggested streams for user " + personId); getSuggestionsForPerson(personId, result); log.info("END getting the list of suggested streams for user " + personId); List<DisplayInfoSettable> displayInfoSettables = new ArrayList<DisplayInfoSettable>(); 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()); Set<Long> allowedPeople = getAllowedPeopleList(displayInfoSettables); filterList(result.getFeaturedStreams(), allowedPeople); filterList(result.getMostFollowedStreams(), allowedPeople); filterList(result.getMostRecentStreams(), allowedPeople); filterList(result.getMostViewedStreams(), allowedPeople); filterList(result.getSuggestedStreams(), allowedPeople); int oldCount = result.getMostActiveStreams().getResultsSublist().size(); filterList(result.getMostActiveStreams().getResultsSublist(), allowedPeople); result.getMostActiveStreams().setTotalResultsCount( result.getMostActiveStreams().getTotalResultsCount() - (oldCount - result.getMostActiveStreams().getResultsSublist().size())); log.info("BEGIN setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); displayInfoSettableDataPopulator.execute(displayInfoSettables); log.info("END setting the display info on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); log.info("BEGIN setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); followerStatusPopulator.execute(personId, displayInfoSettables, FollowerStatus.NOTFOLLOWING); log.info("END setting the follower statuses on " + displayInfoSettables.size() + " GroupModelViews and PersonModelViews"); return result; } GetStreamDiscoverListsDTOExecution(
            final DomainMapper<SuggestedStreamsRequest, List<PersonModelView>> inSuggestedPersonMapper,
            final DomainMapper<SuggestedStreamsRequest, List<DomainGroupModelView>> inSuggestedGroupMapper,
            final int inSuggestionCount,
            final DomainMapper<Serializable, StreamDiscoverListsDTO> inStreamDiscoveryListsMapper,
            final DisplayInfoSettableDataPopulator inDisplayInfoSettableDataPopulator,
            final FollowerStatusPopulator<DisplayInfoSettable> inFollowerStatusPopulator,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPersonModelViewsByIdsDAO); @Override Serializable execute(final PrincipalActionContext inActionContext);  }