@Test public void testModifyDenied() { state.put("person", person); final Stream modifiedStream = new Stream(); modifiedStream.setId(2L); modifiedStream.setName("New Name"); modifiedStream.setRequest("{ query : { keywords : 'test' } }"); modifiedStream.setReadOnly(false); final List<Stream> streams = new ArrayList<Stream>(); final Stream oldStream = new Stream(); oldStream.setId(1L); oldStream.setName("Old Name"); oldStream.setRequest("{ query : { keywords : 'cheese' } }"); oldStream.setReadOnly(true); streams.add(oldStream); CONTEXT.checking(new Expectations() { { oneOf(actionContext).getState(); will(returnValue(state)); oneOf(person).getStreams(); will(returnValue(streams)); oneOf(actionContext).getParams(); will(returnValue(modifiedStream)); } }); sut.execute(actionContext); Assert.assertEquals(1, streams.size()); Assert.assertEquals(oldStream.getName(), streams.get(0).getName()); Assert.assertEquals(oldStream.getRequest(), streams.get(0).getRequest()); Assert.assertEquals(oldStream.getReadOnly(), streams.get(0).getReadOnly()); CONTEXT.assertIsSatisfied(); }
public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Person person = (Person) inActionContext.getState().get("person"); if (person == null) { person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); } List<Stream> streams = person.getStreams(); Stream stream = (Stream) inActionContext.getParams(); stream.setReadOnly(false); if (0L != stream.getId()) { for (Stream s : streams) { if (s.getId() == stream.getId()) { s.setName(stream.getName()); s.setReadOnly(stream.getReadOnly()); s.setRequest(stream.getRequest()); } } } else { streams.add(stream); } return stream; }
ModifyStreamForCurrentUserExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Person person = (Person) inActionContext.getState().get("person"); if (person == null) { person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); } List<Stream> streams = person.getStreams(); Stream stream = (Stream) inActionContext.getParams(); stream.setReadOnly(false); if (0L != stream.getId()) { for (Stream s : streams) { if (s.getId() == stream.getId()) { s.setName(stream.getName()); s.setReadOnly(stream.getReadOnly()); s.setRequest(stream.getRequest()); } } } else { streams.add(stream); } return stream; } }
ModifyStreamForCurrentUserExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Person person = (Person) inActionContext.getState().get("person"); if (person == null) { person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); } List<Stream> streams = person.getStreams(); Stream stream = (Stream) inActionContext.getParams(); stream.setReadOnly(false); if (0L != stream.getId()) { for (Stream s : streams) { if (s.getId() == stream.getId()) { s.setName(stream.getName()); s.setReadOnly(stream.getReadOnly()); s.setRequest(stream.getRequest()); } } } else { streams.add(stream); } return stream; } ModifyStreamForCurrentUserExecution(final FindByIdMapper<Person> inPersonMapper); }
ModifyStreamForCurrentUserExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Person person = (Person) inActionContext.getState().get("person"); if (person == null) { person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); } List<Stream> streams = person.getStreams(); Stream stream = (Stream) inActionContext.getParams(); stream.setReadOnly(false); if (0L != stream.getId()) { for (Stream s : streams) { if (s.getId() == stream.getId()) { s.setName(stream.getName()); s.setReadOnly(stream.getReadOnly()); s.setRequest(stream.getRequest()); } } } else { streams.add(stream); } return stream; } ModifyStreamForCurrentUserExecution(final FindByIdMapper<Person> inPersonMapper); Serializable execute(final PrincipalActionContext inActionContext); }
ModifyStreamForCurrentUserExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { Person person = (Person) inActionContext.getState().get("person"); if (person == null) { person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); } List<Stream> streams = person.getStreams(); Stream stream = (Stream) inActionContext.getParams(); stream.setReadOnly(false); if (0L != stream.getId()) { for (Stream s : streams) { if (s.getId() == stream.getId()) { s.setName(stream.getName()); s.setReadOnly(stream.getReadOnly()); s.setRequest(stream.getRequest()); } } } else { streams.add(stream); } return stream; } ModifyStreamForCurrentUserExecution(final FindByIdMapper<Person> inPersonMapper); Serializable execute(final PrincipalActionContext inActionContext);  }