/** * Set up the configuration for a modify test with an info named "test". * * @return an info named "test" with a different value * @throws Exception */ protected BlobStoreInfo prepForModify() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); goodInfo = this.getGoodInfo("test", 2); return goodInfo; }
@Test public void testListenerDoesntHearFailureToRenameDueToBackend() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); this.config.addBlobStoreListener(listener); EasyMock.replay(listener); this.failNextWrite(); try { this.removeInfo(this.config, "test"); } catch (ConfigurationPersistenceException ex) { // Do Nothing } EasyMock.verify(listener); }
@Test public void testListenerDoesntHearFailureToModifyBadInfo() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); this.config.addBlobStoreListener(listener); BlobStoreInfo badInfo = this.getBadInfo("test", 1); EasyMock.replay(listener); try { this.modifyInfo(this.config, badInfo); } catch (IllegalArgumentException ex) { // Do Nothing } EasyMock.verify(listener); }
@Test public void testListenerDoesntHearFailureToModifyDueToBackend() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); this.config.addBlobStoreListener(listener); goodInfo = this.getGoodInfo("test", 2); EasyMock.replay(listener); this.failNextWrite(); try { this.modifyInfo(this.config, goodInfo); } catch (ConfigurationPersistenceException ex) { // Do Nothing } EasyMock.verify(listener); }
@Test public void testListenerDoesntHearFailureToRenameDuplicate() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); BlobStoreInfo goodInfo2 = this.getGoodInfo("test2", 1); this.addInfo(this.config, goodInfo2); this.config.addBlobStoreListener(listener); EasyMock.replay(listener); try { this.renameInfo(this.config, "test", "test2"); } catch (IllegalArgumentException ex) { // Do Nothing } EasyMock.verify(listener); }
@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 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 testListenerDoesntHearFailureToAddDueToBackend() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); // listener.handleAddBlobStore(EasyMock.eq(badInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.failNextWrite(); try { this.addInfo(this.config, goodInfo); } catch (ConfigurationPersistenceException ex) { // Do Nothing } EasyMock.verify(listener); }
@Test public void testListenerHearsRemove() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); listener.handleRemoveBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.removeInfo(this.config, "test"); EasyMock.verify(listener); }
@Test public void testListenerHearsModify() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); listener.handleModifyBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.doModifyInfo(goodInfo, 2); this.config.modifyBlobStore(goodInfo); EasyMock.verify(listener); }
@Test public void testExceptionInAddListenerNotRolledBack() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.config.addBlobStoreListener(listener); listener.handleAddBlobStore(goodInfo); GeoWebCacheException ex = new GeoWebCacheException("TEST"); EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); try { this.addInfo(this.config, goodInfo); } catch (ConfigurationPersistenceException ex2) { // Do Nothing } assertThat(this.getInfo(config, "test"), isPresent(equalTo(goodInfo))); }
@Test public void testExceptionInRemoveListenerNotRolledBack() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = prepForRemove(); this.config.addBlobStoreListener(listener); GeoWebCacheException ex = new GeoWebCacheException("TEST"); listener.handleRemoveBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); try { this.removeInfo(this.config, "test"); } catch (ConfigurationPersistenceException ex2) { // Do Nothing } assertThat(this.getInfo(config, "test"), notPresent()); }
@Test public void testExceptionInModifyListenerIsWrapped() 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); exception.expect( allOf( instanceOf(ConfigurationPersistenceException.class), hasProperty("cause", sameInstance(ex)))); this.modifyInfo(this.config, goodInfo); }
@Test public void testExceptionInRemoveListenerIsWrapped() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = prepForRemove(); this.config.addBlobStoreListener(listener); GeoWebCacheException ex = new GeoWebCacheException("TEST"); listener.handleRemoveBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); exception.expect( allOf( instanceOf(ConfigurationPersistenceException.class), hasProperty("cause", sameInstance(ex)))); this.removeInfo(this.config, "test"); }
@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))); } }
@Test public void testListenerDoesntHearFailureToModifyDoesntExist() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); EasyMock.replay(listener); try { this.modifyInfo(this.config, goodInfo); } catch (NoSuchElementException ex) { // Do Nothing } EasyMock.verify(listener); }
@Test public void testListenerDoesntHearFailureToAddBadInfo() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); BlobStoreInfo badInfo = this.getBadInfo("test", 1); // listener.handleAddBlobStore(EasyMock.eq(badInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); try { this.addInfo(this.config, badInfo); } catch (IllegalArgumentException ex) { // Do Nothing } EasyMock.verify(listener); }
@Test public void testRollBackOnUnsuitableStorageExceptionInAddHandler() throws Exception { BlobStoreInfo info = getGoodInfo("test", 1); BlobStoreConfigurationListener listener = createMock(BlobStoreConfigurationListener.class); listener.handleAddBlobStore(info); expectLastCall().andThrow(new UnsuitableStorageException("TEST")); EasyMock.replay(listener); config.addBlobStoreListener(listener); exception.expect(instanceOf(ConfigurationPersistenceException.class)); exception.expectCause(instanceOf(UnsuitableStorageException.class)); try { config.addBlobStore(info); } finally { verify(listener); assertThat(config.getBlobStore("test"), notPresent()); } }
@Test public void testExceptionInModifyListenerDoesntBlockOtherListeners() throws Exception { BlobStoreConfigurationListener listener1 = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreConfigurationListener listener2 = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = prepForModify(); this.config.addBlobStoreListener(listener1); this.config.addBlobStoreListener(listener2); GeoWebCacheException ex1 = new GeoWebCacheException("TEST1"); listener1.handleModifyBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex1); listener2.handleModifyBlobStore(goodInfo); EasyMock.expectLastCall().once(); EasyMock.replay(listener1, listener2); try { this.modifyInfo(this.config, goodInfo); } catch (ConfigurationPersistenceException ex3) { // Do Nothing } EasyMock.verify(listener2); }
@Test public void testExceptionInRemoveListenerDoesntBlockOtherListeners() throws Exception { BlobStoreConfigurationListener listener1 = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreConfigurationListener listener2 = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = prepForRemove(); this.config.addBlobStoreListener(listener1); this.config.addBlobStoreListener(listener2); GeoWebCacheException ex1 = new GeoWebCacheException("TEST1"); listener1.handleRemoveBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex1); listener2.handleRemoveBlobStore(goodInfo); EasyMock.expectLastCall().once(); EasyMock.replay(listener1, listener2); try { this.removeInfo(this.config, "test"); } catch (ConfigurationPersistenceException ex3) { // Do Nothing } EasyMock.verify(listener2); }