@Test public void testExecute() { final long personId = 28328L; final TaskHandlerActionContext<PrincipalActionContext> taskContext = context .mock(TaskHandlerActionContext.class); final PrincipalActionContext principalActionContext = context.mock(PrincipalActionContext.class); final Principal principal = context.mock(Principal.class); final String url = "http: final SetSharedResourceLikeRequest actionRequest = new SetSharedResourceLikeRequest(url, true); final SharedResource sharedResourceFoundOrInserted = new SharedResource("http: findOrInsertSharedResourceMapper.setReturnedResource(sharedResourceFoundOrInserted); final List<UserActionRequest> requests = new ArrayList<UserActionRequest>(); final String cacheSuffix = "SOMETHING"; final String expectedCacheKey = CacheKeys.SHARED_RESOURCE_BY_UNIQUE_KEY + cacheSuffix; context.checking(new Expectations() { { allowing(taskContext).getActionContext(); will(returnValue(principalActionContext)); allowing(principalActionContext).getParams(); will(returnValue(actionRequest)); allowing(principalActionContext).getPrincipal(); will(returnValue(principal)); allowing(principal).getId(); will(returnValue(personId)); oneOf(sharedResourceCacheKeySuffixTransformer).transform(url); will(returnValue(cacheSuffix)); oneOf(cache).delete(expectedCacheKey); allowing(taskContext).getUserActionRequests(); will(returnValue(requests)); } }); setLikedResourceStatusMapper.setRequest(null); sut.execute(taskContext); assertEquals(url, findOrInsertSharedResourceMapper.getRequest().getUniqueKey()); assertEquals(personId, setLikedResourceStatusMapper.getRequest().getPersonId()); assertTrue(setLikedResourceStatusMapper.getRequest().getLikedStatus()); assertSame(sharedResourceFoundOrInserted, setLikedResourceStatusMapper.getRequest().getSharedResource()); assertEquals(1, requests.size()); assertEquals("deleteCacheKeysAction", requests.get(0).getActionKey()); Set<String> params = (Set<String>) requests.get(0).getParams(); assertEquals(1, params.size()); for (String p : params) { assertEquals(expectedCacheKey, p); } context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SetSharedResourceLikeRequest request = (SetSharedResourceLikeRequest) inActionContext.getActionContext() .getParams(); if (request == null || request.getUniqueKey() == null) { return new Boolean(false); } final String sharedResourceUniqueKey = request.getUniqueKey().toLowerCase(); final Long personId = inActionContext.getActionContext().getPrincipal().getId(); SharedResource sr = findOrInsertSharedResourceMapper.execute(new SharedResourceRequest( sharedResourceUniqueKey, null)); SetSharedResourceLikeMapperRequest mapperRequest = new SetSharedResourceLikeMapperRequest(personId, sr, request.getLikes()); setLikedResourceStatusMapper.execute(mapperRequest); String cacheKey = CacheKeys.SHARED_RESOURCE_BY_UNIQUE_KEY + sharedResourceCacheKeySuffixTransformer.transform(sharedResourceUniqueKey); log.debug("Immediately deleting cache key while in transaction '" + cacheKey + "', then queuing it up for post-transaction cleanup to avoid race."); cache.delete(cacheKey); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(cacheKey))); return new Boolean(true); }
SetSharedResourceLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SetSharedResourceLikeRequest request = (SetSharedResourceLikeRequest) inActionContext.getActionContext() .getParams(); if (request == null || request.getUniqueKey() == null) { return new Boolean(false); } final String sharedResourceUniqueKey = request.getUniqueKey().toLowerCase(); final Long personId = inActionContext.getActionContext().getPrincipal().getId(); SharedResource sr = findOrInsertSharedResourceMapper.execute(new SharedResourceRequest( sharedResourceUniqueKey, null)); SetSharedResourceLikeMapperRequest mapperRequest = new SetSharedResourceLikeMapperRequest(personId, sr, request.getLikes()); setLikedResourceStatusMapper.execute(mapperRequest); String cacheKey = CacheKeys.SHARED_RESOURCE_BY_UNIQUE_KEY + sharedResourceCacheKeySuffixTransformer.transform(sharedResourceUniqueKey); log.debug("Immediately deleting cache key while in transaction '" + cacheKey + "', then queuing it up for post-transaction cleanup to avoid race."); cache.delete(cacheKey); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(cacheKey))); return new Boolean(true); } }
SetSharedResourceLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SetSharedResourceLikeRequest request = (SetSharedResourceLikeRequest) inActionContext.getActionContext() .getParams(); if (request == null || request.getUniqueKey() == null) { return new Boolean(false); } final String sharedResourceUniqueKey = request.getUniqueKey().toLowerCase(); final Long personId = inActionContext.getActionContext().getPrincipal().getId(); SharedResource sr = findOrInsertSharedResourceMapper.execute(new SharedResourceRequest( sharedResourceUniqueKey, null)); SetSharedResourceLikeMapperRequest mapperRequest = new SetSharedResourceLikeMapperRequest(personId, sr, request.getLikes()); setLikedResourceStatusMapper.execute(mapperRequest); String cacheKey = CacheKeys.SHARED_RESOURCE_BY_UNIQUE_KEY + sharedResourceCacheKeySuffixTransformer.transform(sharedResourceUniqueKey); log.debug("Immediately deleting cache key while in transaction '" + cacheKey + "', then queuing it up for post-transaction cleanup to avoid race."); cache.delete(cacheKey); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(cacheKey))); return new Boolean(true); } SetSharedResourceLikeExecution(
            final DomainMapper<SetSharedResourceLikeMapperRequest, Boolean> inSetLikedResourceStatusMapper,
            final DomainMapper<SharedResourceRequest, SharedResource> inFindOrInsertSharedResourceMapper,
            final Cache inCache, final Transformer<String, String> inSharedResourceCacheKeySuffixTransformer); }
SetSharedResourceLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SetSharedResourceLikeRequest request = (SetSharedResourceLikeRequest) inActionContext.getActionContext() .getParams(); if (request == null || request.getUniqueKey() == null) { return new Boolean(false); } final String sharedResourceUniqueKey = request.getUniqueKey().toLowerCase(); final Long personId = inActionContext.getActionContext().getPrincipal().getId(); SharedResource sr = findOrInsertSharedResourceMapper.execute(new SharedResourceRequest( sharedResourceUniqueKey, null)); SetSharedResourceLikeMapperRequest mapperRequest = new SetSharedResourceLikeMapperRequest(personId, sr, request.getLikes()); setLikedResourceStatusMapper.execute(mapperRequest); String cacheKey = CacheKeys.SHARED_RESOURCE_BY_UNIQUE_KEY + sharedResourceCacheKeySuffixTransformer.transform(sharedResourceUniqueKey); log.debug("Immediately deleting cache key while in transaction '" + cacheKey + "', then queuing it up for post-transaction cleanup to avoid race."); cache.delete(cacheKey); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(cacheKey))); return new Boolean(true); } SetSharedResourceLikeExecution(
            final DomainMapper<SetSharedResourceLikeMapperRequest, Boolean> inSetLikedResourceStatusMapper,
            final DomainMapper<SharedResourceRequest, SharedResource> inFindOrInsertSharedResourceMapper,
            final Cache inCache, final Transformer<String, String> inSharedResourceCacheKeySuffixTransformer); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
SetSharedResourceLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SetSharedResourceLikeRequest request = (SetSharedResourceLikeRequest) inActionContext.getActionContext() .getParams(); if (request == null || request.getUniqueKey() == null) { return new Boolean(false); } final String sharedResourceUniqueKey = request.getUniqueKey().toLowerCase(); final Long personId = inActionContext.getActionContext().getPrincipal().getId(); SharedResource sr = findOrInsertSharedResourceMapper.execute(new SharedResourceRequest( sharedResourceUniqueKey, null)); SetSharedResourceLikeMapperRequest mapperRequest = new SetSharedResourceLikeMapperRequest(personId, sr, request.getLikes()); setLikedResourceStatusMapper.execute(mapperRequest); String cacheKey = CacheKeys.SHARED_RESOURCE_BY_UNIQUE_KEY + sharedResourceCacheKeySuffixTransformer.transform(sharedResourceUniqueKey); log.debug("Immediately deleting cache key while in transaction '" + cacheKey + "', then queuing it up for post-transaction cleanup to avoid race."); cache.delete(cacheKey); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(cacheKey))); return new Boolean(true); } SetSharedResourceLikeExecution(
            final DomainMapper<SetSharedResourceLikeMapperRequest, Boolean> inSetLikedResourceStatusMapper,
            final DomainMapper<SharedResourceRequest, SharedResource> inFindOrInsertSharedResourceMapper,
            final Cache inCache, final Transformer<String, String> inSharedResourceCacheKeySuffixTransformer); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }