24
24
import java .io .IOException ;
25
25
import java .util .EnumSet ;
26
26
27
- import static com .flipkart .zjsonpatch .CompatibilityFlags .MISSING_VALUES_AS_NULLS ;
28
- import static com .flipkart .zjsonpatch .CompatibilityFlags .REMOVE_NONE_EXISTING_ARRAY_ELEMENT ;
27
+ import static com .flipkart .zjsonpatch .CompatibilityFlags .*;
29
28
import static org .hamcrest .core .IsEqual .equalTo ;
30
29
import static org .junit .Assert .assertThat ;
31
30
@@ -35,13 +34,15 @@ public class CompatibilityTest {
35
34
JsonNode addNodeWithMissingValue ;
36
35
JsonNode replaceNodeWithMissingValue ;
37
36
JsonNode removeNoneExistingArrayElement ;
37
+ JsonNode replaceNode ;
38
38
39
39
@ Before
40
40
public void setUp () throws Exception {
41
41
mapper = new ObjectMapper ();
42
42
addNodeWithMissingValue = mapper .readTree ("[{\" op\" :\" add\" ,\" path\" :\" /a\" }]" );
43
43
replaceNodeWithMissingValue = mapper .readTree ("[{\" op\" :\" replace\" ,\" path\" :\" /a\" }]" );
44
44
removeNoneExistingArrayElement = mapper .readTree ("[{\" op\" : \" remove\" ,\" path\" : \" /b/0\" }]" );
45
+ replaceNode = mapper .readTree ("[{\" op\" :\" replace\" ,\" path\" :\" /a\" ,\" value\" :true}]" );
45
46
}
46
47
47
48
@ Test
@@ -76,4 +77,11 @@ public void withFlagIgnoreRemoveNoneExistingArrayElement() throws IOException {
76
77
JsonNode result = JsonPatch .apply (removeNoneExistingArrayElement , source , EnumSet .of (REMOVE_NONE_EXISTING_ARRAY_ELEMENT ));
77
78
assertThat (result , equalTo (expected ));
78
79
}
80
+
81
+ @ Test
82
+ public void withFlagReplaceShouldAddValueWhenMissingInTarget () throws Exception {
83
+ JsonNode expected = mapper .readTree ("{\" a\" : true}" );
84
+ JsonNode result = JsonPatch .apply (replaceNode , mapper .createObjectNode (), EnumSet .of (ALLOW_MISSING_TARGET_OBJECT_ON_REPLACE ));
85
+ assertThat (result , equalTo (expected ));
86
+ }
79
87
}
0 commit comments