@SuppressWarnings("unchecked") @Test public void testExecute() { final Transformer<ActionContext, Serializable> parameterSupplier = context.mock(Transformer.class, "parameterSupplier"); final DomainMapper<Serializable, Serializable> domainMapper = context.mock(DomainMapper.class, "domainMapper"); final Cache cache = context.mock(Cache.class); final Transformer<ActionContext, Serializable> cacheKeyParameterSupplier = context.mock(Transformer.class, "cacheKeyParameterSupplier"); final Serializable params = context.mock(Serializable.class, "params"); final Serializable extractedParams = context.mock(Serializable.class, "extractedParams"); final Serializable result = context.mock(Serializable.class, "result"); final String cacheKeyPrefix = "PREFIX"; final String cacheKeySuffix = "SUFFIX"; final String cacheKey = cacheKeyPrefix + cacheKeySuffix; TaskHandlerExecutionStrategy<PrincipalActionContext> sut = new ExecuteDomainMapperClearCacheExecution( parameterSupplier, domainMapper, cache, cacheKeyPrefix, cacheKeyParameterSupplier); final TaskHandlerActionContext<PrincipalActionContext> actionContext = TestContextCreator .createTaskHandlerContextWithPrincipal(params, "user", 9L); context.checking(new Expectations() { { oneOf(parameterSupplier).transform(actionContext.getActionContext()); will(returnValue(extractedParams)); oneOf(domainMapper).execute(extractedParams); will(returnValue(result)); oneOf(cacheKeyParameterSupplier).transform(actionContext.getActionContext()); will(returnValue(cacheKeySuffix)); oneOf(cache).delete(cacheKey); } }); Serializable results = sut.execute(actionContext); context.assertIsSatisfied(); assertSame(result, results); assertEquals(1, actionContext.getUserActionRequests().size()); UserActionRequest request = actionContext.getUserActionRequests().get(0); assertEquals("deleteCacheKeysAction", request.getActionKey()); assertEquals(1, ((Set<String>) request.getParams()).size()); assertTrue(((Set<String>) request.getParams()).contains(cacheKey)); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { PrincipalActionContext realContext = inActionContext.getActionContext(); Serializable param = parameterSupplier.transform(realContext); Serializable result = domainMapper.execute(param); String key = cacheKeyPrefix + cacheKeyParameterSupplier.transform(realContext); cache.delete(key); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(key))); return result; }
ExecuteDomainMapperClearCacheExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { PrincipalActionContext realContext = inActionContext.getActionContext(); Serializable param = parameterSupplier.transform(realContext); Serializable result = domainMapper.execute(param); String key = cacheKeyPrefix + cacheKeyParameterSupplier.transform(realContext); cache.delete(key); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(key))); return result; } }
ExecuteDomainMapperClearCacheExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { PrincipalActionContext realContext = inActionContext.getActionContext(); Serializable param = parameterSupplier.transform(realContext); Serializable result = domainMapper.execute(param); String key = cacheKeyPrefix + cacheKeyParameterSupplier.transform(realContext); cache.delete(key); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(key))); return result; } ExecuteDomainMapperClearCacheExecution(final Transformer<ActionContext, Serializable> inParameterSupplier,
            final DomainMapper<Serializable, Serializable> inDomainMapper, final Cache inCache,
            final String inCacheKeyPrefix, final Transformer<ActionContext, Serializable> inCacheKeyParameterSupplier); }
ExecuteDomainMapperClearCacheExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { PrincipalActionContext realContext = inActionContext.getActionContext(); Serializable param = parameterSupplier.transform(realContext); Serializable result = domainMapper.execute(param); String key = cacheKeyPrefix + cacheKeyParameterSupplier.transform(realContext); cache.delete(key); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(key))); return result; } ExecuteDomainMapperClearCacheExecution(final Transformer<ActionContext, Serializable> inParameterSupplier,
            final DomainMapper<Serializable, Serializable> inDomainMapper, final Cache inCache,
            final String inCacheKeyPrefix, final Transformer<ActionContext, Serializable> inCacheKeyParameterSupplier); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
ExecuteDomainMapperClearCacheExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { PrincipalActionContext realContext = inActionContext.getActionContext(); Serializable param = parameterSupplier.transform(realContext); Serializable result = domainMapper.execute(param); String key = cacheKeyPrefix + cacheKeyParameterSupplier.transform(realContext); cache.delete(key); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections.singleton(key))); return result; } ExecuteDomainMapperClearCacheExecution(final Transformer<ActionContext, Serializable> inParameterSupplier,
            final DomainMapper<Serializable, Serializable> inDomainMapper, final Cache inCache,
            final String inCacheKeyPrefix, final Transformer<ActionContext, Serializable> inCacheKeyParameterSupplier); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }