@Override public void setProperty(String name, String value) { if (!isUpdateable(name)) { if(value.equalsIgnoreCase(unencryptedContentStoreBeanName)) { throw new IllegalStateException("Switching to an unencrypted content store is not possible."); } if(value.equalsIgnoreCase(encryptedContentStoreBeanName)) { throw new IllegalStateException("Switching to an encrypted content store is not licensed."); } throw new IllegalStateException("Switching to an unknown content store is not possible." + value); } super.setProperty(name, value); } }
if (name.equals(SOURCE_BEAN_PROPERTY)) if(getCurrentSourceBeanName().equals(unencryptedContentStoreBeanName)) if(!getCurrentSourceBeanName().equals(unencryptedContentStoreBeanName))
private void initSwitchableContext(String sourceBeanName) { switchableContext.setSourceBeanName(sourceBeanName); switchableContext.setPropertyDefaults(new Properties()); switchableContext.setUnencryptedContentStoreBeanName(UNENCRYPTED_STORE_SUBSYSTEM); switchableContext.setRegistry(propertyBackedBeanRegistry); switchableContext.setApplicationContext(parentContext); switchableContext.init(); }
@Test public void canSetSourceBeanWhenCurrentStoreIsUnencrypted() { initSwitchableContext(UNENCRYPTED_STORE_SUBSYSTEM); switchableContext.setProperty(SOURCE_BEAN_NAME_PROPERTY, ENCRYPTED_STORE_SUBSYSTEM); assertEquals(ENCRYPTED_STORE_SUBSYSTEM, switchableContext.getProperty(SOURCE_BEAN_NAME_PROPERTY)); }
@Before public void setUp() throws Exception { switchableContext = new CryptodocSwitchableApplicationContextFactory(); when(parentContext.containsBean(ENCRYPTED_STORE_SUBSYSTEM)).thenReturn(true); when(parentContext.containsBean(UNENCRYPTED_STORE_SUBSYSTEM)).thenReturn(true); }
@Test public void cannotSetSourceBeanWhenCurrentStoreIsEncrypted() { initSwitchableContext(ENCRYPTED_STORE_SUBSYSTEM); try { switchableContext.setProperty(SOURCE_BEAN_NAME_PROPERTY, UNENCRYPTED_STORE_SUBSYSTEM); fail("It shouldn't be possible to switch to an unencrypted content store from an encrypted one."); } catch (IllegalStateException e) { // Good } assertEquals(ENCRYPTED_STORE_SUBSYSTEM, switchableContext.getProperty(SOURCE_BEAN_NAME_PROPERTY)); }
@Override public void setProperty(String name, String value) { if (!isUpdateable(name)) { if(value.equalsIgnoreCase(unencryptedContentStoreBeanName)) { throw new IllegalStateException("Switching to an unencrypted content store is not possible."); } if(value.equalsIgnoreCase(encryptedContentStoreBeanName)) { throw new IllegalStateException("Switching to an encrypted content store is not licensed."); } throw new IllegalStateException("Switching to an unknown content store is not possible." + value); } super.setProperty(name, value); } }
if (name.equals(SOURCE_BEAN_PROPERTY)) if(getCurrentSourceBeanName().equals(unencryptedContentStoreBeanName)) if(!getCurrentSourceBeanName().equals(unencryptedContentStoreBeanName))
@Test public void sourceBeanIsUpdateableWhenCurrentStoreIsUnencrypted() { initSwitchableContext(UNENCRYPTED_STORE_SUBSYSTEM); boolean updateable = switchableContext.isUpdateable(SOURCE_BEAN_NAME_PROPERTY); assertTrue("It should be possible to switch subsystems when the current store is unencrypted.", updateable); }
@Test public void sourceBeanIsNotUpdatableWhenCurrentStoreIsEncrypted() { initSwitchableContext(ENCRYPTED_STORE_SUBSYSTEM); boolean updateable = switchableContext.isUpdateable(SOURCE_BEAN_NAME_PROPERTY); assertFalse("It should not be possible to switch subsystems when the current store is encrypted.", updateable); }