You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/src/test/java/dev/openfeature/javasdk/HookSpecTests.java
+35-15Lines changed: 35 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -140,6 +140,7 @@ void emptyApiHooks() {
140
140
.build();
141
141
}
142
142
143
+
@Specification(number="4.3.2", text="The before stage MUST run before flag resolution occurs. It accepts a hook context (required) and hook hints (optional) as parameters and returns either an evaluation context or nothing.")
143
144
@Testvoidbefore_runs_ahead_of_evaluation() {
144
145
OpenFeatureAPIapi = OpenFeatureAPI.getInstance();
145
146
api.setProvider(newAlwaysBrokenProvider());
@@ -180,7 +181,12 @@ void emptyApiHooks() {
180
181
verify(h, times(0)).error(any(), any(), any());
181
182
}
182
183
184
+
183
185
@Specification(number="4.4.1", text="The API, Client and invocation MUST have a method for registering hooks which accepts flag evaluation options")
186
+
@Specification(number="4.3.5", text="The after stage MUST run after flag resolution occurs. It accepts a hook context (required), flag evaluation details (required) and hook hints (optional). It has no return value.")
187
+
@Specification(number="4.4.2", text="Hooks MUST be evaluated in the following order: - before: API, Client, Invocation - after: Invocation, Client, API - error (if applicable): Invocation, Client, API - finally: Invocation, Client, API")
188
+
@Specification(number="4.3.6", text="The error hook MUST run when errors are encountered in the before stage, the after stage or during flag resolution. It accepts hook context (required), exception representing what went wrong (required), and hook hints (optional). It has no return value.")
189
+
@Specification(number="4.3.7", text="The finally hook MUST run after the before, after, and error stages. It accepts a hook context (required) and hook hints (optional). There is no return value.")
184
190
@Testvoidhook_eval_order() {
185
191
List<String> evalOrder = newArrayList<String>();
186
192
OpenFeatureAPIapi = OpenFeatureAPI.getInstance();
@@ -281,6 +287,8 @@ public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object>
281
287
}
282
288
283
289
290
+
@Specification(number="4.2.1", text="hook hints MUST be a structure supports definition of arbitrary properties, with keys of type string, and values of type boolean | string | number | datetime | structure..")
291
+
@Specification(number="4.5.2", text="hook hints MUST be passed to each hook.")
284
292
@Testvoidhook_hints() {
285
293
OpenFeatureAPIapi = OpenFeatureAPI.getInstance();
286
294
api.setProvider(newNoOpProvider());
@@ -316,6 +324,7 @@ public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object>
316
324
.build());
317
325
}
318
326
327
+
@Specification(number="4.5.1", text="Flag evaluation options MAY contain hook hints, a map of data to be provided to hook invocations.")
@Specification(number="4.1.4", text="The evaluation context MUST be mutable only within the before hook.")
404
+
@Specification(number="4.3.3", text="Any evaluation context returned from a before hook MUST be passed to subsequent before hooks (via HookContext).")
380
405
@TestvoidbeforeContextUpdated() {
381
406
EvaluationContextctx = newEvaluationContext();
382
407
Hookhook = mock(Hook.class);
@@ -404,6 +429,8 @@ public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object>
404
429
assertEquals(hc.getCtx(), ctx);
405
430
406
431
}
432
+
433
+
@Specification(number="4.3.4", text="When before hooks have finished executing, any resulting evaluation context MUST be merged with the invocation evaluation context with the invocation evaluation context taking precedence in the case of any conflicts.")
@@ -437,28 +464,21 @@ public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object>
437
464
438
465
439
466
@Specification(number="4.1.2", text="The hook context SHOULD provide: access to the client metadata and the provider metadata fields.")
440
-
@Specification(number="4.1.4", text="The evaluation context MUST be mutable only within the before hook.")
441
-
@Specification(number="4.2.1", text="hook hints MUST be a structure supports definition of arbitrary properties, with keys of type string, and values of type boolean | string | number | datetime | structure..")
442
467
@Specification(number="4.2.2.1", text="Condition: Hook hints MUST be immutable.")
443
468
@Specification(number="4.2.2.2", text="Condition: The client metadata field in the hook context MUST be immutable.")
444
469
@Specification(number="4.2.2.3", text="Condition: The provider metadata field in the hook context MUST be immutable.")
445
-
@Specification(number="4.3.1", text="Hooks MUST specify at least one stage.")
446
-
@Specification(number="4.3.2", text="The before stage MUST run before flag resolution occurs. It accepts a hook context (required) and hook hints (optional) as parameters and returns either an evaluation context or nothing.")
447
-
@Specification(number="4.3.3", text="Any evaluation context returned from a before hook MUST be passed to subsequent before hooks (via HookContext).")
448
-
@Specification(number="4.3.4", text="When before hooks have finished executing, any resulting evaluation context MUST be merged with the invocation evaluation context with the invocation evaluation context taking precedence in the case of any conflicts.")
449
-
@Specification(number="4.3.5", text="The after stage MUST run after flag resolution occurs. It accepts a hook context (required), flag evaluation details (required) and hook hints (optional). It has no return value.")
450
-
@Specification(number="4.3.6", text="The error hook MUST run when errors are encountered in the before stage, the after stage or during flag resolution. It accepts hook context (required), exception representing what went wrong (required), and hook hints (optional). It has no return value.")
451
-
@Specification(number="4.3.7", text="The finally hook MUST run after the before, after, and error stages. It accepts a hook context (required) and hook hints (optional). There is no return value.")
452
-
@Specification(number="4.3.8.1", text="Instead of finally, finallyAfter SHOULD be used.")
453
-
@Specification(number="4.4.2", text="Hooks MUST be evaluated in the following order: - before: API, Client, Invocation - after: Invocation, Client, API - error (if applicable): Invocation, Client, API - finally: Invocation, Client, API")
470
+
471
+
454
472
@Specification(number="4.4.3", text="If a finally hook abnormally terminates, evaluation MUST proceed, including the execution of any remaining finally hooks.")
455
473
@Specification(number="4.4.4", text="If an error hook abnormally terminates, evaluation MUST proceed, including the execution of any remaining error hooks.")
456
-
@Specification(number="4.4.5", text="If an error occurs in the before or after hooks, the error hooks MUST be invoked.")
457
-
@Specification(number="4.5.1", text="Flag evaluation options MAY contain hook hints, a map of data to be provided to hook invocations.")
458
-
@Specification(number="4.5.2", text="hook hints MUST be passed to each hook.")
474
+
459
475
@Specification(number="4.5.3", text="The hook MUST NOT alter the hook hints structure.")
460
476
@Test@Disabledvoidtodo() {}
461
477
478
+
@Specification(number="4.3.1", text="Hooks MUST specify at least one stage.")
479
+
@Testvoiddefault_methods_so_impossible() {}
480
+
481
+
@Specification(number="4.3.8.1", text="Instead of finally, finallyAfter SHOULD be used.")
0 commit comments