@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 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 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 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); }
@SuppressWarnings("unchecked") @Test public void testExceptionInModifyListenerRecordsSuppressedExceptions() 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); Exception ex1 = new GeoWebCacheException("TEST1"); Exception ex2 = new IOException("TEST2"); listener1.handleModifyBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex1); listener2.handleModifyBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex2); EasyMock.replay(listener1, listener2); exception.expect( allOf( instanceOf(ConfigurationPersistenceException.class), hasProperty( "cause", allOf( sameInstance(ex2), hasProperty( "suppressed", arrayContainingInAnyOrder(sameInstance(ex1))))))); this.modifyInfo(this.config, 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))); }