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()) + "%)");
}
Aggregations