SetRandomisationSettingsRequestData implements Serializable, ActionRequest { @Override public void validate() throws FunctionalException { if (this.directAttach < MIN_VALUE_DIRECT_ATTACH || this.directAttach > MAX_VALUE_DIRECT_ATTACH) { throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new Exception(String.format("DirectAttach value range failed. (%s-%s)", MIN_VALUE_DIRECT_ATTACH, MAX_VALUE_DIRECT_ATTACH))); } if (this.randomisationStartWindow < MIN_VALUE_RANDOMIZATION_START_WINDOW || this.randomisationStartWindow > MAX_VALUE_RANDOMIZATION_START_WINDOW) { throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new Exception(String.format("RandomisationStartWindow value range failed. (%s-%s)", MIN_VALUE_RANDOMIZATION_START_WINDOW, MAX_VALUE_RANDOMIZATION_START_WINDOW))); } if (this.multiplicationFactor < MIN_VALUE_MULTIPLICATION_FACTOR || this.multiplicationFactor > MAX_VALUE_MULTIPLICATION_FACTOR) { throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new Exception(String.format("MultiplicationFactor value range failed. (%s-%s)", MIN_VALUE_MULTIPLICATION_FACTOR, MAX_VALUE_MULTIPLICATION_FACTOR))); } if (this.numberOfRetries < MIN_VALUE_NUMBER_OF_RETRIES || this.numberOfRetries > MAX_VALUE_NUMBER_OF_RETRIES) { throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new Exception( String.format("NumberOfRetries value range failed. (%s-%s)", MIN_VALUE_NUMBER_OF_RETRIES, MAX_VALUE_NUMBER_OF_RETRIES))); } } SetRandomisationSettingsRequestData(final int directAttach, final int randomisationStartWindow,
            final int multiplicationFactor, final int numberOfRetries); @Override void validate(); int getDirectAttach(); int getRandomisationStartWindow(); int getMultiplicationFactor(); int getNumberOfRetries(); @Override DeviceFunction getDeviceFunction();  }
@Test public void testInvalidDirectAttach() throws FunctionalException { assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> { new SetRandomisationSettingsRequestData(SetRandomisationSettingsRequestData.MIN_VALUE_DIRECT_ATTACH - 1, SetRandomisationSettingsRequestData.MIN_VALUE_RANDOMIZATION_START_WINDOW, SetRandomisationSettingsRequestData.MIN_VALUE_MULTIPLICATION_FACTOR, SetRandomisationSettingsRequestData.MIN_VALUE_NUMBER_OF_RETRIES).validate(); }); }
@Test public void testInvalidMultiplicationFactor() throws FunctionalException { assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> { new SetRandomisationSettingsRequestData(SetRandomisationSettingsRequestData.MIN_VALUE_DIRECT_ATTACH, SetRandomisationSettingsRequestData.MAX_VALUE_RANDOMIZATION_START_WINDOW, SetRandomisationSettingsRequestData.MAX_VALUE_MULTIPLICATION_FACTOR + 1, SetRandomisationSettingsRequestData.MIN_VALUE_NUMBER_OF_RETRIES).validate(); }); }
@Test public void testInvalidNumberOfRetries() throws FunctionalException { assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> { new SetRandomisationSettingsRequestData(SetRandomisationSettingsRequestData.MIN_VALUE_DIRECT_ATTACH, SetRandomisationSettingsRequestData.MAX_VALUE_RANDOMIZATION_START_WINDOW, SetRandomisationSettingsRequestData.MAX_VALUE_MULTIPLICATION_FACTOR, SetRandomisationSettingsRequestData.MAX_VALUE_NUMBER_OF_RETRIES + 1).validate(); }); }
@Test public void testInvalidRandomisationStartWindow() throws FunctionalException { assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> { new SetRandomisationSettingsRequestData(SetRandomisationSettingsRequestData.MIN_VALUE_DIRECT_ATTACH, SetRandomisationSettingsRequestData.MAX_VALUE_RANDOMIZATION_START_WINDOW + 1, SetRandomisationSettingsRequestData.MIN_VALUE_MULTIPLICATION_FACTOR, SetRandomisationSettingsRequestData.MIN_VALUE_NUMBER_OF_RETRIES).validate(); }); }
@Test public void testValidRequestData() { try { new SetRandomisationSettingsRequestData(SetRandomisationSettingsRequestData.MAX_VALUE_DIRECT_ATTACH, SetRandomisationSettingsRequestData.MIN_VALUE_RANDOMIZATION_START_WINDOW, SetRandomisationSettingsRequestData.MIN_VALUE_MULTIPLICATION_FACTOR, SetRandomisationSettingsRequestData.MIN_VALUE_NUMBER_OF_RETRIES).validate(); } catch (final FunctionalException e) { fail(""); } }