Search in sources :

Example 26 with UserAgentAnalyzer

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());
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test)

Example 27 with UserAgentAnalyzer

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()));
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) UserAgent(nl.basjes.parse.useragent.UserAgent) Test(org.junit.jupiter.api.Test)

Example 28 with UserAgentAnalyzer

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));
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test)

Example 29 with UserAgentAnalyzer

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"));
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) UserAgent(nl.basjes.parse.useragent.UserAgent) Test(org.junit.jupiter.api.Test)

Example 30 with UserAgentAnalyzer

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()));
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) UserAgent(nl.basjes.parse.useragent.UserAgent) Test(org.junit.jupiter.api.Test)

Aggregations

UserAgentAnalyzer (nl.basjes.parse.useragent.UserAgentAnalyzer)38 Test (org.junit.jupiter.api.Test)24 UserAgent (nl.basjes.parse.useragent.UserAgent)11 ArrayList (java.util.ArrayList)4 Disabled (org.junit.jupiter.api.Disabled)4 Map (java.util.Map)3 UserAgentAnalyzerBuilder (nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder)3 MissingUserAgentException (nl.basjes.parse.useragent.servlet.exceptions.MissingUserAgentException)3 Kryo (com.esotericsoftware.kryo.Kryo)2 ByteBufferInput (com.esotericsoftware.kryo.io.ByteBufferInput)2 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInput (java.io.ObjectInput)2 ObjectInputStream (java.io.ObjectInputStream)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 TestCase (nl.basjes.parse.useragent.config.TestCase)2 IngestDocument (org.elasticsearch.ingest.IngestDocument)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2