diff --git a/core-tests/e2e-tests/spring/spring-rest-bb/src/main/kotlin/com/foo/rest/examples/bb/jsonmergepatch/BBJsonMergePatchApplication.kt b/core-tests/e2e-tests/spring/spring-rest-bb/src/main/kotlin/com/foo/rest/examples/bb/jsonmergepatch/BBJsonMergePatchApplication.kt new file mode 100644 index 0000000000..4a84db3add --- /dev/null +++ b/core-tests/e2e-tests/spring/spring-rest-bb/src/main/kotlin/com/foo/rest/examples/bb/jsonmergepatch/BBJsonMergePatchApplication.kt @@ -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) { + SpringApplication.run(BBJsonMergePatchApplication::class.java, *args) + } + } + + + + @PatchMapping("/", consumes = ["application/merge-patch+json"]) + fun patchPet(@RequestBody dto: BBJsonMergePatchDto): ResponseEntity { + + 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? = null, + + @field:Schema(nullable = true) + val x: Optional? = null +) \ No newline at end of file diff --git a/core-tests/e2e-tests/spring/spring-rest-bb/src/test/kotlin/com/foo/rest/examples/bb/jsonmergepatch/BBJsonMergePatchController.kt b/core-tests/e2e-tests/spring/spring-rest-bb/src/test/kotlin/com/foo/rest/examples/bb/jsonmergepatch/BBJsonMergePatchController.kt new file mode 100644 index 0000000000..09d607bff2 --- /dev/null +++ b/core-tests/e2e-tests/spring/spring-rest-bb/src/test/kotlin/com/foo/rest/examples/bb/jsonmergepatch/BBJsonMergePatchController.kt @@ -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) diff --git a/core-tests/e2e-tests/spring/spring-rest-bb/src/test/kotlin/org/evomaster/e2etests/spring/rest/bb/jsonmergepatch/BBJsonMergePatchEMTest.kt b/core-tests/e2e-tests/spring/spring-rest-bb/src/test/kotlin/org/evomaster/e2etests/spring/rest/bb/jsonmergepatch/BBJsonMergePatchEMTest.kt new file mode 100644 index 0000000000..0b9460c827 --- /dev/null +++ b/core-tests/e2e-tests/spring/spring-rest-bb/src/test/kotlin/org/evomaster/e2etests/spring/rest/bb/jsonmergepatch/BBJsonMergePatchEMTest.kt @@ -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 -> + + + 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) + } + } +}