Skip to content

Commit

Permalink
working on paper example for JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
arcuri82 committed Oct 29, 2024
1 parent 634ce0f commit b7d9af6
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
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);
}


}
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");
}
}
}
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);
}
}
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);
});
}
}

0 comments on commit b7d9af6

Please sign in to comment.