1
+ package com .linkedin .hoptimator .util ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .Arrays ;
5
+ import java .util .Collections ;
6
+ import java .util .List ;
7
+ import java .util .Map ;
8
+ import java .util .Properties ;
9
+
10
+ import org .junit .jupiter .api .Test ;
11
+
12
+ import static com .linkedin .hoptimator .util .DeploymentService .HINT_OPTION ;
13
+ import static com .linkedin .hoptimator .util .DeploymentService .PIPELINE_OPTION ;
14
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
15
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
16
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
17
+
18
+
19
+ class DeploymentServiceTest {
20
+
21
+ /**
22
+ * "hint" keys <b>and</b> values are required to be non-{@code null}. An
23
+ * empty {@link Map} is considered invalid and should <b>not</b> be added
24
+ * to the {@link Properties} object.
25
+ * <br/>
26
+ * nb. "pipeline" values are <b>always</b> added when present.
27
+ */
28
+ @ Test
29
+ void parseHints () {
30
+ Map <String , String > empty = DeploymentService .parseHints (new Properties ());
31
+ assertTrue (empty .isEmpty (), "An empty map should not add `hints`." );
32
+
33
+ Map <String , String > defined = DeploymentService .parseHints (new Properties () {{
34
+ put (HINT_OPTION , "key=value" );
35
+ }});
36
+ assertEquals ("value" , defined .get ("key" ), "Did not match expected key value pair: `key=value`." );
37
+
38
+ Map <String , String > nokey = DeploymentService .parseHints (new Properties () {{
39
+ put (HINT_OPTION , "flag0=,flag1=" );
40
+ }});
41
+ assertTrue (nokey .keySet ().containsAll (Arrays .asList ("flag0" , "flag1" )), "Expected to find flags." );
42
+
43
+ Map <String , String > pipelineOnly = DeploymentService .parseHints (new Properties () {{
44
+ put (PIPELINE_OPTION , "pipeline" );
45
+ }});
46
+ assertEquals ("pipeline" , pipelineOnly .get (PIPELINE_OPTION ), "Did not match expected `pipeline` value." );
47
+
48
+ Map <String , String > both = DeploymentService .parseHints (new Properties () {{
49
+ putAll (defined );
50
+ put (PIPELINE_OPTION , "pipeline" );
51
+ }});
52
+ assertEquals ("pipeline" , both .get (PIPELINE_OPTION ), "Did not match expected `pipeline` value." );
53
+ }
54
+ }
0 commit comments