-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrerPrometheusTest.java
More file actions
173 lines (166 loc) · 6.01 KB
/
Copy pathIntegrerPrometheusTest.java
File metadata and controls
173 lines (166 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.cl.outil;
import org.junit.jupiter.api.Test;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.maven.Assertions.pomXml;
import static org.openrewrite.properties.Assertions.properties;
import static org.openrewrite.yaml.Assertions.yaml;
/**
* Vérifie que la recette com.lcl.rewrite.IntegrerPrometheus :
* (a) modifie application.properties et application.yaml/yml avec le contenu attendu,
* (b) ne touche JAMAIS les autres fichiers .properties / .yaml (XD19, connecteur, logback),
* (c) ajoute les dépendances attendues au pom.xml.
*/
class IntegrerPrometheusTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.recipeFromResources("com.lcl.rewrite.IntegrerPrometheus");
}
@Test
void modifieApplicationPropertiesEtIgnoreLesAutresProperties() {
rewriteRun(
// (a) application.properties est modifié
properties(
"""
spring.application.name=mssepamd
server.port=8080
""",
"""
spring.application.name=mssepamd
server.port=8080
management.endpoints.web.exposure.include=prometheus,health,info,metrics
management.metrics.tags.application=${spring.application.name}
management.metrics.distribution.percentiles-histogram.http.server.requests=true
management.metrics.distribution.percentiles.http.server.requests=0.5,0.95,0.99
management.metrics.distribution.percentiles.jvm.gc.pause=0.5,0.95,0.99
management.metrics.enable.jvm.threads=true
""",
s -> s.path("src/main/resources/application.properties")
),
// (b) les autres .properties ne sont PAS touchés (pas de "after" => inchangé attendu)
properties(
"""
xd19.host=cics-prd.lcl.fr
xd19.port=2006
""",
s -> s.path("src/main/resources/XD19.properties")
),
properties(
"""
connecteur.caps.url=https://caps.lcl.fr
connecteur.caps.timeout=5000
""",
s -> s.path("src/main/resources/connecteur.properties")
)
);
}
@Test
void modifieApplicationYamlEtIgnoreLesAutresYaml() {
rewriteRun(
// (a) application.yaml (extension .yaml) est modifié
yaml(
"""
spring:
application:
name: mssepamd
""",
"""
spring:
application:
name: mssepamd
management:
endpoints:
web:
exposure:
include: prometheus,health,info,metrics
metrics:
tags:
application: ${spring.application.name}
distribution:
percentiles-histogram:
http.server.requests: true
percentiles:
http.server.requests: 0.5,0.95,0.99
jvm.gc.pause: 0.5,0.95,0.99
enable:
jvm.threads: true
""",
s -> s.path("src/main/resources/application.yaml")
),
// (a bis) application.yml (extension .yml) est couvert par application.y*ml
yaml(
"""
spring:
application:
name: wsipke04
""",
"""
spring:
application:
name: wsipke04
management:
endpoints:
web:
exposure:
include: prometheus,health,info,metrics
metrics:
tags:
application: ${spring.application.name}
distribution:
percentiles-histogram:
http.server.requests: true
percentiles:
http.server.requests: 0.5,0.95,0.99
jvm.gc.pause: 0.5,0.95,0.99
enable:
jvm.threads: true
""",
s -> s.path("src/main/resources/config/application.yml")
),
// (b) logback.yaml NON touché
yaml(
"""
logging:
level:
root: INFO
""",
s -> s.path("src/main/resources/logback.yaml")
)
);
}
@Test
void ajouteLesDependancesAuPom() {
rewriteRun(
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.5</version>
</parent>
<groupId>com.lcl</groupId>
<artifactId>mssepamd</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
""",
// La version résolue par le sélecteur semver (3.5.x / 1.x) dépend du dépôt :
// on vérifie la présence des GAV plutôt qu'un texte figé.
s -> s.after(pom -> {
assertThat(pom).contains("spring-boot-starter-actuator");
assertThat(pom).contains("micrometer-registry-prometheus");
assertThat(pom).contains("<scope>runtime</scope>");
return pom;
})
)
);
}
}