@Test public void performActionsDeleteGadget() throws Exception { final long targetGadgetId = GADGET6_ID; final List<Gadget> gadgets = buildGadgets(targetGadgetId); final Tab tab = context.mock(Tab.class); context.checking(new Expectations() { { oneOf(tabMapper).findTabByGadgetId(GADGET6_ID); will(returnValue(tab)); oneOf(tab).getGadgets(); will(returnValue(gadgets)); oneOf(tabMapper).deleteGadget(gadgets.get(5)); oneOf(principalMock).getId(); will(returnValue(1L)); allowing(deleteCacheKeysMapper).execute(with(any(Set.class))); oneOf(tabMapper).flush(); } }); ServiceActionContext currentContext = new ServiceActionContext(targetGadgetId, principalMock); sut.execute(currentContext); context.assertIsSatisfied(); }
@Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); List<Gadget> gadgets = tab.getGadgets(); int targetIndex = findTargetIndex(gadgets, gadgetId); if (targetIndex == INVALID_INDEX) { throw new ExecutionException("Gadget could not be deleted because gadget Id " + gadgetId + " was not found"); } try { tabMapper.deleteGadget(gadgets.get(targetIndex)); } catch (GadgetDeletionException e) { throw new ExecutionException("Error occurred deleting gadget.", e); } tabMapper.flush(); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tab; }
DeleteGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); List<Gadget> gadgets = tab.getGadgets(); int targetIndex = findTargetIndex(gadgets, gadgetId); if (targetIndex == INVALID_INDEX) { throw new ExecutionException("Gadget could not be deleted because gadget Id " + gadgetId + " was not found"); } try { tabMapper.deleteGadget(gadgets.get(targetIndex)); } catch (GadgetDeletionException e) { throw new ExecutionException("Error occurred deleting gadget.", e); } tabMapper.flush(); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tab; } }
DeleteGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); List<Gadget> gadgets = tab.getGadgets(); int targetIndex = findTargetIndex(gadgets, gadgetId); if (targetIndex == INVALID_INDEX) { throw new ExecutionException("Gadget could not be deleted because gadget Id " + gadgetId + " was not found"); } try { tabMapper.deleteGadget(gadgets.get(targetIndex)); } catch (GadgetDeletionException e) { throw new ExecutionException("Error occurred deleting gadget.", e); } tabMapper.flush(); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tab; } DeleteGadgetExecution(final TabMapper inTabMapper,
            final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); }
DeleteGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); List<Gadget> gadgets = tab.getGadgets(); int targetIndex = findTargetIndex(gadgets, gadgetId); if (targetIndex == INVALID_INDEX) { throw new ExecutionException("Gadget could not be deleted because gadget Id " + gadgetId + " was not found"); } try { tabMapper.deleteGadget(gadgets.get(targetIndex)); } catch (GadgetDeletionException e) { throw new ExecutionException("Error occurred deleting gadget.", e); } tabMapper.flush(); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tab; } DeleteGadgetExecution(final TabMapper inTabMapper,
            final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); @Override Serializable execute(final PrincipalActionContext inActionContext); }
DeleteGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); List<Gadget> gadgets = tab.getGadgets(); int targetIndex = findTargetIndex(gadgets, gadgetId); if (targetIndex == INVALID_INDEX) { throw new ExecutionException("Gadget could not be deleted because gadget Id " + gadgetId + " was not found"); } try { tabMapper.deleteGadget(gadgets.get(targetIndex)); } catch (GadgetDeletionException e) { throw new ExecutionException("Error occurred deleting gadget.", e); } tabMapper.flush(); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tab; } DeleteGadgetExecution(final TabMapper inTabMapper,
            final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); @Override Serializable execute(final PrincipalActionContext inActionContext);  }