@Test public void testExecuteWhenNotFound() { final SharedResourceDTO dto = new SharedResourceDTO(); dto.setLikerPersonIds(new ArrayList<Long>()); dto.setSharerPersonIds(new ArrayList<Long>()); dto.getLikerPersonIds().add(1L); dto.getLikerPersonIds().add(2L); dto.getLikerPersonIds().add(3L); dto.getLikerPersonIds().add(4L); dto.getLikerPersonIds().add(5L); dto.getLikerPersonIds().add(8L); dto.getSharerPersonIds().add(1L); dto.getSharerPersonIds().add(3L); dto.getSharerPersonIds().add(5L); dto.getSharerPersonIds().add(6L); final List<PersonModelView> people = new ArrayList<PersonModelView>(); PersonModelView mv1 = new PersonModelView(); mv1.setEntityId(1L); people.add(mv1); PersonModelView mv2 = new PersonModelView(); mv2.setEntityId(2L); people.add(mv2); PersonModelView mv3 = new PersonModelView(); mv3.setEntityId(3L); people.add(mv3); PersonModelView mv4 = new PersonModelView(); mv4.setEntityId(4L); people.add(mv4); PersonModelView mv5 = new PersonModelView(); mv5.setEntityId(5L); people.add(mv5); PersonModelView mv6 = new PersonModelView(); mv6.setEntityId(6L); people.add(mv6); final List<Long> peopleIds = new ArrayList<Long>(); peopleIds.add(1L); peopleIds.add(3L); peopleIds.add(5L); peopleIds.add(6L); peopleIds.add(2L); peopleIds.add(4L); getPeopleModelViewsByIdsMapper.setResponse(people); context.checking(new Expectations() { { oneOf(mapper).execute(request); will(returnValue(dto)); } }); sut.execute(actionContext); Assert.assertEquals(6, getPeopleModelViewsByIdsMapper.getRequest().size()); Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(1L)); Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(2L)); Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(5L)); Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(6L)); Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(2L)); Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(4L)); Assert.assertEquals(6, dto.getLikerPersonIds().size()); Assert.assertEquals(4, dto.getSharerPersonIds().size()); Assert.assertEquals(4, dto.getLikersSample().size()); Assert.assertEquals(4, dto.getSharersSample().size()); Assert.assertTrue(dto.getLikersSample().contains(mv1)); Assert.assertTrue(dto.getLikersSample().contains(mv2)); Assert.assertTrue(dto.getLikersSample().contains(mv3)); Assert.assertTrue(dto.getLikersSample().contains(mv4)); Assert.assertTrue(dto.getSharersSample().contains(mv1)); Assert.assertTrue(dto.getSharersSample().contains(mv3)); Assert.assertTrue(dto.getSharersSample().contains(mv5)); Assert.assertTrue(dto.getSharersSample().contains(mv6)); Assert.assertTrue(dto.isLiked()); context.assertIsSatisfied(); }
@Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } GetSharedResourcePropertiesExecution(final DomainMapper<SharedResourceRequest, SharedResourceDTO> inMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleModelViewsByIdsMapper); }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } GetSharedResourcePropertiesExecution(final DomainMapper<SharedResourceRequest, SharedResourceDTO> inMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleModelViewsByIdsMapper); @Override Serializable execute(final PrincipalActionContext inActionContext); }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } GetSharedResourcePropertiesExecution(final DomainMapper<SharedResourceRequest, SharedResourceDTO> inMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleModelViewsByIdsMapper); @Override Serializable execute(final PrincipalActionContext inActionContext);  }