@@ -43,10 +43,16 @@ class JsonPatchDocumentGeneTest {
4343 }
4444
4545 @Test
46- fun testCopyPreservesNonNullResourceSchema () {
47- val original = JsonPatchDocumentGene (" patch" , StringGene (" schema" ))
48- val copy = original.copy() as JsonPatchDocumentGene
49- assertNotNull(copy.resourceSchema)
46+ fun testSchemaFieldsAreUsedAsPaths () {
47+ val schema = ObjectGene (" body" , listOf (StringGene (" name" ), IntegerGene (" age" )))
48+ val d = JsonPatchDocumentGene (" patch" , schema)
49+
50+ val array = d.getViewOfChildren()[0 ] as org.evomaster.core.search.gene.collection.ArrayGene <* >
51+ val removeOp = array.template.getViewOfChildren()[0 ] as JsonPatchPathOnlyGene
52+ val paths = removeOp.pathGene.values.map { it.toString() }
53+
54+ assertTrue(paths.contains(" /name" ), " Expected /name from schema, got: $paths " )
55+ assertTrue(paths.contains(" /age" ), " Expected /age from schema, got: $paths " )
5056 }
5157
5258 // --- operations property ---
@@ -155,13 +161,31 @@ class JsonPatchDocumentGeneTest {
155161
156162 // --- XML serialization ---
157163
164+ @Test
165+ fun testRemoveOperationJsonFormat () {
166+ val op = JsonPatchPathOnlyGene (JsonPatchOperationGene .OP_REMOVE , JsonPatchOperationGene .OP_REMOVE , EnumGene (" path" , listOf (" /x" )))
167+ val result = op.getValueAsPrintableString()
168+ assertEquals(" {\" op\" :\" remove\" ,\" path\" :\" /x\" }" , result)
169+ }
170+
158171 @Test
159172 fun testRemoveOperationXmlFormat () {
160173 val op = JsonPatchPathOnlyGene (JsonPatchOperationGene .OP_REMOVE , JsonPatchOperationGene .OP_REMOVE , EnumGene (" path" , listOf (" /x" )))
161174 val result = op.getValueAsPrintableString(mode = GeneUtils .EscapeMode .XML )
162175 assertEquals(" <operation><op>remove</op><path>/x</path></operation>" , result)
163176 }
164177
178+ @Test
179+ fun testMoveOperationJsonFormat () {
180+ val op = JsonPatchFromPathGene (
181+ JsonPatchOperationGene .OP_MOVE , JsonPatchOperationGene .OP_MOVE ,
182+ fromGene = EnumGene (" from" , listOf (" /a" )),
183+ pathGene = EnumGene (" path" , listOf (" /b" ))
184+ )
185+ val result = op.getValueAsPrintableString()
186+ assertEquals(" {\" op\" :\" move\" ,\" from\" :\" /a\" ,\" path\" :\" /b\" }" , result)
187+ }
188+
165189 @Test
166190 fun testMoveOperationXmlFormat () {
167191 val op = JsonPatchFromPathGene (
@@ -220,25 +244,7 @@ class JsonPatchDocumentGeneTest {
220244 }
221245
222246 @Test
223- fun testContainsSameValueAsTrueWhenBothSchemasAreNull () {
224- val d1 = doc()
225- val d2 = d1.copy() as JsonPatchDocumentGene
226- assertNull(d1.resourceSchema)
227- assertNull(d2.resourceSchema)
228- assertTrue(d1.containsSameValueAs(d2))
229- }
230-
231- @Test
232- fun testContainsSameValueAsFalseWhenOneSchemaIsNull () {
233- val withSchema = JsonPatchDocumentGene (" patch" , ObjectGene (" body" , listOf (StringGene (" name" ))))
234- withSchema.doInitialize(Randomness ().apply { updateSeed(42 ) })
235- val withoutSchema = doc()
236- assertFalse(withSchema.containsSameValueAs(withoutSchema))
237- assertFalse(withoutSchema.containsSameValueAs(withSchema))
238- }
239-
240- @Test
241- fun testContainsSameValueAsTrueForCopiesWithSchema () {
247+ fun testContainsSameValueAsTrueForCopiesBuiltWithSchema () {
242248 val schema = ObjectGene (" body" , listOf (StringGene (" name" ), IntegerGene (" age" )))
243249 val d1 = JsonPatchDocumentGene (" patch" , schema)
244250 d1.doInitialize(Randomness ().apply { updateSeed(1 ) })
@@ -247,13 +253,14 @@ class JsonPatchDocumentGeneTest {
247253 }
248254
249255 @Test
250- fun testContainsSameValueAsFalseForDifferentSchemaTypes () {
251- val schemaA = ObjectGene (" body" , listOf (StringGene (" name" )))
252- val schemaB = ObjectGene (" body" , listOf (IntegerGene (" count" )))
253- val d1 = JsonPatchDocumentGene (" patch" , schemaA)
254- d1.doInitialize(Randomness ().apply { updateSeed(1 ) })
255- val d2 = JsonPatchDocumentGene (" patch" , schemaB)
256- d2.doInitialize(Randomness ().apply { updateSeed(1 ) })
256+ fun testContainsSameValueAsFalseAfterRandomize () {
257+ val d1 = doc(seed = 1L )
258+ val d2 = doc(seed = 2L )
259+ val rand2 = Randomness ().apply { updateSeed(99 ) }
260+ var attempts = 0
261+ while (d1.containsSameValueAs(d2) && attempts++ < 20 ) {
262+ d2.randomize(rand2, tryToForceNewValue = true )
263+ }
257264 assertFalse(d1.containsSameValueAs(d2))
258265 }
259266
0 commit comments