-
Notifications
You must be signed in to change notification settings - Fork 94
Phg/dto kickoff #1249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phg/dto kickoff #1249
Conversation
a comment regarding
an empty string in JSON is a valid string. i guess you should make sure to handle the case of |
core/src/main/kotlin/org/evomaster/core/output/dto/JavaDtoWriter.kt
Outdated
Show resolved
Hide resolved
dtoFilename = TestSuiteFileName(appendDtoPackage(dtoClass.name)) | ||
} | ||
|
||
fun write() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to create a class with constructor, instead of having an object (eg object JavaDtoWriter
) with a parametric fun write(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, two reasons:
- Hadn't thought about it, I just got writing and my first impulse was to add that information in the constructor.
- This writer will most likely change. I was thinking this would change into some kind of delegate/decorator. You should actually ask the
DtoClass
to write itself, which in turn would call the right type of DtoWriter
core/src/main/kotlin/org/evomaster/core/output/service/TestSuiteWriter.kt
Outdated
Show resolved
Hide resolved
private fun getDtos(): List<DtoClass> { | ||
val restSampler = sampler as AbstractRestSampler | ||
val result = mutableListOf<DtoClass>() | ||
restSampler.getActionDefinitions().forEach { action -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could move the code here under some utility function in the dto
package, and then call it with restSampler.getActionDefinitions()
as input
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the future I was actually thinking of creating a new dedicated class for this, but for starters I added here in the TestSuiteWriter
. The class-to-be would actually have to run before tests are split, so as to avoid re-writing or even overwriting DTOs. Then the generated DTOs should be shared with the TestCaseWriter
, not sure how yet
val primaryGene = child.primaryGene() | ||
// TODO: Payloads could also be json arrays, analyze ArrayGene | ||
if (primaryGene is ObjectGene) { | ||
// TODO: Determine strategy for objects that are not defined as a component and do not have a name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use something related to action.getName
, and put this as a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be, yes. We'll most likely come back to this later on
core/src/main/kotlin/org/evomaster/core/output/service/TestSuiteWriter.kt
Outdated
Show resolved
Hide resolved
private fun getDtoField(field: Gene): DtoField { | ||
val wrappedGene = GeneUtils.getWrappedValueGene(field) | ||
return DtoField(field.name, when (wrappedGene) { | ||
// TODO: handle nested arrays, objects and extend type system for dto fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will need to handle the cases of OptionalGene
and NullableGene
(see how wrapping works), as that will impact what kinds of field types you will need to create. also RegexGene is going to be common. anyway, you will see what things crashing when we activate this feature in the E2E... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a matter of fact, we need more E2E tests! Most e2e tests check on tests generated using GET:
- GET: 103+ matches in 36+ files
- POST: 67 matches in 36 files
- PUT: 6 matches in 5 files
And I looking into the POST tests, some do not have a DTO request payload but instead a response one, or are using simple cases. Looked into that for debugging
is FloatGene -> "Float" | ||
is Base64StringGene -> "String" | ||
is DateGene -> "String" | ||
is TimeGene -> "String" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might want to use special types for this, and, in the DTOs, throw an IllegalArgumentExcpetion
if invalid string. however, for now can leave it as acomment (as we still create invalid strings outside robustness testing, and that is not fixed yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's something the Gene could answer by itself, something like: gene.getDtoType()
and have that answer back. That would also save us from these giant ifs
One other question I have is, for these specific cases of Time and Date, should we in the future handle them with jodatime objects or similar? Or just set them as strings and keep it simple? For a start I think strings are fine, not sure what you had in mind for the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now we can keep it simple. then we can see feedback from test engineers at VW
is FloatGene -> "Float" | ||
is Base64StringGene -> "String" | ||
is DateGene -> "String" | ||
is TimeGene -> "String" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now we can keep it simple. then we can see feedback from test engineers at VW
What's in the box?
Kickoff for using DTOs instead of stringified json for REST request payloads.
Current limitations:
The current implementation is able to handle wanted field scenarios using optionals and jackson:
{"myKey": "myValue"}
/{"myKey": ""}
{"myKey": null}
{}
For example, a spec with the following components:
Will generate a class such as: