@BeforeMethod public void init() { MockitoAnnotations.initMocks(this); configuration = new Configuration(); PropertySection section = new PropertySection(); section.addProperty(property1); section.addProperty(property2); configuration.addSection(section); }
/** * Test that not matching property update will not be taken into account. */ @Test @SuppressWarnings("unchecked") public void savedPropertyUpdateNotValid() throws JAXBException, IOException, SAXException { Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); SingleProperty<Long> property = new LongProperty("", "", "property1", 10L, false, false); section.addProperty(property); configuration.addSection(section); doReturn(configuration).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(Configuration.class)); doReturn(configurationUpdate).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(ConfigurationUpdate.class)); AbstractPropertyUpdate<String> propertyUpdate = mock(AbstractPropertyUpdate.class); when(propertyUpdate.getPropertyLogicalName()).thenReturn("property1"); when(propertyUpdate.getUpdateValue()).thenReturn("updatedValue"); when(configurationUpdate.getPropertyUpdates()).thenReturn(Collections.<IPropertyUpdate<?>> singleton(propertyUpdate)); Properties properties = propertyManager.getProperties(); assertThat(Long.valueOf(properties.getProperty("property1")), is(10L)); assertThat(properties.size(), is(1)); }
/** * Test that {@link Properties} will hold an updated value of the property if it's included * in the {@link ConfigurationUpdate}. */ @Test @SuppressWarnings("unchecked") public void savedPropertyUpdateFromTheDefaultConfiguration() throws JAXBException, IOException, SAXException { Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); SingleProperty<String> property = new StringProperty("", "", "property1", "value1", false, false); section.addProperty(property); configuration.addSection(section); doReturn(configuration).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(Configuration.class)); doReturn(configurationUpdate).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(ConfigurationUpdate.class)); AbstractPropertyUpdate<String> propertyUpdate = mock(AbstractPropertyUpdate.class); when(propertyUpdate.getPropertyLogicalName()).thenReturn("property1"); when(propertyUpdate.getUpdateValue()).thenReturn("updatedValue"); when(configurationUpdate.getPropertyUpdates()).thenReturn(Collections.<IPropertyUpdate<?>> singleton(propertyUpdate)); Properties properties = propertyManager.getProperties(); assertThat(properties.getProperty("property1"), is(equalTo("updatedValue"))); assertThat(properties.size(), is(1)); }
/** * Test that {@link Properties} will reseted to default if it's included in the * {@link ConfigurationUpdate}. */ @Test @SuppressWarnings("unchecked") public void savedPropertyRestoreToDefaultUpdate() throws JAXBException, IOException, SAXException { String defaultValue = "value1"; Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); SingleProperty<String> property = new StringProperty("", "", "property1", defaultValue, false, false); property.setValue("someotherthandefault"); section.addProperty(property); configuration.addSection(section); doReturn(configuration).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(Configuration.class)); doReturn(configurationUpdate).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(ConfigurationUpdate.class)); AbstractPropertyUpdate<String> propertyUpdate = mock(AbstractPropertyUpdate.class); when(propertyUpdate.getPropertyLogicalName()).thenReturn("property1"); when(propertyUpdate.isRestoreDefault()).thenReturn(true); when(configurationUpdate.getPropertyUpdates()).thenReturn(Collections.<IPropertyUpdate<?>> singleton(propertyUpdate)); Properties properties = propertyManager.getProperties(); assertThat(properties.getProperty("property1"), is(equalTo(defaultValue))); assertThat(properties.size(), is(1)); }
property.setValue(45523L); section.addProperty(property); configuration.addSection(section);
SingleProperty<Long> property = new LongProperty("", "", "property1", 10L, false, false); section.addProperty(property); configuration.addSection(section);
SingleProperty<Long> property = new LongProperty("", "", "property1", 10L, false, false); section.addProperty(property); configuration.addSection(section);
/** * Check that property will be correctly updated during runtime and server will be * restarted. */ @SuppressWarnings({ "unchecked" }) @Test public void runtimePropertyUpdateServerRestart() throws Exception { Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); SingleProperty<Long> property = new LongProperty("", "", "property1", 10L, false, true); section.addProperty(property); configuration.addSection(section); doReturn(configuration).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(Configuration.class)); doReturn(null).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(ConfigurationUpdate.class)); doNothing().when(transformator).marshall(Matchers.<Path> anyObject(), any(), anyString()); ConfigurationUpdate configurationUpdate = mock(ConfigurationUpdate.class); AbstractPropertyUpdate<Long> propertyUpdate = mock(AbstractPropertyUpdate.class); when(propertyUpdate.getPropertyLogicalName()).thenReturn("property1"); when(propertyUpdate.getUpdateValue()).thenReturn(20L); when(configurationUpdate.getPropertyUpdates()).thenReturn(Collections.<IPropertyUpdate<?>> singleton(propertyUpdate)); propertyManager.init(); propertyManager.loadConfigurationAndUpdates(); propertyManager.updateConfiguration(configurationUpdate, true); assertThat(property.getValue(), is(20L)); // confirm configuration update write verify(transformator, times(1)).marshall(Matchers.<Path> anyObject(), eq(configurationUpdate), anyString()); // confirm server service was called verify(shutdownService).restart(); verifyZeroInteractions(propertyUpdateExecutor); }
configuration.addSection(section);