Search in sources :

Example 1 with YauaaTestsFailed

use of nl.basjes.parse.useragent.servlet.exceptions.YauaaTestsFailed in project yauaa by nielsbasjes.

the class RunTests method getRunTests.

// ===========================================
@Operation(description = "Fire all available test cases against the analyzer and return 200 if all tests were good")
@ApiResponse(// HttpStatus.OK
responseCode = "200", description = "All tests were good", content = @Content(mediaType = TEXT_PLAIN_VALUE, examples = @ExampleObject("All 3866 tests passed in 2994ms (average 0.775ms per testcase).")))
@ApiResponse(// HttpStatus.INTERNAL_SERVER_ERROR
responseCode = "500", description = "A test failed", content = @Content(mediaType = TEXT_PLAIN_VALUE, examples = @ExampleObject("Extensive text describing what went wrong in the test that failed")))
@GetMapping(value = "/runtests", produces = TEXT_PLAIN_VALUE)
public String getRunTests() {
    UserAgentAnalyzer userAgentAnalyzer = ParseService.getUserAgentAnalyzer();
    List<TestCase> testCases = userAgentAnalyzer.getTestCases();
    long start = System.nanoTime();
    List<TestCase> failedTests = testCases.stream().filter(testCase -> !testCase.verify(userAgentAnalyzer)).collect(Collectors.toList());
    long stop = System.nanoTime();
    if (failedTests.isEmpty()) {
        return String.format("All %d tests passed in %dms (average %4.3fms per testcase).", testCases.size(), (stop - start) / 1_000_000, ((stop - start) / 1_000_000D / testCases.size()));
    }
    throw new YauaaTestsFailed("There were " + failedTests.size() + " failed tests " + "(~" + ((100.0D * failedTests.size()) / testCases.size()) + "%)");
}
Also used : TestCase(nl.basjes.parse.useragent.config.TestCase) ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject) ParseService(nl.basjes.parse.useragent.servlet.ParseService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) List(java.util.List) YauaaTestsFailed(nl.basjes.parse.useragent.servlet.exceptions.YauaaTestsFailed) ParseService.ensureStartedForApis(nl.basjes.parse.useragent.servlet.ParseService.ensureStartedForApis) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Tag(io.swagger.v3.oas.annotations.tags.Tag) GetMapping(org.springframework.web.bind.annotation.GetMapping) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) TestCase(nl.basjes.parse.useragent.config.TestCase) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) YauaaTestsFailed(nl.basjes.parse.useragent.servlet.exceptions.YauaaTestsFailed) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)1 Content (io.swagger.v3.oas.annotations.media.Content)1 ExampleObject (io.swagger.v3.oas.annotations.media.ExampleObject)1 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 Tag (io.swagger.v3.oas.annotations.tags.Tag)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 UserAgentAnalyzer (nl.basjes.parse.useragent.UserAgentAnalyzer)1 TestCase (nl.basjes.parse.useragent.config.TestCase)1 ParseService (nl.basjes.parse.useragent.servlet.ParseService)1 ParseService.ensureStartedForApis (nl.basjes.parse.useragent.servlet.ParseService.ensureStartedForApis)1 YauaaTestsFailed (nl.basjes.parse.useragent.servlet.exceptions.YauaaTestsFailed)1 APPLICATION_JSON_VALUE (org.springframework.http.MediaType.APPLICATION_JSON_VALUE)1 TEXT_PLAIN_VALUE (org.springframework.http.MediaType.TEXT_PLAIN_VALUE)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 RestController (org.springframework.web.bind.annotation.RestController)1