|
1 | 1 | package datadog.trace.civisibility.config; |
2 | 2 |
|
3 | | -import com.squareup.moshi.FromJson; |
4 | 3 | import com.squareup.moshi.JsonAdapter; |
5 | 4 | import com.squareup.moshi.Moshi; |
6 | | -import com.squareup.moshi.ToJson; |
7 | 5 | import com.squareup.moshi.Types; |
8 | 6 | import datadog.trace.api.civisibility.config.Configurations; |
9 | 7 | import datadog.trace.api.civisibility.config.TestFQN; |
10 | 8 | import datadog.trace.api.civisibility.config.TestIdentifier; |
11 | 9 | import datadog.trace.api.civisibility.config.TestMetadata; |
12 | | -import java.io.File; |
13 | 10 | import java.io.IOException; |
14 | 11 | import java.lang.reflect.ParameterizedType; |
15 | 12 | import java.nio.file.Path; |
16 | | -import java.util.Base64; |
17 | 13 | import java.util.BitSet; |
18 | 14 | import java.util.Collection; |
19 | 15 | import java.util.Collections; |
@@ -68,7 +64,7 @@ public FileBasedConfigurationApi( |
68 | 64 | .add(CiVisibilitySettings.JsonAdapter.INSTANCE) |
69 | 65 | .add(EarlyFlakeDetectionSettings.JsonAdapter.INSTANCE) |
70 | 66 | .add(TestManagementSettings.JsonAdapter.INSTANCE) |
71 | | - .add(MetaDtoJsonAdapter.INSTANCE) |
| 67 | + .add(MetaDto.JsonAdapter.INSTANCE) |
72 | 68 | .build(); |
73 | 69 |
|
74 | 70 | settingsAdapter = moshi.adapter(SettingsEnvelope.class); |
@@ -248,29 +244,28 @@ private Map<TestSetting, Map<String, Collection<TestFQN>>> parseTestManagementTe |
248 | 244 | Map<String, Collection<TestFQN>> disabled = new HashMap<>(); |
249 | 245 | Map<String, Collection<TestFQN>> attemptToFix = new HashMap<>(); |
250 | 246 |
|
251 | | - if (dto.modules != null) { |
252 | | - for (Map.Entry<String, TestManagementTestsDto.Suites> moduleEntry : dto.modules.entrySet()) { |
253 | | - String moduleName = moduleEntry.getKey(); |
254 | | - Map<String, TestManagementTestsDto.Tests> suites = moduleEntry.getValue().getSuites(); |
255 | | - |
256 | | - for (Map.Entry<String, TestManagementTestsDto.Tests> suiteEntry : suites.entrySet()) { |
257 | | - String suiteName = suiteEntry.getKey(); |
258 | | - Map<String, TestManagementTestsDto.Properties> tests = suiteEntry.getValue().getTests(); |
259 | | - |
260 | | - for (Map.Entry<String, TestManagementTestsDto.Properties> testEntry : tests.entrySet()) { |
261 | | - String testName = testEntry.getKey(); |
262 | | - TestManagementTestsDto.Properties props = testEntry.getValue(); |
263 | | - TestFQN fqn = new TestFQN(suiteName, testName); |
264 | | - |
265 | | - if (props.isQuarantined()) { |
266 | | - quarantined.computeIfAbsent(moduleName, k -> new HashSet<>()).add(fqn); |
267 | | - } |
268 | | - if (props.isDisabled()) { |
269 | | - disabled.computeIfAbsent(moduleName, k -> new HashSet<>()).add(fqn); |
270 | | - } |
271 | | - if (props.isAttemptToFix()) { |
272 | | - attemptToFix.computeIfAbsent(moduleName, k -> new HashSet<>()).add(fqn); |
273 | | - } |
| 247 | + for (Map.Entry<String, TestManagementTestsDto.Suites> moduleEntry : |
| 248 | + dto.getModules().entrySet()) { |
| 249 | + String moduleName = moduleEntry.getKey(); |
| 250 | + Map<String, TestManagementTestsDto.Tests> suites = moduleEntry.getValue().getSuites(); |
| 251 | + |
| 252 | + for (Map.Entry<String, TestManagementTestsDto.Tests> suiteEntry : suites.entrySet()) { |
| 253 | + String suiteName = suiteEntry.getKey(); |
| 254 | + Map<String, TestManagementTestsDto.Properties> tests = suiteEntry.getValue().getTests(); |
| 255 | + |
| 256 | + for (Map.Entry<String, TestManagementTestsDto.Properties> testEntry : tests.entrySet()) { |
| 257 | + String testName = testEntry.getKey(); |
| 258 | + TestManagementTestsDto.Properties props = testEntry.getValue(); |
| 259 | + TestFQN fqn = new TestFQN(suiteName, testName); |
| 260 | + |
| 261 | + if (props.isQuarantined()) { |
| 262 | + quarantined.computeIfAbsent(moduleName, k -> new HashSet<>()).add(fqn); |
| 263 | + } |
| 264 | + if (props.isDisabled()) { |
| 265 | + disabled.computeIfAbsent(moduleName, k -> new HashSet<>()).add(fqn); |
| 266 | + } |
| 267 | + if (props.isAttemptToFix()) { |
| 268 | + attemptToFix.computeIfAbsent(moduleName, k -> new HashSet<>()).add(fqn); |
274 | 269 | } |
275 | 270 | } |
276 | 271 | } |
@@ -322,89 +317,4 @@ static final class TestIdentifierDataDto { |
322 | 317 | String type; |
323 | 318 | TestIdentifierJson attributes; |
324 | 319 | } |
325 | | - |
326 | | - static final class MetaDto { |
327 | | - final String correlationId; |
328 | | - final Map<String, BitSet> coverage; |
329 | | - |
330 | | - MetaDto(String correlationId, Map<String, BitSet> coverage) { |
331 | | - this.correlationId = correlationId; |
332 | | - this.coverage = coverage; |
333 | | - } |
334 | | - } |
335 | | - |
336 | | - static final class MetaDtoJsonAdapter { |
337 | | - static final MetaDtoJsonAdapter INSTANCE = new MetaDtoJsonAdapter(); |
338 | | - |
339 | | - @SuppressWarnings("unchecked") |
340 | | - @FromJson |
341 | | - public MetaDto fromJson(Map<String, Object> json) { |
342 | | - if (json == null) { |
343 | | - return null; |
344 | | - } |
345 | | - |
346 | | - Map<String, BitSet> coverage; |
347 | | - Map<String, String> encodedCoverage = (Map<String, String>) json.get("coverage"); |
348 | | - if (encodedCoverage != null) { |
349 | | - coverage = new HashMap<>(); |
350 | | - for (Map.Entry<String, String> e : encodedCoverage.entrySet()) { |
351 | | - String relativeSourceFilePath = e.getKey(); |
352 | | - String normalizedPath = |
353 | | - relativeSourceFilePath.startsWith(File.separator) |
354 | | - ? relativeSourceFilePath.substring(1) |
355 | | - : relativeSourceFilePath; |
356 | | - byte[] decodedLines = Base64.getDecoder().decode(e.getValue()); |
357 | | - coverage.put(normalizedPath, BitSet.valueOf(decodedLines)); |
358 | | - } |
359 | | - } else { |
360 | | - coverage = null; |
361 | | - } |
362 | | - |
363 | | - return new MetaDto((String) json.get("correlation_id"), coverage); |
364 | | - } |
365 | | - |
366 | | - @ToJson |
367 | | - public Map<String, Object> toJson(MetaDto metaDto) { |
368 | | - throw new UnsupportedOperationException(); |
369 | | - } |
370 | | - } |
371 | | - |
372 | | - static final class TestManagementTestsDto { |
373 | | - Map<String, Suites> modules; |
374 | | - |
375 | | - static final class Properties { |
376 | | - Map<String, Boolean> properties; |
377 | | - |
378 | | - boolean isQuarantined() { |
379 | | - return properties != null |
380 | | - && properties.getOrDefault(TestSetting.QUARANTINED.asString(), false); |
381 | | - } |
382 | | - |
383 | | - boolean isDisabled() { |
384 | | - return properties != null |
385 | | - && properties.getOrDefault(TestSetting.DISABLED.asString(), false); |
386 | | - } |
387 | | - |
388 | | - boolean isAttemptToFix() { |
389 | | - return properties != null |
390 | | - && properties.getOrDefault(TestSetting.ATTEMPT_TO_FIX.asString(), false); |
391 | | - } |
392 | | - } |
393 | | - |
394 | | - static final class Tests { |
395 | | - Map<String, Properties> tests; |
396 | | - |
397 | | - Map<String, Properties> getTests() { |
398 | | - return tests != null ? tests : Collections.emptyMap(); |
399 | | - } |
400 | | - } |
401 | | - |
402 | | - static final class Suites { |
403 | | - Map<String, Tests> suites; |
404 | | - |
405 | | - Map<String, Tests> getSuites() { |
406 | | - return suites != null ? suites : Collections.emptyMap(); |
407 | | - } |
408 | | - } |
409 | | - } |
410 | 320 | } |
0 commit comments