/** * Creates a {@link RestoreDefaultPropertyUpdate} for this property. * * @return {@link RestoreDefaultPropertyUpdate} */ public RestoreDefaultPropertyUpdate<T> createRestoreDefaultPropertyUpdate() { return new RestoreDefaultPropertyUpdate<>(this); }
/** * {@inheritDoc} */ @Override protected AbstractPropertyUpdate<Float> createPropertyUpdate(Float updateValue) { return new PercentagePropertyUpdate(this, updateValue); }
/** * {@inheritDoc} */ @Override protected AbstractPropertyUpdate<Boolean> createPropertyUpdate(Boolean updateValue) { return new BooleanPropertyUpdate(this, updateValue); }
/** * {@inheritDoc} */ @Override protected AbstractPropertyUpdate<String> createPropertyUpdate(String updateValue) { return new StringPropertyUpdate(this, updateValue); }
/** * {@inheritDoc} */ @Override protected AbstractPropertyUpdate<Long> createPropertyUpdate(Long updateValue) { return new BytePropertyUpdate(this, updateValue); }
@Override protected AbstractPropertyUpdate<Long> createPropertyUpdate(Long updateValue) { return new LongPropertyUpdate(this, updateValue); }
@Test public void bytePropertyUpdateXmlSaveLoad() throws PropertyValidationException, JAXBException { long bytes = (10 * 1024 * 1024) + 2; // 10MBs + 2 bytes ByteProperty byteProperty = new ByteProperty("name", "description", "logical-name", Long.valueOf(1), false, false); AbstractPropertyUpdate<Long> bytePropertyUpdate = byteProperty.createAndValidatePropertyUpdate(Long.valueOf(bytes)); JAXBContext context = JAXBContext.newInstance(BytePropertyUpdate.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(bytePropertyUpdate, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(BytePropertyUpdate.class))); BytePropertyUpdate unmarsalled = (BytePropertyUpdate) object; assertThat(byteProperty.canUpdate(unmarsalled), is(true)); byteProperty.setValue(unmarsalled.getUpdateValue()); assertThat(byteProperty.getValue().longValue(), is(bytes)); }
@Test public void booleanPropertyUpdateXmlSaveLoad() throws PropertyValidationException, JAXBException { boolean value = new Random().nextBoolean(); BooleanProperty booleanProperty = new BooleanProperty("name", "description", "logical-name", Boolean.valueOf(!value), false, false); AbstractPropertyUpdate<Boolean> booleanPropertyUpdate = booleanProperty.createAndValidatePropertyUpdate(Boolean.valueOf(value)); JAXBContext context = JAXBContext.newInstance(BooleanPropertyUpdate.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(booleanPropertyUpdate, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(BooleanPropertyUpdate.class))); BooleanPropertyUpdate unmarsalled = (BooleanPropertyUpdate) object; assertThat(booleanProperty.canUpdate(unmarsalled), is(true)); booleanProperty.setValue(unmarsalled.getUpdateValue()); assertThat(booleanProperty.getValue().booleanValue(), is(value)); }
@Test public void stringPropertyUpdateXmlSaveLoad() throws PropertyValidationException, JAXBException { String value = RandomStringUtils.randomAlphabetic(20); StringProperty stringProperty = new StringProperty("name", "description", "logical-name", "balbla", false, false); AbstractPropertyUpdate<String> stringPropertyUpdate = stringProperty.createAndValidatePropertyUpdate(value); JAXBContext context = JAXBContext.newInstance(StringPropertyUpdate.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(stringPropertyUpdate, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(StringPropertyUpdate.class))); StringPropertyUpdate unmarsalled = (StringPropertyUpdate) object; assertThat(stringProperty.canUpdate(unmarsalled), is(true)); stringProperty.setValue(unmarsalled.getUpdateValue()); assertThat(stringProperty.getValue(), is(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 floatPropertyUpdateXmlSaveLoad() throws PropertyValidationException, JAXBException { float value = new Random().nextInt(100); if (1 == value) { // make sure we don't update with same value value++; } PercentageProperty floatProperty = new PercentageProperty("name", "description", "logical-name", Float.valueOf(1), false, false); AbstractPropertyUpdate<Float> floatPropertyUpdate = floatProperty.createAndValidatePropertyUpdate(Float.valueOf(value)); JAXBContext context = JAXBContext.newInstance(PercentagePropertyUpdate.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(floatPropertyUpdate, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(PercentagePropertyUpdate.class))); PercentagePropertyUpdate unmarsalled = (PercentagePropertyUpdate) object; assertThat(floatProperty.canUpdate(unmarsalled), is(true)); floatProperty.setValue(unmarsalled.getUpdateValue()); assertThat(floatProperty.getValue().floatValue(), is(value)); }