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,58 @@
{
"openapi": "3.1.0",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"paths": {
"/api/bbdtonull/items": {
"post": {
"tags": [
"dto-null-application"
],
"operationId": "post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DtoNullDto"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"DtoNullDto": {
"type": "object",
"properties": {
"x": {
"type": ["integer", "null"],
"format": "int32"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package com.foo.rest.examples.bb.dtonull

import com.foo.rest.examples.bb.SpringController
import org.evomaster.client.java.controller.problem.ProblemInfo
import org.evomaster.client.java.controller.problem.RestProblem

class BBDtoNullController : SpringController(DtoNullApplication::class.java)
class BBDtoNullController : SpringController(DtoNullApplication::class.java){

override fun getProblemInfo(): ProblemInfo {
return RestProblem(
//the one generated by old Spring is wrong
"http://localhost:$sutPort/openapi-dtonull.json", null
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ class BBDtoNullEMTest : SpringTestBase() {
executeAndEvaluateBBTest(
outputFormat,
"dtonull",
100,
1000,
3,
listOf("UNDEFINED",
//FIXME currently we do not handle NULL :(
// "NULL",
"POSITIVE","NEGATIVE")
listOf("UNDEFINED", "NULL", "POSITIVE","NEGATIVE")
){ args: MutableList<String> ->

setOption(args, "dtoForRequestPayload", "true")
setOption(args, "bbSwaggerUrl", "$baseUrlOfSut/openapi-dtonull.json")

//TODO need to fix/extend DTO handling before activating it here
// setOption(args, "dtoForRequestPayload", "true")
setOption(args, "dtoForRequestPayload", "false")

val solution = initAndRun(args)

assertTrue(solution.individuals.size >= 1)
assertHasAtLeastOne(solution, HttpVerb.POST, 400, "/api/bbdtonull/items", "UNDEFINED")
//FIXME currently we do not handle NULL :(
//assertHasAtLeastOne(solution, HttpVerb.POST, 409, "/api/bbdtonull/items", "NULL")
assertHasAtLeastOne(solution, HttpVerb.POST, 409, "/api/bbdtonull/items", "NULL")
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/api/bbdtonull/items", "POSITIVE")
assertHasAtLeastOne(solution, HttpVerb.POST, 201, "/api/bbdtonull/items", "NEGATIVE")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.evomaster.core.output.formatter

import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.GsonBuilder
import com.google.gson.JsonParser
Expand Down Expand Up @@ -34,8 +35,14 @@ open abstract class OutputFormatter (val name: String) {
}

val JSON_FORMATTER = object : OutputFormatter("JSON_FORMATTER"){
val gson = GsonBuilder().setPrettyPrinting().create()
/*
GSON does not follow standard for JSON.
Should not be used for validation.
https://stackoverflow.com/questions/43233898/how-to-check-if-json-is-valid-in-java-using-gson
*/
val objectMapper = ObjectMapper()
//also Jackson by default is happy to accept garbage :(
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)

override fun isValid(content: String): Boolean{

Expand All @@ -45,22 +52,15 @@ open abstract class OutputFormatter (val name: String) {
} catch (e: JsonProcessingException) {
false
}
/*
GSON does not follow standard for JSON.
Should not be used for validation.
https://stackoverflow.com/questions/43233898/how-to-check-if-json-is-valid-in-java-using-gson
*/
// return try{
// gson.fromJson(content, Object::class.java)
// true
// }catch (e : JsonSyntaxException ) {
// false
// }

}
override fun getFormatted(content: String): String{
if(this.isValid(content)){
return gson.toJson(JsonParser.parseString(content))
return objectMapper.readTree(content)
.toPrettyString()
//on Windows, Jackson "might" use CRLF,
//which can be problematic
.replace("\r\n", "\n")
}
throw MismatchedFormatException(this, content)
}
Expand Down
Loading
Loading