|
2 | 2 |
|
3 | 3 | import static dev.openfeature.sdk.DoSomethingProvider.DEFAULT_METADATA;
|
4 | 4 | import static org.assertj.core.api.Assertions.assertThat;
|
5 |
| -import static org.assertj.core.api.Assertions.assertThatCode; |
6 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
7 | 6 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
8 | 7 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
20 | 19 | import java.util.HashMap;
|
21 | 20 | import java.util.List;
|
22 | 21 | import java.util.Map;
|
| 22 | +import java.util.Optional; |
23 | 23 |
|
24 | 24 | import org.awaitility.Awaitility;
|
25 | 25 | import org.junit.jupiter.api.AfterEach;
|
@@ -336,11 +336,25 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
|
336 | 336 | FeatureProviderTestUtils.setFeatureProvider(provider);
|
337 | 337 | TransactionContextPropagator transactionContextPropagator = new ThreadLocalTransactionContextPropagator();
|
338 | 338 | api.setTransactionContextPropagator(transactionContextPropagator);
|
| 339 | + Hook<Boolean> hook = spy(new Hook<Boolean>() { |
| 340 | + @Override |
| 341 | + public Optional<EvaluationContext> before(HookContext<Boolean> ctx, Map<String, Object> hints) { |
| 342 | + Map<String, Value> attrs = ctx.getCtx().asMap(); |
| 343 | + attrs.put("before", new Value("5")); |
| 344 | + attrs.put("common7", new Value("5")); |
| 345 | + return Optional.ofNullable(new ImmutableContext(attrs)); |
| 346 | + } |
| 347 | + @Override |
| 348 | + public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) { |
| 349 | + Hook.super.after(ctx, details, hints); |
| 350 | + } |
| 351 | + }); |
339 | 352 |
|
340 | 353 | Map<String, Value> apiAttributes = new HashMap<>();
|
341 | 354 | apiAttributes.put("common1", new Value("1"));
|
342 | 355 | apiAttributes.put("common2", new Value("1"));
|
343 | 356 | apiAttributes.put("common3", new Value("1"));
|
| 357 | + apiAttributes.put("common7", new Value("1")); |
344 | 358 | apiAttributes.put("api", new Value("1"));
|
345 | 359 | EvaluationContext apiCtx = new ImmutableContext(apiAttributes);
|
346 | 360 |
|
@@ -377,21 +391,54 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
|
377 | 391 | invocationAttributes.put("invocation", new Value("4"));
|
378 | 392 | EvaluationContext invocationCtx = new ImmutableContext(invocationAttributes);
|
379 | 393 |
|
380 |
| - c.getBooleanValue("key", false, invocationCtx); |
381 |
| - |
382 |
| - // assert the connect overrides |
| 394 | + c.getBooleanValue("key", false, invocationCtx, FlagEvaluationOptions.builder().hook(hook).build()); |
| 395 | + |
| 396 | + // assert the connect overrides in before hook |
| 397 | + verify(hook).before(argThat((arg) -> { |
| 398 | + EvaluationContext evaluationContext = arg.getCtx(); |
| 399 | + return evaluationContext.getValue("api").asString().equals("1") && |
| 400 | + evaluationContext.getValue("transaction").asString().equals("2") && |
| 401 | + evaluationContext.getValue("client").asString().equals("3") && |
| 402 | + evaluationContext.getValue("invocation").asString().equals("4") && |
| 403 | + evaluationContext.getValue("common1").asString().equals("2") && |
| 404 | + evaluationContext.getValue("common2").asString().equals("3") && |
| 405 | + evaluationContext.getValue("common3").asString().equals("4") && |
| 406 | + evaluationContext.getValue("common4").asString().equals("3") && |
| 407 | + evaluationContext.getValue("common5").asString().equals("4") && |
| 408 | + evaluationContext.getValue("common6").asString().equals("4"); |
| 409 | + }), any()); |
| 410 | + |
| 411 | + // assert the connect overrides in evaluation |
383 | 412 | verify(provider).getBooleanEvaluation(any(), any(), argThat((arg) -> {
|
384 | 413 | return arg.getValue("api").asString().equals("1") &&
|
385 | 414 | arg.getValue("transaction").asString().equals("2") &&
|
386 | 415 | arg.getValue("client").asString().equals("3") &&
|
387 | 416 | arg.getValue("invocation").asString().equals("4") &&
|
| 417 | + arg.getValue("before").asString().equals("5") && |
388 | 418 | arg.getValue("common1").asString().equals("2") &&
|
389 | 419 | arg.getValue("common2").asString().equals("3") &&
|
390 | 420 | arg.getValue("common3").asString().equals("4") &&
|
391 | 421 | arg.getValue("common4").asString().equals("3") &&
|
392 | 422 | arg.getValue("common5").asString().equals("4") &&
|
393 |
| - arg.getValue("common6").asString().equals("4"); |
| 423 | + arg.getValue("common6").asString().equals("4") && |
| 424 | + arg.getValue("common7").asString().equals("5"); |
394 | 425 | }));
|
| 426 | + |
| 427 | + // assert the connect overrides in after hook |
| 428 | + verify(hook).after(argThat((arg) -> { |
| 429 | + EvaluationContext evaluationContext = arg.getCtx(); |
| 430 | + return evaluationContext.getValue("api").asString().equals("1") && |
| 431 | + evaluationContext.getValue("transaction").asString().equals("2") && |
| 432 | + evaluationContext.getValue("client").asString().equals("3") && |
| 433 | + evaluationContext.getValue("invocation").asString().equals("4") && |
| 434 | + evaluationContext.getValue("before").asString().equals("5") && |
| 435 | + evaluationContext.getValue("common1").asString().equals("2") && |
| 436 | + evaluationContext.getValue("common2").asString().equals("3") && |
| 437 | + evaluationContext.getValue("common3").asString().equals("4") && |
| 438 | + evaluationContext.getValue("common4").asString().equals("3") && |
| 439 | + evaluationContext.getValue("common5").asString().equals("4") && |
| 440 | + evaluationContext.getValue("common6").asString().equals("4"); |
| 441 | + }), any(), any()); |
395 | 442 | }
|
396 | 443 |
|
397 | 444 | @Specification(number="3.3.1.1", text="The API SHOULD have a method for setting a transaction context propagator.")
|
|
0 commit comments