use of nl.basjes.parse.useragent.config.TestCase 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.config.TestCase 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.config.TestCase in project yauaa by nielsbasjes.
the class TestTestCase method basicTestCase.
@Test
void basicTestCase() {
TestCase testCase = new TestCase(USERAGENT, "My test");
// The EXPLICITLY requested fields
testCase.expect("DeviceClass", "Phone");
testCase.expect("DeviceBrand", "Google");
testCase.expect("DeviceName", "Google Nexus 6");
testCase.expect("AgentNameVersionMajor", "Chrome 53");
// The IMPLICITLY requested fields (i.e. partials of the actually requested ones)
testCase.expect("AgentName", "Chrome");
testCase.expect("AgentVersion", "53.0.2785.124");
testCase.expect("AgentVersionMajor", "53");
// The NOT requested fields are not there
testCase.expect("OperatingSystemClass", null);
testCase.expect("OperatingSystemName", null);
testCase.expect("OperatingSystemNameVersion", null);
testCase.expect("OperatingSystemNameVersionMajor", null);
testCase.expect("OperatingSystemVersion", null);
testCase.expect("OperatingSystemVersionBuild", null);
testCase.expect("OperatingSystemVersionMajor", null);
testCase.expect("LayoutEngineClass", null);
testCase.expect("LayoutEngineName", null);
testCase.expect("LayoutEngineNameVersion", null);
testCase.expect("LayoutEngineNameVersionMajor", null);
testCase.expect("LayoutEngineVersion", null);
testCase.expect("LayoutEngineVersionMajor", null);
testCase.expect("AgentClass", null);
testCase.expect("AgentNameVersion", null);
assertTrue(testCase.verify(userAgentAnalyzer));
}
Aggregations