Search in sources :

Example 1 with CalculateDeviceBrand

use of nl.basjes.parse.useragent.calculate.CalculateDeviceBrand in project yauaa by nielsbasjes.

the class TestCalculators method checkBrandUrlExtraction.

@ParameterizedTest(name = "Test {index} -> Input: \"{0}\"")
@MethodSource("urlsAndBrands")
void checkBrandUrlExtraction(UrlBrandPair pair) {
    LOG.info("URL: {}", pair);
    MutableUserAgent userAgent = new MutableUserAgent();
    userAgent.setForced(UserAgent.AGENT_INFORMATION_URL, pair.url, 1);
    new CalculateDeviceBrand().calculate(userAgent);
    assertEquals(pair.brand, userAgent.getValue(DEVICE_BRAND));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) CalculateDeviceBrand(nl.basjes.parse.useragent.calculate.CalculateDeviceBrand) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with CalculateDeviceBrand

use of nl.basjes.parse.useragent.calculate.CalculateDeviceBrand in project yauaa by nielsbasjes.

the class TestCalculators method testFieldAgentNameVersionFallback.

@Test
void testFieldAgentNameVersionFallback() {
    MutableUserAgent userAgent = new MutableUserAgent();
    userAgent.setForced(UserAgent.DEVICE_BRAND, "some_thing", 1);
    userAgent.setForced(AGENT_VERSION, "1.2.3", 1);
    new CalculateDeviceBrand().calculate(userAgent);
    new CalculateAgentName().calculate(userAgent);
    new MajorVersionCalculator(AGENT_VERSION_MAJOR, AGENT_VERSION).calculate(userAgent);
    new ConcatNONDuplicatedCalculator(AGENT_NAME_VERSION, AGENT_NAME, AGENT_VERSION).calculate(userAgent);
    new ConcatNONDuplicatedCalculator(AGENT_NAME_VERSION_MAJOR, AGENT_NAME, AGENT_VERSION_MAJOR).calculate(userAgent);
    assertEquals("Some_Thing", userAgent.getValue(DEVICE_BRAND));
    assertEquals("Some_Thing", userAgent.getValue(AGENT_NAME));
    assertEquals("Some_Thing 1.2.3", userAgent.getValue(AGENT_NAME_VERSION));
    assertEquals("1", userAgent.getValue(AGENT_VERSION_MAJOR));
    assertEquals("Some_Thing 1", userAgent.getValue(AGENT_NAME_VERSION_MAJOR));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) CalculateDeviceBrand(nl.basjes.parse.useragent.calculate.CalculateDeviceBrand) CalculateAgentName(nl.basjes.parse.useragent.calculate.CalculateAgentName) MajorVersionCalculator(nl.basjes.parse.useragent.calculate.MajorVersionCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MutableUserAgent (nl.basjes.parse.useragent.UserAgent.MutableUserAgent)2 CalculateDeviceBrand (nl.basjes.parse.useragent.calculate.CalculateDeviceBrand)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 CalculateAgentName (nl.basjes.parse.useragent.calculate.CalculateAgentName)1 ConcatNONDuplicatedCalculator (nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator)1 MajorVersionCalculator (nl.basjes.parse.useragent.calculate.MajorVersionCalculator)1 Test (org.junit.jupiter.api.Test)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1