use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.
the class TestPredefinedBrowsers method makeSureWeDoNotHaveDuplicateTests.
@Test
void makeSureWeDoNotHaveDuplicateTests() {
UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().build();
Map<String, List<String>> allTestInputs = new HashMap<>(2000);
Set<String> duplicates = new HashSet<>();
for (TestCase testCase : uaa.getTestCases()) {
String input = testCase.getUserAgent();
String location = testCase.getMetadata().get("filename") + ":" + testCase.getMetadata().get("fileline");
List<String> locations = allTestInputs.get(input);
if (locations == null) {
locations = new ArrayList<>();
}
locations.add(location);
if (locations.size() > 1) {
duplicates.add(input);
}
allTestInputs.put(input, locations);
}
if (duplicates.size() == 0) {
LOG.info("No duplicate tests were found.");
// We're done and all is fine.
return;
}
StringBuilder sb = new StringBuilder(1024);
for (String duplicate : duplicates) {
sb.append("======================================================\n").append("Testcase > ").append(duplicate).append("\n");
int count = 0;
for (String location : allTestInputs.get(duplicate)) {
sb.append(">Location ").append(++count).append(".(").append(location).append(")\n");
}
}
fail("Found " + duplicates.size() + " testcases multiple times: \n" + sb);
}
use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.
the class TestPredefinedBrowsers method validateAllPredefinedBrowsersViaTestCase.
@Test
void validateAllPredefinedBrowsersViaTestCase() {
UserAgentAnalyzerTester uaa;
uaa = UserAgentAnalyzerTester.newBuilder().immediateInitialization().build();
LOG.info("==============================================================");
LOG.info("Validating when getting all fields");
LOG.info("--------------------------------------------------------------");
List<TestCase> testCases = uaa.getTestCases();
long start = System.nanoTime();
assertEquals(0, testCases.stream().filter(testCase -> !testCase.verify(uaa)).count());
long stop = System.nanoTime();
LOG.info("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()));
LOG.info("--------------------------------------------------------------");
LOG.info("Running all tests again which should return the cached values");
assertEquals(0, testCases.stream().filter(testCase -> !testCase.verify(uaa)).count());
// Only here for ensuring the code being tested with "all fields".
uaa.destroy();
}
use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.
the class DocumentationExample method runDocumentationExample.
@Test
void runDocumentationExample() {
UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().dropDefaultResources().addResources("classpath*:DocumentationExample.yaml").build();
assertTrue(uaa.runTests(false, true));
}
use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.
the class TestErrorHandling method runTest.
private void runTest(String resourceString, Matcher<String> expectedMessage) {
InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> {
UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().dropDefaultResources().keepTests().addResources(resourceString).build();
assertTrue(uaa.runTests(false, false));
});
assertTrue(expectedMessage.matches(exception.getMessage()), "Bad message:" + exception.getMessage());
}
use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.
the class TestPredefinedBrowsers method validateAllPredefinedBrowsers.
@Test
void validateAllPredefinedBrowsers() {
UserAgentAnalyzerTester uaa;
uaa = UserAgentAnalyzerTester.newBuilder().immediateInitialization().build();
LOG.info("==============================================================");
LOG.info("Validating when getting all fields");
LOG.info("--------------------------------------------------------------");
assertTrue(uaa.runTests(false, true, null, false, true));
LOG.info("--------------------------------------------------------------");
LOG.info("Running all tests again which should return the cached values");
assertTrue(uaa.runTests(false, true, null, false, false));
// Only here for ensuring the code being tested with "all fields".
uaa.destroy();
}
Aggregations