@Test public void test_idle_duration_returns_null_when_null_submitted_without_default() { ParameterReader<Duration> idleDurationReader = factory.buildIdleDurationReader(); Duration withoutDefault = idleDurationReader.readParameter(null, false); assertThat(withoutDefault, is(nullValue())); }
@Bean(name = Config.ServiceInstanceParameters.IDLE_DURATION) public ParameterReader<Duration> buildIdleDurationReader() { return new ParameterReader<Duration>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.IDLE_DURATION; } @Override public Duration readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String inactivityPattern = (String) parameter; log.debug("pattern " + inactivityPattern); try { return Duration.parse(inactivityPattern); } catch (DateTimeParseException e) { log.error("Wrong format for inactivity duration - format should respect ISO-8601 duration " + "format " + "PnDTnHnMn"); throw new InvalidParameterException(Config.ServiceInstanceParameters.IDLE_DURATION, "param badly formatted (ISO-8601). Example: \"PT15M\" for 15mn"); } } else if (withDefault) { return Config.DEFAULT_INACTIVITY_PERIOD; } else { return null; } } }; }
ParameterReaderFactory { @Bean(name = Config.ServiceInstanceParameters.IDLE_DURATION) public ParameterReader<Duration> buildIdleDurationReader() { return new ParameterReader<Duration>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.IDLE_DURATION; } @Override public Duration readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String inactivityPattern = (String) parameter; log.debug("pattern " + inactivityPattern); try { return Duration.parse(inactivityPattern); } catch (DateTimeParseException e) { log.error("Wrong format for inactivity duration - format should respect ISO-8601 duration " + "format " + "PnDTnHnMn"); throw new InvalidParameterException(Config.ServiceInstanceParameters.IDLE_DURATION, "param badly formatted (ISO-8601). Example: \"PT15M\" for 15mn"); } } else if (withDefault) { return Config.DEFAULT_INACTIVITY_PERIOD; } else { return null; } } }; } }
ParameterReaderFactory { @Bean(name = Config.ServiceInstanceParameters.IDLE_DURATION) public ParameterReader<Duration> buildIdleDurationReader() { return new ParameterReader<Duration>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.IDLE_DURATION; } @Override public Duration readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String inactivityPattern = (String) parameter; log.debug("pattern " + inactivityPattern); try { return Duration.parse(inactivityPattern); } catch (DateTimeParseException e) { log.error("Wrong format for inactivity duration - format should respect ISO-8601 duration " + "format " + "PnDTnHnMn"); throw new InvalidParameterException(Config.ServiceInstanceParameters.IDLE_DURATION, "param badly formatted (ISO-8601). Example: \"PT15M\" for 15mn"); } } else if (withDefault) { return Config.DEFAULT_INACTIVITY_PERIOD; } else { return null; } } }; }  }
ParameterReaderFactory { @Bean(name = Config.ServiceInstanceParameters.IDLE_DURATION) public ParameterReader<Duration> buildIdleDurationReader() { return new ParameterReader<Duration>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.IDLE_DURATION; } @Override public Duration readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String inactivityPattern = (String) parameter; log.debug("pattern " + inactivityPattern); try { return Duration.parse(inactivityPattern); } catch (DateTimeParseException e) { log.error("Wrong format for inactivity duration - format should respect ISO-8601 duration " + "format " + "PnDTnHnMn"); throw new InvalidParameterException(Config.ServiceInstanceParameters.IDLE_DURATION, "param badly formatted (ISO-8601). Example: \"PT15M\" for 15mn"); } } else if (withDefault) { return Config.DEFAULT_INACTIVITY_PERIOD; } else { return null; } } }; }  @Bean(name = Config.ServiceInstanceParameters.AUTO_ENROLLMENT) ParameterReader<Enrollment> buildAutoEnrollmentReader(); @Bean(name = Config.ServiceInstanceParameters.EXCLUDE_FROM_AUTO_ENROLLMENT) ParameterReader<Pattern> buildExcludeFromAutoEnrollmentReader(); @Bean(name = Config.ServiceInstanceParameters.IDLE_DURATION) ParameterReader<Duration> buildIdleDurationReader(); @Bean(name = ServiceInstanceParameters.IGNORE_ROUTE_SERVICE_ERROR) ParameterReader<Boolean> buildIgnoreRouteServiceErrorReader(); @Bean(name = Config.ServiceInstanceParameters.SECRET) ParameterReader<String> buildSecretReader(); @Bean(name = EnrollmentConfig.EnrollmentParameters.STATE) ParameterReader<EnrollmentState> buildEnrollmentStateReader(); }
ParameterReaderFactory { @Bean(name = Config.ServiceInstanceParameters.IDLE_DURATION) public ParameterReader<Duration> buildIdleDurationReader() { return new ParameterReader<Duration>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.IDLE_DURATION; } @Override public Duration readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String inactivityPattern = (String) parameter; log.debug("pattern " + inactivityPattern); try { return Duration.parse(inactivityPattern); } catch (DateTimeParseException e) { log.error("Wrong format for inactivity duration - format should respect ISO-8601 duration " + "format " + "PnDTnHnMn"); throw new InvalidParameterException(Config.ServiceInstanceParameters.IDLE_DURATION, "param badly formatted (ISO-8601). Example: \"PT15M\" for 15mn"); } } else if (withDefault) { return Config.DEFAULT_INACTIVITY_PERIOD; } else { return null; } } }; }  @Bean(name = Config.ServiceInstanceParameters.AUTO_ENROLLMENT) ParameterReader<Enrollment> buildAutoEnrollmentReader(); @Bean(name = Config.ServiceInstanceParameters.EXCLUDE_FROM_AUTO_ENROLLMENT) ParameterReader<Pattern> buildExcludeFromAutoEnrollmentReader(); @Bean(name = Config.ServiceInstanceParameters.IDLE_DURATION) ParameterReader<Duration> buildIdleDurationReader(); @Bean(name = ServiceInstanceParameters.IGNORE_ROUTE_SERVICE_ERROR) ParameterReader<Boolean> buildIgnoreRouteServiceErrorReader(); @Bean(name = Config.ServiceInstanceParameters.SECRET) ParameterReader<String> buildSecretReader(); @Bean(name = EnrollmentConfig.EnrollmentParameters.STATE) ParameterReader<EnrollmentState> buildEnrollmentStateReader();  }