Search in sources :

Example 1 with Match

use of nl.basjes.parse.useragent.analyze.MatchesList.Match in project yauaa by nielsbasjes.

the class TestMatchesList method testNormalUse.

@Test
void testNormalUse() {
    MatchesList list = new MatchesList(5);
    assertEquals(0, list.size());
    list.add("one", "two", null);
    assertEquals(1, list.size());
    list.add("three", "four", null);
    assertEquals(2, list.size());
    Iterator<Match> iterator = list.iterator();
    assertTrue(iterator.hasNext());
    Match match1 = iterator.next();
    assertTrue(iterator.hasNext());
    Match match2 = iterator.next();
    assertFalse(iterator.hasNext());
    assertEquals("one", match1.getKey());
    assertEquals("two", match1.getValue());
    assertNull(match1.getResult());
    assertEquals("three", match2.getKey());
    assertEquals("four", match2.getValue());
    assertNull(match2.getResult());
}
Also used : Match(nl.basjes.parse.useragent.analyze.MatchesList.Match) Test(org.junit.jupiter.api.Test)

Example 2 with Match

use of nl.basjes.parse.useragent.analyze.MatchesList.Match in project yauaa by nielsbasjes.

the class AbstractUserAgentAnalyzerTester method getUsedMatches.

public synchronized List<Match> getUsedMatches(MutableUserAgent userAgent) {
    // Reset all Matchers
    for (Matcher matcher : getAllMatchers()) {
        matcher.reset();
        matcher.setVerboseTemporarily(false);
    }
    flattener.parse(userAgent);
    List<Match> allMatches = new ArrayList<>(128);
    for (Matcher matcher : getAllMatchers()) {
        allMatches.addAll(matcher.getUsedMatches());
    }
    return allMatches;
}
Also used : Matcher(nl.basjes.parse.useragent.analyze.Matcher) ArrayList(java.util.ArrayList) Match(nl.basjes.parse.useragent.analyze.MatchesList.Match)

Example 3 with Match

use of nl.basjes.parse.useragent.analyze.MatchesList.Match in project yauaa by nielsbasjes.

the class TestDeveloperTools method validateStringOutputsAndMatches.

@Test
void validateStringOutputsAndMatches() {
    UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().withField("DeviceName").build();
    MutableUserAgent useragent = new MutableUserAgent("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");
    ImmutableUserAgent parseResult = uaa.parse(useragent);
    assertTrue(parseResult.toString().contains("'Google Nexus 6'"));
    assertTrue(parseResult.toJson().contains("\"DeviceName\":\"Google Nexus 6\""));
    assertTrue(parseResult.toJson("DeviceName").contains("\"DeviceName\":\"Google Nexus 6\""));
    assertFalse(parseResult.toJson("DeviceClass").contains("\"DeviceName\":\"Google Nexus 6\""));
    assertTrue(parseResult.toXML().contains("<DeviceName>Google Nexus 6</DeviceName>"));
    assertTrue(parseResult.toXML("DeviceName").contains("<DeviceName>Google Nexus 6</DeviceName>"));
    assertFalse(parseResult.toXML("DeviceClass").contains("<DeviceName>Google Nexus 6</DeviceName>"));
    assertEquals("Google Nexus 6", parseResult.toMap().get("DeviceName"));
    assertEquals("Google Nexus 6", parseResult.toMap("DeviceName").get("DeviceName"));
    assertNull(parseResult.toMap("DeviceClass").get("DeviceName"));
    assertTrue(parseResult.toYamlTestCase(true).contains("'Google Nexus 6'"));
    boolean ok = false;
    for (Match match : uaa.getMatches()) {
        if ("agent.(1)product.(1)comments.(3)entry[3-3]".equals(match.getKey())) {
            assertEquals("Build", match.getValue());
            ok = true;
            break;
        }
    }
    assertTrue(ok, "Did not see the expected match.");
    ok = false;
    for (Match match : uaa.getUsedMatches(useragent)) {
        if ("agent.(1)product.(1)comments.(3)entry[3-3]".equals(match.getKey())) {
            assertEquals("Build", match.getValue());
            ok = true;
            break;
        }
    }
    assertTrue(ok, "Did not see the expected match.");
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) ImmutableUserAgent(nl.basjes.parse.useragent.UserAgent.ImmutableUserAgent) Match(nl.basjes.parse.useragent.analyze.MatchesList.Match) Test(org.junit.jupiter.api.Test)

Aggregations

Match (nl.basjes.parse.useragent.analyze.MatchesList.Match)3 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 ImmutableUserAgent (nl.basjes.parse.useragent.UserAgent.ImmutableUserAgent)1 MutableUserAgent (nl.basjes.parse.useragent.UserAgent.MutableUserAgent)1 Matcher (nl.basjes.parse.useragent.analyze.Matcher)1 UserAgentAnalyzerTester (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester)1