-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...ring-rest-openapi-v2/src/main/java/com/foo/rest/examples/spring/json/JsonApplication.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,19 @@ | ||
package com.foo.rest.examples.spring.json; | ||
|
||
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 JsonApplication extends SwaggerConfiguration { | ||
|
||
public static void main(String[] args){ | ||
SpringApplication.run(JsonApplication.class, args); | ||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...ests/spring-rest-openapi-v2/src/main/java/com/foo/rest/examples/spring/json/JsonRest.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,32 @@ | ||
package com.foo.rest.examples.spring.json; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping(path = "/api/json") | ||
public class JsonRest { | ||
|
||
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<String> post(@RequestBody String json) throws JsonProcessingException { | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
Map collection = mapper.readValue(json, Map.class); | ||
List<Integer> z = (List<Integer>) collection.get("z"); | ||
|
||
if (z.get(1) == 2025) { | ||
return ResponseEntity.ok().body("OK"); | ||
} else { | ||
return ResponseEntity.badRequest().body("FAIL"); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...pring-rest-openapi-v2/src/test/java/com/foo/rest/examples/spring/json/JsonController.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,11 @@ | ||
package com.foo.rest.examples.spring.json; | ||
|
||
import com.foo.rest.examples.spring.SpringController; | ||
import com.foo.rest.examples.spring.positiveinteger.PIApplication; | ||
|
||
public class JsonController extends SpringController { | ||
|
||
public JsonController() { | ||
super(JsonApplication.class); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/json/JsonEMTest.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,39 @@ | ||
package org.evomaster.e2etests.spring.examples.json; | ||
|
||
import com.foo.rest.examples.spring.json.JsonController; | ||
import com.foo.rest.examples.spring.postcollection.PostCollectionController; | ||
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.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class JsonEMTest extends SpringTestBase { | ||
|
||
@BeforeAll | ||
public static void initClass() throws Exception { | ||
|
||
SpringTestBase.initClass(new JsonController()); | ||
} | ||
|
||
@Test | ||
public void testRunEM() throws Throwable { | ||
|
||
runTestHandlingFlakyAndCompilation( | ||
"JsonEMTest", | ||
10_000, | ||
(args) -> { | ||
|
||
setOption(args, "taintForceSelectionOfGenesWithSpecialization", "true"); | ||
setOption(args, "discoveredInfoRewardedInFitness", "true"); | ||
|
||
Solution<RestIndividual> solution = initAndRun(args); | ||
assertTrue(solution.getIndividuals().size() >= 1); | ||
|
||
assertHasAtLeastOne(solution, HttpVerb.POST, 200); | ||
}); | ||
} | ||
} |