32d00449a5f5805d6f9b319eafe5e36ef56a5fac
[dcaegen2/services/sdk.git] /
1 /*
2  * ============LICENSE_START====================================
3  * DCAEGEN2-SERVICES-SDK
4  * =========================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
6  * =========================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=====================================
19  */
20
21 package org.onap.dcaegen2.services.sdk.standardization.moher.adapters.springwebflux;
22
23
24 import static org.assertj.core.api.Assertions.assertThat;
25
26 import io.micrometer.prometheus.PrometheusMeterRegistry;
27 import org.junit.jupiter.api.Test;
28 import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.api.Metrics;
29 import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.api.MetricsFactory;
30 import org.springframework.http.MediaType;
31 import org.springframework.test.web.reactive.server.WebTestClient;
32
33 class MetricsControllerIT {
34
35     private final PrometheusMeterRegistry defaultRegistry = MetricsFactory.createDefaultRegistry();
36     private final Metrics metrics = MetricsFactory.createMetrics(defaultRegistry);
37     private final MetricsController sut = new MetricsController(metrics);
38     private final WebTestClient client = WebTestClient.bindToController(sut).build();
39
40     @Test
41     void prometheusMetrics() {
42         client.get().uri("/metrics").accept(MediaType.ALL).exchange()
43                 .expectStatus().isOk()
44                 .expectHeader().contentTypeCompatibleWith(MediaType.TEXT_PLAIN)
45                 .expectBody(String.class)
46                 .value(body -> assertThat(body).contains("system_cpu").contains("jvm_classes"));
47     }
48 }