public Optional<Violation> validate(IndexSetConfig newConfig) {

        // Don't validate prefix conflicts in case of an update
        if (Strings.isNullOrEmpty(newConfig.id())) {
            final Violation prefixViolation = validatePrefix(newConfig);
            if (prefixViolation != null) {
                return Optional.of(prefixViolation);
            }
        }

        final Violation fieldMappingViolation = validateMappingChangesAreLegal(newConfig);
        if (fieldMappingViolation != null) {
            return Optional.of(fieldMappingViolation);
        }

        Violation refreshIntervalViolation = validateSimpleIndexSetConfig(newConfig);
        if (refreshIntervalViolation != null){
            return Optional.of(refreshIntervalViolation);
        }
        return Optional.empty();
    }
@Test
    public void validateMaxRetentionPeriod() {
        when(indexSetRegistry.iterator()).thenReturn(Collections.emptyIterator());

        // no max retention period configured
        assertThat(validator.validate(testIndexSetConfig())).isNotPresent();

        // max retention period >= effective retention period
        when(elasticsearchConfiguration.getMaxIndexRetentionPeriod()).thenReturn(Period.days(10));
        assertThat(validator.validate(testIndexSetConfig())).isNotPresent();

        // max retention period < effective retention period
        when(elasticsearchConfiguration.getMaxIndexRetentionPeriod()).thenReturn(Period.days(9));
        assertThat(validator.validate(testIndexSetConfig())).hasValueSatisfying(v ->
                assertThat(v.message()).contains("effective index retention period of P1W3D")
        );

        // rotation strategy is not time-based
        final IndexSetConfig modifiedConfig = testIndexSetConfig().toBuilder()
                .rotationStrategyConfig(MessageCountRotationStrategyConfig.create(Integer.MAX_VALUE))
                .rotationStrategyClass(MessageCountRotationStrategy.class.getCanonicalName())
                .build();
        assertThat(validator.validate(modifiedConfig)).isNotPresent();
    }