@Test public void test_auto_enrollment_handle_right_parameter() { ParameterReader<Enrollment> enrollmentParameterReader = factory.buildAutoEnrollmentReader(); String parameter = enrollmentParameterReader.getParameterName(); assertThat(parameter, is(equalTo(ServiceInstanceParameters.AUTO_ENROLLMENT))); }
@Bean(name = Config.ServiceInstanceParameters.AUTO_ENROLLMENT) public ParameterReader<Enrollment> buildAutoEnrollmentReader() { return new ParameterReader<Enrollment>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.AUTO_ENROLLMENT; } @Override public Enrollment readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String autoEnrollment = (String) parameter; log.debug("forcedAutoEnrollment " + autoEnrollment); try { return Enrollment.valueOf(autoEnrollment); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(Enrollment.values()).stream() .map(Enrollment::name) .collect(Collectors.toList())); log.error("Wrong value for auto enrollment - choose one between [{}]", availableValues); throw new InvalidParameterException(Config.ServiceInstanceParameters.AUTO_ENROLLMENT, "choose one between: " + availableValues); } } else if (withDefault) { return Enrollment.standard; } else { return null; } } }; }
ParameterReaderFactory { @Bean(name = Config.ServiceInstanceParameters.AUTO_ENROLLMENT) public ParameterReader<Enrollment> buildAutoEnrollmentReader() { return new ParameterReader<Enrollment>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.AUTO_ENROLLMENT; } @Override public Enrollment readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String autoEnrollment = (String) parameter; log.debug("forcedAutoEnrollment " + autoEnrollment); try { return Enrollment.valueOf(autoEnrollment); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(Enrollment.values()).stream() .map(Enrollment::name) .collect(Collectors.toList())); log.error("Wrong value for auto enrollment - choose one between [{}]", availableValues); throw new InvalidParameterException(Config.ServiceInstanceParameters.AUTO_ENROLLMENT, "choose one between: " + availableValues); } } else if (withDefault) { return Enrollment.standard; } else { return null; } } }; } }
ParameterReaderFactory { @Bean(name = Config.ServiceInstanceParameters.AUTO_ENROLLMENT) public ParameterReader<Enrollment> buildAutoEnrollmentReader() { return new ParameterReader<Enrollment>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.AUTO_ENROLLMENT; } @Override public Enrollment readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String autoEnrollment = (String) parameter; log.debug("forcedAutoEnrollment " + autoEnrollment); try { return Enrollment.valueOf(autoEnrollment); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(Enrollment.values()).stream() .map(Enrollment::name) .collect(Collectors.toList())); log.error("Wrong value for auto enrollment - choose one between [{}]", availableValues); throw new InvalidParameterException(Config.ServiceInstanceParameters.AUTO_ENROLLMENT, "choose one between: " + availableValues); } } else if (withDefault) { return Enrollment.standard; } else { return null; } } }; }  }
ParameterReaderFactory { @Bean(name = Config.ServiceInstanceParameters.AUTO_ENROLLMENT) public ParameterReader<Enrollment> buildAutoEnrollmentReader() { return new ParameterReader<Enrollment>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.AUTO_ENROLLMENT; } @Override public Enrollment readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String autoEnrollment = (String) parameter; log.debug("forcedAutoEnrollment " + autoEnrollment); try { return Enrollment.valueOf(autoEnrollment); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(Enrollment.values()).stream() .map(Enrollment::name) .collect(Collectors.toList())); log.error("Wrong value for auto enrollment - choose one between [{}]", availableValues); throw new InvalidParameterException(Config.ServiceInstanceParameters.AUTO_ENROLLMENT, "choose one between: " + availableValues); } } else if (withDefault) { return Enrollment.standard; } 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.AUTO_ENROLLMENT) public ParameterReader<Enrollment> buildAutoEnrollmentReader() { return new ParameterReader<Enrollment>() { @Override public String getParameterName() { return Config.ServiceInstanceParameters.AUTO_ENROLLMENT; } @Override public Enrollment readParameter(Object parameter, boolean withDefault) throws InvalidParameterException { if (parameter != null) { String autoEnrollment = (String) parameter; log.debug("forcedAutoEnrollment " + autoEnrollment); try { return Enrollment.valueOf(autoEnrollment); } catch (IllegalArgumentException i) { String availableValues = String.join(", ", Arrays.asList(Enrollment.values()).stream() .map(Enrollment::name) .collect(Collectors.toList())); log.error("Wrong value for auto enrollment - choose one between [{}]", availableValues); throw new InvalidParameterException(Config.ServiceInstanceParameters.AUTO_ENROLLMENT, "choose one between: " + availableValues); } } else if (withDefault) { return Enrollment.standard; } 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();  }