package io.micrometer.spring.export.prometheus;

import io.micrometer.core.instrument.Clock;
import io.micrometer.spring.autoconfigure.export.prometheus.PrometheusMetricsExportAutoConfiguration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration;
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

/**
 * Adapted from Spring Boot's <a href="https://github.com/spring-projects/spring-boot/blob/10a5cef4ef33e7c86d18e1f92793c2aaa57d5a82/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MvcEndpointPathConfigurationTests.java">MvcEndpointPathConfigurationTests</a>.
 */
class PrometheusScrapeEndpointPathConfigurationTest {

    private AnnotationConfigWebApplicationContext context;

    @AfterEach
    void cleanUp() {
        if (this.context != null) {
            this.context.close();
        }
    }

    @Test
    void pathCanBeConfigured() {
        this.context = new AnnotationConfigWebApplicationContext();
        this.context.register(TestConfiguration.class);
        this.context.setServletContext(new MockServletContext());
        EnvironmentTestUtils.addEnvironment(this.context,
                "endpoints.prometheus.path:/custom/path",
                "endpoints.prometheus.enabled:true");
        this.context.refresh();
        assertThat(getPath()).isEqualTo("/custom/path");
    }

    private String getPath() {
        return ((MvcEndpoint) this.context.getBean(PrometheusScrapeMvcEndpoint.class)).getPath();
    }

    @Configuration
    @ImportAutoConfiguration({ PrometheusMetricsExportAutoConfiguration.class, EndpointAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class })
    protected static class TestConfiguration {

        @Bean
        public Clock clock() {
            return mock(Clock.class);
        }
    }
}

@@ -1,8 +1,624 @@
+/**%0A * Copyright 2019 Pivotal Software, Inc.%0A * %3Cp%3E%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %3Cp%3E%0A * https://www.apache.org/licenses/LICENSE-2.0%0A * %3Cp%3E%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 

Add missing license header