55import com .fasterxml .jackson .core .JsonParser ;
66import com .fasterxml .jackson .core .StreamReadFeature ;
77import com .fasterxml .jackson .databind .DeserializationContext ;
8+ import com .fasterxml .jackson .databind .DeserializationFeature ;
89import com .fasterxml .jackson .databind .JsonDeserializer ;
910import com .fasterxml .jackson .databind .ObjectMapper ;
1011import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
12+ import com .fasterxml .jackson .databind .json .JsonMapper ;
1113import dev .openfeature .sdk .Client ;
1214import dev .openfeature .sdk .ErrorCode ;
1315import dev .openfeature .sdk .EvaluationContext ;
@@ -65,41 +67,43 @@ void evaluate(String fileName, String description, String responseJson, FixtureC
6567
6668 EvaluationContext ctx = buildContext (testCase .configuration .context );
6769 FlagEvaluationDetails <Boolean > result = client .getBooleanDetails (
68- testCase .configuration .slug ,
69- testCase .configuration .defaultValue ,
70- ctx
70+ testCase .configuration .slug ,
71+ testCase .configuration .defaultValue ,
72+ ctx
7173 );
7274
7375 assertThat (result .getValue ())
74- .as ("[%s] %s → value" , fileName , description )
75- .isEqualTo (testCase .expected .value );
76+ .as ("[%s] %s → value" , fileName , description )
77+ .isEqualTo (testCase .expected .value );
7678 assertThat (result .getErrorCode ())
77- .as ("[%s] %s → errorCode" , fileName , description )
78- .isEqualTo (mapErrorCode (testCase .expected .errorCode ));
79+ .as ("[%s] %s → errorCode" , fileName , description )
80+ .isEqualTo (mapErrorCode (testCase .expected .errorCode ));
7981 }
8082
8183 static Stream <Arguments > fixtureTestCases () throws IOException {
82- ObjectMapper mapper = new ObjectMapper (
83- JsonFactory .builder ().enable (StreamReadFeature .INCLUDE_SOURCE_IN_LOCATION ).build ()
84- );
84+ ObjectMapper mapper = JsonMapper .builder ()
85+ .enable (StreamReadFeature .INCLUDE_SOURCE_IN_LOCATION )
86+ .disable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
87+ .build ();
88+
8589 List <Path > jsonFiles ;
8690 try (Stream <Path > files = Files .list (Path .of ("specification" , "Fixtures" ))) {
8791 jsonFiles = files
88- .filter (p -> p .getFileName ().toString ().endsWith (".json" ))
89- .collect (Collectors .toList ());
92+ .filter (p -> p .getFileName ().toString ().endsWith (".json" ))
93+ .collect (Collectors .toList ());
9094 }
9195 if (jsonFiles .isEmpty ()) {
9296 throw new IllegalStateException (
93- "No fixture files found under 'specification/Fixtures/'. " +
94- "Ensure the git submodule is initialised: git submodule update --init" );
97+ "No fixture files found under 'specification/Fixtures/'. " +
98+ "Ensure the git submodule is initialised: git submodule update --init" );
9599 }
96100 return jsonFiles .stream ().flatMap (path -> {
97101 try {
98102 String fileContent = Files .readString (path );
99103 Fixture fixture = mapper .readValue (fileContent , Fixture .class );
100104 String fileName = path .getFileName ().toString ();
101105 return Stream .of (fixture .cases )
102- .map (c -> Arguments .of (fileName , c .description , fixture .response , c ));
106+ .map (c -> Arguments .of (fileName , c .description , fixture .response , c ));
103107 } catch (IOException e ) {
104108 throw new UncheckedIOException (e );
105109 }
@@ -117,50 +121,53 @@ private static EvaluationContext buildContext(Map<String, String> context) {
117121 private static ErrorCode mapErrorCode (String code ) {
118122 if (code == null ) return null ;
119123 switch (code ) {
120- case "FLAG_NOT_FOUND" : return ErrorCode .FLAG_NOT_FOUND ;
121- case "PARSE_ERROR" : return ErrorCode .PARSE_ERROR ;
122- case "TYPE_MISMATCH" : return ErrorCode .TYPE_MISMATCH ;
123- case "TARGETING_KEY_MISSING" : return ErrorCode .TARGETING_KEY_MISSING ;
124- case "PROVIDER_NOT_READY" : return ErrorCode .PROVIDER_NOT_READY ;
125- case "INVALID_CONTEXT" : return ErrorCode .INVALID_CONTEXT ;
126- case "PROVIDER_FATAL" : return ErrorCode .PROVIDER_FATAL ;
127- case "GENERAL" : return ErrorCode .GENERAL ;
128- default : throw new IllegalArgumentException ("Unknown error code in fixture: " + code );
124+ case "FLAG_NOT_FOUND" :
125+ return ErrorCode .FLAG_NOT_FOUND ;
126+ case "PARSE_ERROR" :
127+ return ErrorCode .PARSE_ERROR ;
128+ case "TYPE_MISMATCH" :
129+ return ErrorCode .TYPE_MISMATCH ;
130+ case "TARGETING_KEY_MISSING" :
131+ return ErrorCode .TARGETING_KEY_MISSING ;
132+ case "PROVIDER_NOT_READY" :
133+ return ErrorCode .PROVIDER_NOT_READY ;
134+ case "INVALID_CONTEXT" :
135+ return ErrorCode .INVALID_CONTEXT ;
136+ case "PROVIDER_FATAL" :
137+ return ErrorCode .PROVIDER_FATAL ;
138+ case "GENERAL" :
139+ return ErrorCode .GENERAL ;
140+ default :
141+ throw new IllegalArgumentException ("Unknown error code in fixture: " + code );
129142 }
130143 }
131144
132- // ---- Fixture model classes ----
133-
134- @ JsonIgnoreProperties (ignoreUnknown = true )
135145 static class Fixture {
136146 @ JsonDeserialize (using = RawJsonDeserializer .class )
137147 public String response ;
138148 public FixtureCase [] cases ;
139149 }
140150
141- @ JsonIgnoreProperties (ignoreUnknown = true )
142151 static class FixtureCase {
143152 public String description ;
144153 public FixtureConfiguration configuration ;
145154 public FixtureExpected expected ;
146155 }
147156
148- @ JsonIgnoreProperties (ignoreUnknown = true )
149157 static class FixtureConfiguration {
150158 public String slug ;
151159 public boolean defaultValue ;
152160 public Map <String , String > context ;
153161 }
154162
155- @ JsonIgnoreProperties (ignoreUnknown = true )
156163 static class FixtureExpected {
157164 public boolean value ;
158165 public String errorCode ;
159166 }
160167
161168 static class RawJsonDeserializer extends JsonDeserializer <String > {
162169 @ Override
163- public String deserialize (JsonParser jp , DeserializationContext ctxt ) throws IOException {
170+ public String deserialize (JsonParser jp , DeserializationContext dc ) throws IOException {
164171 long begin = jp .currentLocation ().getCharOffset ();
165172 jp .skipChildren ();
166173 long end = jp .currentLocation ().getCharOffset ();
0 commit comments