|
1 | 1 | package dev.openfeature.contrib.providers.flagd; |
2 | 2 |
|
3 | 3 | import com.google.protobuf.Struct; |
4 | | -import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.Cache; |
5 | | -import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.CacheType; |
| 4 | +import dev.openfeature.contrib.providers.flagd.resolver.Resolver; |
6 | 5 | import dev.openfeature.contrib.providers.flagd.resolver.grpc.GrpcConnector; |
7 | 6 | import dev.openfeature.contrib.providers.flagd.resolver.grpc.GrpcResolver; |
| 7 | +import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.Cache; |
| 8 | +import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.CacheType; |
8 | 9 | import dev.openfeature.flagd.grpc.Schema.EventStreamResponse; |
9 | 10 | import dev.openfeature.flagd.grpc.Schema.ResolveBooleanRequest; |
10 | 11 | import dev.openfeature.flagd.grpc.Schema.ResolveBooleanResponse; |
|
16 | 17 | import dev.openfeature.flagd.grpc.ServiceGrpc.ServiceBlockingStub; |
17 | 18 | import dev.openfeature.flagd.grpc.ServiceGrpc.ServiceStub; |
18 | 19 | import dev.openfeature.sdk.FlagEvaluationDetails; |
| 20 | +import dev.openfeature.sdk.ImmutableContext; |
19 | 21 | import dev.openfeature.sdk.ImmutableMetadata; |
20 | 22 | import dev.openfeature.sdk.MutableContext; |
21 | 23 | import dev.openfeature.sdk.MutableStructure; |
|
48 | 50 | import static org.mockito.ArgumentMatchers.argThat; |
49 | 51 | import static org.mockito.Mockito.mock; |
50 | 52 | import static org.mockito.Mockito.mockStatic; |
| 53 | +import static org.mockito.Mockito.verify; |
51 | 54 | import static org.mockito.Mockito.when; |
52 | 55 |
|
53 | 56 | class FlagdProviderTest { |
@@ -763,6 +766,39 @@ void disabled_cache() { |
763 | 766 | assertEquals(STATIC_REASON, objectDetails.getReason()); |
764 | 767 | } |
765 | 768 |
|
| 769 | + @Test |
| 770 | + void contextMerging() throws Exception { |
| 771 | + // given |
| 772 | + final FlagdProvider provider = new FlagdProvider(); |
| 773 | + |
| 774 | + final Resolver resolverMock = mock(Resolver.class); |
| 775 | + |
| 776 | + Field flagResolver = FlagdProvider.class.getDeclaredField("flagResolver"); |
| 777 | + flagResolver.setAccessible(true); |
| 778 | + flagResolver.set(provider, resolverMock); |
| 779 | + |
| 780 | + final HashMap<String, Value> globalCtxMap = new HashMap<>(); |
| 781 | + globalCtxMap.put("id", new Value("GlobalID")); |
| 782 | + globalCtxMap.put("env", new Value("A")); |
| 783 | + |
| 784 | + final HashMap<String, Value> localCtxMap = new HashMap<>(); |
| 785 | + localCtxMap.put("id", new Value("localID")); |
| 786 | + localCtxMap.put("client", new Value("999")); |
| 787 | + |
| 788 | + final HashMap<String, Value> expectedCtx = new HashMap<>(); |
| 789 | + expectedCtx.put("id", new Value("localID")); |
| 790 | + expectedCtx.put("env", new Value("A")); |
| 791 | + localCtxMap.put("client", new Value("999")); |
| 792 | + |
| 793 | + // when |
| 794 | + provider.initialize(new ImmutableContext(globalCtxMap)); |
| 795 | + provider.getBooleanEvaluation("ket", false, new ImmutableContext(localCtxMap)); |
| 796 | + |
| 797 | + // then |
| 798 | + verify(resolverMock).booleanEvaluation(any(), any(), argThat( |
| 799 | + ctx -> ctx.asMap().entrySet().containsAll(expectedCtx.entrySet()))); |
| 800 | + } |
| 801 | + |
766 | 802 | // test utils |
767 | 803 |
|
768 | 804 | // create provider with given grpc connector |
|
0 commit comments