package io.quarkus.hibernate.validator.test.config;

import static org.junit.jupiter.api.Assertions.assertThrows;

import javax.inject.Inject;
import javax.validation.constraints.Max;

import org.eclipse.microprofile.config.Config;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.ConfigValidationException;
import io.smallrye.config.SmallRyeConfig;

public class ConfigMappingValidatorTest {
    @RegisterExtension
    static final QuarkusUnitTest UNIT_TEST = new QuarkusUnitTest().setArchiveProducer(
            () -> ShrinkWrap.create(JavaArchive.class)
                    .addAsResource(new StringAsset("server.host=localhost\n"), "application.properties"));

    @Inject
    Config config;

    @Test
    void validator() {
        assertThrows(ConfigValidationException.class,
                () -> config.unwrap(SmallRyeConfig.class).getConfigMapping(Server.class),
                "server.host must be less than or equal to 3");
    }

    @ConfigMapping(prefix = "server")
    public interface Server {
        @Max(3)
        String host();
    }
}

@@ -900,16 +900,26 @@
 gAsset(%22
+validator.
 server.h
@@ -1192,16 +1192,26 @@
        %22
+validator.
 server.h
@@ -1285,16 +1285,26 @@
 efix = %22
+validator.
 server%22)

Rename test configuration property names clashing with maven deploy