@Test public void longPropertyXmlSaveLoad() throws JAXBException { long value = new Random().nextLong(); LongProperty longProperty = new LongProperty("name", "description", "logical-name", Long.valueOf(value), false, false); JAXBContext context = JAXBContext.newInstance(ByteProperty.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(longProperty, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(LongProperty.class))); LongProperty unmarsalled = (LongProperty) object; assertThat(unmarsalled.getDefaultValue(), is(Long.valueOf(value))); }
@Test public void longPropertyUpdateXmlSaveLoad() throws PropertyValidationException, JAXBException { long value = new Random().nextLong(); if (1 == value) { // make sure we don't update with same value value++; } LongProperty longProperty = new LongProperty("name", "description", "logical-name", Long.valueOf(1), false, false); AbstractPropertyUpdate<Long> longPropertyUpdate = longProperty.createAndValidatePropertyUpdate(Long.valueOf(value)); JAXBContext context = JAXBContext.newInstance(LongPropertyUpdate.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(longPropertyUpdate, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(LongPropertyUpdate.class))); LongPropertyUpdate unmarsalled = (LongPropertyUpdate) object; assertThat(longProperty.canUpdate(unmarsalled), is(true)); longProperty.setValue(unmarsalled.getUpdateValue()); assertThat(longProperty.getValue().longValue(), is(value)); }
@Test public void marshalConfigurationUpdate() throws JAXBException, PropertyValidationException { ConfigurationUpdate configurationUpdate = new ConfigurationUpdate(); SingleProperty<String> property1 = new StringProperty("title", "Define title", "properties.title", "Lorem ipsum", true, false); configurationUpdate.addPropertyUpdate(property1.createAndValidatePropertyUpdate("New value")); SingleProperty<Long> property2 = new LongProperty("speed", "Define speed", "properties.speed", 10L, true, true); configurationUpdate.addPropertyUpdate(property2.createAndValidatePropertyUpdate(1000L)); SingleProperty<Boolean> property3 = new BooleanProperty("boolean", "Define boolean", "properties.boolean", true, true, true); configurationUpdate.addPropertyUpdate(property3.createAndValidatePropertyUpdate(false)); JAXBContext context = JAXBContext.newInstance(ConfigurationUpdate.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(configurationUpdate, System.out); marshaller.marshal(configurationUpdate, f); Unmarshaller unmarshaller = context.createUnmarshaller(); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(ConfigurationUpdate.class))); assertThat((ConfigurationUpdate) object, is(equalTo(configurationUpdate))); }
/** * 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)); }
Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); SingleProperty<Long> property = new LongProperty("", "", "property1", 10L, false, false); section.addProperty(property); configuration.addSection(section);
Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); SingleProperty<Long> property = new LongProperty("", "", "property1", defaultValue, false, false); property.setValue(45523L); section.addProperty(property);
Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); 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); }
section.addProperty(property1); SingleProperty<Long> property2 = new LongProperty("speed", "Define speed", "properties.speed", 10L, true, true); property2.addValidator(new PositiveValidator<Long>()); section.addProperty(property2); SingleProperty<Long> property3 = new LongProperty("Max rotation", "Define max rotation", "properties.rotation.max", 90L, false, false); groupedProperty.addSingleProperty(property3); SingleProperty<Long> property4 = new LongProperty("Min rotation", "Define min rotation", "properties.rotation.min", 0L, false, false); groupedProperty.addSingleProperty(property4); LessValidator<Long> lessValidator = new LessValidator<>();