use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestUserAgentAnalyzerJavaSerialization method deserialize.
UserAgentAnalyzer deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
try (ObjectInput in = new ObjectInputStream(bis)) {
Object o = in.readObject();
assertTrue(o instanceof UserAgentAnalyzer);
return (UserAgentAnalyzer) o;
}
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testLimitedFields.
@Test
void testLimitedFields() {
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().preheat(100).preheat().withCache(42).withoutCache().hideMatcherLoadStats().showMatcherLoadStats().withAllFields().withField("DeviceClass").withField("AgentNameVersionMajor").withUserAgentMaxLength(1234).build();
assertEquals(1234, userAgentAnalyzer.getUserAgentMaxLength());
runTestCase(userAgentAnalyzer);
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testLoadAdditionalRules.
@Test
void testLoadAdditionalRules() {
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().withField("DeviceClass").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("Phone", parsedAgent.getValue("DeviceClass"));
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 testPreheatNoTests.
@Test
void testPreheatNoTests() {
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().keepTests().hideMatcherLoadStats().withField("AgentName").build();
assertTrue(userAgentAnalyzer.getNumberOfTestCases() > 100);
assertEquals(0, userAgentAnalyzer.preHeat(0));
assertEquals(0, userAgentAnalyzer.preHeat(-1));
assertEquals(0, userAgentAnalyzer.preHeat(1000000000L));
userAgentAnalyzer.dropTests();
// The full testCases from the yaml are NO LONGER used for the preHeat !
// Preheat has a separate list with all the test cases (smaller since we do not have the answers there).
assertEquals(0, userAgentAnalyzer.getNumberOfTestCases());
assertEquals(PreHeatCases.USERAGENTS.size(), userAgentAnalyzer.preHeat());
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testWantedFieldNamesOne.
@Test
void testWantedFieldNamesOne() {
UserAgentAnalyzer uaa = createWithWantedFieldNames(OPERATING_SYSTEM_NAME_VERSION);
Set<String> expectedWantedFields = fields(DEVICE_CLASS, OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_VERSION, OPERATING_SYSTEM_NAME_VERSION, SET_ALL_FIELDS);
assertEquals(expectedWantedFields, uaa.getWantedFieldNames());
Set<String> expectedPossibleFields = fields(SYNTAX_ERROR, DEVICE_CLASS, OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_VERSION, OPERATING_SYSTEM_NAME_VERSION);
assertEquals(expectedPossibleFields, uaa.getAllPossibleFieldNames());
UserAgent userAgent = uaa.parse(TEST_UA);
assertEquals(expectedPossibleFields, new TreeSet<>(userAgent.getAvailableFieldNamesSorted()));
}
Aggregations