@Test public void testExecuteNoChanges() throws Exception { final String userPrefsJson = "{'userPref1':'value1','userPref2':'value2'}"; final GadgetUserPrefActionRequest requestParam = new GadgetUserPrefActionRequest(new Long(1L), userPrefsJson); context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(requestParam)); allowing(testGadget).getOwner(); will(returnValue(owner)); allowing(owner).getId(); will(returnValue(9L)); oneOf(findGadgetByIdMapper).execute(with(any(FindByIdRequest.class))); will(returnValue(testGadget)); oneOf(testGadget).getGadgetUserPref(); will(returnValue(userPrefsJson)); } }); sut.execute(actionContext); context.assertIsSatisfied(); }
@Override public String execute(final ActionContext inActionContext) { GadgetUserPrefActionRequest currentRequest = (GadgetUserPrefActionRequest) inActionContext.getParams(); logger.debug("Updating user prefs for gadget: " + currentRequest.getGadgetId() + " with: " + currentRequest.getGadgetUserPref()); Gadget currentGadgetInstance = findGadgetByIdMapper.execute(new FindByIdRequest("Gadget", currentRequest .getGadgetId())); String oldVal = currentGadgetInstance.getGadgetUserPref(); String newVal = currentRequest.getGadgetUserPref(); if (StringUtils.equalsIgnoreCase(oldVal, newVal)) { logger.debug("prefs didn't change; i refuse to update them"); return oldVal; } currentGadgetInstance.setGadgetUserPref(newVal); updateMapper.execute(new PersistenceRequest<Gadget>(currentGadgetInstance)); pageMapper.execute(currentGadgetInstance.getOwner().getId()); return currentGadgetInstance.getGadgetUserPref(); }
UpdateGadgetUserPrefByIdExecution implements ExecutionStrategy<ActionContext> { @Override public String execute(final ActionContext inActionContext) { GadgetUserPrefActionRequest currentRequest = (GadgetUserPrefActionRequest) inActionContext.getParams(); logger.debug("Updating user prefs for gadget: " + currentRequest.getGadgetId() + " with: " + currentRequest.getGadgetUserPref()); Gadget currentGadgetInstance = findGadgetByIdMapper.execute(new FindByIdRequest("Gadget", currentRequest .getGadgetId())); String oldVal = currentGadgetInstance.getGadgetUserPref(); String newVal = currentRequest.getGadgetUserPref(); if (StringUtils.equalsIgnoreCase(oldVal, newVal)) { logger.debug("prefs didn't change; i refuse to update them"); return oldVal; } currentGadgetInstance.setGadgetUserPref(newVal); updateMapper.execute(new PersistenceRequest<Gadget>(currentGadgetInstance)); pageMapper.execute(currentGadgetInstance.getOwner().getId()); return currentGadgetInstance.getGadgetUserPref(); } }
UpdateGadgetUserPrefByIdExecution implements ExecutionStrategy<ActionContext> { @Override public String execute(final ActionContext inActionContext) { GadgetUserPrefActionRequest currentRequest = (GadgetUserPrefActionRequest) inActionContext.getParams(); logger.debug("Updating user prefs for gadget: " + currentRequest.getGadgetId() + " with: " + currentRequest.getGadgetUserPref()); Gadget currentGadgetInstance = findGadgetByIdMapper.execute(new FindByIdRequest("Gadget", currentRequest .getGadgetId())); String oldVal = currentGadgetInstance.getGadgetUserPref(); String newVal = currentRequest.getGadgetUserPref(); if (StringUtils.equalsIgnoreCase(oldVal, newVal)) { logger.debug("prefs didn't change; i refuse to update them"); return oldVal; } currentGadgetInstance.setGadgetUserPref(newVal); updateMapper.execute(new PersistenceRequest<Gadget>(currentGadgetInstance)); pageMapper.execute(currentGadgetInstance.getOwner().getId()); return currentGadgetInstance.getGadgetUserPref(); } UpdateGadgetUserPrefByIdExecution(final UpdateMapper<Gadget> inUpdateMapper,
            final FindByIdMapper<Gadget> inFindGadgetByIdMapper, final DomainMapper<Long, Object> inPageMapper); }
UpdateGadgetUserPrefByIdExecution implements ExecutionStrategy<ActionContext> { @Override public String execute(final ActionContext inActionContext) { GadgetUserPrefActionRequest currentRequest = (GadgetUserPrefActionRequest) inActionContext.getParams(); logger.debug("Updating user prefs for gadget: " + currentRequest.getGadgetId() + " with: " + currentRequest.getGadgetUserPref()); Gadget currentGadgetInstance = findGadgetByIdMapper.execute(new FindByIdRequest("Gadget", currentRequest .getGadgetId())); String oldVal = currentGadgetInstance.getGadgetUserPref(); String newVal = currentRequest.getGadgetUserPref(); if (StringUtils.equalsIgnoreCase(oldVal, newVal)) { logger.debug("prefs didn't change; i refuse to update them"); return oldVal; } currentGadgetInstance.setGadgetUserPref(newVal); updateMapper.execute(new PersistenceRequest<Gadget>(currentGadgetInstance)); pageMapper.execute(currentGadgetInstance.getOwner().getId()); return currentGadgetInstance.getGadgetUserPref(); } UpdateGadgetUserPrefByIdExecution(final UpdateMapper<Gadget> inUpdateMapper,
            final FindByIdMapper<Gadget> inFindGadgetByIdMapper, final DomainMapper<Long, Object> inPageMapper); @Override String execute(final ActionContext inActionContext); }
UpdateGadgetUserPrefByIdExecution implements ExecutionStrategy<ActionContext> { @Override public String execute(final ActionContext inActionContext) { GadgetUserPrefActionRequest currentRequest = (GadgetUserPrefActionRequest) inActionContext.getParams(); logger.debug("Updating user prefs for gadget: " + currentRequest.getGadgetId() + " with: " + currentRequest.getGadgetUserPref()); Gadget currentGadgetInstance = findGadgetByIdMapper.execute(new FindByIdRequest("Gadget", currentRequest .getGadgetId())); String oldVal = currentGadgetInstance.getGadgetUserPref(); String newVal = currentRequest.getGadgetUserPref(); if (StringUtils.equalsIgnoreCase(oldVal, newVal)) { logger.debug("prefs didn't change; i refuse to update them"); return oldVal; } currentGadgetInstance.setGadgetUserPref(newVal); updateMapper.execute(new PersistenceRequest<Gadget>(currentGadgetInstance)); pageMapper.execute(currentGadgetInstance.getOwner().getId()); return currentGadgetInstance.getGadgetUserPref(); } UpdateGadgetUserPrefByIdExecution(final UpdateMapper<Gadget> inUpdateMapper,
            final FindByIdMapper<Gadget> inFindGadgetByIdMapper, final DomainMapper<Long, Object> inPageMapper); @Override String execute(final ActionContext inActionContext);  }