Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput.json

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])
@RequestMapping(path = ["/api/resources"])
@RestController
open class PartialUpdatePutApplication {

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

private val data = mutableMapOf<Int, ResourceData>()

fun reset(){
data.clear()
}
}

data class ResourceData(
var name: String,
var value: Int
)

data class UpdateRequest(
val name: String,
val value: Int
)


@PostMapping()
open fun create(@RequestBody body: ResourceData): ResponseEntity<ResourceData> {
val id = data.size + 1
data[id] = body.copy()
return ResponseEntity.status(201).body(data[id])
}

@GetMapping(path = ["/{id}"])
open fun get(@PathVariable("id") id: Int): ResponseEntity<ResourceData> {
val resource = data[id]
?: return ResponseEntity.status(404).build()
return ResponseEntity.status(200).body(resource)
}

@PutMapping(path = ["/{id}"])
open fun put(
@PathVariable("id") id: Int,
@RequestBody body: UpdateRequest
): ResponseEntity<Any> {

val resource = data[id]
?: return ResponseEntity.status(404).build()

if(body.name != null) {
resource.name = body.name
}

return ResponseEntity.status(200).body(resource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput.urlencoded

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])
@RequestMapping(path = ["/api/resources"])
@RestController
open class PartialUpdatePutUrlEncodedApplication {

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

private val data = mutableMapOf<Int, ResourceData>()

fun reset(){
data.clear()
}
}

open class ResourceData(
var name: String = "",
var value: Int = 0
)

open class UpdateRequest(
var name: String = "",
var value: Int = 0
)


@PostMapping(
consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE],
produces = [MediaType.APPLICATION_JSON_VALUE]
)
open fun create(@ModelAttribute body: ResourceData): ResponseEntity<ResourceData> {
val id = data.size + 1
data[id] = ResourceData(name = body.name, value = body.value)
return ResponseEntity.status(201).body(data[id])
}

@GetMapping(
path = ["/{id}"],
produces = [MediaType.APPLICATION_JSON_VALUE]
)
open fun get(@PathVariable("id") id: Int): ResponseEntity<ResourceData> {
val resource = data[id]
?: return ResponseEntity.status(404).build()
return ResponseEntity.status(200).body(resource)
}

@PutMapping(
path = ["/{id}"],
consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE],
produces = [MediaType.APPLICATION_JSON_VALUE]
)
open fun put(
@PathVariable("id") id: Int,
@ModelAttribute body: UpdateRequest
): ResponseEntity<Any> {

val resource = data[id]
?: return ResponseEntity.status(404).build()

if(body.name != null) {
resource.name = body.name
}

return ResponseEntity.status(200).body(resource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput.xml

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlRootElement

@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])
@RequestMapping(path = ["/api/resources"])
@RestController
open class PartialUpdatePutXMLApplication {

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

private val data = mutableMapOf<Int, ResourceData>()

fun reset(){
data.clear()
}
}

@XmlRootElement(name = "resourceData")
@XmlAccessorType(XmlAccessType.FIELD)
open class ResourceData(
var name: String = "",
var value: Int = 0
)

@XmlRootElement(name = "updateRequest")
@XmlAccessorType(XmlAccessType.FIELD)
open class UpdateRequest(
var name: String = "",
var value: Int = 0
)


@PostMapping(
consumes = [MediaType.APPLICATION_XML_VALUE],
produces = [MediaType.APPLICATION_XML_VALUE]
)
open fun create(@RequestBody body: ResourceData): ResponseEntity<ResourceData> {
val id = data.size + 1
data[id] = ResourceData(name = body.name, value = body.value)
return ResponseEntity.status(201).body(data[id])
}

@GetMapping(
path = ["/{id}"],
produces = [MediaType.APPLICATION_XML_VALUE]
)
open fun get(@PathVariable("id") id: Int): ResponseEntity<ResourceData> {
val resource = data[id]
?: return ResponseEntity.status(404).build()
return ResponseEntity.status(200).body(resource)
}

@PutMapping(
path = ["/{id}"],
consumes = [MediaType.APPLICATION_XML_VALUE],
produces = [MediaType.APPLICATION_XML_VALUE]
)
open fun put(
@PathVariable("id") id: Int,
@RequestBody body: UpdateRequest
): ResponseEntity<Any> {

val resource = data[id]
?: return ResponseEntity.status(404).build()

if(body.name != null) {
resource.name = body.name
}

return ResponseEntity.status(200).body(resource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput

import com.foo.rest.examples.spring.openapi.v3.SpringController
import com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput.json.PartialUpdatePutApplication


class HttpPartialUpdatePutController: SpringController(PartialUpdatePutApplication::class.java){

override fun resetStateOfSUT() {
PartialUpdatePutApplication.reset()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput

import com.foo.rest.examples.spring.openapi.v3.SpringController
import com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput.urlencoded.PartialUpdatePutUrlEncodedApplication


class HttpPartialUpdatePutURLEncodedController: SpringController(PartialUpdatePutUrlEncodedApplication::class.java){

override fun resetStateOfSUT() {
PartialUpdatePutUrlEncodedApplication.reset()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput

import com.foo.rest.examples.spring.openapi.v3.SpringController
import com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput.xml.PartialUpdatePutXMLApplication


class HttpPartialUpdatePutXMLController: SpringController(PartialUpdatePutXMLApplication::class.java){

override fun resetStateOfSUT() {
PartialUpdatePutXMLApplication.reset()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.evomaster.e2etests.spring.openapi.v3.httporacle.delete

import com.foo.rest.examples.spring.openapi.v3.httporacle.delete.HttpOracleDeleteController
import com.webfuzzing.commons.faults.DefinedFaultCategory
import com.webfuzzing.commons.faults.FaultCategory
import org.evomaster.core.problem.enterprise.DetectedFaultUtils
import org.evomaster.core.problem.enterprise.ExperimentalFaultCategory
Expand Down Expand Up @@ -47,8 +48,8 @@ class HttpOracleDeleteEMTest : SpringTestBase(){


val faults = DetectedFaultUtils.getDetectedFaultCategories(solution)
assertEquals(1, faults.size)
assertEquals(ExperimentalFaultCategory.HTTP_NONWORKING_DELETE, faults.first())
assertTrue({ ExperimentalFaultCategory.HTTP_NONWORKING_DELETE in faults })

}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.evomaster.e2etests.spring.openapi.v3.httporacle.partialupdateput

import com.foo.rest.examples.spring.openapi.v3.httporacle.partialupdateput.HttpPartialUpdatePutController
import org.evomaster.core.problem.enterprise.DetectedFaultUtils
import org.evomaster.core.problem.enterprise.ExperimentalFaultCategory
import org.evomaster.core.problem.rest.data.HttpVerb
import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test

class HttpPartialUpdatePutEMTest : SpringTestBase(){

companion object {
@BeforeAll
@JvmStatic
fun init() {
initClass(HttpPartialUpdatePutController())
}
}


@Test
fun testRunEM() {

runTestHandlingFlakyAndCompilation(
Comment thread
arcuri82 marked this conversation as resolved.
"HttpPartialUpdatePutEM",
1000
) { args: MutableList<String> ->

setOption(args, "security", "false")
setOption(args, "schemaOracles", "false")
setOption(args, "httpOracles", "true")
setOption(args, "useExperimentalOracles", "true")

val solution = initAndRun(args)

assertTrue(solution.individuals.size >= 1)

assertHasAtLeastOne(solution, HttpVerb.PUT, 200, "/api/resources/{id}", null)

val faults = DetectedFaultUtils.getDetectedFaultCategories(solution)
assertEquals(1, faults.size)
assertEquals(ExperimentalFaultCategory.HTTP_PARTIAL_UPDATE_PUT, faults.first())
}
}
}
Loading
Loading