|
1 | 1 | package com.flagsmith.flagengine.unit.mappers; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; |
3 | 4 | import com.flagsmith.MapperFactory; |
4 | 5 | import com.flagsmith.flagengine.EvaluationContext; |
5 | 6 | import com.flagsmith.flagengine.FeatureContext; |
|
12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; |
13 | 14 | import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
14 | 15 |
|
15 | | -import java.io.IOException; |
16 | | -import java.io.InputStream; |
17 | 16 | import java.util.List; |
18 | 17 | import java.util.Map; |
19 | 18 | import java.util.stream.Stream; |
@@ -61,10 +60,59 @@ public void testMapContextAndIdentityDataToContext_returnsExpectedContext( |
61 | 60 |
|
62 | 61 | @Test |
63 | 62 | public void testMapEnvironmentToContext_preservesMultivariateValueTypes() |
64 | | - throws IOException { |
65 | | - InputStream json = getClass().getResourceAsStream("multivariate_environment.json"); |
| 63 | + throws JsonProcessingException { |
| 64 | + String environmentJson = "{\n" |
| 65 | + + " \"api_key\": \"test-key\",\n" |
| 66 | + + " \"name\": \"Test\",\n" |
| 67 | + + " \"project\": {\n" |
| 68 | + + " \"name\": \"Test project\",\n" |
| 69 | + + " \"organisation\": {\n" |
| 70 | + + " \"feature_analytics\": false,\n" |
| 71 | + + " \"name\": \"Test Org\",\n" |
| 72 | + + " \"id\": 1,\n" |
| 73 | + + " \"persist_trait_data\": true,\n" |
| 74 | + + " \"stop_serving_flags\": false\n" |
| 75 | + + " },\n" |
| 76 | + + " \"id\": 1,\n" |
| 77 | + + " \"hide_disabled_flags\": false,\n" |
| 78 | + + " \"segments\": []\n" |
| 79 | + + " },\n" |
| 80 | + + " \"segment_overrides\": [],\n" |
| 81 | + + " \"id\": 1,\n" |
| 82 | + + " \"feature_states\": [\n" |
| 83 | + + " {\n" |
| 84 | + + " \"feature_state_value\": true,\n" |
| 85 | + + " \"django_id\": 1,\n" |
| 86 | + + " \"featurestate_uuid\": \"40eb539d-3713-4720-bbd4-829dbef10d51\",\n" |
| 87 | + + " \"feature\": { \"name\": \"mv_feature\", \"type\": \"MULTIVARIATE\", \"id\": 1 },\n" |
| 88 | + + " \"enabled\": true,\n" |
| 89 | + + " \"multivariate_feature_state_values\": [\n" |
| 90 | + + " {\n" |
| 91 | + + " \"id\": 1,\n" |
| 92 | + + " \"multivariate_feature_option\": { \"value\": false },\n" |
| 93 | + + " \"percentage_allocation\": 50.0,\n" |
| 94 | + + " \"mv_fs_value_uuid\": \"808cba14-03ca-4835-a7f7-58387f01f87d\"\n" |
| 95 | + + " },\n" |
| 96 | + + " {\n" |
| 97 | + + " \"id\": 2,\n" |
| 98 | + + " \"multivariate_feature_option\": { \"value\": 42 },\n" |
| 99 | + + " \"percentage_allocation\": 30.0,\n" |
| 100 | + + " \"mv_fs_value_uuid\": \"918dbb25-14db-4946-b8a8-69488f02f98e\"\n" |
| 101 | + + " },\n" |
| 102 | + + " {\n" |
| 103 | + + " \"id\": 3,\n" |
| 104 | + + " \"multivariate_feature_option\": { \"value\": \"a string\" },\n" |
| 105 | + + " \"percentage_allocation\": 20.0,\n" |
| 106 | + + " \"mv_fs_value_uuid\": \"a29eca36-25dc-5057-c9b9-7a599f13g09f\"\n" |
| 107 | + + " }\n" |
| 108 | + + " ]\n" |
| 109 | + + " }\n" |
| 110 | + + " ],\n" |
| 111 | + + " \"identity_overrides\": []\n" |
| 112 | + + "}"; |
| 113 | + |
66 | 114 | EnvironmentModel env = MapperFactory.getMapper() |
67 | | - .readValue(json, EnvironmentModel.class); |
| 115 | + .readValue(environmentJson, EnvironmentModel.class); |
68 | 116 |
|
69 | 117 | EvaluationContext context = EngineMappers.mapEnvironmentToContext(env); |
70 | 118 |
|
|
0 commit comments