Search in sources :

Example 21 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestYamlBasedExpressions method runDebugOutputTest.

@Test
void runDebugOutputTest() {
    UserAgentAnalyzerTester uaa = createTester("DebugOutput-tests.yaml");
    assertTrue(uaa.runTests(true, true));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test)

Example 22 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestDeveloperTools method determineMatcherEfficiency.

@Test
void determineMatcherEfficiency() {
    UserAgentAnalyzerTester userAgentAnalyzer = UserAgentAnalyzerTester.newBuilder().keepTests().hideMatcherLoadStats().build();
    userAgentAnalyzer.analyzeMatcherImpactAllTests();
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test)

Example 23 with UserAgentAnalyzerTester

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

Example 24 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestDeveloperTools method validateErrorSituationOutput.

@Test
void validateErrorSituationOutput() {
    UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().showMatcherLoadStats().delayInitialization().keepTests().build();
    uaa.loadResources("classpath*:**/CheckErrorOutput.yaml");
    // This test must return an error state
    assertFalse(uaa.runTests(false, true));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test)

Example 25 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestErrorHandlingLogOutput method testConflictingRules.

@Test
void testConflictingRules() {
    assertDoesNotThrow(() -> {
        UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().dropDefaultResources().keepTests().addResources("classpath*:BadDefinitions/ConflictingRules.yaml").build();
        assertFalse(uaa.runTests(false, false));
        LOG.info("Analyzer:\n{}", uaa);
    });
    assertTrue(logMessages.getOutput().contains("Found different value for \"Name\" with SAME confidence 1:"));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) AbstractUserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.AbstractUserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test)

Aggregations

UserAgentAnalyzerTester (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester)43 Test (org.junit.jupiter.api.Test)37 ArrayList (java.util.ArrayList)3 UserAgentAnalyzerTesterBuilder (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester.UserAgentAnalyzerTesterBuilder)3 TestCase (nl.basjes.parse.useragent.config.TestCase)2 YamlUtils.getKeyAsString (nl.basjes.parse.useragent.utils.YamlUtils.getKeyAsString)2 Kryo (com.esotericsoftware.kryo.Kryo)1 ByteBufferInput (com.esotericsoftware.kryo.io.ByteBufferInput)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ImmutableUserAgent (nl.basjes.parse.useragent.UserAgent.ImmutableUserAgent)1 MutableUserAgent (nl.basjes.parse.useragent.UserAgent.MutableUserAgent)1 InvalidParserConfigurationException (nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException)1 Match (nl.basjes.parse.useragent.analyze.MatchesList.Match)1 AbstractUserAgentAnalyzerTester (nl.basjes.parse.useragent.debug.AbstractUserAgentAnalyzerTester)1 Disabled (org.junit.jupiter.api.Disabled)1