use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testPostPreheatDroptests.
@Test
void testPostPreheatDroptests() {
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().immediateInitialization().dropTests().hideMatcherLoadStats().withField("AgentName").build();
assertEquals(0, userAgentAnalyzer.getNumberOfTestCases());
userAgentAnalyzer = UserAgentAnalyzer.newBuilder().immediateInitialization().preheat(// With .preheat(100)
100).dropTests().hideMatcherLoadStats().withField("AgentName").build();
assertEquals(0, userAgentAnalyzer.getNumberOfTestCases());
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testWantedFieldNamesTwo.
@Test
void testWantedFieldNamesTwo() {
UserAgentAnalyzer uaa = createWithWantedFieldNames(OPERATING_SYSTEM_NAME, AGENT_VERSION);
Set<String> expectedWantedFields = fields(DEVICE_CLASS, OPERATING_SYSTEM_NAME, AGENT_VERSION, SET_ALL_FIELDS);
assertEquals(expectedWantedFields, uaa.getWantedFieldNames());
Set<String> expectedPossibleFields = fields(SYNTAX_ERROR, DEVICE_CLASS, OPERATING_SYSTEM_NAME, AGENT_VERSION);
assertEquals(expectedPossibleFields, uaa.getAllPossibleFieldNames());
UserAgent userAgent = uaa.parse(TEST_UA);
assertEquals(expectedPossibleFields, new TreeSet<>(userAgent.getAvailableFieldNamesSorted()));
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testLoadMoreResources.
@Test
void testLoadMoreResources() {
UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder().delayInitialization().withField("DeviceClass");
UserAgentAnalyzer uaa = builder.build();
assertNotNull(uaa, "We should get a first instance from a single builder.");
// Try to load something that does not yield any files.
// Optional --> error message and continue
uaa.loadResources("Bad resource string that is optional should only give a warning", true, true);
// NOT Optional --> fail with exception
assertThrows(InvalidParserConfigurationException.class, () -> uaa.loadResources("Bad resource string that is NOT optional should fail hard", true, false));
uaa.initializeMatchers();
assertThrows(IllegalStateException.class, () -> uaa.loadResources(DEFAULT_RESOURCES));
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testLoadOnlyCustomRules.
@Test
void testLoadOnlyCustomRules() {
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().withoutCache().hideMatcherLoadStats().addResources("ExtraLoadedRule1.yaml").withField("ExtraValue2").withField("ExtraValue1").addResources("ExtraLoadedRule2.yaml").build();
UserAgent parsedAgent = userAgentAnalyzer.parse("Mozilla/5.0 (Linux; Android 7.0; Nexus 6 Build/NBD90Z) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.124 Mobile Safari/537.36");
// The requested fields
assertEquals("One", parsedAgent.getValue("ExtraValue1"));
assertEquals("Two", parsedAgent.getValue("ExtraValue2"));
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testWantedFieldNamesOneAndCalc.
@Test
void testWantedFieldNamesOneAndCalc() {
UserAgentAnalyzer uaa = createWithWantedFieldNames(AGENT_NAME_VERSION_MAJOR);
Set<String> expectedWantedFields = fields(DEVICE_CLASS, DEVICE_BRAND, AGENT_INFORMATION_EMAIL, AGENT_INFORMATION_URL, AGENT_NAME, AGENT_VERSION, AGENT_VERSION_MAJOR, AGENT_NAME_VERSION_MAJOR, SET_ALL_FIELDS);
assertEquals(expectedWantedFields, uaa.getWantedFieldNames());
Set<String> expectedPossibleFields = fields(SYNTAX_ERROR, DEVICE_CLASS, DEVICE_BRAND, AGENT_INFORMATION_EMAIL, AGENT_INFORMATION_URL, AGENT_NAME, AGENT_VERSION, AGENT_VERSION_MAJOR, AGENT_NAME_VERSION_MAJOR);
assertEquals(expectedPossibleFields, uaa.getAllPossibleFieldNames());
UserAgent userAgent = uaa.parse(TEST_UA);
assertEquals(expectedPossibleFields, new TreeSet<>(userAgent.getAvailableFieldNamesSorted()));
}
Aggregations