@Test public void testUpdate$sessionFailure() throws Exception { PersonHandler sut = new PersonHandler(); final Name<String> resourceName = name("resource"); final DataSet data=empty(resourceName); sut.add(resourceName, data); new Expectations() {{ snapshot.name();result=resourceName; session.modify(snapshot); session.saveChanges();result=new WriteSessionException("FAILURE"); }}; try { sut.update(snapshot,empty(resourceName),session); fail("Should not modify if the session fails"); } catch (ApplicationRuntimeException e) { assertThat(e.getCause(),instanceOf(WriteSessionException.class)); assertThat(e.getCause().getMessage(),equalTo("FAILURE")); assertThat(sut.get(snapshot),sameInstance(data)); } }
@Test public void testUpdate$happyPath() throws Exception { PersonHandler sut = new PersonHandler(); final Name<String> resourceName = name("resource"); final DataSet data = withReadOnlyProperty(resourceName); sut.add(resourceName, data); new Expectations() {{ snapshot.name();result=resourceName; session.modify(snapshot); }}; DataSet modified = withReadOnlyProperty(resourceName); sut.update(snapshot,modified,session); assertThat(sut.get(snapshot),sameInstance(modified)); }
@Test public void testUpdate$validationFailure() throws Exception { PersonHandler sut = new PersonHandler(); final Name<String> resourceName = name("resource"); final DataSet data = withReadOnlyProperty(resourceName); sut.add(resourceName, data); new Expectations() {{ snapshot.name();result=resourceName; }}; try { sut.update(snapshot,empty(resourceName),session); fail("Should not modify if the session fails"); } catch (InconsistentContentException e) { assertThat(sut.get(snapshot),sameInstance(data)); } } }