Search in sources :

Example 16 with MutableUserAgent

use of nl.basjes.parse.useragent.UserAgent.MutableUserAgent in project yauaa by nielsbasjes.

the class TestUseragent method testUseragent.

@Test
void testUseragent() {
    String uaString = "Foo Bar";
    UserAgent agent = new MutableUserAgent(uaString);
    assertEquals(uaString, agent.get(UserAgent.USERAGENT_FIELDNAME).getValue());
    assertEquals(0, agent.get(UserAgent.USERAGENT_FIELDNAME).getConfidence());
    assertEquals(uaString, agent.getValue(UserAgent.USERAGENT_FIELDNAME));
    assertEquals(0L, agent.getConfidence(UserAgent.USERAGENT_FIELDNAME).longValue());
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) ImmutableUserAgent(nl.basjes.parse.useragent.UserAgent.ImmutableUserAgent) Test(org.junit.jupiter.api.Test)

Example 17 with MutableUserAgent

use of nl.basjes.parse.useragent.UserAgent.MutableUserAgent 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)

Example 18 with MutableUserAgent

use of nl.basjes.parse.useragent.UserAgent.MutableUserAgent in project yauaa by nielsbasjes.

the class TestClassifier method verifyDeviceClass.

private void verifyDeviceClass(DeviceClass deviceClass, boolean human, boolean mobile, boolean normal, boolean misuse) {
    MutableUserAgent userAgent = new MutableUserAgent();
    userAgent.set(DEVICE_CLASS, deviceClass.getValue(), 1);
    assertEquals(human, isHuman(userAgent), "For the DeviceClass " + deviceClass + " the isHuman() was incorrect.");
    assertEquals(mobile, isMobile(userAgent), "For the DeviceClass " + deviceClass + " the isMobile() was incorrect.");
    assertEquals(normal, isNormalConsumerDevice(userAgent), "For the DeviceClass " + deviceClass + " the isNormalConsumerDevice() was incorrect.");
    assertEquals(misuse, isDeliberateMisuse(userAgent), "For the DeviceClass " + deviceClass + " the isDeliberateMisuse() was incorrect.");
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent)

Aggregations

MutableUserAgent (nl.basjes.parse.useragent.UserAgent.MutableUserAgent)18 Test (org.junit.jupiter.api.Test)13 ConcatNONDuplicatedCalculator (nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator)6 FieldCalculator (nl.basjes.parse.useragent.calculate.FieldCalculator)5 MutableAgentField (nl.basjes.parse.useragent.AgentField.MutableAgentField)4 ImmutableUserAgent (nl.basjes.parse.useragent.UserAgent.ImmutableUserAgent)4 CalculateDeviceBrand (nl.basjes.parse.useragent.calculate.CalculateDeviceBrand)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Match (nl.basjes.parse.useragent.analyze.MatchesList.Match)1 CalculateAgentName (nl.basjes.parse.useragent.calculate.CalculateAgentName)1 MajorVersionCalculator (nl.basjes.parse.useragent.calculate.MajorVersionCalculator)1 UserAgentAnalyzerTester (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1