/*
 * Copyright 2017 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package com.linecorp.armeria.spring;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.DisableOnDebug;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import com.linecorp.armeria.client.WebClient;
import com.linecorp.armeria.common.AggregatedHttpResponse;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.metric.MeterIdPrefixFunction;
import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.spring.ArmeriaAutoConfigurationWithoutMeterTest.NoMeterTestConfiguration;

import io.micrometer.core.instrument.MeterRegistry;

/**
 * This uses {@link ArmeriaAutoConfiguration} for integration tests.
 * application-autoConfTest.yml will be loaded with minimal settings to make it work.
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NoMeterTestConfiguration.class)
@ActiveProfiles({ "local", "autoConfTest" })
public class ArmeriaAutoConfigurationWithoutMeterTest {

    /**
     * {@link MeterIdPrefixFunction} and {@link MeterRegistry} are not registered as bean.
     */
    @SpringBootApplication
    @Import(ArmeriaOkServiceConfiguration.class)
    public static class NoMeterTestConfiguration {
    }

    @Rule
    public TestRule globalTimeout = new DisableOnDebug(new Timeout(10, TimeUnit.SECONDS));

    @Inject
    private Server server;

    private String newUrl(String scheme) {
        final int port = server.activeLocalPort();
        return scheme + "://127.0.0.1:" + port;
    }

    @Test
    public void test() {
        final AggregatedHttpResponse msg = WebClient.of(newUrl("h1c"))
                                                    .get("/ok")
                                                    .aggregate().join();
        assertThat(msg.status()).isEqualTo(HttpStatus.OK);
        assertThat(msg.contentUtf8()).isEqualTo("ok");

        final String metricReport = WebClient.of(newUrl("http"))
                                             .get("/internal/metrics")
                                             .aggregate().join()
                                             .contentUtf8();
        assertThat(metricReport).contains("# TYPE armeria_server_response_duration_seconds_max gauge");
    }
}

@@ -722,16 +722,63 @@
 ertThat;
+%0Aimport static org.awaitility.Awaitility.await;
 %0A%0Aimport
@@ -1156,62 +1156,8 @@
 st;%0A
-import org.springframework.context.annotation.Import;%0A
 impo
@@ -1320,114 +1320,8 @@
 nt;%0A
-import com.linecorp.armeria.common.AggregatedHttpResponse;%0Aimport com.linecorp.armeria.common.HttpStatus;%0A
 impo
@@ -2070,57 +2070,8 @@
 ion%0A
-    @Import(ArmeriaOkServiceConfiguration.class)%0A
     
@@ -2462,323 +2462,42 @@
     
-final AggregatedHttpResponse msg = WebClient.of(newUrl(%22h1c%22))%0A                                                    .get(%22/ok%22)%0A                                                    .aggregate().join();%0A        assertThat(msg.status()).isEqualTo(HttpStatus.OK);%0A        assertThat(msg.contentUtf8()).isEqualTo(%22ok%22);%0A%0A
+await().untilAsserted(() -%3E %7B%0A    
     
@@ -2554,15 +2554,18 @@
 l(%22h
-ttp
+1c
 %22))%0A
+    
     
@@ -2676,16 +2676,20 @@
         
+   
+ 
 .aggrega
@@ -2745,16 +2745,20 @@
         
+    
 .content
@@ -2773,16 +2773,20 @@
         
+ 
+   
 assertTh
@@ -2838,44 +2838,38 @@
 ver_
-response_duration_seconds_max gauge%22
+connections gauge%22);%0A        %7D
 );%0A 

Test failure: com.linecorp.armeria.spring.ArmeriaAutoConfigurationWithoutMeterTest (#3107)