-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #811 from EMResearch/issue-803
enabling constraint handling + working on issue #803
- Loading branch information
Showing
12 changed files
with
237 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...rc/main/java/com/foo/rest/examples/spring/stringminlenght/StringMinLengthApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.foo.rest.examples.spring.stringminlenght; | ||
|
||
import com.foo.rest.examples.spring.SwaggerConfiguration; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
@EnableSwagger2 | ||
@SpringBootApplication(exclude = SecurityAutoConfiguration.class) | ||
public class StringMinLengthApplication extends SwaggerConfiguration { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(StringMinLengthApplication.class, args); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...pi-v2/src/main/java/com/foo/rest/examples/spring/stringminlenght/StringMinLengthRest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.foo.rest.examples.spring.stringminlenght; | ||
|
||
import com.foo.rest.examples.spring.strings.StringsResponseDto; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.Size; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Validated | ||
@RestController | ||
@RequestMapping(path = "/api/minlength") | ||
public class StringMinLengthRest { | ||
|
||
|
||
@RequestMapping( | ||
value = "/{s}", | ||
method = RequestMethod.GET, | ||
produces = MediaType.APPLICATION_JSON | ||
) | ||
public String min20( | ||
@PathVariable("s") @Valid @Size(min = 20) String s | ||
){ | ||
|
||
return "OK"; | ||
} | ||
|
||
|
||
|
||
} |
74 changes: 74 additions & 0 deletions
74
e2e-tests/spring-rest-openapi-v2/src/main/resources/static/swagger-minlength.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "Some description", | ||
"version": "1.0", | ||
"title": "API" | ||
}, | ||
"host": "localhost:8080", | ||
"basePath": "/", | ||
"tags": [ | ||
{ | ||
"name": "string-min-length-rest", | ||
"description": "String Min Length Rest" | ||
} | ||
], | ||
"paths": { | ||
"/api/minlength/{s}": { | ||
"get": { | ||
"tags": [ | ||
"string-min-length-rest" | ||
], | ||
"summary": "min20", | ||
"operationId": "min20UsingGET", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"parameters": [ | ||
{ | ||
"name": "s", | ||
"in": "path", | ||
"description": "s", | ||
"required": true, | ||
"type": "string", | ||
"minLength" : 20 | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"401": { | ||
"description": "Unauthorized" | ||
}, | ||
"403": { | ||
"description": "Forbidden" | ||
}, | ||
"404": { | ||
"description": "Not Found" | ||
} | ||
}, | ||
"responsesObject": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"401": { | ||
"description": "Unauthorized" | ||
}, | ||
"403": { | ||
"description": "Forbidden" | ||
}, | ||
"404": { | ||
"description": "Not Found" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...src/test/java/com/foo/rest/examples/spring/stringminlength/StringMinLengthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.foo.rest.examples.spring.stringminlength; | ||
|
||
import com.foo.rest.examples.spring.SpringController; | ||
import com.foo.rest.examples.spring.stringminlenght.StringMinLengthApplication; | ||
import org.evomaster.client.java.controller.problem.ProblemInfo; | ||
import org.evomaster.client.java.controller.problem.RestProblem; | ||
|
||
public class StringMinLengthController extends SpringController { | ||
|
||
public StringMinLengthController(){ | ||
super(StringMinLengthApplication.class); | ||
} | ||
|
||
@Override | ||
public ProblemInfo getProblemInfo() { | ||
return new RestProblem( | ||
"http://localhost:" + getSutPort() + "/swagger-minlength.json", | ||
null | ||
); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...st/java/org/evomaster/e2etests/spring/examples/stringminlength/StringMinLengthEMTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.evomaster.e2etests.spring.examples.stringminlength; | ||
|
||
import com.foo.rest.examples.spring.stringminlength.StringMinLengthController; | ||
import com.foo.rest.examples.spring.strings.StringsController; | ||
import org.evomaster.core.problem.rest.HttpVerb; | ||
import org.evomaster.core.problem.rest.RestIndividual; | ||
import org.evomaster.core.search.Solution; | ||
import org.evomaster.e2etests.spring.examples.SpringTestBase; | ||
import org.evomaster.e2etests.spring.examples.strings.StringsTestBase; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class StringMinLengthEMTest extends SpringTestBase { | ||
|
||
@BeforeAll | ||
public static void initClass() throws Exception { | ||
SpringTestBase.initClass(new StringMinLengthController()); | ||
} | ||
|
||
@Test | ||
public void testRunEM() throws Throwable { | ||
|
||
runTestHandlingFlakyAndCompilation( | ||
"StringMinLengthEM", | ||
"org.bar.StringMinLengthEM", | ||
10, | ||
(args) -> { | ||
Solution<RestIndividual> solution = initAndRun(args); | ||
|
||
assertTrue(solution.getIndividuals().size() >= 1); | ||
|
||
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/minlength/{s}", "OK"); | ||
}); | ||
} | ||
} |