3
3
import org .junit .jupiter .api .Test ;
4
4
5
5
import java .time .ZonedDateTime ;
6
+ import java .util .Map ;
6
7
7
8
import static org .junit .jupiter .api .Assertions .assertEquals ;
9
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
10
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
8
11
9
12
public class EvalContextTest {
10
- @ Specification (number ="3.1" ,
13
+ @ Specification (number ="3.1.1 " ,
11
14
text ="The `evaluation context` structure **MUST** define an optional `targeting key` field of " +
12
15
"type string, identifying the subject of the flag evaluation." )
13
16
@ Test void requires_targeting_key () {
@@ -16,7 +19,7 @@ public class EvalContextTest {
16
19
assertEquals ("targeting-key" , ec .getTargetingKey ());
17
20
}
18
21
19
- @ Specification (number ="3.2" , text ="The evaluation context MUST support the inclusion of " +
22
+ @ Specification (number ="3.1. 2" , text ="The evaluation context MUST support the inclusion of " +
20
23
"custom fields, having keys of type `string`, and " +
21
24
"values of type `boolean | string | number | datetime | structure`." )
22
25
@ Test void eval_context () {
@@ -36,7 +39,7 @@ public class EvalContextTest {
36
39
assertEquals (dt , ec .getDatetimeAttribute ("dt" ));
37
40
}
38
41
39
- @ Specification (number ="3.2" , text ="The evaluation context MUST support the inclusion of " +
42
+ @ Specification (number ="3.1. 2" , text ="The evaluation context MUST support the inclusion of " +
40
43
"custom fields, having keys of type `string`, and " +
41
44
"values of type `boolean | string | number | datetime | structure`." )
42
45
@ Test void eval_context__structure () {
@@ -59,4 +62,44 @@ public class EvalContextTest {
59
62
assertEquals (2 , nodeFromString .value );
60
63
assertEquals (4 , nodeFromString .left .value );
61
64
}
65
+
66
+ @ Specification (number ="3.1.3" , text ="The evaluation context MUST support fetching the custom fields by key and " +
67
+ "also fetching all of the keys and values." )
68
+ @ Test void fetch_all () {
69
+ EvaluationContext ec = new EvaluationContext ();
70
+
71
+ ec .addStringAttribute ("str" , "test" );
72
+ ec .addStringAttribute ("str2" , "test2" );
73
+
74
+ ec .addBooleanAttribute ("bool" , true );
75
+ ec .addBooleanAttribute ("bool2" , false );
76
+
77
+ ec .addIntegerAttribute ("int" , 4 );
78
+ ec .addIntegerAttribute ("int2" , 2 );
79
+
80
+ ZonedDateTime dt = ZonedDateTime .now ();
81
+ ec .addDatetimeAttribute ("dt" , dt );
82
+
83
+ Node <Integer > n1 = new Node <>();
84
+ n1 .value = 4 ;
85
+ Node <Integer > n2 = new Node <>();
86
+ n2 .value = 2 ;
87
+ n2 .left = n1 ;
88
+ ec .addStructureAttribute ("obj" , n2 );
89
+
90
+ Map <String , String > foundStr = ec .getStringAttributes ();
91
+ assertEquals ("test" , foundStr .get ("str" ));
92
+ assertEquals ("test2" , foundStr .get ("str2" ));
93
+
94
+ Map <String , Boolean > foundBool = ec .getBooleanAttributes ();
95
+ assertTrue (foundBool .get ("bool" ));
96
+ assertFalse (foundBool .get ("bool2" ));
97
+
98
+ Map <String , Integer > foundInt = ec .getIntegerAttributes ();
99
+ assertEquals (4 , foundInt .get ("int" ));
100
+ assertEquals (2 , foundInt .get ("int2" ));
101
+
102
+ Map <String , String > foundObj = ec .getStructureAttributes ();
103
+ assertEquals ("{\" left\" :{\" left\" :null,\" right\" :null,\" value\" :4},\" right\" :null,\" value\" :2}" , foundObj .get ("obj" ));
104
+ }
62
105
}
0 commit comments