Skip to content

Commit

Permalink
starting to look into #1150
Browse files Browse the repository at this point in the history
  • Loading branch information
arcuri82 committed Dec 30, 2024
1 parent ca8203c commit 410409a
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TimeGene(
.thenBy(TimeGene::minute)
.thenBy(TimeGene::second)
//TODO ms and offset
//FIXME: considering offset, this check is wrong.
}

fun selectZ(){
Expand Down
5 changes: 5 additions & 0 deletions e2e-tests/spring-rest-openapi-v3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
<artifactId>auth0</artifactId>
</dependency>

<dependency>
<groupId>com.ethlo.time</groupId>
<artifactId>itu</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.foo.rest.examples.spring.openapi.v3.time

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration

@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])
open class TimeApplication {

companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(TimeApplication::class.java, *args)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.foo.rest.examples.spring.openapi.v3.time

import com.ethlo.time.ITU
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping(path = ["/api/time"])
class TimeRest {


@GetMapping
open fun get(@RequestParam x: String) : ResponseEntity<String> {

try{
ITU.parseDateTime(x)
}catch (e:Exception){
return ResponseEntity.badRequest().body(e.message)
}

if(x.contains("Z") ){
return ResponseEntity.ok("A")
}
if(x.contains("-") ){
return ResponseEntity.ok("B")
}
if(x.contains("+") ){
return ResponseEntity.ok("C")
}

return ResponseEntity.ok("D")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.0
info:
title: time
version: "1"
paths:
/api/time:
get:
parameters:
- in: query
name: x
required: true
schema:
type: string
format: 'date-time'
responses:
200:
description: ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.foo.rest.examples.spring.openapi.v3.time

import com.foo.rest.examples.spring.openapi.v3.SpringController
import org.evomaster.client.java.controller.problem.ProblemInfo
import org.evomaster.client.java.controller.problem.RestProblem

class TimeController : SpringController(TimeApplication::class.java){


override fun getProblemInfo(): ProblemInfo {
return RestProblem(
"http://localhost:$sutPort/openapi-time.yml",
null
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.evomaster.e2etests.spring.openapi.v3.time


import com.foo.rest.examples.spring.openapi.v3.time.TimeController
import org.evomaster.core.problem.rest.HttpVerb
import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test

class TimeEMTest : SpringTestBase(){

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

@Test
fun testRunEM() {

runTestHandlingFlakyAndCompilation(
"TimeEM",
100
) { args: MutableList<String> ->

val solution = initAndRun(args)

Assertions.assertTrue(solution.individuals.size >= 1)
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/time", "A")
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/time", "B")
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/time", "C")

Check failure on line 34 in e2e-tests/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/time/TimeEMTest.kt

View workflow job for this annotation

GitHub Actions / JUnit Test Report

TimeEMTest.testRunEM

Seed 44. Missing 200 GET /api/time C REST calls: 200 GET /api/time?x=1996-11-19T12%3A10%3A38.471%2B06%3A54 , auth=NoAuth 200 GET /api/time?x=2044-09-24T21%3A53%3A57Z&EMextraParam123=_EM_25_XYZ_ , auth=NoAuth 200 GET /api/time?x=2056-01-21T01%3A34%3A12.425-11%3A45&EMextraParam123=_EM_31_XYZ_ , auth=NoAuth 200 GET /openapi-time.yml , auth=NoAuth 400 GET /api/time?x=1900-08-26T-1%3A05%3A60.503-11%3A51 , auth=NoAuth 400 GET /api/time?x=2054-08-27T11%3A60%3A-1Z , auth=NoAuth ==> expected: <true> but was: <false>
Raw output
org.opentest4j.AssertionFailedError: 
Seed 44. Missing 200 GET /api/time C
REST calls:
200 GET /api/time?x=1996-11-19T12%3A10%3A38.471%2B06%3A54 , auth=NoAuth
200 GET /api/time?x=2044-09-24T21%3A53%3A57Z&EMextraParam123=_EM_25_XYZ_ , auth=NoAuth
200 GET /api/time?x=2056-01-21T01%3A34%3A12.425-11%3A45&EMextraParam123=_EM_31_XYZ_ , auth=NoAuth
200 GET /openapi-time.yml , auth=NoAuth
400 GET /api/time?x=1900-08-26T-1%3A05%3A60.503-11%3A51 , auth=NoAuth
400 GET /api/time?x=2054-08-27T11%3A60%3A-1Z , auth=NoAuth
 ==> expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:40)
	at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:193)
	at org.evomaster.e2etests.utils.RestTestBase.assertHasAtLeastOne(RestTestBase.java:313)
	at org.evomaster.e2etests.spring.openapi.v3.time.TimeEMTest.testRunEM$lambda$0(TimeEMTest.kt:34)
	at org.evomaster.e2etests.utils.EnterpriseTestBase.lambda$null$4(EnterpriseTestBase.java:233)
	at org.evomaster.e2etests.utils.EnterpriseTestBase.handleFlaky(EnterpriseTestBase.java:454)
	at org.evomaster.e2etests.utils.EnterpriseTestBase.lambda$runTestHandlingFlaky$5(EnterpriseTestBase.java:229)
	at org.junit.jupiter.api.AssertTimeout.lambda$assertTimeoutPreemptively$2(AssertTimeout.java:102)
	at org.junit.jupiter.api.AssertTimeout.lambda$assertTimeoutPreemptively$4(AssertTimeout.java:138)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/time", "D")
}
}
}
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,14 @@
<version>${mockserver.client.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<!-- To deal with RFC3339 dateTime -->
<groupId>com.ethlo.time</groupId>
<artifactId>itu</artifactId>
<version>1.10.2</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 410409a

Please sign in to comment.