-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMetricsServiceTest.java
More file actions
93 lines (78 loc) · 3 KB
/
MetricsServiceTest.java
File metadata and controls
93 lines (78 loc) · 3 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
package org.phoebus.channelfinder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.phoebus.channelfinder.service.MetricsService;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
class MetricsServiceTest {
@Test
void testGenerateAllMultiValueMaps_example1() {
Map<String, List<String>> properties =
Map.of(
"a", List.of("b", "c"),
"d", List.of("e", "!*"));
List<MultiValueMap<String, String>> allMaps =
MetricsService.generateAllMultiValueMaps(properties);
assertEquals(4, allMaps.size());
assertTrue(allMaps.contains(createMap("a", "b", "d", "e")));
assertTrue(allMaps.contains(createMap("a", "c", "d", "e")));
assertTrue(allMaps.contains(createMap("a", "b", "d!", "*")));
assertTrue(allMaps.contains(createMap("a", "c", "d!", "*")));
}
@Test
void testGenerateAllMultiValueMaps_example2() {
Map<String, List<String>> properties =
Map.of(
"x", List.of("y", "z"),
"p", List.of("q"),
"r", List.of("s", "t"));
List<MultiValueMap<String, String>> allMaps =
MetricsService.generateAllMultiValueMaps(properties);
assertEquals(2 * 2, allMaps.size()); // 2 options (value or null) for each of 2 keys
// Just a basic check, exhaustive check would be large
boolean foundExpectedCombination = false;
for (MultiValueMap<String, String> map : allMaps) {
if (map.get("x").contains("y") && map.get("p").contains("q") && map.get("r").contains("s")) {
foundExpectedCombination = true;
break;
}
}
assertTrue(foundExpectedCombination);
}
@Test
void testGenerateAllMultiValueMaps_emptyList() {
Map<String, List<String>> properties = Map.of("m", List.of());
List<MultiValueMap<String, String>> allMaps =
MetricsService.generateAllMultiValueMaps(properties);
assertEquals(0, allMaps.size()); // One with m=null, one with m implicitly null (not present)
}
@Test
void testGenerateAllMultiValueMaps_emptyMap() {
Map<String, List<String>> properties = Map.of();
List<MultiValueMap<String, String>> allMaps =
MetricsService.generateAllMultiValueMaps(properties);
assertEquals(0, allMaps.size());
}
// Helper method to create a MultiValueMap for easier assertion
private MultiValueMap<String, String> createMap(
String key1, String value1, String key2, String value2) {
LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>();
if (key1 != null) {
map.add(key1, value1);
}
if (key2 != null) {
map.add(key2, value2);
}
return map;
}
private MultiValueMap<String, String> createMap(String key, String value) {
LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>();
if (key != null) {
map.add(key, value);
}
return map;
}
}