@Test public void test_enrollment_state_returns_null_when_null_submitted_without_default() { ParameterReader<EnrollmentState> stateReader = factory .buildEnrollmentStateReader(); EnrollmentState withoutDefault = stateReader .readParameter(null, false); assertThat(withoutDefault, is(nullValue())); }
@Bean(name = EnrollmentConfig.EnrollmentParameters.STATE) public ParameterReader<EnrollmentState> buildEnrollmentStateReader() { return new ParameterReader<EnrollmentState>() { @Override public String getParameterName() { return EnrollmentConfig.EnrollmentParameters.STATE; } @Override public EnrollmentState readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String state = (String) parameter; log.debug("state " + state); try { return EnrollmentState.valueOf(state); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(EnrollmentState.values()).stream() .map(EnrollmentState::name) .collect(Collectors.toList())); log.error("Wrong value for state - choose one between [{}]", availableValues); throw new InvalidParameterException(EnrollmentConfig.EnrollmentParameters.STATE, "choose one between: " + availableValues); } } else if (withDefault) { return EnrollmentState.enrolled; } else { return null; } } }; }
ParameterReaderFactory { @Bean(name = EnrollmentConfig.EnrollmentParameters.STATE) public ParameterReader<EnrollmentState> buildEnrollmentStateReader() { return new ParameterReader<EnrollmentState>() { @Override public String getParameterName() { return EnrollmentConfig.EnrollmentParameters.STATE; } @Override public EnrollmentState readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String state = (String) parameter; log.debug("state " + state); try { return EnrollmentState.valueOf(state); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(EnrollmentState.values()).stream() .map(EnrollmentState::name) .collect(Collectors.toList())); log.error("Wrong value for state - choose one between [{}]", availableValues); throw new InvalidParameterException(EnrollmentConfig.EnrollmentParameters.STATE, "choose one between: " + availableValues); } } else if (withDefault) { return EnrollmentState.enrolled; } else { return null; } } }; } }
ParameterReaderFactory { @Bean(name = EnrollmentConfig.EnrollmentParameters.STATE) public ParameterReader<EnrollmentState> buildEnrollmentStateReader() { return new ParameterReader<EnrollmentState>() { @Override public String getParameterName() { return EnrollmentConfig.EnrollmentParameters.STATE; } @Override public EnrollmentState readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String state = (String) parameter; log.debug("state " + state); try { return EnrollmentState.valueOf(state); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(EnrollmentState.values()).stream() .map(EnrollmentState::name) .collect(Collectors.toList())); log.error("Wrong value for state - choose one between [{}]", availableValues); throw new InvalidParameterException(EnrollmentConfig.EnrollmentParameters.STATE, "choose one between: " + availableValues); } } else if (withDefault) { return EnrollmentState.enrolled; } else { return null; } } }; }  }
ParameterReaderFactory { @Bean(name = EnrollmentConfig.EnrollmentParameters.STATE) public ParameterReader<EnrollmentState> buildEnrollmentStateReader() { return new ParameterReader<EnrollmentState>() { @Override public String getParameterName() { return EnrollmentConfig.EnrollmentParameters.STATE; } @Override public EnrollmentState readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String state = (String) parameter; log.debug("state " + state); try { return EnrollmentState.valueOf(state); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(EnrollmentState.values()).stream() .map(EnrollmentState::name) .collect(Collectors.toList())); log.error("Wrong value for state - choose one between [{}]", availableValues); throw new InvalidParameterException(EnrollmentConfig.EnrollmentParameters.STATE, "choose one between: " + availableValues); } } else if (withDefault) { return EnrollmentState.enrolled; } 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 = EnrollmentConfig.EnrollmentParameters.STATE) public ParameterReader<EnrollmentState> buildEnrollmentStateReader() { return new ParameterReader<EnrollmentState>() { @Override public String getParameterName() { return EnrollmentConfig.EnrollmentParameters.STATE; } @Override public EnrollmentState readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String state = (String) parameter; log.debug("state " + state); try { return EnrollmentState.valueOf(state); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(EnrollmentState.values()).stream() .map(EnrollmentState::name) .collect(Collectors.toList())); log.error("Wrong value for state - choose one between [{}]", availableValues); throw new InvalidParameterException(EnrollmentConfig.EnrollmentParameters.STATE, "choose one between: " + availableValues); } } else if (withDefault) { return EnrollmentState.enrolled; } 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();  }