1111
1212import com .eppo .sdk .dto .*;
1313import com .eppo .sdk .helpers .Converter ;
14- import com .fasterxml .jackson .core .JacksonException ;
1514import com .fasterxml .jackson .core .JsonParser ;
1615import com .fasterxml .jackson .databind .*;
1716import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
3130
3231import lombok .Data ;
3332
34-
3533@ ExtendWith (WireMockExtension .class )
3634public class EppoClientTest {
3735
@@ -120,23 +118,24 @@ public AssignmentValueType deserialize(JsonParser jsonParser, DeserializationCon
120118 void init () {
121119 setupMockRacServer ();
122120 EppoClientConfig config = EppoClientConfig .builder ()
123- .apiKey ("mock-api-key" )
124- .baseURL ("http://localhost:4001" )
125- .assignmentLogger (new IAssignmentLogger () {
126- @ Override
127- public void logAssignment (AssignmentLogData logData ) {
128- // Auto-generated method stub
129- }
130- })
131- .build ();
121+ .apiKey ("mock-api-key" )
122+ .baseURL ("http://localhost:4001" )
123+ .assignmentLogger (new IAssignmentLogger () {
124+ @ Override
125+ public void logAssignment (AssignmentLogData logData ) {
126+ // Auto-generated method stub
127+ }
128+ })
129+ .build ();
132130 EppoClient .init (config );
133131 }
134132
135133 private void setupMockRacServer () {
136134 this .mockServer = new WireMockServer (TEST_PORT );
137135 this .mockServer .start ();
138136 String racResponseJson = getMockRandomizedAssignmentResponse ();
139- this .mockServer .stubFor (WireMock .get (WireMock .urlMatching (".*randomized_assignment.*" )).willReturn (WireMock .okJson (racResponseJson )));
137+ this .mockServer .stubFor (
138+ WireMock .get (WireMock .urlMatching (".*randomized_assignment.*" )).willReturn (WireMock .okJson (racResponseJson )));
140139 }
141140
142141 @ AfterEach
@@ -159,8 +158,14 @@ void testAssignments(AssignmentTestCase testCase) throws IOException {
159158 assertEquals (expectedBooleanAssignments , actualBooleanAssignments );
160159 break ;
161160 case JSON :
162- List <String > actualJSONAssignments = this .getJSONAssignments (testCase );
163- assertEquals (testCase .expectedAssignments , actualJSONAssignments );
161+ List <JsonNode > actualJSONAssignments = this .getJSONAssignments (testCase );
162+ for (JsonNode node : actualJSONAssignments ) {
163+ assertEquals (JsonNodeType .OBJECT , node .getNodeType ());
164+ }
165+
166+ assertEquals (testCase .expectedAssignments , actualJSONAssignments .stream ()
167+ .map (node -> node .toString ())
168+ .collect (Collectors .toList ()));
164169 break ;
165170 default :
166171 List <String > actualStringAssignments = this .getStringAssignments (testCase );
@@ -173,48 +178,49 @@ private List<?> getAssignments(AssignmentTestCase testCase, AssignmentValueType
173178 EppoClient client = EppoClient .getInstance ();
174179 if (testCase .subjectsWithAttributes != null ) {
175180 return testCase .subjectsWithAttributes .stream ()
181+ .map (subject -> {
182+ try {
183+ switch (valueType ) {
184+ case NUMERIC :
185+ return client .getDoubleAssignment (subject .subjectKey , testCase .experiment , subject .subjectAttributes )
186+ .orElse (null );
187+ case BOOLEAN :
188+ return client .getBooleanAssignment (subject .subjectKey , testCase .experiment , subject .subjectAttributes )
189+ .orElse (null );
190+ case JSON :
191+ return client
192+ .getParsedJSONAssignment (subject .subjectKey , testCase .experiment , subject .subjectAttributes )
193+ .orElse (null );
194+ default :
195+ return client .getStringAssignment (subject .subjectKey , testCase .experiment , subject .subjectAttributes )
196+ .orElse (null );
197+ }
198+ } catch (Exception e ) {
199+ throw new RuntimeException (e );
200+ }
201+ }).collect (Collectors .toList ());
202+ }
203+ return testCase .subjects .stream ()
176204 .map (subject -> {
177205 try {
178206 switch (valueType ) {
179207 case NUMERIC :
180- return client .getDoubleAssignment (subject . subjectKey , testCase .experiment , subject . subjectAttributes )
181- .orElse (null );
208+ return client .getDoubleAssignment (subject , testCase .experiment )
209+ .orElse (null );
182210 case BOOLEAN :
183- return client .getBooleanAssignment (subject . subjectKey , testCase .experiment , subject . subjectAttributes )
184- .orElse (null );
211+ return client .getBooleanAssignment (subject , testCase .experiment )
212+ .orElse (null );
185213 case JSON :
186- return client .getJSONAssignment (subject . subjectKey , testCase .experiment , subject . subjectAttributes )
187- .orElse (null );
214+ return client .getParsedJSONAssignment (subject , testCase .experiment )
215+ .orElse (null );
188216 default :
189- return client .getStringAssignment (subject . subjectKey , testCase .experiment , subject . subjectAttributes )
190- .orElse (null );
217+ return client .getStringAssignment (subject , testCase .experiment )
218+ .orElse (null );
191219 }
192220 } catch (Exception e ) {
193221 throw new RuntimeException (e );
194222 }
195223 }).collect (Collectors .toList ());
196- }
197- return testCase .subjects .stream ()
198- .map (subject -> {
199- try {
200- switch (valueType ) {
201- case NUMERIC :
202- return client .getDoubleAssignment (subject , testCase .experiment )
203- .orElse (null );
204- case BOOLEAN :
205- return client .getBooleanAssignment (subject , testCase .experiment )
206- .orElse (null );
207- case JSON :
208- return client .getJSONAssignment (subject , testCase .experiment )
209- .orElse (null );
210- default :
211- return client .getStringAssignment (subject , testCase .experiment )
212- .orElse (null );
213- }
214- } catch (Exception e ) {
215- throw new RuntimeException (e );
216- }
217- }).collect (Collectors .toList ());
218224 }
219225
220226 private List <String > getStringAssignments (AssignmentTestCase testCase ) {
@@ -229,8 +235,8 @@ private List<Boolean> getBooleanAssignments(AssignmentTestCase testCase) {
229235 return (List <Boolean >) this .getAssignments (testCase , AssignmentValueType .BOOLEAN );
230236 }
231237
232- private List <String > getJSONAssignments (AssignmentTestCase testCase ) {
233- return (List <String >) this .getAssignments (testCase , AssignmentValueType .JSON );
238+ private List <JsonNode > getJSONAssignments (AssignmentTestCase testCase ) {
239+ return (List <JsonNode >) this .getAssignments (testCase , AssignmentValueType .JSON );
234240 }
235241
236242 private static Stream <Arguments > getAssignmentTestData () throws IOException {
@@ -248,7 +254,7 @@ private static Stream<Arguments> getAssignmentTestData() throws IOException {
248254 private static String getMockRandomizedAssignmentResponse () {
249255 File mockRacResponse = new File ("src/test/resources/rac-experiments-v3.json" );
250256 try {
251- return FileUtils .readFileToString (mockRacResponse , "UTF8" );
257+ return FileUtils .readFileToString (mockRacResponse , "UTF8" );
252258 } catch (Exception e ) {
253259 throw new RuntimeException ("Error reading mock RAC data" , e );
254260 }
0 commit comments