Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.foo.rest.examples.bb.jsonmergepatch

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
import org.evomaster.e2etests.utils.CoveredTargets
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import java.util.Optional

@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])
@RestController
@RequestMapping("/api/jsonmergepatch")
open class BBJsonMergePatchApplication {

companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(BBJsonMergePatchApplication::class.java, *args)
}
}



@PatchMapping("/", consumes = ["application/merge-patch+json"])
fun patchPet(@RequestBody dto: BBJsonMergePatchDto): ResponseEntity<String> {

if(dto.name == null && dto.x == null){
CoveredTargets.cover("BOTH_UNDEFINED")
return ResponseEntity.status(400).build()
}
if(dto.name == null || dto.x == null){
CoveredTargets.cover("ONE_UNDEFINED")
return ResponseEntity.status(401).build()
}
//we use different status codes just to make sure tests end up in final test suite
if(dto.name.isEmpty && dto.x.isEmpty){
CoveredTargets.cover("BOTH_NULL")
return ResponseEntity.status(403).build()
}
if(!dto.name.isEmpty && !dto.x.isEmpty){
CoveredTargets.cover("BOTH_PRESENT")
return ResponseEntity.status(200).build()
}
if(dto.name.isEmpty || dto.x.isEmpty){
CoveredTargets.cover("ONE_PRESENT")
return ResponseEntity.status(404).build()
}

//should never be reached
return ResponseEntity.ok("patched")
}
}

data class BBJsonMergePatchDto(
@field:Schema(nullable = true)
val name: Optional<String>? = null,

@field:Schema(nullable = true)
val x: Optional<Int>? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.foo.rest.examples.bb.jsonmergepatch

import com.foo.rest.examples.bb.SpringController
import com.foo.rest.examples.bb.jsonpatch.BBJsonPatchApplication

class BBJsonMergePatchController : SpringController(BBJsonMergePatchApplication::class.java)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.evomaster.e2etests.spring.rest.bb.jsonmergepatch

import com.foo.rest.examples.bb.jsonmergepatch.BBJsonMergePatchController
import org.evomaster.core.output.OutputFormat
import org.evomaster.core.problem.rest.data.HttpVerb
import org.evomaster.e2etests.spring.rest.bb.SpringTestBase
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource

class BBJsonMergePatchEMTest : SpringTestBase() {

companion object {
init {
shouldApplyInstrumentation = false
}

@BeforeAll
@JvmStatic
fun init() {
initClass(BBJsonMergePatchController())
}
}



@ParameterizedTest
@EnumSource
fun testBlackBoxOutput(outputFormat: OutputFormat) {

executeAndEvaluateBBTest(
outputFormat,
"jsonmergepatch",
100,
3,
listOf("BOTH_UNDEFINED", "ONE_UNDEFINED", "BOTH_NULL","BOTH_PRESENT","ONE_PRESENT")
){ args: MutableList<String> ->


val solution = initAndRun(args)

assertTrue(solution.individuals.size >= 1)
assertHasAtLeastOne(solution, HttpVerb.PATCH, 400, "/api/jsonmergepatch/", null)
assertHasAtLeastOne(solution, HttpVerb.PATCH, 401, "/api/jsonmergepatch/", null)
assertHasAtLeastOne(solution, HttpVerb.PATCH, 403, "/api/jsonmergepatch/", null)
assertHasAtLeastOne(solution, HttpVerb.PATCH, 404, "/api/jsonmergepatch/", null)
assertHasAtLeastOne(solution, HttpVerb.PATCH, 200, "/api/jsonmergepatch/", null)
}
}
}
Loading