@Test public void testExecuteWhenSharedExists() { final String uniqueKey = "http: final StreamScope sharedResourceStreamScope = context.mock(StreamScope.class); final SharedResourceRequest request = new SharedResourceRequest(uniqueKey, null); final List<Long> sharerIds = new ArrayList<Long>(); final List<Long> likerIds = new ArrayList<Long>(); final List<PersonModelView> people = new ArrayList<PersonModelView>(); final Long streamScopeId = 282834L; final Long sharedResourceId = 83348L; people.add(buildPersonModelView(1L)); people.add(buildPersonModelView(2L)); people.add(buildPersonModelView(3L)); people.add(buildPersonModelView(4L)); people.add(buildPersonModelView(5L)); people.add(buildPersonModelView(6L)); people.add(buildPersonModelView(7L)); sharerIds.add(1L); sharerIds.add(2L); sharerIds.add(3L); sharerIds.add(4L); sharerIds.add(5L); sharerIds.add(6L); likerIds.add(4L); likerIds.add(5L); likerIds.add(6L); likerIds.add(7L); likerIds.add(8L); context.checking(new Expectations() { { oneOf(sharedResourceStreamScope).getId(); will(returnValue(streamScopeId)); oneOf(sharedResourceStreamScope).getDestinationEntityId(); will(returnValue(sharedResourceId)); oneOf(getResourceStreamScopeByKeyMapper).execute(with(uniqueKey)); will(returnValue(sharedResourceStreamScope)); oneOf(getPeopleThatSharedResourceMapper).execute(with(request)); will(returnValue(sharerIds)); oneOf(getPeopleThatLikedResourceMapper).execute(with(request)); will(returnValue(likerIds)); } }); SharedResourceDTO result = sut.execute(request); assertEquals(sharedResourceId, request.getSharedResourceId()); assertEquals(streamScopeId, result.getStreamScopeId()); assertEquals(5, result.getLikeCount()); assertEquals(6, result.getShareCount()); assertNull(result.getLikersSample()); assertNull(result.getSharersSample()); assertEquals(uniqueKey, result.getKey()); context.assertIsSatisfied(); }
@Override public SharedResourceDTO execute(final SharedResourceRequest inRequest) { SharedResourceDTO dto = new SharedResourceDTO(); dto.setKey(inRequest.getUniqueKey()); log.info("Looking for the stream scope for shared resource with uniqueKey " + inRequest.getUniqueKey()); StreamScope sharedResourceStreamScope = getResourceStreamScopeByKeyMapper.execute(inRequest.getUniqueKey()); if (sharedResourceStreamScope == null) { log.info("Couldn't find the stream scope for shared resource with unique key " + inRequest.getUniqueKey() + " - must not exist. Cache as such."); dto.setStreamScopeId(null); dto.setIsLiked(false); return dto; } dto.setStreamScopeId(sharedResourceStreamScope.getId()); inRequest.setSharedResourceId(sharedResourceStreamScope.getDestinationEntityId()); log.info("Found the shared resource for unique key " + inRequest.getUniqueKey() + " - looking for lists of people ids that liked and shared it."); List<Long> sharedPersonIds = getPeopleThatSharedResourceMapper.execute(inRequest); List<Long> likedPersonIds = getPeopleThatLikedResourceMapper.execute(inRequest); if (sharedPersonIds == null) { sharedPersonIds = new ArrayList<Long>(); } dto.setLikerPersonIds(likedPersonIds); if (likedPersonIds == null) { likedPersonIds = new ArrayList<Long>(); } dto.setSharerPersonIds(sharedPersonIds); return dto; }
GetSharedResourcePropertiesMapper extends BaseArgDomainMapper<SharedResourceRequest, SharedResourceDTO> { @Override public SharedResourceDTO execute(final SharedResourceRequest inRequest) { SharedResourceDTO dto = new SharedResourceDTO(); dto.setKey(inRequest.getUniqueKey()); log.info("Looking for the stream scope for shared resource with uniqueKey " + inRequest.getUniqueKey()); StreamScope sharedResourceStreamScope = getResourceStreamScopeByKeyMapper.execute(inRequest.getUniqueKey()); if (sharedResourceStreamScope == null) { log.info("Couldn't find the stream scope for shared resource with unique key " + inRequest.getUniqueKey() + " - must not exist. Cache as such."); dto.setStreamScopeId(null); dto.setIsLiked(false); return dto; } dto.setStreamScopeId(sharedResourceStreamScope.getId()); inRequest.setSharedResourceId(sharedResourceStreamScope.getDestinationEntityId()); log.info("Found the shared resource for unique key " + inRequest.getUniqueKey() + " - looking for lists of people ids that liked and shared it."); List<Long> sharedPersonIds = getPeopleThatSharedResourceMapper.execute(inRequest); List<Long> likedPersonIds = getPeopleThatLikedResourceMapper.execute(inRequest); if (sharedPersonIds == null) { sharedPersonIds = new ArrayList<Long>(); } dto.setLikerPersonIds(likedPersonIds); if (likedPersonIds == null) { likedPersonIds = new ArrayList<Long>(); } dto.setSharerPersonIds(sharedPersonIds); return dto; } }
GetSharedResourcePropertiesMapper extends BaseArgDomainMapper<SharedResourceRequest, SharedResourceDTO> { @Override public SharedResourceDTO execute(final SharedResourceRequest inRequest) { SharedResourceDTO dto = new SharedResourceDTO(); dto.setKey(inRequest.getUniqueKey()); log.info("Looking for the stream scope for shared resource with uniqueKey " + inRequest.getUniqueKey()); StreamScope sharedResourceStreamScope = getResourceStreamScopeByKeyMapper.execute(inRequest.getUniqueKey()); if (sharedResourceStreamScope == null) { log.info("Couldn't find the stream scope for shared resource with unique key " + inRequest.getUniqueKey() + " - must not exist. Cache as such."); dto.setStreamScopeId(null); dto.setIsLiked(false); return dto; } dto.setStreamScopeId(sharedResourceStreamScope.getId()); inRequest.setSharedResourceId(sharedResourceStreamScope.getDestinationEntityId()); log.info("Found the shared resource for unique key " + inRequest.getUniqueKey() + " - looking for lists of people ids that liked and shared it."); List<Long> sharedPersonIds = getPeopleThatSharedResourceMapper.execute(inRequest); List<Long> likedPersonIds = getPeopleThatLikedResourceMapper.execute(inRequest); if (sharedPersonIds == null) { sharedPersonIds = new ArrayList<Long>(); } dto.setLikerPersonIds(likedPersonIds); if (likedPersonIds == null) { likedPersonIds = new ArrayList<Long>(); } dto.setSharerPersonIds(sharedPersonIds); return dto; } GetSharedResourcePropertiesMapper(
            final DomainMapper<String, StreamScope> inGetResourceStreamScopeByKeyMapper,
            final DomainMapper<SharedResourceRequest, List<Long>> inGetPeopleThatSharedResourceMapper,
            final DomainMapper<SharedResourceRequest, List<Long>> inGetPeopleThatLikedResourceMapper); }
GetSharedResourcePropertiesMapper extends BaseArgDomainMapper<SharedResourceRequest, SharedResourceDTO> { @Override public SharedResourceDTO execute(final SharedResourceRequest inRequest) { SharedResourceDTO dto = new SharedResourceDTO(); dto.setKey(inRequest.getUniqueKey()); log.info("Looking for the stream scope for shared resource with uniqueKey " + inRequest.getUniqueKey()); StreamScope sharedResourceStreamScope = getResourceStreamScopeByKeyMapper.execute(inRequest.getUniqueKey()); if (sharedResourceStreamScope == null) { log.info("Couldn't find the stream scope for shared resource with unique key " + inRequest.getUniqueKey() + " - must not exist. Cache as such."); dto.setStreamScopeId(null); dto.setIsLiked(false); return dto; } dto.setStreamScopeId(sharedResourceStreamScope.getId()); inRequest.setSharedResourceId(sharedResourceStreamScope.getDestinationEntityId()); log.info("Found the shared resource for unique key " + inRequest.getUniqueKey() + " - looking for lists of people ids that liked and shared it."); List<Long> sharedPersonIds = getPeopleThatSharedResourceMapper.execute(inRequest); List<Long> likedPersonIds = getPeopleThatLikedResourceMapper.execute(inRequest); if (sharedPersonIds == null) { sharedPersonIds = new ArrayList<Long>(); } dto.setLikerPersonIds(likedPersonIds); if (likedPersonIds == null) { likedPersonIds = new ArrayList<Long>(); } dto.setSharerPersonIds(sharedPersonIds); return dto; } GetSharedResourcePropertiesMapper(
            final DomainMapper<String, StreamScope> inGetResourceStreamScopeByKeyMapper,
            final DomainMapper<SharedResourceRequest, List<Long>> inGetPeopleThatSharedResourceMapper,
            final DomainMapper<SharedResourceRequest, List<Long>> inGetPeopleThatLikedResourceMapper); @Override SharedResourceDTO execute(final SharedResourceRequest inRequest); }
GetSharedResourcePropertiesMapper extends BaseArgDomainMapper<SharedResourceRequest, SharedResourceDTO> { @Override public SharedResourceDTO execute(final SharedResourceRequest inRequest) { SharedResourceDTO dto = new SharedResourceDTO(); dto.setKey(inRequest.getUniqueKey()); log.info("Looking for the stream scope for shared resource with uniqueKey " + inRequest.getUniqueKey()); StreamScope sharedResourceStreamScope = getResourceStreamScopeByKeyMapper.execute(inRequest.getUniqueKey()); if (sharedResourceStreamScope == null) { log.info("Couldn't find the stream scope for shared resource with unique key " + inRequest.getUniqueKey() + " - must not exist. Cache as such."); dto.setStreamScopeId(null); dto.setIsLiked(false); return dto; } dto.setStreamScopeId(sharedResourceStreamScope.getId()); inRequest.setSharedResourceId(sharedResourceStreamScope.getDestinationEntityId()); log.info("Found the shared resource for unique key " + inRequest.getUniqueKey() + " - looking for lists of people ids that liked and shared it."); List<Long> sharedPersonIds = getPeopleThatSharedResourceMapper.execute(inRequest); List<Long> likedPersonIds = getPeopleThatLikedResourceMapper.execute(inRequest); if (sharedPersonIds == null) { sharedPersonIds = new ArrayList<Long>(); } dto.setLikerPersonIds(likedPersonIds); if (likedPersonIds == null) { likedPersonIds = new ArrayList<Long>(); } dto.setSharerPersonIds(sharedPersonIds); return dto; } GetSharedResourcePropertiesMapper(
            final DomainMapper<String, StreamScope> inGetResourceStreamScopeByKeyMapper,
            final DomainMapper<SharedResourceRequest, List<Long>> inGetPeopleThatSharedResourceMapper,
            final DomainMapper<SharedResourceRequest, List<Long>> inGetPeopleThatLikedResourceMapper); @Override SharedResourceDTO execute(final SharedResourceRequest inRequest);  }