/** * Adds a {@link BlobStoreConfigurationListener} to each {@link BlobStoreConfiguration} tracked * by this aggregator * * @param listener the listener */ public void addListener(BlobStoreConfigurationListener listener) { for (BlobStoreConfiguration c : getConfigs()) { c.addBlobStoreListener(listener); } }
@Test public void testListenerDoesntHearFailureToRemoveDoesntExist() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); EasyMock.replay(listener); try { this.removeInfo(this.config, "test"); } catch (NoSuchElementException ex) { // Do Nothing } EasyMock.verify(listener); }
@Test public void testListenerDoesntHearFailureToRenameDoesntExist() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); EasyMock.replay(listener); try { this.renameInfo(this.config, "test", "test2"); } catch (NoSuchElementException ex) { // Do Nothing } EasyMock.verify(listener); }
@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 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 testRemoveListener() throws Exception { BlobStoreConfigurationListener listener1 = EasyMock.createMock("listener1", BlobStoreConfigurationListener.class); BlobStoreConfigurationListener listener2 = EasyMock.createMock("listener2", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener1); this.config.addBlobStoreListener(listener2); this.config.removeBlobStoreListener(listener1); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); listener2.handleAddBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener1, listener2); this.addInfo(this.config, goodInfo); EasyMock.verify(listener1, listener2); }
@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 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 testListenerDoesntHearFailureToRemoveDueToBackend() 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 testListenerHearsAdd() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); listener.handleAddBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.addInfo(this.config, goodInfo); 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 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 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 testExceptionInRenameListenerIsWrapped() 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); exception.expect( allOf( instanceOf(ConfigurationPersistenceException.class), hasProperty("cause", sameInstance(ex)))); this.renameInfo(this.config, "test", "test2"); }
@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 testExceptionInAddListenerIsWrapped() 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); exception.expect( allOf( instanceOf(ConfigurationPersistenceException.class), hasProperty("cause", sameInstance(ex)))); this.addInfo(this.config, goodInfo); }
@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 testListenerHearsRename() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); BlobStoreInfo expectedInfo = this.getGoodInfo("newName", 1); this.addInfo(this.config, goodInfo); BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); listener.handleRenameBlobStore(EasyMock.eq("test"), EasyMock.eq(expectedInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.config.renameBlobStore("test", "newName"); EasyMock.verify(listener); }