/** * Set up the configuration for a remove test with an info named "test". * * @return the info that was added * @throws Exception */ protected BlobStoreInfo prepForRemove() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); return goodInfo; }
@Test public void testListenerDoesntHearFailureToAddDuplicate() throws Exception { BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); BlobStoreInfo goodInfo2 = this.getGoodInfo("test", 2); // listener.handleAddBlobStore(EasyMock.eq(badInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.config.addBlobStoreListener(listener); try { this.addInfo(this.config, goodInfo2); } catch (IllegalArgumentException ex) { // Do Nothing } EasyMock.verify(listener); }
/** * 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; }
/** * Set up the configuration for a rename test with an info named "test". * * @return an info named "test2" * @throws Exception */ protected BlobStoreInfo prepForRename() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); goodInfo = this.getGoodInfo("test2", 1); return goodInfo; }
@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 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 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 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 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 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 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 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 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 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 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 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); }
@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 testMultipleListenersHearAdd() throws Exception { BlobStoreConfigurationListener listener1 = EasyMock.createMock("listener1", BlobStoreConfigurationListener.class); BlobStoreConfigurationListener listener2 = EasyMock.createMock("listener2", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener1); this.config.addBlobStoreListener(listener2); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); listener1.handleAddBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); listener2.handleAddBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener1, listener2); this.addInfo(this.config, goodInfo); EasyMock.verify(listener1, listener2); }
@Test public void testExceptionInAddListenerDoesntBlockOtherListeners() throws Exception { BlobStoreConfigurationListener listener1 = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreConfigurationListener listener2 = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.config.addBlobStoreListener(listener1); this.config.addBlobStoreListener(listener2); GeoWebCacheException ex1 = new GeoWebCacheException("TEST1"); listener1.handleAddBlobStore(goodInfo); EasyMock.expectLastCall().andThrow(ex1); listener2.handleAddBlobStore(goodInfo); EasyMock.expectLastCall().once(); EasyMock.replay(listener1, listener2); try { this.addInfo(this.config, goodInfo); } catch (ConfigurationPersistenceException ex3) { // Do Nothing } EasyMock.verify(listener2); }