@Test public void performActionWithNullAvatarId() throws Exception { context.checking(new Expectations() { { ignoring(servletContext); allowing(taskHandlerActionContext).getActionContext(); will(returnValue(actionContext)); allowing(actionContext).getPrincipal(); will(returnValue(principal)); allowing(actionContext).getParams(); will(returnValue(2L)); oneOf(finder).findEntity(principal, 2L); will(returnValue(person)); oneOf(person).getAvatarId(); will(returnValue(null)); oneOf(person).setAvatarId(null); oneOf(personMapper).flush(); } }); sut.execute(taskHandlerActionContext); context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Long entityId = (Long) inActionContext.getActionContext().getParams(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), entityId); } catch (Exception e) { throw new ExecutionException(e); } String avatarId = avatarEntity.getAvatarId(); if (avatarId != null) { imageWriter.delete("o" + avatarId); imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); } avatarEntity.setAvatarId(null); mapper.flush(); if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), avatarEntity.getId())); } return Boolean.TRUE; }
DeleteAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Long entityId = (Long) inActionContext.getActionContext().getParams(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), entityId); } catch (Exception e) { throw new ExecutionException(e); } String avatarId = avatarEntity.getAvatarId(); if (avatarId != null) { imageWriter.delete("o" + avatarId); imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); } avatarEntity.setAvatarId(null); mapper.flush(); if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), avatarEntity.getId())); } return Boolean.TRUE; } }
DeleteAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Long entityId = (Long) inActionContext.getActionContext().getParams(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), entityId); } catch (Exception e) { throw new ExecutionException(e); } String avatarId = avatarEntity.getAvatarId(); if (avatarId != null) { imageWriter.delete("o" + avatarId); imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); } avatarEntity.setAvatarId(null); mapper.flush(); if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), avatarEntity.getId())); } return Boolean.TRUE; } DeleteAvatarExecution(final DomainEntityMapper<T> inMapper,
            final ImageWriter inImageWriter, final EntityFinder<T> inFinder); }
DeleteAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Long entityId = (Long) inActionContext.getActionContext().getParams(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), entityId); } catch (Exception e) { throw new ExecutionException(e); } String avatarId = avatarEntity.getAvatarId(); if (avatarId != null) { imageWriter.delete("o" + avatarId); imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); } avatarEntity.setAvatarId(null); mapper.flush(); if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), avatarEntity.getId())); } return Boolean.TRUE; } DeleteAvatarExecution(final DomainEntityMapper<T> inMapper,
            final ImageWriter inImageWriter, final EntityFinder<T> inFinder); void setCacheUpdaterStategy(final CacheUpdater inCacheUpdaterStrategy); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
DeleteAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Long entityId = (Long) inActionContext.getActionContext().getParams(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), entityId); } catch (Exception e) { throw new ExecutionException(e); } String avatarId = avatarEntity.getAvatarId(); if (avatarId != null) { imageWriter.delete("o" + avatarId); imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); } avatarEntity.setAvatarId(null); mapper.flush(); if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), avatarEntity.getId())); } return Boolean.TRUE; } DeleteAvatarExecution(final DomainEntityMapper<T> inMapper,
            final ImageWriter inImageWriter, final EntityFinder<T> inFinder); void setCacheUpdaterStategy(final CacheUpdater inCacheUpdaterStrategy); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }