|
4 | 4 | import static org.hamcrest.Matchers.containsString; |
5 | 5 | import static org.hamcrest.Matchers.is; |
6 | 6 | import static org.junit.jupiter.api.Assertions.*; |
7 | | -import static org.junit.jupiter.params.provider.Arguments.arguments; |
| 7 | +import static org.junit.jupiter.params.provider.Arguments.argumentSet; |
8 | 8 |
|
9 | 9 | import fr.insee.onyxia.api.configuration.CatalogWrapper; |
10 | 10 | import fr.insee.onyxia.api.configuration.CustomObjectMapper; |
|
13 | 13 | import fr.insee.onyxia.api.util.TestUtils; |
14 | 14 | import fr.insee.onyxia.model.helm.Chart; |
15 | 15 | import java.util.List; |
| 16 | +import java.util.Map; |
16 | 17 | import java.util.Set; |
17 | 18 | import java.util.stream.Collectors; |
18 | 19 | import java.util.stream.Stream; |
@@ -161,21 +162,144 @@ void packageOnClassPathNotFound() { |
161 | 162 |
|
162 | 163 | @ParameterizedTest |
163 | 164 | @MethodSource("includeKeywords") |
164 | | - void filterIncludeKeywordsTest(List<String> includeKeywords, Set<String> expectedServices) { |
| 165 | + @MethodSource("excludeKeywords") |
| 166 | + @MethodSource("includeAnnotations") |
| 167 | + @MethodSource("excludeAnnotations") |
| 168 | + void filterServicesTest( |
| 169 | + List<String> includeKeywords, |
| 170 | + List<String> excludeKeywords, |
| 171 | + Map<String, String> includeAnnotations, |
| 172 | + Map<String, String> excludeAnnotations, |
| 173 | + Set<String> expectedServices) { |
165 | 174 | CatalogWrapper cw = new CatalogWrapper(); |
166 | 175 | cw.setType("helm"); |
167 | | - cw.setLocation("classpath:/catalog-loader-test-with-keywords"); |
| 176 | + cw.setLocation("classpath:/catalog-loader-test-with-keywords-and-annotations"); |
168 | 177 | cw.setIncludeKeywords(includeKeywords); |
| 178 | + cw.setExcludeKeywords(excludeKeywords); |
| 179 | + cw.setIncludeAnnotations(includeAnnotations); |
| 180 | + cw.setExcludeAnnotations(excludeAnnotations); |
169 | 181 | catalogLoader.updateCatalog(cw); |
170 | 182 | assertEquals(expectedServices, cw.getCatalog().getEntries().keySet()); |
171 | 183 | } |
172 | 184 |
|
173 | 185 | private static Stream<Arguments> includeKeywords() { |
174 | 186 | return Stream.of( |
175 | | - arguments(List.of("CD"), Set.of("keepme")), |
176 | | - arguments(List.of("CD", "Experimental"), Set.of("keepme", "excludeme")), |
177 | | - arguments(List.of(), Set.of("keepme", "excludeme")), |
178 | | - arguments(null, Set.of("keepme", "excludeme")), |
179 | | - arguments(List.of("no one knows"), Set.of())); |
| 187 | + argumentSet( |
| 188 | + "One keyword to include", |
| 189 | + List.of("CD"), |
| 190 | + null, |
| 191 | + null, |
| 192 | + null, |
| 193 | + Set.of("keepme")), |
| 194 | + argumentSet( |
| 195 | + "Two keywords to include", |
| 196 | + List.of("CD", "Experimental"), |
| 197 | + null, |
| 198 | + null, |
| 199 | + null, |
| 200 | + Set.of("keepme", "excludeme")), |
| 201 | + argumentSet( |
| 202 | + "Empty list of keywords to include", |
| 203 | + List.of(), |
| 204 | + null, |
| 205 | + null, |
| 206 | + null, |
| 207 | + Set.of("keepme", "excludeme")), |
| 208 | + argumentSet( |
| 209 | + "null for all filters", |
| 210 | + null, |
| 211 | + null, |
| 212 | + null, |
| 213 | + null, |
| 214 | + Set.of("keepme", "excludeme")), |
| 215 | + argumentSet( |
| 216 | + "Unknown keyword to include", |
| 217 | + List.of("no one knows"), |
| 218 | + null, |
| 219 | + null, |
| 220 | + null, |
| 221 | + Set.of())); |
| 222 | + } |
| 223 | + |
| 224 | + private static Stream<Arguments> excludeKeywords() { |
| 225 | + return Stream.of( |
| 226 | + argumentSet( |
| 227 | + "One keyword to exclude", |
| 228 | + null, |
| 229 | + List.of("Experimental"), |
| 230 | + null, |
| 231 | + null, |
| 232 | + Set.of("keepme")), |
| 233 | + argumentSet( |
| 234 | + "Exclusive keywords to include and exclude", |
| 235 | + List.of("CD"), |
| 236 | + List.of("Experimental"), |
| 237 | + null, |
| 238 | + null, |
| 239 | + Set.of("keepme")), |
| 240 | + argumentSet( |
| 241 | + "Keyword to exclude takes precedence", |
| 242 | + List.of("Experimental"), |
| 243 | + List.of("Experimental"), |
| 244 | + null, |
| 245 | + null, |
| 246 | + Set.of()), |
| 247 | + argumentSet( |
| 248 | + "Two keywords to exclude", |
| 249 | + List.of("CD"), |
| 250 | + List.of("CD", "Experimental"), |
| 251 | + null, |
| 252 | + null, |
| 253 | + Set.of()), |
| 254 | + argumentSet( |
| 255 | + "Empty lists of keywords to include and exclude", |
| 256 | + List.of(), |
| 257 | + List.of(), |
| 258 | + null, |
| 259 | + null, |
| 260 | + Set.of("keepme", "excludeme")), |
| 261 | + argumentSet( |
| 262 | + "Unknown keyword to exclude", |
| 263 | + null, |
| 264 | + List.of("no one knows"), |
| 265 | + null, |
| 266 | + null, |
| 267 | + Set.of("keepme", "excludeme"))); |
| 268 | + } |
| 269 | + |
| 270 | + private static Stream<Arguments> includeAnnotations() { |
| 271 | + return Stream.of( |
| 272 | + argumentSet( |
| 273 | + "One annotation to include", |
| 274 | + null, |
| 275 | + null, |
| 276 | + Map.of("lifecycle", "production"), |
| 277 | + null, |
| 278 | + Set.of("keepme")), |
| 279 | + argumentSet( |
| 280 | + "Exclude keyword takes precedence", |
| 281 | + null, |
| 282 | + List.of("CD"), |
| 283 | + Map.of("lifecycle", "production"), |
| 284 | + null, |
| 285 | + Set.of())); |
| 286 | + } |
| 287 | + |
| 288 | + private static Stream<Arguments> excludeAnnotations() { |
| 289 | + return Stream.of( |
| 290 | + argumentSet( |
| 291 | + "One annotation to exclude", |
| 292 | + null, |
| 293 | + null, |
| 294 | + null, |
| 295 | + Map.of("lifecycle", "production"), |
| 296 | + Set.of("excludeme")), |
| 297 | + argumentSet( |
| 298 | + "Exclude annotation takes precedence", |
| 299 | + null, |
| 300 | + null, |
| 301 | + Map.of("lifecycle", "production"), |
| 302 | + Map.of("lifecycle", "production"), |
| 303 | + Set.of())); |
180 | 304 | } |
181 | 305 | } |
0 commit comments