Search in sources :

Example 6 with MutableUserAgent

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

the class TestConcatenation method testFieldConcatenationNoConfidence.

@Test
void testFieldConcatenationNoConfidence() {
    FieldCalculator fc;
    MutableUserAgent userAgent = createUserAgent();
    fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "MinusOne");
    fc.calculate(userAgent);
    assertEquals("One MinusOne", userAgent.getValue("Combined2"));
    fc = new ConcatNONDuplicatedCalculator("Combined3", "MinusOne", "Two");
    fc.calculate(userAgent);
    assertEquals("MinusOne Two", userAgent.getValue("Combined3"));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Example 7 with MutableUserAgent

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

the class TestConcatenation method testFieldConcatenationSamePrefix.

@Test
void testFieldConcatenationSamePrefix() {
    FieldCalculator fc;
    MutableUserAgent userAgent = createUserAgent();
    fc = new ConcatNONDuplicatedCalculator("Combined1", "One", "Two");
    fc.calculate(userAgent);
    assertEquals("One Two", userAgent.getValue("Combined1"));
    fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "One");
    fc.calculate(userAgent);
    assertEquals("One", userAgent.getValue("Combined2"));
    fc = new ConcatNONDuplicatedCalculator("Combined3", "One", "One Two");
    fc.calculate(userAgent);
    assertEquals("One Two", userAgent.getValue("Combined3"));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Example 8 with MutableUserAgent

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

the class TestConcatenation method testFieldConcatenationAllDefaults.

@Test
void testFieldConcatenationAllDefaults() {
    FieldCalculator fc;
    MutableUserAgent userAgent = new MutableUserAgent();
    userAgent.set("FooBarName", "Dummy", 1);
    userAgent.set("FooBarVersion", "Dummy", 1);
    userAgent.reset();
    fc = new ConcatNONDuplicatedCalculator("FooBarNameVersion", "FooBarName", "FooBarVersion");
    fc.calculate(userAgent);
    assertEquals("Unknown", userAgent.getValue("FooBarName"));
    assertEquals("??", userAgent.getValue("FooBarVersion"));
    assertEquals("Unknown ??", userAgent.getValue("FooBarNameVersion"));
    assertTrue(userAgent.get("FooBarName").isDefaultValue());
    assertTrue(userAgent.get("FooBarVersion").isDefaultValue());
    assertTrue(userAgent.get("FooBarNameVersion").isDefaultValue());
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Example 9 with MutableUserAgent

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

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

the class TestConcatenation method createUserAgent.

private MutableUserAgent createUserAgent() {
    MutableUserAgent userAgent = new MutableUserAgent();
    userAgent.setForced("MinusOne", "MinusOne", -1);
    userAgent.setForced("Zero", "Zero", 0);
    userAgent.setForced("One", "One", 1);
    userAgent.setForced("Two", "Two", 2);
    userAgent.setForced("One Two", "One Two", 12);
    return userAgent;
}
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