@Test public void testExceptionInRenameListenerNotRolledBack() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = prepForRename(); this.config.addBlobStoreListener(listener); GeoWebCacheException ex = new GeoWebCacheException("TEST"); listener.handleRenameBlobStore("test", goodInfo); EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); try { this.renameInfo(this.config, "test", "test2"); } catch (ConfigurationPersistenceException ex2) { // Do Nothing } assertThat(this.getInfo(config, "test2"), isPresent(infoEquals(goodInfo))); }
@Test public void testExceptionInModifyListenerNotRolledBack() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = prepForModify(); this.config.addBlobStoreListener(listener); GeoWebCacheException ex = new GeoWebCacheException("TEST"); listener.handleModifyBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); try { this.modifyInfo(this.config, goodInfo); } catch (ConfigurationPersistenceException ex2) { // Do Nothing } assertThat(this.getInfo(config, "test"), isPresent(infoEquals(2))); }
@Test public void testRollBackOnUnsuitableStorageExceptionInModifyHandler() throws Exception { BlobStoreInfo info1 = getGoodInfo("test", 1); BlobStoreInfo info2 = getGoodInfo("test", 2); BlobStoreConfigurationListener listener = createMock(BlobStoreConfigurationListener.class); listener.handleAddBlobStore(info1); expectLastCall(); listener.handleModifyBlobStore(info2); expectLastCall().andThrow(new UnsuitableStorageException("TEST")); EasyMock.replay(listener); config.addBlobStoreListener(listener); config.addBlobStore(info1); exception.expect(instanceOf(ConfigurationPersistenceException.class)); exception.expectCause(instanceOf(UnsuitableStorageException.class)); try { config.modifyBlobStore(info2); } finally { verify(listener); assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1))); } }
} finally { control.verify(); assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1)));