@Test public void performActionWithOutRefresh() throws Exception { final ResizeAvatarRequest request = new ResizeAvatarRequest(1, 2, 3, Boolean.FALSE, 1L); context.checking(new Expectations() { { ignoring(user); allowing(taskHandlerActionContext).getActionContext(); will(returnValue(actionContext)); allowing(actionContext).getParams(); will(returnValue(request)); allowing(actionContext).getPrincipal(); will(returnValue(principal)); oneOf(finder).findEntity(principal, 1L); will(returnValue(person)); oneOf(person).getAvatarId(); allowing(person).getId(); allowing(imageMock).getWidth(null); will(returnValue(imageWidth)); allowing(imageMock).getHeight(null); will(returnValue(imageHeight)); allowing(imageMock).getWidth(); will(returnValue(imageWidth)); allowing(imageMock).getHeight(); will(returnValue(imageHeight)); allowing(imageMock).getSubimage(1, 2, 3, 3); will(returnValue(imageMock)); allowing(imageMock).getColorModel(); allowing(imageMock).getType(); allowing(imageMock).getRaster(); allowing(imageMock).getAccelerationPriority(); allowing(imageMock).getSampleModel(); oneOf(person).setAvatarCropX(1); oneOf(person).setAvatarCropY(2); oneOf(person).setAvatarCropSize(3); oneOf(personMapper).flush(); oneOf(imageWriter).read(with(any(String.class))); will(returnValue(imageMock)); exactly(2).of(imageWriter).write(with(any(RenderedImage.class)), with(any(String.class))); } }); sut.execute(taskHandlerActionContext); context.assertIsSatisfied(); }
@Override public T execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ResizeAvatarRequest request = (ResizeAvatarRequest) inActionContext.getActionContext().getParams(); Integer x = request.getX(); Integer y = request.getY(); Integer size = request.getSize(); Boolean refreshFiles = request.getRefreshFiles(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), request.getEntityId()); } catch (Exception e1) { throw new ExecutionException(e1); } String avatarId = avatarEntity.getAvatarId(); if (refreshFiles) { imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); String originalPath = "o" + avatarId; avatarId = hasher.hash(((Long) avatarEntity.getId()).toString()); avatarEntity.setAvatarId(avatarId); imageWriter.rename(originalPath, "o" + avatarId); } avatarEntity.setAvatarCropX(x); avatarEntity.setAvatarCropY(y); avatarEntity.setAvatarCropSize(size); mapper.flush(); try { BufferedImage bufferedImage = (BufferedImage) imageWriter.read("o" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, NORMAL_AVATAR_SIZE, size), "n" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, SMALL_AVATAR_SIZE, size), "s" + avatarId); } catch (Exception e) { log.error("Error resizing avatar", e); return null; } if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), request.getEntityId())); } return avatarEntity; }
ResizeAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public T execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ResizeAvatarRequest request = (ResizeAvatarRequest) inActionContext.getActionContext().getParams(); Integer x = request.getX(); Integer y = request.getY(); Integer size = request.getSize(); Boolean refreshFiles = request.getRefreshFiles(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), request.getEntityId()); } catch (Exception e1) { throw new ExecutionException(e1); } String avatarId = avatarEntity.getAvatarId(); if (refreshFiles) { imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); String originalPath = "o" + avatarId; avatarId = hasher.hash(((Long) avatarEntity.getId()).toString()); avatarEntity.setAvatarId(avatarId); imageWriter.rename(originalPath, "o" + avatarId); } avatarEntity.setAvatarCropX(x); avatarEntity.setAvatarCropY(y); avatarEntity.setAvatarCropSize(size); mapper.flush(); try { BufferedImage bufferedImage = (BufferedImage) imageWriter.read("o" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, NORMAL_AVATAR_SIZE, size), "n" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, SMALL_AVATAR_SIZE, size), "s" + avatarId); } catch (Exception e) { log.error("Error resizing avatar", e); return null; } if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), request.getEntityId())); } return avatarEntity; } }
ResizeAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public T execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ResizeAvatarRequest request = (ResizeAvatarRequest) inActionContext.getActionContext().getParams(); Integer x = request.getX(); Integer y = request.getY(); Integer size = request.getSize(); Boolean refreshFiles = request.getRefreshFiles(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), request.getEntityId()); } catch (Exception e1) { throw new ExecutionException(e1); } String avatarId = avatarEntity.getAvatarId(); if (refreshFiles) { imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); String originalPath = "o" + avatarId; avatarId = hasher.hash(((Long) avatarEntity.getId()).toString()); avatarEntity.setAvatarId(avatarId); imageWriter.rename(originalPath, "o" + avatarId); } avatarEntity.setAvatarCropX(x); avatarEntity.setAvatarCropY(y); avatarEntity.setAvatarCropSize(size); mapper.flush(); try { BufferedImage bufferedImage = (BufferedImage) imageWriter.read("o" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, NORMAL_AVATAR_SIZE, size), "n" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, SMALL_AVATAR_SIZE, size), "s" + avatarId); } catch (Exception e) { log.error("Error resizing avatar", e); return null; } if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), request.getEntityId())); } return avatarEntity; } ResizeAvatarExecution(final DomainEntityMapper<T> inMapper, final HashGeneratorStrategy inHasher,
            final ImageWriter inImageWriter, final EntityFinder<T> inFinder); }
ResizeAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public T execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ResizeAvatarRequest request = (ResizeAvatarRequest) inActionContext.getActionContext().getParams(); Integer x = request.getX(); Integer y = request.getY(); Integer size = request.getSize(); Boolean refreshFiles = request.getRefreshFiles(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), request.getEntityId()); } catch (Exception e1) { throw new ExecutionException(e1); } String avatarId = avatarEntity.getAvatarId(); if (refreshFiles) { imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); String originalPath = "o" + avatarId; avatarId = hasher.hash(((Long) avatarEntity.getId()).toString()); avatarEntity.setAvatarId(avatarId); imageWriter.rename(originalPath, "o" + avatarId); } avatarEntity.setAvatarCropX(x); avatarEntity.setAvatarCropY(y); avatarEntity.setAvatarCropSize(size); mapper.flush(); try { BufferedImage bufferedImage = (BufferedImage) imageWriter.read("o" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, NORMAL_AVATAR_SIZE, size), "n" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, SMALL_AVATAR_SIZE, size), "s" + avatarId); } catch (Exception e) { log.error("Error resizing avatar", e); return null; } if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), request.getEntityId())); } return avatarEntity; } ResizeAvatarExecution(final DomainEntityMapper<T> inMapper, final HashGeneratorStrategy inHasher,
            final ImageWriter inImageWriter, final EntityFinder<T> inFinder); void setCacheUpdaterStategy(final CacheUpdater inCacheUpdaterStrategy); @Override T execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
ResizeAvatarExecution implements
        TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public T execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ResizeAvatarRequest request = (ResizeAvatarRequest) inActionContext.getActionContext().getParams(); Integer x = request.getX(); Integer y = request.getY(); Integer size = request.getSize(); Boolean refreshFiles = request.getRefreshFiles(); T avatarEntity; try { avatarEntity = finder.findEntity(inActionContext.getActionContext().getPrincipal(), request.getEntityId()); } catch (Exception e1) { throw new ExecutionException(e1); } String avatarId = avatarEntity.getAvatarId(); if (refreshFiles) { imageWriter.delete("n" + avatarId); imageWriter.delete("s" + avatarId); String originalPath = "o" + avatarId; avatarId = hasher.hash(((Long) avatarEntity.getId()).toString()); avatarEntity.setAvatarId(avatarId); imageWriter.rename(originalPath, "o" + avatarId); } avatarEntity.setAvatarCropX(x); avatarEntity.setAvatarCropY(y); avatarEntity.setAvatarCropSize(size); mapper.flush(); try { BufferedImage bufferedImage = (BufferedImage) imageWriter.read("o" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, NORMAL_AVATAR_SIZE, size), "n" + avatarId); imageWriter.write(createResizedCopy(bufferedImage, x, y, SMALL_AVATAR_SIZE, size), "s" + avatarId); } catch (Exception e) { log.error("Error resizing avatar", e); return null; } if (cacheUpdaterStategy != null) { inActionContext.getUserActionRequests().addAll( cacheUpdaterStategy.getUpdateCacheRequests(inActionContext.getActionContext().getPrincipal(), request.getEntityId())); } return avatarEntity; } ResizeAvatarExecution(final DomainEntityMapper<T> inMapper, final HashGeneratorStrategy inHasher,
            final ImageWriter inImageWriter, final EntityFinder<T> inFinder); void setCacheUpdaterStategy(final CacheUpdater inCacheUpdaterStrategy); @Override T execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }